blob: c9b61c82227a6045c1ccebb1c0bae6f892ffdfa4 [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"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000013#include "libGLESv2/utilities.h"
14#include "libGLESv2/Buffer.h"
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000015#include "libGLESv2/Fence.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000016#include "libGLESv2/Framebuffer.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000017#include "libGLESv2/Renderbuffer.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000018#include "libGLESv2/Program.h"
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000019#include "libGLESv2/ProgramBinary.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000020#include "libGLESv2/Texture.h"
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000021#include "libGLESv2/Query.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000022#include "libGLESv2/Context.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000023
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000024bool validImageSize(GLint level, GLsizei width, GLsizei height, GLsizei depth)
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000025{
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000026 if (level < 0 || width < 0 || height < 0 || depth < 0)
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000027 {
28 return false;
29 }
30
31 if (gl::getContext() && gl::getContext()->supportsNonPower2Texture())
32 {
33 return true;
34 }
35
36 if (level == 0)
37 {
38 return true;
39 }
40
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +000041 if (gl::isPow2(width) && gl::isPow2(height) && gl::isPow2(depth))
daniel@transgaming.com4f9ef0d2011-05-30 23:51:19 +000042 {
43 return true;
44 }
45
46 return false;
47}
48
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000049// Verify that format/type are one of the combinations from table 3.4.
50bool checkTextureFormatType(GLenum format, GLenum type)
51{
52 // validate <format> by itself (used as secondary key below)
53 switch (format)
54 {
55 case GL_RGBA:
56 case GL_BGRA_EXT:
57 case GL_RGB:
58 case GL_ALPHA:
59 case GL_LUMINANCE:
60 case GL_LUMINANCE_ALPHA:
61 case GL_DEPTH_COMPONENT:
62 case GL_DEPTH_STENCIL_OES:
63 break;
64 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000065 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000066 }
67
68 // invalid <type> -> sets INVALID_ENUM
69 // invalid <format>+<type> combination -> sets INVALID_OPERATION
70 switch (type)
71 {
72 case GL_UNSIGNED_BYTE:
73 switch (format)
74 {
75 case GL_RGBA:
76 case GL_BGRA_EXT:
77 case GL_RGB:
78 case GL_ALPHA:
79 case GL_LUMINANCE:
80 case GL_LUMINANCE_ALPHA:
81 return true;
82 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000083 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000084 }
85
86 case GL_FLOAT:
87 case GL_HALF_FLOAT_OES:
88 switch (format)
89 {
90 case GL_RGBA:
91 case GL_RGB:
92 case GL_ALPHA:
93 case GL_LUMINANCE:
94 case GL_LUMINANCE_ALPHA:
95 return true;
96 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000097 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +000098 }
99
100 case GL_UNSIGNED_SHORT_4_4_4_4:
101 case GL_UNSIGNED_SHORT_5_5_5_1:
102 switch (format)
103 {
104 case GL_RGBA:
105 return true;
106 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000107 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000108 }
109
110 case GL_UNSIGNED_SHORT_5_6_5:
111 switch (format)
112 {
113 case GL_RGB:
114 return true;
115 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000116 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000117 }
118
119 case GL_UNSIGNED_SHORT:
120 case GL_UNSIGNED_INT:
121 switch (format)
122 {
123 case GL_DEPTH_COMPONENT:
124 return true;
125 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000126 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000127 }
128
129 case GL_UNSIGNED_INT_24_8_OES:
130 switch (format)
131 {
132 case GL_DEPTH_STENCIL_OES:
133 return true;
134 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000135 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000136 }
137
138 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000139 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com8833dd22012-06-05 19:49:58 +0000140 }
141}
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000142
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000143bool validateSubImageParams2D(bool compressed, GLsizei width, GLsizei height,
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000144 GLint xoffset, GLint yoffset, GLint level, GLenum format, GLenum type,
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000145 gl::Texture2D *texture)
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000146{
147 if (!texture)
148 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000149 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000150 }
151
daniel@transgaming.com92f49922012-05-09 15:49:19 +0000152 if (compressed != texture->isCompressed(level))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000153 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000154 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000155 }
156
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000157 if (format != GL_NONE)
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000158 {
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000159 GLenum internalformat = gl::ConvertSizedInternalFormat(format, type);
160 if (internalformat != texture->getInternalFormat(level))
161 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000162 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000163 }
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000164 }
165
166 if (compressed)
167 {
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000168 if ((width % 4 != 0 && width != texture->getWidth(0)) ||
169 (height % 4 != 0 && height != texture->getHeight(0)))
170 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000171 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000172 }
173 }
174
175 if (xoffset + width > texture->getWidth(level) ||
176 yoffset + height > texture->getHeight(level))
177 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000178 return gl::error(GL_INVALID_VALUE, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000179 }
180
181 return true;
182}
183
184bool validateSubImageParamsCube(bool compressed, GLsizei width, GLsizei height,
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000185 GLint xoffset, GLint yoffset, GLenum target, GLint level, GLenum format, GLenum type,
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000186 gl::TextureCubeMap *texture)
187{
188 if (!texture)
189 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000190 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000191 }
192
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000193 if (compressed != texture->isCompressed(target, level))
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000194 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000195 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000196 }
197
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000198 if (format != GL_NONE)
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000199 {
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000200 GLenum internalformat = gl::ConvertSizedInternalFormat(format, type);
201 if (internalformat != texture->getInternalFormat(target, level))
202 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000203 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +0000204 }
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +0000205 }
206
207 if (compressed)
208 {
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000209 if ((width % 4 != 0 && width != texture->getWidth(target, 0)) ||
210 (height % 4 != 0 && height != texture->getHeight(target, 0)))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000211 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000212 return gl::error(GL_INVALID_OPERATION, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000213 }
214 }
215
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000216 if (xoffset + width > texture->getWidth(target, level) ||
217 yoffset + height > texture->getHeight(target, level))
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000218 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000219 return gl::error(GL_INVALID_VALUE, false);
daniel@transgaming.com343373a2011-11-29 19:42:32 +0000220 }
221
222 return true;
223}
224
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000225bool validateES3TexImageFormat(gl::Context *context, GLenum target, GLint level, GLint internalformat, bool isCompressed, bool isSubImage,
226 GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
227 GLint border, GLenum format, GLenum type)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000228{
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000229 // Validate image size
230 if (level < 0 || width < 0 || height < 0 || depth < 0 )
231 {
232 return gl::error(GL_INVALID_VALUE, false);
233 }
234
235 if (isCompressed)
236 {
237 if (width != 1 && width != 2 && width % 4 != 0)
238 {
239 return gl::error(GL_INVALID_OPERATION, false);
240 }
241
242 if (height != 1 && height != 2 && height % 4 != 0)
243 {
244 return gl::error(GL_INVALID_OPERATION, false);
245 }
246 }
247
248 // Verify zero border
249 if (border != 0)
250 {
251 return gl::error(GL_INVALID_VALUE, false);
252 }
253
254 // Validate dimensions based on Context limits and validate the texture
255 if (level > context->getMaximumTextureLevel())
256 {
257 return gl::error(GL_INVALID_VALUE, false);
258 }
259
260 gl::Texture *texture = NULL;
261 bool textureCompressed = false;
262 GLenum textureInternalFormat = GL_NONE;
263 GLint textureLevelWidth = 0;
264 GLint textureLevelHeight = 0;
265 GLint textureLevelDepth = 0;
266 switch (target)
267 {
268 case GL_TEXTURE_2D:
269 {
270 if (width > (context->getMaximum2DTextureDimension() >> level) ||
271 height > (context->getMaximum2DTextureDimension() >> level))
272 {
273 return gl::error(GL_INVALID_VALUE, false);
274 }
275
276 gl::Texture2D *texture2d = context->getTexture2D();
277 if (texture2d)
278 {
279 textureCompressed = texture2d->isCompressed(level);
280 textureInternalFormat = texture2d->getInternalFormat(level);
281 textureLevelWidth = texture2d->getWidth(level);
282 textureLevelHeight = texture2d->getHeight(level);
283 textureLevelDepth = 1;
284 texture = texture2d;
285 }
286 }
287 break;
288
289 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
290 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
291 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
292 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
293 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
294 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
295 {
296 if (width != height)
297 {
298 return gl::error(GL_INVALID_VALUE, false);
299 }
300
301 if (width > (context->getMaximumCubeTextureDimension() >> level))
302 {
303 return gl::error(GL_INVALID_VALUE, false);
304 }
305
306 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
307 if (textureCube)
308 {
309 textureCompressed = textureCube->isCompressed(target, level);
310 textureInternalFormat = textureCube->getInternalFormat(target, level);
311 textureLevelWidth = textureCube->getWidth(target, level);
312 textureLevelHeight = textureCube->getHeight(target, level);
313 textureLevelDepth = 1;
314 texture = textureCube;
315 }
316 }
317 break;
318
319 case GL_TEXTURE_3D:
320 {
321 if (width > (context->getMaximum3DTextureDimension() >> level) ||
322 height > (context->getMaximum3DTextureDimension() >> level) ||
323 depth > (context->getMaximum3DTextureDimension() >> level))
324 {
325 return gl::error(GL_INVALID_VALUE, false);
326 }
327
328 gl::Texture3D *texture3d = context->getTexture3D();
329 if (texture3d)
330 {
331 textureCompressed = texture3d->isCompressed(level);
332 textureInternalFormat = texture3d->getInternalFormat(level);
333 textureLevelWidth = texture3d->getWidth(level);
334 textureLevelHeight = texture3d->getHeight(level);
335 textureLevelDepth = texture3d->getDepth(level);
336 texture = texture3d;
337 }
338 }
339 break;
340
341 default:
342 return gl::error(GL_INVALID_ENUM, false);
343 }
344
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000345 if (!texture)
346 {
347 return gl::error(GL_INVALID_OPERATION, false);
348 }
349
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000350 if (texture->isImmutable())
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000351 {
352 return gl::error(GL_INVALID_OPERATION, false);
353 }
354
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000355 // Validate texture formats
356 GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
357 if (isCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000358 {
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000359 if (!gl::IsValidES3CompressedFormat(actualInternalFormat))
360 {
361 return gl::error(GL_INVALID_ENUM, false);
362 }
363
364 if (target == GL_TEXTURE_3D)
365 {
366 return gl::error(GL_INVALID_OPERATION, false);
367 }
368 }
369 else
370 {
371 GLenum err;
372 if (!gl::IsValidES3FormatCombination(actualInternalFormat, format, type, &err))
373 {
374 return gl::error(err, false);
375 }
376
377 if ((target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY) &&
378 (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL))
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000379 {
380 return gl::error(GL_INVALID_OPERATION, false);
381 }
382 }
383
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000384 // Validate sub image parameters
385 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000386 {
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000387 if (isCompressed != textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000388 {
389 return gl::error(GL_INVALID_OPERATION, false);
390 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000391
392 if (format != GL_NONE)
393 {
394 GLenum internalformat = gl::ConvertSizedInternalFormat(format, type);
395 if (internalformat != textureInternalFormat)
396 {
397 return gl::error(GL_INVALID_OPERATION, false);
398 }
399 }
400
401 if (isCompressed)
402 {
403 if ((width % 4 != 0 && width != textureLevelWidth) ||
404 (height % 4 != 0 && height != textureLevelHeight))
405 {
406 return gl::error(GL_INVALID_OPERATION, false);
407 }
408 }
409
410 if (width == 0 || height == 0 || depth == 0)
411 {
412 return false;
413 }
414
415 if (xoffset < 0 || yoffset < 0 || zoffset < 0)
416 {
417 return gl::error(GL_INVALID_VALUE, false);
418 }
419
420 if (std::numeric_limits<GLsizei>::max() - xoffset < width ||
421 std::numeric_limits<GLsizei>::max() - yoffset < height ||
422 std::numeric_limits<GLsizei>::max() - zoffset < depth)
423 {
424 return gl::error(GL_INVALID_VALUE, false);
425 }
426
427 if (xoffset + width > textureLevelWidth ||
428 yoffset + height > textureLevelHeight ||
429 zoffset + depth > textureLevelDepth)
430 {
431 return gl::error(GL_INVALID_VALUE, false);
432 }
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000433 }
434
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000435 return true;
436}
437
438bool validateCopyTexImageParameters(gl::Context *context, GLenum target, bool isCompressed, GLint level,
439 GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y,
440 GLsizei width, GLsizei height)
441{
442 if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000443 {
444 return gl::error(GL_INVALID_VALUE, false);
445 }
446
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000447 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
448 {
449 return gl::error(GL_INVALID_VALUE, false);
450 }
451
452 if (width == 0 || height == 0)
453 {
454 return false;
455 }
456
457 if (level > context->getMaximumTextureLevel())
458 {
459 return gl::error(GL_INVALID_VALUE, false);
460 }
461
462 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
463
464 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
465 {
466 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
467 }
468
469 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
470 {
471 return gl::error(GL_INVALID_OPERATION, false);
472 }
473
474 gl::Renderbuffer *source = framebuffer->getReadColorbuffer();
475 GLenum colorbufferFormat = source->getInternalFormat();
476 gl::Texture *texture = NULL;
477 GLenum textureFormat = GL_RGBA;
478 bool textureCompressed = false;
479 GLint textureLevelWidth = 0;
480 GLint textureLevelHeight = 0;
481 GLint textureLevelDepth = 0;
482 switch (target)
483 {
484 case GL_TEXTURE_2D:
485 {
486 gl::Texture2D *texture2d = context->getTexture2D();
487 if (texture2d)
488 {
489 textureFormat = gl::ExtractFormat(texture2d->getInternalFormat(level));
490 textureCompressed = texture2d->isCompressed(level);
491 textureLevelWidth = texture2d->getWidth(level);
492 textureLevelHeight = texture2d->getHeight(level);
493 textureLevelDepth = 1;
494 texture = texture2d;
495 }
496 }
497 break;
498
499 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
500 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
501 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
502 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
503 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
504 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
505 {
506 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
507 if (textureCube)
508 {
509 textureFormat = gl::ExtractFormat(textureCube->getInternalFormat(target, level));
510 textureCompressed = textureCube->isCompressed(target, level);
511 textureLevelWidth = textureCube->getWidth(target, level);
512 textureLevelHeight = textureCube->getHeight(target, level);
513 textureLevelDepth = 1;
514 texture = textureCube;
515 }
516 }
517 break;
518
519 case GL_TEXTURE_3D:
520 {
521 gl::Texture3D *texture3d = context->getTexture3D();
522 if (texture3d)
523 {
524 textureFormat = gl::ExtractFormat(texture3d->getInternalFormat(level));
525 textureCompressed = texture3d->isCompressed(level);
526 textureLevelWidth = texture3d->getWidth(level);
527 textureLevelHeight = texture3d->getHeight(level);
528 textureLevelDepth = texture3d->getDepth(level);
529 texture = texture3d;
530 }
531 }
532 break;
533
534 default:
535 return gl::error(GL_INVALID_ENUM, false);
536 }
537
538 if (!texture)
539 {
540 return gl::error(GL_INVALID_OPERATION, false);
541 }
542
543 if (isCompressed != textureCompressed)
544 {
545 return gl::error(GL_INVALID_OPERATION, false);
546 }
547
548 if (isCompressed)
549 {
550 if ((width % 4 != 0 && width != textureLevelWidth) ||
551 (height % 4 != 0 && height != textureLevelHeight))
552 {
553 return gl::error(GL_INVALID_OPERATION, false);
554 }
555 }
556
557 if (xoffset + width > textureLevelWidth ||
558 yoffset + height > textureLevelHeight ||
559 zoffset >= textureLevelDepth)
560 {
561 return gl::error(GL_INVALID_VALUE, false);
562 }
563
564 if (!gl::IsValidES3CopyTexImageCombination(textureFormat, colorbufferFormat))
565 {
566 return gl::error(GL_INVALID_OPERATION, false);
567 }
568
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000569 return true;
570}
571
daniel@transgaming.comb7915a52011-11-12 03:14:20 +0000572// check for combinations of format and type that are valid for ReadPixels
573bool validReadFormatType(GLenum format, GLenum type)
574{
575 switch (format)
576 {
577 case GL_RGBA:
578 switch (type)
579 {
580 case GL_UNSIGNED_BYTE:
581 break;
582 default:
583 return false;
584 }
585 break;
586 case GL_BGRA_EXT:
587 switch (type)
588 {
589 case GL_UNSIGNED_BYTE:
590 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
591 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
592 break;
593 default:
594 return false;
595 }
596 break;
daniel@transgaming.comb7915a52011-11-12 03:14:20 +0000597 default:
598 return false;
599 }
600 return true;
601}
602
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000603extern "C"
604{
605
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000606// OpenGL ES 2.0 functions
607
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000608void __stdcall glActiveTexture(GLenum texture)
609{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000610 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000611
612 try
613 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000614 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000615
616 if (context)
617 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +0000618 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
619 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000620 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +0000621 }
622
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000623 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000624 }
625 }
626 catch(std::bad_alloc&)
627 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000628 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000629 }
630}
631
632void __stdcall glAttachShader(GLuint program, GLuint shader)
633{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000634 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000635
636 try
637 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000638 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000639
640 if (context)
641 {
642 gl::Program *programObject = context->getProgram(program);
643 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +0000644
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +0000645 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000646 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +0000647 if (context->getShader(program))
648 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000649 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +0000650 }
651 else
652 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000653 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +0000654 }
655 }
656
657 if (!shaderObject)
658 {
659 if (context->getProgram(shader))
660 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000661 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +0000662 }
663 else
664 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000665 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +0000666 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000667 }
668
669 if (!programObject->attachShader(shaderObject))
670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000671 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000672 }
673 }
674 }
675 catch(std::bad_alloc&)
676 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000677 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000678 }
679}
680
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000681void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
682{
683 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
684
685 try
686 {
687 switch (target)
688 {
689 case GL_ANY_SAMPLES_PASSED_EXT:
690 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
691 break;
692 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000693 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000694 }
695
696 if (id == 0)
697 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000698 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000699 }
700
701 gl::Context *context = gl::getNonLostContext();
702
703 if (context)
704 {
705 context->beginQuery(target, id);
706 }
707 }
708 catch(std::bad_alloc&)
709 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000710 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000711 }
712}
713
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000714void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000715{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000716 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000717
718 try
719 {
720 if (index >= gl::MAX_VERTEX_ATTRIBS)
721 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000722 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000723 }
724
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000725 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000726
727 if (context)
728 {
729 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +0000730
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000731 if (!programObject)
732 {
daniel@transgaming.com98079832010-04-13 03:26:29 +0000733 if (context->getShader(program))
734 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000735 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +0000736 }
737 else
738 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000739 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +0000740 }
741 }
742
743 if (strncmp(name, "gl_", 3) == 0)
744 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000745 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000746 }
747
748 programObject->bindAttributeLocation(index, name);
749 }
750 }
751 catch(std::bad_alloc&)
752 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000753 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000754 }
755}
756
757void __stdcall glBindBuffer(GLenum target, GLuint buffer)
758{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000759 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000760
761 try
762 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000763 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000764
765 if (context)
766 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000767 // Check ES3 specific targets
768 switch (target)
769 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000770 case GL_COPY_READ_BUFFER:
771 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +0000772 case GL_PIXEL_PACK_BUFFER:
773 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000774 case GL_UNIFORM_BUFFER:
775 case GL_TRANSFORM_FEEDBACK_BUFFER:
776 if (context->getClientVersion() < 3)
777 {
778 return gl::error(GL_INVALID_ENUM);
779 }
780 }
781
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000782 switch (target)
783 {
784 case GL_ARRAY_BUFFER:
785 context->bindArrayBuffer(buffer);
786 return;
787 case GL_ELEMENT_ARRAY_BUFFER:
788 context->bindElementArrayBuffer(buffer);
789 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000790 case GL_COPY_READ_BUFFER:
791 context->bindCopyReadBuffer(buffer);
792 return;
793 case GL_COPY_WRITE_BUFFER:
794 context->bindCopyWriteBuffer(buffer);
795 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +0000796 case GL_PIXEL_PACK_BUFFER:
797 context->bindPixelPackBuffer(buffer);
798 return;
799 case GL_PIXEL_UNPACK_BUFFER:
800 context->bindPixelUnpackBuffer(buffer);
801 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000802 case GL_UNIFORM_BUFFER:
803 context->bindGenericUniformBuffer(buffer);
804 return;
805 case GL_TRANSFORM_FEEDBACK_BUFFER:
806 context->bindGenericUniformBuffer(buffer);
807 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000808 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000809 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000810 }
811 }
812 }
813 catch(std::bad_alloc&)
814 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000815 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000816 }
817}
818
819void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
820{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000821 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000822
823 try
824 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000825 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000826 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000827 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000828 }
829
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000830 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000831
832 if (context)
833 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000834 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
835 {
836 context->bindReadFramebuffer(framebuffer);
837 }
838
839 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
840 {
841 context->bindDrawFramebuffer(framebuffer);
842 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000843 }
844 }
845 catch(std::bad_alloc&)
846 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000847 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000848 }
849}
850
851void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
852{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000853 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000854
855 try
856 {
857 if (target != GL_RENDERBUFFER)
858 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000859 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000860 }
861
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000862 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000863
864 if (context)
865 {
866 context->bindRenderbuffer(renderbuffer);
867 }
868 }
869 catch(std::bad_alloc&)
870 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000871 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000872 }
873}
874
875void __stdcall glBindTexture(GLenum target, GLuint texture)
876{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000877 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000878
879 try
880 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000881 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000882
883 if (context)
884 {
885 gl::Texture *textureObject = context->getTexture(texture);
886
887 if (textureObject && textureObject->getTarget() != target && texture != 0)
888 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000889 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000890 }
891
892 switch (target)
893 {
894 case GL_TEXTURE_2D:
895 context->bindTexture2D(texture);
896 return;
897 case GL_TEXTURE_CUBE_MAP:
898 context->bindTextureCubeMap(texture);
899 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +0000900 case GL_TEXTURE_3D:
901 if (context->getClientVersion() < 3)
902 {
903 return gl::error(GL_INVALID_ENUM);
904 }
905 context->bindTexture3D(texture);
906 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000907 case GL_TEXTURE_2D_ARRAY:
908 if (context->getClientVersion() < 3)
909 {
910 return gl::error(GL_INVALID_ENUM);
911 }
912 context->bindTexture2DArray(texture);
913 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000914 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000915 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000916 }
917 }
918 }
919 catch(std::bad_alloc&)
920 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000921 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000922 }
923}
924
925void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
926{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000927 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000928 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000929
930 try
931 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000932 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000933
934 if (context)
935 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000936 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000937 }
938 }
939 catch(std::bad_alloc&)
940 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000941 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000942 }
943}
944
945void __stdcall glBlendEquation(GLenum mode)
946{
947 glBlendEquationSeparate(mode, mode);
948}
949
950void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
951{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000952 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000953
954 try
955 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +0000956 gl::Context *context = gl::getNonLostContext();
957
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000958 switch (modeRGB)
959 {
960 case GL_FUNC_ADD:
961 case GL_FUNC_SUBTRACT:
962 case GL_FUNC_REVERSE_SUBTRACT:
963 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +0000964
965 case GL_MIN:
966 case GL_MAX:
967 if (context && context->getClientVersion() < 3)
968 {
969 return gl::error(GL_INVALID_ENUM);
970 }
971 break;
972
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000973 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000974 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000975 }
976
977 switch (modeAlpha)
978 {
979 case GL_FUNC_ADD:
980 case GL_FUNC_SUBTRACT:
981 case GL_FUNC_REVERSE_SUBTRACT:
982 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +0000983
984 case GL_MIN:
985 case GL_MAX:
986 if (context && context->getClientVersion() < 3)
987 {
988 return gl::error(GL_INVALID_ENUM);
989 }
990 break;
991
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000992 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000993 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000994 }
995
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000996 if (context)
997 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000998 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000999 }
1000 }
1001 catch(std::bad_alloc&)
1002 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001003 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001004 }
1005}
1006
1007void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
1008{
1009 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
1010}
1011
1012void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
1013{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001014 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 +00001015 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001016
1017 try
1018 {
1019 switch (srcRGB)
1020 {
1021 case GL_ZERO:
1022 case GL_ONE:
1023 case GL_SRC_COLOR:
1024 case GL_ONE_MINUS_SRC_COLOR:
1025 case GL_DST_COLOR:
1026 case GL_ONE_MINUS_DST_COLOR:
1027 case GL_SRC_ALPHA:
1028 case GL_ONE_MINUS_SRC_ALPHA:
1029 case GL_DST_ALPHA:
1030 case GL_ONE_MINUS_DST_ALPHA:
1031 case GL_CONSTANT_COLOR:
1032 case GL_ONE_MINUS_CONSTANT_COLOR:
1033 case GL_CONSTANT_ALPHA:
1034 case GL_ONE_MINUS_CONSTANT_ALPHA:
1035 case GL_SRC_ALPHA_SATURATE:
1036 break;
1037 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001038 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001039 }
1040
1041 switch (dstRGB)
1042 {
1043 case GL_ZERO:
1044 case GL_ONE:
1045 case GL_SRC_COLOR:
1046 case GL_ONE_MINUS_SRC_COLOR:
1047 case GL_DST_COLOR:
1048 case GL_ONE_MINUS_DST_COLOR:
1049 case GL_SRC_ALPHA:
1050 case GL_ONE_MINUS_SRC_ALPHA:
1051 case GL_DST_ALPHA:
1052 case GL_ONE_MINUS_DST_ALPHA:
1053 case GL_CONSTANT_COLOR:
1054 case GL_ONE_MINUS_CONSTANT_COLOR:
1055 case GL_CONSTANT_ALPHA:
1056 case GL_ONE_MINUS_CONSTANT_ALPHA:
1057 break;
1058 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001059 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001060 }
1061
1062 switch (srcAlpha)
1063 {
1064 case GL_ZERO:
1065 case GL_ONE:
1066 case GL_SRC_COLOR:
1067 case GL_ONE_MINUS_SRC_COLOR:
1068 case GL_DST_COLOR:
1069 case GL_ONE_MINUS_DST_COLOR:
1070 case GL_SRC_ALPHA:
1071 case GL_ONE_MINUS_SRC_ALPHA:
1072 case GL_DST_ALPHA:
1073 case GL_ONE_MINUS_DST_ALPHA:
1074 case GL_CONSTANT_COLOR:
1075 case GL_ONE_MINUS_CONSTANT_COLOR:
1076 case GL_CONSTANT_ALPHA:
1077 case GL_ONE_MINUS_CONSTANT_ALPHA:
1078 case GL_SRC_ALPHA_SATURATE:
1079 break;
1080 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001081 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001082 }
1083
1084 switch (dstAlpha)
1085 {
1086 case GL_ZERO:
1087 case GL_ONE:
1088 case GL_SRC_COLOR:
1089 case GL_ONE_MINUS_SRC_COLOR:
1090 case GL_DST_COLOR:
1091 case GL_ONE_MINUS_DST_COLOR:
1092 case GL_SRC_ALPHA:
1093 case GL_ONE_MINUS_SRC_ALPHA:
1094 case GL_DST_ALPHA:
1095 case GL_ONE_MINUS_DST_ALPHA:
1096 case GL_CONSTANT_COLOR:
1097 case GL_ONE_MINUS_CONSTANT_COLOR:
1098 case GL_CONSTANT_ALPHA:
1099 case GL_ONE_MINUS_CONSTANT_ALPHA:
1100 break;
1101 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001102 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001103 }
1104
daniel@transgaming.comfe453652010-03-16 06:23:28 +00001105 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
1106 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
1107
1108 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
1109 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
1110
1111 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001112 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00001113 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 +00001114 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001115 }
1116
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001117 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001118
1119 if (context)
1120 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00001121 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001122 }
1123 }
1124 catch(std::bad_alloc&)
1125 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001126 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001127 }
1128}
1129
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001130void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001131{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001132 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 +00001133 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001134
1135 try
1136 {
1137 if (size < 0)
1138 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001139 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001140 }
1141
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00001142 gl::Context *context = gl::getNonLostContext();
1143
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001144 switch (usage)
1145 {
1146 case GL_STREAM_DRAW:
1147 case GL_STATIC_DRAW:
1148 case GL_DYNAMIC_DRAW:
1149 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00001150
1151 case GL_STREAM_READ:
1152 case GL_STREAM_COPY:
1153 case GL_STATIC_READ:
1154 case GL_STATIC_COPY:
1155 case GL_DYNAMIC_READ:
1156 case GL_DYNAMIC_COPY:
1157 if (context && context->getClientVersion() < 3)
1158 {
1159 return gl::error(GL_INVALID_ENUM);
1160 }
1161 break;
1162
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001163 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001164 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001165 }
1166
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001167 if (context)
1168 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001169 // Check ES3 specific targets
1170 switch (target)
1171 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001172 case GL_COPY_READ_BUFFER:
1173 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001174 case GL_PIXEL_PACK_BUFFER:
1175 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001176 case GL_UNIFORM_BUFFER:
1177 case GL_TRANSFORM_FEEDBACK_BUFFER:
1178 if (context->getClientVersion() < 3)
1179 {
1180 return gl::error(GL_INVALID_ENUM);
1181 }
1182 }
1183
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001184 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00001185
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001186 switch (target)
1187 {
1188 case GL_ARRAY_BUFFER:
1189 buffer = context->getArrayBuffer();
1190 break;
1191 case GL_ELEMENT_ARRAY_BUFFER:
1192 buffer = context->getElementArrayBuffer();
1193 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001194 case GL_COPY_READ_BUFFER:
1195 buffer = context->getCopyReadBuffer();
1196 break;
1197 case GL_COPY_WRITE_BUFFER:
1198 buffer = context->getCopyWriteBuffer();
1199 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001200 case GL_PIXEL_PACK_BUFFER:
1201 buffer = context->getPixelPackBuffer();
1202 break;
1203 case GL_PIXEL_UNPACK_BUFFER:
1204 buffer = context->getPixelUnpackBuffer();
1205 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001206 case GL_TRANSFORM_FEEDBACK_BUFFER:
1207 buffer = context->getGenericTransformFeedbackBuffer();
1208 break;
1209 case GL_UNIFORM_BUFFER:
1210 buffer = context->getGenericUniformBuffer();
1211 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001212 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001213 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001214 }
1215
1216 if (!buffer)
1217 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001218 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001219 }
1220
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001221 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001222 }
1223 }
1224 catch(std::bad_alloc&)
1225 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001226 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001227 }
1228}
1229
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001230void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001231{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001232 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 +00001233 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001234
1235 try
1236 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00001237 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001238 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001239 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001240 }
1241
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00001242 if (data == NULL)
1243 {
1244 return;
1245 }
1246
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001247 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001248
1249 if (context)
1250 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001251 // Check ES3 specific targets
1252 switch (target)
1253 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001254 case GL_COPY_READ_BUFFER:
1255 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001256 case GL_PIXEL_PACK_BUFFER:
1257 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001258 case GL_UNIFORM_BUFFER:
1259 case GL_TRANSFORM_FEEDBACK_BUFFER:
1260 if (context->getClientVersion() < 3)
1261 {
1262 return gl::error(GL_INVALID_ENUM);
1263 }
1264 }
1265
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001266 gl::Buffer *buffer;
1267
1268 switch (target)
1269 {
1270 case GL_ARRAY_BUFFER:
1271 buffer = context->getArrayBuffer();
1272 break;
1273 case GL_ELEMENT_ARRAY_BUFFER:
1274 buffer = context->getElementArrayBuffer();
1275 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001276 case GL_COPY_READ_BUFFER:
1277 buffer = context->getCopyReadBuffer();
1278 break;
1279 case GL_COPY_WRITE_BUFFER:
1280 buffer = context->getCopyWriteBuffer();
1281 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001282 case GL_PIXEL_PACK_BUFFER:
1283 buffer = context->getPixelPackBuffer();
1284 break;
1285 case GL_PIXEL_UNPACK_BUFFER:
1286 buffer = context->getPixelUnpackBuffer();
1287 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001288 case GL_TRANSFORM_FEEDBACK_BUFFER:
1289 buffer = context->getGenericTransformFeedbackBuffer();
1290 break;
1291 case GL_UNIFORM_BUFFER:
1292 buffer = context->getGenericUniformBuffer();
1293 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001294 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001295 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001296 }
1297
1298 if (!buffer)
1299 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001300 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001301 }
1302
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00001303 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001304 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001305 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001306 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00001307
1308 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001309 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001310 }
1311 catch(std::bad_alloc&)
1312 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001313 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001314 }
1315}
1316
1317GLenum __stdcall glCheckFramebufferStatus(GLenum target)
1318{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001319 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001320
1321 try
1322 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00001323 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001324 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001325 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001326 }
1327
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001328 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001329
1330 if (context)
1331 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00001332 gl::Framebuffer *framebuffer = NULL;
1333 if (target == GL_READ_FRAMEBUFFER_ANGLE)
1334 {
1335 framebuffer = context->getReadFramebuffer();
1336 }
1337 else
1338 {
1339 framebuffer = context->getDrawFramebuffer();
1340 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001341
1342 return framebuffer->completeness();
1343 }
1344 }
1345 catch(std::bad_alloc&)
1346 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001347 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001348 }
1349
1350 return 0;
1351}
1352
1353void __stdcall glClear(GLbitfield mask)
1354{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001355 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001356
1357 try
1358 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001359 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001360
1361 if (context)
1362 {
1363 context->clear(mask);
1364 }
1365 }
1366 catch(std::bad_alloc&)
1367 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001368 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001369 }
1370}
1371
1372void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
1373{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001374 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001375 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001376
1377 try
1378 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001379 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001380
1381 if (context)
1382 {
1383 context->setClearColor(red, green, blue, alpha);
1384 }
1385 }
1386 catch(std::bad_alloc&)
1387 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001388 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001389 }
1390}
1391
1392void __stdcall glClearDepthf(GLclampf depth)
1393{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001394 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001395
1396 try
1397 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001398 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001399
1400 if (context)
1401 {
1402 context->setClearDepth(depth);
1403 }
1404 }
1405 catch(std::bad_alloc&)
1406 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001407 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001408 }
1409}
1410
1411void __stdcall glClearStencil(GLint s)
1412{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001413 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001414
1415 try
1416 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001417 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001418
1419 if (context)
1420 {
1421 context->setClearStencil(s);
1422 }
1423 }
1424 catch(std::bad_alloc&)
1425 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001426 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001427 }
1428}
1429
1430void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
1431{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001432 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001433 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001434
1435 try
1436 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001437 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001438
1439 if (context)
1440 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00001441 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001442 }
1443 }
1444 catch(std::bad_alloc&)
1445 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001446 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001447 }
1448}
1449
1450void __stdcall glCompileShader(GLuint shader)
1451{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001452 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001453
1454 try
1455 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001456 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001457
1458 if (context)
1459 {
1460 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00001461
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001462 if (!shaderObject)
1463 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00001464 if (context->getProgram(shader))
1465 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001466 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00001467 }
1468 else
1469 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001470 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00001471 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001472 }
1473
1474 shaderObject->compile();
1475 }
1476 }
1477 catch(std::bad_alloc&)
1478 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001479 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001480 }
1481}
1482
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001483void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
1484 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001485{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001486 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001487 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001488 target, level, internalformat, width, height, border, imageSize, data);
1489
1490 try
1491 {
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001492 if (!validImageSize(level, width, height, 1) || border != 0 || imageSize < 0)
daniel@transgaming.com41430492010-03-11 20:36:18 +00001493 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001494 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com41430492010-03-11 20:36:18 +00001495 }
1496
daniel@transgaming.com01868132010-08-24 19:21:17 +00001497 switch (internalformat)
1498 {
1499 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1500 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
gman@chromium.org50c526d2011-08-10 05:19:44 +00001501 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1502 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
daniel@transgaming.com01868132010-08-24 19:21:17 +00001503 break;
1504 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001505 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001506 }
1507
1508 if (border != 0)
1509 {
shannon.woods@transgaming.com0efef902013-02-28 23:21:09 +00001510 return gl::error(GL_INVALID_OPERATION);
1511 }
1512
1513 if (width != 1 && width != 2 && width % 4 != 0)
1514 {
1515 return gl::error(GL_INVALID_OPERATION);
1516 }
1517
1518 if (height != 1 && height != 2 && height % 4 != 0)
1519 {
1520 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001521 }
1522
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001523 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00001524
1525 if (context)
1526 {
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001527 if (level > context->getMaximumTextureLevel())
1528 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001529 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001530 }
1531
1532 switch (target)
1533 {
1534 case GL_TEXTURE_2D:
shannon.woods%transgaming.com@gtempaccount.comc1fdf6b2013-04-13 03:44:41 +00001535 if (width > (context->getMaximum2DTextureDimension() >> level) ||
1536 height > (context->getMaximum2DTextureDimension() >> level))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001537 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001538 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001539 }
1540 break;
1541 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1542 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1543 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1544 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1545 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1546 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1547 if (width != height)
1548 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001549 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001550 }
1551
1552 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
1553 height > (context->getMaximumCubeTextureDimension() >> level))
1554 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001555 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001556 }
1557 break;
1558 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001559 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001560 }
1561
gman@chromium.org50c526d2011-08-10 05:19:44 +00001562 switch (internalformat) {
1563 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1564 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1565 if (!context->supportsDXT1Textures())
1566 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001567 return gl::error(GL_INVALID_ENUM); // in this case, it's as though the internal format switch failed
gman@chromium.org50c526d2011-08-10 05:19:44 +00001568 }
1569 break;
1570 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1571 if (!context->supportsDXT3Textures())
1572 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001573 return gl::error(GL_INVALID_ENUM); // in this case, it's as though the internal format switch failed
gman@chromium.org50c526d2011-08-10 05:19:44 +00001574 }
1575 break;
1576 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1577 if (!context->supportsDXT5Textures())
1578 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001579 return gl::error(GL_INVALID_ENUM); // in this case, it's as though the internal format switch failed
gman@chromium.org50c526d2011-08-10 05:19:44 +00001580 }
1581 break;
1582 default: UNREACHABLE();
daniel@transgaming.com01868132010-08-24 19:21:17 +00001583 }
1584
1585 if (imageSize != gl::ComputeCompressedSize(width, height, internalformat))
1586 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001587 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001588 }
1589
1590 if (target == GL_TEXTURE_2D)
1591 {
1592 gl::Texture2D *texture = context->getTexture2D();
1593
1594 if (!texture)
1595 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001596 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001597 }
1598
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001599 if (texture->isImmutable())
1600 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001601 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001602 }
1603
daniel@transgaming.com01868132010-08-24 19:21:17 +00001604 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
1605 }
1606 else
1607 {
1608 gl::TextureCubeMap *texture = context->getTextureCubeMap();
1609
1610 if (!texture)
1611 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001612 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001613 }
1614
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001615 if (texture->isImmutable())
1616 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001617 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001618 }
1619
daniel@transgaming.com01868132010-08-24 19:21:17 +00001620 switch (target)
1621 {
1622 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1623 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1624 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1625 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1626 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1627 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1628 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
1629 break;
1630 default: UNREACHABLE();
1631 }
1632 }
1633 }
1634
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001635 }
1636 catch(std::bad_alloc&)
1637 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001638 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001639 }
1640}
1641
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001642void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
1643 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001644{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001645 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001646 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001647 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001648 target, level, xoffset, yoffset, width, height, format, imageSize, data);
1649
1650 try
1651 {
apatrick@chromium.org551022e2012-01-23 19:56:54 +00001652 if (!gl::IsInternalTextureTarget(target))
daniel@transgaming.com41430492010-03-11 20:36:18 +00001653 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001654 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com41430492010-03-11 20:36:18 +00001655 }
1656
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001657 if (xoffset < 0 || yoffset < 0 || !validImageSize(level, width, height, 1) || imageSize < 0)
daniel@transgaming.com41430492010-03-11 20:36:18 +00001658 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001659 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com41430492010-03-11 20:36:18 +00001660 }
1661
daniel@transgaming.com01868132010-08-24 19:21:17 +00001662 switch (format)
daniel@transgaming.com41430492010-03-11 20:36:18 +00001663 {
daniel@transgaming.com01868132010-08-24 19:21:17 +00001664 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1665 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
gman@chromium.org50c526d2011-08-10 05:19:44 +00001666 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1667 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
daniel@transgaming.com01868132010-08-24 19:21:17 +00001668 break;
1669 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001670 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com41430492010-03-11 20:36:18 +00001671 }
1672
daniel@transgaming.com01868132010-08-24 19:21:17 +00001673 if (width == 0 || height == 0 || data == NULL)
1674 {
1675 return;
1676 }
1677
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001678 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00001679
1680 if (context)
1681 {
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001682 if (level > context->getMaximumTextureLevel())
1683 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001684 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001685 }
1686
gman@chromium.org50c526d2011-08-10 05:19:44 +00001687 switch (format) {
1688 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1689 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1690 if (!context->supportsDXT1Textures())
1691 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001692 return gl::error(GL_INVALID_ENUM); // in this case, it's as though the internal format switch failed
gman@chromium.org50c526d2011-08-10 05:19:44 +00001693 }
1694 break;
1695 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1696 if (!context->supportsDXT3Textures())
1697 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001698 return gl::error(GL_INVALID_ENUM); // in this case, it's as though the internal format switch failed
gman@chromium.org50c526d2011-08-10 05:19:44 +00001699 }
1700 break;
1701 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1702 if (!context->supportsDXT5Textures())
1703 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001704 return gl::error(GL_INVALID_ENUM); // in this case, it's as though the internal format switch failed
gman@chromium.org50c526d2011-08-10 05:19:44 +00001705 }
1706 break;
1707 default: UNREACHABLE();
daniel@transgaming.com01868132010-08-24 19:21:17 +00001708 }
1709
1710 if (imageSize != gl::ComputeCompressedSize(width, height, format))
1711 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001712 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001713 }
1714
1715 if (xoffset % 4 != 0 || yoffset % 4 != 0)
1716 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001717 return gl::error(GL_INVALID_OPERATION); // we wait to check the offsets until this point, because the multiple-of-four restriction
gman@chromium.org50c526d2011-08-10 05:19:44 +00001718 // does not exist unless DXT textures are supported.
daniel@transgaming.com01868132010-08-24 19:21:17 +00001719 }
1720
1721 if (target == GL_TEXTURE_2D)
1722 {
1723 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00001724 if (validateSubImageParams2D(true, width, height, xoffset, yoffset, level, format, GL_NONE, texture))
daniel@transgaming.com01868132010-08-24 19:21:17 +00001725 {
daniel@transgaming.com343373a2011-11-29 19:42:32 +00001726 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001727 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00001728 }
1729 else if (gl::IsCubemapTextureTarget(target))
1730 {
1731 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00001732 if (validateSubImageParamsCube(true, width, height, xoffset, yoffset, target, level, format, GL_NONE, texture))
daniel@transgaming.com01868132010-08-24 19:21:17 +00001733 {
daniel@transgaming.com343373a2011-11-29 19:42:32 +00001734 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001735 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00001736 }
1737 else
1738 {
1739 UNREACHABLE();
1740 }
1741 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001742 }
1743 catch(std::bad_alloc&)
1744 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001745 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001746 }
1747}
1748
1749void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
1750{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001751 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001752 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001753 target, level, internalformat, x, y, width, height, border);
1754
1755 try
1756 {
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001757 if (!validImageSize(level, width, height, 1))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001758 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001759 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001760 }
1761
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001762 if (border != 0)
1763 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001764 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001765 }
1766
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001767 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001768
1769 if (context)
1770 {
daniel@transgaming.com32b11442011-11-19 02:42:48 +00001771 if (level > context->getMaximumTextureLevel())
1772 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001773 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com32b11442011-11-19 02:42:48 +00001774 }
1775
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001776 switch (target)
1777 {
1778 case GL_TEXTURE_2D:
shannon.woods%transgaming.com@gtempaccount.comc1fdf6b2013-04-13 03:44:41 +00001779 if (width > (context->getMaximum2DTextureDimension() >> level) ||
1780 height > (context->getMaximum2DTextureDimension() >> level))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001782 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001783 }
1784 break;
1785 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1786 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1787 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1788 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1789 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1790 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1791 if (width != height)
1792 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001793 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001794 }
1795
1796 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
1797 height > (context->getMaximumCubeTextureDimension() >> level))
1798 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001799 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001800 }
1801 break;
1802 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001803 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001804 }
1805
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00001806 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001807
daniel@transgaming.combbc57792010-07-28 19:21:05 +00001808 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1809 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001810 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION);
daniel@transgaming.combbc57792010-07-28 19:21:05 +00001811 }
1812
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001813 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00001814 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001815 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00001816 }
1817
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001818 gl::Renderbuffer *source = framebuffer->getReadColorbuffer();
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00001819 GLenum colorbufferFormat = source->getInternalFormat();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001820
1821 // [OpenGL ES 2.0.24] table 3.9
1822 switch (internalformat)
1823 {
1824 case GL_ALPHA:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00001825 if (colorbufferFormat != GL_ALPHA8_EXT &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001826 colorbufferFormat != GL_RGBA4 &&
1827 colorbufferFormat != GL_RGB5_A1 &&
shannon.woods@transgaming.com28e7ba02013-02-28 23:09:28 +00001828 colorbufferFormat != GL_BGRA8_EXT &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001829 colorbufferFormat != GL_RGBA8_OES)
1830 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001831 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001832 }
1833 break;
1834 case GL_LUMINANCE:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00001835 case GL_RGB:
1836 if (colorbufferFormat != GL_RGB565 &&
1837 colorbufferFormat != GL_RGB8_OES &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001838 colorbufferFormat != GL_RGBA4 &&
1839 colorbufferFormat != GL_RGB5_A1 &&
shannon.woods@transgaming.com28e7ba02013-02-28 23:09:28 +00001840 colorbufferFormat != GL_BGRA8_EXT &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001841 colorbufferFormat != GL_RGBA8_OES)
1842 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001843 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001844 }
1845 break;
1846 case GL_LUMINANCE_ALPHA:
1847 case GL_RGBA:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00001848 if (colorbufferFormat != GL_RGBA4 &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001849 colorbufferFormat != GL_RGB5_A1 &&
shannon.woods@transgaming.com28e7ba02013-02-28 23:09:28 +00001850 colorbufferFormat != GL_BGRA8_EXT &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001851 colorbufferFormat != GL_RGBA8_OES)
1852 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001853 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001854 }
1855 break;
1856 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1857 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
gman@chromium.org50c526d2011-08-10 05:19:44 +00001858 if (context->supportsDXT1Textures())
1859 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001860 return gl::error(GL_INVALID_OPERATION);
gman@chromium.org50c526d2011-08-10 05:19:44 +00001861 }
1862 else
1863 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001864 return gl::error(GL_INVALID_ENUM);
gman@chromium.org50c526d2011-08-10 05:19:44 +00001865 }
1866 break;
1867 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1868 if (context->supportsDXT3Textures())
1869 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001870 return gl::error(GL_INVALID_OPERATION);
gman@chromium.org50c526d2011-08-10 05:19:44 +00001871 }
1872 else
1873 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001874 return gl::error(GL_INVALID_ENUM);
gman@chromium.org50c526d2011-08-10 05:19:44 +00001875 }
1876 break;
1877 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1878 if (context->supportsDXT5Textures())
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001879 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001880 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001881 }
1882 else
1883 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001884 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001885 }
1886 break;
daniel@transgaming.com0c854682012-05-31 01:14:11 +00001887 case GL_DEPTH_COMPONENT:
1888 case GL_DEPTH_COMPONENT16:
1889 case GL_DEPTH_COMPONENT32_OES:
1890 case GL_DEPTH_STENCIL_OES:
1891 case GL_DEPTH24_STENCIL8_OES:
1892 if (context->supportsDepthTextures())
1893 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001894 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00001895 }
1896 else
1897 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001898 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00001899 }
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001900 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001901 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001902 }
1903
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001904 if (target == GL_TEXTURE_2D)
1905 {
1906 gl::Texture2D *texture = context->getTexture2D();
1907
1908 if (!texture)
1909 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001910 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001911 }
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00001912
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001913 if (texture->isImmutable())
1914 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001915 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001916 }
1917
apatrick@chromium.orgb31f5322011-01-19 19:02:52 +00001918 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001919 }
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00001920 else if (gl::IsCubemapTextureTarget(target))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001921 {
1922 gl::TextureCubeMap *texture = context->getTextureCubeMap();
1923
1924 if (!texture)
1925 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001926 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001927 }
1928
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001929 if (texture->isImmutable())
1930 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001931 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001932 }
1933
apatrick@chromium.orgb31f5322011-01-19 19:02:52 +00001934 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001935 }
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001936 else UNREACHABLE();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001937 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001938 }
1939 catch(std::bad_alloc&)
1940 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001941 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001942 }
1943}
1944
1945void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
1946{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001947 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001948 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001949 target, level, xoffset, yoffset, x, y, width, height);
1950
1951 try
1952 {
apatrick@chromium.org551022e2012-01-23 19:56:54 +00001953 if (!gl::IsInternalTextureTarget(target))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001954 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001955 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001956 }
1957
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001958 if (level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001959 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001960 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001961 }
1962
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001963 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
1964 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001965 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001966 }
1967
1968 if (width == 0 || height == 0)
1969 {
1970 return;
1971 }
1972
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001973 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001974
1975 if (context)
1976 {
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001977 if (level > context->getMaximumTextureLevel())
1978 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001979 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001980 }
1981
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00001982 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001983
daniel@transgaming.combbc57792010-07-28 19:21:05 +00001984 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1985 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001986 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION);
daniel@transgaming.combbc57792010-07-28 19:21:05 +00001987 }
1988
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001989 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00001990 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001991 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00001992 }
1993
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001994 gl::Renderbuffer *source = framebuffer->getReadColorbuffer();
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00001995 GLenum colorbufferFormat = source->getInternalFormat();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001996 gl::Texture *texture = NULL;
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00001997 GLenum textureFormat = GL_RGBA;
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001998
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001999 if (target == GL_TEXTURE_2D)
2000 {
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002001 gl::Texture2D *tex2d = context->getTexture2D();
2002
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002003 if (!validateSubImageParams2D(false, width, height, xoffset, yoffset, level, GL_NONE, GL_NONE, tex2d))
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002004 {
2005 return; // error already registered by validateSubImageParams
2006 }
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002007 textureFormat = gl::ExtractFormat(tex2d->getInternalFormat(level));
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002008 texture = tex2d;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002009 }
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00002010 else if (gl::IsCubemapTextureTarget(target))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002011 {
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002012 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
2013
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002014 if (!validateSubImageParamsCube(false, width, height, xoffset, yoffset, target, level, GL_NONE, GL_NONE, texcube))
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002015 {
2016 return; // error already registered by validateSubImageParams
2017 }
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002018 textureFormat = gl::ExtractFormat(texcube->getInternalFormat(target, level));
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002019 texture = texcube;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002020 }
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002021 else UNREACHABLE();
2022
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002023 // [OpenGL ES 2.0.24] table 3.9
2024 switch (textureFormat)
2025 {
2026 case GL_ALPHA:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002027 if (colorbufferFormat != GL_ALPHA8_EXT &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002028 colorbufferFormat != GL_RGBA4 &&
2029 colorbufferFormat != GL_RGB5_A1 &&
2030 colorbufferFormat != GL_RGBA8_OES)
2031 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002032 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002033 }
2034 break;
2035 case GL_LUMINANCE:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002036 case GL_RGB:
2037 if (colorbufferFormat != GL_RGB565 &&
2038 colorbufferFormat != GL_RGB8_OES &&
2039 colorbufferFormat != GL_RGBA4 &&
2040 colorbufferFormat != GL_RGB5_A1 &&
2041 colorbufferFormat != GL_RGBA8_OES)
2042 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002043 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002044 }
2045 break;
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002046 case GL_LUMINANCE_ALPHA:
2047 case GL_RGBA:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002048 if (colorbufferFormat != GL_RGBA4 &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002049 colorbufferFormat != GL_RGB5_A1 &&
2050 colorbufferFormat != GL_RGBA8_OES)
2051 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002052 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002053 }
2054 break;
2055 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
2056 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
gman@chromium.org50c526d2011-08-10 05:19:44 +00002057 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
2058 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002059 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00002060 case GL_DEPTH_COMPONENT:
2061 case GL_DEPTH_STENCIL_OES:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002062 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002063 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002064 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002065 }
2066
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +00002067 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002068 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002069 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002070
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002071 catch(std::bad_alloc&)
2072 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002073 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002074 }
2075}
2076
2077GLuint __stdcall glCreateProgram(void)
2078{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002079 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002080
2081 try
2082 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002083 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002084
2085 if (context)
2086 {
2087 return context->createProgram();
2088 }
2089 }
2090 catch(std::bad_alloc&)
2091 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002092 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002093 }
2094
2095 return 0;
2096}
2097
2098GLuint __stdcall glCreateShader(GLenum type)
2099{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002100 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002101
2102 try
2103 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002104 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002105
2106 if (context)
2107 {
2108 switch (type)
2109 {
2110 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002111 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002112 return context->createShader(type);
2113 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002114 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002115 }
2116 }
2117 }
2118 catch(std::bad_alloc&)
2119 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002120 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002121 }
2122
2123 return 0;
2124}
2125
2126void __stdcall glCullFace(GLenum mode)
2127{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002128 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002129
2130 try
2131 {
2132 switch (mode)
2133 {
2134 case GL_FRONT:
2135 case GL_BACK:
2136 case GL_FRONT_AND_BACK:
2137 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002138 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002139
2140 if (context)
2141 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002142 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002143 }
2144 }
2145 break;
2146 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002147 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002148 }
2149 }
2150 catch(std::bad_alloc&)
2151 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002152 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002153 }
2154}
2155
2156void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
2157{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002158 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002159
2160 try
2161 {
2162 if (n < 0)
2163 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002164 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002165 }
2166
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002167 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002168
2169 if (context)
2170 {
2171 for (int i = 0; i < n; i++)
2172 {
2173 context->deleteBuffer(buffers[i]);
2174 }
2175 }
2176 }
2177 catch(std::bad_alloc&)
2178 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002179 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002180 }
2181}
2182
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002183void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
2184{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002185 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002186
2187 try
2188 {
2189 if (n < 0)
2190 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002191 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002192 }
2193
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002194 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002195
2196 if (context)
2197 {
2198 for (int i = 0; i < n; i++)
2199 {
2200 context->deleteFence(fences[i]);
2201 }
2202 }
2203 }
2204 catch(std::bad_alloc&)
2205 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002206 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002207 }
2208}
2209
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002210void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
2211{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002212 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002213
2214 try
2215 {
2216 if (n < 0)
2217 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002218 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002219 }
2220
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002221 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002222
2223 if (context)
2224 {
2225 for (int i = 0; i < n; i++)
2226 {
2227 if (framebuffers[i] != 0)
2228 {
2229 context->deleteFramebuffer(framebuffers[i]);
2230 }
2231 }
2232 }
2233 }
2234 catch(std::bad_alloc&)
2235 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002236 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002237 }
2238}
2239
2240void __stdcall glDeleteProgram(GLuint program)
2241{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002242 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002243
2244 try
2245 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002246 if (program == 0)
2247 {
2248 return;
2249 }
2250
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002251 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002252
2253 if (context)
2254 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002255 if (!context->getProgram(program))
2256 {
2257 if(context->getShader(program))
2258 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002259 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002260 }
2261 else
2262 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002263 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002264 }
2265 }
2266
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002267 context->deleteProgram(program);
2268 }
2269 }
2270 catch(std::bad_alloc&)
2271 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002272 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002273 }
2274}
2275
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002276void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
2277{
2278 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
2279
2280 try
2281 {
2282 if (n < 0)
2283 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002284 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002285 }
2286
2287 gl::Context *context = gl::getNonLostContext();
2288
2289 if (context)
2290 {
2291 for (int i = 0; i < n; i++)
2292 {
2293 context->deleteQuery(ids[i]);
2294 }
2295 }
2296 }
2297 catch(std::bad_alloc&)
2298 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002299 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002300 }
2301}
2302
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002303void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
2304{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002305 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002306
2307 try
2308 {
2309 if (n < 0)
2310 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002311 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002312 }
2313
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002314 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002315
2316 if (context)
2317 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00002318 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002319 {
2320 context->deleteRenderbuffer(renderbuffers[i]);
2321 }
2322 }
2323 }
2324 catch(std::bad_alloc&)
2325 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002326 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002327 }
2328}
2329
2330void __stdcall glDeleteShader(GLuint shader)
2331{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002332 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002333
2334 try
2335 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002336 if (shader == 0)
2337 {
2338 return;
2339 }
2340
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002341 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002342
2343 if (context)
2344 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002345 if (!context->getShader(shader))
2346 {
2347 if(context->getProgram(shader))
2348 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002349 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002350 }
2351 else
2352 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002353 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002354 }
2355 }
2356
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002357 context->deleteShader(shader);
2358 }
2359 }
2360 catch(std::bad_alloc&)
2361 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002362 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002363 }
2364}
2365
2366void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
2367{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002368 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002369
2370 try
2371 {
2372 if (n < 0)
2373 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002374 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002375 }
2376
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002377 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002378
2379 if (context)
2380 {
2381 for (int i = 0; i < n; i++)
2382 {
2383 if (textures[i] != 0)
2384 {
2385 context->deleteTexture(textures[i]);
2386 }
2387 }
2388 }
2389 }
2390 catch(std::bad_alloc&)
2391 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002392 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002393 }
2394}
2395
2396void __stdcall glDepthFunc(GLenum func)
2397{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002398 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002399
2400 try
2401 {
2402 switch (func)
2403 {
2404 case GL_NEVER:
2405 case GL_ALWAYS:
2406 case GL_LESS:
2407 case GL_LEQUAL:
2408 case GL_EQUAL:
2409 case GL_GREATER:
2410 case GL_GEQUAL:
2411 case GL_NOTEQUAL:
2412 break;
2413 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002414 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002415 }
2416
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002417 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002418
2419 if (context)
2420 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002421 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002422 }
2423 }
2424 catch(std::bad_alloc&)
2425 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002426 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002427 }
2428}
2429
2430void __stdcall glDepthMask(GLboolean flag)
2431{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002432 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002433
2434 try
2435 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002436 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002437
2438 if (context)
2439 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002440 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002441 }
2442 }
2443 catch(std::bad_alloc&)
2444 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002445 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002446 }
2447}
2448
2449void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
2450{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002451 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002452
2453 try
2454 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002455 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002456
2457 if (context)
2458 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002459 context->setDepthRange(zNear, zFar);
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
2468void __stdcall glDetachShader(GLuint program, GLuint shader)
2469{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002470 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002471
2472 try
2473 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002474 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002475
2476 if (context)
2477 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002478
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002479 gl::Program *programObject = context->getProgram(program);
2480 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002481
2482 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002483 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002484 gl::Shader *shaderByProgramHandle;
2485 shaderByProgramHandle = context->getShader(program);
2486 if (!shaderByProgramHandle)
2487 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002488 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002489 }
2490 else
2491 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002492 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002493 }
2494 }
2495
2496 if (!shaderObject)
2497 {
2498 gl::Program *programByShaderHandle = context->getProgram(shader);
2499 if (!programByShaderHandle)
2500 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002501 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002502 }
2503 else
2504 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002505 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002506 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002507 }
2508
2509 if (!programObject->detachShader(shaderObject))
2510 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002511 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002512 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002513 }
2514 }
2515 catch(std::bad_alloc&)
2516 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002517 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002518 }
2519}
2520
2521void __stdcall glDisable(GLenum cap)
2522{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002523 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002524
2525 try
2526 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002527 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002528
2529 if (context)
2530 {
2531 switch (cap)
2532 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002533 case GL_CULL_FACE: context->setCullFace(false); break;
2534 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
2535 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
2536 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
2537 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
2538 case GL_STENCIL_TEST: context->setStencilTest(false); break;
2539 case GL_DEPTH_TEST: context->setDepthTest(false); break;
2540 case GL_BLEND: context->setBlend(false); break;
2541 case GL_DITHER: context->setDither(false); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002542 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002543 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002544 }
2545 }
2546 }
2547 catch(std::bad_alloc&)
2548 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002549 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002550 }
2551}
2552
2553void __stdcall glDisableVertexAttribArray(GLuint index)
2554{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002555 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002556
2557 try
2558 {
2559 if (index >= gl::MAX_VERTEX_ATTRIBS)
2560 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002561 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002562 }
2563
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002564 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002565
2566 if (context)
2567 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00002568 context->setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002569 }
2570 }
2571 catch(std::bad_alloc&)
2572 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002573 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002574 }
2575}
2576
2577void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
2578{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002579 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002580
2581 try
2582 {
2583 if (count < 0 || first < 0)
2584 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002585 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002586 }
2587
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002588 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002589
2590 if (context)
2591 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002592 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002593 }
2594 }
2595 catch(std::bad_alloc&)
2596 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002597 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002598 }
2599}
2600
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002601void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
2602{
2603 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
2604
2605 try
2606 {
2607 if (count < 0 || first < 0 || primcount < 0)
2608 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002609 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002610 }
2611
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002612 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002613 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002614 gl::Context *context = gl::getNonLostContext();
2615
2616 if (context)
2617 {
2618 context->drawArrays(mode, first, count, primcount);
2619 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002620 }
2621 }
2622 catch(std::bad_alloc&)
2623 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002624 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002625 }
2626}
2627
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002628void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002629{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002630 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 +00002631 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002632
2633 try
2634 {
2635 if (count < 0)
2636 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002637 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002638 }
2639
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002640 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002641
2642 if (context)
2643 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00002644 switch (type)
2645 {
2646 case GL_UNSIGNED_BYTE:
2647 case GL_UNSIGNED_SHORT:
2648 break;
2649 case GL_UNSIGNED_INT:
2650 if (!context->supports32bitIndices())
2651 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002652 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00002653 }
2654 break;
2655 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002656 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00002657 }
2658
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002659 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002660 }
2661 }
2662 catch(std::bad_alloc&)
2663 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002664 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002665 }
2666}
2667
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002668void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
2669{
2670 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
2671 mode, count, type, indices, primcount);
2672
2673 try
2674 {
2675 if (count < 0 || primcount < 0)
2676 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002677 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002678 }
2679
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002680 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002681 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002682 gl::Context *context = gl::getNonLostContext();
2683
2684 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002685 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002686 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002687 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002688 case GL_UNSIGNED_BYTE:
2689 case GL_UNSIGNED_SHORT:
2690 break;
2691 case GL_UNSIGNED_INT:
2692 if (!context->supports32bitIndices())
2693 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002694 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002695 }
2696 break;
2697 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002698 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002699 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002700
2701 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002702 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002703 }
2704 }
2705 catch(std::bad_alloc&)
2706 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002707 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002708 }
2709}
2710
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002711void __stdcall glEnable(GLenum cap)
2712{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002713 EVENT("(GLenum cap = 0x%X)", cap);
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 switch (cap)
2722 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002723 case GL_CULL_FACE: context->setCullFace(true); break;
2724 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
2725 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
2726 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
2727 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
2728 case GL_STENCIL_TEST: context->setStencilTest(true); break;
2729 case GL_DEPTH_TEST: context->setDepthTest(true); break;
2730 case GL_BLEND: context->setBlend(true); break;
2731 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002732 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002733 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002734 }
2735 }
2736 }
2737 catch(std::bad_alloc&)
2738 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002739 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002740 }
2741}
2742
2743void __stdcall glEnableVertexAttribArray(GLuint index)
2744{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002745 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002746
2747 try
2748 {
2749 if (index >= gl::MAX_VERTEX_ATTRIBS)
2750 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002751 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002752 }
2753
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002754 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002755
2756 if (context)
2757 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00002758 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002759 }
2760 }
2761 catch(std::bad_alloc&)
2762 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002763 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002764 }
2765}
2766
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002767void __stdcall glEndQueryEXT(GLenum target)
2768{
2769 EVENT("GLenum target = 0x%X)", target);
2770
2771 try
2772 {
2773 switch (target)
2774 {
2775 case GL_ANY_SAMPLES_PASSED_EXT:
2776 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
2777 break;
2778 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002779 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002780 }
2781
2782 gl::Context *context = gl::getNonLostContext();
2783
2784 if (context)
2785 {
2786 context->endQuery(target);
2787 }
2788 }
2789 catch(std::bad_alloc&)
2790 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002791 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002792 }
2793}
2794
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002795void __stdcall glFinishFenceNV(GLuint fence)
2796{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002797 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002798
2799 try
2800 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002801 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002802
2803 if (context)
2804 {
2805 gl::Fence* fenceObject = context->getFence(fence);
2806
2807 if (fenceObject == NULL)
2808 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002809 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002810 }
2811
2812 fenceObject->finishFence();
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);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002818 }
2819}
2820
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002821void __stdcall glFinish(void)
2822{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002823 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002824
2825 try
2826 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002827 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002828
2829 if (context)
2830 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00002831 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002832 }
2833 }
2834 catch(std::bad_alloc&)
2835 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002836 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002837 }
2838}
2839
2840void __stdcall glFlush(void)
2841{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002842 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002843
2844 try
2845 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002846 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002847
2848 if (context)
2849 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00002850 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002851 }
2852 }
2853 catch(std::bad_alloc&)
2854 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002855 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002856 }
2857}
2858
2859void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
2860{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002861 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002862 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002863
2864 try
2865 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002866 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00002867 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002868 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002869 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002870 }
2871
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002872 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002873
2874 if (context)
2875 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002876 gl::Framebuffer *framebuffer = NULL;
2877 GLuint framebufferHandle = 0;
2878 if (target == GL_READ_FRAMEBUFFER_ANGLE)
2879 {
2880 framebuffer = context->getReadFramebuffer();
2881 framebufferHandle = context->getReadFramebufferHandle();
2882 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00002883 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002884 {
2885 framebuffer = context->getDrawFramebuffer();
2886 framebufferHandle = context->getDrawFramebufferHandle();
2887 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002888
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00002889 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002890 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002891 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002892 }
2893
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002894 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002895 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002896 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
2897
2898 if (colorAttachment >= context->getMaximumRenderTargets())
2899 {
2900 return gl::error(GL_INVALID_VALUE);
2901 }
2902
2903 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer);
2904 }
2905 else
2906 {
2907 switch (attachment)
2908 {
2909 case GL_DEPTH_ATTACHMENT:
2910 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer);
2911 break;
2912 case GL_STENCIL_ATTACHMENT:
2913 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer);
2914 break;
2915 default:
2916 return gl::error(GL_INVALID_ENUM);
2917 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002918 }
2919 }
2920 }
2921 catch(std::bad_alloc&)
2922 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002923 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002924 }
2925}
2926
2927void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
2928{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002929 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002930 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002931
2932 try
2933 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002934 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002935 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002936 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002937 }
2938
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002939 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002940
2941 if (context)
2942 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002943 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
2944 {
2945 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
2946
2947 if (colorAttachment >= context->getMaximumRenderTargets())
2948 {
2949 return gl::error(GL_INVALID_VALUE);
2950 }
2951 }
2952 else
2953 {
2954 switch (attachment)
2955 {
2956 case GL_DEPTH_ATTACHMENT:
2957 case GL_STENCIL_ATTACHMENT:
2958 break;
2959 default:
2960 return gl::error(GL_INVALID_ENUM);
2961 }
2962 }
2963
daniel@transgaming.com93a81472010-04-20 18:52:58 +00002964 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002965 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00002966 textarget = GL_NONE;
2967 }
2968 else
2969 {
2970 gl::Texture *tex = context->getTexture(texture);
2971
2972 if (tex == NULL)
2973 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002974 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com93a81472010-04-20 18:52:58 +00002975 }
2976
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002977 switch (textarget)
2978 {
2979 case GL_TEXTURE_2D:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002980 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00002981 if (tex->getTarget() != GL_TEXTURE_2D)
2982 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002983 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00002984 }
2985 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
daniel@transgaming.com92f49922012-05-09 15:49:19 +00002986 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00002987 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002988 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00002989 }
2990 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002991 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00002992
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002993 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002994 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002995 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002996 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002997 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002998 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com93a81472010-04-20 18:52:58 +00002999 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003000 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
3001 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003002 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003003 }
3004 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00003005 if (texcube->isCompressed(textarget, level))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003006 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003007 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003008 }
3009 break;
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003010 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003011
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003012 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003013 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003014 }
3015
3016 if (level != 0)
3017 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003018 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003019 }
3020 }
3021
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003022 gl::Framebuffer *framebuffer = NULL;
3023 GLuint framebufferHandle = 0;
3024 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3025 {
3026 framebuffer = context->getReadFramebuffer();
3027 framebufferHandle = context->getReadFramebufferHandle();
3028 }
3029 else
3030 {
3031 framebuffer = context->getDrawFramebuffer();
3032 framebufferHandle = context->getDrawFramebufferHandle();
3033 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003034
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003035 if (framebufferHandle == 0 || !framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003036 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003037 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003038 }
3039
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003040 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00003041 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003042 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3043
3044 if (colorAttachment >= context->getMaximumRenderTargets())
3045 {
3046 return gl::error(GL_INVALID_VALUE);
3047 }
3048
3049 framebuffer->setColorbuffer(colorAttachment, textarget, texture);
3050 }
3051 else
3052 {
3053 switch (attachment)
3054 {
3055 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture); break;
3056 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture); break;
3057 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00003058 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003059 }
3060 }
3061 catch(std::bad_alloc&)
3062 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003063 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003064 }
3065}
3066
3067void __stdcall glFrontFace(GLenum mode)
3068{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003069 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003070
3071 try
3072 {
3073 switch (mode)
3074 {
3075 case GL_CW:
3076 case GL_CCW:
3077 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003078 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003079
3080 if (context)
3081 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003082 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003083 }
3084 }
3085 break;
3086 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003087 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003088 }
3089 }
3090 catch(std::bad_alloc&)
3091 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003092 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003093 }
3094}
3095
3096void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
3097{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003098 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003099
3100 try
3101 {
3102 if (n < 0)
3103 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003104 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003105 }
3106
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003107 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003108
3109 if (context)
3110 {
3111 for (int i = 0; i < n; i++)
3112 {
3113 buffers[i] = context->createBuffer();
3114 }
3115 }
3116 }
3117 catch(std::bad_alloc&)
3118 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003119 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003120 }
3121}
3122
3123void __stdcall glGenerateMipmap(GLenum target)
3124{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003125 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003126
3127 try
3128 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003129 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003130
3131 if (context)
3132 {
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003133 switch (target)
3134 {
3135 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003136 {
3137 gl::Texture2D *tex2d = context->getTexture2D();
3138
daniel@transgaming.com92f49922012-05-09 15:49:19 +00003139 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003140 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003141 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003142 }
daniel@transgaming.com0c854682012-05-31 01:14:11 +00003143 if (tex2d->isDepth(0))
3144 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003145 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00003146 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003147
3148 tex2d->generateMipmaps();
3149 break;
3150 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003151
3152 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003153 {
3154 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
3155
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00003156 if (texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003157 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003158 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003159 }
3160
3161 texcube->generateMipmaps();
3162 break;
3163 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003164
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00003165 case GL_TEXTURE_3D:
3166 {
3167 if (context->getClientVersion() < 3)
3168 {
3169 return gl::error(GL_INVALID_ENUM);
3170 }
3171
3172 gl::Texture3D *tex3D = context->getTexture3D();
3173 if (tex3D->isCompressed(0))
3174 {
3175 return gl::error(GL_INVALID_OPERATION);
3176 }
3177
3178 tex3D->generateMipmaps();
3179 break;
3180 }
3181
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003182 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003183 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003184 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003185 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003186 }
3187 catch(std::bad_alloc&)
3188 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003189 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003190 }
3191}
3192
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003193void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
3194{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003195 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003196
3197 try
3198 {
3199 if (n < 0)
3200 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003201 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003202 }
3203
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003204 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003205
3206 if (context)
3207 {
3208 for (int i = 0; i < n; i++)
3209 {
3210 fences[i] = context->createFence();
3211 }
3212 }
3213 }
3214 catch(std::bad_alloc&)
3215 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003216 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003217 }
3218}
3219
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003220void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
3221{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003222 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003223
3224 try
3225 {
3226 if (n < 0)
3227 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003228 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003229 }
3230
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003231 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003232
3233 if (context)
3234 {
3235 for (int i = 0; i < n; i++)
3236 {
3237 framebuffers[i] = context->createFramebuffer();
3238 }
3239 }
3240 }
3241 catch(std::bad_alloc&)
3242 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003243 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003244 }
3245}
3246
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003247void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
3248{
3249 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
3250
3251 try
3252 {
3253 if (n < 0)
3254 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003255 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003256 }
3257
3258 gl::Context *context = gl::getNonLostContext();
3259
3260 if (context)
3261 {
3262 for (int i = 0; i < n; i++)
3263 {
3264 ids[i] = context->createQuery();
3265 }
3266 }
3267 }
3268 catch(std::bad_alloc&)
3269 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003270 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003271 }
3272}
3273
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003274void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
3275{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003276 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003277
3278 try
3279 {
3280 if (n < 0)
3281 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003282 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003283 }
3284
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003285 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003286
3287 if (context)
3288 {
3289 for (int i = 0; i < n; i++)
3290 {
3291 renderbuffers[i] = context->createRenderbuffer();
3292 }
3293 }
3294 }
3295 catch(std::bad_alloc&)
3296 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003297 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003298 }
3299}
3300
3301void __stdcall glGenTextures(GLsizei n, GLuint* textures)
3302{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003303 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003304
3305 try
3306 {
3307 if (n < 0)
3308 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003309 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003310 }
3311
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003312 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003313
3314 if (context)
3315 {
3316 for (int i = 0; i < n; i++)
3317 {
3318 textures[i] = context->createTexture();
3319 }
3320 }
3321 }
3322 catch(std::bad_alloc&)
3323 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003324 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003325 }
3326}
3327
daniel@transgaming.com85423182010-04-22 13:35:27 +00003328void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003329{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003330 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00003331 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003332 program, index, bufsize, length, size, type, name);
3333
3334 try
3335 {
3336 if (bufsize < 0)
3337 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003338 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003339 }
3340
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003341 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00003342
3343 if (context)
3344 {
3345 gl::Program *programObject = context->getProgram(program);
3346
3347 if (!programObject)
3348 {
3349 if (context->getShader(program))
3350 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003351 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00003352 }
3353 else
3354 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003355 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00003356 }
3357 }
3358
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00003359 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00003360 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003361 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00003362 }
3363
3364 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
3365 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003366 }
3367 catch(std::bad_alloc&)
3368 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003369 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003370 }
3371}
3372
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003373void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003374{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003375 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003376 "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 +00003377 program, index, bufsize, length, size, type, name);
3378
3379 try
3380 {
3381 if (bufsize < 0)
3382 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003383 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003384 }
3385
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003386 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00003387
3388 if (context)
3389 {
3390 gl::Program *programObject = context->getProgram(program);
3391
3392 if (!programObject)
3393 {
3394 if (context->getShader(program))
3395 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003396 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00003397 }
3398 else
3399 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003400 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00003401 }
3402 }
3403
3404 if (index >= (GLuint)programObject->getActiveUniformCount())
3405 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003406 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00003407 }
3408
3409 programObject->getActiveUniform(index, bufsize, length, size, type, name);
3410 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003411 }
3412 catch(std::bad_alloc&)
3413 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003414 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003415 }
3416}
3417
3418void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
3419{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003420 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 +00003421 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003422
3423 try
3424 {
3425 if (maxcount < 0)
3426 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003427 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003428 }
3429
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003430 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00003431
3432 if (context)
3433 {
3434 gl::Program *programObject = context->getProgram(program);
3435
3436 if (!programObject)
3437 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00003438 if (context->getShader(program))
3439 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003440 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00003441 }
3442 else
3443 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003444 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00003445 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00003446 }
3447
3448 return programObject->getAttachedShaders(maxcount, count, shaders);
3449 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003450 }
3451 catch(std::bad_alloc&)
3452 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003453 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003454 }
3455}
3456
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003457int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003458{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003459 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003460
3461 try
3462 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003463 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003464
3465 if (context)
3466 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00003467
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003468 gl::Program *programObject = context->getProgram(program);
3469
3470 if (!programObject)
3471 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00003472 if (context->getShader(program))
3473 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003474 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00003475 }
3476 else
3477 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003478 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00003479 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003480 }
3481
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00003482 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00003483 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00003484 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003485 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00003486 }
3487
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00003488 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003489 }
3490 }
3491 catch(std::bad_alloc&)
3492 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003493 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003494 }
3495
3496 return -1;
3497}
3498
3499void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
3500{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003501 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003502
3503 try
3504 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003505 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003506
3507 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003508 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003509 if (!(context->getBooleanv(pname, params)))
3510 {
3511 GLenum nativeType;
3512 unsigned int numParams = 0;
3513 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003514 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003515
3516 if (numParams == 0)
3517 return; // it is known that the pname is valid, but there are no parameters to return
3518
3519 if (nativeType == GL_FLOAT)
3520 {
3521 GLfloat *floatParams = NULL;
3522 floatParams = new GLfloat[numParams];
3523
3524 context->getFloatv(pname, floatParams);
3525
3526 for (unsigned int i = 0; i < numParams; ++i)
3527 {
3528 if (floatParams[i] == 0.0f)
3529 params[i] = GL_FALSE;
3530 else
3531 params[i] = GL_TRUE;
3532 }
3533
3534 delete [] floatParams;
3535 }
3536 else if (nativeType == GL_INT)
3537 {
3538 GLint *intParams = NULL;
3539 intParams = new GLint[numParams];
3540
3541 context->getIntegerv(pname, intParams);
3542
3543 for (unsigned int i = 0; i < numParams; ++i)
3544 {
3545 if (intParams[i] == 0)
3546 params[i] = GL_FALSE;
3547 else
3548 params[i] = GL_TRUE;
3549 }
3550
3551 delete [] intParams;
3552 }
3553 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003554 }
3555 }
3556 catch(std::bad_alloc&)
3557 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003558 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003559 }
3560}
3561
3562void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
3563{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003564 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 +00003565
3566 try
3567 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003568 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00003569
3570 if (context)
3571 {
3572 gl::Buffer *buffer;
3573
3574 switch (target)
3575 {
3576 case GL_ARRAY_BUFFER:
3577 buffer = context->getArrayBuffer();
3578 break;
3579 case GL_ELEMENT_ARRAY_BUFFER:
3580 buffer = context->getElementArrayBuffer();
3581 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003582 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00003583 }
3584
3585 if (!buffer)
3586 {
3587 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003588 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00003589 }
3590
3591 switch (pname)
3592 {
3593 case GL_BUFFER_USAGE:
3594 *params = buffer->usage();
3595 break;
3596 case GL_BUFFER_SIZE:
3597 *params = buffer->size();
3598 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003599 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00003600 }
3601 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003602 }
3603 catch(std::bad_alloc&)
3604 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003605 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003606 }
3607}
3608
3609GLenum __stdcall glGetError(void)
3610{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003611 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003612
3613 gl::Context *context = gl::getContext();
3614
3615 if (context)
3616 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00003617 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003618 }
3619
3620 return GL_NO_ERROR;
3621}
3622
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003623void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
3624{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003625 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003626
3627 try
3628 {
3629
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003630 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003631
3632 if (context)
3633 {
3634 gl::Fence *fenceObject = context->getFence(fence);
3635
3636 if (fenceObject == NULL)
3637 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003638 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003639 }
3640
3641 fenceObject->getFenceiv(pname, params);
3642 }
3643 }
3644 catch(std::bad_alloc&)
3645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003646 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003647 }
3648}
3649
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003650void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
3651{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003652 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003653
3654 try
3655 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003656 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00003657
3658 if (context)
3659 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003660 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00003661 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003662 GLenum nativeType;
3663 unsigned int numParams = 0;
3664 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003665 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003666
3667 if (numParams == 0)
3668 return; // it is known that the pname is valid, but that there are no parameters to return.
3669
3670 if (nativeType == GL_BOOL)
3671 {
3672 GLboolean *boolParams = NULL;
3673 boolParams = new GLboolean[numParams];
3674
3675 context->getBooleanv(pname, boolParams);
3676
3677 for (unsigned int i = 0; i < numParams; ++i)
3678 {
3679 if (boolParams[i] == GL_FALSE)
3680 params[i] = 0.0f;
3681 else
3682 params[i] = 1.0f;
3683 }
3684
3685 delete [] boolParams;
3686 }
3687 else if (nativeType == GL_INT)
3688 {
3689 GLint *intParams = NULL;
3690 intParams = new GLint[numParams];
3691
3692 context->getIntegerv(pname, intParams);
3693
3694 for (unsigned int i = 0; i < numParams; ++i)
3695 {
3696 params[i] = (GLfloat)intParams[i];
3697 }
3698
3699 delete [] intParams;
3700 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00003701 }
3702 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003703 }
3704 catch(std::bad_alloc&)
3705 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003706 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003707 }
3708}
3709
3710void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
3711{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003712 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 +00003713 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003714
3715 try
3716 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003717 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003718
3719 if (context)
3720 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003721 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003722 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003723 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003724 }
3725
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003726 gl::Framebuffer *framebuffer = NULL;
3727 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3728 {
3729 if(context->getReadFramebufferHandle() == 0)
3730 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003731 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003732 }
3733
3734 framebuffer = context->getReadFramebuffer();
3735 }
3736 else
3737 {
3738 if (context->getDrawFramebufferHandle() == 0)
3739 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003740 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003741 }
3742
3743 framebuffer = context->getDrawFramebuffer();
3744 }
3745
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003746 GLenum attachmentType;
3747 GLuint attachmentHandle;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003748
3749 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003750 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003751 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3752
3753 if (colorAttachment >= context->getMaximumRenderTargets())
3754 {
3755 return gl::error(GL_INVALID_ENUM);
3756 }
3757
3758 attachmentType = framebuffer->getColorbufferType(colorAttachment);
3759 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
3760 }
3761 else
3762 {
3763 switch (attachment)
3764 {
3765 case GL_DEPTH_ATTACHMENT:
3766 attachmentType = framebuffer->getDepthbufferType();
3767 attachmentHandle = framebuffer->getDepthbufferHandle();
3768 break;
3769 case GL_STENCIL_ATTACHMENT:
3770 attachmentType = framebuffer->getStencilbufferType();
3771 attachmentHandle = framebuffer->getStencilbufferHandle();
3772 break;
3773 default: return gl::error(GL_INVALID_ENUM);
3774 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003775 }
3776
3777 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00003778 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003779 {
3780 attachmentObjectType = attachmentType;
3781 }
apatrick@chromium.org551022e2012-01-23 19:56:54 +00003782 else if (gl::IsInternalTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003783 {
3784 attachmentObjectType = GL_TEXTURE;
3785 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00003786 else
3787 {
3788 UNREACHABLE();
3789 return;
3790 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003791
3792 switch (pname)
3793 {
3794 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
3795 *params = attachmentObjectType;
3796 break;
3797 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
3798 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
3799 {
3800 *params = attachmentHandle;
3801 }
3802 else
3803 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003804 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003805 }
3806 break;
3807 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
3808 if (attachmentObjectType == GL_TEXTURE)
3809 {
3810 *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0
3811 }
3812 else
3813 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003814 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003815 }
3816 break;
3817 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
3818 if (attachmentObjectType == GL_TEXTURE)
3819 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00003820 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003821 {
3822 *params = attachmentType;
3823 }
3824 else
3825 {
3826 *params = 0;
3827 }
3828 }
3829 else
3830 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003831 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003832 }
3833 break;
3834 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003835 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003836 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003837 }
3838 }
3839 catch(std::bad_alloc&)
3840 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003841 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003842 }
3843}
3844
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00003845GLenum __stdcall glGetGraphicsResetStatusEXT(void)
3846{
3847 EVENT("()");
3848
3849 try
3850 {
3851 gl::Context *context = gl::getContext();
3852
3853 if (context)
3854 {
3855 return context->getResetStatus();
3856 }
3857
3858 return GL_NO_ERROR;
3859 }
3860 catch(std::bad_alloc&)
3861 {
3862 return GL_OUT_OF_MEMORY;
3863 }
3864}
3865
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003866void __stdcall glGetIntegerv(GLenum pname, GLint* params)
3867{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003868 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003869
3870 try
3871 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003872 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003873
3874 if (context)
3875 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003876 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003877 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003878 GLenum nativeType;
3879 unsigned int numParams = 0;
3880 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003881 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003882
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003883 if (numParams == 0)
3884 return; // it is known that pname is valid, but there are no parameters to return
3885
3886 if (nativeType == GL_BOOL)
3887 {
3888 GLboolean *boolParams = NULL;
3889 boolParams = new GLboolean[numParams];
3890
3891 context->getBooleanv(pname, boolParams);
3892
3893 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003894 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003895 if (boolParams[i] == GL_FALSE)
3896 params[i] = 0;
3897 else
3898 params[i] = 1;
3899 }
3900
3901 delete [] boolParams;
3902 }
3903 else if (nativeType == GL_FLOAT)
3904 {
3905 GLfloat *floatParams = NULL;
3906 floatParams = new GLfloat[numParams];
3907
3908 context->getFloatv(pname, floatParams);
3909
3910 for (unsigned int i = 0; i < numParams; ++i)
3911 {
daniel@transgaming.comc1641352010-04-26 15:33:36 +00003912 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 +00003913 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003914 params[i] = (GLint)(((GLfloat)(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003915 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003916 else
3917 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 +00003918 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003919
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003920 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003921 }
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 glGetProgramiv(GLuint program, GLenum pname, GLint* params)
3932{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003933 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003934
3935 try
3936 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003937 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003938
3939 if (context)
3940 {
3941 gl::Program *programObject = context->getProgram(program);
3942
3943 if (!programObject)
3944 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003945 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003946 }
3947
3948 switch (pname)
3949 {
3950 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00003951 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003952 return;
3953 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00003954 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003955 return;
3956 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00003957 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003958 return;
3959 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00003960 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003961 return;
3962 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00003963 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003964 return;
3965 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00003966 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003967 return;
3968 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00003969 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003970 return;
3971 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00003972 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003973 return;
3974 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00003975 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003976 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00003977 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00003978 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00003979 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003980 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003981 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003982 }
3983 }
3984 }
3985 catch(std::bad_alloc&)
3986 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003987 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003988 }
3989}
3990
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003991void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003992{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003993 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 +00003994 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003995
3996 try
3997 {
3998 if (bufsize < 0)
3999 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004000 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004001 }
4002
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004003 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004004
4005 if (context)
4006 {
4007 gl::Program *programObject = context->getProgram(program);
4008
4009 if (!programObject)
4010 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004011 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004012 }
4013
4014 programObject->getInfoLog(bufsize, length, infolog);
4015 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004016 }
4017 catch(std::bad_alloc&)
4018 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004019 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004020 }
4021}
4022
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004023void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
4024{
4025 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
4026
4027 try
4028 {
4029 switch (pname)
4030 {
4031 case GL_CURRENT_QUERY_EXT:
4032 break;
4033 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004034 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004035 }
4036
4037 gl::Context *context = gl::getNonLostContext();
4038
4039 if (context)
4040 {
4041 params[0] = context->getActiveQuery(target);
4042 }
4043 }
4044 catch(std::bad_alloc&)
4045 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004046 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004047 }
4048}
4049
4050void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
4051{
4052 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
4053
4054 try
4055 {
4056 switch (pname)
4057 {
4058 case GL_QUERY_RESULT_EXT:
4059 case GL_QUERY_RESULT_AVAILABLE_EXT:
4060 break;
4061 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004062 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004063 }
4064 gl::Context *context = gl::getNonLostContext();
4065
4066 if (context)
4067 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004068 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
4069
4070 if (!queryObject)
4071 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004072 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004073 }
4074
4075 if (context->getActiveQuery(queryObject->getType()) == id)
4076 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004077 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004078 }
4079
4080 switch(pname)
4081 {
4082 case GL_QUERY_RESULT_EXT:
4083 params[0] = queryObject->getResult();
4084 break;
4085 case GL_QUERY_RESULT_AVAILABLE_EXT:
4086 params[0] = queryObject->isResultAvailable();
4087 break;
4088 default:
4089 ASSERT(false);
4090 }
4091 }
4092 }
4093 catch(std::bad_alloc&)
4094 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004095 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004096 }
4097}
4098
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004099void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
4100{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004101 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 +00004102
4103 try
4104 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004105 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004106
4107 if (context)
4108 {
4109 if (target != GL_RENDERBUFFER)
4110 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004111 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004112 }
4113
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004114 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004115 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004116 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004117 }
4118
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004119 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004120
4121 switch (pname)
4122 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00004123 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
4124 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
4125 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
4126 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
4127 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
4128 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
4129 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
4130 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
4131 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00004132 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00004133 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00004134 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00004135 *params = renderbuffer->getSamples();
4136 }
4137 else
4138 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004139 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00004140 }
4141 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004142 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004143 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004144 }
4145 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004146 }
4147 catch(std::bad_alloc&)
4148 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004149 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004150 }
4151}
4152
4153void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
4154{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004155 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004156
4157 try
4158 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004159 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004160
4161 if (context)
4162 {
4163 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00004164
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004165 if (!shaderObject)
4166 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004167 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004168 }
4169
4170 switch (pname)
4171 {
4172 case GL_SHADER_TYPE:
4173 *params = shaderObject->getType();
4174 return;
4175 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004176 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004177 return;
4178 case GL_COMPILE_STATUS:
4179 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
4180 return;
4181 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004182 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004183 return;
4184 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004185 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004186 return;
zmo@google.coma574f782011-10-03 21:45:23 +00004187 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
4188 *params = shaderObject->getTranslatedSourceLength();
4189 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004190 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004191 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004192 }
4193 }
4194 }
4195 catch(std::bad_alloc&)
4196 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004197 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004198 }
4199}
4200
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004201void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004202{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004203 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 +00004204 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004205
4206 try
4207 {
4208 if (bufsize < 0)
4209 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004210 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004211 }
4212
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004213 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004214
4215 if (context)
4216 {
4217 gl::Shader *shaderObject = context->getShader(shader);
4218
4219 if (!shaderObject)
4220 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004221 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004222 }
4223
4224 shaderObject->getInfoLog(bufsize, length, infolog);
4225 }
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
4233void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
4234{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004235 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 +00004236 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004237
4238 try
4239 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004240 switch (shadertype)
4241 {
4242 case GL_VERTEX_SHADER:
4243 case GL_FRAGMENT_SHADER:
4244 break;
4245 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004246 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004247 }
4248
4249 switch (precisiontype)
4250 {
4251 case GL_LOW_FLOAT:
4252 case GL_MEDIUM_FLOAT:
4253 case GL_HIGH_FLOAT:
4254 // Assume IEEE 754 precision
4255 range[0] = 127;
4256 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00004257 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004258 break;
4259 case GL_LOW_INT:
4260 case GL_MEDIUM_INT:
4261 case GL_HIGH_INT:
4262 // Some (most) hardware only supports single-precision floating-point numbers,
4263 // which can accurately represent integers up to +/-16777216
4264 range[0] = 24;
4265 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00004266 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004267 break;
4268 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004269 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004270 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004271 }
4272 catch(std::bad_alloc&)
4273 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004274 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004275 }
4276}
4277
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004278void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004279{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004280 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 +00004281 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004282
4283 try
4284 {
4285 if (bufsize < 0)
4286 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004287 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004288 }
4289
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004290 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004291
4292 if (context)
4293 {
4294 gl::Shader *shaderObject = context->getShader(shader);
4295
4296 if (!shaderObject)
4297 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004298 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004299 }
4300
4301 shaderObject->getSource(bufsize, length, source);
4302 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004303 }
4304 catch(std::bad_alloc&)
4305 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004306 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004307 }
4308}
4309
zmo@google.coma574f782011-10-03 21:45:23 +00004310void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
4311{
4312 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
4313 shader, bufsize, length, source);
4314
4315 try
4316 {
4317 if (bufsize < 0)
4318 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004319 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00004320 }
4321
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004322 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00004323
4324 if (context)
4325 {
4326 gl::Shader *shaderObject = context->getShader(shader);
4327
4328 if (!shaderObject)
4329 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004330 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00004331 }
4332
4333 shaderObject->getTranslatedSource(bufsize, length, source);
4334 }
4335 }
4336 catch(std::bad_alloc&)
4337 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004338 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00004339 }
4340}
4341
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004342const GLubyte* __stdcall glGetString(GLenum name)
4343{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004344 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004345
4346 try
4347 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004348 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00004349
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004350 switch (name)
4351 {
4352 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00004353 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004354 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00004355 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004356 case GL_VERSION:
daniel@transgaming.com1825d8e2012-08-27 16:25:29 +00004357 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004358 case GL_SHADING_LANGUAGE_VERSION:
daniel@transgaming.com1825d8e2012-08-27 16:25:29 +00004359 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004360 case GL_EXTENSIONS:
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00004361 return (GLubyte*)((context != NULL) ? context->getExtensionString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004362 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004363 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004364 }
4365 }
4366 catch(std::bad_alloc&)
4367 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004368 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004369 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004370}
4371
4372void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
4373{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004374 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 +00004375
4376 try
4377 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004378 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004379
4380 if (context)
4381 {
4382 gl::Texture *texture;
4383
4384 switch (target)
4385 {
4386 case GL_TEXTURE_2D:
4387 texture = context->getTexture2D();
4388 break;
4389 case GL_TEXTURE_CUBE_MAP:
4390 texture = context->getTextureCubeMap();
4391 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00004392 case GL_TEXTURE_3D:
4393 if (context->getClientVersion() < 3)
4394 {
4395 return gl::error(GL_INVALID_ENUM);
4396 }
4397 texture = context->getTexture3D();
4398 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004399 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004400 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004401 }
4402
4403 switch (pname)
4404 {
4405 case GL_TEXTURE_MAG_FILTER:
4406 *params = (GLfloat)texture->getMagFilter();
4407 break;
4408 case GL_TEXTURE_MIN_FILTER:
4409 *params = (GLfloat)texture->getMinFilter();
4410 break;
4411 case GL_TEXTURE_WRAP_S:
4412 *params = (GLfloat)texture->getWrapS();
4413 break;
4414 case GL_TEXTURE_WRAP_T:
4415 *params = (GLfloat)texture->getWrapT();
4416 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00004417 case GL_TEXTURE_WRAP_R:
4418 if (context->getClientVersion() < 3)
4419 {
4420 return gl::error(GL_INVALID_ENUM);
4421 }
4422 *params = (GLfloat)texture->getWrapR();
4423 break;
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00004424 case GL_TEXTURE_IMMUTABLE_FORMAT_EXT:
4425 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
4426 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00004427 case GL_TEXTURE_USAGE_ANGLE:
4428 *params = (GLfloat)texture->getUsage();
4429 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004430 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
4431 if (!context->supportsTextureFilterAnisotropy())
4432 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004433 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004434 }
4435 *params = (GLfloat)texture->getMaxAnisotropy();
4436 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004437 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004438 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004439 }
4440 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004441 }
4442 catch(std::bad_alloc&)
4443 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004444 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004445 }
4446}
4447
4448void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
4449{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004450 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 +00004451
4452 try
4453 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004454 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004455
4456 if (context)
4457 {
4458 gl::Texture *texture;
4459
4460 switch (target)
4461 {
4462 case GL_TEXTURE_2D:
4463 texture = context->getTexture2D();
4464 break;
4465 case GL_TEXTURE_CUBE_MAP:
4466 texture = context->getTextureCubeMap();
4467 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00004468 case GL_TEXTURE_3D:
4469 if (context->getClientVersion() < 3)
4470 {
4471 return gl::error(GL_INVALID_ENUM);
4472 }
4473 texture = context->getTexture3D();
4474 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004475 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004476 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004477 }
4478
4479 switch (pname)
4480 {
4481 case GL_TEXTURE_MAG_FILTER:
4482 *params = texture->getMagFilter();
4483 break;
4484 case GL_TEXTURE_MIN_FILTER:
4485 *params = texture->getMinFilter();
4486 break;
4487 case GL_TEXTURE_WRAP_S:
4488 *params = texture->getWrapS();
4489 break;
4490 case GL_TEXTURE_WRAP_T:
4491 *params = texture->getWrapT();
4492 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00004493 case GL_TEXTURE_WRAP_R:
4494 if (context->getClientVersion() < 3)
4495 {
4496 return gl::error(GL_INVALID_ENUM);
4497 }
4498 *params = texture->getWrapR();
4499 break;
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00004500 case GL_TEXTURE_IMMUTABLE_FORMAT_EXT:
4501 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
4502 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00004503 case GL_TEXTURE_USAGE_ANGLE:
4504 *params = texture->getUsage();
4505 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004506 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
4507 if (!context->supportsTextureFilterAnisotropy())
4508 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004509 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004510 }
4511 *params = (GLint)texture->getMaxAnisotropy();
4512 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004513 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004514 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004515 }
4516 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004517 }
4518 catch(std::bad_alloc&)
4519 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004520 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004521 }
4522}
4523
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004524void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
4525{
4526 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
4527 program, location, bufSize, params);
4528
4529 try
4530 {
4531 if (bufSize < 0)
4532 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004533 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004534 }
4535
4536 gl::Context *context = gl::getNonLostContext();
4537
4538 if (context)
4539 {
4540 if (program == 0)
4541 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004542 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004543 }
4544
4545 gl::Program *programObject = context->getProgram(program);
4546
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004547 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004548 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004549 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004550 }
4551
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004552 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
4553 if (!programBinary)
4554 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004555 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004556 }
4557
4558 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004559 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004560 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004561 }
4562 }
4563 }
4564 catch(std::bad_alloc&)
4565 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004566 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004567 }
4568}
4569
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004570void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
4571{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004572 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004573
4574 try
4575 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004576 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004577
4578 if (context)
4579 {
4580 if (program == 0)
4581 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004582 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004583 }
4584
4585 gl::Program *programObject = context->getProgram(program);
4586
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004587 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004588 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004589 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004590 }
4591
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004592 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
4593 if (!programBinary)
4594 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004595 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004596 }
4597
4598 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004599 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004600 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004601 }
4602 }
4603 }
4604 catch(std::bad_alloc&)
4605 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004606 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004607 }
4608}
4609
4610void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
4611{
4612 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
4613 program, location, bufSize, params);
4614
4615 try
4616 {
4617 if (bufSize < 0)
4618 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004619 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004620 }
4621
4622 gl::Context *context = gl::getNonLostContext();
4623
4624 if (context)
4625 {
4626 if (program == 0)
4627 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004628 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004629 }
4630
4631 gl::Program *programObject = context->getProgram(program);
4632
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004633 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004634 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004635 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004636 }
4637
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004638 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
4639 if (!programBinary)
4640 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004641 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004642 }
4643
4644 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004646 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004647 }
4648 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004649 }
4650 catch(std::bad_alloc&)
4651 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004652 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004653 }
4654}
4655
4656void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
4657{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004658 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004659
4660 try
4661 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004662 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004663
4664 if (context)
4665 {
4666 if (program == 0)
4667 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004668 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004669 }
4670
4671 gl::Program *programObject = context->getProgram(program);
4672
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004673 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004674 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004675 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004676 }
4677
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004678 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
4679 if (!programBinary)
4680 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004681 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004682 }
4683
4684 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004685 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004686 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004687 }
4688 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004689 }
4690 catch(std::bad_alloc&)
4691 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004692 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004693 }
4694}
4695
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004696int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004697{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004698 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004699
4700 try
4701 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004702 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004703
4704 if (strstr(name, "gl_") == name)
4705 {
4706 return -1;
4707 }
4708
4709 if (context)
4710 {
4711 gl::Program *programObject = context->getProgram(program);
4712
4713 if (!programObject)
4714 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00004715 if (context->getShader(program))
4716 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004717 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00004718 }
4719 else
4720 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004721 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00004722 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004723 }
4724
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004725 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004726 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004727 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004728 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004729 }
4730
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004731 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004732 }
4733 }
4734 catch(std::bad_alloc&)
4735 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004736 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004737 }
4738
4739 return -1;
4740}
4741
4742void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
4743{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004744 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004745
4746 try
4747 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004748 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004749
daniel@transgaming.come0078962010-04-15 20:45:08 +00004750 if (context)
4751 {
4752 if (index >= gl::MAX_VERTEX_ATTRIBS)
4753 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004754 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004755 }
4756
daniel@transgaming.com83921382011-01-08 05:46:00 +00004757 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004758
daniel@transgaming.come0078962010-04-15 20:45:08 +00004759 switch (pname)
4760 {
4761 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00004762 *params = (GLfloat)(attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004763 break;
4764 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004765 *params = (GLfloat)attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00004766 break;
4767 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004768 *params = (GLfloat)attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00004769 break;
4770 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004771 *params = (GLfloat)attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00004772 break;
4773 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004774 *params = (GLfloat)(attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004775 break;
4776 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00004777 *params = (GLfloat)attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00004778 break;
4779 case GL_CURRENT_VERTEX_ATTRIB:
4780 for (int i = 0; i < 4; ++i)
4781 {
shannon.woods%transgaming.com@gtempaccount.com3026dc72013-04-13 03:37:27 +00004782 params[i] = attribState.mCurrentValue.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00004783 }
4784 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00004785 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
4786 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
4787 // the same constant.
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004788 *params = (GLfloat)attribState.mDivisor;
4789 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004790 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004791 }
4792 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004793 }
4794 catch(std::bad_alloc&)
4795 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004796 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004797 }
4798}
4799
4800void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
4801{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004802 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004803
4804 try
4805 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004806 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004807
daniel@transgaming.come0078962010-04-15 20:45:08 +00004808 if (context)
4809 {
4810 if (index >= gl::MAX_VERTEX_ATTRIBS)
4811 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004812 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004813 }
4814
daniel@transgaming.com83921382011-01-08 05:46:00 +00004815 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004816
daniel@transgaming.come0078962010-04-15 20:45:08 +00004817 switch (pname)
4818 {
4819 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00004820 *params = (attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004821 break;
4822 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004823 *params = attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00004824 break;
4825 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004826 *params = attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00004827 break;
4828 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004829 *params = attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00004830 break;
4831 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004832 *params = (attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004833 break;
4834 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00004835 *params = attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00004836 break;
4837 case GL_CURRENT_VERTEX_ATTRIB:
4838 for (int i = 0; i < 4; ++i)
4839 {
shannon.woods%transgaming.com@gtempaccount.com3026dc72013-04-13 03:37:27 +00004840 float currentValue = attribState.mCurrentValue.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00004841 params[i] = (GLint)(currentValue > 0.0f ? floor(currentValue + 0.5f) : ceil(currentValue - 0.5f));
4842 }
4843 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00004844 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
4845 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
4846 // the same constant.
4847 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004848 *params = (GLint)attribState.mDivisor;
4849 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004850 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004851 }
4852 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004853 }
4854 catch(std::bad_alloc&)
4855 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004856 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004857 }
4858}
4859
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004860void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004861{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004862 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004863
4864 try
4865 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004866 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004867
daniel@transgaming.come0078962010-04-15 20:45:08 +00004868 if (context)
4869 {
4870 if (index >= gl::MAX_VERTEX_ATTRIBS)
4871 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004872 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004873 }
4874
4875 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
4876 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004877 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004878 }
4879
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004880 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00004881 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004882 }
4883 catch(std::bad_alloc&)
4884 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004885 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004886 }
4887}
4888
4889void __stdcall glHint(GLenum target, GLenum mode)
4890{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004891 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004892
4893 try
4894 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00004895 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00004896 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00004897 case GL_FASTEST:
4898 case GL_NICEST:
4899 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00004900 break;
4901 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004902 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00004903 }
4904
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004905 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00004906 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00004907 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00004908 case GL_GENERATE_MIPMAP_HINT:
4909 if (context) context->setGenerateMipmapHint(mode);
4910 break;
4911 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
4912 if (context) context->setFragmentShaderDerivativeHint(mode);
4913 break;
4914 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004915 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00004916 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004917 }
4918 catch(std::bad_alloc&)
4919 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004920 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004921 }
4922}
4923
4924GLboolean __stdcall glIsBuffer(GLuint buffer)
4925{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004926 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004927
4928 try
4929 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004930 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004931
4932 if (context && buffer)
4933 {
4934 gl::Buffer *bufferObject = context->getBuffer(buffer);
4935
4936 if (bufferObject)
4937 {
4938 return GL_TRUE;
4939 }
4940 }
4941 }
4942 catch(std::bad_alloc&)
4943 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004944 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004945 }
4946
4947 return GL_FALSE;
4948}
4949
4950GLboolean __stdcall glIsEnabled(GLenum cap)
4951{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004952 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004953
4954 try
4955 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004956 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004957
4958 if (context)
4959 {
4960 switch (cap)
4961 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004962 case GL_CULL_FACE: return context->isCullFaceEnabled();
4963 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
4964 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
4965 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
4966 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
4967 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
4968 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
4969 case GL_BLEND: return context->isBlendEnabled();
4970 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004971 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004972 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004973 }
4974 }
4975 }
4976 catch(std::bad_alloc&)
4977 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004978 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004979 }
4980
4981 return false;
4982}
4983
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004984GLboolean __stdcall glIsFenceNV(GLuint fence)
4985{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004986 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004987
4988 try
4989 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004990 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004991
4992 if (context)
4993 {
4994 gl::Fence *fenceObject = context->getFence(fence);
4995
4996 if (fenceObject == NULL)
4997 {
4998 return GL_FALSE;
4999 }
5000
5001 return fenceObject->isFence();
5002 }
5003 }
5004 catch(std::bad_alloc&)
5005 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005006 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005007 }
5008
5009 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005010}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005011
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005012GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
5013{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005014 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005015
5016 try
5017 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005018 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005019
5020 if (context && framebuffer)
5021 {
5022 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
5023
5024 if (framebufferObject)
5025 {
5026 return GL_TRUE;
5027 }
5028 }
5029 }
5030 catch(std::bad_alloc&)
5031 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005032 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005033 }
5034
5035 return GL_FALSE;
5036}
5037
5038GLboolean __stdcall glIsProgram(GLuint program)
5039{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005040 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005041
5042 try
5043 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005044 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005045
5046 if (context && program)
5047 {
5048 gl::Program *programObject = context->getProgram(program);
5049
5050 if (programObject)
5051 {
5052 return GL_TRUE;
5053 }
5054 }
5055 }
5056 catch(std::bad_alloc&)
5057 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005058 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005059 }
5060
5061 return GL_FALSE;
5062}
5063
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005064GLboolean __stdcall glIsQueryEXT(GLuint id)
5065{
5066 EVENT("(GLuint id = %d)", id);
5067
5068 try
5069 {
5070 if (id == 0)
5071 {
5072 return GL_FALSE;
5073 }
5074
5075 gl::Context *context = gl::getNonLostContext();
5076
5077 if (context)
5078 {
5079 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5080
5081 if (queryObject)
5082 {
5083 return GL_TRUE;
5084 }
5085 }
5086 }
5087 catch(std::bad_alloc&)
5088 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005089 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005090 }
5091
5092 return GL_FALSE;
5093}
5094
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005095GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
5096{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005097 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005098
5099 try
5100 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005101 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005102
5103 if (context && renderbuffer)
5104 {
5105 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
5106
5107 if (renderbufferObject)
5108 {
5109 return GL_TRUE;
5110 }
5111 }
5112 }
5113 catch(std::bad_alloc&)
5114 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005115 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005116 }
5117
5118 return GL_FALSE;
5119}
5120
5121GLboolean __stdcall glIsShader(GLuint shader)
5122{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005123 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005124
5125 try
5126 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005127 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005128
5129 if (context && shader)
5130 {
5131 gl::Shader *shaderObject = context->getShader(shader);
5132
5133 if (shaderObject)
5134 {
5135 return GL_TRUE;
5136 }
5137 }
5138 }
5139 catch(std::bad_alloc&)
5140 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005141 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005142 }
5143
5144 return GL_FALSE;
5145}
5146
5147GLboolean __stdcall glIsTexture(GLuint texture)
5148{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005149 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005150
5151 try
5152 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005153 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005154
5155 if (context && texture)
5156 {
5157 gl::Texture *textureObject = context->getTexture(texture);
5158
5159 if (textureObject)
5160 {
5161 return GL_TRUE;
5162 }
5163 }
5164 }
5165 catch(std::bad_alloc&)
5166 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005167 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005168 }
5169
5170 return GL_FALSE;
5171}
5172
5173void __stdcall glLineWidth(GLfloat width)
5174{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005175 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005176
5177 try
5178 {
5179 if (width <= 0.0f)
5180 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005181 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005182 }
5183
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005184 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00005185
5186 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005187 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005188 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005189 }
5190 }
5191 catch(std::bad_alloc&)
5192 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005193 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005194 }
5195}
5196
5197void __stdcall glLinkProgram(GLuint program)
5198{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005199 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005200
5201 try
5202 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005203 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005204
5205 if (context)
5206 {
5207 gl::Program *programObject = context->getProgram(program);
5208
5209 if (!programObject)
5210 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00005211 if (context->getShader(program))
5212 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005213 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00005214 }
5215 else
5216 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005217 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00005218 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005219 }
5220
daniel@transgaming.com95d29422012-07-24 18:36:10 +00005221 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005222 }
5223 }
5224 catch(std::bad_alloc&)
5225 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005226 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005227 }
5228}
5229
5230void __stdcall glPixelStorei(GLenum pname, GLint param)
5231{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005232 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005233
5234 try
5235 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005236 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005237
5238 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005239 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005240 switch (pname)
5241 {
5242 case GL_UNPACK_ALIGNMENT:
5243 if (param != 1 && param != 2 && param != 4 && param != 8)
5244 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005245 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005246 }
5247
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005248 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005249 break;
5250
5251 case GL_PACK_ALIGNMENT:
5252 if (param != 1 && param != 2 && param != 4 && param != 8)
5253 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005254 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005255 }
5256
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005257 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005258 break;
5259
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00005260 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
5261 context->setPackReverseRowOrder(param != 0);
5262 break;
5263
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005264 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005265 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005266 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005267 }
5268 }
5269 catch(std::bad_alloc&)
5270 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005271 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005272 }
5273}
5274
5275void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
5276{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005277 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005278
5279 try
5280 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005281 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00005282
5283 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005284 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005285 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005286 }
5287 }
5288 catch(std::bad_alloc&)
5289 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005290 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005291 }
5292}
5293
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00005294void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
5295 GLenum format, GLenum type, GLsizei bufSize,
5296 GLvoid *data)
5297{
5298 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
5299 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
5300 x, y, width, height, format, type, bufSize, data);
5301
5302 try
5303 {
5304 if (width < 0 || height < 0 || bufSize < 0)
5305 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005306 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00005307 }
5308
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00005309 gl::Context *context = gl::getNonLostContext();
5310
5311 if (context)
5312 {
daniel@transgaming.com42944b02012-09-27 17:45:57 +00005313 GLenum currentFormat, currentType;
5314
5315 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
5316 // and attempting to read back if that's the case is an error. The error will be registered
5317 // by getCurrentReadFormat.
5318 if (!context->getCurrentReadFormatType(&currentFormat, &currentType))
5319 return;
5320
5321 if (!(currentFormat == format && currentType == type) && !validReadFormatType(format, type))
5322 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005323 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00005324 }
5325
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00005326 context->readPixels(x, y, width, height, format, type, &bufSize, data);
5327 }
5328 }
5329 catch(std::bad_alloc&)
5330 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005331 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00005332 }
5333}
5334
5335void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
5336 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005337{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005338 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005339 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00005340 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005341
5342 try
5343 {
5344 if (width < 0 || height < 0)
5345 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005346 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005347 }
5348
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005349 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005350
5351 if (context)
5352 {
daniel@transgaming.com42944b02012-09-27 17:45:57 +00005353 GLenum currentFormat, currentType;
5354
5355 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
5356 // and attempting to read back if that's the case is an error. The error will be registered
5357 // by getCurrentReadFormat.
5358 if (!context->getCurrentReadFormatType(&currentFormat, &currentType))
5359 return;
5360
5361 if (!(currentFormat == format && currentType == type) && !validReadFormatType(format, type))
5362 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005363 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00005364 }
5365
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00005366 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005367 }
5368 }
5369 catch(std::bad_alloc&)
5370 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005371 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005372 }
5373}
5374
5375void __stdcall glReleaseShaderCompiler(void)
5376{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005377 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005378
5379 try
5380 {
5381 gl::Shader::releaseCompiler();
5382 }
5383 catch(std::bad_alloc&)
5384 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005385 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005386 }
5387}
5388
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005389void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005390{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005391 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 +00005392 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005393
5394 try
5395 {
5396 switch (target)
5397 {
5398 case GL_RENDERBUFFER:
5399 break;
5400 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005401 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005402 }
5403
daniel@transgaming.comedc19182010-10-15 17:57:55 +00005404 if (!gl::IsColorRenderable(internalformat) && !gl::IsDepthRenderable(internalformat) && !gl::IsStencilRenderable(internalformat))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005405 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005406 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005407 }
5408
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005409 if (width < 0 || height < 0 || samples < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005410 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005411 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005412 }
5413
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005414 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005415
5416 if (context)
5417 {
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005418 if (width > context->getMaximumRenderbufferDimension() ||
5419 height > context->getMaximumRenderbufferDimension() ||
5420 samples > context->getMaxSupportedSamples())
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005421 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005422 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005423 }
5424
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00005425 GLuint handle = context->getRenderbufferHandle();
5426 if (handle == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005427 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005428 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005429 }
5430
5431 switch (internalformat)
5432 {
5433 case GL_DEPTH_COMPONENT16:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005434 case GL_RGBA4:
5435 case GL_RGB5_A1:
5436 case GL_RGB565:
daniel@transgaming.com63977542010-08-24 19:21:02 +00005437 case GL_RGB8_OES:
5438 case GL_RGBA8_OES:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005439 case GL_STENCIL_INDEX8:
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +00005440 case GL_DEPTH24_STENCIL8_OES:
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00005441 break;
5442 case GL_SRGB8_ALPHA8:
5443 case GL_RGB10_A2:
5444 case GL_RG8:
5445 case GL_R8:
5446 if (context->getClientVersion() < 3)
5447 {
5448 return gl::error(GL_INVALID_ENUM);
5449 }
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +00005450 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005451 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005452 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005453 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00005454
5455 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005456 }
5457 }
5458 catch(std::bad_alloc&)
5459 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005460 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005461 }
5462}
5463
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005464void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
5465{
5466 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
5467}
5468
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005469void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
5470{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005471 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005472
5473 try
5474 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005475 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005476
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005477 if (context)
5478 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00005479 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005480 }
5481 }
5482 catch(std::bad_alloc&)
5483 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005484 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005485 }
5486}
5487
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005488void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
5489{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005490 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005491
5492 try
5493 {
5494 if (condition != GL_ALL_COMPLETED_NV)
5495 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005496 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005497 }
5498
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005499 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005500
5501 if (context)
5502 {
5503 gl::Fence *fenceObject = context->getFence(fence);
5504
5505 if (fenceObject == NULL)
5506 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005507 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005508 }
5509
5510 fenceObject->setFence(condition);
5511 }
5512 }
5513 catch(std::bad_alloc&)
5514 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005515 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005516 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005517}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005518
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005519void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
5520{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005521 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 +00005522
5523 try
5524 {
5525 if (width < 0 || height < 0)
5526 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005527 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005528 }
5529
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005530 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005531
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005532 if (context)
5533 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005534 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005535 }
5536 }
5537 catch(std::bad_alloc&)
5538 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005539 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005540 }
5541}
5542
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005543void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005544{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005545 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005546 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00005547 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005548
5549 try
5550 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00005551 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005552 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005553 }
5554 catch(std::bad_alloc&)
5555 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005556 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005557 }
5558}
5559
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00005560void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005561{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005562 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 +00005563 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005564
5565 try
5566 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00005567 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005568 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005569 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005570 }
5571
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005572 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005573
5574 if (context)
5575 {
5576 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005577
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005578 if (!shaderObject)
5579 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00005580 if (context->getProgram(shader))
5581 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005582 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00005583 }
5584 else
5585 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005586 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00005587 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005588 }
5589
5590 shaderObject->setSource(count, string, length);
5591 }
5592 }
5593 catch(std::bad_alloc&)
5594 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005595 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005596 }
5597}
5598
5599void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
5600{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005601 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005602}
5603
5604void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
5605{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005606 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 +00005607
5608 try
5609 {
5610 switch (face)
5611 {
5612 case GL_FRONT:
5613 case GL_BACK:
5614 case GL_FRONT_AND_BACK:
5615 break;
5616 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005617 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005618 }
5619
5620 switch (func)
5621 {
5622 case GL_NEVER:
5623 case GL_ALWAYS:
5624 case GL_LESS:
5625 case GL_LEQUAL:
5626 case GL_EQUAL:
5627 case GL_GEQUAL:
5628 case GL_GREATER:
5629 case GL_NOTEQUAL:
5630 break;
5631 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005632 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005633 }
5634
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005635 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005636
5637 if (context)
5638 {
5639 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
5640 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005641 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005642 }
5643
5644 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
5645 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005646 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005647 }
5648 }
5649 }
5650 catch(std::bad_alloc&)
5651 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005652 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005653 }
5654}
5655
5656void __stdcall glStencilMask(GLuint mask)
5657{
5658 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5659}
5660
5661void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
5662{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005663 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005664
5665 try
5666 {
5667 switch (face)
5668 {
5669 case GL_FRONT:
5670 case GL_BACK:
5671 case GL_FRONT_AND_BACK:
5672 break;
5673 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005674 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005675 }
5676
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005677 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005678
5679 if (context)
5680 {
5681 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
5682 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005683 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005684 }
5685
5686 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
5687 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005688 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005689 }
5690 }
5691 }
5692 catch(std::bad_alloc&)
5693 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005694 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005695 }
5696}
5697
5698void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5699{
5700 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5701}
5702
5703void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
5704{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005705 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 +00005706 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005707
5708 try
5709 {
5710 switch (face)
5711 {
5712 case GL_FRONT:
5713 case GL_BACK:
5714 case GL_FRONT_AND_BACK:
5715 break;
5716 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005717 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005718 }
5719
5720 switch (fail)
5721 {
5722 case GL_ZERO:
5723 case GL_KEEP:
5724 case GL_REPLACE:
5725 case GL_INCR:
5726 case GL_DECR:
5727 case GL_INVERT:
5728 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005729 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005730 break;
5731 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005732 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005733 }
5734
5735 switch (zfail)
5736 {
5737 case GL_ZERO:
5738 case GL_KEEP:
5739 case GL_REPLACE:
5740 case GL_INCR:
5741 case GL_DECR:
5742 case GL_INVERT:
5743 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005744 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005745 break;
5746 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005747 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005748 }
5749
5750 switch (zpass)
5751 {
5752 case GL_ZERO:
5753 case GL_KEEP:
5754 case GL_REPLACE:
5755 case GL_INCR:
5756 case GL_DECR:
5757 case GL_INVERT:
5758 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005759 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005760 break;
5761 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005762 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005763 }
5764
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005765 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005766
5767 if (context)
5768 {
5769 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
5770 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005771 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005772 }
5773
5774 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
5775 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005776 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005777 }
5778 }
5779 }
5780 catch(std::bad_alloc&)
5781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005782 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005783 }
5784}
5785
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005786GLboolean __stdcall glTestFenceNV(GLuint fence)
5787{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005788 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005789
5790 try
5791 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005792 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005793
5794 if (context)
5795 {
5796 gl::Fence *fenceObject = context->getFence(fence);
5797
5798 if (fenceObject == NULL)
5799 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005800 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005801 }
5802
5803 return fenceObject->testFence();
5804 }
5805 }
5806 catch(std::bad_alloc&)
5807 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005808 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005809 }
5810
5811 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005812}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005813
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005814void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
5815 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005816{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005817 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 +00005818 "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 +00005819 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005820
5821 try
5822 {
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00005823 if (!validImageSize(level, width, height, 1))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005824 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005825 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005826 }
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005827
apatrick@chromium.orge057c5d2012-01-26 19:18:24 +00005828 if (internalformat != GLint(format))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005829 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005830 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005831 }
5832
daniel@transgaming.com6377e362012-06-05 19:49:55 +00005833 // validate <type> by itself (used as secondary key below)
5834 switch (type)
5835 {
5836 case GL_UNSIGNED_BYTE:
5837 case GL_UNSIGNED_SHORT_5_6_5:
5838 case GL_UNSIGNED_SHORT_4_4_4_4:
5839 case GL_UNSIGNED_SHORT_5_5_5_1:
5840 case GL_UNSIGNED_SHORT:
5841 case GL_UNSIGNED_INT:
5842 case GL_UNSIGNED_INT_24_8_OES:
5843 case GL_HALF_FLOAT_OES:
5844 case GL_FLOAT:
5845 break;
5846 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005847 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6377e362012-06-05 19:49:55 +00005848 }
5849
5850 // validate <format> + <type> combinations
5851 // - invalid <format> -> sets INVALID_ENUM
5852 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00005853 switch (format)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005854 {
5855 case GL_ALPHA:
5856 case GL_LUMINANCE:
5857 case GL_LUMINANCE_ALPHA:
5858 switch (type)
5859 {
5860 case GL_UNSIGNED_BYTE:
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00005861 case GL_FLOAT:
5862 case GL_HALF_FLOAT_OES:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005863 break;
5864 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005865 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005866 }
5867 break;
5868 case GL_RGB:
5869 switch (type)
5870 {
5871 case GL_UNSIGNED_BYTE:
5872 case GL_UNSIGNED_SHORT_5_6_5:
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00005873 case GL_FLOAT:
5874 case GL_HALF_FLOAT_OES:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005875 break;
5876 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005877 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005878 }
5879 break;
5880 case GL_RGBA:
5881 switch (type)
5882 {
5883 case GL_UNSIGNED_BYTE:
5884 case GL_UNSIGNED_SHORT_4_4_4_4:
5885 case GL_UNSIGNED_SHORT_5_5_5_1:
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00005886 case GL_FLOAT:
5887 case GL_HALF_FLOAT_OES:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005888 break;
5889 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005890 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005891 }
5892 break;
daniel@transgaming.coma9198d92010-08-08 04:49:56 +00005893 case GL_BGRA_EXT:
5894 switch (type)
5895 {
5896 case GL_UNSIGNED_BYTE:
5897 break;
5898 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005899 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma9198d92010-08-08 04:49:56 +00005900 }
5901 break;
daniel@transgaming.com01868132010-08-24 19:21:17 +00005902 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are handled below
5903 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
gman@chromium.org50c526d2011-08-10 05:19:44 +00005904 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
5905 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
daniel@transgaming.com01868132010-08-24 19:21:17 +00005906 break;
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00005907 case GL_DEPTH_COMPONENT:
5908 switch (type)
5909 {
5910 case GL_UNSIGNED_SHORT:
5911 case GL_UNSIGNED_INT:
5912 break;
5913 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005914 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00005915 }
5916 break;
5917 case GL_DEPTH_STENCIL_OES:
5918 switch (type)
5919 {
5920 case GL_UNSIGNED_INT_24_8_OES:
5921 break;
5922 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005923 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00005924 }
5925 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005926 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005927 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005928 }
5929
5930 if (border != 0)
5931 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005932 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005933 }
5934
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005935 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005936
5937 if (context)
5938 {
daniel@transgaming.com32b11442011-11-19 02:42:48 +00005939 if (level > context->getMaximumTextureLevel())
5940 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005941 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com32b11442011-11-19 02:42:48 +00005942 }
5943
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005944 switch (target)
5945 {
5946 case GL_TEXTURE_2D:
shannon.woods%transgaming.com@gtempaccount.comc1fdf6b2013-04-13 03:44:41 +00005947 if (width > (context->getMaximum2DTextureDimension() >> level) ||
5948 height > (context->getMaximum2DTextureDimension() >> level))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005949 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005950 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005951 }
5952 break;
5953 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
5954 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
5955 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
5956 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
5957 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
5958 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
5959 if (width != height)
5960 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005961 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005962 }
5963
5964 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
5965 height > (context->getMaximumCubeTextureDimension() >> level))
5966 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005967 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005968 }
5969 break;
5970 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005971 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005972 }
5973
gman@chromium.org50c526d2011-08-10 05:19:44 +00005974 switch (format) {
5975 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
5976 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
5977 if (context->supportsDXT1Textures())
daniel@transgaming.com01868132010-08-24 19:21:17 +00005978 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005979 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com01868132010-08-24 19:21:17 +00005980 }
5981 else
5982 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005983 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00005984 }
gman@chromium.org50c526d2011-08-10 05:19:44 +00005985 break;
5986 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
5987 if (context->supportsDXT3Textures())
5988 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005989 return gl::error(GL_INVALID_OPERATION);
gman@chromium.org50c526d2011-08-10 05:19:44 +00005990 }
5991 else
5992 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005993 return gl::error(GL_INVALID_ENUM);
gman@chromium.org50c526d2011-08-10 05:19:44 +00005994 }
5995 break;
5996 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
5997 if (context->supportsDXT5Textures())
5998 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005999 return gl::error(GL_INVALID_OPERATION);
gman@chromium.org50c526d2011-08-10 05:19:44 +00006000 }
6001 else
6002 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006003 return gl::error(GL_INVALID_ENUM);
gman@chromium.org50c526d2011-08-10 05:19:44 +00006004 }
6005 break;
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006006 case GL_DEPTH_COMPONENT:
6007 case GL_DEPTH_STENCIL_OES:
6008 if (!context->supportsDepthTextures())
6009 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006010 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006011 }
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006012 if (target != GL_TEXTURE_2D)
6013 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006014 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006015 }
daniel@transgaming.com797924b2012-06-05 19:50:01 +00006016 // OES_depth_texture supports loading depth data and multiple levels,
6017 // but ANGLE_depth_texture does not
6018 if (pixels != NULL || level != 0)
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006019 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006020 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006021 }
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006022 break;
gman@chromium.org50c526d2011-08-10 05:19:44 +00006023 default:
6024 break;
daniel@transgaming.com01868132010-08-24 19:21:17 +00006025 }
6026
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006027 if (type == GL_FLOAT)
6028 {
daniel@transgaming.combbeffbb2011-11-09 17:46:11 +00006029 if (!context->supportsFloat32Textures())
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006030 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006031 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006032 }
6033 }
6034 else if (type == GL_HALF_FLOAT_OES)
6035 {
daniel@transgaming.combbeffbb2011-11-09 17:46:11 +00006036 if (!context->supportsFloat16Textures())
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006037 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006038 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006039 }
6040 }
6041
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006042 if (target == GL_TEXTURE_2D)
6043 {
6044 gl::Texture2D *texture = context->getTexture2D();
6045
6046 if (!texture)
6047 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006048 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006049 }
6050
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006051 if (texture->isImmutable())
6052 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006053 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006054 }
6055
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006056 texture->setImage(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006057 }
6058 else
6059 {
6060 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6061
6062 if (!texture)
6063 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006064 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006065 }
6066
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006067 if (texture->isImmutable())
6068 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006069 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006070 }
6071
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006072 switch (target)
6073 {
6074 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006075 texture->setImagePosX(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006076 break;
6077 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006078 texture->setImageNegX(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006079 break;
6080 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006081 texture->setImagePosY(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006082 break;
6083 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006084 texture->setImageNegY(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006085 break;
6086 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006087 texture->setImagePosZ(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006088 break;
6089 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006090 texture->setImageNegZ(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006091 break;
6092 default: UNREACHABLE();
6093 }
6094 }
6095 }
6096 }
6097 catch(std::bad_alloc&)
6098 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006099 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006100 }
6101}
6102
6103void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
6104{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006105 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
6106
6107 try
6108 {
6109 gl::Context *context = gl::getNonLostContext();
6110
6111 if (context)
6112 {
6113 gl::Texture *texture;
6114
6115 switch (target)
6116 {
6117 case GL_TEXTURE_2D:
6118 texture = context->getTexture2D();
6119 break;
6120 case GL_TEXTURE_CUBE_MAP:
6121 texture = context->getTextureCubeMap();
6122 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006123 case GL_TEXTURE_3D:
6124 if (context->getClientVersion() < 3)
6125 {
6126 return gl::error(GL_INVALID_ENUM);
6127 }
6128 texture = context->getTexture3D();
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00006129 case GL_TEXTURE_2D_ARRAY:
6130 if (context->getClientVersion() < 3)
6131 {
6132 return gl::error(GL_INVALID_ENUM);
6133 }
6134 texture = context->getTexture2DArray();
6135 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006136 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006137 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006138 }
6139
6140 switch (pname)
6141 {
6142 case GL_TEXTURE_WRAP_S:
6143 if (!texture->setWrapS((GLenum)param))
6144 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006145 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006146 }
6147 break;
6148 case GL_TEXTURE_WRAP_T:
6149 if (!texture->setWrapT((GLenum)param))
6150 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006151 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006152 }
6153 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00006154 case GL_TEXTURE_WRAP_R:
6155 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
6156 {
6157 return gl::error(GL_INVALID_ENUM);
6158 }
6159 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006160 case GL_TEXTURE_MIN_FILTER:
6161 if (!texture->setMinFilter((GLenum)param))
6162 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006163 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006164 }
6165 break;
6166 case GL_TEXTURE_MAG_FILTER:
6167 if (!texture->setMagFilter((GLenum)param))
6168 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006169 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006170 }
6171 break;
6172 case GL_TEXTURE_USAGE_ANGLE:
6173 if (!texture->setUsage((GLenum)param))
6174 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006175 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006176 }
6177 break;
6178 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
6179 if (!context->supportsTextureFilterAnisotropy())
6180 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006181 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006182 }
6183 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
6184 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006185 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006186 }
6187 break;
6188 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006189 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006190 }
6191 }
6192 }
6193 catch(std::bad_alloc&)
6194 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006195 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006196 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006197}
6198
6199void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
6200{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006201 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006202}
6203
6204void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
6205{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006206 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006207
6208 try
6209 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006210 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006211
6212 if (context)
6213 {
6214 gl::Texture *texture;
6215
6216 switch (target)
6217 {
6218 case GL_TEXTURE_2D:
6219 texture = context->getTexture2D();
6220 break;
6221 case GL_TEXTURE_CUBE_MAP:
6222 texture = context->getTextureCubeMap();
6223 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006224 case GL_TEXTURE_3D:
6225 if (context->getClientVersion() < 3)
6226 {
6227 return gl::error(GL_INVALID_ENUM);
6228 }
6229 texture = context->getTexture3D();
6230 break;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00006231 case GL_TEXTURE_2D_ARRAY:
6232 if (context->getClientVersion() < 3)
6233 {
6234 return gl::error(GL_INVALID_ENUM);
6235 }
6236 texture = context->getTexture2DArray();
6237 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006238 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006239 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006240 }
6241
6242 switch (pname)
6243 {
6244 case GL_TEXTURE_WRAP_S:
6245 if (!texture->setWrapS((GLenum)param))
6246 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006247 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006248 }
6249 break;
6250 case GL_TEXTURE_WRAP_T:
6251 if (!texture->setWrapT((GLenum)param))
6252 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006253 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006254 }
6255 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00006256 case GL_TEXTURE_WRAP_R:
6257 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
6258 {
6259 return gl::error(GL_INVALID_ENUM);
6260 }
6261 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006262 case GL_TEXTURE_MIN_FILTER:
6263 if (!texture->setMinFilter((GLenum)param))
6264 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006265 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006266 }
6267 break;
6268 case GL_TEXTURE_MAG_FILTER:
6269 if (!texture->setMagFilter((GLenum)param))
6270 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006271 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006272 }
6273 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00006274 case GL_TEXTURE_USAGE_ANGLE:
6275 if (!texture->setUsage((GLenum)param))
6276 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006277 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00006278 }
6279 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006280 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
6281 if (!context->supportsTextureFilterAnisotropy())
6282 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006283 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006284 }
6285 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
6286 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006287 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006288 }
6289 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006290 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006291 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006292 }
6293 }
6294 }
6295 catch(std::bad_alloc&)
6296 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006297 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006298 }
6299}
6300
6301void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
6302{
6303 glTexParameteri(target, pname, *params);
6304}
6305
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006306void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
6307{
6308 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
6309 target, levels, internalformat, width, height);
6310
6311 try
6312 {
6313 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP)
6314 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006315 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006316 }
6317
6318 if (width < 1 || height < 1 || levels < 1)
6319 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006320 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006321 }
6322
6323 if (target == GL_TEXTURE_CUBE_MAP && width != height)
6324 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006325 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006326 }
6327
daniel@transgaming.com45b888a2011-11-16 03:56:39 +00006328 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006329 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006330 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006331 }
6332
6333 GLenum format = gl::ExtractFormat(internalformat);
6334 GLenum type = gl::ExtractType(internalformat);
6335
6336 if (format == GL_NONE || type == GL_NONE)
6337 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006338 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006339 }
6340
6341 gl::Context *context = gl::getNonLostContext();
6342
6343 if (context)
6344 {
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006345 switch (target)
6346 {
6347 case GL_TEXTURE_2D:
shannon.woods%transgaming.com@gtempaccount.comc1fdf6b2013-04-13 03:44:41 +00006348 if (width > context->getMaximum2DTextureDimension() ||
6349 height > context->getMaximum2DTextureDimension())
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006350 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006351 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006352 }
6353 break;
6354 case GL_TEXTURE_CUBE_MAP:
6355 if (width > context->getMaximumCubeTextureDimension() ||
6356 height > context->getMaximumCubeTextureDimension())
6357 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006358 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006359 }
6360 break;
6361 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006362 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006363 }
6364
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006365 if (levels != 1 && !context->supportsNonPower2Texture())
6366 {
6367 if (!gl::isPow2(width) || !gl::isPow2(height))
6368 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006369 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006370 }
6371 }
6372
daniel@transgaming.come1077362011-11-11 04:16:50 +00006373 switch (internalformat)
6374 {
6375 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
6376 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
6377 if (!context->supportsDXT1Textures())
6378 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006379 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come1077362011-11-11 04:16:50 +00006380 }
6381 break;
6382 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
6383 if (!context->supportsDXT3Textures())
6384 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006385 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come1077362011-11-11 04:16:50 +00006386 }
6387 break;
6388 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
6389 if (!context->supportsDXT5Textures())
6390 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006391 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come1077362011-11-11 04:16:50 +00006392 }
6393 break;
daniel@transgaming.comff941aa2011-11-11 04:17:09 +00006394 case GL_RGBA32F_EXT:
6395 case GL_RGB32F_EXT:
6396 case GL_ALPHA32F_EXT:
6397 case GL_LUMINANCE32F_EXT:
6398 case GL_LUMINANCE_ALPHA32F_EXT:
6399 if (!context->supportsFloat32Textures())
6400 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006401 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comff941aa2011-11-11 04:17:09 +00006402 }
6403 break;
6404 case GL_RGBA16F_EXT:
6405 case GL_RGB16F_EXT:
6406 case GL_ALPHA16F_EXT:
6407 case GL_LUMINANCE16F_EXT:
6408 case GL_LUMINANCE_ALPHA16F_EXT:
6409 if (!context->supportsFloat16Textures())
6410 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006411 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comff941aa2011-11-11 04:17:09 +00006412 }
6413 break;
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006414 case GL_DEPTH_COMPONENT16:
6415 case GL_DEPTH_COMPONENT32_OES:
6416 case GL_DEPTH24_STENCIL8_OES:
6417 if (!context->supportsDepthTextures())
6418 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006419 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006420 }
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006421 if (target != GL_TEXTURE_2D)
6422 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006423 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006424 }
daniel@transgaming.com797924b2012-06-05 19:50:01 +00006425 // ANGLE_depth_texture only supports 1-level textures
6426 if (levels != 1)
6427 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006428 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com797924b2012-06-05 19:50:01 +00006429 }
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006430 break;
6431 default:
6432 break;
daniel@transgaming.come1077362011-11-11 04:16:50 +00006433 }
6434
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006435 if (target == GL_TEXTURE_2D)
6436 {
6437 gl::Texture2D *texture = context->getTexture2D();
6438
6439 if (!texture || texture->id() == 0)
6440 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006441 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006442 }
6443
6444 if (texture->isImmutable())
6445 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006446 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006447 }
6448
6449 texture->storage(levels, internalformat, width, height);
6450 }
6451 else if (target == GL_TEXTURE_CUBE_MAP)
6452 {
6453 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6454
6455 if (!texture || texture->id() == 0)
6456 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006457 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006458 }
6459
6460 if (texture->isImmutable())
6461 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006462 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006463 }
6464
6465 texture->storage(levels, internalformat, width);
6466 }
6467 else UNREACHABLE();
6468 }
6469 }
6470 catch(std::bad_alloc&)
6471 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006472 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006473 }
6474}
6475
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006476void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
6477 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006478{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006479 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006480 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006481 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006482 target, level, xoffset, yoffset, width, height, format, type, pixels);
6483
6484 try
6485 {
apatrick@chromium.org551022e2012-01-23 19:56:54 +00006486 if (!gl::IsInternalTextureTarget(target))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006487 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006488 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006489 }
6490
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006491 if (level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006492 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006493 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006494 }
6495
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006496 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
6497 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006498 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006499 }
6500
daniel@transgaming.com8833dd22012-06-05 19:49:58 +00006501 if (!checkTextureFormatType(format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006502 {
daniel@transgaming.com8833dd22012-06-05 19:49:58 +00006503 return; // error is set by helper function
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006504 }
6505
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006506 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006507
6508 if (context)
6509 {
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006510 if (level > context->getMaximumTextureLevel())
6511 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006512 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006513 }
6514
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006515 if (format == GL_FLOAT)
6516 {
daniel@transgaming.combbeffbb2011-11-09 17:46:11 +00006517 if (!context->supportsFloat32Textures())
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006518 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006519 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006520 }
6521 }
6522 else if (format == GL_HALF_FLOAT_OES)
6523 {
daniel@transgaming.combbeffbb2011-11-09 17:46:11 +00006524 if (!context->supportsFloat16Textures())
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006525 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006526 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006527 }
6528 }
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006529 else if (gl::IsDepthTexture(format))
6530 {
6531 if (!context->supportsDepthTextures())
6532 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006533 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006534 }
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006535 if (target != GL_TEXTURE_2D)
6536 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006537 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006538 }
6539 // OES_depth_texture supports loading depth data, but ANGLE_depth_texture does not
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006540 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006541 }
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006542
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00006543 if (width == 0 || height == 0 || pixels == NULL)
6544 {
6545 return;
6546 }
6547
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006548 if (target == GL_TEXTURE_2D)
6549 {
6550 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00006551 if (validateSubImageParams2D(false, width, height, xoffset, yoffset, level, format, type, texture))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006552 {
daniel@transgaming.com343373a2011-11-29 19:42:32 +00006553 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006554 }
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006555 }
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00006556 else if (gl::IsCubemapTextureTarget(target))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006557 {
6558 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00006559 if (validateSubImageParamsCube(false, width, height, xoffset, yoffset, target, level, format, type, texture))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006560 {
daniel@transgaming.com343373a2011-11-29 19:42:32 +00006561 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006562 }
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006563 }
6564 else
6565 {
6566 UNREACHABLE();
6567 }
6568 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006569 }
6570 catch(std::bad_alloc&)
6571 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006572 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006573 }
6574}
6575
6576void __stdcall glUniform1f(GLint location, GLfloat x)
6577{
6578 glUniform1fv(location, 1, &x);
6579}
6580
6581void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
6582{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006583 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006584
6585 try
6586 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006587 if (count < 0)
6588 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006589 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006590 }
6591
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006592 if (location == -1)
6593 {
6594 return;
6595 }
6596
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006597 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006598
6599 if (context)
6600 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006601 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006602 if (!programBinary)
6603 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006604 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006605 }
6606
6607 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006608 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006609 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006610 }
6611 }
6612 }
6613 catch(std::bad_alloc&)
6614 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006615 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006616 }
6617}
6618
6619void __stdcall glUniform1i(GLint location, GLint x)
6620{
6621 glUniform1iv(location, 1, &x);
6622}
6623
6624void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
6625{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006626 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006627
6628 try
6629 {
6630 if (count < 0)
6631 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006632 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006633 }
6634
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006635 if (location == -1)
6636 {
6637 return;
6638 }
6639
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006640 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006641
6642 if (context)
6643 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006644 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006645 if (!programBinary)
6646 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006647 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006648 }
6649
6650 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006651 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006652 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006653 }
6654 }
6655 }
6656 catch(std::bad_alloc&)
6657 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006658 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006659 }
6660}
6661
6662void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
6663{
6664 GLfloat xy[2] = {x, y};
6665
6666 glUniform2fv(location, 1, (GLfloat*)&xy);
6667}
6668
6669void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
6670{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006671 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006672
6673 try
6674 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006675 if (count < 0)
6676 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006677 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006678 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006679
6680 if (location == -1)
6681 {
6682 return;
6683 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006684
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006685 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006686
6687 if (context)
6688 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006689 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006690 if (!programBinary)
6691 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006692 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006693 }
6694
6695 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006696 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006697 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006698 }
6699 }
6700 }
6701 catch(std::bad_alloc&)
6702 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006703 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006704 }
6705}
6706
6707void __stdcall glUniform2i(GLint location, GLint x, GLint y)
6708{
6709 GLint xy[4] = {x, y};
6710
6711 glUniform2iv(location, 1, (GLint*)&xy);
6712}
6713
6714void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
6715{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006716 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006717
6718 try
6719 {
6720 if (count < 0)
6721 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006722 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006723 }
6724
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006725 if (location == -1)
6726 {
6727 return;
6728 }
6729
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006730 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006731
6732 if (context)
6733 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006734 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006735 if (!programBinary)
6736 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006737 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006738 }
6739
6740 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006741 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006742 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006743 }
6744 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006745 }
6746 catch(std::bad_alloc&)
6747 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006748 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006749 }
6750}
6751
6752void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
6753{
6754 GLfloat xyz[3] = {x, y, z};
6755
6756 glUniform3fv(location, 1, (GLfloat*)&xyz);
6757}
6758
6759void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
6760{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006761 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006762
6763 try
6764 {
6765 if (count < 0)
6766 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006767 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006768 }
6769
6770 if (location == -1)
6771 {
6772 return;
6773 }
6774
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006775 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006776
6777 if (context)
6778 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006779 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006780 if (!programBinary)
6781 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006782 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006783 }
6784
6785 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006786 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006787 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006788 }
6789 }
6790 }
6791 catch(std::bad_alloc&)
6792 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006793 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006794 }
6795}
6796
6797void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
6798{
6799 GLint xyz[3] = {x, y, z};
6800
6801 glUniform3iv(location, 1, (GLint*)&xyz);
6802}
6803
6804void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
6805{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006806 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006807
6808 try
6809 {
6810 if (count < 0)
6811 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006812 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006813 }
6814
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006815 if (location == -1)
6816 {
6817 return;
6818 }
6819
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006820 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006821
6822 if (context)
6823 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006824 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006825 if (!programBinary)
6826 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006827 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006828 }
6829
6830 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006831 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006832 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006833 }
6834 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006835 }
6836 catch(std::bad_alloc&)
6837 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006838 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006839 }
6840}
6841
6842void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6843{
6844 GLfloat xyzw[4] = {x, y, z, w};
6845
6846 glUniform4fv(location, 1, (GLfloat*)&xyzw);
6847}
6848
6849void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
6850{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006851 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006852
6853 try
6854 {
6855 if (count < 0)
6856 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006857 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006858 }
6859
6860 if (location == -1)
6861 {
6862 return;
6863 }
6864
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006865 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006866
6867 if (context)
6868 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006869 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006870 if (!programBinary)
6871 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006872 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006873 }
6874
6875 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006876 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006877 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006878 }
6879 }
6880 }
6881 catch(std::bad_alloc&)
6882 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006883 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006884 }
6885}
6886
6887void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
6888{
6889 GLint xyzw[4] = {x, y, z, w};
6890
6891 glUniform4iv(location, 1, (GLint*)&xyzw);
6892}
6893
6894void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
6895{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006896 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006897
6898 try
6899 {
6900 if (count < 0)
6901 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006902 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006903 }
6904
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006905 if (location == -1)
6906 {
6907 return;
6908 }
6909
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006910 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006911
6912 if (context)
6913 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006914 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006915 if (!programBinary)
6916 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006917 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006918 }
6919
6920 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006921 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006922 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006923 }
6924 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006925 }
6926 catch(std::bad_alloc&)
6927 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006928 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006929 }
6930}
6931
6932void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
6933{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006934 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006935 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006936
6937 try
6938 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00006939 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006940 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006941 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006942 }
6943
6944 if (location == -1)
6945 {
6946 return;
6947 }
6948
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006949 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006950
6951 if (context)
6952 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00006953 if (transpose != GL_FALSE && context->getClientVersion() < 3)
6954 {
6955 return gl::error(GL_INVALID_VALUE);
6956 }
6957
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006958 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006959 if (!programBinary)
6960 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006961 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006962 }
6963
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00006964 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006965 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006966 return gl::error(GL_INVALID_OPERATION);
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 glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
6977{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006978 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006979 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006980
6981 try
6982 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00006983 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006984 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006985 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006986 }
6987
6988 if (location == -1)
6989 {
6990 return;
6991 }
6992
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006993 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006994
6995 if (context)
6996 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00006997 if (transpose != GL_FALSE && context->getClientVersion() < 3)
6998 {
6999 return gl::error(GL_INVALID_VALUE);
7000 }
7001
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007002 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007003 if (!programBinary)
7004 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007005 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007006 }
7007
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007008 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007009 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007010 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007011 }
7012 }
7013 }
7014 catch(std::bad_alloc&)
7015 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007016 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007017 }
7018}
7019
7020void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7021{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007022 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007023 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007024
7025 try
7026 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007027 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007028 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007029 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007030 }
7031
7032 if (location == -1)
7033 {
7034 return;
7035 }
7036
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007037 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007038
7039 if (context)
7040 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007041 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7042 {
7043 return gl::error(GL_INVALID_VALUE);
7044 }
7045
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007046 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007047 if (!programBinary)
7048 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007049 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007050 }
7051
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007052 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007053 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007054 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007055 }
7056 }
7057 }
7058 catch(std::bad_alloc&)
7059 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007060 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007061 }
7062}
7063
7064void __stdcall glUseProgram(GLuint program)
7065{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007066 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007067
7068 try
7069 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007070 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007071
7072 if (context)
7073 {
7074 gl::Program *programObject = context->getProgram(program);
7075
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007076 if (!programObject && program != 0)
7077 {
7078 if (context->getShader(program))
7079 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007080 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007081 }
7082 else
7083 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007084 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007085 }
7086 }
7087
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007088 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007089 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007090 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007091 }
7092
7093 context->useProgram(program);
7094 }
7095 }
7096 catch(std::bad_alloc&)
7097 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007098 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007099 }
7100}
7101
7102void __stdcall glValidateProgram(GLuint program)
7103{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007104 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007105
7106 try
7107 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007108 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007109
7110 if (context)
7111 {
7112 gl::Program *programObject = context->getProgram(program);
7113
7114 if (!programObject)
7115 {
7116 if (context->getShader(program))
7117 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007118 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007119 }
7120 else
7121 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007122 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007123 }
7124 }
7125
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00007126 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007127 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007128 }
7129 catch(std::bad_alloc&)
7130 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007131 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007132 }
7133}
7134
7135void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
7136{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007137 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007138
7139 try
7140 {
7141 if (index >= gl::MAX_VERTEX_ATTRIBS)
7142 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007143 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007144 }
7145
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007146 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007147
7148 if (context)
7149 {
7150 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007151 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007152 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007153 }
7154 catch(std::bad_alloc&)
7155 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007156 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007157 }
7158}
7159
7160void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
7161{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007162 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007163
7164 try
7165 {
7166 if (index >= gl::MAX_VERTEX_ATTRIBS)
7167 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007168 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007169 }
7170
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007171 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007172
7173 if (context)
7174 {
7175 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007176 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007177 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007178 }
7179 catch(std::bad_alloc&)
7180 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007181 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007182 }
7183}
7184
7185void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
7186{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007187 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007188
7189 try
7190 {
7191 if (index >= gl::MAX_VERTEX_ATTRIBS)
7192 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007193 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007194 }
7195
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007196 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007197
7198 if (context)
7199 {
7200 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007201 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007202 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007203 }
7204 catch(std::bad_alloc&)
7205 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007206 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007207 }
7208}
7209
7210void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
7211{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007212 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007213
7214 try
7215 {
7216 if (index >= gl::MAX_VERTEX_ATTRIBS)
7217 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007218 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007219 }
7220
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007221 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007222
7223 if (context)
7224 {
7225 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007226 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007227 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007228 }
7229 catch(std::bad_alloc&)
7230 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007231 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007232 }
7233}
7234
7235void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
7236{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007237 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 +00007238
7239 try
7240 {
7241 if (index >= gl::MAX_VERTEX_ATTRIBS)
7242 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007243 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007244 }
7245
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007246 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007247
7248 if (context)
7249 {
7250 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007251 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007252 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007253 }
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.com4f39fd92010-03-08 20:26:45 +00007257 }
7258}
7259
7260void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
7261{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007262 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007263
7264 try
7265 {
7266 if (index >= gl::MAX_VERTEX_ATTRIBS)
7267 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007268 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007269 }
7270
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007271 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007272
7273 if (context)
7274 {
7275 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007276 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007277 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007278 }
7279 catch(std::bad_alloc&)
7280 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007281 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007282 }
7283}
7284
7285void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7286{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007287 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 +00007288
7289 try
7290 {
7291 if (index >= gl::MAX_VERTEX_ATTRIBS)
7292 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007293 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007294 }
7295
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007296 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007297
7298 if (context)
7299 {
7300 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007301 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007302 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007303 }
7304 catch(std::bad_alloc&)
7305 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007306 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007307 }
7308}
7309
7310void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
7311{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007312 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007313
7314 try
7315 {
7316 if (index >= gl::MAX_VERTEX_ATTRIBS)
7317 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007318 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007319 }
7320
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007321 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007322
7323 if (context)
7324 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007325 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007326 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007327 }
7328 catch(std::bad_alloc&)
7329 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007330 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007331 }
7332}
7333
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007334void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
7335{
7336 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
7337
7338 try
7339 {
7340 if (index >= gl::MAX_VERTEX_ATTRIBS)
7341 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007342 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007343 }
7344
7345 gl::Context *context = gl::getNonLostContext();
7346
7347 if (context)
7348 {
7349 context->setVertexAttribDivisor(index, divisor);
7350 }
7351 }
7352 catch(std::bad_alloc&)
7353 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007354 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007355 }
7356}
7357
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007358void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007359{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007360 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007361 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007362 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007363
7364 try
7365 {
7366 if (index >= gl::MAX_VERTEX_ATTRIBS)
7367 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007368 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007369 }
7370
7371 if (size < 1 || size > 4)
7372 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007373 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007374 }
7375
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007376 gl::Context *context = gl::getNonLostContext();
7377
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007378 switch (type)
7379 {
7380 case GL_BYTE:
7381 case GL_UNSIGNED_BYTE:
7382 case GL_SHORT:
7383 case GL_UNSIGNED_SHORT:
7384 case GL_FIXED:
7385 case GL_FLOAT:
7386 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007387 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007388 case GL_INT:
7389 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00007390 case GL_INT_2_10_10_10_REV:
7391 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007392 if (context && context->getClientVersion() < 3)
7393 {
7394 return gl::error(GL_INVALID_ENUM);
7395 }
7396 else
7397 {
7398 break;
7399 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007400 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007401 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007402 }
7403
7404 if (stride < 0)
7405 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007406 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007407 }
7408
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00007409 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
7410 {
7411 return gl::error(GL_INVALID_OPERATION);
7412 }
7413
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007414 if (context)
7415 {
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00007416 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
7417 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007418 }
7419 }
7420 catch(std::bad_alloc&)
7421 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007422 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007423 }
7424}
7425
7426void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
7427{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007428 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 +00007429
7430 try
7431 {
7432 if (width < 0 || height < 0)
7433 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007434 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007435 }
7436
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007437 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007438
7439 if (context)
7440 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007441 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007442 }
7443 }
7444 catch(std::bad_alloc&)
7445 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007446 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007447 }
7448}
7449
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007450// OpenGL ES 3.0 functions
7451
7452void __stdcall glReadBuffer(GLenum mode)
7453{
7454 EVENT("(GLenum mode = 0x%X)", mode);
7455
7456 try
7457 {
7458 gl::Context *context = gl::getNonLostContext();
7459
7460 if (context)
7461 {
7462 if (context->getClientVersion() < 3)
7463 {
7464 return gl::error(GL_INVALID_OPERATION);
7465 }
7466 }
7467
7468 UNIMPLEMENTED();
7469 }
7470 catch(std::bad_alloc&)
7471 {
7472 return gl::error(GL_OUT_OF_MEMORY);
7473 }
7474}
7475
7476void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
7477{
7478 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
7479 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
7480
7481 try
7482 {
7483 gl::Context *context = gl::getNonLostContext();
7484
7485 if (context)
7486 {
7487 if (context->getClientVersion() < 3)
7488 {
7489 return gl::error(GL_INVALID_OPERATION);
7490 }
7491 }
7492
7493 UNIMPLEMENTED();
7494 }
7495 catch(std::bad_alloc&)
7496 {
7497 return gl::error(GL_OUT_OF_MEMORY);
7498 }
7499}
7500
7501void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
7502{
7503 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
7504 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
7505 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
7506 target, level, internalformat, width, height, depth, border, format, type, pixels);
7507
7508 try
7509 {
7510 gl::Context *context = gl::getNonLostContext();
7511
7512 if (context)
7513 {
7514 if (context->getClientVersion() < 3)
7515 {
7516 return gl::error(GL_INVALID_OPERATION);
7517 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007518
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007519 // validateES3TexImageFormat sets the error code if there is an error
7520 if (!validateES3TexImageFormat(context, target, level, internalformat, false, false,
7521 0, 0, 0, width, height, depth, border, format, type))
7522 {
7523 return;
7524 }
7525
7526 switch(target)
7527 {
7528 case GL_TEXTURE_3D:
7529 {
7530 gl::Texture3D *texture = context->getTexture3D();
7531 texture->setImage(level, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
7532 }
7533 break;
7534
7535 case GL_TEXTURE_2D_ARRAY:
7536 UNIMPLEMENTED();
7537 break;
7538
7539 default:
7540 return gl::error(GL_INVALID_ENUM);
7541 }
7542 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007543 }
7544 catch(std::bad_alloc&)
7545 {
7546 return gl::error(GL_OUT_OF_MEMORY);
7547 }
7548}
7549
7550void __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)
7551{
7552 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
7553 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
7554 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
7555 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
7556
7557 try
7558 {
7559 gl::Context *context = gl::getNonLostContext();
7560
7561 if (context)
7562 {
7563 if (context->getClientVersion() < 3)
7564 {
7565 return gl::error(GL_INVALID_OPERATION);
7566 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007567
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007568 if (!pixels)
7569 {
7570 return gl::error(GL_INVALID_VALUE);
7571 }
7572
7573 // validateES3TexImageFormat sets the error code if there is an error
7574 if (!validateES3TexImageFormat(context, target, level, GL_NONE, false, true,
7575 xoffset, yoffset, zoffset, width, height, depth, 0,
7576 format, type))
7577 {
7578 return;
7579 }
7580
7581 switch(target)
7582 {
7583 case GL_TEXTURE_3D:
7584 {
7585 gl::Texture3D *texture = context->getTexture3D();
7586 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
7587 }
7588 break;
7589
7590 case GL_TEXTURE_2D_ARRAY:
7591 UNIMPLEMENTED();
7592 break;
7593
7594 default:
7595 return gl::error(GL_INVALID_ENUM);
7596 }
7597 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007598 }
7599 catch(std::bad_alloc&)
7600 {
7601 return gl::error(GL_OUT_OF_MEMORY);
7602 }
7603}
7604
7605void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
7606{
7607 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
7608 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
7609 target, level, xoffset, yoffset, zoffset, x, y, width, height);
7610
7611 try
7612 {
7613 gl::Context *context = gl::getNonLostContext();
7614
7615 if (context)
7616 {
7617 if (context->getClientVersion() < 3)
7618 {
7619 return gl::error(GL_INVALID_OPERATION);
7620 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007621
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007622 if (!validateCopyTexImageParameters(context, target, false, level, xoffset, yoffset, zoffset,
7623 x, y, width, height))
7624 {
7625 return;
7626 }
7627
7628 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
7629 gl::Texture *texture = NULL;
7630 switch (target)
7631 {
7632 case GL_TEXTURE_3D:
7633 texture = context->getTexture3D();
7634 break;
7635
7636 case GL_TEXTURE_2D_ARRAY:
7637 UNIMPLEMENTED();
7638 break;
7639
7640 default:
7641 return gl::error(GL_INVALID_ENUM);
7642 }
7643
7644 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
7645 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007646 }
7647 catch(std::bad_alloc&)
7648 {
7649 return gl::error(GL_OUT_OF_MEMORY);
7650 }
7651}
7652
7653void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
7654{
7655 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
7656 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
7657 "const GLvoid* data = 0x%0.8p)",
7658 target, level, internalformat, width, height, depth, border, imageSize, data);
7659
7660 try
7661 {
7662 gl::Context *context = gl::getNonLostContext();
7663
7664 if (context)
7665 {
7666 if (context->getClientVersion() < 3)
7667 {
7668 return gl::error(GL_INVALID_OPERATION);
7669 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007670
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007671 if (imageSize < 0 || imageSize != gl::ComputeCompressedSize(width, height, internalformat))
7672 {
7673 return gl::error(GL_INVALID_VALUE);
7674 }
7675
7676 // validateES3TexImageFormat sets the error code if there is an error
7677 if (!validateES3TexImageFormat(context, target, level, internalformat, true, false,
7678 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
7679 {
7680 return;
7681 }
7682
7683 switch(target)
7684 {
7685 case GL_TEXTURE_3D:
7686 {
7687 gl::Texture3D *texture = context->getTexture3D();
7688 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
7689 }
7690 break;
7691
7692 case GL_TEXTURE_2D_ARRAY:
7693 UNIMPLEMENTED();
7694 break;
7695
7696 default:
7697 return gl::error(GL_INVALID_ENUM);
7698 }
7699 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007700 }
7701 catch(std::bad_alloc&)
7702 {
7703 return gl::error(GL_OUT_OF_MEMORY);
7704 }
7705}
7706
7707void __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)
7708{
7709 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
7710 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
7711 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
7712 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
7713
7714 try
7715 {
7716 gl::Context *context = gl::getNonLostContext();
7717
7718 if (context)
7719 {
7720 if (context->getClientVersion() < 3)
7721 {
7722 return gl::error(GL_INVALID_OPERATION);
7723 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007724
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007725 if (imageSize < 0 || imageSize != gl::ComputeCompressedSize(width, height, format))
7726 {
7727 return gl::error(GL_INVALID_VALUE);
7728 }
7729
7730 if (!data)
7731 {
7732 return gl::error(GL_INVALID_VALUE);
7733 }
7734
7735 // validateES3TexImageFormat sets the error code if there is an error
7736 if (!validateES3TexImageFormat(context, target, level, GL_NONE, true, true,
7737 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
7738 {
7739 return;
7740 }
7741
7742 switch(target)
7743 {
7744 case GL_TEXTURE_3D:
7745 {
7746 gl::Texture3D *texture = context->getTexture3D();
7747 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
7748 format, imageSize, data);
7749 }
7750 break;
7751
7752 case GL_TEXTURE_2D_ARRAY:
7753 UNIMPLEMENTED();
7754 break;
7755
7756 default:
7757 return gl::error(GL_INVALID_ENUM);
7758 }
7759 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007760 }
7761 catch(std::bad_alloc&)
7762 {
7763 return gl::error(GL_OUT_OF_MEMORY);
7764 }
7765}
7766
7767void __stdcall glGenQueries(GLsizei n, GLuint* ids)
7768{
7769 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7770
7771 try
7772 {
7773 gl::Context *context = gl::getNonLostContext();
7774
7775 if (context)
7776 {
7777 if (context->getClientVersion() < 3)
7778 {
7779 return gl::error(GL_INVALID_OPERATION);
7780 }
7781 }
7782
7783 UNIMPLEMENTED();
7784 }
7785 catch(std::bad_alloc&)
7786 {
7787 return gl::error(GL_OUT_OF_MEMORY);
7788 }
7789}
7790
7791void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
7792{
7793 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7794
7795 try
7796 {
7797 gl::Context *context = gl::getNonLostContext();
7798
7799 if (context)
7800 {
7801 if (context->getClientVersion() < 3)
7802 {
7803 return gl::error(GL_INVALID_OPERATION);
7804 }
7805 }
7806
7807 UNIMPLEMENTED();
7808 }
7809 catch(std::bad_alloc&)
7810 {
7811 return gl::error(GL_OUT_OF_MEMORY);
7812 }
7813}
7814
7815GLboolean __stdcall glIsQuery(GLuint id)
7816{
7817 EVENT("(GLuint id = %u)", id);
7818
7819 try
7820 {
7821 gl::Context *context = gl::getNonLostContext();
7822
7823 if (context)
7824 {
7825 if (context->getClientVersion() < 3)
7826 {
7827 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
7828 }
7829 }
7830
7831 UNIMPLEMENTED();
7832 }
7833 catch(std::bad_alloc&)
7834 {
7835 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
7836 }
7837
7838 return GL_FALSE;
7839}
7840
7841void __stdcall glBeginQuery(GLenum target, GLuint id)
7842{
7843 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
7844
7845 try
7846 {
7847 gl::Context *context = gl::getNonLostContext();
7848
7849 if (context)
7850 {
7851 if (context->getClientVersion() < 3)
7852 {
7853 return gl::error(GL_INVALID_OPERATION);
7854 }
7855 }
7856
7857 UNIMPLEMENTED();
7858 }
7859 catch(std::bad_alloc&)
7860 {
7861 return gl::error(GL_OUT_OF_MEMORY);
7862 }
7863}
7864
7865void __stdcall glEndQuery(GLenum target)
7866{
7867 EVENT("(GLenum target = 0x%X)", target);
7868
7869 try
7870 {
7871 gl::Context *context = gl::getNonLostContext();
7872
7873 if (context)
7874 {
7875 if (context->getClientVersion() < 3)
7876 {
7877 return gl::error(GL_INVALID_OPERATION);
7878 }
7879 }
7880
7881 UNIMPLEMENTED();
7882 }
7883 catch(std::bad_alloc&)
7884 {
7885 return gl::error(GL_OUT_OF_MEMORY);
7886 }
7887}
7888
7889void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
7890{
7891 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
7892
7893 try
7894 {
7895 gl::Context *context = gl::getNonLostContext();
7896
7897 if (context)
7898 {
7899 if (context->getClientVersion() < 3)
7900 {
7901 return gl::error(GL_INVALID_OPERATION);
7902 }
7903 }
7904
7905 UNIMPLEMENTED();
7906 }
7907 catch(std::bad_alloc&)
7908 {
7909 return gl::error(GL_OUT_OF_MEMORY);
7910 }
7911}
7912
7913void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
7914{
7915 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
7916
7917 try
7918 {
7919 gl::Context *context = gl::getNonLostContext();
7920
7921 if (context)
7922 {
7923 if (context->getClientVersion() < 3)
7924 {
7925 return gl::error(GL_INVALID_OPERATION);
7926 }
7927 }
7928
7929 UNIMPLEMENTED();
7930 }
7931 catch(std::bad_alloc&)
7932 {
7933 return gl::error(GL_OUT_OF_MEMORY);
7934 }
7935}
7936
7937GLboolean __stdcall glUnmapBuffer(GLenum target)
7938{
7939 EVENT("(GLenum target = 0x%X)", target);
7940
7941 try
7942 {
7943 gl::Context *context = gl::getNonLostContext();
7944
7945 if (context)
7946 {
7947 if (context->getClientVersion() < 3)
7948 {
7949 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
7950 }
7951 }
7952
7953 UNIMPLEMENTED();
7954 }
7955 catch(std::bad_alloc&)
7956 {
7957 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
7958 }
7959
7960 return GL_FALSE;
7961}
7962
7963void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
7964{
7965 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
7966
7967 try
7968 {
7969 gl::Context *context = gl::getNonLostContext();
7970
7971 if (context)
7972 {
7973 if (context->getClientVersion() < 3)
7974 {
7975 return gl::error(GL_INVALID_OPERATION);
7976 }
7977 }
7978
7979 UNIMPLEMENTED();
7980 }
7981 catch(std::bad_alloc&)
7982 {
7983 return gl::error(GL_OUT_OF_MEMORY);
7984 }
7985}
7986
7987void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
7988{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007989 try
7990 {
7991 gl::Context *context = gl::getNonLostContext();
7992
7993 if (context)
7994 {
7995 if (context->getClientVersion() < 3)
7996 {
7997 return gl::error(GL_INVALID_OPERATION);
7998 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007999
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00008000 glDrawBuffersEXT(n, bufs);
8001 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008002 }
8003 catch(std::bad_alloc&)
8004 {
8005 return gl::error(GL_OUT_OF_MEMORY);
8006 }
8007}
8008
8009void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8010{
8011 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8012 location, count, transpose, value);
8013
8014 try
8015 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008016 if (count < 0)
8017 {
8018 return gl::error(GL_INVALID_VALUE);
8019 }
8020
8021 if (location == -1)
8022 {
8023 return;
8024 }
8025
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008026 gl::Context *context = gl::getNonLostContext();
8027
8028 if (context)
8029 {
8030 if (context->getClientVersion() < 3)
8031 {
8032 return gl::error(GL_INVALID_OPERATION);
8033 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008034
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008035 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8036 if (!programBinary)
8037 {
8038 return gl::error(GL_INVALID_OPERATION);
8039 }
8040
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008041 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008042 {
8043 return gl::error(GL_INVALID_OPERATION);
8044 }
8045 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008046 }
8047 catch(std::bad_alloc&)
8048 {
8049 return gl::error(GL_OUT_OF_MEMORY);
8050 }
8051}
8052
8053void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8054{
8055 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8056 location, count, transpose, value);
8057
8058 try
8059 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008060 if (count < 0)
8061 {
8062 return gl::error(GL_INVALID_VALUE);
8063 }
8064
8065 if (location == -1)
8066 {
8067 return;
8068 }
8069
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008070 gl::Context *context = gl::getNonLostContext();
8071
8072 if (context)
8073 {
8074 if (context->getClientVersion() < 3)
8075 {
8076 return gl::error(GL_INVALID_OPERATION);
8077 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008078
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008079 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8080 if (!programBinary)
8081 {
8082 return gl::error(GL_INVALID_OPERATION);
8083 }
8084
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008085 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008086 {
8087 return gl::error(GL_INVALID_OPERATION);
8088 }
8089 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008090 }
8091 catch(std::bad_alloc&)
8092 {
8093 return gl::error(GL_OUT_OF_MEMORY);
8094 }
8095}
8096
8097void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8098{
8099 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8100 location, count, transpose, value);
8101
8102 try
8103 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008104 if (count < 0)
8105 {
8106 return gl::error(GL_INVALID_VALUE);
8107 }
8108
8109 if (location == -1)
8110 {
8111 return;
8112 }
8113
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008114 gl::Context *context = gl::getNonLostContext();
8115
8116 if (context)
8117 {
8118 if (context->getClientVersion() < 3)
8119 {
8120 return gl::error(GL_INVALID_OPERATION);
8121 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008122
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008123 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8124 if (!programBinary)
8125 {
8126 return gl::error(GL_INVALID_OPERATION);
8127 }
8128
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008129 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008130 {
8131 return gl::error(GL_INVALID_OPERATION);
8132 }
8133 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008134 }
8135 catch(std::bad_alloc&)
8136 {
8137 return gl::error(GL_OUT_OF_MEMORY);
8138 }
8139}
8140
8141void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8142{
8143 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8144 location, count, transpose, value);
8145
8146 try
8147 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008148 if (count < 0)
8149 {
8150 return gl::error(GL_INVALID_VALUE);
8151 }
8152
8153 if (location == -1)
8154 {
8155 return;
8156 }
8157
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008158 gl::Context *context = gl::getNonLostContext();
8159
8160 if (context)
8161 {
8162 if (context->getClientVersion() < 3)
8163 {
8164 return gl::error(GL_INVALID_OPERATION);
8165 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008166
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008167 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8168 if (!programBinary)
8169 {
8170 return gl::error(GL_INVALID_OPERATION);
8171 }
8172
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008173 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008174 {
8175 return gl::error(GL_INVALID_OPERATION);
8176 }
8177 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008178 }
8179 catch(std::bad_alloc&)
8180 {
8181 return gl::error(GL_OUT_OF_MEMORY);
8182 }
8183}
8184
8185void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8186{
8187 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8188 location, count, transpose, value);
8189
8190 try
8191 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008192 if (count < 0)
8193 {
8194 return gl::error(GL_INVALID_VALUE);
8195 }
8196
8197 if (location == -1)
8198 {
8199 return;
8200 }
8201
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008202 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
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008211 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8212 if (!programBinary)
8213 {
8214 return gl::error(GL_INVALID_OPERATION);
8215 }
8216
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008217 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008218 {
8219 return gl::error(GL_INVALID_OPERATION);
8220 }
8221 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008222 }
8223 catch(std::bad_alloc&)
8224 {
8225 return gl::error(GL_OUT_OF_MEMORY);
8226 }
8227}
8228
8229void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8230{
8231 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8232 location, count, transpose, value);
8233
8234 try
8235 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008236 if (count < 0)
8237 {
8238 return gl::error(GL_INVALID_VALUE);
8239 }
8240
8241 if (location == -1)
8242 {
8243 return;
8244 }
8245
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008246 gl::Context *context = gl::getNonLostContext();
8247
8248 if (context)
8249 {
8250 if (context->getClientVersion() < 3)
8251 {
8252 return gl::error(GL_INVALID_OPERATION);
8253 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008254
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008255 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8256 if (!programBinary)
8257 {
8258 return gl::error(GL_INVALID_OPERATION);
8259 }
8260
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008261 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008262 {
8263 return gl::error(GL_INVALID_OPERATION);
8264 }
8265 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008266 }
8267 catch(std::bad_alloc&)
8268 {
8269 return gl::error(GL_OUT_OF_MEMORY);
8270 }
8271}
8272
8273void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
8274{
8275 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
8276 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
8277 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
8278
8279 try
8280 {
8281 gl::Context *context = gl::getNonLostContext();
8282
8283 if (context)
8284 {
8285 if (context->getClientVersion() < 3)
8286 {
8287 return gl::error(GL_INVALID_OPERATION);
8288 }
8289 }
8290
8291 UNIMPLEMENTED();
8292 }
8293 catch(std::bad_alloc&)
8294 {
8295 return gl::error(GL_OUT_OF_MEMORY);
8296 }
8297}
8298
8299void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
8300{
8301 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
8302 target, samples, internalformat, width, height);
8303
8304 try
8305 {
8306 gl::Context *context = gl::getNonLostContext();
8307
8308 if (context)
8309 {
8310 if (context->getClientVersion() < 3)
8311 {
8312 return gl::error(GL_INVALID_OPERATION);
8313 }
8314 }
8315
8316 UNIMPLEMENTED();
8317 }
8318 catch(std::bad_alloc&)
8319 {
8320 return gl::error(GL_OUT_OF_MEMORY);
8321 }
8322}
8323
8324void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
8325{
8326 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
8327 target, attachment, texture, level, layer);
8328
8329 try
8330 {
8331 gl::Context *context = gl::getNonLostContext();
8332
8333 if (context)
8334 {
8335 if (context->getClientVersion() < 3)
8336 {
8337 return gl::error(GL_INVALID_OPERATION);
8338 }
8339 }
8340
8341 UNIMPLEMENTED();
8342 }
8343 catch(std::bad_alloc&)
8344 {
8345 return gl::error(GL_OUT_OF_MEMORY);
8346 }
8347}
8348
8349GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8350{
8351 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8352 target, offset, length, access);
8353
8354 try
8355 {
8356 gl::Context *context = gl::getNonLostContext();
8357
8358 if (context)
8359 {
8360 if (context->getClientVersion() < 3)
8361 {
8362 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8363 }
8364 }
8365
8366 UNIMPLEMENTED();
8367 }
8368 catch(std::bad_alloc&)
8369 {
8370 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
8371 }
8372
8373 return NULL;
8374}
8375
8376void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
8377{
8378 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8379
8380 try
8381 {
8382 gl::Context *context = gl::getNonLostContext();
8383
8384 if (context)
8385 {
8386 if (context->getClientVersion() < 3)
8387 {
8388 return gl::error(GL_INVALID_OPERATION);
8389 }
8390 }
8391
8392 UNIMPLEMENTED();
8393 }
8394 catch(std::bad_alloc&)
8395 {
8396 return gl::error(GL_OUT_OF_MEMORY);
8397 }
8398}
8399
8400void __stdcall glBindVertexArray(GLuint array)
8401{
8402 EVENT("(GLuint array = %u)", array);
8403
8404 try
8405 {
8406 gl::Context *context = gl::getNonLostContext();
8407
8408 if (context)
8409 {
8410 if (context->getClientVersion() < 3)
8411 {
8412 return gl::error(GL_INVALID_OPERATION);
8413 }
8414 }
8415
8416 UNIMPLEMENTED();
8417 }
8418 catch(std::bad_alloc&)
8419 {
8420 return gl::error(GL_OUT_OF_MEMORY);
8421 }
8422}
8423
8424void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
8425{
8426 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
8427
8428 try
8429 {
8430 gl::Context *context = gl::getNonLostContext();
8431
8432 if (context)
8433 {
8434 if (context->getClientVersion() < 3)
8435 {
8436 return gl::error(GL_INVALID_OPERATION);
8437 }
8438 }
8439
8440 UNIMPLEMENTED();
8441 }
8442 catch(std::bad_alloc&)
8443 {
8444 return gl::error(GL_OUT_OF_MEMORY);
8445 }
8446}
8447
8448void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
8449{
8450 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
8451
8452 try
8453 {
8454 gl::Context *context = gl::getNonLostContext();
8455
8456 if (context)
8457 {
8458 if (context->getClientVersion() < 3)
8459 {
8460 return gl::error(GL_INVALID_OPERATION);
8461 }
8462 }
8463
8464 UNIMPLEMENTED();
8465 }
8466 catch(std::bad_alloc&)
8467 {
8468 return gl::error(GL_OUT_OF_MEMORY);
8469 }
8470}
8471
8472GLboolean __stdcall glIsVertexArray(GLuint array)
8473{
8474 EVENT("(GLuint array = %u)", array);
8475
8476 try
8477 {
8478 gl::Context *context = gl::getNonLostContext();
8479
8480 if (context)
8481 {
8482 if (context->getClientVersion() < 3)
8483 {
8484 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8485 }
8486 }
8487
8488 UNIMPLEMENTED();
8489 }
8490 catch(std::bad_alloc&)
8491 {
8492 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8493 }
8494
8495 return GL_FALSE;
8496}
8497
8498void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
8499{
8500 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
8501 target, index, data);
8502
8503 try
8504 {
8505 gl::Context *context = gl::getNonLostContext();
8506
8507 if (context)
8508 {
8509 if (context->getClientVersion() < 3)
8510 {
8511 return gl::error(GL_INVALID_OPERATION);
8512 }
8513 }
8514
8515 UNIMPLEMENTED();
8516 }
8517 catch(std::bad_alloc&)
8518 {
8519 return gl::error(GL_OUT_OF_MEMORY);
8520 }
8521}
8522
8523void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
8524{
8525 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
8526
8527 try
8528 {
8529 gl::Context *context = gl::getNonLostContext();
8530
8531 if (context)
8532 {
8533 if (context->getClientVersion() < 3)
8534 {
8535 return gl::error(GL_INVALID_OPERATION);
8536 }
8537 }
8538
8539 UNIMPLEMENTED();
8540 }
8541 catch(std::bad_alloc&)
8542 {
8543 return gl::error(GL_OUT_OF_MEMORY);
8544 }
8545}
8546
8547void __stdcall glEndTransformFeedback(void)
8548{
8549 EVENT("(void)");
8550
8551 try
8552 {
8553 gl::Context *context = gl::getNonLostContext();
8554
8555 if (context)
8556 {
8557 if (context->getClientVersion() < 3)
8558 {
8559 return gl::error(GL_INVALID_OPERATION);
8560 }
8561 }
8562
8563 UNIMPLEMENTED();
8564 }
8565 catch(std::bad_alloc&)
8566 {
8567 return gl::error(GL_OUT_OF_MEMORY);
8568 }
8569}
8570
8571void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
8572{
8573 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
8574 target, index, buffer, offset, size);
8575
8576 try
8577 {
8578 gl::Context *context = gl::getNonLostContext();
8579
8580 if (context)
8581 {
8582 if (context->getClientVersion() < 3)
8583 {
8584 return gl::error(GL_INVALID_OPERATION);
8585 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008586
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008587 switch (target)
8588 {
8589 case GL_TRANSFORM_FEEDBACK_BUFFER:
8590 if (index > context->getMaxTransformFeedbackBufferBindings())
8591 {
8592 return gl::error(GL_INVALID_VALUE);
8593 }
8594 break;
8595
8596 case GL_UNIFORM_BUFFER:
8597 if (index >= context->getMaximumCombinedUniformBufferBindings())
8598 {
8599 return gl::error(GL_INVALID_VALUE);
8600 }
8601 break;
8602
8603 default:
8604 return gl::error(GL_INVALID_ENUM);
8605 }
8606
8607 gl::Buffer *bufferObject = context->getBuffer(buffer);
8608 if (!bufferObject)
8609 {
8610 // Buffer index must not have been valid
8611 return gl::error(GL_INVALID_VALUE);
8612 }
8613
8614 if (size <= 0 || static_cast<unsigned int>(offset + size) > bufferObject->size())
8615 {
8616 return gl::error(GL_INVALID_VALUE);
8617 }
8618
8619 switch (target)
8620 {
8621 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00008622 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
8623 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008624 break;
8625
8626 case GL_UNIFORM_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00008627 context->bindIndexedUniformBuffer(buffer, index, offset, size);
8628 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008629 break;
8630
8631 default:
8632 UNREACHABLE();
8633 }
8634 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008635 }
8636 catch(std::bad_alloc&)
8637 {
8638 return gl::error(GL_OUT_OF_MEMORY);
8639 }
8640}
8641
8642void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
8643{
8644 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
8645 target, index, buffer);
8646
8647 try
8648 {
8649 gl::Context *context = gl::getNonLostContext();
8650
8651 if (context)
8652 {
8653 if (context->getClientVersion() < 3)
8654 {
8655 return gl::error(GL_INVALID_OPERATION);
8656 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008657
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008658 switch (target)
8659 {
8660 case GL_TRANSFORM_FEEDBACK_BUFFER:
8661 if (index > context->getMaxTransformFeedbackBufferBindings())
8662 {
8663 return gl::error(GL_INVALID_VALUE);
8664 }
8665 break;
8666
8667 case GL_UNIFORM_BUFFER:
8668 if (index > context->getMaximumCombinedUniformBufferBindings())
8669 {
8670 return gl::error(GL_INVALID_VALUE);
8671 }
8672 break;
8673
8674 default:
8675 return gl::error(GL_INVALID_ENUM);
8676 }
8677
8678 gl::Buffer *bufferObject = context->getBuffer(buffer);
8679 if (!bufferObject)
8680 {
8681 // Buffer index must not have been valid
8682 return gl::error(GL_INVALID_VALUE);
8683 }
8684
8685 switch (target)
8686 {
8687 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00008688 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, -1);
8689 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008690 break;
8691
8692 case GL_UNIFORM_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00008693 context->bindIndexedUniformBuffer(buffer, index, 0, -1);
8694 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008695 break;
8696
8697 default:
8698 UNREACHABLE();
8699 }
8700 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008701 }
8702 catch(std::bad_alloc&)
8703 {
8704 return gl::error(GL_OUT_OF_MEMORY);
8705 }
8706}
8707
8708void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
8709{
8710 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
8711 program, count, varyings, bufferMode);
8712
8713 try
8714 {
8715 gl::Context *context = gl::getNonLostContext();
8716
8717 if (context)
8718 {
8719 if (context->getClientVersion() < 3)
8720 {
8721 return gl::error(GL_INVALID_OPERATION);
8722 }
8723 }
8724
8725 UNIMPLEMENTED();
8726 }
8727 catch(std::bad_alloc&)
8728 {
8729 return gl::error(GL_OUT_OF_MEMORY);
8730 }
8731}
8732
8733void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
8734{
8735 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
8736 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
8737 program, index, bufSize, length, size, type, name);
8738
8739 try
8740 {
8741 gl::Context *context = gl::getNonLostContext();
8742
8743 if (context)
8744 {
8745 if (context->getClientVersion() < 3)
8746 {
8747 return gl::error(GL_INVALID_OPERATION);
8748 }
8749 }
8750
8751 UNIMPLEMENTED();
8752 }
8753 catch(std::bad_alloc&)
8754 {
8755 return gl::error(GL_OUT_OF_MEMORY);
8756 }
8757}
8758
8759void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
8760{
8761 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
8762 index, size, type, stride, pointer);
8763
8764 try
8765 {
8766 gl::Context *context = gl::getNonLostContext();
8767
8768 if (context)
8769 {
8770 if (context->getClientVersion() < 3)
8771 {
8772 return gl::error(GL_INVALID_OPERATION);
8773 }
8774 }
8775
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008776 if (index >= gl::MAX_VERTEX_ATTRIBS)
8777 {
8778 return gl::error(GL_INVALID_VALUE);
8779 }
8780
8781 if (size < 1 || size > 4)
8782 {
8783 return gl::error(GL_INVALID_VALUE);
8784 }
8785
8786 switch (type)
8787 {
8788 case GL_BYTE:
8789 case GL_UNSIGNED_BYTE:
8790 case GL_SHORT:
8791 case GL_UNSIGNED_SHORT:
8792 case GL_INT:
8793 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008794 case GL_INT_2_10_10_10_REV:
8795 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008796 break;
8797 default:
8798 return gl::error(GL_INVALID_ENUM);
8799 }
8800
8801 if (stride < 0)
8802 {
8803 return gl::error(GL_INVALID_VALUE);
8804 }
8805
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008806 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
8807 {
8808 return gl::error(GL_INVALID_OPERATION);
8809 }
8810
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008811 if (context)
8812 {
8813 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
8814 stride, pointer);
8815 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008816 }
8817 catch(std::bad_alloc&)
8818 {
8819 return gl::error(GL_OUT_OF_MEMORY);
8820 }
8821}
8822
8823void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
8824{
8825 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
8826 index, pname, params);
8827
8828 try
8829 {
8830 gl::Context *context = gl::getNonLostContext();
8831
8832 if (context)
8833 {
8834 if (context->getClientVersion() < 3)
8835 {
8836 return gl::error(GL_INVALID_OPERATION);
8837 }
8838 }
8839
8840 UNIMPLEMENTED();
8841 }
8842 catch(std::bad_alloc&)
8843 {
8844 return gl::error(GL_OUT_OF_MEMORY);
8845 }
8846}
8847
8848void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
8849{
8850 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
8851 index, pname, params);
8852
8853 try
8854 {
8855 gl::Context *context = gl::getNonLostContext();
8856
8857 if (context)
8858 {
8859 if (context->getClientVersion() < 3)
8860 {
8861 return gl::error(GL_INVALID_OPERATION);
8862 }
8863 }
8864
8865 UNIMPLEMENTED();
8866 }
8867 catch(std::bad_alloc&)
8868 {
8869 return gl::error(GL_OUT_OF_MEMORY);
8870 }
8871}
8872
8873void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
8874{
8875 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
8876 index, x, y, z, w);
8877
8878 try
8879 {
8880 gl::Context *context = gl::getNonLostContext();
8881
8882 if (context)
8883 {
8884 if (context->getClientVersion() < 3)
8885 {
8886 return gl::error(GL_INVALID_OPERATION);
8887 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008888
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008889 if (index >= gl::MAX_VERTEX_ATTRIBS)
8890 {
8891 return gl::error(GL_INVALID_VALUE);
8892 }
8893
8894 GLint vals[4] = { x, y, z, w };
8895 context->setVertexAttribi(index, vals);
8896 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008897 }
8898 catch(std::bad_alloc&)
8899 {
8900 return gl::error(GL_OUT_OF_MEMORY);
8901 }
8902}
8903
8904void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
8905{
8906 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
8907 index, x, y, z, w);
8908
8909 try
8910 {
8911 gl::Context *context = gl::getNonLostContext();
8912
8913 if (context)
8914 {
8915 if (context->getClientVersion() < 3)
8916 {
8917 return gl::error(GL_INVALID_OPERATION);
8918 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008919
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008920 if (index >= gl::MAX_VERTEX_ATTRIBS)
8921 {
8922 return gl::error(GL_INVALID_VALUE);
8923 }
8924
8925 GLuint vals[4] = { x, y, z, w };
8926 context->setVertexAttribu(index, vals);
8927 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008928 }
8929 catch(std::bad_alloc&)
8930 {
8931 return gl::error(GL_OUT_OF_MEMORY);
8932 }
8933}
8934
8935void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
8936{
8937 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
8938
8939 try
8940 {
8941 gl::Context *context = gl::getNonLostContext();
8942
8943 if (context)
8944 {
8945 if (context->getClientVersion() < 3)
8946 {
8947 return gl::error(GL_INVALID_OPERATION);
8948 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008949
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008950 if (index >= gl::MAX_VERTEX_ATTRIBS)
8951 {
8952 return gl::error(GL_INVALID_VALUE);
8953 }
8954
8955 context->setVertexAttribi(index, v);
8956 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008957 }
8958 catch(std::bad_alloc&)
8959 {
8960 return gl::error(GL_OUT_OF_MEMORY);
8961 }
8962}
8963
8964void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
8965{
8966 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
8967
8968 try
8969 {
8970 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.coma8885862013-04-13 03:37:53 +00008979 if (index >= gl::MAX_VERTEX_ATTRIBS)
8980 {
8981 return gl::error(GL_INVALID_VALUE);
8982 }
8983
8984 context->setVertexAttribu(index, v);
8985 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008986 }
8987 catch(std::bad_alloc&)
8988 {
8989 return gl::error(GL_OUT_OF_MEMORY);
8990 }
8991}
8992
8993void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
8994{
8995 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
8996 program, location, params);
8997
8998 try
8999 {
9000 gl::Context *context = gl::getNonLostContext();
9001
9002 if (context)
9003 {
9004 if (context->getClientVersion() < 3)
9005 {
9006 return gl::error(GL_INVALID_OPERATION);
9007 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009008
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00009009 if (program == 0)
9010 {
9011 return gl::error(GL_INVALID_VALUE);
9012 }
9013
9014 gl::Program *programObject = context->getProgram(program);
9015
9016 if (!programObject || !programObject->isLinked())
9017 {
9018 return gl::error(GL_INVALID_OPERATION);
9019 }
9020
9021 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9022 if (!programBinary)
9023 {
9024 return gl::error(GL_INVALID_OPERATION);
9025 }
9026
9027 if (!programBinary->getUniformuiv(location, NULL, params))
9028 {
9029 return gl::error(GL_INVALID_OPERATION);
9030 }
9031 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009032 }
9033 catch(std::bad_alloc&)
9034 {
9035 return gl::error(GL_OUT_OF_MEMORY);
9036 }
9037}
9038
9039GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
9040{
9041 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
9042 program, name);
9043
9044 try
9045 {
9046 gl::Context *context = gl::getNonLostContext();
9047
9048 if (context)
9049 {
9050 if (context->getClientVersion() < 3)
9051 {
9052 return gl::error(GL_INVALID_OPERATION, 0);
9053 }
9054 }
9055
9056 UNIMPLEMENTED();
9057 }
9058 catch(std::bad_alloc&)
9059 {
9060 return gl::error(GL_OUT_OF_MEMORY, 0);
9061 }
9062
9063 return 0;
9064}
9065
9066void __stdcall glUniform1ui(GLint location, GLuint v0)
9067{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009068 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009069}
9070
9071void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
9072{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009073 const GLuint xy[] = { v0, v1 };
9074 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009075}
9076
9077void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
9078{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009079 const GLuint xyz[] = { v0, v1, v2 };
9080 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009081}
9082
9083void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
9084{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009085 const GLuint xyzw[] = { v0, v1, v2, v3 };
9086 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009087}
9088
9089void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
9090{
9091 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9092 location, count, value);
9093
9094 try
9095 {
9096 gl::Context *context = gl::getNonLostContext();
9097
9098 if (context)
9099 {
9100 if (context->getClientVersion() < 3)
9101 {
9102 return gl::error(GL_INVALID_OPERATION);
9103 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009104
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009105 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9106 if (!programBinary)
9107 {
9108 return gl::error(GL_INVALID_OPERATION);
9109 }
9110
9111 if (!programBinary->setUniform1uiv(location, count, value))
9112 {
9113 return gl::error(GL_INVALID_OPERATION);
9114 }
9115 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009116 }
9117 catch(std::bad_alloc&)
9118 {
9119 return gl::error(GL_OUT_OF_MEMORY);
9120 }
9121}
9122
9123void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
9124{
9125 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9126 location, count, value);
9127
9128 try
9129 {
9130 gl::Context *context = gl::getNonLostContext();
9131
9132 if (context)
9133 {
9134 if (context->getClientVersion() < 3)
9135 {
9136 return gl::error(GL_INVALID_OPERATION);
9137 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009138
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009139 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9140 if (!programBinary)
9141 {
9142 return gl::error(GL_INVALID_OPERATION);
9143 }
9144
9145 if (!programBinary->setUniform2uiv(location, count, value))
9146 {
9147 return gl::error(GL_INVALID_OPERATION);
9148 }
9149 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009150 }
9151 catch(std::bad_alloc&)
9152 {
9153 return gl::error(GL_OUT_OF_MEMORY);
9154 }
9155}
9156
9157void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
9158{
9159 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
9160 location, count, value);
9161
9162 try
9163 {
9164 gl::Context *context = gl::getNonLostContext();
9165
9166 if (context)
9167 {
9168 if (context->getClientVersion() < 3)
9169 {
9170 return gl::error(GL_INVALID_OPERATION);
9171 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009172
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009173 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9174 if (!programBinary)
9175 {
9176 return gl::error(GL_INVALID_OPERATION);
9177 }
9178
9179 if (!programBinary->setUniform3uiv(location, count, value))
9180 {
9181 return gl::error(GL_INVALID_OPERATION);
9182 }
9183 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009184 }
9185 catch(std::bad_alloc&)
9186 {
9187 return gl::error(GL_OUT_OF_MEMORY);
9188 }
9189}
9190
9191void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
9192{
9193 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9194 location, count, value);
9195
9196 try
9197 {
9198 gl::Context *context = gl::getNonLostContext();
9199
9200 if (context)
9201 {
9202 if (context->getClientVersion() < 3)
9203 {
9204 return gl::error(GL_INVALID_OPERATION);
9205 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009206
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009207 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9208 if (!programBinary)
9209 {
9210 return gl::error(GL_INVALID_OPERATION);
9211 }
9212
9213 if (!programBinary->setUniform4uiv(location, count, value))
9214 {
9215 return gl::error(GL_INVALID_OPERATION);
9216 }
9217 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009218 }
9219 catch(std::bad_alloc&)
9220 {
9221 return gl::error(GL_OUT_OF_MEMORY);
9222 }
9223}
9224
9225void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
9226{
9227 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
9228 buffer, drawbuffer, value);
9229
9230 try
9231 {
9232 gl::Context *context = gl::getNonLostContext();
9233
9234 if (context)
9235 {
9236 if (context->getClientVersion() < 3)
9237 {
9238 return gl::error(GL_INVALID_OPERATION);
9239 }
9240 }
9241
9242 UNIMPLEMENTED();
9243 }
9244 catch(std::bad_alloc&)
9245 {
9246 return gl::error(GL_OUT_OF_MEMORY);
9247 }
9248}
9249
9250void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
9251{
9252 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
9253 buffer, drawbuffer, value);
9254
9255 try
9256 {
9257 gl::Context *context = gl::getNonLostContext();
9258
9259 if (context)
9260 {
9261 if (context->getClientVersion() < 3)
9262 {
9263 return gl::error(GL_INVALID_OPERATION);
9264 }
9265 }
9266
9267 UNIMPLEMENTED();
9268 }
9269 catch(std::bad_alloc&)
9270 {
9271 return gl::error(GL_OUT_OF_MEMORY);
9272 }
9273}
9274
9275void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
9276{
9277 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
9278 buffer, drawbuffer, value);
9279
9280 try
9281 {
9282 gl::Context *context = gl::getNonLostContext();
9283
9284 if (context)
9285 {
9286 if (context->getClientVersion() < 3)
9287 {
9288 return gl::error(GL_INVALID_OPERATION);
9289 }
9290 }
9291
9292 UNIMPLEMENTED();
9293 }
9294 catch(std::bad_alloc&)
9295 {
9296 return gl::error(GL_OUT_OF_MEMORY);
9297 }
9298}
9299
9300void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
9301{
9302 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
9303 buffer, drawbuffer, depth, stencil);
9304
9305 try
9306 {
9307 gl::Context *context = gl::getNonLostContext();
9308
9309 if (context)
9310 {
9311 if (context->getClientVersion() < 3)
9312 {
9313 return gl::error(GL_INVALID_OPERATION);
9314 }
9315 }
9316
9317 UNIMPLEMENTED();
9318 }
9319 catch(std::bad_alloc&)
9320 {
9321 return gl::error(GL_OUT_OF_MEMORY);
9322 }
9323}
9324
9325const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
9326{
9327 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
9328
9329 try
9330 {
9331 gl::Context *context = gl::getNonLostContext();
9332
9333 if (context)
9334 {
9335 if (context->getClientVersion() < 3)
9336 {
9337 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
9338 }
9339 }
9340
9341 UNIMPLEMENTED();
9342 }
9343 catch(std::bad_alloc&)
9344 {
9345 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
9346 }
9347
9348 return NULL;
9349}
9350
9351void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
9352{
9353 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
9354 readTarget, writeTarget, readOffset, writeOffset, size);
9355
9356 try
9357 {
9358 gl::Context *context = gl::getNonLostContext();
9359
9360 if (context)
9361 {
9362 if (context->getClientVersion() < 3)
9363 {
9364 return gl::error(GL_INVALID_OPERATION);
9365 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009366
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00009367 gl::Buffer *readBuffer = NULL;
9368 switch (readTarget)
9369 {
9370 case GL_ARRAY_BUFFER:
9371 readBuffer = context->getArrayBuffer();
9372 break;
9373 case GL_COPY_READ_BUFFER:
9374 readBuffer = context->getCopyReadBuffer();
9375 break;
9376 case GL_COPY_WRITE_BUFFER:
9377 readBuffer = context->getCopyWriteBuffer();
9378 break;
9379 case GL_ELEMENT_ARRAY_BUFFER:
9380 readBuffer = context->getElementArrayBuffer();
9381 break;
9382 case GL_PIXEL_PACK_BUFFER:
9383 readBuffer = context->getPixelPackBuffer();
9384 break;
9385 case GL_PIXEL_UNPACK_BUFFER:
9386 readBuffer = context->getPixelUnpackBuffer();
9387 break;
9388 case GL_TRANSFORM_FEEDBACK_BUFFER:
9389 readBuffer = context->getGenericTransformFeedbackBuffer();
9390 break;
9391 case GL_UNIFORM_BUFFER:
9392 readBuffer = context->getGenericUniformBuffer();
9393 break;
9394 default:
9395 return gl::error(GL_INVALID_ENUM);
9396 }
9397
9398 gl::Buffer *writeBuffer = NULL;
9399 switch (writeTarget)
9400 {
9401 case GL_ARRAY_BUFFER:
9402 writeBuffer = context->getArrayBuffer();
9403 break;
9404 case GL_COPY_READ_BUFFER:
9405 writeBuffer = context->getCopyReadBuffer();
9406 break;
9407 case GL_COPY_WRITE_BUFFER:
9408 writeBuffer = context->getCopyWriteBuffer();
9409 break;
9410 case GL_ELEMENT_ARRAY_BUFFER:
9411 writeBuffer = context->getElementArrayBuffer();
9412 break;
9413 case GL_PIXEL_PACK_BUFFER:
9414 writeBuffer = context->getPixelPackBuffer();
9415 break;
9416 case GL_PIXEL_UNPACK_BUFFER:
9417 writeBuffer = context->getPixelUnpackBuffer();
9418 break;
9419 case GL_TRANSFORM_FEEDBACK_BUFFER:
9420 writeBuffer = context->getGenericTransformFeedbackBuffer();
9421 break;
9422 case GL_UNIFORM_BUFFER:
9423 writeBuffer = context->getGenericUniformBuffer();
9424 break;
9425 default:
9426 return gl::error(GL_INVALID_ENUM);
9427 }
9428
9429 if (!readBuffer || !writeBuffer)
9430 {
9431 return gl::error(GL_INVALID_OPERATION);
9432 }
9433
9434 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
9435 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
9436 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
9437 {
9438 return gl::error(GL_INVALID_VALUE);
9439 }
9440
9441 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
9442 {
9443 return gl::error(GL_INVALID_VALUE);
9444 }
9445
9446 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
9447
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +00009448 // if size is zero, the copy is a successful no-op
9449 if (size > 0)
9450 {
9451 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
9452 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00009453 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009454 }
9455 catch(std::bad_alloc&)
9456 {
9457 return gl::error(GL_OUT_OF_MEMORY);
9458 }
9459}
9460
9461void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
9462{
9463 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
9464 program, uniformCount, uniformNames, uniformIndices);
9465
9466 try
9467 {
9468 gl::Context *context = gl::getNonLostContext();
9469
9470 if (context)
9471 {
9472 if (context->getClientVersion() < 3)
9473 {
9474 return gl::error(GL_INVALID_OPERATION);
9475 }
9476 }
9477
9478 UNIMPLEMENTED();
9479 }
9480 catch(std::bad_alloc&)
9481 {
9482 return gl::error(GL_OUT_OF_MEMORY);
9483 }
9484}
9485
9486void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
9487{
9488 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9489 program, uniformCount, uniformIndices, pname, params);
9490
9491 try
9492 {
9493 gl::Context *context = gl::getNonLostContext();
9494
9495 if (context)
9496 {
9497 if (context->getClientVersion() < 3)
9498 {
9499 return gl::error(GL_INVALID_OPERATION);
9500 }
9501 }
9502
9503 UNIMPLEMENTED();
9504 }
9505 catch(std::bad_alloc&)
9506 {
9507 return gl::error(GL_OUT_OF_MEMORY);
9508 }
9509}
9510
9511GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
9512{
9513 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
9514
9515 try
9516 {
9517 gl::Context *context = gl::getNonLostContext();
9518
9519 if (context)
9520 {
9521 if (context->getClientVersion() < 3)
9522 {
9523 return gl::error(GL_INVALID_OPERATION, 0);
9524 }
9525 }
9526
9527 UNIMPLEMENTED();
9528 }
9529 catch(std::bad_alloc&)
9530 {
9531 return gl::error(GL_OUT_OF_MEMORY, 0);
9532 }
9533
9534 return 0;
9535}
9536
9537void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
9538{
9539 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9540 program, uniformBlockIndex, pname, params);
9541
9542 try
9543 {
9544 gl::Context *context = gl::getNonLostContext();
9545
9546 if (context)
9547 {
9548 if (context->getClientVersion() < 3)
9549 {
9550 return gl::error(GL_INVALID_OPERATION);
9551 }
9552 }
9553
9554 UNIMPLEMENTED();
9555 }
9556 catch(std::bad_alloc&)
9557 {
9558 return gl::error(GL_OUT_OF_MEMORY);
9559 }
9560}
9561
9562void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
9563{
9564 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
9565 program, uniformBlockIndex, bufSize, length, uniformBlockName);
9566
9567 try
9568 {
9569 gl::Context *context = gl::getNonLostContext();
9570
9571 if (context)
9572 {
9573 if (context->getClientVersion() < 3)
9574 {
9575 return gl::error(GL_INVALID_OPERATION);
9576 }
9577 }
9578
9579 UNIMPLEMENTED();
9580 }
9581 catch(std::bad_alloc&)
9582 {
9583 return gl::error(GL_OUT_OF_MEMORY);
9584 }
9585}
9586
9587void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
9588{
9589 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
9590 program, uniformBlockIndex, uniformBlockBinding);
9591
9592 try
9593 {
9594 gl::Context *context = gl::getNonLostContext();
9595
9596 if (context)
9597 {
9598 if (context->getClientVersion() < 3)
9599 {
9600 return gl::error(GL_INVALID_OPERATION);
9601 }
9602 }
9603
9604 UNIMPLEMENTED();
9605 }
9606 catch(std::bad_alloc&)
9607 {
9608 return gl::error(GL_OUT_OF_MEMORY);
9609 }
9610}
9611
9612void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
9613{
9614 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
9615 mode, first, count, instanceCount);
9616
9617 try
9618 {
9619 gl::Context *context = gl::getNonLostContext();
9620
9621 if (context)
9622 {
9623 if (context->getClientVersion() < 3)
9624 {
9625 return gl::error(GL_INVALID_OPERATION);
9626 }
9627 }
9628
9629 UNIMPLEMENTED();
9630 }
9631 catch(std::bad_alloc&)
9632 {
9633 return gl::error(GL_OUT_OF_MEMORY);
9634 }
9635}
9636
9637void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
9638{
9639 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
9640 mode, count, type, indices, instanceCount);
9641
9642 try
9643 {
9644 gl::Context *context = gl::getNonLostContext();
9645
9646 if (context)
9647 {
9648 if (context->getClientVersion() < 3)
9649 {
9650 return gl::error(GL_INVALID_OPERATION);
9651 }
9652 }
9653
9654 UNIMPLEMENTED();
9655 }
9656 catch(std::bad_alloc&)
9657 {
9658 return gl::error(GL_OUT_OF_MEMORY);
9659 }
9660}
9661
9662GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
9663{
9664 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
9665
9666 try
9667 {
9668 gl::Context *context = gl::getNonLostContext();
9669
9670 if (context)
9671 {
9672 if (context->getClientVersion() < 3)
9673 {
9674 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(NULL));
9675 }
9676 }
9677
9678 UNIMPLEMENTED();
9679 }
9680 catch(std::bad_alloc&)
9681 {
9682 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
9683 }
9684
9685 return NULL;
9686}
9687
9688GLboolean __stdcall glIsSync(GLsync sync)
9689{
9690 EVENT("(GLsync sync = 0x%0.8p)", sync);
9691
9692 try
9693 {
9694 gl::Context *context = gl::getNonLostContext();
9695
9696 if (context)
9697 {
9698 if (context->getClientVersion() < 3)
9699 {
9700 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9701 }
9702 }
9703
9704 UNIMPLEMENTED();
9705 }
9706 catch(std::bad_alloc&)
9707 {
9708 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9709 }
9710
9711 return GL_FALSE;
9712}
9713
9714void __stdcall glDeleteSync(GLsync sync)
9715{
9716 EVENT("(GLsync sync = 0x%0.8p)", sync);
9717
9718 try
9719 {
9720 gl::Context *context = gl::getNonLostContext();
9721
9722 if (context)
9723 {
9724 if (context->getClientVersion() < 3)
9725 {
9726 return gl::error(GL_INVALID_OPERATION);
9727 }
9728 }
9729
9730 UNIMPLEMENTED();
9731 }
9732 catch(std::bad_alloc&)
9733 {
9734 return gl::error(GL_OUT_OF_MEMORY);
9735 }
9736}
9737
9738GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
9739{
9740 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
9741 sync, flags, timeout);
9742
9743 try
9744 {
9745 gl::Context *context = gl::getNonLostContext();
9746
9747 if (context)
9748 {
9749 if (context->getClientVersion() < 3)
9750 {
9751 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9752 }
9753 }
9754
9755 UNIMPLEMENTED();
9756 }
9757 catch(std::bad_alloc&)
9758 {
9759 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9760 }
9761
9762 return GL_FALSE;
9763}
9764
9765void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
9766{
9767 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
9768 sync, flags, timeout);
9769
9770 try
9771 {
9772 gl::Context *context = gl::getNonLostContext();
9773
9774 if (context)
9775 {
9776 if (context->getClientVersion() < 3)
9777 {
9778 return gl::error(GL_INVALID_OPERATION);
9779 }
9780 }
9781
9782 UNIMPLEMENTED();
9783 }
9784 catch(std::bad_alloc&)
9785 {
9786 return gl::error(GL_OUT_OF_MEMORY);
9787 }
9788}
9789
9790void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
9791{
9792 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
9793 pname, params);
9794
9795 try
9796 {
9797 gl::Context *context = gl::getNonLostContext();
9798
9799 if (context)
9800 {
9801 if (context->getClientVersion() < 3)
9802 {
9803 return gl::error(GL_INVALID_OPERATION);
9804 }
9805 }
9806
9807 UNIMPLEMENTED();
9808 }
9809 catch(std::bad_alloc&)
9810 {
9811 return gl::error(GL_OUT_OF_MEMORY);
9812 }
9813}
9814
9815void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
9816{
9817 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
9818 sync, pname, bufSize, length, values);
9819
9820 try
9821 {
9822 gl::Context *context = gl::getNonLostContext();
9823
9824 if (context)
9825 {
9826 if (context->getClientVersion() < 3)
9827 {
9828 return gl::error(GL_INVALID_OPERATION);
9829 }
9830 }
9831
9832 UNIMPLEMENTED();
9833 }
9834 catch(std::bad_alloc&)
9835 {
9836 return gl::error(GL_OUT_OF_MEMORY);
9837 }
9838}
9839
9840void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
9841{
9842 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
9843 target, index, data);
9844
9845 try
9846 {
9847 gl::Context *context = gl::getNonLostContext();
9848
9849 if (context)
9850 {
9851 if (context->getClientVersion() < 3)
9852 {
9853 return gl::error(GL_INVALID_OPERATION);
9854 }
9855 }
9856
9857 UNIMPLEMENTED();
9858 }
9859 catch(std::bad_alloc&)
9860 {
9861 return gl::error(GL_OUT_OF_MEMORY);
9862 }
9863}
9864
9865void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
9866{
9867 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
9868 target, pname, params);
9869
9870 try
9871 {
9872 gl::Context *context = gl::getNonLostContext();
9873
9874 if (context)
9875 {
9876 if (context->getClientVersion() < 3)
9877 {
9878 return gl::error(GL_INVALID_OPERATION);
9879 }
9880 }
9881
9882 UNIMPLEMENTED();
9883 }
9884 catch(std::bad_alloc&)
9885 {
9886 return gl::error(GL_OUT_OF_MEMORY);
9887 }
9888}
9889
9890void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
9891{
9892 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
9893
9894 try
9895 {
9896 gl::Context *context = gl::getNonLostContext();
9897
9898 if (context)
9899 {
9900 if (context->getClientVersion() < 3)
9901 {
9902 return gl::error(GL_INVALID_OPERATION);
9903 }
9904 }
9905
9906 UNIMPLEMENTED();
9907 }
9908 catch(std::bad_alloc&)
9909 {
9910 return gl::error(GL_OUT_OF_MEMORY);
9911 }
9912}
9913
9914void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
9915{
9916 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
9917
9918 try
9919 {
9920 gl::Context *context = gl::getNonLostContext();
9921
9922 if (context)
9923 {
9924 if (context->getClientVersion() < 3)
9925 {
9926 return gl::error(GL_INVALID_OPERATION);
9927 }
9928 }
9929
9930 UNIMPLEMENTED();
9931 }
9932 catch(std::bad_alloc&)
9933 {
9934 return gl::error(GL_OUT_OF_MEMORY);
9935 }
9936}
9937
9938GLboolean __stdcall glIsSampler(GLuint sampler)
9939{
9940 EVENT("(GLuint sampler = %u)", sampler);
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, GL_FALSE);
9951 }
9952 }
9953
9954 UNIMPLEMENTED();
9955 }
9956 catch(std::bad_alloc&)
9957 {
9958 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9959 }
9960
9961 return GL_FALSE;
9962}
9963
9964void __stdcall glBindSampler(GLuint unit, GLuint sampler)
9965{
9966 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
9967
9968 try
9969 {
9970 gl::Context *context = gl::getNonLostContext();
9971
9972 if (context)
9973 {
9974 if (context->getClientVersion() < 3)
9975 {
9976 return gl::error(GL_INVALID_OPERATION);
9977 }
9978 }
9979
9980 UNIMPLEMENTED();
9981 }
9982 catch(std::bad_alloc&)
9983 {
9984 return gl::error(GL_OUT_OF_MEMORY);
9985 }
9986}
9987
9988void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
9989{
9990 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
9991
9992 try
9993 {
9994 gl::Context *context = gl::getNonLostContext();
9995
9996 if (context)
9997 {
9998 if (context->getClientVersion() < 3)
9999 {
10000 return gl::error(GL_INVALID_OPERATION);
10001 }
10002 }
10003
10004 UNIMPLEMENTED();
10005 }
10006 catch(std::bad_alloc&)
10007 {
10008 return gl::error(GL_OUT_OF_MEMORY);
10009 }
10010}
10011
10012void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
10013{
10014 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLint* param = 0x%0.8p)",
10015 sampler, pname, param);
10016
10017 try
10018 {
10019 gl::Context *context = gl::getNonLostContext();
10020
10021 if (context)
10022 {
10023 if (context->getClientVersion() < 3)
10024 {
10025 return gl::error(GL_INVALID_OPERATION);
10026 }
10027 }
10028
10029 UNIMPLEMENTED();
10030 }
10031 catch(std::bad_alloc&)
10032 {
10033 return gl::error(GL_OUT_OF_MEMORY);
10034 }
10035}
10036
10037void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
10038{
10039 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
10040
10041 try
10042 {
10043 gl::Context *context = gl::getNonLostContext();
10044
10045 if (context)
10046 {
10047 if (context->getClientVersion() < 3)
10048 {
10049 return gl::error(GL_INVALID_OPERATION);
10050 }
10051 }
10052
10053 UNIMPLEMENTED();
10054 }
10055 catch(std::bad_alloc&)
10056 {
10057 return gl::error(GL_OUT_OF_MEMORY);
10058 }
10059}
10060
10061void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
10062{
10063 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLfloat* param = 0x%0.8p)", sampler, pname, param);
10064
10065 try
10066 {
10067 gl::Context *context = gl::getNonLostContext();
10068
10069 if (context)
10070 {
10071 if (context->getClientVersion() < 3)
10072 {
10073 return gl::error(GL_INVALID_OPERATION);
10074 }
10075 }
10076
10077 UNIMPLEMENTED();
10078 }
10079 catch(std::bad_alloc&)
10080 {
10081 return gl::error(GL_OUT_OF_MEMORY);
10082 }
10083}
10084
10085void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
10086{
10087 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
10088
10089 try
10090 {
10091 gl::Context *context = gl::getNonLostContext();
10092
10093 if (context)
10094 {
10095 if (context->getClientVersion() < 3)
10096 {
10097 return gl::error(GL_INVALID_OPERATION);
10098 }
10099 }
10100
10101 UNIMPLEMENTED();
10102 }
10103 catch(std::bad_alloc&)
10104 {
10105 return gl::error(GL_OUT_OF_MEMORY);
10106 }
10107}
10108
10109void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
10110{
10111 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
10112
10113 try
10114 {
10115 gl::Context *context = gl::getNonLostContext();
10116
10117 if (context)
10118 {
10119 if (context->getClientVersion() < 3)
10120 {
10121 return gl::error(GL_INVALID_OPERATION);
10122 }
10123 }
10124
10125 UNIMPLEMENTED();
10126 }
10127 catch(std::bad_alloc&)
10128 {
10129 return gl::error(GL_OUT_OF_MEMORY);
10130 }
10131}
10132
10133void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
10134{
10135 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
10136
10137 try
10138 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000010139 if (index >= gl::MAX_VERTEX_ATTRIBS)
10140 {
10141 return gl::error(GL_INVALID_VALUE);
10142 }
10143
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010144 gl::Context *context = gl::getNonLostContext();
10145
10146 if (context)
10147 {
10148 if (context->getClientVersion() < 3)
10149 {
10150 return gl::error(GL_INVALID_OPERATION);
10151 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010152
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000010153 context->setVertexAttribDivisor(index, divisor);
10154 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010155 }
10156 catch(std::bad_alloc&)
10157 {
10158 return gl::error(GL_OUT_OF_MEMORY);
10159 }
10160}
10161
10162void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
10163{
10164 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
10165
10166 try
10167 {
10168 gl::Context *context = gl::getNonLostContext();
10169
10170 if (context)
10171 {
10172 if (context->getClientVersion() < 3)
10173 {
10174 return gl::error(GL_INVALID_OPERATION);
10175 }
10176 }
10177
10178 UNIMPLEMENTED();
10179 }
10180 catch(std::bad_alloc&)
10181 {
10182 return gl::error(GL_OUT_OF_MEMORY);
10183 }
10184}
10185
10186void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
10187{
10188 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
10189
10190 try
10191 {
10192 gl::Context *context = gl::getNonLostContext();
10193
10194 if (context)
10195 {
10196 if (context->getClientVersion() < 3)
10197 {
10198 return gl::error(GL_INVALID_OPERATION);
10199 }
10200 }
10201
10202 UNIMPLEMENTED();
10203 }
10204 catch(std::bad_alloc&)
10205 {
10206 return gl::error(GL_OUT_OF_MEMORY);
10207 }
10208}
10209
10210void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
10211{
10212 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
10213
10214 try
10215 {
10216 gl::Context *context = gl::getNonLostContext();
10217
10218 if (context)
10219 {
10220 if (context->getClientVersion() < 3)
10221 {
10222 return gl::error(GL_INVALID_OPERATION);
10223 }
10224 }
10225
10226 UNIMPLEMENTED();
10227 }
10228 catch(std::bad_alloc&)
10229 {
10230 return gl::error(GL_OUT_OF_MEMORY);
10231 }
10232}
10233
10234GLboolean __stdcall glIsTransformFeedback(GLuint id)
10235{
10236 EVENT("(GLuint id = %u)", id);
10237
10238 try
10239 {
10240 gl::Context *context = gl::getNonLostContext();
10241
10242 if (context)
10243 {
10244 if (context->getClientVersion() < 3)
10245 {
10246 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10247 }
10248 }
10249
10250 UNIMPLEMENTED();
10251 }
10252 catch(std::bad_alloc&)
10253 {
10254 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10255 }
10256
10257 return GL_FALSE;
10258}
10259
10260void __stdcall glPauseTransformFeedback(void)
10261{
10262 EVENT("(void)");
10263
10264 try
10265 {
10266 gl::Context *context = gl::getNonLostContext();
10267
10268 if (context)
10269 {
10270 if (context->getClientVersion() < 3)
10271 {
10272 return gl::error(GL_INVALID_OPERATION);
10273 }
10274 }
10275
10276 UNIMPLEMENTED();
10277 }
10278 catch(std::bad_alloc&)
10279 {
10280 return gl::error(GL_OUT_OF_MEMORY);
10281 }
10282}
10283
10284void __stdcall glResumeTransformFeedback(void)
10285{
10286 EVENT("(void)");
10287
10288 try
10289 {
10290 gl::Context *context = gl::getNonLostContext();
10291
10292 if (context)
10293 {
10294 if (context->getClientVersion() < 3)
10295 {
10296 return gl::error(GL_INVALID_OPERATION);
10297 }
10298 }
10299
10300 UNIMPLEMENTED();
10301 }
10302 catch(std::bad_alloc&)
10303 {
10304 return gl::error(GL_OUT_OF_MEMORY);
10305 }
10306}
10307
10308void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
10309{
10310 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
10311 program, bufSize, length, binaryFormat, binary);
10312
10313 try
10314 {
10315 gl::Context *context = gl::getNonLostContext();
10316
10317 if (context)
10318 {
10319 if (context->getClientVersion() < 3)
10320 {
10321 return gl::error(GL_INVALID_OPERATION);
10322 }
10323 }
10324
10325 UNIMPLEMENTED();
10326 }
10327 catch(std::bad_alloc&)
10328 {
10329 return gl::error(GL_OUT_OF_MEMORY);
10330 }
10331}
10332
10333void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
10334{
10335 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
10336 program, binaryFormat, binary, length);
10337
10338 try
10339 {
10340 gl::Context *context = gl::getNonLostContext();
10341
10342 if (context)
10343 {
10344 if (context->getClientVersion() < 3)
10345 {
10346 return gl::error(GL_INVALID_OPERATION);
10347 }
10348 }
10349
10350 UNIMPLEMENTED();
10351 }
10352 catch(std::bad_alloc&)
10353 {
10354 return gl::error(GL_OUT_OF_MEMORY);
10355 }
10356}
10357
10358void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
10359{
10360 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
10361 program, pname, value);
10362
10363 try
10364 {
10365 gl::Context *context = gl::getNonLostContext();
10366
10367 if (context)
10368 {
10369 if (context->getClientVersion() < 3)
10370 {
10371 return gl::error(GL_INVALID_OPERATION);
10372 }
10373 }
10374
10375 UNIMPLEMENTED();
10376 }
10377 catch(std::bad_alloc&)
10378 {
10379 return gl::error(GL_OUT_OF_MEMORY);
10380 }
10381}
10382
10383void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
10384{
10385 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
10386 target, numAttachments, attachments);
10387
10388 try
10389 {
10390 gl::Context *context = gl::getNonLostContext();
10391
10392 if (context)
10393 {
10394 if (context->getClientVersion() < 3)
10395 {
10396 return gl::error(GL_INVALID_OPERATION);
10397 }
10398 }
10399
10400 UNIMPLEMENTED();
10401 }
10402 catch(std::bad_alloc&)
10403 {
10404 return gl::error(GL_OUT_OF_MEMORY);
10405 }
10406}
10407
10408void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
10409{
10410 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
10411 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
10412 target, numAttachments, attachments, x, y, width, height);
10413
10414 try
10415 {
10416 gl::Context *context = gl::getNonLostContext();
10417
10418 if (context)
10419 {
10420 if (context->getClientVersion() < 3)
10421 {
10422 return gl::error(GL_INVALID_OPERATION);
10423 }
10424 }
10425
10426 UNIMPLEMENTED();
10427 }
10428 catch(std::bad_alloc&)
10429 {
10430 return gl::error(GL_OUT_OF_MEMORY);
10431 }
10432}
10433
10434void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
10435{
10436 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
10437 target, levels, internalformat, width, height);
10438
10439 try
10440 {
10441 gl::Context *context = gl::getNonLostContext();
10442
10443 if (context)
10444 {
10445 if (context->getClientVersion() < 3)
10446 {
10447 return gl::error(GL_INVALID_OPERATION);
10448 }
10449 }
10450
10451 UNIMPLEMENTED();
10452 }
10453 catch(std::bad_alloc&)
10454 {
10455 return gl::error(GL_OUT_OF_MEMORY);
10456 }
10457}
10458
10459void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
10460{
10461 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
10462 "GLsizei height = %d, GLsizei depth = %d)",
10463 target, levels, internalformat, width, height, depth);
10464
10465 try
10466 {
10467 gl::Context *context = gl::getNonLostContext();
10468
10469 if (context)
10470 {
10471 if (context->getClientVersion() < 3)
10472 {
10473 return gl::error(GL_INVALID_OPERATION);
10474 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000010475 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010476 }
10477 catch(std::bad_alloc&)
10478 {
10479 return gl::error(GL_OUT_OF_MEMORY);
10480 }
10481}
10482
10483void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
10484{
10485 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
10486 "GLint* params = 0x%0.8p)",
10487 target, internalformat, pname, bufSize, params);
10488
10489 try
10490 {
10491 gl::Context *context = gl::getNonLostContext();
10492
10493 if (context)
10494 {
10495 if (context->getClientVersion() < 3)
10496 {
10497 return gl::error(GL_INVALID_OPERATION);
10498 }
10499 }
10500
10501 UNIMPLEMENTED();
10502 }
10503 catch(std::bad_alloc&)
10504 {
10505 return gl::error(GL_OUT_OF_MEMORY);
10506 }
10507}
10508
10509// Extension functions
10510
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010511void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
10512 GLbitfield mask, GLenum filter)
10513{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000010514 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010515 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
10516 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
10517 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
10518
10519 try
10520 {
10521 switch (filter)
10522 {
10523 case GL_NEAREST:
10524 break;
10525 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010526 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010527 }
10528
10529 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
10530 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010531 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010532 }
10533
10534 if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0)
10535 {
10536 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation");
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010537 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010538 }
10539
daniel@transgaming.com9d788502011-11-09 17:46:55 +000010540 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010541
10542 if (context)
10543 {
10544 if (context->getReadFramebufferHandle() == context->getDrawFramebufferHandle())
10545 {
10546 ERR("Blits with the same source and destination framebuffer are not supported by this implementation.");
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010547 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010548 }
10549
10550 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask);
10551 }
10552 }
10553 catch(std::bad_alloc&)
10554 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010555 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010556 }
10557}
10558
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000010559void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
10560 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000010561{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000010562 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000010563 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000010564 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000010565 target, level, internalformat, width, height, depth, border, format, type, pixels);
10566
10567 try
10568 {
10569 UNIMPLEMENTED(); // FIXME
10570 }
10571 catch(std::bad_alloc&)
10572 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010573 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000010574 }
10575}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000010576
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010577void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
10578 GLenum *binaryFormat, void *binary)
10579{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000010580 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 +000010581 program, bufSize, length, binaryFormat, binary);
10582
10583 try
10584 {
10585 gl::Context *context = gl::getNonLostContext();
10586
10587 if (context)
10588 {
10589 gl::Program *programObject = context->getProgram(program);
10590
daniel@transgaming.com716056c2012-07-24 18:38:59 +000010591 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010592 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010593 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010594 }
10595
10596 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10597
10598 if (!programBinary)
10599 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010600 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010601 }
10602
apatrick@chromium.org90080e32012-07-09 22:15:33 +000010603 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010604 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010605 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010606 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000010607
10608 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010609 }
10610 }
10611 catch(std::bad_alloc&)
10612 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010613 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010614 }
10615}
10616
10617void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
10618 const void *binary, GLint length)
10619{
10620 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
10621 program, binaryFormat, binary, length);
10622
10623 try
10624 {
10625 gl::Context *context = gl::getNonLostContext();
10626
10627 if (context)
10628 {
10629 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
10630 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010631 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010632 }
10633
10634 gl::Program *programObject = context->getProgram(program);
10635
10636 if (!programObject)
10637 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010638 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010639 }
10640
daniel@transgaming.com95d29422012-07-24 18:36:10 +000010641 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010642 }
10643 }
10644 catch(std::bad_alloc&)
10645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010646 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010647 }
10648}
10649
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000010650void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
10651{
10652 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
10653
10654 try
10655 {
10656 gl::Context *context = gl::getNonLostContext();
10657
10658 if (context)
10659 {
10660 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
10661 {
10662 return gl::error(GL_INVALID_VALUE);
10663 }
10664
10665 if (context->getDrawFramebufferHandle() == 0)
10666 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000010667 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000010668 {
10669 return gl::error(GL_INVALID_OPERATION);
10670 }
10671
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000010672 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000010673 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000010674 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000010675 }
10676 }
10677 else
10678 {
10679 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
10680 {
10681 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
10682 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
10683 {
10684 return gl::error(GL_INVALID_OPERATION);
10685 }
10686 }
10687 }
10688
10689 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
10690
10691 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
10692 {
10693 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
10694 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000010695
10696 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
10697 {
10698 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
10699 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000010700 }
10701 }
10702 catch (std::bad_alloc&)
10703 {
10704 return gl::error(GL_OUT_OF_MEMORY);
10705 }
10706}
10707
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000010708__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
10709{
10710 struct Extension
10711 {
10712 const char *name;
10713 __eglMustCastToProperFunctionPointerType address;
10714 };
10715
10716 static const Extension glExtensions[] =
10717 {
10718 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000010719 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000010720 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000010721 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
10722 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
10723 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
10724 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
10725 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
10726 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
10727 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000010728 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000010729 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000010730 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
10731 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
10732 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
10733 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000010734 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
10735 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
10736 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
10737 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
10738 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
10739 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
10740 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000010741 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000010742 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
10743 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
10744 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010745 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
10746 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000010747
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000010748 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000010749 {
10750 if (strcmp(procname, glExtensions[ext].name) == 0)
10751 {
10752 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
10753 }
10754 }
10755
10756 return NULL;
10757}
10758
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000010759// Non-public functions used by EGL
10760
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000010761bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000010762{
10763 EVENT("(egl::Surface* surface = 0x%0.8p)",
10764 surface);
10765
10766 try
10767 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000010768 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000010769
10770 if (context)
10771 {
10772 gl::Texture2D *textureObject = context->getTexture2D();
10773
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000010774 if (textureObject->isImmutable())
10775 {
10776 return false;
10777 }
10778
jbauman@chromium.orgae345802011-03-30 22:04:25 +000010779 if (textureObject)
10780 {
10781 textureObject->bindTexImage(surface);
10782 }
10783 }
10784 }
10785 catch(std::bad_alloc&)
10786 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010787 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000010788 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000010789
10790 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000010791}
10792
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000010793}