blob: 72e35ab5656a22c4ad4459e2b8ff914f4f7a6f50 [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:
daniel@transgaming.come0078962010-04-15 20:45:08 +00005881 {
Jamie Madilla857c362013-07-02 11:57:02 -04005882 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
5883 for (int i = 0; i < 4; ++i)
5884 {
5885 params[i] = currentValueData.FloatValues[i];
5886 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00005887 }
5888 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00005889 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
5890 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
5891 // the same constant.
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00005892 *params = (GLfloat)attribState.mDivisor;
5893 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005894 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005895 }
5896 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005897 }
5898 catch(std::bad_alloc&)
5899 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005900 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005901 }
5902}
5903
5904void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
5905{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005906 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005907
5908 try
5909 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005910 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005911
daniel@transgaming.come0078962010-04-15 20:45:08 +00005912 if (context)
5913 {
5914 if (index >= gl::MAX_VERTEX_ATTRIBS)
5915 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005916 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005917 }
5918
daniel@transgaming.com83921382011-01-08 05:46:00 +00005919 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005920
daniel@transgaming.come0078962010-04-15 20:45:08 +00005921 switch (pname)
5922 {
5923 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00005924 *params = (attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005925 break;
5926 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005927 *params = attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005928 break;
5929 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005930 *params = attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005931 break;
5932 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005933 *params = attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00005934 break;
5935 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005936 *params = (attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005937 break;
5938 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00005939 *params = attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00005940 break;
5941 case GL_CURRENT_VERTEX_ATTRIB:
daniel@transgaming.come0078962010-04-15 20:45:08 +00005942 {
Jamie Madilla857c362013-07-02 11:57:02 -04005943 const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
5944 for (int i = 0; i < 4; ++i)
5945 {
5946 float currentValue = currentValueData.FloatValues[i];
5947 params[i] = (GLint)(currentValue > 0.0f ? floor(currentValue + 0.5f) : ceil(currentValue - 0.5f));
5948 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00005949 }
5950 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00005951 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
5952 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
5953 // the same constant.
5954 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00005955 *params = (GLint)attribState.mDivisor;
5956 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005957 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005958 }
5959 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005960 }
5961 catch(std::bad_alloc&)
5962 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005963 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005964 }
5965}
5966
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005967void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005968{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005969 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005970
5971 try
5972 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005973 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005974
daniel@transgaming.come0078962010-04-15 20:45:08 +00005975 if (context)
5976 {
5977 if (index >= gl::MAX_VERTEX_ATTRIBS)
5978 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005979 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005980 }
5981
5982 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
5983 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005984 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00005985 }
5986
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005987 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00005988 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005989 }
5990 catch(std::bad_alloc&)
5991 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005992 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005993 }
5994}
5995
5996void __stdcall glHint(GLenum target, GLenum mode)
5997{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005998 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005999
6000 try
6001 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006002 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006003 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006004 case GL_FASTEST:
6005 case GL_NICEST:
6006 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006007 break;
6008 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006009 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006010 }
6011
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006012 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006013 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006014 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00006015 case GL_GENERATE_MIPMAP_HINT:
6016 if (context) context->setGenerateMipmapHint(mode);
6017 break;
6018 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
6019 if (context) context->setFragmentShaderDerivativeHint(mode);
6020 break;
6021 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006022 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00006023 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006024 }
6025 catch(std::bad_alloc&)
6026 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006027 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006028 }
6029}
6030
6031GLboolean __stdcall glIsBuffer(GLuint buffer)
6032{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006033 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006034
6035 try
6036 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006037 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006038
6039 if (context && buffer)
6040 {
6041 gl::Buffer *bufferObject = context->getBuffer(buffer);
6042
6043 if (bufferObject)
6044 {
6045 return GL_TRUE;
6046 }
6047 }
6048 }
6049 catch(std::bad_alloc&)
6050 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006051 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006052 }
6053
6054 return GL_FALSE;
6055}
6056
6057GLboolean __stdcall glIsEnabled(GLenum cap)
6058{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006059 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006060
6061 try
6062 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006063 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006064
6065 if (context)
6066 {
6067 switch (cap)
6068 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006069 case GL_CULL_FACE: return context->isCullFaceEnabled();
6070 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
6071 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
6072 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
6073 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
6074 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
6075 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
6076 case GL_BLEND: return context->isBlendEnabled();
6077 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006078 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006079 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006080 }
6081 }
6082 }
6083 catch(std::bad_alloc&)
6084 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006085 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006086 }
6087
6088 return false;
6089}
6090
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006091GLboolean __stdcall glIsFenceNV(GLuint fence)
6092{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006093 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006094
6095 try
6096 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006097 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006098
6099 if (context)
6100 {
6101 gl::Fence *fenceObject = context->getFence(fence);
6102
6103 if (fenceObject == NULL)
6104 {
6105 return GL_FALSE;
6106 }
6107
6108 return fenceObject->isFence();
6109 }
6110 }
6111 catch(std::bad_alloc&)
6112 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006113 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006114 }
6115
6116 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006117}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006118
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006119GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
6120{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006121 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006122
6123 try
6124 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006125 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006126
6127 if (context && framebuffer)
6128 {
6129 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
6130
6131 if (framebufferObject)
6132 {
6133 return GL_TRUE;
6134 }
6135 }
6136 }
6137 catch(std::bad_alloc&)
6138 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006139 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006140 }
6141
6142 return GL_FALSE;
6143}
6144
6145GLboolean __stdcall glIsProgram(GLuint program)
6146{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006147 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006148
6149 try
6150 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006151 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006152
6153 if (context && program)
6154 {
6155 gl::Program *programObject = context->getProgram(program);
6156
6157 if (programObject)
6158 {
6159 return GL_TRUE;
6160 }
6161 }
6162 }
6163 catch(std::bad_alloc&)
6164 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006165 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006166 }
6167
6168 return GL_FALSE;
6169}
6170
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006171GLboolean __stdcall glIsQueryEXT(GLuint id)
6172{
6173 EVENT("(GLuint id = %d)", id);
6174
6175 try
6176 {
6177 if (id == 0)
6178 {
6179 return GL_FALSE;
6180 }
6181
6182 gl::Context *context = gl::getNonLostContext();
6183
6184 if (context)
6185 {
6186 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
6187
6188 if (queryObject)
6189 {
6190 return GL_TRUE;
6191 }
6192 }
6193 }
6194 catch(std::bad_alloc&)
6195 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006196 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00006197 }
6198
6199 return GL_FALSE;
6200}
6201
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006202GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
6203{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006204 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006205
6206 try
6207 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006208 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006209
6210 if (context && renderbuffer)
6211 {
6212 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
6213
6214 if (renderbufferObject)
6215 {
6216 return GL_TRUE;
6217 }
6218 }
6219 }
6220 catch(std::bad_alloc&)
6221 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006222 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006223 }
6224
6225 return GL_FALSE;
6226}
6227
6228GLboolean __stdcall glIsShader(GLuint shader)
6229{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006230 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006231
6232 try
6233 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006234 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006235
6236 if (context && shader)
6237 {
6238 gl::Shader *shaderObject = context->getShader(shader);
6239
6240 if (shaderObject)
6241 {
6242 return GL_TRUE;
6243 }
6244 }
6245 }
6246 catch(std::bad_alloc&)
6247 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006248 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006249 }
6250
6251 return GL_FALSE;
6252}
6253
6254GLboolean __stdcall glIsTexture(GLuint texture)
6255{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006256 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006257
6258 try
6259 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006260 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006261
6262 if (context && texture)
6263 {
6264 gl::Texture *textureObject = context->getTexture(texture);
6265
6266 if (textureObject)
6267 {
6268 return GL_TRUE;
6269 }
6270 }
6271 }
6272 catch(std::bad_alloc&)
6273 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006274 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006275 }
6276
6277 return GL_FALSE;
6278}
6279
6280void __stdcall glLineWidth(GLfloat width)
6281{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006282 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006283
6284 try
6285 {
6286 if (width <= 0.0f)
6287 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006288 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006289 }
6290
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006291 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00006292
6293 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006294 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006295 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006296 }
6297 }
6298 catch(std::bad_alloc&)
6299 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006300 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006301 }
6302}
6303
6304void __stdcall glLinkProgram(GLuint program)
6305{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006306 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006307
6308 try
6309 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006310 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006311
6312 if (context)
6313 {
6314 gl::Program *programObject = context->getProgram(program);
6315
6316 if (!programObject)
6317 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006318 if (context->getShader(program))
6319 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006320 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006321 }
6322 else
6323 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006324 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00006325 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006326 }
6327
daniel@transgaming.com95d29422012-07-24 18:36:10 +00006328 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006329 }
6330 }
6331 catch(std::bad_alloc&)
6332 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006333 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006334 }
6335}
6336
6337void __stdcall glPixelStorei(GLenum pname, GLint param)
6338{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006339 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006340
6341 try
6342 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006343 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006344
6345 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006346 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006347 switch (pname)
6348 {
6349 case GL_UNPACK_ALIGNMENT:
6350 if (param != 1 && param != 2 && param != 4 && param != 8)
6351 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006352 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006353 }
6354
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006355 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006356 break;
6357
6358 case GL_PACK_ALIGNMENT:
6359 if (param != 1 && param != 2 && param != 4 && param != 8)
6360 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006361 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006362 }
6363
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006364 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006365 break;
6366
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00006367 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6368 context->setPackReverseRowOrder(param != 0);
6369 break;
6370
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00006371 case GL_UNPACK_IMAGE_HEIGHT:
6372 case GL_UNPACK_SKIP_IMAGES:
6373 case GL_UNPACK_ROW_LENGTH:
6374 case GL_UNPACK_SKIP_ROWS:
6375 case GL_UNPACK_SKIP_PIXELS:
6376 case GL_PACK_ROW_LENGTH:
6377 case GL_PACK_SKIP_ROWS:
6378 case GL_PACK_SKIP_PIXELS:
6379 if (context->getClientVersion() < 3)
6380 {
6381 return gl::error(GL_INVALID_ENUM);
6382 }
6383 UNIMPLEMENTED();
6384 break;
6385
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006386 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006387 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00006388 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006389 }
6390 }
6391 catch(std::bad_alloc&)
6392 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006393 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006394 }
6395}
6396
6397void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
6398{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006399 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006400
6401 try
6402 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006403 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00006404
6405 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006406 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006407 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006408 }
6409 }
6410 catch(std::bad_alloc&)
6411 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006412 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006413 }
6414}
6415
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006416void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
6417 GLenum format, GLenum type, GLsizei bufSize,
6418 GLvoid *data)
6419{
6420 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
6421 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
6422 x, y, width, height, format, type, bufSize, data);
6423
6424 try
6425 {
6426 if (width < 0 || height < 0 || bufSize < 0)
6427 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006428 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006429 }
6430
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006431 gl::Context *context = gl::getNonLostContext();
6432
6433 if (context)
6434 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006435 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006436 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006437
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006438 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6439 // and attempting to read back if that's the case is an error. The error will be registered
6440 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006441 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006442 return;
6443
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006444 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6445 validES3ReadFormatType(currentInternalFormat, format, type);
6446
6447 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006448 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006449 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006450 }
6451
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006452 context->readPixels(x, y, width, height, format, type, &bufSize, data);
6453 }
6454 }
6455 catch(std::bad_alloc&)
6456 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006457 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006458 }
6459}
6460
6461void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
6462 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006463{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006464 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006465 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006466 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006467
6468 try
6469 {
6470 if (width < 0 || height < 0)
6471 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006472 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006473 }
6474
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006475 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006476
6477 if (context)
6478 {
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006479 GLint currentInternalFormat;
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006480 GLenum currentFormat, currentType;
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006481
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006482 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
6483 // and attempting to read back if that's the case is an error. The error will be registered
6484 // by getCurrentReadFormat.
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006485 if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006486 return;
6487
shannonwoods@chromium.org44a4f982013-05-30 00:13:49 +00006488 bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
6489 validES3ReadFormatType(currentInternalFormat, format, type);
6490
6491 if (!(currentFormat == format && currentType == type) && !validReadFormat)
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006492 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006493 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00006494 }
6495
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00006496 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006497 }
6498 }
6499 catch(std::bad_alloc&)
6500 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006501 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006502 }
6503}
6504
6505void __stdcall glReleaseShaderCompiler(void)
6506{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006507 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006508
6509 try
6510 {
6511 gl::Shader::releaseCompiler();
6512 }
6513 catch(std::bad_alloc&)
6514 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006515 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006516 }
6517}
6518
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006519void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006520{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006521 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 +00006522 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006523
6524 try
6525 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006526 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006527
6528 if (context)
6529 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006530 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
6531 width, height, true))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00006532 {
Geoff Lang2e1dcd52013-05-29 10:34:08 -04006533 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006534 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00006535
6536 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006537 }
6538 }
6539 catch(std::bad_alloc&)
6540 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006541 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006542 }
6543}
6544
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00006545void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
6546{
6547 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
6548}
6549
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006550void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
6551{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006552 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006553
6554 try
6555 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006556 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006557
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006558 if (context)
6559 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00006560 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006561 }
6562 }
6563 catch(std::bad_alloc&)
6564 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006565 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006566 }
6567}
6568
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006569void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
6570{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006571 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006572
6573 try
6574 {
6575 if (condition != GL_ALL_COMPLETED_NV)
6576 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006577 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006578 }
6579
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006580 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006581
6582 if (context)
6583 {
6584 gl::Fence *fenceObject = context->getFence(fence);
6585
6586 if (fenceObject == NULL)
6587 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006588 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006589 }
6590
6591 fenceObject->setFence(condition);
6592 }
6593 }
6594 catch(std::bad_alloc&)
6595 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006596 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006597 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006598}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006599
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006600void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
6601{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006602 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 +00006603
6604 try
6605 {
6606 if (width < 0 || height < 0)
6607 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006608 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006609 }
6610
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006611 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006612
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006613 if (context)
6614 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006615 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006616 }
6617 }
6618 catch(std::bad_alloc&)
6619 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006620 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006621 }
6622}
6623
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006624void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006625{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006626 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006627 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006628 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006629
6630 try
6631 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00006632 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006633 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006634 }
6635 catch(std::bad_alloc&)
6636 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006637 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006638 }
6639}
6640
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00006641void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006642{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006643 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 +00006644 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006645
6646 try
6647 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006648 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006649 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006650 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006651 }
6652
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006653 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006654
6655 if (context)
6656 {
6657 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006658
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006659 if (!shaderObject)
6660 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006661 if (context->getProgram(shader))
6662 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006663 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006664 }
6665 else
6666 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006667 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00006668 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006669 }
6670
6671 shaderObject->setSource(count, string, length);
6672 }
6673 }
6674 catch(std::bad_alloc&)
6675 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006676 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006677 }
6678}
6679
6680void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
6681{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006682 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006683}
6684
6685void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
6686{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006687 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 +00006688
6689 try
6690 {
6691 switch (face)
6692 {
6693 case GL_FRONT:
6694 case GL_BACK:
6695 case GL_FRONT_AND_BACK:
6696 break;
6697 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006698 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006699 }
6700
6701 switch (func)
6702 {
6703 case GL_NEVER:
6704 case GL_ALWAYS:
6705 case GL_LESS:
6706 case GL_LEQUAL:
6707 case GL_EQUAL:
6708 case GL_GEQUAL:
6709 case GL_GREATER:
6710 case GL_NOTEQUAL:
6711 break;
6712 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006713 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006714 }
6715
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006716 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006717
6718 if (context)
6719 {
6720 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6721 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006722 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006723 }
6724
6725 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6726 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006727 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006728 }
6729 }
6730 }
6731 catch(std::bad_alloc&)
6732 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006733 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006734 }
6735}
6736
6737void __stdcall glStencilMask(GLuint mask)
6738{
6739 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6740}
6741
6742void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
6743{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006744 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006745
6746 try
6747 {
6748 switch (face)
6749 {
6750 case GL_FRONT:
6751 case GL_BACK:
6752 case GL_FRONT_AND_BACK:
6753 break;
6754 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006755 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006756 }
6757
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006758 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006759
6760 if (context)
6761 {
6762 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6763 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006764 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006765 }
6766
6767 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6768 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006769 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006770 }
6771 }
6772 }
6773 catch(std::bad_alloc&)
6774 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006775 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006776 }
6777}
6778
6779void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6780{
6781 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6782}
6783
6784void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
6785{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006786 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 +00006787 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006788
6789 try
6790 {
6791 switch (face)
6792 {
6793 case GL_FRONT:
6794 case GL_BACK:
6795 case GL_FRONT_AND_BACK:
6796 break;
6797 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006798 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006799 }
6800
6801 switch (fail)
6802 {
6803 case GL_ZERO:
6804 case GL_KEEP:
6805 case GL_REPLACE:
6806 case GL_INCR:
6807 case GL_DECR:
6808 case GL_INVERT:
6809 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006810 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006811 break;
6812 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006813 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006814 }
6815
6816 switch (zfail)
6817 {
6818 case GL_ZERO:
6819 case GL_KEEP:
6820 case GL_REPLACE:
6821 case GL_INCR:
6822 case GL_DECR:
6823 case GL_INVERT:
6824 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006825 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006826 break;
6827 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006828 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006829 }
6830
6831 switch (zpass)
6832 {
6833 case GL_ZERO:
6834 case GL_KEEP:
6835 case GL_REPLACE:
6836 case GL_INCR:
6837 case GL_DECR:
6838 case GL_INVERT:
6839 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00006840 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006841 break;
6842 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006843 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006844 }
6845
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006846 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006847
6848 if (context)
6849 {
6850 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
6851 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006852 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006853 }
6854
6855 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
6856 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00006857 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006858 }
6859 }
6860 }
6861 catch(std::bad_alloc&)
6862 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006863 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006864 }
6865}
6866
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006867GLboolean __stdcall glTestFenceNV(GLuint fence)
6868{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006869 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006870
6871 try
6872 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006873 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006874
6875 if (context)
6876 {
6877 gl::Fence *fenceObject = context->getFence(fence);
6878
6879 if (fenceObject == NULL)
6880 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006881 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006882 }
6883
6884 return fenceObject->testFence();
6885 }
6886 }
6887 catch(std::bad_alloc&)
6888 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006889 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006890 }
6891
6892 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00006893}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00006894
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006895void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
6896 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006897{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006898 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 +00006899 "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 +00006900 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006901
6902 try
6903 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006904 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006905
6906 if (context)
6907 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006908 if (context->getClientVersion() < 3 &&
6909 !validateES2TexImageParameters(context, target, level, internalformat, false, false,
6910 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006911 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006912 return;
6913 }
6914
6915 if (context->getClientVersion() >= 3 &&
6916 !validateES3TexImageParameters(context, target, level, internalformat, false, false,
6917 0, 0, 0, width, height, 1, border, format, type))
6918 {
6919 return;
daniel@transgaming.com32b11442011-11-19 02:42:48 +00006920 }
6921
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006922 switch (target)
6923 {
6924 case GL_TEXTURE_2D:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006925 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006926 gl::Texture2D *texture = context->getTexture2D();
6927 texture->setImage(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006928 }
6929 break;
6930 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006931 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006932 gl::TextureCubeMap *texture = context->getTextureCubeMap();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00006933 texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006934 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00006935 break;
6936 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
6937 {
6938 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6939 texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6940 }
6941 break;
6942 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
6943 {
6944 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6945 texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6946 }
6947 break;
6948 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
6949 {
6950 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6951 texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6952 }
6953 break;
6954 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
6955 {
6956 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6957 texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6958 }
6959 break;
6960 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
6961 {
6962 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6963 texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackAlignment(), pixels);
6964 }
6965 break;
6966 default: UNREACHABLE();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006967 }
6968 }
6969 }
6970 catch(std::bad_alloc&)
6971 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006972 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006973 }
6974}
6975
6976void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
6977{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006978 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
6979
6980 try
6981 {
6982 gl::Context *context = gl::getNonLostContext();
6983
6984 if (context)
6985 {
6986 gl::Texture *texture;
6987
6988 switch (target)
6989 {
6990 case GL_TEXTURE_2D:
6991 texture = context->getTexture2D();
6992 break;
6993 case GL_TEXTURE_CUBE_MAP:
6994 texture = context->getTextureCubeMap();
6995 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006996 case GL_TEXTURE_3D:
6997 if (context->getClientVersion() < 3)
6998 {
6999 return gl::error(GL_INVALID_ENUM);
7000 }
7001 texture = context->getTexture3D();
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00007002 case GL_TEXTURE_2D_ARRAY:
7003 if (context->getClientVersion() < 3)
7004 {
7005 return gl::error(GL_INVALID_ENUM);
7006 }
7007 texture = context->getTexture2DArray();
7008 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007009 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007010 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007011 }
7012
7013 switch (pname)
7014 {
7015 case GL_TEXTURE_WRAP_S:
7016 if (!texture->setWrapS((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;
7021 case GL_TEXTURE_WRAP_T:
7022 if (!texture->setWrapT((GLenum)param))
7023 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007024 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007025 }
7026 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00007027 case GL_TEXTURE_WRAP_R:
7028 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
7029 {
7030 return gl::error(GL_INVALID_ENUM);
7031 }
7032 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007033 case GL_TEXTURE_MIN_FILTER:
7034 if (!texture->setMinFilter((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_MAG_FILTER:
7040 if (!texture->setMagFilter((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_USAGE_ANGLE:
7046 if (!texture->setUsage((GLenum)param))
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 break;
7051 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
7052 if (!context->supportsTextureFilterAnisotropy())
7053 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007054 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007055 }
7056 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
7057 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007058 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007059 }
7060 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007061
7062 case GL_TEXTURE_MIN_LOD:
7063 case GL_TEXTURE_MAX_LOD:
7064 if (context->getClientVersion() < 3)
7065 {
7066 return gl::error(GL_INVALID_ENUM);
7067 }
7068 UNIMPLEMENTED();
7069 break;
7070
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007071 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007072 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007073 }
7074 }
7075 }
7076 catch(std::bad_alloc&)
7077 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007078 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007079 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007080}
7081
7082void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
7083{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007084 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007085}
7086
7087void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
7088{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007089 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007090
7091 try
7092 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007093 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007094
7095 if (context)
7096 {
7097 gl::Texture *texture;
7098
7099 switch (target)
7100 {
7101 case GL_TEXTURE_2D:
7102 texture = context->getTexture2D();
7103 break;
7104 case GL_TEXTURE_CUBE_MAP:
7105 texture = context->getTextureCubeMap();
7106 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00007107 case GL_TEXTURE_3D:
7108 if (context->getClientVersion() < 3)
7109 {
7110 return gl::error(GL_INVALID_ENUM);
7111 }
7112 texture = context->getTexture3D();
7113 break;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00007114 case GL_TEXTURE_2D_ARRAY:
7115 if (context->getClientVersion() < 3)
7116 {
7117 return gl::error(GL_INVALID_ENUM);
7118 }
7119 texture = context->getTexture2DArray();
7120 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007121 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007122 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007123 }
7124
7125 switch (pname)
7126 {
7127 case GL_TEXTURE_WRAP_S:
7128 if (!texture->setWrapS((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;
7133 case GL_TEXTURE_WRAP_T:
7134 if (!texture->setWrapT((GLenum)param))
7135 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007136 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007137 }
7138 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00007139 case GL_TEXTURE_WRAP_R:
7140 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
7141 {
7142 return gl::error(GL_INVALID_ENUM);
7143 }
7144 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007145 case GL_TEXTURE_MIN_FILTER:
7146 if (!texture->setMinFilter((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;
7151 case GL_TEXTURE_MAG_FILTER:
7152 if (!texture->setMagFilter((GLenum)param))
7153 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007154 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007155 }
7156 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00007157 case GL_TEXTURE_USAGE_ANGLE:
7158 if (!texture->setUsage((GLenum)param))
7159 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007160 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00007161 }
7162 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007163 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
7164 if (!context->supportsTextureFilterAnisotropy())
7165 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007166 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007167 }
7168 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
7169 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007170 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00007171 }
7172 break;
shannonwoods@chromium.orgabf14cc2013-05-30 00:20:58 +00007173
7174 case GL_TEXTURE_SWIZZLE_R:
7175 case GL_TEXTURE_SWIZZLE_G:
7176 case GL_TEXTURE_SWIZZLE_B:
7177 case GL_TEXTURE_SWIZZLE_A:
7178 case GL_TEXTURE_BASE_LEVEL:
7179 case GL_TEXTURE_MAX_LEVEL:
7180 case GL_TEXTURE_COMPARE_MODE:
7181 case GL_TEXTURE_COMPARE_FUNC:
7182 if (context->getClientVersion() < 3)
7183 {
7184 return gl::error(GL_INVALID_ENUM);
7185 }
7186 UNIMPLEMENTED();
7187 break;
7188
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007189 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007190 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007191 }
7192 }
7193 }
7194 catch(std::bad_alloc&)
7195 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007196 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007197 }
7198}
7199
7200void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
7201{
7202 glTexParameteri(target, pname, *params);
7203}
7204
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007205void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
7206{
7207 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
7208 target, levels, internalformat, width, height);
7209
7210 try
7211 {
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007212 gl::Context *context = gl::getNonLostContext();
7213
7214 if (context)
7215 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007216 if (context->getClientVersion() < 3 &&
7217 !validateES2TexStorageParameters(context, target, levels, internalformat, width, height))
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
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007222 if (context->getClientVersion() >= 3 &&
7223 !validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007224 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007225 return;
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00007226 }
7227
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007228 switch (target)
7229 {
7230 case GL_TEXTURE_2D:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007231 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007232 gl::Texture2D *texture2d = context->getTexture2D();
7233 texture2d->storage(levels, internalformat, width, height);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007234 }
7235 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007236
7237 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7238 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7239 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7240 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7241 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7242 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007243 {
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007244 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
7245 textureCube->storage(levels, internalformat, width);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007246 }
7247 break;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00007248
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007249 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007250 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00007251 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007252 }
7253 }
7254 catch(std::bad_alloc&)
7255 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007256 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00007257 }
7258}
7259
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007260void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
7261 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007262{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007263 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007264 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007265 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007266 target, level, xoffset, yoffset, width, height, format, type, pixels);
7267
7268 try
7269 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007270 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007271
7272 if (context)
7273 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007274 if (context->getClientVersion() < 3 &&
7275 !validateES2TexImageParameters(context, target, level, GL_NONE, false, true,
7276 0, 0, width, height, 0, format, type, pixels))
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00007277 {
7278 return;
7279 }
7280
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007281 if (context->getClientVersion() >= 3 &&
7282 !validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
7283 0, 0, 0, width, height, 1, 0, format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007284 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007285 return;
7286 }
7287
7288 switch (target)
7289 {
7290 case GL_TEXTURE_2D:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007291 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007292 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007293 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007294 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007295 break;
7296
7297 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
7298 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
7299 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
7300 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
7301 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
7302 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007303 {
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007304 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com343373a2011-11-29 19:42:32 +00007305 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007306 }
shannonwoods@chromium.orgf3a3eda2013-05-30 00:13:42 +00007307 break;
7308
7309 default:
7310 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00007311 }
7312 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007313 }
7314 catch(std::bad_alloc&)
7315 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007316 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007317 }
7318}
7319
7320void __stdcall glUniform1f(GLint location, GLfloat x)
7321{
7322 glUniform1fv(location, 1, &x);
7323}
7324
7325void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
7326{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007327 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007328
7329 try
7330 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007331 if (count < 0)
7332 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007333 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007334 }
7335
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007336 if (location == -1)
7337 {
7338 return;
7339 }
7340
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007341 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007342
7343 if (context)
7344 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007345 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007346 if (!programBinary)
7347 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007348 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007349 }
7350
7351 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007352 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007353 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007354 }
7355 }
7356 }
7357 catch(std::bad_alloc&)
7358 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007359 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007360 }
7361}
7362
7363void __stdcall glUniform1i(GLint location, GLint x)
7364{
7365 glUniform1iv(location, 1, &x);
7366}
7367
7368void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
7369{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007370 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007371
7372 try
7373 {
7374 if (count < 0)
7375 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007376 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007377 }
7378
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007379 if (location == -1)
7380 {
7381 return;
7382 }
7383
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007384 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007385
7386 if (context)
7387 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007388 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007389 if (!programBinary)
7390 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007391 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007392 }
7393
7394 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007395 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007396 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007397 }
7398 }
7399 }
7400 catch(std::bad_alloc&)
7401 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007402 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007403 }
7404}
7405
7406void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
7407{
7408 GLfloat xy[2] = {x, y};
7409
7410 glUniform2fv(location, 1, (GLfloat*)&xy);
7411}
7412
7413void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
7414{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007415 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007416
7417 try
7418 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007419 if (count < 0)
7420 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007421 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007422 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007423
7424 if (location == -1)
7425 {
7426 return;
7427 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007428
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007429 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007430
7431 if (context)
7432 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007433 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007434 if (!programBinary)
7435 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007436 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007437 }
7438
7439 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007440 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007441 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007442 }
7443 }
7444 }
7445 catch(std::bad_alloc&)
7446 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007447 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007448 }
7449}
7450
7451void __stdcall glUniform2i(GLint location, GLint x, GLint y)
7452{
7453 GLint xy[4] = {x, y};
7454
7455 glUniform2iv(location, 1, (GLint*)&xy);
7456}
7457
7458void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
7459{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007460 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007461
7462 try
7463 {
7464 if (count < 0)
7465 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007466 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007467 }
7468
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007469 if (location == -1)
7470 {
7471 return;
7472 }
7473
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007474 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007475
7476 if (context)
7477 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007478 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007479 if (!programBinary)
7480 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007481 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007482 }
7483
7484 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007485 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007486 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007487 }
7488 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007489 }
7490 catch(std::bad_alloc&)
7491 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007492 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007493 }
7494}
7495
7496void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
7497{
7498 GLfloat xyz[3] = {x, y, z};
7499
7500 glUniform3fv(location, 1, (GLfloat*)&xyz);
7501}
7502
7503void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
7504{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007505 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007506
7507 try
7508 {
7509 if (count < 0)
7510 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007511 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007512 }
7513
7514 if (location == -1)
7515 {
7516 return;
7517 }
7518
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007519 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007520
7521 if (context)
7522 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007523 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007524 if (!programBinary)
7525 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007526 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007527 }
7528
7529 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007530 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007531 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007532 }
7533 }
7534 }
7535 catch(std::bad_alloc&)
7536 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007537 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007538 }
7539}
7540
7541void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
7542{
7543 GLint xyz[3] = {x, y, z};
7544
7545 glUniform3iv(location, 1, (GLint*)&xyz);
7546}
7547
7548void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
7549{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007550 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007551
7552 try
7553 {
7554 if (count < 0)
7555 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007556 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007557 }
7558
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007559 if (location == -1)
7560 {
7561 return;
7562 }
7563
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007564 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007565
7566 if (context)
7567 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007568 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007569 if (!programBinary)
7570 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007571 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007572 }
7573
7574 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007575 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007576 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007577 }
7578 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007579 }
7580 catch(std::bad_alloc&)
7581 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007582 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007583 }
7584}
7585
7586void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7587{
7588 GLfloat xyzw[4] = {x, y, z, w};
7589
7590 glUniform4fv(location, 1, (GLfloat*)&xyzw);
7591}
7592
7593void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
7594{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007595 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007596
7597 try
7598 {
7599 if (count < 0)
7600 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007601 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007602 }
7603
7604 if (location == -1)
7605 {
7606 return;
7607 }
7608
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007609 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007610
7611 if (context)
7612 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007613 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007614 if (!programBinary)
7615 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007616 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007617 }
7618
7619 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007620 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007621 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007622 }
7623 }
7624 }
7625 catch(std::bad_alloc&)
7626 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007627 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007628 }
7629}
7630
7631void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
7632{
7633 GLint xyzw[4] = {x, y, z, w};
7634
7635 glUniform4iv(location, 1, (GLint*)&xyzw);
7636}
7637
7638void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
7639{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007640 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007641
7642 try
7643 {
7644 if (count < 0)
7645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007646 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007647 }
7648
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007649 if (location == -1)
7650 {
7651 return;
7652 }
7653
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007654 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007655
7656 if (context)
7657 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007658 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007659 if (!programBinary)
7660 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007661 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007662 }
7663
7664 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007665 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007666 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00007667 }
7668 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007669 }
7670 catch(std::bad_alloc&)
7671 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007672 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007673 }
7674}
7675
7676void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7677{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007678 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007679 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007680
7681 try
7682 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007683 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007684 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007685 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007686 }
7687
7688 if (location == -1)
7689 {
7690 return;
7691 }
7692
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007693 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007694
7695 if (context)
7696 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007697 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7698 {
7699 return gl::error(GL_INVALID_VALUE);
7700 }
7701
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007702 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007703 if (!programBinary)
7704 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007705 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007706 }
7707
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007708 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007709 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007710 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007711 }
7712 }
7713 }
7714 catch(std::bad_alloc&)
7715 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007716 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007717 }
7718}
7719
7720void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7721{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007722 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007723 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007724
7725 try
7726 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007727 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007728 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007729 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007730 }
7731
7732 if (location == -1)
7733 {
7734 return;
7735 }
7736
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007737 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007738
7739 if (context)
7740 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007741 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7742 {
7743 return gl::error(GL_INVALID_VALUE);
7744 }
7745
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007746 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007747 if (!programBinary)
7748 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007749 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007750 }
7751
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007752 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007753 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007754 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007755 }
7756 }
7757 }
7758 catch(std::bad_alloc&)
7759 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007760 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007761 }
7762}
7763
7764void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7765{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007766 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007767 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007768
7769 try
7770 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007771 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007772 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007773 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007774 }
7775
7776 if (location == -1)
7777 {
7778 return;
7779 }
7780
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007781 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007782
7783 if (context)
7784 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007785 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7786 {
7787 return gl::error(GL_INVALID_VALUE);
7788 }
7789
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007790 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007791 if (!programBinary)
7792 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007793 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007794 }
7795
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007796 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007797 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007798 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007799 }
7800 }
7801 }
7802 catch(std::bad_alloc&)
7803 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007804 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007805 }
7806}
7807
7808void __stdcall glUseProgram(GLuint program)
7809{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007810 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007811
7812 try
7813 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007814 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007815
7816 if (context)
7817 {
7818 gl::Program *programObject = context->getProgram(program);
7819
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007820 if (!programObject && program != 0)
7821 {
7822 if (context->getShader(program))
7823 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007824 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007825 }
7826 else
7827 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007828 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007829 }
7830 }
7831
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007832 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007833 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007834 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007835 }
7836
7837 context->useProgram(program);
7838 }
7839 }
7840 catch(std::bad_alloc&)
7841 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007842 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007843 }
7844}
7845
7846void __stdcall glValidateProgram(GLuint program)
7847{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007848 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007849
7850 try
7851 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007852 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007853
7854 if (context)
7855 {
7856 gl::Program *programObject = context->getProgram(program);
7857
7858 if (!programObject)
7859 {
7860 if (context->getShader(program))
7861 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007862 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007863 }
7864 else
7865 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007866 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007867 }
7868 }
7869
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00007870 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007871 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007872 }
7873 catch(std::bad_alloc&)
7874 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007875 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007876 }
7877}
7878
7879void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
7880{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007881 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007882
7883 try
7884 {
7885 if (index >= gl::MAX_VERTEX_ATTRIBS)
7886 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007887 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007888 }
7889
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007890 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007891
7892 if (context)
7893 {
7894 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007895 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007896 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007897 }
7898 catch(std::bad_alloc&)
7899 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007900 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007901 }
7902}
7903
7904void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
7905{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007906 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007907
7908 try
7909 {
7910 if (index >= gl::MAX_VERTEX_ATTRIBS)
7911 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007912 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007913 }
7914
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007915 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007916
7917 if (context)
7918 {
7919 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007920 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007921 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007922 }
7923 catch(std::bad_alloc&)
7924 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007925 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007926 }
7927}
7928
7929void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
7930{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007931 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007932
7933 try
7934 {
7935 if (index >= gl::MAX_VERTEX_ATTRIBS)
7936 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007937 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007938 }
7939
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007940 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007941
7942 if (context)
7943 {
7944 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007945 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007946 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007947 }
7948 catch(std::bad_alloc&)
7949 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007950 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007951 }
7952}
7953
7954void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
7955{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007956 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007957
7958 try
7959 {
7960 if (index >= gl::MAX_VERTEX_ATTRIBS)
7961 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007962 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007963 }
7964
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007965 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007966
7967 if (context)
7968 {
7969 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007970 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007971 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007972 }
7973 catch(std::bad_alloc&)
7974 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007975 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007976 }
7977}
7978
7979void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
7980{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007981 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 +00007982
7983 try
7984 {
7985 if (index >= gl::MAX_VERTEX_ATTRIBS)
7986 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007987 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007988 }
7989
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007990 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007991
7992 if (context)
7993 {
7994 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007995 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007996 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007997 }
7998 catch(std::bad_alloc&)
7999 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008000 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008001 }
8002}
8003
8004void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
8005{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008006 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008007
8008 try
8009 {
8010 if (index >= gl::MAX_VERTEX_ATTRIBS)
8011 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008012 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008013 }
8014
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008015 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008016
8017 if (context)
8018 {
8019 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008020 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008021 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008022 }
8023 catch(std::bad_alloc&)
8024 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008025 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008026 }
8027}
8028
8029void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
8030{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008031 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 +00008032
8033 try
8034 {
8035 if (index >= gl::MAX_VERTEX_ATTRIBS)
8036 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008037 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008038 }
8039
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008040 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008041
8042 if (context)
8043 {
8044 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008045 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008046 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008047 }
8048 catch(std::bad_alloc&)
8049 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008050 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008051 }
8052}
8053
8054void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
8055{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008056 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008057
8058 try
8059 {
8060 if (index >= gl::MAX_VERTEX_ATTRIBS)
8061 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008062 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008063 }
8064
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008065 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008066
8067 if (context)
8068 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008069 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00008070 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008071 }
8072 catch(std::bad_alloc&)
8073 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008074 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008075 }
8076}
8077
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008078void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
8079{
8080 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
8081
8082 try
8083 {
8084 if (index >= gl::MAX_VERTEX_ATTRIBS)
8085 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008086 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008087 }
8088
8089 gl::Context *context = gl::getNonLostContext();
8090
8091 if (context)
8092 {
8093 context->setVertexAttribDivisor(index, divisor);
8094 }
8095 }
8096 catch(std::bad_alloc&)
8097 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008098 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00008099 }
8100}
8101
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008102void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008103{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008104 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008105 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008106 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008107
8108 try
8109 {
8110 if (index >= gl::MAX_VERTEX_ATTRIBS)
8111 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008112 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008113 }
8114
8115 if (size < 1 || size > 4)
8116 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008117 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008118 }
8119
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008120 gl::Context *context = gl::getNonLostContext();
8121
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008122 switch (type)
8123 {
8124 case GL_BYTE:
8125 case GL_UNSIGNED_BYTE:
8126 case GL_SHORT:
8127 case GL_UNSIGNED_SHORT:
8128 case GL_FIXED:
8129 case GL_FLOAT:
8130 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008131 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008132 case GL_INT:
8133 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008134 case GL_INT_2_10_10_10_REV:
8135 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00008136 if (context && context->getClientVersion() < 3)
8137 {
8138 return gl::error(GL_INVALID_ENUM);
8139 }
8140 else
8141 {
8142 break;
8143 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008144 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008145 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008146 }
8147
8148 if (stride < 0)
8149 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008150 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008151 }
8152
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008153 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
8154 {
8155 return gl::error(GL_INVALID_OPERATION);
8156 }
8157
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008158 if (context)
8159 {
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00008160 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
8161 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008162 }
8163 }
8164 catch(std::bad_alloc&)
8165 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008166 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008167 }
8168}
8169
8170void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
8171{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008172 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 +00008173
8174 try
8175 {
8176 if (width < 0 || height < 0)
8177 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008178 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008179 }
8180
daniel@transgaming.com9d788502011-11-09 17:46:55 +00008181 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008182
8183 if (context)
8184 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00008185 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008186 }
8187 }
8188 catch(std::bad_alloc&)
8189 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00008190 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008191 }
8192}
8193
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008194// OpenGL ES 3.0 functions
8195
8196void __stdcall glReadBuffer(GLenum mode)
8197{
8198 EVENT("(GLenum mode = 0x%X)", mode);
8199
8200 try
8201 {
8202 gl::Context *context = gl::getNonLostContext();
8203
8204 if (context)
8205 {
8206 if (context->getClientVersion() < 3)
8207 {
8208 return gl::error(GL_INVALID_OPERATION);
8209 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008210
Jamie Madill54133512013-06-21 09:33:07 -04008211 // glReadBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008212 UNIMPLEMENTED();
8213 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008214 }
8215 catch(std::bad_alloc&)
8216 {
8217 return gl::error(GL_OUT_OF_MEMORY);
8218 }
8219}
8220
8221void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
8222{
8223 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
8224 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
8225
8226 try
8227 {
8228 gl::Context *context = gl::getNonLostContext();
8229
8230 if (context)
8231 {
8232 if (context->getClientVersion() < 3)
8233 {
8234 return gl::error(GL_INVALID_OPERATION);
8235 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008236
Jamie Madill54133512013-06-21 09:33:07 -04008237 // glDrawRangeElements
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008238 UNIMPLEMENTED();
8239 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008240 }
8241 catch(std::bad_alloc&)
8242 {
8243 return gl::error(GL_OUT_OF_MEMORY);
8244 }
8245}
8246
8247void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
8248{
8249 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8250 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
8251 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8252 target, level, internalformat, width, height, depth, border, format, type, pixels);
8253
8254 try
8255 {
8256 gl::Context *context = gl::getNonLostContext();
8257
8258 if (context)
8259 {
8260 if (context->getClientVersion() < 3)
8261 {
8262 return gl::error(GL_INVALID_OPERATION);
8263 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008264
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008265 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008266 if (!validateES3TexImageParameters(context, target, level, internalformat, false, false,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008267 0, 0, 0, width, height, depth, border, format, type))
8268 {
8269 return;
8270 }
8271
8272 switch(target)
8273 {
8274 case GL_TEXTURE_3D:
8275 {
8276 gl::Texture3D *texture = context->getTexture3D();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008277 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008278 }
8279 break;
8280
8281 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008282 {
8283 gl::Texture2DArray *texture = context->getTexture2DArray();
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +00008284 texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackAlignment(), pixels);
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008285 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008286 break;
8287
8288 default:
8289 return gl::error(GL_INVALID_ENUM);
8290 }
8291 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008292 }
8293 catch(std::bad_alloc&)
8294 {
8295 return gl::error(GL_OUT_OF_MEMORY);
8296 }
8297}
8298
8299void __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)
8300{
8301 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8302 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8303 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
8304 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
8305
8306 try
8307 {
8308 gl::Context *context = gl::getNonLostContext();
8309
8310 if (context)
8311 {
8312 if (context->getClientVersion() < 3)
8313 {
8314 return gl::error(GL_INVALID_OPERATION);
8315 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008316
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008317 if (!pixels)
8318 {
8319 return gl::error(GL_INVALID_VALUE);
8320 }
8321
8322 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008323 if (!validateES3TexImageParameters(context, target, level, GL_NONE, false, true,
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008324 xoffset, yoffset, zoffset, width, height, depth, 0,
8325 format, type))
8326 {
8327 return;
8328 }
8329
8330 switch(target)
8331 {
8332 case GL_TEXTURE_3D:
8333 {
8334 gl::Texture3D *texture = context->getTexture3D();
8335 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8336 }
8337 break;
8338
8339 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008340 {
8341 gl::Texture2DArray *texture = context->getTexture2DArray();
8342 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
8343 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008344 break;
8345
8346 default:
8347 return gl::error(GL_INVALID_ENUM);
8348 }
8349 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008350 }
8351 catch(std::bad_alloc&)
8352 {
8353 return gl::error(GL_OUT_OF_MEMORY);
8354 }
8355}
8356
8357void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
8358{
8359 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8360 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8361 target, level, xoffset, yoffset, zoffset, x, y, width, height);
8362
8363 try
8364 {
8365 gl::Context *context = gl::getNonLostContext();
8366
8367 if (context)
8368 {
8369 if (context->getClientVersion() < 3)
8370 {
8371 return gl::error(GL_INVALID_OPERATION);
8372 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008373
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008374 if (!validateES3CopyTexImageParameters(context, target, level, GL_NONE, false, xoffset, yoffset, zoffset,
8375 x, y, width, height, 0))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008376 {
8377 return;
8378 }
8379
8380 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
8381 gl::Texture *texture = NULL;
8382 switch (target)
8383 {
8384 case GL_TEXTURE_3D:
8385 texture = context->getTexture3D();
8386 break;
8387
8388 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008389 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008390 break;
8391
8392 default:
8393 return gl::error(GL_INVALID_ENUM);
8394 }
8395
8396 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
8397 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008398 }
8399 catch(std::bad_alloc&)
8400 {
8401 return gl::error(GL_OUT_OF_MEMORY);
8402 }
8403}
8404
8405void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
8406{
8407 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
8408 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
8409 "const GLvoid* data = 0x%0.8p)",
8410 target, level, internalformat, width, height, depth, border, imageSize, data);
8411
8412 try
8413 {
8414 gl::Context *context = gl::getNonLostContext();
8415
8416 if (context)
8417 {
8418 if (context->getClientVersion() < 3)
8419 {
8420 return gl::error(GL_INVALID_OPERATION);
8421 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008422
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008423 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 +00008424 {
8425 return gl::error(GL_INVALID_VALUE);
8426 }
8427
8428 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008429 if (!validateES3TexImageParameters(context, target, level, internalformat, true, false,
8430 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008431 {
8432 return;
8433 }
8434
8435 switch(target)
8436 {
8437 case GL_TEXTURE_3D:
8438 {
8439 gl::Texture3D *texture = context->getTexture3D();
8440 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8441 }
8442 break;
8443
8444 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008445 {
8446 gl::Texture2DArray *texture = context->getTexture2DArray();
8447 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
8448 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008449 break;
8450
8451 default:
8452 return gl::error(GL_INVALID_ENUM);
8453 }
8454 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008455 }
8456 catch(std::bad_alloc&)
8457 {
8458 return gl::error(GL_OUT_OF_MEMORY);
8459 }
8460}
8461
8462void __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)
8463{
8464 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
8465 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
8466 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
8467 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
8468
8469 try
8470 {
8471 gl::Context *context = gl::getNonLostContext();
8472
8473 if (context)
8474 {
8475 if (context->getClientVersion() < 3)
8476 {
8477 return gl::error(GL_INVALID_OPERATION);
8478 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008479
shannonwoods@chromium.org8dcfc6a2013-05-30 00:09:48 +00008480 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 +00008481 {
8482 return gl::error(GL_INVALID_VALUE);
8483 }
8484
8485 if (!data)
8486 {
8487 return gl::error(GL_INVALID_VALUE);
8488 }
8489
8490 // validateES3TexImageFormat sets the error code if there is an error
shannonwoods@chromium.org6cf2b0e2013-05-30 00:13:36 +00008491 if (!validateES3TexImageParameters(context, target, level, GL_NONE, true, true,
8492 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008493 {
8494 return;
8495 }
8496
8497 switch(target)
8498 {
8499 case GL_TEXTURE_3D:
8500 {
8501 gl::Texture3D *texture = context->getTexture3D();
8502 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8503 format, imageSize, data);
8504 }
8505 break;
8506
8507 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00008508 {
8509 gl::Texture2DArray *texture = context->getTexture2DArray();
8510 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
8511 format, imageSize, data);
8512 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00008513 break;
8514
8515 default:
8516 return gl::error(GL_INVALID_ENUM);
8517 }
8518 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008519 }
8520 catch(std::bad_alloc&)
8521 {
8522 return gl::error(GL_OUT_OF_MEMORY);
8523 }
8524}
8525
8526void __stdcall glGenQueries(GLsizei n, GLuint* ids)
8527{
8528 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8529
8530 try
8531 {
8532 gl::Context *context = gl::getNonLostContext();
8533
8534 if (context)
8535 {
8536 if (context->getClientVersion() < 3)
8537 {
8538 return gl::error(GL_INVALID_OPERATION);
8539 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008540
Jamie Madill54133512013-06-21 09:33:07 -04008541 // glGenQueries
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008542 UNIMPLEMENTED();
8543 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008544 }
8545 catch(std::bad_alloc&)
8546 {
8547 return gl::error(GL_OUT_OF_MEMORY);
8548 }
8549}
8550
8551void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
8552{
8553 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8554
8555 try
8556 {
8557 gl::Context *context = gl::getNonLostContext();
8558
8559 if (context)
8560 {
8561 if (context->getClientVersion() < 3)
8562 {
8563 return gl::error(GL_INVALID_OPERATION);
8564 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008565
Jamie Madill54133512013-06-21 09:33:07 -04008566 // glDeleteQueries
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008567 UNIMPLEMENTED();
8568 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008569 }
8570 catch(std::bad_alloc&)
8571 {
8572 return gl::error(GL_OUT_OF_MEMORY);
8573 }
8574}
8575
8576GLboolean __stdcall glIsQuery(GLuint id)
8577{
8578 EVENT("(GLuint id = %u)", id);
8579
8580 try
8581 {
8582 gl::Context *context = gl::getNonLostContext();
8583
8584 if (context)
8585 {
8586 if (context->getClientVersion() < 3)
8587 {
8588 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8589 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008590
Jamie Madill54133512013-06-21 09:33:07 -04008591 // glIsQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008592 UNIMPLEMENTED();
8593 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008594 }
8595 catch(std::bad_alloc&)
8596 {
8597 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8598 }
8599
8600 return GL_FALSE;
8601}
8602
8603void __stdcall glBeginQuery(GLenum target, GLuint id)
8604{
8605 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8606
8607 try
8608 {
8609 gl::Context *context = gl::getNonLostContext();
8610
8611 if (context)
8612 {
8613 if (context->getClientVersion() < 3)
8614 {
8615 return gl::error(GL_INVALID_OPERATION);
8616 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008617
Jamie Madill54133512013-06-21 09:33:07 -04008618 // glBeginQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008619 UNIMPLEMENTED();
8620 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008621 }
8622 catch(std::bad_alloc&)
8623 {
8624 return gl::error(GL_OUT_OF_MEMORY);
8625 }
8626}
8627
8628void __stdcall glEndQuery(GLenum target)
8629{
8630 EVENT("(GLenum target = 0x%X)", target);
8631
8632 try
8633 {
8634 gl::Context *context = gl::getNonLostContext();
8635
8636 if (context)
8637 {
8638 if (context->getClientVersion() < 3)
8639 {
8640 return gl::error(GL_INVALID_OPERATION);
8641 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008642
Jamie Madill54133512013-06-21 09:33:07 -04008643 // glEndQuery
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008644 UNIMPLEMENTED();
8645 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008646 }
8647 catch(std::bad_alloc&)
8648 {
8649 return gl::error(GL_OUT_OF_MEMORY);
8650 }
8651}
8652
8653void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
8654{
8655 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
8656
8657 try
8658 {
8659 gl::Context *context = gl::getNonLostContext();
8660
8661 if (context)
8662 {
8663 if (context->getClientVersion() < 3)
8664 {
8665 return gl::error(GL_INVALID_OPERATION);
8666 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008667
Jamie Madill54133512013-06-21 09:33:07 -04008668 // glGetQueryiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008669 UNIMPLEMENTED();
8670 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008671 }
8672 catch(std::bad_alloc&)
8673 {
8674 return gl::error(GL_OUT_OF_MEMORY);
8675 }
8676}
8677
8678void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
8679{
8680 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
8681
8682 try
8683 {
8684 gl::Context *context = gl::getNonLostContext();
8685
8686 if (context)
8687 {
8688 if (context->getClientVersion() < 3)
8689 {
8690 return gl::error(GL_INVALID_OPERATION);
8691 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008692
Jamie Madill54133512013-06-21 09:33:07 -04008693 // glGetQueryObjectuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008694 UNIMPLEMENTED();
8695 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008696 }
8697 catch(std::bad_alloc&)
8698 {
8699 return gl::error(GL_OUT_OF_MEMORY);
8700 }
8701}
8702
8703GLboolean __stdcall glUnmapBuffer(GLenum target)
8704{
8705 EVENT("(GLenum target = 0x%X)", target);
8706
8707 try
8708 {
8709 gl::Context *context = gl::getNonLostContext();
8710
8711 if (context)
8712 {
8713 if (context->getClientVersion() < 3)
8714 {
8715 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8716 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008717
Jamie Madill54133512013-06-21 09:33:07 -04008718 // glUnmapBuffer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008719 UNIMPLEMENTED();
8720 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008721 }
8722 catch(std::bad_alloc&)
8723 {
8724 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8725 }
8726
8727 return GL_FALSE;
8728}
8729
8730void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
8731{
8732 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8733
8734 try
8735 {
8736 gl::Context *context = gl::getNonLostContext();
8737
8738 if (context)
8739 {
8740 if (context->getClientVersion() < 3)
8741 {
8742 return gl::error(GL_INVALID_OPERATION);
8743 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008744
Jamie Madill54133512013-06-21 09:33:07 -04008745 // glGetBufferPointerv
shannonwoods@chromium.org2d2190a2013-05-30 00:17:35 +00008746 UNIMPLEMENTED();
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008747 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008748 }
8749 catch(std::bad_alloc&)
8750 {
8751 return gl::error(GL_OUT_OF_MEMORY);
8752 }
8753}
8754
8755void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8756{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008757 try
8758 {
8759 gl::Context *context = gl::getNonLostContext();
8760
8761 if (context)
8762 {
8763 if (context->getClientVersion() < 3)
8764 {
8765 return gl::error(GL_INVALID_OPERATION);
8766 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008767
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008768 glDrawBuffersEXT(n, bufs);
8769 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008770 }
8771 catch(std::bad_alloc&)
8772 {
8773 return gl::error(GL_OUT_OF_MEMORY);
8774 }
8775}
8776
8777void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8778{
8779 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8780 location, count, transpose, value);
8781
8782 try
8783 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008784 if (count < 0)
8785 {
8786 return gl::error(GL_INVALID_VALUE);
8787 }
8788
8789 if (location == -1)
8790 {
8791 return;
8792 }
8793
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008794 gl::Context *context = gl::getNonLostContext();
8795
8796 if (context)
8797 {
8798 if (context->getClientVersion() < 3)
8799 {
8800 return gl::error(GL_INVALID_OPERATION);
8801 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008802
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008803 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8804 if (!programBinary)
8805 {
8806 return gl::error(GL_INVALID_OPERATION);
8807 }
8808
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008809 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008810 {
8811 return gl::error(GL_INVALID_OPERATION);
8812 }
8813 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008814 }
8815 catch(std::bad_alloc&)
8816 {
8817 return gl::error(GL_OUT_OF_MEMORY);
8818 }
8819}
8820
8821void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8822{
8823 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8824 location, count, transpose, value);
8825
8826 try
8827 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008828 if (count < 0)
8829 {
8830 return gl::error(GL_INVALID_VALUE);
8831 }
8832
8833 if (location == -1)
8834 {
8835 return;
8836 }
8837
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008838 gl::Context *context = gl::getNonLostContext();
8839
8840 if (context)
8841 {
8842 if (context->getClientVersion() < 3)
8843 {
8844 return gl::error(GL_INVALID_OPERATION);
8845 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008846
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008847 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8848 if (!programBinary)
8849 {
8850 return gl::error(GL_INVALID_OPERATION);
8851 }
8852
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008853 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008854 {
8855 return gl::error(GL_INVALID_OPERATION);
8856 }
8857 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008858 }
8859 catch(std::bad_alloc&)
8860 {
8861 return gl::error(GL_OUT_OF_MEMORY);
8862 }
8863}
8864
8865void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8866{
8867 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8868 location, count, transpose, value);
8869
8870 try
8871 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008872 if (count < 0)
8873 {
8874 return gl::error(GL_INVALID_VALUE);
8875 }
8876
8877 if (location == -1)
8878 {
8879 return;
8880 }
8881
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008882 gl::Context *context = gl::getNonLostContext();
8883
8884 if (context)
8885 {
8886 if (context->getClientVersion() < 3)
8887 {
8888 return gl::error(GL_INVALID_OPERATION);
8889 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008890
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008891 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8892 if (!programBinary)
8893 {
8894 return gl::error(GL_INVALID_OPERATION);
8895 }
8896
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008897 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008898 {
8899 return gl::error(GL_INVALID_OPERATION);
8900 }
8901 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008902 }
8903 catch(std::bad_alloc&)
8904 {
8905 return gl::error(GL_OUT_OF_MEMORY);
8906 }
8907}
8908
8909void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8910{
8911 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8912 location, count, transpose, value);
8913
8914 try
8915 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008916 if (count < 0)
8917 {
8918 return gl::error(GL_INVALID_VALUE);
8919 }
8920
8921 if (location == -1)
8922 {
8923 return;
8924 }
8925
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008926 gl::Context *context = gl::getNonLostContext();
8927
8928 if (context)
8929 {
8930 if (context->getClientVersion() < 3)
8931 {
8932 return gl::error(GL_INVALID_OPERATION);
8933 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008934
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008935 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8936 if (!programBinary)
8937 {
8938 return gl::error(GL_INVALID_OPERATION);
8939 }
8940
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008941 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008942 {
8943 return gl::error(GL_INVALID_OPERATION);
8944 }
8945 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008946 }
8947 catch(std::bad_alloc&)
8948 {
8949 return gl::error(GL_OUT_OF_MEMORY);
8950 }
8951}
8952
8953void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8954{
8955 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8956 location, count, transpose, value);
8957
8958 try
8959 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008960 if (count < 0)
8961 {
8962 return gl::error(GL_INVALID_VALUE);
8963 }
8964
8965 if (location == -1)
8966 {
8967 return;
8968 }
8969
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008970 gl::Context *context = gl::getNonLostContext();
8971
8972 if (context)
8973 {
8974 if (context->getClientVersion() < 3)
8975 {
8976 return gl::error(GL_INVALID_OPERATION);
8977 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008978
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008979 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8980 if (!programBinary)
8981 {
8982 return gl::error(GL_INVALID_OPERATION);
8983 }
8984
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008985 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008986 {
8987 return gl::error(GL_INVALID_OPERATION);
8988 }
8989 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008990 }
8991 catch(std::bad_alloc&)
8992 {
8993 return gl::error(GL_OUT_OF_MEMORY);
8994 }
8995}
8996
8997void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8998{
8999 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
9000 location, count, transpose, value);
9001
9002 try
9003 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009004 if (count < 0)
9005 {
9006 return gl::error(GL_INVALID_VALUE);
9007 }
9008
9009 if (location == -1)
9010 {
9011 return;
9012 }
9013
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009014 gl::Context *context = gl::getNonLostContext();
9015
9016 if (context)
9017 {
9018 if (context->getClientVersion() < 3)
9019 {
9020 return gl::error(GL_INVALID_OPERATION);
9021 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009022
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009023 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9024 if (!programBinary)
9025 {
9026 return gl::error(GL_INVALID_OPERATION);
9027 }
9028
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00009029 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00009030 {
9031 return gl::error(GL_INVALID_OPERATION);
9032 }
9033 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009034 }
9035 catch(std::bad_alloc&)
9036 {
9037 return gl::error(GL_OUT_OF_MEMORY);
9038 }
9039}
9040
9041void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
9042{
9043 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
9044 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
9045 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
9046
9047 try
9048 {
9049 gl::Context *context = gl::getNonLostContext();
9050
9051 if (context)
9052 {
9053 if (context->getClientVersion() < 3)
9054 {
9055 return gl::error(GL_INVALID_OPERATION);
9056 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009057
Geoff Lang758d5b22013-06-11 11:42:50 -04009058 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
9059 dstX0, dstY0, dstX1, dstY1, mask, filter,
9060 false))
9061 {
9062 return;
9063 }
9064
9065 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
9066 mask, filter);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009067 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009068 }
9069 catch(std::bad_alloc&)
9070 {
9071 return gl::error(GL_OUT_OF_MEMORY);
9072 }
9073}
9074
9075void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
9076{
9077 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
9078 target, samples, internalformat, width, height);
9079
9080 try
9081 {
9082 gl::Context *context = gl::getNonLostContext();
9083
9084 if (context)
9085 {
9086 if (context->getClientVersion() < 3)
9087 {
9088 return gl::error(GL_INVALID_OPERATION);
9089 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009090
Geoff Lang2e1dcd52013-05-29 10:34:08 -04009091 if (!validateRenderbufferStorageParameters(context, target, samples, internalformat,
9092 width, height, false))
9093 {
9094 return;
9095 }
9096
9097 context->setRenderbufferStorage(width, height, internalformat, samples);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009098 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009099 }
9100 catch(std::bad_alloc&)
9101 {
9102 return gl::error(GL_OUT_OF_MEMORY);
9103 }
9104}
9105
9106void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
9107{
9108 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
9109 target, attachment, texture, level, layer);
9110
9111 try
9112 {
9113 gl::Context *context = gl::getNonLostContext();
9114
9115 if (context)
9116 {
9117 if (context->getClientVersion() < 3)
9118 {
9119 return gl::error(GL_INVALID_OPERATION);
9120 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009121
Jamie Madill54133512013-06-21 09:33:07 -04009122 // glFramebufferTextureLayer
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009123 UNIMPLEMENTED();
9124 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009125 }
9126 catch(std::bad_alloc&)
9127 {
9128 return gl::error(GL_OUT_OF_MEMORY);
9129 }
9130}
9131
9132GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
9133{
9134 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
9135 target, offset, length, access);
9136
9137 try
9138 {
9139 gl::Context *context = gl::getNonLostContext();
9140
9141 if (context)
9142 {
9143 if (context->getClientVersion() < 3)
9144 {
9145 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
9146 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009147
Jamie Madill54133512013-06-21 09:33:07 -04009148 // glMapBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009149 UNIMPLEMENTED();
9150 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009151 }
9152 catch(std::bad_alloc&)
9153 {
9154 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
9155 }
9156
9157 return NULL;
9158}
9159
9160void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
9161{
9162 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
9163
9164 try
9165 {
9166 gl::Context *context = gl::getNonLostContext();
9167
9168 if (context)
9169 {
9170 if (context->getClientVersion() < 3)
9171 {
9172 return gl::error(GL_INVALID_OPERATION);
9173 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009174
Jamie Madill54133512013-06-21 09:33:07 -04009175 // glFlushMappedBufferRange
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009176 UNIMPLEMENTED();
9177 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009178 }
9179 catch(std::bad_alloc&)
9180 {
9181 return gl::error(GL_OUT_OF_MEMORY);
9182 }
9183}
9184
9185void __stdcall glBindVertexArray(GLuint array)
9186{
9187 EVENT("(GLuint array = %u)", array);
9188
9189 try
9190 {
9191 gl::Context *context = gl::getNonLostContext();
9192
9193 if (context)
9194 {
9195 if (context->getClientVersion() < 3)
9196 {
9197 return gl::error(GL_INVALID_OPERATION);
9198 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009199
Jamie Madill54133512013-06-21 09:33:07 -04009200 // glBindVertexArray
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009201 UNIMPLEMENTED();
9202 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009203 }
9204 catch(std::bad_alloc&)
9205 {
9206 return gl::error(GL_OUT_OF_MEMORY);
9207 }
9208}
9209
9210void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
9211{
9212 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
9213
9214 try
9215 {
9216 gl::Context *context = gl::getNonLostContext();
9217
9218 if (context)
9219 {
9220 if (context->getClientVersion() < 3)
9221 {
9222 return gl::error(GL_INVALID_OPERATION);
9223 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009224
Jamie Madill54133512013-06-21 09:33:07 -04009225 // glDeleteVertexArrays
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009226 UNIMPLEMENTED();
9227 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009228 }
9229 catch(std::bad_alloc&)
9230 {
9231 return gl::error(GL_OUT_OF_MEMORY);
9232 }
9233}
9234
9235void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
9236{
9237 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
9238
9239 try
9240 {
9241 gl::Context *context = gl::getNonLostContext();
9242
9243 if (context)
9244 {
9245 if (context->getClientVersion() < 3)
9246 {
9247 return gl::error(GL_INVALID_OPERATION);
9248 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009249
Jamie Madill54133512013-06-21 09:33:07 -04009250 // glGenVertexArrays
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009251 UNIMPLEMENTED();
9252 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009253 }
9254 catch(std::bad_alloc&)
9255 {
9256 return gl::error(GL_OUT_OF_MEMORY);
9257 }
9258}
9259
9260GLboolean __stdcall glIsVertexArray(GLuint array)
9261{
9262 EVENT("(GLuint array = %u)", array);
9263
9264 try
9265 {
9266 gl::Context *context = gl::getNonLostContext();
9267
9268 if (context)
9269 {
9270 if (context->getClientVersion() < 3)
9271 {
9272 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9273 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009274
Jamie Madill54133512013-06-21 09:33:07 -04009275 // glIsVertexArray
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009276 UNIMPLEMENTED();
9277 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009278 }
9279 catch(std::bad_alloc&)
9280 {
9281 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9282 }
9283
9284 return GL_FALSE;
9285}
9286
9287void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
9288{
9289 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
9290 target, index, data);
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
Jamie Madill54133512013-06-21 09:33:07 -04009303 // glGetIntegeri_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009304 UNIMPLEMENTED();
9305 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009306 }
9307 catch(std::bad_alloc&)
9308 {
9309 return gl::error(GL_OUT_OF_MEMORY);
9310 }
9311}
9312
9313void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
9314{
9315 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
9316
9317 try
9318 {
9319 gl::Context *context = gl::getNonLostContext();
9320
9321 if (context)
9322 {
9323 if (context->getClientVersion() < 3)
9324 {
9325 return gl::error(GL_INVALID_OPERATION);
9326 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009327
Jamie Madill54133512013-06-21 09:33:07 -04009328 // glBeginTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009329 UNIMPLEMENTED();
9330 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009331 }
9332 catch(std::bad_alloc&)
9333 {
9334 return gl::error(GL_OUT_OF_MEMORY);
9335 }
9336}
9337
9338void __stdcall glEndTransformFeedback(void)
9339{
9340 EVENT("(void)");
9341
9342 try
9343 {
9344 gl::Context *context = gl::getNonLostContext();
9345
9346 if (context)
9347 {
9348 if (context->getClientVersion() < 3)
9349 {
9350 return gl::error(GL_INVALID_OPERATION);
9351 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009352
Jamie Madill54133512013-06-21 09:33:07 -04009353 // glEndTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009354 UNIMPLEMENTED();
9355 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009356 }
9357 catch(std::bad_alloc&)
9358 {
9359 return gl::error(GL_OUT_OF_MEMORY);
9360 }
9361}
9362
9363void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
9364{
9365 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
9366 target, index, buffer, offset, size);
9367
9368 try
9369 {
9370 gl::Context *context = gl::getNonLostContext();
9371
9372 if (context)
9373 {
9374 if (context->getClientVersion() < 3)
9375 {
9376 return gl::error(GL_INVALID_OPERATION);
9377 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009378
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009379 switch (target)
9380 {
9381 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009382 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009383 {
9384 return gl::error(GL_INVALID_VALUE);
9385 }
9386 break;
9387
9388 case GL_UNIFORM_BUFFER:
9389 if (index >= context->getMaximumCombinedUniformBufferBindings())
9390 {
9391 return gl::error(GL_INVALID_VALUE);
9392 }
9393 break;
9394
9395 default:
9396 return gl::error(GL_INVALID_ENUM);
9397 }
9398
shannonwoods@chromium.orge6e00792013-05-30 00:06:07 +00009399 if (buffer != 0 && size <= 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009400 {
9401 return gl::error(GL_INVALID_VALUE);
9402 }
9403
9404 switch (target)
9405 {
9406 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orga26aeaf2013-05-30 00:06:13 +00009407
9408 // size and offset must be a multiple of 4
9409 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
9410 {
9411 return gl::error(GL_INVALID_VALUE);
9412 }
9413
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009414 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
9415 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009416 break;
9417
9418 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org97c3d502013-05-30 00:04:34 +00009419
9420 // it is an error to bind an offset not a multiple of the alignment
9421 if (buffer != 0 && (offset % context->getUniformBufferOffsetAlignment()) != 0)
9422 {
9423 return gl::error(GL_INVALID_VALUE);
9424 }
9425
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009426 context->bindIndexedUniformBuffer(buffer, index, offset, size);
9427 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009428 break;
9429
9430 default:
9431 UNREACHABLE();
9432 }
9433 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009434 }
9435 catch(std::bad_alloc&)
9436 {
9437 return gl::error(GL_OUT_OF_MEMORY);
9438 }
9439}
9440
9441void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
9442{
9443 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
9444 target, index, buffer);
9445
9446 try
9447 {
9448 gl::Context *context = gl::getNonLostContext();
9449
9450 if (context)
9451 {
9452 if (context->getClientVersion() < 3)
9453 {
9454 return gl::error(GL_INVALID_OPERATION);
9455 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009456
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009457 switch (target)
9458 {
9459 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009460 if (index >= context->getMaxTransformFeedbackBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009461 {
9462 return gl::error(GL_INVALID_VALUE);
9463 }
9464 break;
9465
9466 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.orgd11158f2013-05-30 00:06:19 +00009467 if (index >= context->getMaximumCombinedUniformBufferBindings())
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009468 {
9469 return gl::error(GL_INVALID_VALUE);
9470 }
9471 break;
9472
9473 default:
9474 return gl::error(GL_INVALID_ENUM);
9475 }
9476
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009477 switch (target)
9478 {
9479 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009480 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009481 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009482 break;
9483
9484 case GL_UNIFORM_BUFFER:
shannonwoods@chromium.org3eeca1e2013-05-30 00:04:28 +00009485 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00009486 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00009487 break;
9488
9489 default:
9490 UNREACHABLE();
9491 }
9492 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009493 }
9494 catch(std::bad_alloc&)
9495 {
9496 return gl::error(GL_OUT_OF_MEMORY);
9497 }
9498}
9499
9500void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
9501{
9502 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
9503 program, count, varyings, bufferMode);
9504
9505 try
9506 {
9507 gl::Context *context = gl::getNonLostContext();
9508
9509 if (context)
9510 {
9511 if (context->getClientVersion() < 3)
9512 {
9513 return gl::error(GL_INVALID_OPERATION);
9514 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009515
Jamie Madill54133512013-06-21 09:33:07 -04009516 // glTransformFeedbackVaryings
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009517 UNIMPLEMENTED();
9518 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009519 }
9520 catch(std::bad_alloc&)
9521 {
9522 return gl::error(GL_OUT_OF_MEMORY);
9523 }
9524}
9525
9526void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
9527{
9528 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
9529 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
9530 program, index, bufSize, length, size, type, name);
9531
9532 try
9533 {
9534 gl::Context *context = gl::getNonLostContext();
9535
9536 if (context)
9537 {
9538 if (context->getClientVersion() < 3)
9539 {
9540 return gl::error(GL_INVALID_OPERATION);
9541 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009542
Jamie Madill54133512013-06-21 09:33:07 -04009543 // glGetTransformFeedbackVarying
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009544 UNIMPLEMENTED();
9545 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009546 }
9547 catch(std::bad_alloc&)
9548 {
9549 return gl::error(GL_OUT_OF_MEMORY);
9550 }
9551}
9552
9553void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
9554{
9555 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
9556 index, size, type, stride, pointer);
9557
9558 try
9559 {
9560 gl::Context *context = gl::getNonLostContext();
9561
9562 if (context)
9563 {
9564 if (context->getClientVersion() < 3)
9565 {
9566 return gl::error(GL_INVALID_OPERATION);
9567 }
9568 }
9569
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009570 if (index >= gl::MAX_VERTEX_ATTRIBS)
9571 {
9572 return gl::error(GL_INVALID_VALUE);
9573 }
9574
9575 if (size < 1 || size > 4)
9576 {
9577 return gl::error(GL_INVALID_VALUE);
9578 }
9579
9580 switch (type)
9581 {
9582 case GL_BYTE:
9583 case GL_UNSIGNED_BYTE:
9584 case GL_SHORT:
9585 case GL_UNSIGNED_SHORT:
9586 case GL_INT:
9587 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009588 case GL_INT_2_10_10_10_REV:
9589 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009590 break;
9591 default:
9592 return gl::error(GL_INVALID_ENUM);
9593 }
9594
9595 if (stride < 0)
9596 {
9597 return gl::error(GL_INVALID_VALUE);
9598 }
9599
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00009600 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
9601 {
9602 return gl::error(GL_INVALID_OPERATION);
9603 }
9604
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009605 if (context)
9606 {
9607 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
9608 stride, pointer);
9609 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009610 }
9611 catch(std::bad_alloc&)
9612 {
9613 return gl::error(GL_OUT_OF_MEMORY);
9614 }
9615}
9616
9617void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
9618{
9619 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9620 index, pname, params);
9621
9622 try
9623 {
9624 gl::Context *context = gl::getNonLostContext();
9625
9626 if (context)
9627 {
9628 if (context->getClientVersion() < 3)
9629 {
9630 return gl::error(GL_INVALID_OPERATION);
9631 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009632
Jamie Madill54133512013-06-21 09:33:07 -04009633 // glGetVertexAttribIiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009634 UNIMPLEMENTED();
9635 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009636 }
9637 catch(std::bad_alloc&)
9638 {
9639 return gl::error(GL_OUT_OF_MEMORY);
9640 }
9641}
9642
9643void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
9644{
9645 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
9646 index, pname, params);
9647
9648 try
9649 {
9650 gl::Context *context = gl::getNonLostContext();
9651
9652 if (context)
9653 {
9654 if (context->getClientVersion() < 3)
9655 {
9656 return gl::error(GL_INVALID_OPERATION);
9657 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009658
Jamie Madill54133512013-06-21 09:33:07 -04009659 // glGetVertexAttribIuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009660 UNIMPLEMENTED();
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 glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
9670{
9671 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
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 GLint vals[4] = { x, y, z, w };
9691 context->setVertexAttribi(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 glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
9701{
9702 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
9703 index, x, y, z, w);
9704
9705 try
9706 {
9707 gl::Context *context = gl::getNonLostContext();
9708
9709 if (context)
9710 {
9711 if (context->getClientVersion() < 3)
9712 {
9713 return gl::error(GL_INVALID_OPERATION);
9714 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009715
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009716 if (index >= gl::MAX_VERTEX_ATTRIBS)
9717 {
9718 return gl::error(GL_INVALID_VALUE);
9719 }
9720
9721 GLuint vals[4] = { x, y, z, w };
9722 context->setVertexAttribu(index, vals);
9723 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009724 }
9725 catch(std::bad_alloc&)
9726 {
9727 return gl::error(GL_OUT_OF_MEMORY);
9728 }
9729}
9730
9731void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
9732{
9733 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
9734
9735 try
9736 {
9737 gl::Context *context = gl::getNonLostContext();
9738
9739 if (context)
9740 {
9741 if (context->getClientVersion() < 3)
9742 {
9743 return gl::error(GL_INVALID_OPERATION);
9744 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009745
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009746 if (index >= gl::MAX_VERTEX_ATTRIBS)
9747 {
9748 return gl::error(GL_INVALID_VALUE);
9749 }
9750
9751 context->setVertexAttribi(index, v);
9752 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009753 }
9754 catch(std::bad_alloc&)
9755 {
9756 return gl::error(GL_OUT_OF_MEMORY);
9757 }
9758}
9759
9760void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
9761{
9762 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
9763
9764 try
9765 {
9766 gl::Context *context = gl::getNonLostContext();
9767
9768 if (context)
9769 {
9770 if (context->getClientVersion() < 3)
9771 {
9772 return gl::error(GL_INVALID_OPERATION);
9773 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009774
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009775 if (index >= gl::MAX_VERTEX_ATTRIBS)
9776 {
9777 return gl::error(GL_INVALID_VALUE);
9778 }
9779
9780 context->setVertexAttribu(index, v);
9781 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009782 }
9783 catch(std::bad_alloc&)
9784 {
9785 return gl::error(GL_OUT_OF_MEMORY);
9786 }
9787}
9788
9789void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
9790{
9791 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
9792 program, location, params);
9793
9794 try
9795 {
9796 gl::Context *context = gl::getNonLostContext();
9797
9798 if (context)
9799 {
9800 if (context->getClientVersion() < 3)
9801 {
9802 return gl::error(GL_INVALID_OPERATION);
9803 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009804
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00009805 if (program == 0)
9806 {
9807 return gl::error(GL_INVALID_VALUE);
9808 }
9809
9810 gl::Program *programObject = context->getProgram(program);
9811
9812 if (!programObject || !programObject->isLinked())
9813 {
9814 return gl::error(GL_INVALID_OPERATION);
9815 }
9816
9817 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9818 if (!programBinary)
9819 {
9820 return gl::error(GL_INVALID_OPERATION);
9821 }
9822
9823 if (!programBinary->getUniformuiv(location, NULL, params))
9824 {
9825 return gl::error(GL_INVALID_OPERATION);
9826 }
9827 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009828 }
9829 catch(std::bad_alloc&)
9830 {
9831 return gl::error(GL_OUT_OF_MEMORY);
9832 }
9833}
9834
9835GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
9836{
9837 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
9838 program, name);
9839
9840 try
9841 {
9842 gl::Context *context = gl::getNonLostContext();
9843
9844 if (context)
9845 {
9846 if (context->getClientVersion() < 3)
9847 {
Jamie Madilld1e78c92013-06-20 11:55:50 -04009848 return gl::error(GL_INVALID_OPERATION, -1);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009849 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009850
Jamie Madilld1e78c92013-06-20 11:55:50 -04009851 if (program == 0)
9852 {
9853 return gl::error(GL_INVALID_VALUE, -1);
9854 }
9855
9856 gl::Program *programObject = context->getProgram(program);
9857
9858 if (!programObject || !programObject->isLinked())
9859 {
9860 return gl::error(GL_INVALID_OPERATION, -1);
9861 }
9862
9863 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9864 if (!programBinary)
9865 {
9866 return gl::error(GL_INVALID_OPERATION, -1);
9867 }
9868
9869 return programBinary->getFragDataLocation(name);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00009870 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009871 }
9872 catch(std::bad_alloc&)
9873 {
9874 return gl::error(GL_OUT_OF_MEMORY, 0);
9875 }
9876
9877 return 0;
9878}
9879
9880void __stdcall glUniform1ui(GLint location, GLuint v0)
9881{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009882 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009883}
9884
9885void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
9886{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009887 const GLuint xy[] = { v0, v1 };
9888 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009889}
9890
9891void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
9892{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009893 const GLuint xyz[] = { v0, v1, v2 };
9894 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009895}
9896
9897void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
9898{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009899 const GLuint xyzw[] = { v0, v1, v2, v3 };
9900 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009901}
9902
9903void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
9904{
9905 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9906 location, count, value);
9907
9908 try
9909 {
9910 gl::Context *context = gl::getNonLostContext();
9911
9912 if (context)
9913 {
9914 if (context->getClientVersion() < 3)
9915 {
9916 return gl::error(GL_INVALID_OPERATION);
9917 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009918
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009919 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9920 if (!programBinary)
9921 {
9922 return gl::error(GL_INVALID_OPERATION);
9923 }
9924
9925 if (!programBinary->setUniform1uiv(location, count, value))
9926 {
9927 return gl::error(GL_INVALID_OPERATION);
9928 }
9929 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009930 }
9931 catch(std::bad_alloc&)
9932 {
9933 return gl::error(GL_OUT_OF_MEMORY);
9934 }
9935}
9936
9937void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
9938{
9939 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9940 location, count, value);
9941
9942 try
9943 {
9944 gl::Context *context = gl::getNonLostContext();
9945
9946 if (context)
9947 {
9948 if (context->getClientVersion() < 3)
9949 {
9950 return gl::error(GL_INVALID_OPERATION);
9951 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009952
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009953 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9954 if (!programBinary)
9955 {
9956 return gl::error(GL_INVALID_OPERATION);
9957 }
9958
9959 if (!programBinary->setUniform2uiv(location, count, value))
9960 {
9961 return gl::error(GL_INVALID_OPERATION);
9962 }
9963 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009964 }
9965 catch(std::bad_alloc&)
9966 {
9967 return gl::error(GL_OUT_OF_MEMORY);
9968 }
9969}
9970
9971void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
9972{
9973 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
9974 location, count, value);
9975
9976 try
9977 {
9978 gl::Context *context = gl::getNonLostContext();
9979
9980 if (context)
9981 {
9982 if (context->getClientVersion() < 3)
9983 {
9984 return gl::error(GL_INVALID_OPERATION);
9985 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009986
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009987 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9988 if (!programBinary)
9989 {
9990 return gl::error(GL_INVALID_OPERATION);
9991 }
9992
9993 if (!programBinary->setUniform3uiv(location, count, value))
9994 {
9995 return gl::error(GL_INVALID_OPERATION);
9996 }
9997 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009998 }
9999 catch(std::bad_alloc&)
10000 {
10001 return gl::error(GL_OUT_OF_MEMORY);
10002 }
10003}
10004
10005void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
10006{
10007 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
10008 location, count, value);
10009
10010 try
10011 {
10012 gl::Context *context = gl::getNonLostContext();
10013
10014 if (context)
10015 {
10016 if (context->getClientVersion() < 3)
10017 {
10018 return gl::error(GL_INVALID_OPERATION);
10019 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010020
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +000010021 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
10022 if (!programBinary)
10023 {
10024 return gl::error(GL_INVALID_OPERATION);
10025 }
10026
10027 if (!programBinary->setUniform4uiv(location, count, value))
10028 {
10029 return gl::error(GL_INVALID_OPERATION);
10030 }
10031 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010032 }
10033 catch(std::bad_alloc&)
10034 {
10035 return gl::error(GL_OUT_OF_MEMORY);
10036 }
10037}
10038
10039void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
10040{
10041 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
10042 buffer, drawbuffer, value);
10043
10044 try
10045 {
10046 gl::Context *context = gl::getNonLostContext();
10047
10048 if (context)
10049 {
10050 if (context->getClientVersion() < 3)
10051 {
10052 return gl::error(GL_INVALID_OPERATION);
10053 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010054
Jamie Madill54133512013-06-21 09:33:07 -040010055 // glClearBufferiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010056 UNIMPLEMENTED();
10057 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010058 }
10059 catch(std::bad_alloc&)
10060 {
10061 return gl::error(GL_OUT_OF_MEMORY);
10062 }
10063}
10064
10065void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
10066{
10067 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
10068 buffer, drawbuffer, value);
10069
10070 try
10071 {
10072 gl::Context *context = gl::getNonLostContext();
10073
10074 if (context)
10075 {
10076 if (context->getClientVersion() < 3)
10077 {
10078 return gl::error(GL_INVALID_OPERATION);
10079 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010080
Jamie Madill54133512013-06-21 09:33:07 -040010081 // glClearBufferuiv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010082 UNIMPLEMENTED();
10083 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010084 }
10085 catch(std::bad_alloc&)
10086 {
10087 return gl::error(GL_OUT_OF_MEMORY);
10088 }
10089}
10090
10091void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
10092{
10093 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
10094 buffer, drawbuffer, value);
10095
10096 try
10097 {
10098 gl::Context *context = gl::getNonLostContext();
10099
10100 if (context)
10101 {
10102 if (context->getClientVersion() < 3)
10103 {
10104 return gl::error(GL_INVALID_OPERATION);
10105 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010106
Jamie Madill54133512013-06-21 09:33:07 -040010107 // glClearBufferfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010108 UNIMPLEMENTED();
10109 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010110 }
10111 catch(std::bad_alloc&)
10112 {
10113 return gl::error(GL_OUT_OF_MEMORY);
10114 }
10115}
10116
10117void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
10118{
10119 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
10120 buffer, drawbuffer, depth, stencil);
10121
10122 try
10123 {
10124 gl::Context *context = gl::getNonLostContext();
10125
10126 if (context)
10127 {
10128 if (context->getClientVersion() < 3)
10129 {
10130 return gl::error(GL_INVALID_OPERATION);
10131 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010132
Jamie Madill54133512013-06-21 09:33:07 -040010133 // glClearBufferfi
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010134 UNIMPLEMENTED();
10135 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010136 }
10137 catch(std::bad_alloc&)
10138 {
10139 return gl::error(GL_OUT_OF_MEMORY);
10140 }
10141}
10142
10143const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
10144{
10145 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
10146
10147 try
10148 {
10149 gl::Context *context = gl::getNonLostContext();
10150
10151 if (context)
10152 {
10153 if (context->getClientVersion() < 3)
10154 {
10155 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
10156 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010157
shannonwoods@chromium.org302df742013-05-30 00:05:54 +000010158 if (name != GL_EXTENSIONS)
10159 {
10160 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLubyte*>(NULL));
10161 }
10162
10163 if (index >= context->getNumExtensions())
10164 {
10165 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLubyte*>(NULL));
10166 }
10167
10168 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index));
10169 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010170 }
10171 catch(std::bad_alloc&)
10172 {
10173 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
10174 }
10175
10176 return NULL;
10177}
10178
10179void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
10180{
10181 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
10182 readTarget, writeTarget, readOffset, writeOffset, size);
10183
10184 try
10185 {
10186 gl::Context *context = gl::getNonLostContext();
10187
10188 if (context)
10189 {
10190 if (context->getClientVersion() < 3)
10191 {
10192 return gl::error(GL_INVALID_OPERATION);
10193 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010194
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010195 gl::Buffer *readBuffer = NULL;
10196 switch (readTarget)
10197 {
10198 case GL_ARRAY_BUFFER:
10199 readBuffer = context->getArrayBuffer();
10200 break;
10201 case GL_COPY_READ_BUFFER:
10202 readBuffer = context->getCopyReadBuffer();
10203 break;
10204 case GL_COPY_WRITE_BUFFER:
10205 readBuffer = context->getCopyWriteBuffer();
10206 break;
10207 case GL_ELEMENT_ARRAY_BUFFER:
10208 readBuffer = context->getElementArrayBuffer();
10209 break;
10210 case GL_PIXEL_PACK_BUFFER:
10211 readBuffer = context->getPixelPackBuffer();
10212 break;
10213 case GL_PIXEL_UNPACK_BUFFER:
10214 readBuffer = context->getPixelUnpackBuffer();
10215 break;
10216 case GL_TRANSFORM_FEEDBACK_BUFFER:
10217 readBuffer = context->getGenericTransformFeedbackBuffer();
10218 break;
10219 case GL_UNIFORM_BUFFER:
10220 readBuffer = context->getGenericUniformBuffer();
10221 break;
10222 default:
10223 return gl::error(GL_INVALID_ENUM);
10224 }
10225
10226 gl::Buffer *writeBuffer = NULL;
10227 switch (writeTarget)
10228 {
10229 case GL_ARRAY_BUFFER:
10230 writeBuffer = context->getArrayBuffer();
10231 break;
10232 case GL_COPY_READ_BUFFER:
10233 writeBuffer = context->getCopyReadBuffer();
10234 break;
10235 case GL_COPY_WRITE_BUFFER:
10236 writeBuffer = context->getCopyWriteBuffer();
10237 break;
10238 case GL_ELEMENT_ARRAY_BUFFER:
10239 writeBuffer = context->getElementArrayBuffer();
10240 break;
10241 case GL_PIXEL_PACK_BUFFER:
10242 writeBuffer = context->getPixelPackBuffer();
10243 break;
10244 case GL_PIXEL_UNPACK_BUFFER:
10245 writeBuffer = context->getPixelUnpackBuffer();
10246 break;
10247 case GL_TRANSFORM_FEEDBACK_BUFFER:
10248 writeBuffer = context->getGenericTransformFeedbackBuffer();
10249 break;
10250 case GL_UNIFORM_BUFFER:
10251 writeBuffer = context->getGenericUniformBuffer();
10252 break;
10253 default:
10254 return gl::error(GL_INVALID_ENUM);
10255 }
10256
10257 if (!readBuffer || !writeBuffer)
10258 {
10259 return gl::error(GL_INVALID_OPERATION);
10260 }
10261
10262 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
10263 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
10264 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
10265 {
10266 return gl::error(GL_INVALID_VALUE);
10267 }
10268
10269 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
10270 {
10271 return gl::error(GL_INVALID_VALUE);
10272 }
10273
10274 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
10275
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +000010276 // if size is zero, the copy is a successful no-op
10277 if (size > 0)
10278 {
10279 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
10280 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +000010281 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010282 }
10283 catch(std::bad_alloc&)
10284 {
10285 return gl::error(GL_OUT_OF_MEMORY);
10286 }
10287}
10288
10289void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
10290{
10291 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
10292 program, uniformCount, uniformNames, uniformIndices);
10293
10294 try
10295 {
10296 gl::Context *context = gl::getNonLostContext();
10297
10298 if (context)
10299 {
10300 if (context->getClientVersion() < 3)
10301 {
10302 return gl::error(GL_INVALID_OPERATION);
10303 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010304
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +000010305 if (uniformCount < 0)
10306 {
10307 return gl::error(GL_INVALID_VALUE);
10308 }
10309
10310 gl::Program *programObject = context->getProgram(program);
10311
10312 if (!programObject)
10313 {
10314 if (context->getShader(program))
10315 {
10316 return gl::error(GL_INVALID_OPERATION);
10317 }
10318 else
10319 {
10320 return gl::error(GL_INVALID_VALUE);
10321 }
10322 }
10323
10324 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10325 if (!programObject->isLinked() || !programBinary)
10326 {
10327 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10328 {
10329 uniformIndices[uniformId] = GL_INVALID_INDEX;
10330 }
10331 }
10332 else
10333 {
10334 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10335 {
10336 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
10337 }
10338 }
10339 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010340 }
10341 catch(std::bad_alloc&)
10342 {
10343 return gl::error(GL_OUT_OF_MEMORY);
10344 }
10345}
10346
10347void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
10348{
10349 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10350 program, uniformCount, uniformIndices, pname, params);
10351
10352 try
10353 {
10354 gl::Context *context = gl::getNonLostContext();
10355
10356 if (context)
10357 {
10358 if (context->getClientVersion() < 3)
10359 {
10360 return gl::error(GL_INVALID_OPERATION);
10361 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010362
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +000010363 if (uniformCount < 0)
10364 {
10365 return gl::error(GL_INVALID_VALUE);
10366 }
10367
10368 gl::Program *programObject = context->getProgram(program);
10369
10370 if (!programObject)
10371 {
10372 if (context->getShader(program))
10373 {
10374 return gl::error(GL_INVALID_OPERATION);
10375 }
10376 else
10377 {
10378 return gl::error(GL_INVALID_VALUE);
10379 }
10380 }
10381
10382 switch (pname)
10383 {
10384 case GL_UNIFORM_TYPE:
10385 case GL_UNIFORM_SIZE:
10386 case GL_UNIFORM_NAME_LENGTH:
10387 case GL_UNIFORM_BLOCK_INDEX:
10388 case GL_UNIFORM_OFFSET:
10389 case GL_UNIFORM_ARRAY_STRIDE:
10390 case GL_UNIFORM_MATRIX_STRIDE:
10391 case GL_UNIFORM_IS_ROW_MAJOR:
10392 break;
10393 default:
10394 return gl::error(GL_INVALID_ENUM);
10395 }
10396
10397 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10398
10399 if (!programBinary && uniformCount > 0)
10400 {
10401 return gl::error(GL_INVALID_VALUE);
10402 }
10403
10404 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10405 {
10406 const GLuint index = uniformIndices[uniformId];
10407
10408 if (index >= (GLuint)programBinary->getActiveUniformCount())
10409 {
10410 return gl::error(GL_INVALID_VALUE);
10411 }
10412 }
10413
10414 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
10415 {
10416 const GLuint index = uniformIndices[uniformId];
10417 params[uniformId] = programBinary->getActiveUniformi(index, pname);
10418 }
10419 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010420 }
10421 catch(std::bad_alloc&)
10422 {
10423 return gl::error(GL_OUT_OF_MEMORY);
10424 }
10425}
10426
10427GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
10428{
10429 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
10430
10431 try
10432 {
10433 gl::Context *context = gl::getNonLostContext();
10434
10435 if (context)
10436 {
10437 if (context->getClientVersion() < 3)
10438 {
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010439 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010440 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010441
shannonwoods@chromium.org42766252013-05-30 00:07:12 +000010442 gl::Program *programObject = context->getProgram(program);
10443
10444 if (!programObject)
10445 {
10446 if (context->getShader(program))
10447 {
10448 return gl::error(GL_INVALID_OPERATION, GL_INVALID_INDEX);
10449 }
10450 else
10451 {
10452 return gl::error(GL_INVALID_VALUE, GL_INVALID_INDEX);
10453 }
10454 }
10455
10456 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10457 if (!programBinary)
10458 {
10459 return GL_INVALID_INDEX;
10460 }
10461
10462 return programBinary->getUniformBlockIndex(uniformBlockName);
10463 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010464 }
10465 catch(std::bad_alloc&)
10466 {
10467 return gl::error(GL_OUT_OF_MEMORY, 0);
10468 }
10469
10470 return 0;
10471}
10472
10473void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
10474{
10475 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
10476 program, uniformBlockIndex, pname, params);
10477
10478 try
10479 {
10480 gl::Context *context = gl::getNonLostContext();
10481
10482 if (context)
10483 {
10484 if (context->getClientVersion() < 3)
10485 {
10486 return gl::error(GL_INVALID_OPERATION);
10487 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010488 gl::Program *programObject = context->getProgram(program);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010489
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +000010490 if (!programObject)
10491 {
10492 if (context->getShader(program))
10493 {
10494 return gl::error(GL_INVALID_OPERATION);
10495 }
10496 else
10497 {
10498 return gl::error(GL_INVALID_VALUE);
10499 }
10500 }
10501
10502 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10503
10504 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10505 {
10506 return gl::error(GL_INVALID_VALUE);
10507 }
10508
10509 switch (pname)
10510 {
10511 case GL_UNIFORM_BLOCK_BINDING:
10512 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
10513 break;
10514
10515 case GL_UNIFORM_BLOCK_DATA_SIZE:
10516 case GL_UNIFORM_BLOCK_NAME_LENGTH:
10517 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
10518 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
10519 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
10520 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
10521 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
10522 break;
10523
10524 default:
10525 return gl::error(GL_INVALID_ENUM);
10526 }
10527 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010528 }
10529 catch(std::bad_alloc&)
10530 {
10531 return gl::error(GL_OUT_OF_MEMORY);
10532 }
10533}
10534
10535void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
10536{
10537 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
10538 program, uniformBlockIndex, bufSize, length, uniformBlockName);
10539
10540 try
10541 {
10542 gl::Context *context = gl::getNonLostContext();
10543
10544 if (context)
10545 {
10546 if (context->getClientVersion() < 3)
10547 {
10548 return gl::error(GL_INVALID_OPERATION);
10549 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010550
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +000010551 gl::Program *programObject = context->getProgram(program);
10552
10553 if (!programObject)
10554 {
10555 if (context->getShader(program))
10556 {
10557 return gl::error(GL_INVALID_OPERATION);
10558 }
10559 else
10560 {
10561 return gl::error(GL_INVALID_VALUE);
10562 }
10563 }
10564
10565 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10566
10567 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10568 {
10569 return gl::error(GL_INVALID_VALUE);
10570 }
10571
10572 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
10573 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010574 }
10575 catch(std::bad_alloc&)
10576 {
10577 return gl::error(GL_OUT_OF_MEMORY);
10578 }
10579}
10580
10581void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
10582{
10583 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
10584 program, uniformBlockIndex, uniformBlockBinding);
10585
10586 try
10587 {
10588 gl::Context *context = gl::getNonLostContext();
10589
10590 if (context)
10591 {
10592 if (context->getClientVersion() < 3)
10593 {
10594 return gl::error(GL_INVALID_OPERATION);
10595 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010596
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000010597 if (uniformBlockBinding >= context->getMaximumCombinedUniformBufferBindings())
10598 {
10599 return gl::error(GL_INVALID_VALUE);
10600 }
10601
10602 gl::Program *programObject = context->getProgram(program);
10603
10604 if (!programObject)
10605 {
10606 if (context->getShader(program))
10607 {
10608 return gl::error(GL_INVALID_OPERATION);
10609 }
10610 else
10611 {
10612 return gl::error(GL_INVALID_VALUE);
10613 }
10614 }
10615
10616 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10617
10618 // if never linked, there won't be any uniform blocks
10619 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
10620 {
10621 return gl::error(GL_INVALID_VALUE);
10622 }
10623
10624 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
10625 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010626 }
10627 catch(std::bad_alloc&)
10628 {
10629 return gl::error(GL_OUT_OF_MEMORY);
10630 }
10631}
10632
10633void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
10634{
10635 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
10636 mode, first, count, instanceCount);
10637
10638 try
10639 {
10640 gl::Context *context = gl::getNonLostContext();
10641
10642 if (context)
10643 {
10644 if (context->getClientVersion() < 3)
10645 {
10646 return gl::error(GL_INVALID_OPERATION);
10647 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010648
Jamie Madill54133512013-06-21 09:33:07 -040010649 // glDrawArraysInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010650 UNIMPLEMENTED();
10651 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010652 }
10653 catch(std::bad_alloc&)
10654 {
10655 return gl::error(GL_OUT_OF_MEMORY);
10656 }
10657}
10658
10659void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
10660{
10661 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
10662 mode, count, type, indices, instanceCount);
10663
10664 try
10665 {
10666 gl::Context *context = gl::getNonLostContext();
10667
10668 if (context)
10669 {
10670 if (context->getClientVersion() < 3)
10671 {
10672 return gl::error(GL_INVALID_OPERATION);
10673 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010674
Jamie Madill54133512013-06-21 09:33:07 -040010675 // glDrawElementsInstanced
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010676 UNIMPLEMENTED();
10677 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010678 }
10679 catch(std::bad_alloc&)
10680 {
10681 return gl::error(GL_OUT_OF_MEMORY);
10682 }
10683}
10684
10685GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
10686{
10687 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
10688
10689 try
10690 {
10691 gl::Context *context = gl::getNonLostContext();
10692
10693 if (context)
10694 {
10695 if (context->getClientVersion() < 3)
10696 {
10697 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(NULL));
10698 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010699
Jamie Madill54133512013-06-21 09:33:07 -040010700 // glFenceSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010701 UNIMPLEMENTED();
10702 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010703 }
10704 catch(std::bad_alloc&)
10705 {
10706 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
10707 }
10708
10709 return NULL;
10710}
10711
10712GLboolean __stdcall glIsSync(GLsync sync)
10713{
10714 EVENT("(GLsync sync = 0x%0.8p)", sync);
10715
10716 try
10717 {
10718 gl::Context *context = gl::getNonLostContext();
10719
10720 if (context)
10721 {
10722 if (context->getClientVersion() < 3)
10723 {
10724 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10725 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010726
Jamie Madill54133512013-06-21 09:33:07 -040010727 // glIsSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010728 UNIMPLEMENTED();
10729 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010730 }
10731 catch(std::bad_alloc&)
10732 {
10733 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10734 }
10735
10736 return GL_FALSE;
10737}
10738
10739void __stdcall glDeleteSync(GLsync sync)
10740{
10741 EVENT("(GLsync sync = 0x%0.8p)", sync);
10742
10743 try
10744 {
10745 gl::Context *context = gl::getNonLostContext();
10746
10747 if (context)
10748 {
10749 if (context->getClientVersion() < 3)
10750 {
10751 return gl::error(GL_INVALID_OPERATION);
10752 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010753
Jamie Madill54133512013-06-21 09:33:07 -040010754 // glDeleteSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010755 UNIMPLEMENTED();
10756 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010757 }
10758 catch(std::bad_alloc&)
10759 {
10760 return gl::error(GL_OUT_OF_MEMORY);
10761 }
10762}
10763
10764GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10765{
10766 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10767 sync, flags, timeout);
10768
10769 try
10770 {
10771 gl::Context *context = gl::getNonLostContext();
10772
10773 if (context)
10774 {
10775 if (context->getClientVersion() < 3)
10776 {
10777 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10778 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010779
Jamie Madill54133512013-06-21 09:33:07 -040010780 // glClientWaitSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010781 UNIMPLEMENTED();
10782 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010783 }
10784 catch(std::bad_alloc&)
10785 {
10786 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10787 }
10788
10789 return GL_FALSE;
10790}
10791
10792void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
10793{
10794 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
10795 sync, flags, timeout);
10796
10797 try
10798 {
10799 gl::Context *context = gl::getNonLostContext();
10800
10801 if (context)
10802 {
10803 if (context->getClientVersion() < 3)
10804 {
10805 return gl::error(GL_INVALID_OPERATION);
10806 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010807
Jamie Madill54133512013-06-21 09:33:07 -040010808 // glWaitSync
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010809 UNIMPLEMENTED();
10810 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010811 }
10812 catch(std::bad_alloc&)
10813 {
10814 return gl::error(GL_OUT_OF_MEMORY);
10815 }
10816}
10817
10818void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
10819{
10820 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10821 pname, params);
10822
10823 try
10824 {
10825 gl::Context *context = gl::getNonLostContext();
10826
10827 if (context)
10828 {
10829 if (context->getClientVersion() < 3)
10830 {
10831 return gl::error(GL_INVALID_OPERATION);
10832 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010833
Jamie Madill54133512013-06-21 09:33:07 -040010834 // glGetInteger64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010835 UNIMPLEMENTED();
10836 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010837 }
10838 catch(std::bad_alloc&)
10839 {
10840 return gl::error(GL_OUT_OF_MEMORY);
10841 }
10842}
10843
10844void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
10845{
10846 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
10847 sync, pname, bufSize, length, values);
10848
10849 try
10850 {
10851 gl::Context *context = gl::getNonLostContext();
10852
10853 if (context)
10854 {
10855 if (context->getClientVersion() < 3)
10856 {
10857 return gl::error(GL_INVALID_OPERATION);
10858 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010859
Jamie Madill54133512013-06-21 09:33:07 -040010860 // glGetSynciv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010861 UNIMPLEMENTED();
10862 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010863 }
10864 catch(std::bad_alloc&)
10865 {
10866 return gl::error(GL_OUT_OF_MEMORY);
10867 }
10868}
10869
10870void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
10871{
10872 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
10873 target, index, data);
10874
10875 try
10876 {
10877 gl::Context *context = gl::getNonLostContext();
10878
10879 if (context)
10880 {
10881 if (context->getClientVersion() < 3)
10882 {
10883 return gl::error(GL_INVALID_OPERATION);
10884 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010885
Jamie Madill54133512013-06-21 09:33:07 -040010886 // glGetInteger64i_v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010887 UNIMPLEMENTED();
10888 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010889 }
10890 catch(std::bad_alloc&)
10891 {
10892 return gl::error(GL_OUT_OF_MEMORY);
10893 }
10894}
10895
10896void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
10897{
10898 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
10899 target, pname, params);
10900
10901 try
10902 {
10903 gl::Context *context = gl::getNonLostContext();
10904
10905 if (context)
10906 {
10907 if (context->getClientVersion() < 3)
10908 {
10909 return gl::error(GL_INVALID_OPERATION);
10910 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010911
Jamie Madill54133512013-06-21 09:33:07 -040010912 // glGetBufferParameteri64v
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010913 UNIMPLEMENTED();
10914 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010915 }
10916 catch(std::bad_alloc&)
10917 {
10918 return gl::error(GL_OUT_OF_MEMORY);
10919 }
10920}
10921
10922void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
10923{
10924 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
10925
10926 try
10927 {
10928 gl::Context *context = gl::getNonLostContext();
10929
10930 if (context)
10931 {
10932 if (context->getClientVersion() < 3)
10933 {
10934 return gl::error(GL_INVALID_OPERATION);
10935 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010936
Jamie Madill54133512013-06-21 09:33:07 -040010937 // glGenSamplers
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010938 UNIMPLEMENTED();
10939 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010940 }
10941 catch(std::bad_alloc&)
10942 {
10943 return gl::error(GL_OUT_OF_MEMORY);
10944 }
10945}
10946
10947void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
10948{
10949 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
10950
10951 try
10952 {
10953 gl::Context *context = gl::getNonLostContext();
10954
10955 if (context)
10956 {
10957 if (context->getClientVersion() < 3)
10958 {
10959 return gl::error(GL_INVALID_OPERATION);
10960 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010961
Jamie Madill54133512013-06-21 09:33:07 -040010962 // glDeleteSamplers
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010963 UNIMPLEMENTED();
10964 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010965 }
10966 catch(std::bad_alloc&)
10967 {
10968 return gl::error(GL_OUT_OF_MEMORY);
10969 }
10970}
10971
10972GLboolean __stdcall glIsSampler(GLuint sampler)
10973{
10974 EVENT("(GLuint sampler = %u)", sampler);
10975
10976 try
10977 {
10978 gl::Context *context = gl::getNonLostContext();
10979
10980 if (context)
10981 {
10982 if (context->getClientVersion() < 3)
10983 {
10984 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10985 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010986
Jamie Madill54133512013-06-21 09:33:07 -040010987 // glIsSampler
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000010988 UNIMPLEMENTED();
10989 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010990 }
10991 catch(std::bad_alloc&)
10992 {
10993 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10994 }
10995
10996 return GL_FALSE;
10997}
10998
10999void __stdcall glBindSampler(GLuint unit, GLuint sampler)
11000{
11001 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
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
Jamie Madill54133512013-06-21 09:33:07 -040011014 // glBindSampler
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011015 UNIMPLEMENTED();
11016 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011017 }
11018 catch(std::bad_alloc&)
11019 {
11020 return gl::error(GL_OUT_OF_MEMORY);
11021 }
11022}
11023
11024void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
11025{
11026 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
11027
11028 try
11029 {
11030 gl::Context *context = gl::getNonLostContext();
11031
11032 if (context)
11033 {
11034 if (context->getClientVersion() < 3)
11035 {
11036 return gl::error(GL_INVALID_OPERATION);
11037 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011038
Jamie Madill54133512013-06-21 09:33:07 -040011039 // glSamplerParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011040 UNIMPLEMENTED();
11041 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011042 }
11043 catch(std::bad_alloc&)
11044 {
11045 return gl::error(GL_OUT_OF_MEMORY);
11046 }
11047}
11048
11049void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
11050{
11051 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLint* param = 0x%0.8p)",
11052 sampler, pname, param);
11053
11054 try
11055 {
11056 gl::Context *context = gl::getNonLostContext();
11057
11058 if (context)
11059 {
11060 if (context->getClientVersion() < 3)
11061 {
11062 return gl::error(GL_INVALID_OPERATION);
11063 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011064
Jamie Madill54133512013-06-21 09:33:07 -040011065 // glSamplerParameteriv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011066 UNIMPLEMENTED();
11067 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011068 }
11069 catch(std::bad_alloc&)
11070 {
11071 return gl::error(GL_OUT_OF_MEMORY);
11072 }
11073}
11074
11075void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
11076{
11077 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
11078
11079 try
11080 {
11081 gl::Context *context = gl::getNonLostContext();
11082
11083 if (context)
11084 {
11085 if (context->getClientVersion() < 3)
11086 {
11087 return gl::error(GL_INVALID_OPERATION);
11088 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011089
Jamie Madill54133512013-06-21 09:33:07 -040011090 // glSamplerParameterf
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011091 UNIMPLEMENTED();
11092 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011093 }
11094 catch(std::bad_alloc&)
11095 {
11096 return gl::error(GL_OUT_OF_MEMORY);
11097 }
11098}
11099
11100void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
11101{
11102 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLfloat* param = 0x%0.8p)", sampler, pname, param);
11103
11104 try
11105 {
11106 gl::Context *context = gl::getNonLostContext();
11107
11108 if (context)
11109 {
11110 if (context->getClientVersion() < 3)
11111 {
11112 return gl::error(GL_INVALID_OPERATION);
11113 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011114
Jamie Madill54133512013-06-21 09:33:07 -040011115 // glSamplerParameterfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011116 UNIMPLEMENTED();
11117 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011118 }
11119 catch(std::bad_alloc&)
11120 {
11121 return gl::error(GL_OUT_OF_MEMORY);
11122 }
11123}
11124
11125void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
11126{
11127 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
11128
11129 try
11130 {
11131 gl::Context *context = gl::getNonLostContext();
11132
11133 if (context)
11134 {
11135 if (context->getClientVersion() < 3)
11136 {
11137 return gl::error(GL_INVALID_OPERATION);
11138 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011139
Jamie Madill54133512013-06-21 09:33:07 -040011140 // glGetSamplerParameteriv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011141 UNIMPLEMENTED();
11142 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011143 }
11144 catch(std::bad_alloc&)
11145 {
11146 return gl::error(GL_OUT_OF_MEMORY);
11147 }
11148}
11149
11150void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
11151{
11152 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
11153
11154 try
11155 {
11156 gl::Context *context = gl::getNonLostContext();
11157
11158 if (context)
11159 {
11160 if (context->getClientVersion() < 3)
11161 {
11162 return gl::error(GL_INVALID_OPERATION);
11163 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011164
Jamie Madill54133512013-06-21 09:33:07 -040011165 // glGetSamplerParameterfv
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011166 UNIMPLEMENTED();
11167 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011168 }
11169 catch(std::bad_alloc&)
11170 {
11171 return gl::error(GL_OUT_OF_MEMORY);
11172 }
11173}
11174
11175void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
11176{
11177 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
11178
11179 try
11180 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011181 if (index >= gl::MAX_VERTEX_ATTRIBS)
11182 {
11183 return gl::error(GL_INVALID_VALUE);
11184 }
11185
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011186 gl::Context *context = gl::getNonLostContext();
11187
11188 if (context)
11189 {
11190 if (context->getClientVersion() < 3)
11191 {
11192 return gl::error(GL_INVALID_OPERATION);
11193 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011194
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000011195 context->setVertexAttribDivisor(index, divisor);
11196 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011197 }
11198 catch(std::bad_alloc&)
11199 {
11200 return gl::error(GL_OUT_OF_MEMORY);
11201 }
11202}
11203
11204void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
11205{
11206 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
11207
11208 try
11209 {
11210 gl::Context *context = gl::getNonLostContext();
11211
11212 if (context)
11213 {
11214 if (context->getClientVersion() < 3)
11215 {
11216 return gl::error(GL_INVALID_OPERATION);
11217 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011218
Jamie Madill54133512013-06-21 09:33:07 -040011219 // glBindTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011220 UNIMPLEMENTED();
11221 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011222 }
11223 catch(std::bad_alloc&)
11224 {
11225 return gl::error(GL_OUT_OF_MEMORY);
11226 }
11227}
11228
11229void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
11230{
11231 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
11232
11233 try
11234 {
11235 gl::Context *context = gl::getNonLostContext();
11236
11237 if (context)
11238 {
11239 if (context->getClientVersion() < 3)
11240 {
11241 return gl::error(GL_INVALID_OPERATION);
11242 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011243
Jamie Madill54133512013-06-21 09:33:07 -040011244 // glDeleteTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011245 UNIMPLEMENTED();
11246 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011247 }
11248 catch(std::bad_alloc&)
11249 {
11250 return gl::error(GL_OUT_OF_MEMORY);
11251 }
11252}
11253
11254void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
11255{
11256 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
11257
11258 try
11259 {
11260 gl::Context *context = gl::getNonLostContext();
11261
11262 if (context)
11263 {
11264 if (context->getClientVersion() < 3)
11265 {
11266 return gl::error(GL_INVALID_OPERATION);
11267 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011268
Jamie Madill54133512013-06-21 09:33:07 -040011269 // glGenTransformFeedbacks
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011270 UNIMPLEMENTED();
11271 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011272 }
11273 catch(std::bad_alloc&)
11274 {
11275 return gl::error(GL_OUT_OF_MEMORY);
11276 }
11277}
11278
11279GLboolean __stdcall glIsTransformFeedback(GLuint id)
11280{
11281 EVENT("(GLuint id = %u)", id);
11282
11283 try
11284 {
11285 gl::Context *context = gl::getNonLostContext();
11286
11287 if (context)
11288 {
11289 if (context->getClientVersion() < 3)
11290 {
11291 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
11292 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011293
Jamie Madill54133512013-06-21 09:33:07 -040011294 // glIsTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011295 UNIMPLEMENTED();
11296 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011297 }
11298 catch(std::bad_alloc&)
11299 {
11300 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
11301 }
11302
11303 return GL_FALSE;
11304}
11305
11306void __stdcall glPauseTransformFeedback(void)
11307{
11308 EVENT("(void)");
11309
11310 try
11311 {
11312 gl::Context *context = gl::getNonLostContext();
11313
11314 if (context)
11315 {
11316 if (context->getClientVersion() < 3)
11317 {
11318 return gl::error(GL_INVALID_OPERATION);
11319 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011320
Jamie Madill54133512013-06-21 09:33:07 -040011321 // glPauseTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011322 UNIMPLEMENTED();
11323 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011324 }
11325 catch(std::bad_alloc&)
11326 {
11327 return gl::error(GL_OUT_OF_MEMORY);
11328 }
11329}
11330
11331void __stdcall glResumeTransformFeedback(void)
11332{
11333 EVENT("(void)");
11334
11335 try
11336 {
11337 gl::Context *context = gl::getNonLostContext();
11338
11339 if (context)
11340 {
11341 if (context->getClientVersion() < 3)
11342 {
11343 return gl::error(GL_INVALID_OPERATION);
11344 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011345
Jamie Madill54133512013-06-21 09:33:07 -040011346 // glResumeTransformFeedback
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011347 UNIMPLEMENTED();
11348 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011349 }
11350 catch(std::bad_alloc&)
11351 {
11352 return gl::error(GL_OUT_OF_MEMORY);
11353 }
11354}
11355
11356void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
11357{
11358 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
11359 program, bufSize, length, binaryFormat, binary);
11360
11361 try
11362 {
11363 gl::Context *context = gl::getNonLostContext();
11364
11365 if (context)
11366 {
11367 if (context->getClientVersion() < 3)
11368 {
11369 return gl::error(GL_INVALID_OPERATION);
11370 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011371
Jamie Madill54133512013-06-21 09:33:07 -040011372 // glGetProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011373 UNIMPLEMENTED();
11374 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011375 }
11376 catch(std::bad_alloc&)
11377 {
11378 return gl::error(GL_OUT_OF_MEMORY);
11379 }
11380}
11381
11382void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
11383{
11384 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
11385 program, binaryFormat, binary, length);
11386
11387 try
11388 {
11389 gl::Context *context = gl::getNonLostContext();
11390
11391 if (context)
11392 {
11393 if (context->getClientVersion() < 3)
11394 {
11395 return gl::error(GL_INVALID_OPERATION);
11396 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011397
Jamie Madill54133512013-06-21 09:33:07 -040011398 // glProgramBinary
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011399 UNIMPLEMENTED();
11400 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011401 }
11402 catch(std::bad_alloc&)
11403 {
11404 return gl::error(GL_OUT_OF_MEMORY);
11405 }
11406}
11407
11408void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
11409{
11410 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
11411 program, pname, value);
11412
11413 try
11414 {
11415 gl::Context *context = gl::getNonLostContext();
11416
11417 if (context)
11418 {
11419 if (context->getClientVersion() < 3)
11420 {
11421 return gl::error(GL_INVALID_OPERATION);
11422 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011423
Jamie Madill54133512013-06-21 09:33:07 -040011424 // glProgramParameteri
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011425 UNIMPLEMENTED();
11426 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011427 }
11428 catch(std::bad_alloc&)
11429 {
11430 return gl::error(GL_OUT_OF_MEMORY);
11431 }
11432}
11433
11434void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
11435{
11436 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
11437 target, numAttachments, attachments);
11438
11439 try
11440 {
11441 gl::Context *context = gl::getNonLostContext();
11442
11443 if (context)
11444 {
11445 if (context->getClientVersion() < 3)
11446 {
11447 return gl::error(GL_INVALID_OPERATION);
11448 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011449
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011450 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11451 {
11452 return;
11453 }
11454
11455 int maxDimension = context->getMaximumRenderbufferDimension();
11456 context->invalidateFrameBuffer(target, numAttachments, attachments, 0, 0, maxDimension, maxDimension);
11457 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011458 }
11459 catch(std::bad_alloc&)
11460 {
11461 return gl::error(GL_OUT_OF_MEMORY);
11462 }
11463}
11464
11465void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
11466{
11467 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
11468 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
11469 target, numAttachments, attachments, x, y, width, height);
11470
11471 try
11472 {
11473 gl::Context *context = gl::getNonLostContext();
11474
11475 if (context)
11476 {
11477 if (context->getClientVersion() < 3)
11478 {
11479 return gl::error(GL_INVALID_OPERATION);
11480 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011481
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +000011482 if (!validateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
11483 {
11484 return;
11485 }
11486
11487 context->invalidateFrameBuffer(target, numAttachments, attachments, x, y, width, height);
11488 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011489 }
11490 catch(std::bad_alloc&)
11491 {
11492 return gl::error(GL_OUT_OF_MEMORY);
11493 }
11494}
11495
11496void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
11497{
11498 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
11499 target, levels, internalformat, width, height);
11500
11501 try
11502 {
11503 gl::Context *context = gl::getNonLostContext();
11504
11505 if (context)
11506 {
11507 if (context->getClientVersion() < 3)
11508 {
11509 return gl::error(GL_INVALID_OPERATION);
11510 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011511
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011512 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
11513 {
11514 return;
11515 }
11516
11517 switch (target)
11518 {
11519 case GL_TEXTURE_2D:
11520 {
11521 gl::Texture2D *texture2d = context->getTexture2D();
11522 texture2d->storage(levels, internalformat, width, height);
11523 }
11524 break;
11525
11526 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
11527 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
11528 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
11529 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
11530 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
11531 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
11532 {
11533 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
11534 textureCube->storage(levels, internalformat, width);
11535 }
11536 break;
11537
11538 default:
11539 return gl::error(GL_INVALID_ENUM);
11540 }
11541 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011542 }
11543 catch(std::bad_alloc&)
11544 {
11545 return gl::error(GL_OUT_OF_MEMORY);
11546 }
11547}
11548
11549void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
11550{
11551 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
11552 "GLsizei height = %d, GLsizei depth = %d)",
11553 target, levels, internalformat, width, height, depth);
11554
11555 try
11556 {
11557 gl::Context *context = gl::getNonLostContext();
11558
11559 if (context)
11560 {
11561 if (context->getClientVersion() < 3)
11562 {
11563 return gl::error(GL_INVALID_OPERATION);
11564 }
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +000011565
11566 if (!validateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
11567 {
11568 return;
11569 }
11570
11571 switch (target)
11572 {
11573 case GL_TEXTURE_3D:
11574 {
11575 gl::Texture3D *texture3d = context->getTexture3D();
11576 texture3d->storage(levels, internalformat, width, height, depth);
11577 }
11578 break;
11579
11580 case GL_TEXTURE_2D_ARRAY:
11581 {
11582 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
11583 texture2darray->storage(levels, internalformat, width, height, depth);
11584 }
11585 break;
11586
11587 default:
11588 return gl::error(GL_INVALID_ENUM);
11589 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000011590 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011591 }
11592 catch(std::bad_alloc&)
11593 {
11594 return gl::error(GL_OUT_OF_MEMORY);
11595 }
11596}
11597
11598void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
11599{
11600 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
11601 "GLint* params = 0x%0.8p)",
11602 target, internalformat, pname, bufSize, params);
11603
11604 try
11605 {
11606 gl::Context *context = gl::getNonLostContext();
11607
11608 if (context)
11609 {
11610 if (context->getClientVersion() < 3)
11611 {
11612 return gl::error(GL_INVALID_OPERATION);
11613 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011614
Jamie Madill54133512013-06-21 09:33:07 -040011615 // glGetInternalformativ
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +000011616 UNIMPLEMENTED();
11617 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000011618 }
11619 catch(std::bad_alloc&)
11620 {
11621 return gl::error(GL_OUT_OF_MEMORY);
11622 }
11623}
11624
11625// Extension functions
11626
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011627void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
11628 GLbitfield mask, GLenum filter)
11629{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011630 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011631 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
11632 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
11633 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
11634
11635 try
11636 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011637 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011638
11639 if (context)
11640 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011641 if (!validateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
11642 dstX0, dstY0, dstX1, dstY1, mask, filter,
11643 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011644 {
Geoff Lang758d5b22013-06-11 11:42:50 -040011645 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011646 }
11647
Geoff Lang758d5b22013-06-11 11:42:50 -040011648 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
11649 mask, filter);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011650 }
11651 }
11652 catch(std::bad_alloc&)
11653 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011654 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000011655 }
11656}
11657
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011658void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
11659 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011660{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000011661 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000011662 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000011663 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011664 target, level, internalformat, width, height, depth, border, format, type, pixels);
11665
11666 try
11667 {
11668 UNIMPLEMENTED(); // FIXME
11669 }
11670 catch(std::bad_alloc&)
11671 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011672 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011673 }
11674}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011675
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011676void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
11677 GLenum *binaryFormat, void *binary)
11678{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011679 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 +000011680 program, bufSize, length, binaryFormat, binary);
11681
11682 try
11683 {
11684 gl::Context *context = gl::getNonLostContext();
11685
11686 if (context)
11687 {
11688 gl::Program *programObject = context->getProgram(program);
11689
daniel@transgaming.com716056c2012-07-24 18:38:59 +000011690 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011691 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011692 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011693 }
11694
11695 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
11696
11697 if (!programBinary)
11698 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011699 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011700 }
11701
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011702 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011703 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011704 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011705 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000011706
11707 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011708 }
11709 }
11710 catch(std::bad_alloc&)
11711 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011712 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011713 }
11714}
11715
11716void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
11717 const void *binary, GLint length)
11718{
11719 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
11720 program, binaryFormat, binary, length);
11721
11722 try
11723 {
11724 gl::Context *context = gl::getNonLostContext();
11725
11726 if (context)
11727 {
11728 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
11729 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011730 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011731 }
11732
11733 gl::Program *programObject = context->getProgram(program);
11734
11735 if (!programObject)
11736 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011737 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011738 }
11739
daniel@transgaming.com95d29422012-07-24 18:36:10 +000011740 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011741 }
11742 }
11743 catch(std::bad_alloc&)
11744 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011745 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011746 }
11747}
11748
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011749void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
11750{
11751 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
11752
11753 try
11754 {
11755 gl::Context *context = gl::getNonLostContext();
11756
11757 if (context)
11758 {
11759 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
11760 {
11761 return gl::error(GL_INVALID_VALUE);
11762 }
11763
11764 if (context->getDrawFramebufferHandle() == 0)
11765 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011766 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011767 {
11768 return gl::error(GL_INVALID_OPERATION);
11769 }
11770
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011771 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011772 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011773 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011774 }
11775 }
11776 else
11777 {
11778 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11779 {
11780 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
11781 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
11782 {
11783 return gl::error(GL_INVALID_OPERATION);
11784 }
11785 }
11786 }
11787
11788 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
11789
11790 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
11791 {
11792 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
11793 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000011794
11795 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
11796 {
11797 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
11798 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000011799 }
11800 }
11801 catch (std::bad_alloc&)
11802 {
11803 return gl::error(GL_OUT_OF_MEMORY);
11804 }
11805}
11806
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011807__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
11808{
11809 struct Extension
11810 {
11811 const char *name;
11812 __eglMustCastToProperFunctionPointerType address;
11813 };
11814
11815 static const Extension glExtensions[] =
11816 {
11817 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000011818 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000011819 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000011820 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
11821 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
11822 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
11823 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
11824 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
11825 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
11826 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000011827 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000011828 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000011829 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
11830 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
11831 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
11832 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000011833 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
11834 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
11835 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
11836 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
11837 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
11838 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
11839 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000011840 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000011841 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
11842 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
11843 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000011844 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
11845 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011846
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000011847 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000011848 {
11849 if (strcmp(procname, glExtensions[ext].name) == 0)
11850 {
11851 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
11852 }
11853 }
11854
11855 return NULL;
11856}
11857
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000011858// Non-public functions used by EGL
11859
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011860bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011861{
11862 EVENT("(egl::Surface* surface = 0x%0.8p)",
11863 surface);
11864
11865 try
11866 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000011867 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011868
11869 if (context)
11870 {
11871 gl::Texture2D *textureObject = context->getTexture2D();
11872
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011873 if (textureObject->isImmutable())
11874 {
11875 return false;
11876 }
11877
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011878 if (textureObject)
11879 {
11880 textureObject->bindTexImage(surface);
11881 }
11882 }
11883 }
11884 catch(std::bad_alloc&)
11885 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000011886 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011887 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000011888
11889 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000011890}
11891
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011892}