blob: 68fb0e79858877581b8de6d9044f353d6c91c9a9 [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
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008205 UNIMPLEMENTED();
8206 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008207 }
8208 catch(std::bad_alloc&)
8209 {
8210 return gl::error(GL_OUT_OF_MEMORY);
8211 }
8212}
8213
8214void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
8215{
8216 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
8217 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
8218
8219 try
8220 {
8221 gl::Context *context = gl::getNonLostContext();
8222
8223 if (context)
8224 {
8225 if (context->getClientVersion() < 3)
8226 {
8227 return gl::error(GL_INVALID_OPERATION);
8228 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008229
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008230 UNIMPLEMENTED();
8231 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008232 }
8233 catch(std::bad_alloc&)
8234 {
8235 return gl::error(GL_OUT_OF_MEMORY);
8236 }
8237}
8238
8239void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
8240{
8241 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8242 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
8243 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8244 target, level, internalformat, width, height, depth, border, format, type, pixels);
8245
8246 try
8247 {
8248 gl::Context *context = gl::getNonLostContext();
8249
8250 if (context)
8251 {
8252 if (context->getClientVersion() < 3)
8253 {
8254 return gl::error(GL_INVALID_OPERATION);
8255 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008256
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008257 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008258 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008259 0, 0, 0, width, height, depth, border, format, type))
8260 {
8261 return;
8262 }
8263
8264 switch(target)
8265 {
8266 case GL_TEXTURE_3D:
8267 {
8268 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008269 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008270 }
8271 break;
8272
8273 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008274 {
8275 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008276 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008277 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008278 break;
8279
8280 default:
8281 return gl::error(GL_INVALID_ENUM);
8282 }
8283 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008284 }
8285 catch(std::bad_alloc&)
8286 {
8287 return gl::error(GL_OUT_OF_MEMORY);
8288 }
8289}
8290
8291void __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)
8292{
8293 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8294 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8295 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8296 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
8297
8298 try
8299 {
8300 gl::Context *context = gl::getNonLostContext();
8301
8302 if (context)
8303 {
8304 if (context->getClientVersion() < 3)
8305 {
8306 return gl::error(GL_INVALID_OPERATION);
8307 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008308
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008309 if (!pixels)
8310 {
8311 return gl::error(GL_INVALID_VALUE);
8312 }
8313
8314 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008315 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008316 xoffset, yoffset, zoffset, width, height, depth, 0,
8317 format, type))
8318 {
8319 return;
8320 }
8321
8322 switch(target)
8323 {
8324 case GL_TEXTURE_3D:
8325 {
8326 gl::Texture3D *texture = context->getTexture3D();
8327 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8328 }
8329 break;
8330
8331 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008332 {
8333 gl::Texture2DArray *texture = context->getTexture2DArray();
8334 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8335 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008336 break;
8337
8338 default:
8339 return gl::error(GL_INVALID_ENUM);
8340 }
8341 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008342 }
8343 catch(std::bad_alloc&)
8344 {
8345 return gl::error(GL_OUT_OF_MEMORY);
8346 }
8347}
8348
8349void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8350{
8351 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8352 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8353 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8354
8355 try
8356 {
8357 gl::Context *context = gl::getNonLostContext();
8358
8359 if (context)
8360 {
8361 if (context->getClientVersion() < 3)
8362 {
8363 return gl::error(GL_INVALID_OPERATION);
8364 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008365
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008366 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8367 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008368 {
8369 return;
8370 }
8371
8372 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8373 gl::Texture *texture = NULL;
8374 switch (target)
8375 {
8376 case GL_TEXTURE_3D:
8377 texture = context->getTexture3D();
8378 break;
8379
8380 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008381 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008382 break;
8383
8384 default:
8385 return gl::error(GL_INVALID_ENUM);
8386 }
8387
8388 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8389 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008390 }
8391 catch(std::bad_alloc&)
8392 {
8393 return gl::error(GL_OUT_OF_MEMORY);
8394 }
8395}
8396
8397void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8398{
8399 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8400 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8401 "const GLvoid* data = 0x%0.8p)",
8402 target, level, internalformat, width, height, depth, border, imageSize, data);
8403
8404 try
8405 {
8406 gl::Context *context = gl::getNonLostContext();
8407
8408 if (context)
8409 {
8410 if (context->getClientVersion() < 3)
8411 {
8412 return gl::error(GL_INVALID_OPERATION);
8413 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008414
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008415 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 +00008416 {
8417 return gl::error(GL_INVALID_VALUE);
8418 }
8419
8420 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008421 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8422 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008423 {
8424 return;
8425 }
8426
8427 switch(target)
8428 {
8429 case GL_TEXTURE_3D:
8430 {
8431 gl::Texture3D *texture = context->getTexture3D();
8432 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8433 }
8434 break;
8435
8436 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008437 {
8438 gl::Texture2DArray *texture = context->getTexture2DArray();
8439 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8440 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008441 break;
8442
8443 default:
8444 return gl::error(GL_INVALID_ENUM);
8445 }
8446 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008447 }
8448 catch(std::bad_alloc&)
8449 {
8450 return gl::error(GL_OUT_OF_MEMORY);
8451 }
8452}
8453
8454void __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)
8455{
8456 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8457 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8458 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8459 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8460
8461 try
8462 {
8463 gl::Context *context = gl::getNonLostContext();
8464
8465 if (context)
8466 {
8467 if (context->getClientVersion() < 3)
8468 {
8469 return gl::error(GL_INVALID_OPERATION);
8470 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008471
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008472 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 +00008473 {
8474 return gl::error(GL_INVALID_VALUE);
8475 }
8476
8477 if (!data)
8478 {
8479 return gl::error(GL_INVALID_VALUE);
8480 }
8481
8482 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008483 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8484 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008485 {
8486 return;
8487 }
8488
8489 switch(target)
8490 {
8491 case GL_TEXTURE_3D:
8492 {
8493 gl::Texture3D *texture = context->getTexture3D();
8494 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8495 format, imageSize, data);
8496 }
8497 break;
8498
8499 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008500 {
8501 gl::Texture2DArray *texture = context->getTexture2DArray();
8502 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8503 format, imageSize, data);
8504 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008505 break;
8506
8507 default:
8508 return gl::error(GL_INVALID_ENUM);
8509 }
8510 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008511 }
8512 catch(std::bad_alloc&)
8513 {
8514 return gl::error(GL_OUT_OF_MEMORY);
8515 }
8516}
8517
8518void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8519{
8520 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8521
8522 try
8523 {
8524 gl::Context *context = gl::getNonLostContext();
8525
8526 if (context)
8527 {
8528 if (context->getClientVersion() < 3)
8529 {
8530 return gl::error(GL_INVALID_OPERATION);
8531 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008532
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008533 UNIMPLEMENTED();
8534 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008535 }
8536 catch(std::bad_alloc&)
8537 {
8538 return gl::error(GL_OUT_OF_MEMORY);
8539 }
8540}
8541
8542void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8543{
8544 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8545
8546 try
8547 {
8548 gl::Context *context = gl::getNonLostContext();
8549
8550 if (context)
8551 {
8552 if (context->getClientVersion() < 3)
8553 {
8554 return gl::error(GL_INVALID_OPERATION);
8555 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008556
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008557 UNIMPLEMENTED();
8558 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008559 }
8560 catch(std::bad_alloc&)
8561 {
8562 return gl::error(GL_OUT_OF_MEMORY);
8563 }
8564}
8565
8566GLboolean __stdcall glIsQuery(GLuint id)
8567{
8568 EVENT("(GLuint id = %u)", id);
8569
8570 try
8571 {
8572 gl::Context *context = gl::getNonLostContext();
8573
8574 if (context)
8575 {
8576 if (context->getClientVersion() < 3)
8577 {
8578 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8579 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008580
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008581 UNIMPLEMENTED();
8582 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008583 }
8584 catch(std::bad_alloc&)
8585 {
8586 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8587 }
8588
8589 return GL_FALSE;
8590}
8591
8592void __stdcall glBeginQuery(GLenum target, GLuint id)
8593{
8594 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8595
8596 try
8597 {
8598 gl::Context *context = gl::getNonLostContext();
8599
8600 if (context)
8601 {
8602 if (context->getClientVersion() < 3)
8603 {
8604 return gl::error(GL_INVALID_OPERATION);
8605 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008606
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008607 UNIMPLEMENTED();
8608 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008609 }
8610 catch(std::bad_alloc&)
8611 {
8612 return gl::error(GL_OUT_OF_MEMORY);
8613 }
8614}
8615
8616void __stdcall glEndQuery(GLenum target)
8617{
8618 EVENT("(GLenum target = 0x%X)", target);
8619
8620 try
8621 {
8622 gl::Context *context = gl::getNonLostContext();
8623
8624 if (context)
8625 {
8626 if (context->getClientVersion() < 3)
8627 {
8628 return gl::error(GL_INVALID_OPERATION);
8629 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008630
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008631 UNIMPLEMENTED();
8632 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008633 }
8634 catch(std::bad_alloc&)
8635 {
8636 return gl::error(GL_OUT_OF_MEMORY);
8637 }
8638}
8639
8640void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
8641{
8642 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
8643
8644 try
8645 {
8646 gl::Context *context = gl::getNonLostContext();
8647
8648 if (context)
8649 {
8650 if (context->getClientVersion() < 3)
8651 {
8652 return gl::error(GL_INVALID_OPERATION);
8653 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008654
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008655 UNIMPLEMENTED();
8656 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008657 }
8658 catch(std::bad_alloc&)
8659 {
8660 return gl::error(GL_OUT_OF_MEMORY);
8661 }
8662}
8663
8664void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
8665{
8666 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
8667
8668 try
8669 {
8670 gl::Context *context = gl::getNonLostContext();
8671
8672 if (context)
8673 {
8674 if (context->getClientVersion() < 3)
8675 {
8676 return gl::error(GL_INVALID_OPERATION);
8677 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008678
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008679 UNIMPLEMENTED();
8680 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008681 }
8682 catch(std::bad_alloc&)
8683 {
8684 return gl::error(GL_OUT_OF_MEMORY);
8685 }
8686}
8687
8688GLboolean __stdcall glUnmapBuffer(GLenum target)
8689{
8690 EVENT("(GLenum target = 0x%X)", target);
8691
8692 try
8693 {
8694 gl::Context *context = gl::getNonLostContext();
8695
8696 if (context)
8697 {
8698 if (context->getClientVersion() < 3)
8699 {
8700 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8701 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008702
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008703 UNIMPLEMENTED();
8704 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008705 }
8706 catch(std::bad_alloc&)
8707 {
8708 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8709 }
8710
8711 return GL_FALSE;
8712}
8713
8714void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
8715{
8716 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8717
8718 try
8719 {
8720 gl::Context *context = gl::getNonLostContext();
8721
8722 if (context)
8723 {
8724 if (context->getClientVersion() < 3)
8725 {
8726 return gl::error(GL_INVALID_OPERATION);
8727 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008728
shannonwoods@chromium.org2d2190a2013-05-30 00:17:35 +00008729 UNIMPLEMENTED();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008730 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008731 }
8732 catch(std::bad_alloc&)
8733 {
8734 return gl::error(GL_OUT_OF_MEMORY);
8735 }
8736}
8737
8738void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8739{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008740 try
8741 {
8742 gl::Context *context = gl::getNonLostContext();
8743
8744 if (context)
8745 {
8746 if (context->getClientVersion() < 3)
8747 {
8748 return gl::error(GL_INVALID_OPERATION);
8749 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008750
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008751 glDrawBuffersEXT(n, bufs);
8752 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008753 }
8754 catch(std::bad_alloc&)
8755 {
8756 return gl::error(GL_OUT_OF_MEMORY);
8757 }
8758}
8759
8760void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8761{
8762 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8763 location, count, transpose, value);
8764
8765 try
8766 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008767 if (count < 0)
8768 {
8769 return gl::error(GL_INVALID_VALUE);
8770 }
8771
8772 if (location == -1)
8773 {
8774 return;
8775 }
8776
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008777 gl::Context *context = gl::getNonLostContext();
8778
8779 if (context)
8780 {
8781 if (context->getClientVersion() < 3)
8782 {
8783 return gl::error(GL_INVALID_OPERATION);
8784 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008785
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008786 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8787 if (!programBinary)
8788 {
8789 return gl::error(GL_INVALID_OPERATION);
8790 }
8791
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008792 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008793 {
8794 return gl::error(GL_INVALID_OPERATION);
8795 }
8796 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008797 }
8798 catch(std::bad_alloc&)
8799 {
8800 return gl::error(GL_OUT_OF_MEMORY);
8801 }
8802}
8803
8804void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8805{
8806 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8807 location, count, transpose, value);
8808
8809 try
8810 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008811 if (count < 0)
8812 {
8813 return gl::error(GL_INVALID_VALUE);
8814 }
8815
8816 if (location == -1)
8817 {
8818 return;
8819 }
8820
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008821 gl::Context *context = gl::getNonLostContext();
8822
8823 if (context)
8824 {
8825 if (context->getClientVersion() < 3)
8826 {
8827 return gl::error(GL_INVALID_OPERATION);
8828 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008829
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008830 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8831 if (!programBinary)
8832 {
8833 return gl::error(GL_INVALID_OPERATION);
8834 }
8835
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008836 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008837 {
8838 return gl::error(GL_INVALID_OPERATION);
8839 }
8840 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008841 }
8842 catch(std::bad_alloc&)
8843 {
8844 return gl::error(GL_OUT_OF_MEMORY);
8845 }
8846}
8847
8848void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8849{
8850 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8851 location, count, transpose, value);
8852
8853 try
8854 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008855 if (count < 0)
8856 {
8857 return gl::error(GL_INVALID_VALUE);
8858 }
8859
8860 if (location == -1)
8861 {
8862 return;
8863 }
8864
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008865 gl::Context *context = gl::getNonLostContext();
8866
8867 if (context)
8868 {
8869 if (context->getClientVersion() < 3)
8870 {
8871 return gl::error(GL_INVALID_OPERATION);
8872 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008873
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008874 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8875 if (!programBinary)
8876 {
8877 return gl::error(GL_INVALID_OPERATION);
8878 }
8879
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008880 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008881 {
8882 return gl::error(GL_INVALID_OPERATION);
8883 }
8884 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008885 }
8886 catch(std::bad_alloc&)
8887 {
8888 return gl::error(GL_OUT_OF_MEMORY);
8889 }
8890}
8891
8892void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8893{
8894 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8895 location, count, transpose, value);
8896
8897 try
8898 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008899 if (count < 0)
8900 {
8901 return gl::error(GL_INVALID_VALUE);
8902 }
8903
8904 if (location == -1)
8905 {
8906 return;
8907 }
8908
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008909 gl::Context *context = gl::getNonLostContext();
8910
8911 if (context)
8912 {
8913 if (context->getClientVersion() < 3)
8914 {
8915 return gl::error(GL_INVALID_OPERATION);
8916 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008917
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008918 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8919 if (!programBinary)
8920 {
8921 return gl::error(GL_INVALID_OPERATION);
8922 }
8923
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008924 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008925 {
8926 return gl::error(GL_INVALID_OPERATION);
8927 }
8928 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008929 }
8930 catch(std::bad_alloc&)
8931 {
8932 return gl::error(GL_OUT_OF_MEMORY);
8933 }
8934}
8935
8936void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8937{
8938 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8939 location, count, transpose, value);
8940
8941 try
8942 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008943 if (count < 0)
8944 {
8945 return gl::error(GL_INVALID_VALUE);
8946 }
8947
8948 if (location == -1)
8949 {
8950 return;
8951 }
8952
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008953 gl::Context *context = gl::getNonLostContext();
8954
8955 if (context)
8956 {
8957 if (context->getClientVersion() < 3)
8958 {
8959 return gl::error(GL_INVALID_OPERATION);
8960 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008961
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008962 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8963 if (!programBinary)
8964 {
8965 return gl::error(GL_INVALID_OPERATION);
8966 }
8967
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008968 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008969 {
8970 return gl::error(GL_INVALID_OPERATION);
8971 }
8972 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008973 }
8974 catch(std::bad_alloc&)
8975 {
8976 return gl::error(GL_OUT_OF_MEMORY);
8977 }
8978}
8979
8980void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8981{
8982 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8983 location, count, transpose, value);
8984
8985 try
8986 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008987 if (count < 0)
8988 {
8989 return gl::error(GL_INVALID_VALUE);
8990 }
8991
8992 if (location == -1)
8993 {
8994 return;
8995 }
8996
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008997 gl::Context *context = gl::getNonLostContext();
8998
8999 if (context)
9000 {
9001 if (context->getClientVersion() < 3)
9002 {
9003 return gl::error(GL_INVALID_OPERATION);
9004 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009005
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009006 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9007 if (!programBinary)
9008 {
9009 return gl::error(GL_INVALID_OPERATION);
9010 }
9011
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009012 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009013 {
9014 return gl::error(GL_INVALID_OPERATION);
9015 }
9016 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009017 }
9018 catch(std::bad_alloc&)
9019 {
9020 return gl::error(GL_OUT_OF_MEMORY);
9021 }
9022}
9023
9024void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
9025{
9026 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
9027 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
9028 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
9029
9030 try
9031 {
9032 gl::Context *context = gl::getNonLostContext();
9033
9034 if (context)
9035 {
9036 if (context->getClientVersion() < 3)
9037 {
9038 return gl::error(GL_INVALID_OPERATION);
9039 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009040
Geoff Lang758d5b22013-06-11 11:42:50 -04009041 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
9042 dstX0, dstY0, dstX1, dstY1, mask, filter,
9043 false))
9044 {
9045 return;
9046 }
9047
9048 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
9049 mask, filter);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009050 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009051 }
9052 catch(std::bad_alloc&)
9053 {
9054 return gl::error(GL_OUT_OF_MEMORY);
9055 }
9056}
9057
9058void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
9059{
9060 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
9061 target, samples, internalformat, width, height);
9062
9063 try
9064 {
9065 gl::Context *context = gl::getNonLostContext();
9066
9067 if (context)
9068 {
9069 if (context->getClientVersion() < 3)
9070 {
9071 return gl::error(GL_INVALID_OPERATION);
9072 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009073
Geoff Lang2e1dcd52013-05-29 10:34:08 -04009074 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
9075 width, height, false))
9076 {
9077 return;
9078 }
9079
9080 context->setRenderbufferStorage(width, height, internalformat, samples);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009081 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009082 }
9083 catch(std::bad_alloc&)
9084 {
9085 return gl::error(GL_OUT_OF_MEMORY);
9086 }
9087}
9088
9089void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
9090{
9091 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
9092 target, attachment, texture, level, layer);
9093
9094 try
9095 {
9096 gl::Context *context = gl::getNonLostContext();
9097
9098 if (context)
9099 {
9100 if (context->getClientVersion() < 3)
9101 {
9102 return gl::error(GL_INVALID_OPERATION);
9103 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009104
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009105 UNIMPLEMENTED();
9106 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009107 }
9108 catch(std::bad_alloc&)
9109 {
9110 return gl::error(GL_OUT_OF_MEMORY);
9111 }
9112}
9113
9114GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
9115{
9116 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
9117 target, offset, length, access);
9118
9119 try
9120 {
9121 gl::Context *context = gl::getNonLostContext();
9122
9123 if (context)
9124 {
9125 if (context->getClientVersion() < 3)
9126 {
9127 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
9128 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009129
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009130 UNIMPLEMENTED();
9131 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009132 }
9133 catch(std::bad_alloc&)
9134 {
9135 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
9136 }
9137
9138 return NULL;
9139}
9140
9141void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
9142{
9143 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
9144
9145 try
9146 {
9147 gl::Context *context = gl::getNonLostContext();
9148
9149 if (context)
9150 {
9151 if (context->getClientVersion() < 3)
9152 {
9153 return gl::error(GL_INVALID_OPERATION);
9154 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009155
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009156 UNIMPLEMENTED();
9157 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009158 }
9159 catch(std::bad_alloc&)
9160 {
9161 return gl::error(GL_OUT_OF_MEMORY);
9162 }
9163}
9164
9165void __stdcall glBindVertexArray(GLuint array)
9166{
9167 EVENT("(GLuint array = %u)", array);
9168
9169 try
9170 {
9171 gl::Context *context = gl::getNonLostContext();
9172
9173 if (context)
9174 {
9175 if (context->getClientVersion() < 3)
9176 {
9177 return gl::error(GL_INVALID_OPERATION);
9178 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009179
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009180 UNIMPLEMENTED();
9181 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009182 }
9183 catch(std::bad_alloc&)
9184 {
9185 return gl::error(GL_OUT_OF_MEMORY);
9186 }
9187}
9188
9189void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
9190{
9191 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
9192
9193 try
9194 {
9195 gl::Context *context = gl::getNonLostContext();
9196
9197 if (context)
9198 {
9199 if (context->getClientVersion() < 3)
9200 {
9201 return gl::error(GL_INVALID_OPERATION);
9202 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009203
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009204 UNIMPLEMENTED();
9205 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009206 }
9207 catch(std::bad_alloc&)
9208 {
9209 return gl::error(GL_OUT_OF_MEMORY);
9210 }
9211}
9212
9213void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
9214{
9215 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
9216
9217 try
9218 {
9219 gl::Context *context = gl::getNonLostContext();
9220
9221 if (context)
9222 {
9223 if (context->getClientVersion() < 3)
9224 {
9225 return gl::error(GL_INVALID_OPERATION);
9226 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009227
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009228 UNIMPLEMENTED();
9229 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009230 }
9231 catch(std::bad_alloc&)
9232 {
9233 return gl::error(GL_OUT_OF_MEMORY);
9234 }
9235}
9236
9237GLboolean __stdcall glIsVertexArray(GLuint array)
9238{
9239 EVENT("(GLuint array = %u)", array);
9240
9241 try
9242 {
9243 gl::Context *context = gl::getNonLostContext();
9244
9245 if (context)
9246 {
9247 if (context->getClientVersion() < 3)
9248 {
9249 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9250 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009251
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009252 UNIMPLEMENTED();
9253 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009254 }
9255 catch(std::bad_alloc&)
9256 {
9257 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9258 }
9259
9260 return GL_FALSE;
9261}
9262
9263void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
9264{
9265 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
9266 target, index, data);
9267
9268 try
9269 {
9270 gl::Context *context = gl::getNonLostContext();
9271
9272 if (context)
9273 {
9274 if (context->getClientVersion() < 3)
9275 {
9276 return gl::error(GL_INVALID_OPERATION);
9277 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009278
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009279 UNIMPLEMENTED();
9280 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009281 }
9282 catch(std::bad_alloc&)
9283 {
9284 return gl::error(GL_OUT_OF_MEMORY);
9285 }
9286}
9287
9288void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
9289{
9290 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
9291
9292 try
9293 {
9294 gl::Context *context = gl::getNonLostContext();
9295
9296 if (context)
9297 {
9298 if (context->getClientVersion() < 3)
9299 {
9300 return gl::error(GL_INVALID_OPERATION);
9301 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009302
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009303 UNIMPLEMENTED();
9304 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009305 }
9306 catch(std::bad_alloc&)
9307 {
9308 return gl::error(GL_OUT_OF_MEMORY);
9309 }
9310}
9311
9312void __stdcall glEndTransformFeedback(void)
9313{
9314 EVENT("(void)");
9315
9316 try
9317 {
9318 gl::Context *context = gl::getNonLostContext();
9319
9320 if (context)
9321 {
9322 if (context->getClientVersion() < 3)
9323 {
9324 return gl::error(GL_INVALID_OPERATION);
9325 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009326
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009327 UNIMPLEMENTED();
9328 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009329 }
9330 catch(std::bad_alloc&)
9331 {
9332 return gl::error(GL_OUT_OF_MEMORY);
9333 }
9334}
9335
9336void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
9337{
9338 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
9339 target, index, buffer, offset, size);
9340
9341 try
9342 {
9343 gl::Context *context = gl::getNonLostContext();
9344
9345 if (context)
9346 {
9347 if (context->getClientVersion() < 3)
9348 {
9349 return gl::error(GL_INVALID_OPERATION);
9350 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009351
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009352 switch (target)
9353 {
9354 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009355 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009356 {
9357 return gl::error(GL_INVALID_VALUE);
9358 }
9359 break;
9360
9361 case GL_UNIFORM_BUFFER:
9362 if (index >= context->getMaximumCombinedUniformBufferBindings())
9363 {
9364 return gl::error(GL_INVALID_VALUE);
9365 }
9366 break;
9367
9368 default:
9369 return gl::error(GL_INVALID_ENUM);
9370 }
9371
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009372 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009373 {
9374 return gl::error(GL_INVALID_VALUE);
9375 }
9376
9377 switch (target)
9378 {
9379 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009380
9381 // size and offset must be a multiple of 4
9382 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9383 {
9384 return gl::error(GL_INVALID_VALUE);
9385 }
9386
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009387 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9388 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009389 break;
9390
9391 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009392
9393 // it is an error to bind an offset not a multiple of the alignment
9394 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9395 {
9396 return gl::error(GL_INVALID_VALUE);
9397 }
9398
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009399 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9400 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009401 break;
9402
9403 default:
9404 UNREACHABLE();
9405 }
9406 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009407 }
9408 catch(std::bad_alloc&)
9409 {
9410 return gl::error(GL_OUT_OF_MEMORY);
9411 }
9412}
9413
9414void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9415{
9416 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9417 target, index, buffer);
9418
9419 try
9420 {
9421 gl::Context *context = gl::getNonLostContext();
9422
9423 if (context)
9424 {
9425 if (context->getClientVersion() < 3)
9426 {
9427 return gl::error(GL_INVALID_OPERATION);
9428 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009429
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009430 switch (target)
9431 {
9432 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009433 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009434 {
9435 return gl::error(GL_INVALID_VALUE);
9436 }
9437 break;
9438
9439 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009440 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009441 {
9442 return gl::error(GL_INVALID_VALUE);
9443 }
9444 break;
9445
9446 default:
9447 return gl::error(GL_INVALID_ENUM);
9448 }
9449
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009450 switch (target)
9451 {
9452 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009453 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009454 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009455 break;
9456
9457 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009458 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009459 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009460 break;
9461
9462 default:
9463 UNREACHABLE();
9464 }
9465 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009466 }
9467 catch(std::bad_alloc&)
9468 {
9469 return gl::error(GL_OUT_OF_MEMORY);
9470 }
9471}
9472
9473void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9474{
9475 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9476 program, count, varyings, bufferMode);
9477
9478 try
9479 {
9480 gl::Context *context = gl::getNonLostContext();
9481
9482 if (context)
9483 {
9484 if (context->getClientVersion() < 3)
9485 {
9486 return gl::error(GL_INVALID_OPERATION);
9487 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009488
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009489 UNIMPLEMENTED();
9490 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009491 }
9492 catch(std::bad_alloc&)
9493 {
9494 return gl::error(GL_OUT_OF_MEMORY);
9495 }
9496}
9497
9498void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9499{
9500 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9501 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9502 program, index, bufSize, length, size, type, name);
9503
9504 try
9505 {
9506 gl::Context *context = gl::getNonLostContext();
9507
9508 if (context)
9509 {
9510 if (context->getClientVersion() < 3)
9511 {
9512 return gl::error(GL_INVALID_OPERATION);
9513 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009514
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009515 UNIMPLEMENTED();
9516 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009517 }
9518 catch(std::bad_alloc&)
9519 {
9520 return gl::error(GL_OUT_OF_MEMORY);
9521 }
9522}
9523
9524void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9525{
9526 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9527 index, size, type, stride, pointer);
9528
9529 try
9530 {
9531 gl::Context *context = gl::getNonLostContext();
9532
9533 if (context)
9534 {
9535 if (context->getClientVersion() < 3)
9536 {
9537 return gl::error(GL_INVALID_OPERATION);
9538 }
9539 }
9540
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009541 if (index >= gl::MAX_VERTEX_ATTRIBS)
9542 {
9543 return gl::error(GL_INVALID_VALUE);
9544 }
9545
9546 if (size < 1 || size > 4)
9547 {
9548 return gl::error(GL_INVALID_VALUE);
9549 }
9550
9551 switch (type)
9552 {
9553 case GL_BYTE:
9554 case GL_UNSIGNED_BYTE:
9555 case GL_SHORT:
9556 case GL_UNSIGNED_SHORT:
9557 case GL_INT:
9558 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009559 case GL_INT_2_10_10_10_REV:
9560 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009561 break;
9562 default:
9563 return gl::error(GL_INVALID_ENUM);
9564 }
9565
9566 if (stride < 0)
9567 {
9568 return gl::error(GL_INVALID_VALUE);
9569 }
9570
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009571 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
9572 {
9573 return gl::error(GL_INVALID_OPERATION);
9574 }
9575
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009576 if (context)
9577 {
9578 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
9579 stride, pointer);
9580 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009581 }
9582 catch(std::bad_alloc&)
9583 {
9584 return gl::error(GL_OUT_OF_MEMORY);
9585 }
9586}
9587
9588void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
9589{
9590 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9591 index, pname, params);
9592
9593 try
9594 {
9595 gl::Context *context = gl::getNonLostContext();
9596
9597 if (context)
9598 {
9599 if (context->getClientVersion() < 3)
9600 {
9601 return gl::error(GL_INVALID_OPERATION);
9602 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009603
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009604 UNIMPLEMENTED();
9605 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009606 }
9607 catch(std::bad_alloc&)
9608 {
9609 return gl::error(GL_OUT_OF_MEMORY);
9610 }
9611}
9612
9613void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
9614{
9615 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
9616 index, pname, params);
9617
9618 try
9619 {
9620 gl::Context *context = gl::getNonLostContext();
9621
9622 if (context)
9623 {
9624 if (context->getClientVersion() < 3)
9625 {
9626 return gl::error(GL_INVALID_OPERATION);
9627 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009628
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009629 UNIMPLEMENTED();
9630 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009631 }
9632 catch(std::bad_alloc&)
9633 {
9634 return gl::error(GL_OUT_OF_MEMORY);
9635 }
9636}
9637
9638void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
9639{
9640 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
9641 index, x, y, z, w);
9642
9643 try
9644 {
9645 gl::Context *context = gl::getNonLostContext();
9646
9647 if (context)
9648 {
9649 if (context->getClientVersion() < 3)
9650 {
9651 return gl::error(GL_INVALID_OPERATION);
9652 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009653
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009654 if (index >= gl::MAX_VERTEX_ATTRIBS)
9655 {
9656 return gl::error(GL_INVALID_VALUE);
9657 }
9658
9659 GLint vals[4] = { x, y, z, w };
9660 context->setVertexAttribi(index, vals);
9661 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009662 }
9663 catch(std::bad_alloc&)
9664 {
9665 return gl::error(GL_OUT_OF_MEMORY);
9666 }
9667}
9668
9669void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
9670{
9671 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
9672 index, x, y, z, w);
9673
9674 try
9675 {
9676 gl::Context *context = gl::getNonLostContext();
9677
9678 if (context)
9679 {
9680 if (context->getClientVersion() < 3)
9681 {
9682 return gl::error(GL_INVALID_OPERATION);
9683 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009684
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009685 if (index >= gl::MAX_VERTEX_ATTRIBS)
9686 {
9687 return gl::error(GL_INVALID_VALUE);
9688 }
9689
9690 GLuint vals[4] = { x, y, z, w };
9691 context->setVertexAttribu(index, vals);
9692 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009693 }
9694 catch(std::bad_alloc&)
9695 {
9696 return gl::error(GL_OUT_OF_MEMORY);
9697 }
9698}
9699
9700void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
9701{
9702 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
9703
9704 try
9705 {
9706 gl::Context *context = gl::getNonLostContext();
9707
9708 if (context)
9709 {
9710 if (context->getClientVersion() < 3)
9711 {
9712 return gl::error(GL_INVALID_OPERATION);
9713 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009714
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009715 if (index >= gl::MAX_VERTEX_ATTRIBS)
9716 {
9717 return gl::error(GL_INVALID_VALUE);
9718 }
9719
9720 context->setVertexAttribi(index, v);
9721 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009722 }
9723 catch(std::bad_alloc&)
9724 {
9725 return gl::error(GL_OUT_OF_MEMORY);
9726 }
9727}
9728
9729void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
9730{
9731 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
9732
9733 try
9734 {
9735 gl::Context *context = gl::getNonLostContext();
9736
9737 if (context)
9738 {
9739 if (context->getClientVersion() < 3)
9740 {
9741 return gl::error(GL_INVALID_OPERATION);
9742 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009743
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009744 if (index >= gl::MAX_VERTEX_ATTRIBS)
9745 {
9746 return gl::error(GL_INVALID_VALUE);
9747 }
9748
9749 context->setVertexAttribu(index, v);
9750 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009751 }
9752 catch(std::bad_alloc&)
9753 {
9754 return gl::error(GL_OUT_OF_MEMORY);
9755 }
9756}
9757
9758void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
9759{
9760 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
9761 program, location, params);
9762
9763 try
9764 {
9765 gl::Context *context = gl::getNonLostContext();
9766
9767 if (context)
9768 {
9769 if (context->getClientVersion() < 3)
9770 {
9771 return gl::error(GL_INVALID_OPERATION);
9772 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009773
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00009774 if (program == 0)
9775 {
9776 return gl::error(GL_INVALID_VALUE);
9777 }
9778
9779 gl::Program *programObject = context->getProgram(program);
9780
9781 if (!programObject || !programObject->isLinked())
9782 {
9783 return gl::error(GL_INVALID_OPERATION);
9784 }
9785
9786 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9787 if (!programBinary)
9788 {
9789 return gl::error(GL_INVALID_OPERATION);
9790 }
9791
9792 if (!programBinary->getUniformuiv(location, NULL, params))
9793 {
9794 return gl::error(GL_INVALID_OPERATION);
9795 }
9796 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009797 }
9798 catch(std::bad_alloc&)
9799 {
9800 return gl::error(GL_OUT_OF_MEMORY);
9801 }
9802}
9803
9804GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
9805{
9806 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
9807 program, name);
9808
9809 try
9810 {
9811 gl::Context *context = gl::getNonLostContext();
9812
9813 if (context)
9814 {
9815 if (context->getClientVersion() < 3)
9816 {
Jamie Madilld1e78c92013-06-20 11:55:50 -04009817 return gl::error(GL_INVALID_OPERATION, -1);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009818 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009819
Jamie Madilld1e78c92013-06-20 11:55:50 -04009820 if (program == 0)
9821 {
9822 return gl::error(GL_INVALID_VALUE, -1);
9823 }
9824
9825 gl::Program *programObject = context->getProgram(program);
9826
9827 if (!programObject || !programObject->isLinked())
9828 {
9829 return gl::error(GL_INVALID_OPERATION, -1);
9830 }
9831
9832 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9833 if (!programBinary)
9834 {
9835 return gl::error(GL_INVALID_OPERATION, -1);
9836 }
9837
9838 return programBinary->getFragDataLocation(name);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009839 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009840 }
9841 catch(std::bad_alloc&)
9842 {
9843 return gl::error(GL_OUT_OF_MEMORY, 0);
9844 }
9845
9846 return 0;
9847}
9848
9849void __stdcall glUniform1ui(GLint location, GLuint v0)
9850{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009851 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009852}
9853
9854void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
9855{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009856 const GLuint xy[] = { v0, v1 };
9857 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009858}
9859
9860void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
9861{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009862 const GLuint xyz[] = { v0, v1, v2 };
9863 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009864}
9865
9866void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
9867{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009868 const GLuint xyzw[] = { v0, v1, v2, v3 };
9869 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009870}
9871
9872void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
9873{
9874 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9875 location, count, value);
9876
9877 try
9878 {
9879 gl::Context *context = gl::getNonLostContext();
9880
9881 if (context)
9882 {
9883 if (context->getClientVersion() < 3)
9884 {
9885 return gl::error(GL_INVALID_OPERATION);
9886 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009887
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009888 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9889 if (!programBinary)
9890 {
9891 return gl::error(GL_INVALID_OPERATION);
9892 }
9893
9894 if (!programBinary->setUniform1uiv(location, count, value))
9895 {
9896 return gl::error(GL_INVALID_OPERATION);
9897 }
9898 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009899 }
9900 catch(std::bad_alloc&)
9901 {
9902 return gl::error(GL_OUT_OF_MEMORY);
9903 }
9904}
9905
9906void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
9907{
9908 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9909 location, count, value);
9910
9911 try
9912 {
9913 gl::Context *context = gl::getNonLostContext();
9914
9915 if (context)
9916 {
9917 if (context->getClientVersion() < 3)
9918 {
9919 return gl::error(GL_INVALID_OPERATION);
9920 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009921
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009922 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9923 if (!programBinary)
9924 {
9925 return gl::error(GL_INVALID_OPERATION);
9926 }
9927
9928 if (!programBinary->setUniform2uiv(location, count, value))
9929 {
9930 return gl::error(GL_INVALID_OPERATION);
9931 }
9932 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009933 }
9934 catch(std::bad_alloc&)
9935 {
9936 return gl::error(GL_OUT_OF_MEMORY);
9937 }
9938}
9939
9940void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
9941{
9942 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
9943 location, count, value);
9944
9945 try
9946 {
9947 gl::Context *context = gl::getNonLostContext();
9948
9949 if (context)
9950 {
9951 if (context->getClientVersion() < 3)
9952 {
9953 return gl::error(GL_INVALID_OPERATION);
9954 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009955
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009956 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9957 if (!programBinary)
9958 {
9959 return gl::error(GL_INVALID_OPERATION);
9960 }
9961
9962 if (!programBinary->setUniform3uiv(location, count, value))
9963 {
9964 return gl::error(GL_INVALID_OPERATION);
9965 }
9966 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009967 }
9968 catch(std::bad_alloc&)
9969 {
9970 return gl::error(GL_OUT_OF_MEMORY);
9971 }
9972}
9973
9974void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
9975{
9976 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9977 location, count, value);
9978
9979 try
9980 {
9981 gl::Context *context = gl::getNonLostContext();
9982
9983 if (context)
9984 {
9985 if (context->getClientVersion() < 3)
9986 {
9987 return gl::error(GL_INVALID_OPERATION);
9988 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009989
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009990 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9991 if (!programBinary)
9992 {
9993 return gl::error(GL_INVALID_OPERATION);
9994 }
9995
9996 if (!programBinary->setUniform4uiv(location, count, value))
9997 {
9998 return gl::error(GL_INVALID_OPERATION);
9999 }
10000 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010001 }
10002 catch(std::bad_alloc&)
10003 {
10004 return gl::error(GL_OUT_OF_MEMORY);
10005 }
10006}
10007
10008void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
10009{
10010 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
10011 buffer, drawbuffer, value);
10012
10013 try
10014 {
10015 gl::Context *context = gl::getNonLostContext();
10016
10017 if (context)
10018 {
10019 if (context->getClientVersion() < 3)
10020 {
10021 return gl::error(GL_INVALID_OPERATION);
10022 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010023
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010024 UNIMPLEMENTED();
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 glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
10034{
10035 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* 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
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010049 UNIMPLEMENTED();
10050 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010051 }
10052 catch(std::bad_alloc&)
10053 {
10054 return gl::error(GL_OUT_OF_MEMORY);
10055 }
10056}
10057
10058void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
10059{
10060 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
10061 buffer, drawbuffer, value);
10062
10063 try
10064 {
10065 gl::Context *context = gl::getNonLostContext();
10066
10067 if (context)
10068 {
10069 if (context->getClientVersion() < 3)
10070 {
10071 return gl::error(GL_INVALID_OPERATION);
10072 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010073
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010074 UNIMPLEMENTED();
10075 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010076 }
10077 catch(std::bad_alloc&)
10078 {
10079 return gl::error(GL_OUT_OF_MEMORY);
10080 }
10081}
10082
10083void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
10084{
10085 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
10086 buffer, drawbuffer, depth, stencil);
10087
10088 try
10089 {
10090 gl::Context *context = gl::getNonLostContext();
10091
10092 if (context)
10093 {
10094 if (context->getClientVersion() < 3)
10095 {
10096 return gl::error(GL_INVALID_OPERATION);
10097 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010098
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010099 UNIMPLEMENTED();
10100 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010101 }
10102 catch(std::bad_alloc&)
10103 {
10104 return gl::error(GL_OUT_OF_MEMORY);
10105 }
10106}
10107
10108const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
10109{
10110 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
10111
10112 try
10113 {
10114 gl::Context *context = gl::getNonLostContext();
10115
10116 if (context)
10117 {
10118 if (context->getClientVersion() < 3)
10119 {
10120 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
10121 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010122
shannonwoods@chromium.org302df742013-05-30 00:05:54 +000010123 if (name != GL_EXTENSIONS)
10124 {
10125 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
10126 }
10127
10128 if (index >= context->getNumExtensions())
10129 {
10130 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
10131 }
10132
10133 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
10134 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010135 }
10136 catch(std::bad_alloc&)
10137 {
10138 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
10139 }
10140
10141 return NULL;
10142}
10143
10144void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
10145{
10146 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
10147 readTarget, writeTarget, readOffset, writeOffset, size);
10148
10149 try
10150 {
10151 gl::Context *context = gl::getNonLostContext();
10152
10153 if (context)
10154 {
10155 if (context->getClientVersion() < 3)
10156 {
10157 return gl::error(GL_INVALID_OPERATION);
10158 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010159
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010160 gl::Buffer *readBuffer = NULL;
10161 switch (readTarget)
10162 {
10163 case GL_ARRAY_BUFFER:
10164 readBuffer = context->getArrayBuffer();
10165 break;
10166 case GL_COPY_READ_BUFFER:
10167 readBuffer = context->getCopyReadBuffer();
10168 break;
10169 case GL_COPY_WRITE_BUFFER:
10170 readBuffer = context->getCopyWriteBuffer();
10171 break;
10172 case GL_ELEMENT_ARRAY_BUFFER:
10173 readBuffer = context->getElementArrayBuffer();
10174 break;
10175 case GL_PIXEL_PACK_BUFFER:
10176 readBuffer = context->getPixelPackBuffer();
10177 break;
10178 case GL_PIXEL_UNPACK_BUFFER:
10179 readBuffer = context->getPixelUnpackBuffer();
10180 break;
10181 case GL_TRANSFORM_FEEDBACK_BUFFER:
10182 readBuffer = context->getGenericTransformFeedbackBuffer();
10183 break;
10184 case GL_UNIFORM_BUFFER:
10185 readBuffer = context->getGenericUniformBuffer();
10186 break;
10187 default:
10188 return gl::error(GL_INVALID_ENUM);
10189 }
10190
10191 gl::Buffer *writeBuffer = NULL;
10192 switch (writeTarget)
10193 {
10194 case GL_ARRAY_BUFFER:
10195 writeBuffer = context->getArrayBuffer();
10196 break;
10197 case GL_COPY_READ_BUFFER:
10198 writeBuffer = context->getCopyReadBuffer();
10199 break;
10200 case GL_COPY_WRITE_BUFFER:
10201 writeBuffer = context->getCopyWriteBuffer();
10202 break;
10203 case GL_ELEMENT_ARRAY_BUFFER:
10204 writeBuffer = context->getElementArrayBuffer();
10205 break;
10206 case GL_PIXEL_PACK_BUFFER:
10207 writeBuffer = context->getPixelPackBuffer();
10208 break;
10209 case GL_PIXEL_UNPACK_BUFFER:
10210 writeBuffer = context->getPixelUnpackBuffer();
10211 break;
10212 case GL_TRANSFORM_FEEDBACK_BUFFER:
10213 writeBuffer = context->getGenericTransformFeedbackBuffer();
10214 break;
10215 case GL_UNIFORM_BUFFER:
10216 writeBuffer = context->getGenericUniformBuffer();
10217 break;
10218 default:
10219 return gl::error(GL_INVALID_ENUM);
10220 }
10221
10222 if (!readBuffer || !writeBuffer)
10223 {
10224 return gl::error(GL_INVALID_OPERATION);
10225 }
10226
10227 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
10228 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
10229 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
10230 {
10231 return gl::error(GL_INVALID_VALUE);
10232 }
10233
10234 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
10235 {
10236 return gl::error(GL_INVALID_VALUE);
10237 }
10238
10239 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
10240
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +000010241 // if size is zero, the copy is a successful no-op
10242 if (size > 0)
10243 {
10244 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
10245 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010246 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010247 }
10248 catch(std::bad_alloc&)
10249 {
10250 return gl::error(GL_OUT_OF_MEMORY);
10251 }
10252}
10253
10254void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
10255{
10256 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
10257 program, uniformCount, uniformNames, uniformIndices);
10258
10259 try
10260 {
10261 gl::Context *context = gl::getNonLostContext();
10262
10263 if (context)
10264 {
10265 if (context->getClientVersion() < 3)
10266 {
10267 return gl::error(GL_INVALID_OPERATION);
10268 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010269
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +000010270 if (uniformCount < 0)
10271 {
10272 return gl::error(GL_INVALID_VALUE);
10273 }
10274
10275 gl::Program *programObject = context->getProgram(program);
10276
10277 if (!programObject)
10278 {
10279 if (context->getShader(program))
10280 {
10281 return gl::error(GL_INVALID_OPERATION);
10282 }
10283 else
10284 {
10285 return gl::error(GL_INVALID_VALUE);
10286 }
10287 }
10288
10289 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10290 if (!programObject->isLinked() || !programBinary)
10291 {
10292 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10293 {
10294 uniformIndices[uniformId] = GL_INVALID_INDEX;
10295 }
10296 }
10297 else
10298 {
10299 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10300 {
10301 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
10302 }
10303 }
10304 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010305 }
10306 catch(std::bad_alloc&)
10307 {
10308 return gl::error(GL_OUT_OF_MEMORY);
10309 }
10310}
10311
10312void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
10313{
10314 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10315 program, uniformCount, uniformIndices, pname, params);
10316
10317 try
10318 {
10319 gl::Context *context = gl::getNonLostContext();
10320
10321 if (context)
10322 {
10323 if (context->getClientVersion() < 3)
10324 {
10325 return gl::error(GL_INVALID_OPERATION);
10326 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010327
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +000010328 if (uniformCount < 0)
10329 {
10330 return gl::error(GL_INVALID_VALUE);
10331 }
10332
10333 gl::Program *programObject = context->getProgram(program);
10334
10335 if (!programObject)
10336 {
10337 if (context->getShader(program))
10338 {
10339 return gl::error(GL_INVALID_OPERATION);
10340 }
10341 else
10342 {
10343 return gl::error(GL_INVALID_VALUE);
10344 }
10345 }
10346
10347 switch (pname)
10348 {
10349 case GL_UNIFORM_TYPE:
10350 case GL_UNIFORM_SIZE:
10351 case GL_UNIFORM_NAME_LENGTH:
10352 case GL_UNIFORM_BLOCK_INDEX:
10353 case GL_UNIFORM_OFFSET:
10354 case GL_UNIFORM_ARRAY_STRIDE:
10355 case GL_UNIFORM_MATRIX_STRIDE:
10356 case GL_UNIFORM_IS_ROW_MAJOR:
10357 break;
10358 default:
10359 return gl::error(GL_INVALID_ENUM);
10360 }
10361
10362 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10363
10364 if (!programBinary && uniformCount > 0)
10365 {
10366 return gl::error(GL_INVALID_VALUE);
10367 }
10368
10369 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10370 {
10371 const GLuint index = uniformIndices[uniformId];
10372
10373 if (index >= (GLuint)programBinary->getActiveUniformCount())
10374 {
10375 return gl::error(GL_INVALID_VALUE);
10376 }
10377 }
10378
10379 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10380 {
10381 const GLuint index = uniformIndices[uniformId];
10382 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10383 }
10384 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010385 }
10386 catch(std::bad_alloc&)
10387 {
10388 return gl::error(GL_OUT_OF_MEMORY);
10389 }
10390}
10391
10392GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10393{
10394 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10395
10396 try
10397 {
10398 gl::Context *context = gl::getNonLostContext();
10399
10400 if (context)
10401 {
10402 if (context->getClientVersion() < 3)
10403 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010404 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010405 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010406
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010407 gl::Program *programObject = context->getProgram(program);
10408
10409 if (!programObject)
10410 {
10411 if (context->getShader(program))
10412 {
10413 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10414 }
10415 else
10416 {
10417 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10418 }
10419 }
10420
10421 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10422 if (!programBinary)
10423 {
10424 return GL_INVALID_INDEX;
10425 }
10426
10427 return programBinary->getUniformBlockIndex(uniformBlockName);
10428 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010429 }
10430 catch(std::bad_alloc&)
10431 {
10432 return gl::error(GL_OUT_OF_MEMORY, 0);
10433 }
10434
10435 return 0;
10436}
10437
10438void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10439{
10440 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10441 program, uniformBlockIndex, pname, params);
10442
10443 try
10444 {
10445 gl::Context *context = gl::getNonLostContext();
10446
10447 if (context)
10448 {
10449 if (context->getClientVersion() < 3)
10450 {
10451 return gl::error(GL_INVALID_OPERATION);
10452 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010453 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010454
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010455 if (!programObject)
10456 {
10457 if (context->getShader(program))
10458 {
10459 return gl::error(GL_INVALID_OPERATION);
10460 }
10461 else
10462 {
10463 return gl::error(GL_INVALID_VALUE);
10464 }
10465 }
10466
10467 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10468
10469 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10470 {
10471 return gl::error(GL_INVALID_VALUE);
10472 }
10473
10474 switch (pname)
10475 {
10476 case GL_UNIFORM_BLOCK_BINDING:
10477 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10478 break;
10479
10480 case GL_UNIFORM_BLOCK_DATA_SIZE:
10481 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10482 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10483 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10484 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10485 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10486 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10487 break;
10488
10489 default:
10490 return gl::error(GL_INVALID_ENUM);
10491 }
10492 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010493 }
10494 catch(std::bad_alloc&)
10495 {
10496 return gl::error(GL_OUT_OF_MEMORY);
10497 }
10498}
10499
10500void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
10501{
10502 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
10503 program, uniformBlockIndex, bufSize, length, uniformBlockName);
10504
10505 try
10506 {
10507 gl::Context *context = gl::getNonLostContext();
10508
10509 if (context)
10510 {
10511 if (context->getClientVersion() < 3)
10512 {
10513 return gl::error(GL_INVALID_OPERATION);
10514 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010515
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000010516 gl::Program *programObject = context->getProgram(program);
10517
10518 if (!programObject)
10519 {
10520 if (context->getShader(program))
10521 {
10522 return gl::error(GL_INVALID_OPERATION);
10523 }
10524 else
10525 {
10526 return gl::error(GL_INVALID_VALUE);
10527 }
10528 }
10529
10530 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10531
10532 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10533 {
10534 return gl::error(GL_INVALID_VALUE);
10535 }
10536
10537 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
10538 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010539 }
10540 catch(std::bad_alloc&)
10541 {
10542 return gl::error(GL_OUT_OF_MEMORY);
10543 }
10544}
10545
10546void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
10547{
10548 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
10549 program, uniformBlockIndex, uniformBlockBinding);
10550
10551 try
10552 {
10553 gl::Context *context = gl::getNonLostContext();
10554
10555 if (context)
10556 {
10557 if (context->getClientVersion() < 3)
10558 {
10559 return gl::error(GL_INVALID_OPERATION);
10560 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010561
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000010562 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
10563 {
10564 return gl::error(GL_INVALID_VALUE);
10565 }
10566
10567 gl::Program *programObject = context->getProgram(program);
10568
10569 if (!programObject)
10570 {
10571 if (context->getShader(program))
10572 {
10573 return gl::error(GL_INVALID_OPERATION);
10574 }
10575 else
10576 {
10577 return gl::error(GL_INVALID_VALUE);
10578 }
10579 }
10580
10581 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10582
10583 // if never linked, there won't be any uniform blocks
10584 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10585 {
10586 return gl::error(GL_INVALID_VALUE);
10587 }
10588
10589 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
10590 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010591 }
10592 catch(std::bad_alloc&)
10593 {
10594 return gl::error(GL_OUT_OF_MEMORY);
10595 }
10596}
10597
10598void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
10599{
10600 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
10601 mode, first, count, instanceCount);
10602
10603 try
10604 {
10605 gl::Context *context = gl::getNonLostContext();
10606
10607 if (context)
10608 {
10609 if (context->getClientVersion() < 3)
10610 {
10611 return gl::error(GL_INVALID_OPERATION);
10612 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010613
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010614 UNIMPLEMENTED();
10615 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010616 }
10617 catch(std::bad_alloc&)
10618 {
10619 return gl::error(GL_OUT_OF_MEMORY);
10620 }
10621}
10622
10623void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
10624{
10625 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
10626 mode, count, type, indices, instanceCount);
10627
10628 try
10629 {
10630 gl::Context *context = gl::getNonLostContext();
10631
10632 if (context)
10633 {
10634 if (context->getClientVersion() < 3)
10635 {
10636 return gl::error(GL_INVALID_OPERATION);
10637 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010638
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010639 UNIMPLEMENTED();
10640 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010641 }
10642 catch(std::bad_alloc&)
10643 {
10644 return gl::error(GL_OUT_OF_MEMORY);
10645 }
10646}
10647
10648GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
10649{
10650 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
10651
10652 try
10653 {
10654 gl::Context *context = gl::getNonLostContext();
10655
10656 if (context)
10657 {
10658 if (context->getClientVersion() < 3)
10659 {
10660 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(NULL));
10661 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010662
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010663 UNIMPLEMENTED();
10664 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010665 }
10666 catch(std::bad_alloc&)
10667 {
10668 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
10669 }
10670
10671 return NULL;
10672}
10673
10674GLboolean __stdcall glIsSync(GLsync sync)
10675{
10676 EVENT("(GLsync sync = 0x%0.8p)", sync);
10677
10678 try
10679 {
10680 gl::Context *context = gl::getNonLostContext();
10681
10682 if (context)
10683 {
10684 if (context->getClientVersion() < 3)
10685 {
10686 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10687 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010688
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010689 UNIMPLEMENTED();
10690 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010691 }
10692 catch(std::bad_alloc&)
10693 {
10694 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10695 }
10696
10697 return GL_FALSE;
10698}
10699
10700void __stdcall glDeleteSync(GLsync sync)
10701{
10702 EVENT("(GLsync sync = 0x%0.8p)", sync);
10703
10704 try
10705 {
10706 gl::Context *context = gl::getNonLostContext();
10707
10708 if (context)
10709 {
10710 if (context->getClientVersion() < 3)
10711 {
10712 return gl::error(GL_INVALID_OPERATION);
10713 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010714
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010715 UNIMPLEMENTED();
10716 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010717 }
10718 catch(std::bad_alloc&)
10719 {
10720 return gl::error(GL_OUT_OF_MEMORY);
10721 }
10722}
10723
10724GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10725{
10726 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10727 sync, flags, timeout);
10728
10729 try
10730 {
10731 gl::Context *context = gl::getNonLostContext();
10732
10733 if (context)
10734 {
10735 if (context->getClientVersion() < 3)
10736 {
10737 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10738 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010739
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010740 UNIMPLEMENTED();
10741 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010742 }
10743 catch(std::bad_alloc&)
10744 {
10745 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10746 }
10747
10748 return GL_FALSE;
10749}
10750
10751void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10752{
10753 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10754 sync, flags, timeout);
10755
10756 try
10757 {
10758 gl::Context *context = gl::getNonLostContext();
10759
10760 if (context)
10761 {
10762 if (context->getClientVersion() < 3)
10763 {
10764 return gl::error(GL_INVALID_OPERATION);
10765 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010766
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010767 UNIMPLEMENTED();
10768 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010769 }
10770 catch(std::bad_alloc&)
10771 {
10772 return gl::error(GL_OUT_OF_MEMORY);
10773 }
10774}
10775
10776void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
10777{
10778 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10779 pname, params);
10780
10781 try
10782 {
10783 gl::Context *context = gl::getNonLostContext();
10784
10785 if (context)
10786 {
10787 if (context->getClientVersion() < 3)
10788 {
10789 return gl::error(GL_INVALID_OPERATION);
10790 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010791
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010792 UNIMPLEMENTED();
10793 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010794 }
10795 catch(std::bad_alloc&)
10796 {
10797 return gl::error(GL_OUT_OF_MEMORY);
10798 }
10799}
10800
10801void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
10802{
10803 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
10804 sync, pname, bufSize, length, values);
10805
10806 try
10807 {
10808 gl::Context *context = gl::getNonLostContext();
10809
10810 if (context)
10811 {
10812 if (context->getClientVersion() < 3)
10813 {
10814 return gl::error(GL_INVALID_OPERATION);
10815 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010816
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010817 UNIMPLEMENTED();
10818 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010819 }
10820 catch(std::bad_alloc&)
10821 {
10822 return gl::error(GL_OUT_OF_MEMORY);
10823 }
10824}
10825
10826void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
10827{
10828 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
10829 target, index, data);
10830
10831 try
10832 {
10833 gl::Context *context = gl::getNonLostContext();
10834
10835 if (context)
10836 {
10837 if (context->getClientVersion() < 3)
10838 {
10839 return gl::error(GL_INVALID_OPERATION);
10840 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010841
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010842 UNIMPLEMENTED();
10843 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010844 }
10845 catch(std::bad_alloc&)
10846 {
10847 return gl::error(GL_OUT_OF_MEMORY);
10848 }
10849}
10850
10851void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
10852{
10853 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10854 target, pname, params);
10855
10856 try
10857 {
10858 gl::Context *context = gl::getNonLostContext();
10859
10860 if (context)
10861 {
10862 if (context->getClientVersion() < 3)
10863 {
10864 return gl::error(GL_INVALID_OPERATION);
10865 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010866
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010867 UNIMPLEMENTED();
10868 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010869 }
10870 catch(std::bad_alloc&)
10871 {
10872 return gl::error(GL_OUT_OF_MEMORY);
10873 }
10874}
10875
10876void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
10877{
10878 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
10879
10880 try
10881 {
10882 gl::Context *context = gl::getNonLostContext();
10883
10884 if (context)
10885 {
10886 if (context->getClientVersion() < 3)
10887 {
10888 return gl::error(GL_INVALID_OPERATION);
10889 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010890
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010891 UNIMPLEMENTED();
10892 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010893 }
10894 catch(std::bad_alloc&)
10895 {
10896 return gl::error(GL_OUT_OF_MEMORY);
10897 }
10898}
10899
10900void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
10901{
10902 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
10903
10904 try
10905 {
10906 gl::Context *context = gl::getNonLostContext();
10907
10908 if (context)
10909 {
10910 if (context->getClientVersion() < 3)
10911 {
10912 return gl::error(GL_INVALID_OPERATION);
10913 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010914
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010915 UNIMPLEMENTED();
10916 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010917 }
10918 catch(std::bad_alloc&)
10919 {
10920 return gl::error(GL_OUT_OF_MEMORY);
10921 }
10922}
10923
10924GLboolean __stdcall glIsSampler(GLuint sampler)
10925{
10926 EVENT("(GLuint sampler = %u)", sampler);
10927
10928 try
10929 {
10930 gl::Context *context = gl::getNonLostContext();
10931
10932 if (context)
10933 {
10934 if (context->getClientVersion() < 3)
10935 {
10936 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10937 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010938
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010939 UNIMPLEMENTED();
10940 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010941 }
10942 catch(std::bad_alloc&)
10943 {
10944 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10945 }
10946
10947 return GL_FALSE;
10948}
10949
10950void __stdcall glBindSampler(GLuint unit, GLuint sampler)
10951{
10952 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
10953
10954 try
10955 {
10956 gl::Context *context = gl::getNonLostContext();
10957
10958 if (context)
10959 {
10960 if (context->getClientVersion() < 3)
10961 {
10962 return gl::error(GL_INVALID_OPERATION);
10963 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010964
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010965 UNIMPLEMENTED();
10966 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010967 }
10968 catch(std::bad_alloc&)
10969 {
10970 return gl::error(GL_OUT_OF_MEMORY);
10971 }
10972}
10973
10974void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
10975{
10976 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
10977
10978 try
10979 {
10980 gl::Context *context = gl::getNonLostContext();
10981
10982 if (context)
10983 {
10984 if (context->getClientVersion() < 3)
10985 {
10986 return gl::error(GL_INVALID_OPERATION);
10987 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010988
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010989 UNIMPLEMENTED();
10990 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010991 }
10992 catch(std::bad_alloc&)
10993 {
10994 return gl::error(GL_OUT_OF_MEMORY);
10995 }
10996}
10997
10998void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
10999{
11000 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLint* param = 0x%0.8p)",
11001 sampler, pname, param);
11002
11003 try
11004 {
11005 gl::Context *context = gl::getNonLostContext();
11006
11007 if (context)
11008 {
11009 if (context->getClientVersion() < 3)
11010 {
11011 return gl::error(GL_INVALID_OPERATION);
11012 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011013
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011014 UNIMPLEMENTED();
11015 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011016 }
11017 catch(std::bad_alloc&)
11018 {
11019 return gl::error(GL_OUT_OF_MEMORY);
11020 }
11021}
11022
11023void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
11024{
11025 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
11026
11027 try
11028 {
11029 gl::Context *context = gl::getNonLostContext();
11030
11031 if (context)
11032 {
11033 if (context->getClientVersion() < 3)
11034 {
11035 return gl::error(GL_INVALID_OPERATION);
11036 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011037
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011038 UNIMPLEMENTED();
11039 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011040 }
11041 catch(std::bad_alloc&)
11042 {
11043 return gl::error(GL_OUT_OF_MEMORY);
11044 }
11045}
11046
11047void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
11048{
11049 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLfloat* param = 0x%0.8p)", sampler, pname, param);
11050
11051 try
11052 {
11053 gl::Context *context = gl::getNonLostContext();
11054
11055 if (context)
11056 {
11057 if (context->getClientVersion() < 3)
11058 {
11059 return gl::error(GL_INVALID_OPERATION);
11060 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011061
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011062 UNIMPLEMENTED();
11063 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011064 }
11065 catch(std::bad_alloc&)
11066 {
11067 return gl::error(GL_OUT_OF_MEMORY);
11068 }
11069}
11070
11071void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
11072{
11073 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
11074
11075 try
11076 {
11077 gl::Context *context = gl::getNonLostContext();
11078
11079 if (context)
11080 {
11081 if (context->getClientVersion() < 3)
11082 {
11083 return gl::error(GL_INVALID_OPERATION);
11084 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011085
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011086 UNIMPLEMENTED();
11087 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011088 }
11089 catch(std::bad_alloc&)
11090 {
11091 return gl::error(GL_OUT_OF_MEMORY);
11092 }
11093}
11094
11095void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
11096{
11097 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
11098
11099 try
11100 {
11101 gl::Context *context = gl::getNonLostContext();
11102
11103 if (context)
11104 {
11105 if (context->getClientVersion() < 3)
11106 {
11107 return gl::error(GL_INVALID_OPERATION);
11108 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011109
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 glVertexAttribDivisor(GLuint index, GLuint divisor)
11120{
11121 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
11122
11123 try
11124 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011125 if (index >= gl::MAX_VERTEX_ATTRIBS)
11126 {
11127 return gl::error(GL_INVALID_VALUE);
11128 }
11129
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011130 gl::Context *context = gl::getNonLostContext();
11131
11132 if (context)
11133 {
11134 if (context->getClientVersion() < 3)
11135 {
11136 return gl::error(GL_INVALID_OPERATION);
11137 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011138
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011139 context->setVertexAttribDivisor(index, divisor);
11140 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011141 }
11142 catch(std::bad_alloc&)
11143 {
11144 return gl::error(GL_OUT_OF_MEMORY);
11145 }
11146}
11147
11148void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
11149{
11150 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
11151
11152 try
11153 {
11154 gl::Context *context = gl::getNonLostContext();
11155
11156 if (context)
11157 {
11158 if (context->getClientVersion() < 3)
11159 {
11160 return gl::error(GL_INVALID_OPERATION);
11161 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011162
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011163 UNIMPLEMENTED();
11164 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011165 }
11166 catch(std::bad_alloc&)
11167 {
11168 return gl::error(GL_OUT_OF_MEMORY);
11169 }
11170}
11171
11172void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
11173{
11174 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
11175
11176 try
11177 {
11178 gl::Context *context = gl::getNonLostContext();
11179
11180 if (context)
11181 {
11182 if (context->getClientVersion() < 3)
11183 {
11184 return gl::error(GL_INVALID_OPERATION);
11185 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011186
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011187 UNIMPLEMENTED();
11188 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011189 }
11190 catch(std::bad_alloc&)
11191 {
11192 return gl::error(GL_OUT_OF_MEMORY);
11193 }
11194}
11195
11196void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
11197{
11198 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
11199
11200 try
11201 {
11202 gl::Context *context = gl::getNonLostContext();
11203
11204 if (context)
11205 {
11206 if (context->getClientVersion() < 3)
11207 {
11208 return gl::error(GL_INVALID_OPERATION);
11209 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011210
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011211 UNIMPLEMENTED();
11212 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011213 }
11214 catch(std::bad_alloc&)
11215 {
11216 return gl::error(GL_OUT_OF_MEMORY);
11217 }
11218}
11219
11220GLboolean __stdcall glIsTransformFeedback(GLuint id)
11221{
11222 EVENT("(GLuint id = %u)", id);
11223
11224 try
11225 {
11226 gl::Context *context = gl::getNonLostContext();
11227
11228 if (context)
11229 {
11230 if (context->getClientVersion() < 3)
11231 {
11232 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11233 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011234
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011235 UNIMPLEMENTED();
11236 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011237 }
11238 catch(std::bad_alloc&)
11239 {
11240 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11241 }
11242
11243 return GL_FALSE;
11244}
11245
11246void __stdcall glPauseTransformFeedback(void)
11247{
11248 EVENT("(void)");
11249
11250 try
11251 {
11252 gl::Context *context = gl::getNonLostContext();
11253
11254 if (context)
11255 {
11256 if (context->getClientVersion() < 3)
11257 {
11258 return gl::error(GL_INVALID_OPERATION);
11259 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011260
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011261 UNIMPLEMENTED();
11262 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011263 }
11264 catch(std::bad_alloc&)
11265 {
11266 return gl::error(GL_OUT_OF_MEMORY);
11267 }
11268}
11269
11270void __stdcall glResumeTransformFeedback(void)
11271{
11272 EVENT("(void)");
11273
11274 try
11275 {
11276 gl::Context *context = gl::getNonLostContext();
11277
11278 if (context)
11279 {
11280 if (context->getClientVersion() < 3)
11281 {
11282 return gl::error(GL_INVALID_OPERATION);
11283 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011284
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011285 UNIMPLEMENTED();
11286 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011287 }
11288 catch(std::bad_alloc&)
11289 {
11290 return gl::error(GL_OUT_OF_MEMORY);
11291 }
11292}
11293
11294void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
11295{
11296 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
11297 program, bufSize, length, binaryFormat, binary);
11298
11299 try
11300 {
11301 gl::Context *context = gl::getNonLostContext();
11302
11303 if (context)
11304 {
11305 if (context->getClientVersion() < 3)
11306 {
11307 return gl::error(GL_INVALID_OPERATION);
11308 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011309
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011310 UNIMPLEMENTED();
11311 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011312 }
11313 catch(std::bad_alloc&)
11314 {
11315 return gl::error(GL_OUT_OF_MEMORY);
11316 }
11317}
11318
11319void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
11320{
11321 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
11322 program, binaryFormat, binary, length);
11323
11324 try
11325 {
11326 gl::Context *context = gl::getNonLostContext();
11327
11328 if (context)
11329 {
11330 if (context->getClientVersion() < 3)
11331 {
11332 return gl::error(GL_INVALID_OPERATION);
11333 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011334
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011335 UNIMPLEMENTED();
11336 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011337 }
11338 catch(std::bad_alloc&)
11339 {
11340 return gl::error(GL_OUT_OF_MEMORY);
11341 }
11342}
11343
11344void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
11345{
11346 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
11347 program, pname, value);
11348
11349 try
11350 {
11351 gl::Context *context = gl::getNonLostContext();
11352
11353 if (context)
11354 {
11355 if (context->getClientVersion() < 3)
11356 {
11357 return gl::error(GL_INVALID_OPERATION);
11358 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011359
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011360 UNIMPLEMENTED();
11361 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011362 }
11363 catch(std::bad_alloc&)
11364 {
11365 return gl::error(GL_OUT_OF_MEMORY);
11366 }
11367}
11368
11369void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
11370{
11371 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
11372 target, numAttachments, attachments);
11373
11374 try
11375 {
11376 gl::Context *context = gl::getNonLostContext();
11377
11378 if (context)
11379 {
11380 if (context->getClientVersion() < 3)
11381 {
11382 return gl::error(GL_INVALID_OPERATION);
11383 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011384
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011385 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11386 {
11387 return;
11388 }
11389
11390 int maxDimension = context->getMaximumRenderbufferDimension();
11391 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
11392 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011393 }
11394 catch(std::bad_alloc&)
11395 {
11396 return gl::error(GL_OUT_OF_MEMORY);
11397 }
11398}
11399
11400void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
11401{
11402 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
11403 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
11404 target, numAttachments, attachments, x, y, width, height);
11405
11406 try
11407 {
11408 gl::Context *context = gl::getNonLostContext();
11409
11410 if (context)
11411 {
11412 if (context->getClientVersion() < 3)
11413 {
11414 return gl::error(GL_INVALID_OPERATION);
11415 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011416
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011417 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11418 {
11419 return;
11420 }
11421
11422 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
11423 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011424 }
11425 catch(std::bad_alloc&)
11426 {
11427 return gl::error(GL_OUT_OF_MEMORY);
11428 }
11429}
11430
11431void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
11432{
11433 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
11434 target, levels, internalformat, width, height);
11435
11436 try
11437 {
11438 gl::Context *context = gl::getNonLostContext();
11439
11440 if (context)
11441 {
11442 if (context->getClientVersion() < 3)
11443 {
11444 return gl::error(GL_INVALID_OPERATION);
11445 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011446
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011447 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
11448 {
11449 return;
11450 }
11451
11452 switch (target)
11453 {
11454 case GL_TEXTURE_2D:
11455 {
11456 gl::Texture2D *texture2d = context->getTexture2D();
11457 texture2d->storage(levels, internalformat, width, height);
11458 }
11459 break;
11460
11461 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
11462 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
11463 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
11464 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
11465 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
11466 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
11467 {
11468 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
11469 textureCube->storage(levels, internalformat, width);
11470 }
11471 break;
11472
11473 default:
11474 return gl::error(GL_INVALID_ENUM);
11475 }
11476 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011477 }
11478 catch(std::bad_alloc&)
11479 {
11480 return gl::error(GL_OUT_OF_MEMORY);
11481 }
11482}
11483
11484void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
11485{
11486 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
11487 "GLsizei height = %d, GLsizei depth = %d)",
11488 target, levels, internalformat, width, height, depth);
11489
11490 try
11491 {
11492 gl::Context *context = gl::getNonLostContext();
11493
11494 if (context)
11495 {
11496 if (context->getClientVersion() < 3)
11497 {
11498 return gl::error(GL_INVALID_OPERATION);
11499 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011500
11501 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
11502 {
11503 return;
11504 }
11505
11506 switch (target)
11507 {
11508 case GL_TEXTURE_3D:
11509 {
11510 gl::Texture3D *texture3d = context->getTexture3D();
11511 texture3d->storage(levels, internalformat, width, height, depth);
11512 }
11513 break;
11514
11515 case GL_TEXTURE_2D_ARRAY:
11516 {
11517 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
11518 texture2darray->storage(levels, internalformat, width, height, depth);
11519 }
11520 break;
11521
11522 default:
11523 return gl::error(GL_INVALID_ENUM);
11524 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000011525 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011526 }
11527 catch(std::bad_alloc&)
11528 {
11529 return gl::error(GL_OUT_OF_MEMORY);
11530 }
11531}
11532
11533void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
11534{
11535 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
11536 "GLint* params = 0x%0.8p)",
11537 target, internalformat, pname, bufSize, params);
11538
11539 try
11540 {
11541 gl::Context *context = gl::getNonLostContext();
11542
11543 if (context)
11544 {
11545 if (context->getClientVersion() < 3)
11546 {
11547 return gl::error(GL_INVALID_OPERATION);
11548 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011549
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011550 UNIMPLEMENTED();
11551 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011552 }
11553 catch(std::bad_alloc&)
11554 {
11555 return gl::error(GL_OUT_OF_MEMORY);
11556 }
11557}
11558
11559// Extension functions
11560
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011561void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
11562 GLbitfield mask, GLenum filter)
11563{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011564 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011565 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
11566 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
11567 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
11568
11569 try
11570 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011571 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011572
11573 if (context)
11574 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011575 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
11576 dstX0, dstY0, dstX1, dstY1, mask, filter,
11577 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011578 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011579 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011580 }
11581
Geoff Lang758d5b22013-06-11 11:42:50 -040011582 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
11583 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011584 }
11585 }
11586 catch(std::bad_alloc&)
11587 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011588 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011589 }
11590}
11591
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011592void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
11593 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011594{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011595 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000011596 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011597 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011598 target, level, internalformat, width, height, depth, border, format, type, pixels);
11599
11600 try
11601 {
11602 UNIMPLEMENTED(); // FIXME
11603 }
11604 catch(std::bad_alloc&)
11605 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011606 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011607 }
11608}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011609
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011610void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
11611 GLenum *binaryFormat, void *binary)
11612{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011613 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 +000011614 program, bufSize, length, binaryFormat, binary);
11615
11616 try
11617 {
11618 gl::Context *context = gl::getNonLostContext();
11619
11620 if (context)
11621 {
11622 gl::Program *programObject = context->getProgram(program);
11623
daniel@transgaming.com716056c2012-07-24 18:38:59 +000011624 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011625 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011626 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011627 }
11628
11629 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11630
11631 if (!programBinary)
11632 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011633 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011634 }
11635
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011636 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011637 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011638 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011639 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011640
11641 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011642 }
11643 }
11644 catch(std::bad_alloc&)
11645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011646 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011647 }
11648}
11649
11650void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
11651 const void *binary, GLint length)
11652{
11653 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
11654 program, binaryFormat, binary, length);
11655
11656 try
11657 {
11658 gl::Context *context = gl::getNonLostContext();
11659
11660 if (context)
11661 {
11662 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
11663 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011664 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011665 }
11666
11667 gl::Program *programObject = context->getProgram(program);
11668
11669 if (!programObject)
11670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011671 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011672 }
11673
daniel@transgaming.com95d29422012-07-24 18:36:10 +000011674 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011675 }
11676 }
11677 catch(std::bad_alloc&)
11678 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011679 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011680 }
11681}
11682
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011683void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
11684{
11685 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
11686
11687 try
11688 {
11689 gl::Context *context = gl::getNonLostContext();
11690
11691 if (context)
11692 {
11693 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
11694 {
11695 return gl::error(GL_INVALID_VALUE);
11696 }
11697
11698 if (context->getDrawFramebufferHandle() == 0)
11699 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011700 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011701 {
11702 return gl::error(GL_INVALID_OPERATION);
11703 }
11704
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011705 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011706 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011707 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011708 }
11709 }
11710 else
11711 {
11712 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11713 {
11714 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
11715 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
11716 {
11717 return gl::error(GL_INVALID_OPERATION);
11718 }
11719 }
11720 }
11721
11722 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
11723
11724 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11725 {
11726 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
11727 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011728
11729 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
11730 {
11731 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
11732 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011733 }
11734 }
11735 catch (std::bad_alloc&)
11736 {
11737 return gl::error(GL_OUT_OF_MEMORY);
11738 }
11739}
11740
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011741__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
11742{
11743 struct Extension
11744 {
11745 const char *name;
11746 __eglMustCastToProperFunctionPointerType address;
11747 };
11748
11749 static const Extension glExtensions[] =
11750 {
11751 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000011752 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000011753 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000011754 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
11755 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
11756 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
11757 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
11758 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
11759 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
11760 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000011761 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000011762 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000011763 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
11764 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
11765 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
11766 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000011767 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
11768 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
11769 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
11770 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
11771 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
11772 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
11773 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000011774 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000011775 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
11776 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
11777 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011778 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
11779 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011780
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000011781 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011782 {
11783 if (strcmp(procname, glExtensions[ext].name) == 0)
11784 {
11785 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
11786 }
11787 }
11788
11789 return NULL;
11790}
11791
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000011792// Non-public functions used by EGL
11793
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011794bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011795{
11796 EVENT("(egl::Surface* surface = 0x%0.8p)",
11797 surface);
11798
11799 try
11800 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011801 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011802
11803 if (context)
11804 {
11805 gl::Texture2D *textureObject = context->getTexture2D();
11806
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011807 if (textureObject->isImmutable())
11808 {
11809 return false;
11810 }
11811
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011812 if (textureObject)
11813 {
11814 textureObject->bindTexImage(surface);
11815 }
11816 }
11817 }
11818 catch(std::bad_alloc&)
11819 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011820 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011821 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011822
11823 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011824}
11825
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011826}