blob: abf93b144e362064f278154940e5ee5c08b14490 [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
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +0000341 case GL_TEXTURE_2D_ARRAY:
342 {
343 if (width > (context->getMaximum2DTextureDimension() >> level) ||
344 height > (context->getMaximum2DTextureDimension() >> level) ||
345 depth > (context->getMaximum2DArrayTextureLayers() >> level))
346 {
347 return gl::error(GL_INVALID_VALUE, false);
348 }
349
350 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
351 if (texture2darray)
352 {
353 textureCompressed = texture2darray->isCompressed(level);
354 textureInternalFormat = texture2darray->getInternalFormat(level);
355 textureLevelWidth = texture2darray->getWidth(level);
356 textureLevelHeight = texture2darray->getHeight(level);
357 textureLevelDepth = texture2darray->getDepth(level);
358 texture = texture2darray;
359 }
360 }
361 break;
362
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000363 default:
364 return gl::error(GL_INVALID_ENUM, false);
365 }
366
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000367 if (!texture)
368 {
369 return gl::error(GL_INVALID_OPERATION, false);
370 }
371
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000372 if (texture->isImmutable())
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000373 {
374 return gl::error(GL_INVALID_OPERATION, false);
375 }
376
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000377 // Validate texture formats
378 GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
379 if (isCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000380 {
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000381 if (!gl::IsValidES3CompressedFormat(actualInternalFormat))
382 {
383 return gl::error(GL_INVALID_ENUM, false);
384 }
385
386 if (target == GL_TEXTURE_3D)
387 {
388 return gl::error(GL_INVALID_OPERATION, false);
389 }
390 }
391 else
392 {
393 GLenum err;
394 if (!gl::IsValidES3FormatCombination(actualInternalFormat, format, type, &err))
395 {
396 return gl::error(err, false);
397 }
398
399 if ((target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY) &&
400 (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL))
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000401 {
402 return gl::error(GL_INVALID_OPERATION, false);
403 }
404 }
405
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000406 // Validate sub image parameters
407 if (isSubImage)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000408 {
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000409 if (isCompressed != textureCompressed)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000410 {
411 return gl::error(GL_INVALID_OPERATION, false);
412 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000413
414 if (format != GL_NONE)
415 {
416 GLenum internalformat = gl::ConvertSizedInternalFormat(format, type);
417 if (internalformat != textureInternalFormat)
418 {
419 return gl::error(GL_INVALID_OPERATION, false);
420 }
421 }
422
423 if (isCompressed)
424 {
425 if ((width % 4 != 0 && width != textureLevelWidth) ||
426 (height % 4 != 0 && height != textureLevelHeight))
427 {
428 return gl::error(GL_INVALID_OPERATION, false);
429 }
430 }
431
432 if (width == 0 || height == 0 || depth == 0)
433 {
434 return false;
435 }
436
437 if (xoffset < 0 || yoffset < 0 || zoffset < 0)
438 {
439 return gl::error(GL_INVALID_VALUE, false);
440 }
441
442 if (std::numeric_limits<GLsizei>::max() - xoffset < width ||
443 std::numeric_limits<GLsizei>::max() - yoffset < height ||
444 std::numeric_limits<GLsizei>::max() - zoffset < depth)
445 {
446 return gl::error(GL_INVALID_VALUE, false);
447 }
448
449 if (xoffset + width > textureLevelWidth ||
450 yoffset + height > textureLevelHeight ||
451 zoffset + depth > textureLevelDepth)
452 {
453 return gl::error(GL_INVALID_VALUE, false);
454 }
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000455 }
456
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000457 return true;
458}
459
460bool validateCopyTexImageParameters(gl::Context *context, GLenum target, bool isCompressed, GLint level,
461 GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y,
462 GLsizei width, GLsizei height)
463{
464 if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0)
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000465 {
466 return gl::error(GL_INVALID_VALUE, false);
467 }
468
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +0000469 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
470 {
471 return gl::error(GL_INVALID_VALUE, false);
472 }
473
474 if (width == 0 || height == 0)
475 {
476 return false;
477 }
478
479 if (level > context->getMaximumTextureLevel())
480 {
481 return gl::error(GL_INVALID_VALUE, false);
482 }
483
484 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
485
486 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
487 {
488 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
489 }
490
491 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
492 {
493 return gl::error(GL_INVALID_OPERATION, false);
494 }
495
496 gl::Renderbuffer *source = framebuffer->getReadColorbuffer();
497 GLenum colorbufferFormat = source->getInternalFormat();
498 gl::Texture *texture = NULL;
499 GLenum textureFormat = GL_RGBA;
500 bool textureCompressed = false;
501 GLint textureLevelWidth = 0;
502 GLint textureLevelHeight = 0;
503 GLint textureLevelDepth = 0;
504 switch (target)
505 {
506 case GL_TEXTURE_2D:
507 {
508 gl::Texture2D *texture2d = context->getTexture2D();
509 if (texture2d)
510 {
511 textureFormat = gl::ExtractFormat(texture2d->getInternalFormat(level));
512 textureCompressed = texture2d->isCompressed(level);
513 textureLevelWidth = texture2d->getWidth(level);
514 textureLevelHeight = texture2d->getHeight(level);
515 textureLevelDepth = 1;
516 texture = texture2d;
517 }
518 }
519 break;
520
521 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
522 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
523 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
524 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
525 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
526 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
527 {
528 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
529 if (textureCube)
530 {
531 textureFormat = gl::ExtractFormat(textureCube->getInternalFormat(target, level));
532 textureCompressed = textureCube->isCompressed(target, level);
533 textureLevelWidth = textureCube->getWidth(target, level);
534 textureLevelHeight = textureCube->getHeight(target, level);
535 textureLevelDepth = 1;
536 texture = textureCube;
537 }
538 }
539 break;
540
541 case GL_TEXTURE_3D:
542 {
543 gl::Texture3D *texture3d = context->getTexture3D();
544 if (texture3d)
545 {
546 textureFormat = gl::ExtractFormat(texture3d->getInternalFormat(level));
547 textureCompressed = texture3d->isCompressed(level);
548 textureLevelWidth = texture3d->getWidth(level);
549 textureLevelHeight = texture3d->getHeight(level);
550 textureLevelDepth = texture3d->getDepth(level);
551 texture = texture3d;
552 }
553 }
554 break;
555
556 default:
557 return gl::error(GL_INVALID_ENUM, false);
558 }
559
560 if (!texture)
561 {
562 return gl::error(GL_INVALID_OPERATION, false);
563 }
564
565 if (isCompressed != textureCompressed)
566 {
567 return gl::error(GL_INVALID_OPERATION, false);
568 }
569
570 if (isCompressed)
571 {
572 if ((width % 4 != 0 && width != textureLevelWidth) ||
573 (height % 4 != 0 && height != textureLevelHeight))
574 {
575 return gl::error(GL_INVALID_OPERATION, false);
576 }
577 }
578
579 if (xoffset + width > textureLevelWidth ||
580 yoffset + height > textureLevelHeight ||
581 zoffset >= textureLevelDepth)
582 {
583 return gl::error(GL_INVALID_VALUE, false);
584 }
585
586 if (!gl::IsValidES3CopyTexImageCombination(textureFormat, colorbufferFormat))
587 {
588 return gl::error(GL_INVALID_OPERATION, false);
589 }
590
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +0000591 return true;
592}
593
daniel@transgaming.comb7915a52011-11-12 03:14:20 +0000594// check for combinations of format and type that are valid for ReadPixels
595bool validReadFormatType(GLenum format, GLenum type)
596{
597 switch (format)
598 {
599 case GL_RGBA:
600 switch (type)
601 {
602 case GL_UNSIGNED_BYTE:
603 break;
604 default:
605 return false;
606 }
607 break;
608 case GL_BGRA_EXT:
609 switch (type)
610 {
611 case GL_UNSIGNED_BYTE:
612 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
613 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
614 break;
615 default:
616 return false;
617 }
618 break;
daniel@transgaming.comb7915a52011-11-12 03:14:20 +0000619 default:
620 return false;
621 }
622 return true;
623}
624
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000625extern "C"
626{
627
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000628// OpenGL ES 2.0 functions
629
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000630void __stdcall glActiveTexture(GLenum texture)
631{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000632 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000633
634 try
635 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000636 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000637
638 if (context)
639 {
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +0000640 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
641 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000642 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f74c7a2011-05-11 15:36:51 +0000643 }
644
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000645 context->setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000646 }
647 }
648 catch(std::bad_alloc&)
649 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000650 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000651 }
652}
653
654void __stdcall glAttachShader(GLuint program, GLuint shader)
655{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000656 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000657
658 try
659 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000660 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000661
662 if (context)
663 {
664 gl::Program *programObject = context->getProgram(program);
665 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +0000666
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +0000667 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000668 {
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +0000669 if (context->getShader(program))
670 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000671 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +0000672 }
673 else
674 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000675 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +0000676 }
677 }
678
679 if (!shaderObject)
680 {
681 if (context->getProgram(shader))
682 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000683 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +0000684 }
685 else
686 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000687 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come9d6ed02010-04-13 03:26:23 +0000688 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000689 }
690
691 if (!programObject->attachShader(shaderObject))
692 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000693 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000694 }
695 }
696 }
697 catch(std::bad_alloc&)
698 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000699 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000700 }
701}
702
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000703void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
704{
705 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
706
707 try
708 {
709 switch (target)
710 {
711 case GL_ANY_SAMPLES_PASSED_EXT:
712 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
713 break;
714 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000715 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000716 }
717
718 if (id == 0)
719 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000720 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000721 }
722
723 gl::Context *context = gl::getNonLostContext();
724
725 if (context)
726 {
727 context->beginQuery(target, id);
728 }
729 }
730 catch(std::bad_alloc&)
731 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000732 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000733 }
734}
735
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000736void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000737{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000738 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000739
740 try
741 {
742 if (index >= gl::MAX_VERTEX_ATTRIBS)
743 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000744 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000745 }
746
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000747 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000748
749 if (context)
750 {
751 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +0000752
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000753 if (!programObject)
754 {
daniel@transgaming.com98079832010-04-13 03:26:29 +0000755 if (context->getShader(program))
756 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000757 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com98079832010-04-13 03:26:29 +0000758 }
759 else
760 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000761 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com98079832010-04-13 03:26:29 +0000762 }
763 }
764
765 if (strncmp(name, "gl_", 3) == 0)
766 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000767 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000768 }
769
770 programObject->bindAttributeLocation(index, name);
771 }
772 }
773 catch(std::bad_alloc&)
774 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000775 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000776 }
777}
778
779void __stdcall glBindBuffer(GLenum target, GLuint buffer)
780{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000781 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000782
783 try
784 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000785 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000786
787 if (context)
788 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000789 // Check ES3 specific targets
790 switch (target)
791 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000792 case GL_COPY_READ_BUFFER:
793 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +0000794 case GL_PIXEL_PACK_BUFFER:
795 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000796 case GL_UNIFORM_BUFFER:
797 case GL_TRANSFORM_FEEDBACK_BUFFER:
798 if (context->getClientVersion() < 3)
799 {
800 return gl::error(GL_INVALID_ENUM);
801 }
802 }
803
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000804 switch (target)
805 {
806 case GL_ARRAY_BUFFER:
807 context->bindArrayBuffer(buffer);
808 return;
809 case GL_ELEMENT_ARRAY_BUFFER:
810 context->bindElementArrayBuffer(buffer);
811 return;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000812 case GL_COPY_READ_BUFFER:
813 context->bindCopyReadBuffer(buffer);
814 return;
815 case GL_COPY_WRITE_BUFFER:
816 context->bindCopyWriteBuffer(buffer);
817 return;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +0000818 case GL_PIXEL_PACK_BUFFER:
819 context->bindPixelPackBuffer(buffer);
820 return;
821 case GL_PIXEL_UNPACK_BUFFER:
822 context->bindPixelUnpackBuffer(buffer);
823 return;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000824 case GL_UNIFORM_BUFFER:
825 context->bindGenericUniformBuffer(buffer);
826 return;
827 case GL_TRANSFORM_FEEDBACK_BUFFER:
828 context->bindGenericUniformBuffer(buffer);
829 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000830 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000831 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000832 }
833 }
834 }
835 catch(std::bad_alloc&)
836 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000837 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000838 }
839}
840
841void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
842{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000843 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000844
845 try
846 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000847 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000848 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000849 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000850 }
851
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000852 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000853
854 if (context)
855 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +0000856 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
857 {
858 context->bindReadFramebuffer(framebuffer);
859 }
860
861 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
862 {
863 context->bindDrawFramebuffer(framebuffer);
864 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000865 }
866 }
867 catch(std::bad_alloc&)
868 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000869 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000870 }
871}
872
873void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
874{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000875 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000876
877 try
878 {
879 if (target != GL_RENDERBUFFER)
880 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000881 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000882 }
883
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000884 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000885
886 if (context)
887 {
888 context->bindRenderbuffer(renderbuffer);
889 }
890 }
891 catch(std::bad_alloc&)
892 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000893 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000894 }
895}
896
897void __stdcall glBindTexture(GLenum target, GLuint texture)
898{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000899 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000900
901 try
902 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000903 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000904
905 if (context)
906 {
907 gl::Texture *textureObject = context->getTexture(texture);
908
909 if (textureObject && textureObject->getTarget() != target && texture != 0)
910 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000911 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000912 }
913
914 switch (target)
915 {
916 case GL_TEXTURE_2D:
917 context->bindTexture2D(texture);
918 return;
919 case GL_TEXTURE_CUBE_MAP:
920 context->bindTextureCubeMap(texture);
921 return;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +0000922 case GL_TEXTURE_3D:
923 if (context->getClientVersion() < 3)
924 {
925 return gl::error(GL_INVALID_ENUM);
926 }
927 context->bindTexture3D(texture);
928 return;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000929 case GL_TEXTURE_2D_ARRAY:
930 if (context->getClientVersion() < 3)
931 {
932 return gl::error(GL_INVALID_ENUM);
933 }
934 context->bindTexture2DArray(texture);
935 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000936 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000937 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000938 }
939 }
940 }
941 catch(std::bad_alloc&)
942 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000943 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000944 }
945}
946
947void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
948{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000949 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000950 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000951
952 try
953 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +0000954 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000955
956 if (context)
957 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +0000958 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000959 }
960 }
961 catch(std::bad_alloc&)
962 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000963 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000964 }
965}
966
967void __stdcall glBlendEquation(GLenum mode)
968{
969 glBlendEquationSeparate(mode, mode);
970}
971
972void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
973{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000974 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000975
976 try
977 {
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +0000978 gl::Context *context = gl::getNonLostContext();
979
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000980 switch (modeRGB)
981 {
982 case GL_FUNC_ADD:
983 case GL_FUNC_SUBTRACT:
984 case GL_FUNC_REVERSE_SUBTRACT:
985 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +0000986
987 case GL_MIN:
988 case GL_MAX:
989 if (context && context->getClientVersion() < 3)
990 {
991 return gl::error(GL_INVALID_ENUM);
992 }
993 break;
994
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000995 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +0000996 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000997 }
998
999 switch (modeAlpha)
1000 {
1001 case GL_FUNC_ADD:
1002 case GL_FUNC_SUBTRACT:
1003 case GL_FUNC_REVERSE_SUBTRACT:
1004 break;
shannon.woods%transgaming.com@gtempaccount.com00b6a0e2013-04-13 03:38:00 +00001005
1006 case GL_MIN:
1007 case GL_MAX:
1008 if (context && context->getClientVersion() < 3)
1009 {
1010 return gl::error(GL_INVALID_ENUM);
1011 }
1012 break;
1013
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001014 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001015 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001016 }
1017
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001018 if (context)
1019 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00001020 context->setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001021 }
1022 }
1023 catch(std::bad_alloc&)
1024 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001025 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001026 }
1027}
1028
1029void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
1030{
1031 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
1032}
1033
1034void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
1035{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001036 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 +00001037 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001038
1039 try
1040 {
1041 switch (srcRGB)
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 case GL_SRC_ALPHA_SATURATE:
1058 break;
1059 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001060 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001061 }
1062
1063 switch (dstRGB)
1064 {
1065 case GL_ZERO:
1066 case GL_ONE:
1067 case GL_SRC_COLOR:
1068 case GL_ONE_MINUS_SRC_COLOR:
1069 case GL_DST_COLOR:
1070 case GL_ONE_MINUS_DST_COLOR:
1071 case GL_SRC_ALPHA:
1072 case GL_ONE_MINUS_SRC_ALPHA:
1073 case GL_DST_ALPHA:
1074 case GL_ONE_MINUS_DST_ALPHA:
1075 case GL_CONSTANT_COLOR:
1076 case GL_ONE_MINUS_CONSTANT_COLOR:
1077 case GL_CONSTANT_ALPHA:
1078 case GL_ONE_MINUS_CONSTANT_ALPHA:
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 (srcAlpha)
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 case GL_SRC_ALPHA_SATURATE:
1101 break;
1102 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001103 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001104 }
1105
1106 switch (dstAlpha)
1107 {
1108 case GL_ZERO:
1109 case GL_ONE:
1110 case GL_SRC_COLOR:
1111 case GL_ONE_MINUS_SRC_COLOR:
1112 case GL_DST_COLOR:
1113 case GL_ONE_MINUS_DST_COLOR:
1114 case GL_SRC_ALPHA:
1115 case GL_ONE_MINUS_SRC_ALPHA:
1116 case GL_DST_ALPHA:
1117 case GL_ONE_MINUS_DST_ALPHA:
1118 case GL_CONSTANT_COLOR:
1119 case GL_ONE_MINUS_CONSTANT_COLOR:
1120 case GL_CONSTANT_ALPHA:
1121 case GL_ONE_MINUS_CONSTANT_ALPHA:
1122 break;
1123 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001124 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001125 }
1126
daniel@transgaming.comfe453652010-03-16 06:23:28 +00001127 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
1128 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
1129
1130 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
1131 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
1132
1133 if (constantColorUsed && constantAlphaUsed)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001134 {
daniel@transgaming.comfe453652010-03-16 06:23:28 +00001135 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 +00001136 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001137 }
1138
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001139 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001140
1141 if (context)
1142 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00001143 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001144 }
1145 }
1146 catch(std::bad_alloc&)
1147 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001148 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001149 }
1150}
1151
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001152void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001153{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001154 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 +00001155 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001156
1157 try
1158 {
1159 if (size < 0)
1160 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001161 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001162 }
1163
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00001164 gl::Context *context = gl::getNonLostContext();
1165
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001166 switch (usage)
1167 {
1168 case GL_STREAM_DRAW:
1169 case GL_STATIC_DRAW:
1170 case GL_DYNAMIC_DRAW:
1171 break;
shannon.woods%transgaming.com@gtempaccount.comf2db40b2013-04-13 03:37:09 +00001172
1173 case GL_STREAM_READ:
1174 case GL_STREAM_COPY:
1175 case GL_STATIC_READ:
1176 case GL_STATIC_COPY:
1177 case GL_DYNAMIC_READ:
1178 case GL_DYNAMIC_COPY:
1179 if (context && context->getClientVersion() < 3)
1180 {
1181 return gl::error(GL_INVALID_ENUM);
1182 }
1183 break;
1184
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001185 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001186 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001187 }
1188
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001189 if (context)
1190 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001191 // Check ES3 specific targets
1192 switch (target)
1193 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001194 case GL_COPY_READ_BUFFER:
1195 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001196 case GL_PIXEL_PACK_BUFFER:
1197 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001198 case GL_UNIFORM_BUFFER:
1199 case GL_TRANSFORM_FEEDBACK_BUFFER:
1200 if (context->getClientVersion() < 3)
1201 {
1202 return gl::error(GL_INVALID_ENUM);
1203 }
1204 }
1205
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001206 gl::Buffer *buffer;
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00001207
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001208 switch (target)
1209 {
1210 case GL_ARRAY_BUFFER:
1211 buffer = context->getArrayBuffer();
1212 break;
1213 case GL_ELEMENT_ARRAY_BUFFER:
1214 buffer = context->getElementArrayBuffer();
1215 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001216 case GL_COPY_READ_BUFFER:
1217 buffer = context->getCopyReadBuffer();
1218 break;
1219 case GL_COPY_WRITE_BUFFER:
1220 buffer = context->getCopyWriteBuffer();
1221 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001222 case GL_PIXEL_PACK_BUFFER:
1223 buffer = context->getPixelPackBuffer();
1224 break;
1225 case GL_PIXEL_UNPACK_BUFFER:
1226 buffer = context->getPixelUnpackBuffer();
1227 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001228 case GL_TRANSFORM_FEEDBACK_BUFFER:
1229 buffer = context->getGenericTransformFeedbackBuffer();
1230 break;
1231 case GL_UNIFORM_BUFFER:
1232 buffer = context->getGenericUniformBuffer();
1233 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001234 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001235 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001236 }
1237
1238 if (!buffer)
1239 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001240 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001241 }
1242
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001243 buffer->bufferData(data, size, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001244 }
1245 }
1246 catch(std::bad_alloc&)
1247 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001248 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001249 }
1250}
1251
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001252void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001253{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001254 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 +00001255 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001256
1257 try
1258 {
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00001259 if (size < 0 || offset < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001260 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001261 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001262 }
1263
daniel@transgaming.comd4620a32010-03-21 04:31:28 +00001264 if (data == NULL)
1265 {
1266 return;
1267 }
1268
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001269 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001270
1271 if (context)
1272 {
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001273 // Check ES3 specific targets
1274 switch (target)
1275 {
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001276 case GL_COPY_READ_BUFFER:
1277 case GL_COPY_WRITE_BUFFER:
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001278 case GL_PIXEL_PACK_BUFFER:
1279 case GL_PIXEL_UNPACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001280 case GL_UNIFORM_BUFFER:
1281 case GL_TRANSFORM_FEEDBACK_BUFFER:
1282 if (context->getClientVersion() < 3)
1283 {
1284 return gl::error(GL_INVALID_ENUM);
1285 }
1286 }
1287
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001288 gl::Buffer *buffer;
1289
1290 switch (target)
1291 {
1292 case GL_ARRAY_BUFFER:
1293 buffer = context->getArrayBuffer();
1294 break;
1295 case GL_ELEMENT_ARRAY_BUFFER:
1296 buffer = context->getElementArrayBuffer();
1297 break;
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001298 case GL_COPY_READ_BUFFER:
1299 buffer = context->getCopyReadBuffer();
1300 break;
1301 case GL_COPY_WRITE_BUFFER:
1302 buffer = context->getCopyWriteBuffer();
1303 break;
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001304 case GL_PIXEL_PACK_BUFFER:
1305 buffer = context->getPixelPackBuffer();
1306 break;
1307 case GL_PIXEL_UNPACK_BUFFER:
1308 buffer = context->getPixelUnpackBuffer();
1309 break;
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001310 case GL_TRANSFORM_FEEDBACK_BUFFER:
1311 buffer = context->getGenericTransformFeedbackBuffer();
1312 break;
1313 case GL_UNIFORM_BUFFER:
1314 buffer = context->getGenericUniformBuffer();
1315 break;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001316 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001317 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001318 }
1319
1320 if (!buffer)
1321 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001322 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001323 }
1324
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00001325 if ((size_t)size + offset > buffer->size())
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001326 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001327 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001328 }
daniel@transgaming.comdefa1c32010-05-18 18:51:45 +00001329
1330 buffer->bufferSubData(data, size, offset);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001331 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001332 }
1333 catch(std::bad_alloc&)
1334 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001335 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001336 }
1337}
1338
1339GLenum __stdcall glCheckFramebufferStatus(GLenum target)
1340{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001341 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001342
1343 try
1344 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00001345 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001346 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001347 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001348 }
1349
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001350 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001351
1352 if (context)
1353 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00001354 gl::Framebuffer *framebuffer = NULL;
1355 if (target == GL_READ_FRAMEBUFFER_ANGLE)
1356 {
1357 framebuffer = context->getReadFramebuffer();
1358 }
1359 else
1360 {
1361 framebuffer = context->getDrawFramebuffer();
1362 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001363
1364 return framebuffer->completeness();
1365 }
1366 }
1367 catch(std::bad_alloc&)
1368 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001369 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001370 }
1371
1372 return 0;
1373}
1374
1375void __stdcall glClear(GLbitfield mask)
1376{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001377 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001378
1379 try
1380 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001381 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001382
1383 if (context)
1384 {
1385 context->clear(mask);
1386 }
1387 }
1388 catch(std::bad_alloc&)
1389 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001390 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001391 }
1392}
1393
1394void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
1395{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001396 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001397 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001398
1399 try
1400 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001401 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001402
1403 if (context)
1404 {
1405 context->setClearColor(red, green, blue, alpha);
1406 }
1407 }
1408 catch(std::bad_alloc&)
1409 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001410 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001411 }
1412}
1413
1414void __stdcall glClearDepthf(GLclampf depth)
1415{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001416 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001417
1418 try
1419 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001420 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001421
1422 if (context)
1423 {
1424 context->setClearDepth(depth);
1425 }
1426 }
1427 catch(std::bad_alloc&)
1428 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001429 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001430 }
1431}
1432
1433void __stdcall glClearStencil(GLint s)
1434{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001435 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001436
1437 try
1438 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001439 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001440
1441 if (context)
1442 {
1443 context->setClearStencil(s);
1444 }
1445 }
1446 catch(std::bad_alloc&)
1447 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001448 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001449 }
1450}
1451
1452void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
1453{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001454 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001455 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001456
1457 try
1458 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001459 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001460
1461 if (context)
1462 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00001463 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001464 }
1465 }
1466 catch(std::bad_alloc&)
1467 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001468 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001469 }
1470}
1471
1472void __stdcall glCompileShader(GLuint shader)
1473{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001474 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001475
1476 try
1477 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001478 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001479
1480 if (context)
1481 {
1482 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00001483
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001484 if (!shaderObject)
1485 {
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00001486 if (context->getProgram(shader))
1487 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001488 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00001489 }
1490 else
1491 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001492 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com0cefaf42010-04-13 03:26:36 +00001493 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001494 }
1495
1496 shaderObject->compile();
1497 }
1498 }
1499 catch(std::bad_alloc&)
1500 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001501 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001502 }
1503}
1504
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001505void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
1506 GLint border, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001507{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001508 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001509 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001510 target, level, internalformat, width, height, border, imageSize, data);
1511
1512 try
1513 {
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001514 if (!validImageSize(level, width, height, 1) || border != 0 || imageSize < 0)
daniel@transgaming.com41430492010-03-11 20:36:18 +00001515 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001516 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com41430492010-03-11 20:36:18 +00001517 }
1518
daniel@transgaming.com01868132010-08-24 19:21:17 +00001519 switch (internalformat)
1520 {
1521 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1522 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
gman@chromium.org50c526d2011-08-10 05:19:44 +00001523 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1524 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
daniel@transgaming.com01868132010-08-24 19:21:17 +00001525 break;
1526 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001527 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001528 }
1529
1530 if (border != 0)
1531 {
shannon.woods@transgaming.com0efef902013-02-28 23:21:09 +00001532 return gl::error(GL_INVALID_OPERATION);
1533 }
1534
1535 if (width != 1 && width != 2 && width % 4 != 0)
1536 {
1537 return gl::error(GL_INVALID_OPERATION);
1538 }
1539
1540 if (height != 1 && height != 2 && height % 4 != 0)
1541 {
1542 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001543 }
1544
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001545 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00001546
1547 if (context)
1548 {
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001549 if (level > context->getMaximumTextureLevel())
1550 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001551 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001552 }
1553
1554 switch (target)
1555 {
1556 case GL_TEXTURE_2D:
shannon.woods%transgaming.com@gtempaccount.comc1fdf6b2013-04-13 03:44:41 +00001557 if (width > (context->getMaximum2DTextureDimension() >> level) ||
1558 height > (context->getMaximum2DTextureDimension() >> level))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001559 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001560 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001561 }
1562 break;
1563 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1564 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1565 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1566 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1567 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1568 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1569 if (width != height)
1570 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001571 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001572 }
1573
1574 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
1575 height > (context->getMaximumCubeTextureDimension() >> level))
1576 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001577 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001578 }
1579 break;
1580 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001581 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001582 }
1583
gman@chromium.org50c526d2011-08-10 05:19:44 +00001584 switch (internalformat) {
1585 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1586 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1587 if (!context->supportsDXT1Textures())
1588 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001589 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 +00001590 }
1591 break;
1592 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1593 if (!context->supportsDXT3Textures())
1594 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001595 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 +00001596 }
1597 break;
1598 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1599 if (!context->supportsDXT5Textures())
1600 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001601 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 +00001602 }
1603 break;
1604 default: UNREACHABLE();
daniel@transgaming.com01868132010-08-24 19:21:17 +00001605 }
1606
1607 if (imageSize != gl::ComputeCompressedSize(width, height, internalformat))
1608 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001609 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001610 }
1611
1612 if (target == GL_TEXTURE_2D)
1613 {
1614 gl::Texture2D *texture = context->getTexture2D();
1615
1616 if (!texture)
1617 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001618 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001619 }
1620
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001621 if (texture->isImmutable())
1622 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001623 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001624 }
1625
daniel@transgaming.com01868132010-08-24 19:21:17 +00001626 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
1627 }
1628 else
1629 {
1630 gl::TextureCubeMap *texture = context->getTextureCubeMap();
1631
1632 if (!texture)
1633 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001634 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001635 }
1636
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001637 if (texture->isImmutable())
1638 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001639 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001640 }
1641
daniel@transgaming.com01868132010-08-24 19:21:17 +00001642 switch (target)
1643 {
1644 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1645 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1646 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1647 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1648 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1649 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1650 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
1651 break;
1652 default: UNREACHABLE();
1653 }
1654 }
1655 }
1656
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001657 }
1658 catch(std::bad_alloc&)
1659 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001660 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001661 }
1662}
1663
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001664void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
1665 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001666{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001667 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001668 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001669 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001670 target, level, xoffset, yoffset, width, height, format, imageSize, data);
1671
1672 try
1673 {
apatrick@chromium.org551022e2012-01-23 19:56:54 +00001674 if (!gl::IsInternalTextureTarget(target))
daniel@transgaming.com41430492010-03-11 20:36:18 +00001675 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001676 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com41430492010-03-11 20:36:18 +00001677 }
1678
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001679 if (xoffset < 0 || yoffset < 0 || !validImageSize(level, width, height, 1) || imageSize < 0)
daniel@transgaming.com41430492010-03-11 20:36:18 +00001680 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001681 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com41430492010-03-11 20:36:18 +00001682 }
1683
daniel@transgaming.com01868132010-08-24 19:21:17 +00001684 switch (format)
daniel@transgaming.com41430492010-03-11 20:36:18 +00001685 {
daniel@transgaming.com01868132010-08-24 19:21:17 +00001686 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1687 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
gman@chromium.org50c526d2011-08-10 05:19:44 +00001688 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1689 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
daniel@transgaming.com01868132010-08-24 19:21:17 +00001690 break;
1691 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001692 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com41430492010-03-11 20:36:18 +00001693 }
1694
daniel@transgaming.com01868132010-08-24 19:21:17 +00001695 if (width == 0 || height == 0 || data == NULL)
1696 {
1697 return;
1698 }
1699
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001700 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com01868132010-08-24 19:21:17 +00001701
1702 if (context)
1703 {
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001704 if (level > context->getMaximumTextureLevel())
1705 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001706 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001707 }
1708
gman@chromium.org50c526d2011-08-10 05:19:44 +00001709 switch (format) {
1710 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1711 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1712 if (!context->supportsDXT1Textures())
1713 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001714 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 +00001715 }
1716 break;
1717 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1718 if (!context->supportsDXT3Textures())
1719 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001720 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 +00001721 }
1722 break;
1723 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1724 if (!context->supportsDXT5Textures())
1725 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001726 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 +00001727 }
1728 break;
1729 default: UNREACHABLE();
daniel@transgaming.com01868132010-08-24 19:21:17 +00001730 }
1731
1732 if (imageSize != gl::ComputeCompressedSize(width, height, format))
1733 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001734 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001735 }
1736
1737 if (xoffset % 4 != 0 || yoffset % 4 != 0)
1738 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001739 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 +00001740 // does not exist unless DXT textures are supported.
daniel@transgaming.com01868132010-08-24 19:21:17 +00001741 }
1742
1743 if (target == GL_TEXTURE_2D)
1744 {
1745 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00001746 if (validateSubImageParams2D(true, width, height, xoffset, yoffset, level, format, GL_NONE, texture))
daniel@transgaming.com01868132010-08-24 19:21:17 +00001747 {
daniel@transgaming.com343373a2011-11-29 19:42:32 +00001748 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001749 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00001750 }
1751 else if (gl::IsCubemapTextureTarget(target))
1752 {
1753 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00001754 if (validateSubImageParamsCube(true, width, height, xoffset, yoffset, target, level, format, GL_NONE, texture))
daniel@transgaming.com01868132010-08-24 19:21:17 +00001755 {
daniel@transgaming.com343373a2011-11-29 19:42:32 +00001756 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
daniel@transgaming.com01868132010-08-24 19:21:17 +00001757 }
daniel@transgaming.com01868132010-08-24 19:21:17 +00001758 }
1759 else
1760 {
1761 UNREACHABLE();
1762 }
1763 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001764 }
1765 catch(std::bad_alloc&)
1766 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001767 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001768 }
1769}
1770
1771void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
1772{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001773 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001774 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001775 target, level, internalformat, x, y, width, height, border);
1776
1777 try
1778 {
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00001779 if (!validImageSize(level, width, height, 1))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001780 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001781 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001782 }
1783
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001784 if (border != 0)
1785 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001786 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001787 }
1788
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001789 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001790
1791 if (context)
1792 {
daniel@transgaming.com32b11442011-11-19 02:42:48 +00001793 if (level > context->getMaximumTextureLevel())
1794 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001795 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com32b11442011-11-19 02:42:48 +00001796 }
1797
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001798 switch (target)
1799 {
1800 case GL_TEXTURE_2D:
shannon.woods%transgaming.com@gtempaccount.comc1fdf6b2013-04-13 03:44:41 +00001801 if (width > (context->getMaximum2DTextureDimension() >> level) ||
1802 height > (context->getMaximum2DTextureDimension() >> level))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001803 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001804 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001805 }
1806 break;
1807 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1808 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1809 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1810 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1811 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1812 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1813 if (width != height)
1814 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001815 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001816 }
1817
1818 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
1819 height > (context->getMaximumCubeTextureDimension() >> level))
1820 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001821 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001822 }
1823 break;
1824 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001825 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001826 }
1827
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00001828 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001829
daniel@transgaming.combbc57792010-07-28 19:21:05 +00001830 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1831 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001832 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION);
daniel@transgaming.combbc57792010-07-28 19:21:05 +00001833 }
1834
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001835 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00001836 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001837 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00001838 }
1839
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001840 gl::Renderbuffer *source = framebuffer->getReadColorbuffer();
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00001841 GLenum colorbufferFormat = source->getInternalFormat();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001842
1843 // [OpenGL ES 2.0.24] table 3.9
1844 switch (internalformat)
1845 {
1846 case GL_ALPHA:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00001847 if (colorbufferFormat != GL_ALPHA8_EXT &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001848 colorbufferFormat != GL_RGBA4 &&
1849 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_LUMINANCE:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00001857 case GL_RGB:
1858 if (colorbufferFormat != GL_RGB565 &&
1859 colorbufferFormat != GL_RGB8_OES &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001860 colorbufferFormat != GL_RGBA4 &&
1861 colorbufferFormat != GL_RGB5_A1 &&
shannon.woods@transgaming.com28e7ba02013-02-28 23:09:28 +00001862 colorbufferFormat != GL_BGRA8_EXT &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001863 colorbufferFormat != GL_RGBA8_OES)
1864 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001865 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001866 }
1867 break;
1868 case GL_LUMINANCE_ALPHA:
1869 case GL_RGBA:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00001870 if (colorbufferFormat != GL_RGBA4 &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001871 colorbufferFormat != GL_RGB5_A1 &&
shannon.woods@transgaming.com28e7ba02013-02-28 23:09:28 +00001872 colorbufferFormat != GL_BGRA8_EXT &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001873 colorbufferFormat != GL_RGBA8_OES)
1874 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001875 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001876 }
1877 break;
1878 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1879 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
gman@chromium.org50c526d2011-08-10 05:19:44 +00001880 if (context->supportsDXT1Textures())
1881 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001882 return gl::error(GL_INVALID_OPERATION);
gman@chromium.org50c526d2011-08-10 05:19:44 +00001883 }
1884 else
1885 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001886 return gl::error(GL_INVALID_ENUM);
gman@chromium.org50c526d2011-08-10 05:19:44 +00001887 }
1888 break;
1889 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1890 if (context->supportsDXT3Textures())
1891 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001892 return gl::error(GL_INVALID_OPERATION);
gman@chromium.org50c526d2011-08-10 05:19:44 +00001893 }
1894 else
1895 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001896 return gl::error(GL_INVALID_ENUM);
gman@chromium.org50c526d2011-08-10 05:19:44 +00001897 }
1898 break;
1899 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1900 if (context->supportsDXT5Textures())
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001901 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001902 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001903 }
1904 else
1905 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001906 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001907 }
1908 break;
daniel@transgaming.com0c854682012-05-31 01:14:11 +00001909 case GL_DEPTH_COMPONENT:
1910 case GL_DEPTH_COMPONENT16:
1911 case GL_DEPTH_COMPONENT32_OES:
1912 case GL_DEPTH_STENCIL_OES:
1913 case GL_DEPTH24_STENCIL8_OES:
1914 if (context->supportsDepthTextures())
1915 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001916 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00001917 }
1918 else
1919 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001920 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00001921 }
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001922 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001923 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001924 }
1925
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001926 if (target == GL_TEXTURE_2D)
1927 {
1928 gl::Texture2D *texture = context->getTexture2D();
1929
1930 if (!texture)
1931 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001932 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001933 }
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00001934
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001935 if (texture->isImmutable())
1936 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001937 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001938 }
1939
apatrick@chromium.orgb31f5322011-01-19 19:02:52 +00001940 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001941 }
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00001942 else if (gl::IsCubemapTextureTarget(target))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001943 {
1944 gl::TextureCubeMap *texture = context->getTextureCubeMap();
1945
1946 if (!texture)
1947 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001948 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001949 }
1950
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001951 if (texture->isImmutable())
1952 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001953 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00001954 }
1955
apatrick@chromium.orgb31f5322011-01-19 19:02:52 +00001956 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001957 }
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00001958 else UNREACHABLE();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001959 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001960 }
1961 catch(std::bad_alloc&)
1962 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001963 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001964 }
1965}
1966
1967void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
1968{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001969 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001970 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001971 target, level, xoffset, yoffset, x, y, width, height);
1972
1973 try
1974 {
apatrick@chromium.org551022e2012-01-23 19:56:54 +00001975 if (!gl::IsInternalTextureTarget(target))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001976 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001977 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001978 }
1979
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001980 if (level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001981 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001982 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001983 }
1984
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001985 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
1986 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00001987 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001988 }
1989
1990 if (width == 0 || height == 0)
1991 {
1992 return;
1993 }
1994
daniel@transgaming.com9d788502011-11-09 17:46:55 +00001995 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00001996
1997 if (context)
1998 {
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00001999 if (level > context->getMaximumTextureLevel())
2000 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002001 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00002002 }
2003
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002004 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002005
daniel@transgaming.combbc57792010-07-28 19:21:05 +00002006 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
2007 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002008 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION);
daniel@transgaming.combbc57792010-07-28 19:21:05 +00002009 }
2010
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002011 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00002012 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002013 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00002014 }
2015
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002016 gl::Renderbuffer *source = framebuffer->getReadColorbuffer();
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00002017 GLenum colorbufferFormat = source->getInternalFormat();
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002018 gl::Texture *texture = NULL;
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002019 GLenum textureFormat = GL_RGBA;
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002020
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002021 if (target == GL_TEXTURE_2D)
2022 {
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002023 gl::Texture2D *tex2d = context->getTexture2D();
2024
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002025 if (!validateSubImageParams2D(false, width, height, xoffset, yoffset, level, GL_NONE, GL_NONE, tex2d))
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002026 {
2027 return; // error already registered by validateSubImageParams
2028 }
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002029 textureFormat = gl::ExtractFormat(tex2d->getInternalFormat(level));
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002030 texture = tex2d;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002031 }
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00002032 else if (gl::IsCubemapTextureTarget(target))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002033 {
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002034 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
2035
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002036 if (!validateSubImageParamsCube(false, width, height, xoffset, yoffset, target, level, GL_NONE, GL_NONE, texcube))
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002037 {
2038 return; // error already registered by validateSubImageParams
2039 }
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002040 textureFormat = gl::ExtractFormat(texcube->getInternalFormat(target, level));
daniel@transgaming.com2ccbbef2012-05-09 15:49:00 +00002041 texture = texcube;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002042 }
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002043 else UNREACHABLE();
2044
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002045 // [OpenGL ES 2.0.24] table 3.9
2046 switch (textureFormat)
2047 {
2048 case GL_ALPHA:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002049 if (colorbufferFormat != GL_ALPHA8_EXT &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002050 colorbufferFormat != GL_RGBA4 &&
2051 colorbufferFormat != GL_RGB5_A1 &&
2052 colorbufferFormat != GL_RGBA8_OES)
2053 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002054 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002055 }
2056 break;
2057 case GL_LUMINANCE:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002058 case GL_RGB:
2059 if (colorbufferFormat != GL_RGB565 &&
2060 colorbufferFormat != GL_RGB8_OES &&
2061 colorbufferFormat != GL_RGBA4 &&
2062 colorbufferFormat != GL_RGB5_A1 &&
2063 colorbufferFormat != GL_RGBA8_OES)
2064 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002065 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002066 }
2067 break;
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002068 case GL_LUMINANCE_ALPHA:
2069 case GL_RGBA:
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00002070 if (colorbufferFormat != GL_RGBA4 &&
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002071 colorbufferFormat != GL_RGB5_A1 &&
2072 colorbufferFormat != GL_RGBA8_OES)
2073 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002074 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002075 }
2076 break;
2077 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
2078 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
gman@chromium.org50c526d2011-08-10 05:19:44 +00002079 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
2080 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002081 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00002082 case GL_DEPTH_COMPONENT:
2083 case GL_DEPTH_STENCIL_OES:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002084 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002085 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002086 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com3f85fbb2010-10-15 17:58:05 +00002087 }
2088
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +00002089 texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002090 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002091 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +00002092
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002093 catch(std::bad_alloc&)
2094 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002095 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002096 }
2097}
2098
2099GLuint __stdcall glCreateProgram(void)
2100{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002101 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002102
2103 try
2104 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002105 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002106
2107 if (context)
2108 {
2109 return context->createProgram();
2110 }
2111 }
2112 catch(std::bad_alloc&)
2113 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002114 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002115 }
2116
2117 return 0;
2118}
2119
2120GLuint __stdcall glCreateShader(GLenum type)
2121{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002122 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002123
2124 try
2125 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002126 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002127
2128 if (context)
2129 {
2130 switch (type)
2131 {
2132 case GL_FRAGMENT_SHADER:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00002133 case GL_VERTEX_SHADER:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002134 return context->createShader(type);
2135 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002136 return gl::error(GL_INVALID_ENUM, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002137 }
2138 }
2139 }
2140 catch(std::bad_alloc&)
2141 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002142 return gl::error(GL_OUT_OF_MEMORY, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002143 }
2144
2145 return 0;
2146}
2147
2148void __stdcall glCullFace(GLenum mode)
2149{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002150 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002151
2152 try
2153 {
2154 switch (mode)
2155 {
2156 case GL_FRONT:
2157 case GL_BACK:
2158 case GL_FRONT_AND_BACK:
2159 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002160 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002161
2162 if (context)
2163 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002164 context->setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002165 }
2166 }
2167 break;
2168 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002169 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002170 }
2171 }
2172 catch(std::bad_alloc&)
2173 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002174 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002175 }
2176}
2177
2178void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
2179{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002180 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002181
2182 try
2183 {
2184 if (n < 0)
2185 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002186 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002187 }
2188
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002189 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002190
2191 if (context)
2192 {
2193 for (int i = 0; i < n; i++)
2194 {
2195 context->deleteBuffer(buffers[i]);
2196 }
2197 }
2198 }
2199 catch(std::bad_alloc&)
2200 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002201 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002202 }
2203}
2204
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002205void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
2206{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002207 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002208
2209 try
2210 {
2211 if (n < 0)
2212 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002213 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002214 }
2215
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002216 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002217
2218 if (context)
2219 {
2220 for (int i = 0; i < n; i++)
2221 {
2222 context->deleteFence(fences[i]);
2223 }
2224 }
2225 }
2226 catch(std::bad_alloc&)
2227 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002228 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002229 }
2230}
2231
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002232void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
2233{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002234 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002235
2236 try
2237 {
2238 if (n < 0)
2239 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002240 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002241 }
2242
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002243 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002244
2245 if (context)
2246 {
2247 for (int i = 0; i < n; i++)
2248 {
2249 if (framebuffers[i] != 0)
2250 {
2251 context->deleteFramebuffer(framebuffers[i]);
2252 }
2253 }
2254 }
2255 }
2256 catch(std::bad_alloc&)
2257 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002258 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002259 }
2260}
2261
2262void __stdcall glDeleteProgram(GLuint program)
2263{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002264 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002265
2266 try
2267 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002268 if (program == 0)
2269 {
2270 return;
2271 }
2272
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002273 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002274
2275 if (context)
2276 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002277 if (!context->getProgram(program))
2278 {
2279 if(context->getShader(program))
2280 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002281 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002282 }
2283 else
2284 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002285 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002286 }
2287 }
2288
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002289 context->deleteProgram(program);
2290 }
2291 }
2292 catch(std::bad_alloc&)
2293 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002294 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002295 }
2296}
2297
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002298void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
2299{
2300 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
2301
2302 try
2303 {
2304 if (n < 0)
2305 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002306 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002307 }
2308
2309 gl::Context *context = gl::getNonLostContext();
2310
2311 if (context)
2312 {
2313 for (int i = 0; i < n; i++)
2314 {
2315 context->deleteQuery(ids[i]);
2316 }
2317 }
2318 }
2319 catch(std::bad_alloc&)
2320 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002321 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002322 }
2323}
2324
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002325void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
2326{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002327 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002328
2329 try
2330 {
2331 if (n < 0)
2332 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002333 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002334 }
2335
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002336 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002337
2338 if (context)
2339 {
daniel@transgaming.come2b22122010-03-11 19:22:14 +00002340 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002341 {
2342 context->deleteRenderbuffer(renderbuffers[i]);
2343 }
2344 }
2345 }
2346 catch(std::bad_alloc&)
2347 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002348 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002349 }
2350}
2351
2352void __stdcall glDeleteShader(GLuint shader)
2353{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002354 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002355
2356 try
2357 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002358 if (shader == 0)
2359 {
2360 return;
2361 }
2362
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002363 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002364
2365 if (context)
2366 {
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002367 if (!context->getShader(shader))
2368 {
2369 if(context->getProgram(shader))
2370 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002371 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002372 }
2373 else
2374 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002375 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com75401e62010-04-13 03:26:39 +00002376 }
2377 }
2378
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002379 context->deleteShader(shader);
2380 }
2381 }
2382 catch(std::bad_alloc&)
2383 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002384 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002385 }
2386}
2387
2388void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
2389{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002390 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002391
2392 try
2393 {
2394 if (n < 0)
2395 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002396 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002397 }
2398
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002399 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002400
2401 if (context)
2402 {
2403 for (int i = 0; i < n; i++)
2404 {
2405 if (textures[i] != 0)
2406 {
2407 context->deleteTexture(textures[i]);
2408 }
2409 }
2410 }
2411 }
2412 catch(std::bad_alloc&)
2413 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002414 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002415 }
2416}
2417
2418void __stdcall glDepthFunc(GLenum func)
2419{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002420 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002421
2422 try
2423 {
2424 switch (func)
2425 {
2426 case GL_NEVER:
2427 case GL_ALWAYS:
2428 case GL_LESS:
2429 case GL_LEQUAL:
2430 case GL_EQUAL:
2431 case GL_GREATER:
2432 case GL_GEQUAL:
2433 case GL_NOTEQUAL:
2434 break;
2435 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002436 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002437 }
2438
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002439 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002440
2441 if (context)
2442 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002443 context->setDepthFunc(func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002444 }
2445 }
2446 catch(std::bad_alloc&)
2447 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002448 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002449 }
2450}
2451
2452void __stdcall glDepthMask(GLboolean flag)
2453{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00002454 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002455
2456 try
2457 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002458 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002459
2460 if (context)
2461 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002462 context->setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002463 }
2464 }
2465 catch(std::bad_alloc&)
2466 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002467 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002468 }
2469}
2470
2471void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
2472{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002473 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002474
2475 try
2476 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002477 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002478
2479 if (context)
2480 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002481 context->setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002482 }
2483 }
2484 catch(std::bad_alloc&)
2485 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002486 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002487 }
2488}
2489
2490void __stdcall glDetachShader(GLuint program, GLuint shader)
2491{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002492 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002493
2494 try
2495 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002496 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002497
2498 if (context)
2499 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002500
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002501 gl::Program *programObject = context->getProgram(program);
2502 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002503
2504 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002505 {
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002506 gl::Shader *shaderByProgramHandle;
2507 shaderByProgramHandle = context->getShader(program);
2508 if (!shaderByProgramHandle)
2509 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002510 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002511 }
2512 else
2513 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002514 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002515 }
2516 }
2517
2518 if (!shaderObject)
2519 {
2520 gl::Program *programByShaderHandle = context->getProgram(shader);
2521 if (!programByShaderHandle)
2522 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002523 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002524 }
2525 else
2526 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002527 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00002528 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002529 }
2530
2531 if (!programObject->detachShader(shaderObject))
2532 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002533 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002534 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002535 }
2536 }
2537 catch(std::bad_alloc&)
2538 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002539 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002540 }
2541}
2542
2543void __stdcall glDisable(GLenum cap)
2544{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002545 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002546
2547 try
2548 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002549 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002550
2551 if (context)
2552 {
2553 switch (cap)
2554 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002555 case GL_CULL_FACE: context->setCullFace(false); break;
2556 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
2557 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
2558 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
2559 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
2560 case GL_STENCIL_TEST: context->setStencilTest(false); break;
2561 case GL_DEPTH_TEST: context->setDepthTest(false); break;
2562 case GL_BLEND: context->setBlend(false); break;
2563 case GL_DITHER: context->setDither(false); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002564 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002565 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002566 }
2567 }
2568 }
2569 catch(std::bad_alloc&)
2570 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002571 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002572 }
2573}
2574
2575void __stdcall glDisableVertexAttribArray(GLuint index)
2576{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002577 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002578
2579 try
2580 {
2581 if (index >= gl::MAX_VERTEX_ATTRIBS)
2582 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002583 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002584 }
2585
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002586 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002587
2588 if (context)
2589 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00002590 context->setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002591 }
2592 }
2593 catch(std::bad_alloc&)
2594 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002595 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002596 }
2597}
2598
2599void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
2600{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002601 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002602
2603 try
2604 {
2605 if (count < 0 || first < 0)
2606 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002607 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002608 }
2609
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002610 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002611
2612 if (context)
2613 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002614 context->drawArrays(mode, first, count, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002615 }
2616 }
2617 catch(std::bad_alloc&)
2618 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002619 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002620 }
2621}
2622
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002623void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
2624{
2625 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
2626
2627 try
2628 {
2629 if (count < 0 || first < 0 || primcount < 0)
2630 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002631 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002632 }
2633
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002634 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002635 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002636 gl::Context *context = gl::getNonLostContext();
2637
2638 if (context)
2639 {
2640 context->drawArrays(mode, first, count, primcount);
2641 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002642 }
2643 }
2644 catch(std::bad_alloc&)
2645 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002646 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002647 }
2648}
2649
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00002650void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002651{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002652 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 +00002653 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002654
2655 try
2656 {
2657 if (count < 0)
2658 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002659 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002660 }
2661
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002662 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002663
2664 if (context)
2665 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00002666 switch (type)
2667 {
2668 case GL_UNSIGNED_BYTE:
2669 case GL_UNSIGNED_SHORT:
2670 break;
2671 case GL_UNSIGNED_INT:
2672 if (!context->supports32bitIndices())
2673 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002674 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00002675 }
2676 break;
2677 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002678 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com83921382011-01-08 05:46:00 +00002679 }
2680
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002681 context->drawElements(mode, count, type, indices, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002682 }
2683 }
2684 catch(std::bad_alloc&)
2685 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002686 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002687 }
2688}
2689
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002690void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
2691{
2692 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
2693 mode, count, type, indices, primcount);
2694
2695 try
2696 {
2697 if (count < 0 || primcount < 0)
2698 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002699 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002700 }
2701
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002702 if (primcount > 0)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002703 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002704 gl::Context *context = gl::getNonLostContext();
2705
2706 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002707 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002708 switch (type)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002709 {
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002710 case GL_UNSIGNED_BYTE:
2711 case GL_UNSIGNED_SHORT:
2712 break;
2713 case GL_UNSIGNED_INT:
2714 if (!context->supports32bitIndices())
2715 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002716 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002717 }
2718 break;
2719 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002720 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002721 }
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002722
2723 context->drawElements(mode, count, type, indices, primcount);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002724 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002725 }
2726 }
2727 catch(std::bad_alloc&)
2728 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002729 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00002730 }
2731}
2732
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002733void __stdcall glEnable(GLenum cap)
2734{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002735 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002736
2737 try
2738 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002739 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002740
2741 if (context)
2742 {
2743 switch (cap)
2744 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00002745 case GL_CULL_FACE: context->setCullFace(true); break;
2746 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
2747 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
2748 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
2749 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
2750 case GL_STENCIL_TEST: context->setStencilTest(true); break;
2751 case GL_DEPTH_TEST: context->setDepthTest(true); break;
2752 case GL_BLEND: context->setBlend(true); break;
2753 case GL_DITHER: context->setDither(true); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002754 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002755 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002756 }
2757 }
2758 }
2759 catch(std::bad_alloc&)
2760 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002761 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002762 }
2763}
2764
2765void __stdcall glEnableVertexAttribArray(GLuint index)
2766{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002767 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002768
2769 try
2770 {
2771 if (index >= gl::MAX_VERTEX_ATTRIBS)
2772 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002773 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002774 }
2775
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002776 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002777
2778 if (context)
2779 {
daniel@transgaming.com83921382011-01-08 05:46:00 +00002780 context->setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002781 }
2782 }
2783 catch(std::bad_alloc&)
2784 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002785 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002786 }
2787}
2788
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002789void __stdcall glEndQueryEXT(GLenum target)
2790{
2791 EVENT("GLenum target = 0x%X)", target);
2792
2793 try
2794 {
2795 switch (target)
2796 {
2797 case GL_ANY_SAMPLES_PASSED_EXT:
2798 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
2799 break;
2800 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002801 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002802 }
2803
2804 gl::Context *context = gl::getNonLostContext();
2805
2806 if (context)
2807 {
2808 context->endQuery(target);
2809 }
2810 }
2811 catch(std::bad_alloc&)
2812 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002813 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002814 }
2815}
2816
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002817void __stdcall glFinishFenceNV(GLuint fence)
2818{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002819 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002820
2821 try
2822 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002823 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002824
2825 if (context)
2826 {
2827 gl::Fence* fenceObject = context->getFence(fence);
2828
2829 if (fenceObject == NULL)
2830 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002831 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002832 }
2833
2834 fenceObject->finishFence();
2835 }
2836 }
2837 catch(std::bad_alloc&)
2838 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002839 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002840 }
2841}
2842
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002843void __stdcall glFinish(void)
2844{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002845 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002846
2847 try
2848 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002849 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002850
2851 if (context)
2852 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00002853 context->sync(true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002854 }
2855 }
2856 catch(std::bad_alloc&)
2857 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002858 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002859 }
2860}
2861
2862void __stdcall glFlush(void)
2863{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002864 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002865
2866 try
2867 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002868 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002869
2870 if (context)
2871 {
daniel@transgaming.com0d86aa72011-10-26 02:35:10 +00002872 context->sync(false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002873 }
2874 }
2875 catch(std::bad_alloc&)
2876 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002877 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002878 }
2879}
2880
2881void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
2882{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002883 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002884 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002885
2886 try
2887 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002888 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00002889 || (renderbuffertarget != GL_RENDERBUFFER && 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_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002892 }
2893
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002894 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002895
2896 if (context)
2897 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002898 gl::Framebuffer *framebuffer = NULL;
2899 GLuint framebufferHandle = 0;
2900 if (target == GL_READ_FRAMEBUFFER_ANGLE)
2901 {
2902 framebuffer = context->getReadFramebuffer();
2903 framebufferHandle = context->getReadFramebufferHandle();
2904 }
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00002905 else
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002906 {
2907 framebuffer = context->getDrawFramebuffer();
2908 framebufferHandle = context->getDrawFramebufferHandle();
2909 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002910
daniel@transgaming.com2fa45512011-10-04 18:43:18 +00002911 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002912 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002913 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002914 }
2915
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002916 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002917 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002918 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
2919
2920 if (colorAttachment >= context->getMaximumRenderTargets())
2921 {
2922 return gl::error(GL_INVALID_VALUE);
2923 }
2924
2925 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer);
2926 }
2927 else
2928 {
2929 switch (attachment)
2930 {
2931 case GL_DEPTH_ATTACHMENT:
2932 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer);
2933 break;
2934 case GL_STENCIL_ATTACHMENT:
2935 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer);
2936 break;
2937 default:
2938 return gl::error(GL_INVALID_ENUM);
2939 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002940 }
2941 }
2942 }
2943 catch(std::bad_alloc&)
2944 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002945 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002946 }
2947}
2948
2949void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
2950{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002951 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002952 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002953
2954 try
2955 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002956 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002957 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002958 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002959 }
2960
daniel@transgaming.com9d788502011-11-09 17:46:55 +00002961 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002962
2963 if (context)
2964 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00002965 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
2966 {
2967 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
2968
2969 if (colorAttachment >= context->getMaximumRenderTargets())
2970 {
2971 return gl::error(GL_INVALID_VALUE);
2972 }
2973 }
2974 else
2975 {
2976 switch (attachment)
2977 {
2978 case GL_DEPTH_ATTACHMENT:
2979 case GL_STENCIL_ATTACHMENT:
2980 break;
2981 default:
2982 return gl::error(GL_INVALID_ENUM);
2983 }
2984 }
2985
daniel@transgaming.com93a81472010-04-20 18:52:58 +00002986 if (texture == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002987 {
daniel@transgaming.com93a81472010-04-20 18:52:58 +00002988 textarget = GL_NONE;
2989 }
2990 else
2991 {
2992 gl::Texture *tex = context->getTexture(texture);
2993
2994 if (tex == NULL)
2995 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00002996 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com93a81472010-04-20 18:52:58 +00002997 }
2998
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002999 switch (textarget)
3000 {
3001 case GL_TEXTURE_2D:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003002 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003003 if (tex->getTarget() != GL_TEXTURE_2D)
3004 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003005 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003006 }
3007 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
daniel@transgaming.com92f49922012-05-09 15:49:19 +00003008 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003009 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003010 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003011 }
3012 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003013 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003014
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003015 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003016 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003017 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003018 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003019 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003020 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003021 {
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003022 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
3023 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003024 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003025 }
3026 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00003027 if (texcube->isCompressed(textarget, level))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003028 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003029 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003030 }
3031 break;
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003032 }
daniel@transgaming.com93a81472010-04-20 18:52:58 +00003033
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003034 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003035 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003036 }
3037
3038 if (level != 0)
3039 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003040 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003041 }
3042 }
3043
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003044 gl::Framebuffer *framebuffer = NULL;
3045 GLuint framebufferHandle = 0;
3046 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3047 {
3048 framebuffer = context->getReadFramebuffer();
3049 framebufferHandle = context->getReadFramebufferHandle();
3050 }
3051 else
3052 {
3053 framebuffer = context->getDrawFramebuffer();
3054 framebufferHandle = context->getDrawFramebufferHandle();
3055 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003056
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003057 if (framebufferHandle == 0 || !framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003058 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003059 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003060 }
3061
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003062 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00003063 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003064 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3065
3066 if (colorAttachment >= context->getMaximumRenderTargets())
3067 {
3068 return gl::error(GL_INVALID_VALUE);
3069 }
3070
3071 framebuffer->setColorbuffer(colorAttachment, textarget, texture);
3072 }
3073 else
3074 {
3075 switch (attachment)
3076 {
3077 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture); break;
3078 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture); break;
3079 }
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00003080 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003081 }
3082 }
3083 catch(std::bad_alloc&)
3084 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003085 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003086 }
3087}
3088
3089void __stdcall glFrontFace(GLenum mode)
3090{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003091 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003092
3093 try
3094 {
3095 switch (mode)
3096 {
3097 case GL_CW:
3098 case GL_CCW:
3099 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003100 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003101
3102 if (context)
3103 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003104 context->setFrontFace(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003105 }
3106 }
3107 break;
3108 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003109 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003110 }
3111 }
3112 catch(std::bad_alloc&)
3113 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003114 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003115 }
3116}
3117
3118void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
3119{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003120 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003121
3122 try
3123 {
3124 if (n < 0)
3125 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003126 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003127 }
3128
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003129 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003130
3131 if (context)
3132 {
3133 for (int i = 0; i < n; i++)
3134 {
3135 buffers[i] = context->createBuffer();
3136 }
3137 }
3138 }
3139 catch(std::bad_alloc&)
3140 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003141 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003142 }
3143}
3144
3145void __stdcall glGenerateMipmap(GLenum target)
3146{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003147 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003148
3149 try
3150 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003151 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003152
3153 if (context)
3154 {
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003155 switch (target)
3156 {
3157 case GL_TEXTURE_2D:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003158 {
3159 gl::Texture2D *tex2d = context->getTexture2D();
3160
daniel@transgaming.com92f49922012-05-09 15:49:19 +00003161 if (tex2d->isCompressed(0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003162 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003163 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003164 }
daniel@transgaming.com0c854682012-05-31 01:14:11 +00003165 if (tex2d->isDepth(0))
3166 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003167 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00003168 }
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003169
3170 tex2d->generateMipmaps();
3171 break;
3172 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003173
3174 case GL_TEXTURE_CUBE_MAP:
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003175 {
3176 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
3177
daniel@transgaming.com4df88e82012-05-09 15:49:24 +00003178 if (texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0))
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003179 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003180 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comeb3c01a2012-05-09 15:49:12 +00003181 }
3182
3183 texcube->generateMipmaps();
3184 break;
3185 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003186
shannon.woods%transgaming.com@gtempaccount.com86740a92013-04-13 03:45:24 +00003187 case GL_TEXTURE_3D:
3188 {
3189 if (context->getClientVersion() < 3)
3190 {
3191 return gl::error(GL_INVALID_ENUM);
3192 }
3193
3194 gl::Texture3D *tex3D = context->getTexture3D();
3195 if (tex3D->isCompressed(0))
3196 {
3197 return gl::error(GL_INVALID_OPERATION);
3198 }
3199
3200 tex3D->generateMipmaps();
3201 break;
3202 }
3203
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003204 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003205 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003206 }
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00003207 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003208 }
3209 catch(std::bad_alloc&)
3210 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003211 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003212 }
3213}
3214
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003215void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
3216{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003217 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003218
3219 try
3220 {
3221 if (n < 0)
3222 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003223 return gl::error(GL_INVALID_VALUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003224 }
3225
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003226 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003227
3228 if (context)
3229 {
3230 for (int i = 0; i < n; i++)
3231 {
3232 fences[i] = context->createFence();
3233 }
3234 }
3235 }
3236 catch(std::bad_alloc&)
3237 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003238 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003239 }
3240}
3241
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003242void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
3243{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003244 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003245
3246 try
3247 {
3248 if (n < 0)
3249 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003250 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003251 }
3252
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003253 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003254
3255 if (context)
3256 {
3257 for (int i = 0; i < n; i++)
3258 {
3259 framebuffers[i] = context->createFramebuffer();
3260 }
3261 }
3262 }
3263 catch(std::bad_alloc&)
3264 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003265 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003266 }
3267}
3268
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003269void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
3270{
3271 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
3272
3273 try
3274 {
3275 if (n < 0)
3276 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003277 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003278 }
3279
3280 gl::Context *context = gl::getNonLostContext();
3281
3282 if (context)
3283 {
3284 for (int i = 0; i < n; i++)
3285 {
3286 ids[i] = context->createQuery();
3287 }
3288 }
3289 }
3290 catch(std::bad_alloc&)
3291 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003292 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003293 }
3294}
3295
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003296void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
3297{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003298 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003299
3300 try
3301 {
3302 if (n < 0)
3303 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003304 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003305 }
3306
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003307 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003308
3309 if (context)
3310 {
3311 for (int i = 0; i < n; i++)
3312 {
3313 renderbuffers[i] = context->createRenderbuffer();
3314 }
3315 }
3316 }
3317 catch(std::bad_alloc&)
3318 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003319 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003320 }
3321}
3322
3323void __stdcall glGenTextures(GLsizei n, GLuint* textures)
3324{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003325 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003326
3327 try
3328 {
3329 if (n < 0)
3330 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003331 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003332 }
3333
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003334 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003335
3336 if (context)
3337 {
3338 for (int i = 0; i < n; i++)
3339 {
3340 textures[i] = context->createTexture();
3341 }
3342 }
3343 }
3344 catch(std::bad_alloc&)
3345 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003346 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003347 }
3348}
3349
daniel@transgaming.com85423182010-04-22 13:35:27 +00003350void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003351{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003352 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00003353 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003354 program, index, bufsize, length, size, type, name);
3355
3356 try
3357 {
3358 if (bufsize < 0)
3359 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003360 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003361 }
3362
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003363 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com85423182010-04-22 13:35:27 +00003364
3365 if (context)
3366 {
3367 gl::Program *programObject = context->getProgram(program);
3368
3369 if (!programObject)
3370 {
3371 if (context->getShader(program))
3372 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003373 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com85423182010-04-22 13:35:27 +00003374 }
3375 else
3376 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003377 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00003378 }
3379 }
3380
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00003381 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com85423182010-04-22 13:35:27 +00003382 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003383 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com85423182010-04-22 13:35:27 +00003384 }
3385
3386 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
3387 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003388 }
3389 catch(std::bad_alloc&)
3390 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003391 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003392 }
3393}
3394
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003395void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003396{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003397 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003398 "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 +00003399 program, index, bufsize, length, size, type, name);
3400
3401 try
3402 {
3403 if (bufsize < 0)
3404 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003405 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003406 }
3407
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003408 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00003409
3410 if (context)
3411 {
3412 gl::Program *programObject = context->getProgram(program);
3413
3414 if (!programObject)
3415 {
3416 if (context->getShader(program))
3417 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003418 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00003419 }
3420 else
3421 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003422 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00003423 }
3424 }
3425
3426 if (index >= (GLuint)programObject->getActiveUniformCount())
3427 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003428 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00003429 }
3430
3431 programObject->getActiveUniform(index, bufsize, length, size, type, name);
3432 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003433 }
3434 catch(std::bad_alloc&)
3435 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003436 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003437 }
3438}
3439
3440void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
3441{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003442 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 +00003443 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003444
3445 try
3446 {
3447 if (maxcount < 0)
3448 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003449 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003450 }
3451
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003452 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com6c785212010-03-30 03:36:17 +00003453
3454 if (context)
3455 {
3456 gl::Program *programObject = context->getProgram(program);
3457
3458 if (!programObject)
3459 {
daniel@transgaming.com23953e32010-04-13 19:53:31 +00003460 if (context->getShader(program))
3461 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003462 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00003463 }
3464 else
3465 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003466 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com23953e32010-04-13 19:53:31 +00003467 }
daniel@transgaming.com6c785212010-03-30 03:36:17 +00003468 }
3469
3470 return programObject->getAttachedShaders(maxcount, count, shaders);
3471 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003472 }
3473 catch(std::bad_alloc&)
3474 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003475 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003476 }
3477}
3478
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003479int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003480{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003481 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003482
3483 try
3484 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003485 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003486
3487 if (context)
3488 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00003489
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003490 gl::Program *programObject = context->getProgram(program);
3491
3492 if (!programObject)
3493 {
daniel@transgaming.combb274c32010-04-13 03:26:21 +00003494 if (context->getShader(program))
3495 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003496 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00003497 }
3498 else
3499 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003500 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.combb274c32010-04-13 03:26:21 +00003501 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003502 }
3503
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00003504 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00003505 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00003506 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003507 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00003508 }
3509
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00003510 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003511 }
3512 }
3513 catch(std::bad_alloc&)
3514 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003515 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003516 }
3517
3518 return -1;
3519}
3520
3521void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
3522{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003523 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003524
3525 try
3526 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003527 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003528
3529 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003530 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003531 if (!(context->getBooleanv(pname, params)))
3532 {
3533 GLenum nativeType;
3534 unsigned int numParams = 0;
3535 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003536 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003537
3538 if (numParams == 0)
3539 return; // it is known that the pname is valid, but there are no parameters to return
3540
3541 if (nativeType == GL_FLOAT)
3542 {
3543 GLfloat *floatParams = NULL;
3544 floatParams = new GLfloat[numParams];
3545
3546 context->getFloatv(pname, floatParams);
3547
3548 for (unsigned int i = 0; i < numParams; ++i)
3549 {
3550 if (floatParams[i] == 0.0f)
3551 params[i] = GL_FALSE;
3552 else
3553 params[i] = GL_TRUE;
3554 }
3555
3556 delete [] floatParams;
3557 }
3558 else if (nativeType == GL_INT)
3559 {
3560 GLint *intParams = NULL;
3561 intParams = new GLint[numParams];
3562
3563 context->getIntegerv(pname, intParams);
3564
3565 for (unsigned int i = 0; i < numParams; ++i)
3566 {
3567 if (intParams[i] == 0)
3568 params[i] = GL_FALSE;
3569 else
3570 params[i] = GL_TRUE;
3571 }
3572
3573 delete [] intParams;
3574 }
3575 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003576 }
3577 }
3578 catch(std::bad_alloc&)
3579 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003580 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003581 }
3582}
3583
3584void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
3585{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003586 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 +00003587
3588 try
3589 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003590 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00003591
3592 if (context)
3593 {
3594 gl::Buffer *buffer;
3595
3596 switch (target)
3597 {
3598 case GL_ARRAY_BUFFER:
3599 buffer = context->getArrayBuffer();
3600 break;
3601 case GL_ELEMENT_ARRAY_BUFFER:
3602 buffer = context->getElementArrayBuffer();
3603 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003604 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00003605 }
3606
3607 if (!buffer)
3608 {
3609 // A null buffer means that "0" is bound to the requested buffer target
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003610 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00003611 }
3612
3613 switch (pname)
3614 {
3615 case GL_BUFFER_USAGE:
3616 *params = buffer->usage();
3617 break;
3618 case GL_BUFFER_SIZE:
3619 *params = buffer->size();
3620 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003621 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00003622 }
3623 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003624 }
3625 catch(std::bad_alloc&)
3626 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003627 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003628 }
3629}
3630
3631GLenum __stdcall glGetError(void)
3632{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003633 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003634
3635 gl::Context *context = gl::getContext();
3636
3637 if (context)
3638 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00003639 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003640 }
3641
3642 return GL_NO_ERROR;
3643}
3644
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003645void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
3646{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003647 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003648
3649 try
3650 {
3651
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003652 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003653
3654 if (context)
3655 {
3656 gl::Fence *fenceObject = context->getFence(fence);
3657
3658 if (fenceObject == NULL)
3659 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003660 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003661 }
3662
3663 fenceObject->getFenceiv(pname, params);
3664 }
3665 }
3666 catch(std::bad_alloc&)
3667 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003668 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003669 }
3670}
3671
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003672void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
3673{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003674 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003675
3676 try
3677 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003678 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00003679
3680 if (context)
3681 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003682 if (!(context->getFloatv(pname, params)))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00003683 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003684 GLenum nativeType;
3685 unsigned int numParams = 0;
3686 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003687 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003688
3689 if (numParams == 0)
3690 return; // it is known that the pname is valid, but that there are no parameters to return.
3691
3692 if (nativeType == GL_BOOL)
3693 {
3694 GLboolean *boolParams = NULL;
3695 boolParams = new GLboolean[numParams];
3696
3697 context->getBooleanv(pname, boolParams);
3698
3699 for (unsigned int i = 0; i < numParams; ++i)
3700 {
3701 if (boolParams[i] == GL_FALSE)
3702 params[i] = 0.0f;
3703 else
3704 params[i] = 1.0f;
3705 }
3706
3707 delete [] boolParams;
3708 }
3709 else if (nativeType == GL_INT)
3710 {
3711 GLint *intParams = NULL;
3712 intParams = new GLint[numParams];
3713
3714 context->getIntegerv(pname, intParams);
3715
3716 for (unsigned int i = 0; i < numParams; ++i)
3717 {
3718 params[i] = (GLfloat)intParams[i];
3719 }
3720
3721 delete [] intParams;
3722 }
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00003723 }
3724 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003725 }
3726 catch(std::bad_alloc&)
3727 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003728 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003729 }
3730}
3731
3732void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
3733{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003734 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 +00003735 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003736
3737 try
3738 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003739 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003740
3741 if (context)
3742 {
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003743 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003744 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003745 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003746 }
3747
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003748 gl::Framebuffer *framebuffer = NULL;
3749 if (target == GL_READ_FRAMEBUFFER_ANGLE)
3750 {
3751 if(context->getReadFramebufferHandle() == 0)
3752 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003753 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003754 }
3755
3756 framebuffer = context->getReadFramebuffer();
3757 }
3758 else
3759 {
3760 if (context->getDrawFramebufferHandle() == 0)
3761 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003762 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00003763 }
3764
3765 framebuffer = context->getDrawFramebuffer();
3766 }
3767
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003768 GLenum attachmentType;
3769 GLuint attachmentHandle;
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003770
3771 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003772 {
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00003773 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
3774
3775 if (colorAttachment >= context->getMaximumRenderTargets())
3776 {
3777 return gl::error(GL_INVALID_ENUM);
3778 }
3779
3780 attachmentType = framebuffer->getColorbufferType(colorAttachment);
3781 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
3782 }
3783 else
3784 {
3785 switch (attachment)
3786 {
3787 case GL_DEPTH_ATTACHMENT:
3788 attachmentType = framebuffer->getDepthbufferType();
3789 attachmentHandle = framebuffer->getDepthbufferHandle();
3790 break;
3791 case GL_STENCIL_ATTACHMENT:
3792 attachmentType = framebuffer->getStencilbufferType();
3793 attachmentHandle = framebuffer->getStencilbufferHandle();
3794 break;
3795 default: return gl::error(GL_INVALID_ENUM);
3796 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003797 }
3798
3799 GLenum attachmentObjectType; // Type category
daniel@transgaming.comfbc09532010-04-26 15:33:41 +00003800 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003801 {
3802 attachmentObjectType = attachmentType;
3803 }
apatrick@chromium.org551022e2012-01-23 19:56:54 +00003804 else if (gl::IsInternalTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003805 {
3806 attachmentObjectType = GL_TEXTURE;
3807 }
apatrick@chromium.orga1d80592012-01-25 21:52:10 +00003808 else
3809 {
3810 UNREACHABLE();
3811 return;
3812 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003813
3814 switch (pname)
3815 {
3816 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
3817 *params = attachmentObjectType;
3818 break;
3819 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
3820 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
3821 {
3822 *params = attachmentHandle;
3823 }
3824 else
3825 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003826 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003827 }
3828 break;
3829 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
3830 if (attachmentObjectType == GL_TEXTURE)
3831 {
3832 *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0
3833 }
3834 else
3835 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003836 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003837 }
3838 break;
3839 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
3840 if (attachmentObjectType == GL_TEXTURE)
3841 {
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00003842 if (gl::IsCubemapTextureTarget(attachmentType))
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003843 {
3844 *params = attachmentType;
3845 }
3846 else
3847 {
3848 *params = 0;
3849 }
3850 }
3851 else
3852 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003853 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003854 }
3855 break;
3856 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003857 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00003858 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003859 }
3860 }
3861 catch(std::bad_alloc&)
3862 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003863 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003864 }
3865}
3866
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00003867GLenum __stdcall glGetGraphicsResetStatusEXT(void)
3868{
3869 EVENT("()");
3870
3871 try
3872 {
3873 gl::Context *context = gl::getContext();
3874
3875 if (context)
3876 {
3877 return context->getResetStatus();
3878 }
3879
3880 return GL_NO_ERROR;
3881 }
3882 catch(std::bad_alloc&)
3883 {
3884 return GL_OUT_OF_MEMORY;
3885 }
3886}
3887
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003888void __stdcall glGetIntegerv(GLenum pname, GLint* params)
3889{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003890 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003891
3892 try
3893 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003894 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003895
3896 if (context)
3897 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003898 if (!(context->getIntegerv(pname, params)))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003899 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003900 GLenum nativeType;
3901 unsigned int numParams = 0;
3902 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003903 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003904
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003905 if (numParams == 0)
3906 return; // it is known that pname is valid, but there are no parameters to return
3907
3908 if (nativeType == GL_BOOL)
3909 {
3910 GLboolean *boolParams = NULL;
3911 boolParams = new GLboolean[numParams];
3912
3913 context->getBooleanv(pname, boolParams);
3914
3915 for (unsigned int i = 0; i < numParams; ++i)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003916 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003917 if (boolParams[i] == GL_FALSE)
3918 params[i] = 0;
3919 else
3920 params[i] = 1;
3921 }
3922
3923 delete [] boolParams;
3924 }
3925 else if (nativeType == GL_FLOAT)
3926 {
3927 GLfloat *floatParams = NULL;
3928 floatParams = new GLfloat[numParams];
3929
3930 context->getFloatv(pname, floatParams);
3931
3932 for (unsigned int i = 0; i < numParams; ++i)
3933 {
daniel@transgaming.comc1641352010-04-26 15:33:36 +00003934 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 +00003935 {
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003936 params[i] = (GLint)(((GLfloat)(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003937 }
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003938 else
3939 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 +00003940 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003941
daniel@transgaming.com777f2672010-04-07 03:25:16 +00003942 delete [] floatParams;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003943 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003944 }
3945 }
3946 }
3947 catch(std::bad_alloc&)
3948 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003949 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003950 }
3951}
3952
3953void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
3954{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003955 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003956
3957 try
3958 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00003959 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003960
3961 if (context)
3962 {
3963 gl::Program *programObject = context->getProgram(program);
3964
3965 if (!programObject)
3966 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00003967 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003968 }
3969
3970 switch (pname)
3971 {
3972 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00003973 *params = programObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003974 return;
3975 case GL_LINK_STATUS:
daniel@transgaming.com716056c2012-07-24 18:38:59 +00003976 *params = programObject->isLinked();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003977 return;
3978 case GL_VALIDATE_STATUS:
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00003979 *params = programObject->isValidated();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003980 return;
3981 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00003982 *params = programObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003983 return;
3984 case GL_ATTACHED_SHADERS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00003985 *params = programObject->getAttachedShadersCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003986 return;
3987 case GL_ACTIVE_ATTRIBUTES:
daniel@transgaming.com85423182010-04-22 13:35:27 +00003988 *params = programObject->getActiveAttributeCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003989 return;
3990 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
daniel@transgaming.com85423182010-04-22 13:35:27 +00003991 *params = programObject->getActiveAttributeMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003992 return;
3993 case GL_ACTIVE_UNIFORMS:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00003994 *params = programObject->getActiveUniformCount();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003995 return;
3996 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
daniel@transgaming.com09fbfef2010-04-22 13:35:31 +00003997 *params = programObject->getActiveUniformMaxLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003998 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00003999 case GL_PROGRAM_BINARY_LENGTH_OES:
apatrick@chromium.org90080e32012-07-09 22:15:33 +00004000 *params = programObject->getProgramBinaryLength();
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00004001 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004002 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004003 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004004 }
4005 }
4006 }
4007 catch(std::bad_alloc&)
4008 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004009 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004010 }
4011}
4012
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004013void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004014{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004015 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 +00004016 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004017
4018 try
4019 {
4020 if (bufsize < 0)
4021 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004022 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004023 }
4024
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004025 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004026
4027 if (context)
4028 {
4029 gl::Program *programObject = context->getProgram(program);
4030
4031 if (!programObject)
4032 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004033 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004034 }
4035
4036 programObject->getInfoLog(bufsize, length, infolog);
4037 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004038 }
4039 catch(std::bad_alloc&)
4040 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004041 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004042 }
4043}
4044
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004045void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
4046{
4047 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
4048
4049 try
4050 {
4051 switch (pname)
4052 {
4053 case GL_CURRENT_QUERY_EXT:
4054 break;
4055 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004056 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004057 }
4058
4059 gl::Context *context = gl::getNonLostContext();
4060
4061 if (context)
4062 {
4063 params[0] = context->getActiveQuery(target);
4064 }
4065 }
4066 catch(std::bad_alloc&)
4067 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004068 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004069 }
4070}
4071
4072void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
4073{
4074 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
4075
4076 try
4077 {
4078 switch (pname)
4079 {
4080 case GL_QUERY_RESULT_EXT:
4081 case GL_QUERY_RESULT_AVAILABLE_EXT:
4082 break;
4083 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004084 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004085 }
4086 gl::Context *context = gl::getNonLostContext();
4087
4088 if (context)
4089 {
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004090 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
4091
4092 if (!queryObject)
4093 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004094 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004095 }
4096
4097 if (context->getActiveQuery(queryObject->getType()) == id)
4098 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004099 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004100 }
4101
4102 switch(pname)
4103 {
4104 case GL_QUERY_RESULT_EXT:
4105 params[0] = queryObject->getResult();
4106 break;
4107 case GL_QUERY_RESULT_AVAILABLE_EXT:
4108 params[0] = queryObject->isResultAvailable();
4109 break;
4110 default:
4111 ASSERT(false);
4112 }
4113 }
4114 }
4115 catch(std::bad_alloc&)
4116 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004117 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00004118 }
4119}
4120
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004121void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
4122{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004123 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 +00004124
4125 try
4126 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004127 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004128
4129 if (context)
4130 {
4131 if (target != GL_RENDERBUFFER)
4132 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004133 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004134 }
4135
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004136 if (context->getRenderbufferHandle() == 0)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004137 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004138 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004139 }
4140
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004141 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004142
4143 switch (pname)
4144 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00004145 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
4146 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
4147 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
4148 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
4149 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
4150 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
4151 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
4152 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
4153 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00004154 case GL_RENDERBUFFER_SAMPLES_ANGLE:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00004155 if (context->getMaxSupportedSamples() != 0)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00004156 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +00004157 *params = renderbuffer->getSamples();
4158 }
4159 else
4160 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004161 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00004162 }
4163 break;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004164 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004165 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00004166 }
4167 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004168 }
4169 catch(std::bad_alloc&)
4170 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004171 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004172 }
4173}
4174
4175void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
4176{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004177 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004178
4179 try
4180 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004181 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004182
4183 if (context)
4184 {
4185 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00004186
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004187 if (!shaderObject)
4188 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004189 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004190 }
4191
4192 switch (pname)
4193 {
4194 case GL_SHADER_TYPE:
4195 *params = shaderObject->getType();
4196 return;
4197 case GL_DELETE_STATUS:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004198 *params = shaderObject->isFlaggedForDeletion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004199 return;
4200 case GL_COMPILE_STATUS:
4201 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
4202 return;
4203 case GL_INFO_LOG_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004204 *params = shaderObject->getInfoLogLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004205 return;
4206 case GL_SHADER_SOURCE_LENGTH:
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004207 *params = shaderObject->getSourceLength();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004208 return;
zmo@google.coma574f782011-10-03 21:45:23 +00004209 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
4210 *params = shaderObject->getTranslatedSourceLength();
4211 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004212 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004213 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004214 }
4215 }
4216 }
4217 catch(std::bad_alloc&)
4218 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004219 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004220 }
4221}
4222
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004223void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004224{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004225 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 +00004226 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004227
4228 try
4229 {
4230 if (bufsize < 0)
4231 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004232 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004233 }
4234
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004235 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004236
4237 if (context)
4238 {
4239 gl::Shader *shaderObject = context->getShader(shader);
4240
4241 if (!shaderObject)
4242 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004243 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004244 }
4245
4246 shaderObject->getInfoLog(bufsize, length, infolog);
4247 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004248 }
4249 catch(std::bad_alloc&)
4250 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004251 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004252 }
4253}
4254
4255void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
4256{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004257 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 +00004258 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004259
4260 try
4261 {
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004262 switch (shadertype)
4263 {
4264 case GL_VERTEX_SHADER:
4265 case GL_FRAGMENT_SHADER:
4266 break;
4267 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004268 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004269 }
4270
4271 switch (precisiontype)
4272 {
4273 case GL_LOW_FLOAT:
4274 case GL_MEDIUM_FLOAT:
4275 case GL_HIGH_FLOAT:
4276 // Assume IEEE 754 precision
4277 range[0] = 127;
4278 range[1] = 127;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00004279 *precision = 23;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004280 break;
4281 case GL_LOW_INT:
4282 case GL_MEDIUM_INT:
4283 case GL_HIGH_INT:
4284 // Some (most) hardware only supports single-precision floating-point numbers,
4285 // which can accurately represent integers up to +/-16777216
4286 range[0] = 24;
4287 range[1] = 24;
daniel@transgaming.comc5c15382010-04-23 18:34:49 +00004288 *precision = 0;
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004289 break;
4290 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004291 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6c785212010-03-30 03:36:17 +00004292 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004293 }
4294 catch(std::bad_alloc&)
4295 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004296 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004297 }
4298}
4299
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004300void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004301{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004302 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 +00004303 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004304
4305 try
4306 {
4307 if (bufsize < 0)
4308 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004309 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004310 }
4311
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004312 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004313
4314 if (context)
4315 {
4316 gl::Shader *shaderObject = context->getShader(shader);
4317
4318 if (!shaderObject)
4319 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004320 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comcba50572010-03-28 19:36:09 +00004321 }
4322
4323 shaderObject->getSource(bufsize, length, source);
4324 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004325 }
4326 catch(std::bad_alloc&)
4327 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004328 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004329 }
4330}
4331
zmo@google.coma574f782011-10-03 21:45:23 +00004332void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
4333{
4334 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
4335 shader, bufsize, length, source);
4336
4337 try
4338 {
4339 if (bufsize < 0)
4340 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004341 return gl::error(GL_INVALID_VALUE);
zmo@google.coma574f782011-10-03 21:45:23 +00004342 }
4343
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004344 gl::Context *context = gl::getNonLostContext();
zmo@google.coma574f782011-10-03 21:45:23 +00004345
4346 if (context)
4347 {
4348 gl::Shader *shaderObject = context->getShader(shader);
4349
4350 if (!shaderObject)
4351 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004352 return gl::error(GL_INVALID_OPERATION);
zmo@google.coma574f782011-10-03 21:45:23 +00004353 }
4354
4355 shaderObject->getTranslatedSource(bufsize, length, source);
4356 }
4357 }
4358 catch(std::bad_alloc&)
4359 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004360 return gl::error(GL_OUT_OF_MEMORY);
zmo@google.coma574f782011-10-03 21:45:23 +00004361 }
4362}
4363
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004364const GLubyte* __stdcall glGetString(GLenum name)
4365{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004366 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004367
4368 try
4369 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004370 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00004371
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004372 switch (name)
4373 {
4374 case GL_VENDOR:
daniel@transgaming.coma0ce7e62011-01-25 14:47:16 +00004375 return (GLubyte*)"Google Inc.";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004376 case GL_RENDERER:
daniel@transgaming.comc23ff642011-08-16 20:28:45 +00004377 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004378 case GL_VERSION:
daniel@transgaming.com1825d8e2012-08-27 16:25:29 +00004379 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004380 case GL_SHADING_LANGUAGE_VERSION:
daniel@transgaming.com1825d8e2012-08-27 16:25:29 +00004381 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004382 case GL_EXTENSIONS:
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00004383 return (GLubyte*)((context != NULL) ? context->getExtensionString() : "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004384 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004385 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004386 }
4387 }
4388 catch(std::bad_alloc&)
4389 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004390 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004391 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004392}
4393
4394void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
4395{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004396 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 +00004397
4398 try
4399 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004400 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004401
4402 if (context)
4403 {
4404 gl::Texture *texture;
4405
4406 switch (target)
4407 {
4408 case GL_TEXTURE_2D:
4409 texture = context->getTexture2D();
4410 break;
4411 case GL_TEXTURE_CUBE_MAP:
4412 texture = context->getTextureCubeMap();
4413 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00004414 case GL_TEXTURE_3D:
4415 if (context->getClientVersion() < 3)
4416 {
4417 return gl::error(GL_INVALID_ENUM);
4418 }
4419 texture = context->getTexture3D();
4420 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004421 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004422 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004423 }
4424
4425 switch (pname)
4426 {
4427 case GL_TEXTURE_MAG_FILTER:
4428 *params = (GLfloat)texture->getMagFilter();
4429 break;
4430 case GL_TEXTURE_MIN_FILTER:
4431 *params = (GLfloat)texture->getMinFilter();
4432 break;
4433 case GL_TEXTURE_WRAP_S:
4434 *params = (GLfloat)texture->getWrapS();
4435 break;
4436 case GL_TEXTURE_WRAP_T:
4437 *params = (GLfloat)texture->getWrapT();
4438 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00004439 case GL_TEXTURE_WRAP_R:
4440 if (context->getClientVersion() < 3)
4441 {
4442 return gl::error(GL_INVALID_ENUM);
4443 }
4444 *params = (GLfloat)texture->getWrapR();
4445 break;
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00004446 case GL_TEXTURE_IMMUTABLE_FORMAT_EXT:
4447 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
4448 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00004449 case GL_TEXTURE_USAGE_ANGLE:
4450 *params = (GLfloat)texture->getUsage();
4451 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004452 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
4453 if (!context->supportsTextureFilterAnisotropy())
4454 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004455 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004456 }
4457 *params = (GLfloat)texture->getMaxAnisotropy();
4458 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004459 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004460 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004461 }
4462 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004463 }
4464 catch(std::bad_alloc&)
4465 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004466 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004467 }
4468}
4469
4470void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
4471{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004472 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 +00004473
4474 try
4475 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004476 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004477
4478 if (context)
4479 {
4480 gl::Texture *texture;
4481
4482 switch (target)
4483 {
4484 case GL_TEXTURE_2D:
4485 texture = context->getTexture2D();
4486 break;
4487 case GL_TEXTURE_CUBE_MAP:
4488 texture = context->getTextureCubeMap();
4489 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00004490 case GL_TEXTURE_3D:
4491 if (context->getClientVersion() < 3)
4492 {
4493 return gl::error(GL_INVALID_ENUM);
4494 }
4495 texture = context->getTexture3D();
4496 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004497 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004498 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004499 }
4500
4501 switch (pname)
4502 {
4503 case GL_TEXTURE_MAG_FILTER:
4504 *params = texture->getMagFilter();
4505 break;
4506 case GL_TEXTURE_MIN_FILTER:
4507 *params = texture->getMinFilter();
4508 break;
4509 case GL_TEXTURE_WRAP_S:
4510 *params = texture->getWrapS();
4511 break;
4512 case GL_TEXTURE_WRAP_T:
4513 *params = texture->getWrapT();
4514 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00004515 case GL_TEXTURE_WRAP_R:
4516 if (context->getClientVersion() < 3)
4517 {
4518 return gl::error(GL_INVALID_ENUM);
4519 }
4520 *params = texture->getWrapR();
4521 break;
daniel@transgaming.comd30bd0a2011-11-11 04:10:34 +00004522 case GL_TEXTURE_IMMUTABLE_FORMAT_EXT:
4523 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
4524 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00004525 case GL_TEXTURE_USAGE_ANGLE:
4526 *params = texture->getUsage();
4527 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004528 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
4529 if (!context->supportsTextureFilterAnisotropy())
4530 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004531 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004532 }
4533 *params = (GLint)texture->getMaxAnisotropy();
4534 break;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004535 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004536 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00004537 }
4538 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004539 }
4540 catch(std::bad_alloc&)
4541 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004542 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004543 }
4544}
4545
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004546void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
4547{
4548 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
4549 program, location, bufSize, params);
4550
4551 try
4552 {
4553 if (bufSize < 0)
4554 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004555 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004556 }
4557
4558 gl::Context *context = gl::getNonLostContext();
4559
4560 if (context)
4561 {
4562 if (program == 0)
4563 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004564 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004565 }
4566
4567 gl::Program *programObject = context->getProgram(program);
4568
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004569 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004570 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004571 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004572 }
4573
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004574 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
4575 if (!programBinary)
4576 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004577 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004578 }
4579
4580 if (!programBinary->getUniformfv(location, &bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004581 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004582 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004583 }
4584 }
4585 }
4586 catch(std::bad_alloc&)
4587 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004588 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004589 }
4590}
4591
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004592void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
4593{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004594 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004595
4596 try
4597 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004598 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004599
4600 if (context)
4601 {
4602 if (program == 0)
4603 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004604 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004605 }
4606
4607 gl::Program *programObject = context->getProgram(program);
4608
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004609 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004610 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004611 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004612 }
4613
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004614 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
4615 if (!programBinary)
4616 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004617 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004618 }
4619
4620 if (!programBinary->getUniformfv(location, NULL, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004621 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004622 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004623 }
4624 }
4625 }
4626 catch(std::bad_alloc&)
4627 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004628 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004629 }
4630}
4631
4632void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
4633{
4634 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
4635 program, location, bufSize, params);
4636
4637 try
4638 {
4639 if (bufSize < 0)
4640 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004641 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004642 }
4643
4644 gl::Context *context = gl::getNonLostContext();
4645
4646 if (context)
4647 {
4648 if (program == 0)
4649 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004650 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004651 }
4652
4653 gl::Program *programObject = context->getProgram(program);
4654
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004655 if (!programObject || !programObject->isLinked())
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004656 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004657 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00004658 }
4659
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004660 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
4661 if (!programBinary)
4662 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004663 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004664 }
4665
4666 if (!programBinary->getUniformiv(location, &bufSize, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004667 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004668 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004669 }
4670 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004671 }
4672 catch(std::bad_alloc&)
4673 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004674 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004675 }
4676}
4677
4678void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
4679{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004680 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004681
4682 try
4683 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004684 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004685
4686 if (context)
4687 {
4688 if (program == 0)
4689 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004690 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004691 }
4692
4693 gl::Program *programObject = context->getProgram(program);
4694
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004695 if (!programObject || !programObject->isLinked())
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004696 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004697 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004698 }
4699
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004700 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
4701 if (!programBinary)
4702 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004703 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004704 }
4705
4706 if (!programBinary->getUniformiv(location, NULL, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004707 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004708 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00004709 }
4710 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004711 }
4712 catch(std::bad_alloc&)
4713 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004714 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004715 }
4716}
4717
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004718int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004719{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004720 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004721
4722 try
4723 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004724 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004725
4726 if (strstr(name, "gl_") == name)
4727 {
4728 return -1;
4729 }
4730
4731 if (context)
4732 {
4733 gl::Program *programObject = context->getProgram(program);
4734
4735 if (!programObject)
4736 {
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00004737 if (context->getShader(program))
4738 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004739 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00004740 }
4741 else
4742 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004743 return gl::error(GL_INVALID_VALUE, -1);
daniel@transgaming.comd1abe5b2010-04-13 19:53:33 +00004744 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004745 }
4746
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004747 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
daniel@transgaming.com716056c2012-07-24 18:38:59 +00004748 if (!programObject->isLinked() || !programBinary)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004749 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004750 return gl::error(GL_INVALID_OPERATION, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004751 }
4752
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00004753 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004754 }
4755 }
4756 catch(std::bad_alloc&)
4757 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004758 return gl::error(GL_OUT_OF_MEMORY, -1);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004759 }
4760
4761 return -1;
4762}
4763
4764void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
4765{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004766 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004767
4768 try
4769 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004770 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004771
daniel@transgaming.come0078962010-04-15 20:45:08 +00004772 if (context)
4773 {
4774 if (index >= gl::MAX_VERTEX_ATTRIBS)
4775 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004776 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004777 }
4778
daniel@transgaming.com83921382011-01-08 05:46:00 +00004779 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004780
daniel@transgaming.come0078962010-04-15 20:45:08 +00004781 switch (pname)
4782 {
4783 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00004784 *params = (GLfloat)(attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004785 break;
4786 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004787 *params = (GLfloat)attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00004788 break;
4789 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004790 *params = (GLfloat)attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00004791 break;
4792 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004793 *params = (GLfloat)attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00004794 break;
4795 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004796 *params = (GLfloat)(attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004797 break;
4798 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00004799 *params = (GLfloat)attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00004800 break;
4801 case GL_CURRENT_VERTEX_ATTRIB:
4802 for (int i = 0; i < 4; ++i)
4803 {
shannon.woods%transgaming.com@gtempaccount.com3026dc72013-04-13 03:37:27 +00004804 params[i] = attribState.mCurrentValue.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00004805 }
4806 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00004807 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
4808 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
4809 // the same constant.
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004810 *params = (GLfloat)attribState.mDivisor;
4811 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004812 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004813 }
4814 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004815 }
4816 catch(std::bad_alloc&)
4817 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004818 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004819 }
4820}
4821
4822void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
4823{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004824 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004825
4826 try
4827 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004828 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004829
daniel@transgaming.come0078962010-04-15 20:45:08 +00004830 if (context)
4831 {
4832 if (index >= gl::MAX_VERTEX_ATTRIBS)
4833 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004834 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004835 }
4836
daniel@transgaming.com83921382011-01-08 05:46:00 +00004837 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004838
daniel@transgaming.come0078962010-04-15 20:45:08 +00004839 switch (pname)
4840 {
4841 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
daniel@transgaming.com83921382011-01-08 05:46:00 +00004842 *params = (attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004843 break;
4844 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004845 *params = attribState.mSize;
daniel@transgaming.come0078962010-04-15 20:45:08 +00004846 break;
4847 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004848 *params = attribState.mStride;
daniel@transgaming.come0078962010-04-15 20:45:08 +00004849 break;
4850 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004851 *params = attribState.mType;
daniel@transgaming.come0078962010-04-15 20:45:08 +00004852 break;
4853 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004854 *params = (attribState.mNormalized ? GL_TRUE : GL_FALSE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004855 break;
4856 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00004857 *params = attribState.mBoundBuffer.id();
daniel@transgaming.come0078962010-04-15 20:45:08 +00004858 break;
4859 case GL_CURRENT_VERTEX_ATTRIB:
4860 for (int i = 0; i < 4; ++i)
4861 {
shannon.woods%transgaming.com@gtempaccount.com3026dc72013-04-13 03:37:27 +00004862 float currentValue = attribState.mCurrentValue.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00004863 params[i] = (GLint)(currentValue > 0.0f ? floor(currentValue + 0.5f) : ceil(currentValue - 0.5f));
4864 }
4865 break;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00004866 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
4867 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
4868 // the same constant.
4869 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004870 *params = (GLint)attribState.mDivisor;
4871 break;
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004872 default: return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004873 }
4874 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004875 }
4876 catch(std::bad_alloc&)
4877 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004878 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004879 }
4880}
4881
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004882void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004883{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004884 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004885
4886 try
4887 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004888 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004889
daniel@transgaming.come0078962010-04-15 20:45:08 +00004890 if (context)
4891 {
4892 if (index >= gl::MAX_VERTEX_ATTRIBS)
4893 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004894 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004895 }
4896
4897 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
4898 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004899 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come0078962010-04-15 20:45:08 +00004900 }
4901
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004902 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
daniel@transgaming.come0078962010-04-15 20:45:08 +00004903 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004904 }
4905 catch(std::bad_alloc&)
4906 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004907 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004908 }
4909}
4910
4911void __stdcall glHint(GLenum target, GLenum mode)
4912{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004913 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004914
4915 try
4916 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00004917 switch (mode)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00004918 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00004919 case GL_FASTEST:
4920 case GL_NICEST:
4921 case GL_DONT_CARE:
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00004922 break;
4923 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004924 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00004925 }
4926
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004927 gl::Context *context = gl::getNonLostContext();
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00004928 switch (target)
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00004929 {
alokp@chromium.orgd303ef92010-09-09 17:30:15 +00004930 case GL_GENERATE_MIPMAP_HINT:
4931 if (context) context->setGenerateMipmapHint(mode);
4932 break;
4933 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
4934 if (context) context->setFragmentShaderDerivativeHint(mode);
4935 break;
4936 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004937 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5949aa12010-03-21 04:31:15 +00004938 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004939 }
4940 catch(std::bad_alloc&)
4941 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004942 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004943 }
4944}
4945
4946GLboolean __stdcall glIsBuffer(GLuint buffer)
4947{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004948 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004949
4950 try
4951 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004952 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004953
4954 if (context && buffer)
4955 {
4956 gl::Buffer *bufferObject = context->getBuffer(buffer);
4957
4958 if (bufferObject)
4959 {
4960 return GL_TRUE;
4961 }
4962 }
4963 }
4964 catch(std::bad_alloc&)
4965 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004966 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004967 }
4968
4969 return GL_FALSE;
4970}
4971
4972GLboolean __stdcall glIsEnabled(GLenum cap)
4973{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004974 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004975
4976 try
4977 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00004978 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004979
4980 if (context)
4981 {
4982 switch (cap)
4983 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00004984 case GL_CULL_FACE: return context->isCullFaceEnabled();
4985 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
4986 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
4987 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
4988 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
4989 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
4990 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
4991 case GL_BLEND: return context->isBlendEnabled();
4992 case GL_DITHER: return context->isDitherEnabled();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004993 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00004994 return gl::error(GL_INVALID_ENUM, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004995 }
4996 }
4997 }
4998 catch(std::bad_alloc&)
4999 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005000 return gl::error(GL_OUT_OF_MEMORY, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005001 }
5002
5003 return false;
5004}
5005
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005006GLboolean __stdcall glIsFenceNV(GLuint fence)
5007{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005008 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005009
5010 try
5011 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005012 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005013
5014 if (context)
5015 {
5016 gl::Fence *fenceObject = context->getFence(fence);
5017
5018 if (fenceObject == NULL)
5019 {
5020 return GL_FALSE;
5021 }
5022
5023 return fenceObject->isFence();
5024 }
5025 }
5026 catch(std::bad_alloc&)
5027 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005028 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005029 }
5030
5031 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005032}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005033
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005034GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
5035{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005036 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005037
5038 try
5039 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005040 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005041
5042 if (context && framebuffer)
5043 {
5044 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
5045
5046 if (framebufferObject)
5047 {
5048 return GL_TRUE;
5049 }
5050 }
5051 }
5052 catch(std::bad_alloc&)
5053 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005054 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005055 }
5056
5057 return GL_FALSE;
5058}
5059
5060GLboolean __stdcall glIsProgram(GLuint program)
5061{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005062 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005063
5064 try
5065 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005066 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005067
5068 if (context && program)
5069 {
5070 gl::Program *programObject = context->getProgram(program);
5071
5072 if (programObject)
5073 {
5074 return GL_TRUE;
5075 }
5076 }
5077 }
5078 catch(std::bad_alloc&)
5079 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005080 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005081 }
5082
5083 return GL_FALSE;
5084}
5085
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005086GLboolean __stdcall glIsQueryEXT(GLuint id)
5087{
5088 EVENT("(GLuint id = %d)", id);
5089
5090 try
5091 {
5092 if (id == 0)
5093 {
5094 return GL_FALSE;
5095 }
5096
5097 gl::Context *context = gl::getNonLostContext();
5098
5099 if (context)
5100 {
5101 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5102
5103 if (queryObject)
5104 {
5105 return GL_TRUE;
5106 }
5107 }
5108 }
5109 catch(std::bad_alloc&)
5110 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005111 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00005112 }
5113
5114 return GL_FALSE;
5115}
5116
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005117GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
5118{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005119 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005120
5121 try
5122 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005123 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005124
5125 if (context && renderbuffer)
5126 {
5127 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
5128
5129 if (renderbufferObject)
5130 {
5131 return GL_TRUE;
5132 }
5133 }
5134 }
5135 catch(std::bad_alloc&)
5136 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005137 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005138 }
5139
5140 return GL_FALSE;
5141}
5142
5143GLboolean __stdcall glIsShader(GLuint shader)
5144{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005145 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005146
5147 try
5148 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005149 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005150
5151 if (context && shader)
5152 {
5153 gl::Shader *shaderObject = context->getShader(shader);
5154
5155 if (shaderObject)
5156 {
5157 return GL_TRUE;
5158 }
5159 }
5160 }
5161 catch(std::bad_alloc&)
5162 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005163 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005164 }
5165
5166 return GL_FALSE;
5167}
5168
5169GLboolean __stdcall glIsTexture(GLuint texture)
5170{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005171 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005172
5173 try
5174 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005175 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005176
5177 if (context && texture)
5178 {
5179 gl::Texture *textureObject = context->getTexture(texture);
5180
5181 if (textureObject)
5182 {
5183 return GL_TRUE;
5184 }
5185 }
5186 }
5187 catch(std::bad_alloc&)
5188 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005189 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005190 }
5191
5192 return GL_FALSE;
5193}
5194
5195void __stdcall glLineWidth(GLfloat width)
5196{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005197 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005198
5199 try
5200 {
5201 if (width <= 0.0f)
5202 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005203 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005204 }
5205
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005206 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00005207
5208 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005209 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005210 context->setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005211 }
5212 }
5213 catch(std::bad_alloc&)
5214 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005215 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005216 }
5217}
5218
5219void __stdcall glLinkProgram(GLuint program)
5220{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005221 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005222
5223 try
5224 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005225 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005226
5227 if (context)
5228 {
5229 gl::Program *programObject = context->getProgram(program);
5230
5231 if (!programObject)
5232 {
daniel@transgaming.com277b7142010-04-13 03:26:44 +00005233 if (context->getShader(program))
5234 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005235 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00005236 }
5237 else
5238 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005239 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com277b7142010-04-13 03:26:44 +00005240 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005241 }
5242
daniel@transgaming.com95d29422012-07-24 18:36:10 +00005243 context->linkProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005244 }
5245 }
5246 catch(std::bad_alloc&)
5247 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005248 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005249 }
5250}
5251
5252void __stdcall glPixelStorei(GLenum pname, GLint param)
5253{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005254 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005255
5256 try
5257 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005258 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005259
5260 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005261 {
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005262 switch (pname)
5263 {
5264 case GL_UNPACK_ALIGNMENT:
5265 if (param != 1 && param != 2 && param != 4 && param != 8)
5266 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005267 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005268 }
5269
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005270 context->setUnpackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005271 break;
5272
5273 case GL_PACK_ALIGNMENT:
5274 if (param != 1 && param != 2 && param != 4 && param != 8)
5275 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005276 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005277 }
5278
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005279 context->setPackAlignment(param);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005280 break;
5281
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00005282 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
5283 context->setPackReverseRowOrder(param != 0);
5284 break;
5285
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005286 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005287 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00005288 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005289 }
5290 }
5291 catch(std::bad_alloc&)
5292 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005293 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005294 }
5295}
5296
5297void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
5298{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005299 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005300
5301 try
5302 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005303 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.comaede6302010-04-29 03:35:48 +00005304
5305 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005306 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005307 context->setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005308 }
5309 }
5310 catch(std::bad_alloc&)
5311 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005312 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005313 }
5314}
5315
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00005316void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
5317 GLenum format, GLenum type, GLsizei bufSize,
5318 GLvoid *data)
5319{
5320 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
5321 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
5322 x, y, width, height, format, type, bufSize, data);
5323
5324 try
5325 {
5326 if (width < 0 || height < 0 || bufSize < 0)
5327 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005328 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00005329 }
5330
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00005331 gl::Context *context = gl::getNonLostContext();
5332
5333 if (context)
5334 {
daniel@transgaming.com42944b02012-09-27 17:45:57 +00005335 GLenum currentFormat, currentType;
5336
5337 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
5338 // and attempting to read back if that's the case is an error. The error will be registered
5339 // by getCurrentReadFormat.
5340 if (!context->getCurrentReadFormatType(&currentFormat, &currentType))
5341 return;
5342
5343 if (!(currentFormat == format && currentType == type) && !validReadFormatType(format, type))
5344 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005345 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00005346 }
5347
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00005348 context->readPixels(x, y, width, height, format, type, &bufSize, data);
5349 }
5350 }
5351 catch(std::bad_alloc&)
5352 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005353 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00005354 }
5355}
5356
5357void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
5358 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005359{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005360 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005361 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00005362 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005363
5364 try
5365 {
5366 if (width < 0 || height < 0)
5367 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005368 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005369 }
5370
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005371 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005372
5373 if (context)
5374 {
daniel@transgaming.com42944b02012-09-27 17:45:57 +00005375 GLenum currentFormat, currentType;
5376
5377 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
5378 // and attempting to read back if that's the case is an error. The error will be registered
5379 // by getCurrentReadFormat.
5380 if (!context->getCurrentReadFormatType(&currentFormat, &currentType))
5381 return;
5382
5383 if (!(currentFormat == format && currentType == type) && !validReadFormatType(format, type))
5384 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005385 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com42944b02012-09-27 17:45:57 +00005386 }
5387
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00005388 context->readPixels(x, y, width, height, format, type, NULL, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005389 }
5390 }
5391 catch(std::bad_alloc&)
5392 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005393 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005394 }
5395}
5396
5397void __stdcall glReleaseShaderCompiler(void)
5398{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005399 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005400
5401 try
5402 {
5403 gl::Shader::releaseCompiler();
5404 }
5405 catch(std::bad_alloc&)
5406 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005407 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005408 }
5409}
5410
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005411void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005412{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005413 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 +00005414 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005415
5416 try
5417 {
5418 switch (target)
5419 {
5420 case GL_RENDERBUFFER:
5421 break;
5422 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005423 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005424 }
5425
daniel@transgaming.comedc19182010-10-15 17:57:55 +00005426 if (!gl::IsColorRenderable(internalformat) && !gl::IsDepthRenderable(internalformat) && !gl::IsStencilRenderable(internalformat))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005427 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005428 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005429 }
5430
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005431 if (width < 0 || height < 0 || samples < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005432 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005433 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005434 }
5435
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005436 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005437
5438 if (context)
5439 {
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005440 if (width > context->getMaximumRenderbufferDimension() ||
5441 height > context->getMaximumRenderbufferDimension() ||
5442 samples > context->getMaxSupportedSamples())
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005443 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005444 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005445 }
5446
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00005447 GLuint handle = context->getRenderbufferHandle();
5448 if (handle == 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005449 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005450 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005451 }
5452
5453 switch (internalformat)
5454 {
5455 case GL_DEPTH_COMPONENT16:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005456 case GL_RGBA4:
5457 case GL_RGB5_A1:
5458 case GL_RGB565:
daniel@transgaming.com63977542010-08-24 19:21:02 +00005459 case GL_RGB8_OES:
5460 case GL_RGBA8_OES:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005461 case GL_STENCIL_INDEX8:
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +00005462 case GL_DEPTH24_STENCIL8_OES:
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00005463 break;
5464 case GL_SRGB8_ALPHA8:
5465 case GL_RGB10_A2:
5466 case GL_RG8:
5467 case GL_R8:
5468 if (context->getClientVersion() < 3)
5469 {
5470 return gl::error(GL_INVALID_ENUM);
5471 }
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +00005472 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005473 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005474 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005475 }
shannon.woods%transgaming.com@gtempaccount.com8dce6512013-04-13 03:42:19 +00005476
5477 context->setRenderbufferStorage(width, height, internalformat, samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005478 }
5479 }
5480 catch(std::bad_alloc&)
5481 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005482 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005483 }
5484}
5485
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00005486void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
5487{
5488 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
5489}
5490
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005491void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
5492{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005493 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005494
5495 try
5496 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005497 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005498
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005499 if (context)
5500 {
daniel@transgaming.coma36f98e2010-05-18 18:51:09 +00005501 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005502 }
5503 }
5504 catch(std::bad_alloc&)
5505 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005506 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005507 }
5508}
5509
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005510void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
5511{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005512 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005513
5514 try
5515 {
5516 if (condition != GL_ALL_COMPLETED_NV)
5517 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005518 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005519 }
5520
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005521 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005522
5523 if (context)
5524 {
5525 gl::Fence *fenceObject = context->getFence(fence);
5526
5527 if (fenceObject == NULL)
5528 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005529 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005530 }
5531
5532 fenceObject->setFence(condition);
5533 }
5534 }
5535 catch(std::bad_alloc&)
5536 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005537 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005538 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005539}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005540
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005541void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
5542{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005543 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 +00005544
5545 try
5546 {
5547 if (width < 0 || height < 0)
5548 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005549 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005550 }
5551
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005552 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005553
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005554 if (context)
5555 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005556 context->setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005557 }
5558 }
5559 catch(std::bad_alloc&)
5560 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005561 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005562 }
5563}
5564
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005565void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005566{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005567 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005568 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00005569 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005570
5571 try
5572 {
daniel@transgaming.comd1f667f2010-04-29 03:38:52 +00005573 // No binary shader formats are supported.
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005574 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005575 }
5576 catch(std::bad_alloc&)
5577 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005578 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005579 }
5580}
5581
shannon.woods%transgaming.com@gtempaccount.com5f339332013-04-13 03:29:02 +00005582void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005583{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005584 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 +00005585 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005586
5587 try
5588 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00005589 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005590 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005591 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005592 }
5593
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005594 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005595
5596 if (context)
5597 {
5598 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005599
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005600 if (!shaderObject)
5601 {
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00005602 if (context->getProgram(shader))
5603 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005604 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00005605 }
5606 else
5607 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005608 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com8e6a6be2010-04-13 03:26:41 +00005609 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005610 }
5611
5612 shaderObject->setSource(count, string, length);
5613 }
5614 }
5615 catch(std::bad_alloc&)
5616 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005617 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005618 }
5619}
5620
5621void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
5622{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005623 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005624}
5625
5626void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
5627{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005628 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 +00005629
5630 try
5631 {
5632 switch (face)
5633 {
5634 case GL_FRONT:
5635 case GL_BACK:
5636 case GL_FRONT_AND_BACK:
5637 break;
5638 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005639 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005640 }
5641
5642 switch (func)
5643 {
5644 case GL_NEVER:
5645 case GL_ALWAYS:
5646 case GL_LESS:
5647 case GL_LEQUAL:
5648 case GL_EQUAL:
5649 case GL_GEQUAL:
5650 case GL_GREATER:
5651 case GL_NOTEQUAL:
5652 break;
5653 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005654 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005655 }
5656
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005657 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005658
5659 if (context)
5660 {
5661 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
5662 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005663 context->setStencilParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005664 }
5665
5666 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
5667 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005668 context->setStencilBackParams(func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005669 }
5670 }
5671 }
5672 catch(std::bad_alloc&)
5673 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005674 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005675 }
5676}
5677
5678void __stdcall glStencilMask(GLuint mask)
5679{
5680 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5681}
5682
5683void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
5684{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005685 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005686
5687 try
5688 {
5689 switch (face)
5690 {
5691 case GL_FRONT:
5692 case GL_BACK:
5693 case GL_FRONT_AND_BACK:
5694 break;
5695 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005696 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005697 }
5698
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005699 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005700
5701 if (context)
5702 {
5703 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
5704 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005705 context->setStencilWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005706 }
5707
5708 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
5709 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005710 context->setStencilBackWritemask(mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005711 }
5712 }
5713 }
5714 catch(std::bad_alloc&)
5715 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005716 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005717 }
5718}
5719
5720void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5721{
5722 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5723}
5724
5725void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
5726{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005727 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 +00005728 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005729
5730 try
5731 {
5732 switch (face)
5733 {
5734 case GL_FRONT:
5735 case GL_BACK:
5736 case GL_FRONT_AND_BACK:
5737 break;
5738 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005739 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005740 }
5741
5742 switch (fail)
5743 {
5744 case GL_ZERO:
5745 case GL_KEEP:
5746 case GL_REPLACE:
5747 case GL_INCR:
5748 case GL_DECR:
5749 case GL_INVERT:
5750 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005751 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005752 break;
5753 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005754 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005755 }
5756
5757 switch (zfail)
5758 {
5759 case GL_ZERO:
5760 case GL_KEEP:
5761 case GL_REPLACE:
5762 case GL_INCR:
5763 case GL_DECR:
5764 case GL_INVERT:
5765 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005766 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005767 break;
5768 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005769 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005770 }
5771
5772 switch (zpass)
5773 {
5774 case GL_ZERO:
5775 case GL_KEEP:
5776 case GL_REPLACE:
5777 case GL_INCR:
5778 case GL_DECR:
5779 case GL_INVERT:
5780 case GL_INCR_WRAP:
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005781 case GL_DECR_WRAP:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005782 break;
5783 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005784 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005785 }
5786
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005787 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005788
5789 if (context)
5790 {
5791 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
5792 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005793 context->setStencilOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005794 }
5795
5796 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
5797 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00005798 context->setStencilBackOperations(fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005799 }
5800 }
5801 }
5802 catch(std::bad_alloc&)
5803 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005804 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005805 }
5806}
5807
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005808GLboolean __stdcall glTestFenceNV(GLuint fence)
5809{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005810 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005811
5812 try
5813 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005814 gl::Context *context = gl::getNonLostContext();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005815
5816 if (context)
5817 {
5818 gl::Fence *fenceObject = context->getFence(fence);
5819
5820 if (fenceObject == NULL)
5821 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005822 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005823 }
5824
5825 return fenceObject->testFence();
5826 }
5827 }
5828 catch(std::bad_alloc&)
5829 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005830 gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005831 }
5832
5833 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00005834}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00005835
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00005836void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
5837 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005838{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00005839 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 +00005840 "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 +00005841 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005842
5843 try
5844 {
shannon.woods%transgaming.com@gtempaccount.com6d73c4e2013-04-13 03:45:12 +00005845 if (!validImageSize(level, width, height, 1))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005846 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005847 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005848 }
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00005849
apatrick@chromium.orge057c5d2012-01-26 19:18:24 +00005850 if (internalformat != GLint(format))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005851 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005852 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005853 }
5854
daniel@transgaming.com6377e362012-06-05 19:49:55 +00005855 // validate <type> by itself (used as secondary key below)
5856 switch (type)
5857 {
5858 case GL_UNSIGNED_BYTE:
5859 case GL_UNSIGNED_SHORT_5_6_5:
5860 case GL_UNSIGNED_SHORT_4_4_4_4:
5861 case GL_UNSIGNED_SHORT_5_5_5_1:
5862 case GL_UNSIGNED_SHORT:
5863 case GL_UNSIGNED_INT:
5864 case GL_UNSIGNED_INT_24_8_OES:
5865 case GL_HALF_FLOAT_OES:
5866 case GL_FLOAT:
5867 break;
5868 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005869 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com6377e362012-06-05 19:49:55 +00005870 }
5871
5872 // validate <format> + <type> combinations
5873 // - invalid <format> -> sets INVALID_ENUM
5874 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00005875 switch (format)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005876 {
5877 case GL_ALPHA:
5878 case GL_LUMINANCE:
5879 case GL_LUMINANCE_ALPHA:
5880 switch (type)
5881 {
5882 case GL_UNSIGNED_BYTE:
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00005883 case GL_FLOAT:
5884 case GL_HALF_FLOAT_OES:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005885 break;
5886 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005887 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005888 }
5889 break;
5890 case GL_RGB:
5891 switch (type)
5892 {
5893 case GL_UNSIGNED_BYTE:
5894 case GL_UNSIGNED_SHORT_5_6_5:
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00005895 case GL_FLOAT:
5896 case GL_HALF_FLOAT_OES:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005897 break;
5898 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005899 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005900 }
5901 break;
5902 case GL_RGBA:
5903 switch (type)
5904 {
5905 case GL_UNSIGNED_BYTE:
5906 case GL_UNSIGNED_SHORT_4_4_4_4:
5907 case GL_UNSIGNED_SHORT_5_5_5_1:
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00005908 case GL_FLOAT:
5909 case GL_HALF_FLOAT_OES:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005910 break;
5911 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005912 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005913 }
5914 break;
daniel@transgaming.coma9198d92010-08-08 04:49:56 +00005915 case GL_BGRA_EXT:
5916 switch (type)
5917 {
5918 case GL_UNSIGNED_BYTE:
5919 break;
5920 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005921 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.coma9198d92010-08-08 04:49:56 +00005922 }
5923 break;
daniel@transgaming.com01868132010-08-24 19:21:17 +00005924 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are handled below
5925 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
gman@chromium.org50c526d2011-08-10 05:19:44 +00005926 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
5927 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
daniel@transgaming.com01868132010-08-24 19:21:17 +00005928 break;
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00005929 case GL_DEPTH_COMPONENT:
5930 switch (type)
5931 {
5932 case GL_UNSIGNED_SHORT:
5933 case GL_UNSIGNED_INT:
5934 break;
5935 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005936 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00005937 }
5938 break;
5939 case GL_DEPTH_STENCIL_OES:
5940 switch (type)
5941 {
5942 case GL_UNSIGNED_INT_24_8_OES:
5943 break;
5944 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005945 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00005946 }
5947 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005948 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005949 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005950 }
5951
5952 if (border != 0)
5953 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005954 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005955 }
5956
daniel@transgaming.com9d788502011-11-09 17:46:55 +00005957 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005958
5959 if (context)
5960 {
daniel@transgaming.com32b11442011-11-19 02:42:48 +00005961 if (level > context->getMaximumTextureLevel())
5962 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005963 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com32b11442011-11-19 02:42:48 +00005964 }
5965
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005966 switch (target)
5967 {
5968 case GL_TEXTURE_2D:
shannon.woods%transgaming.com@gtempaccount.comc1fdf6b2013-04-13 03:44:41 +00005969 if (width > (context->getMaximum2DTextureDimension() >> level) ||
5970 height > (context->getMaximum2DTextureDimension() >> level))
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005971 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005972 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005973 }
5974 break;
5975 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
5976 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
5977 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
5978 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
5979 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
5980 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
5981 if (width != height)
5982 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005983 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005984 }
5985
5986 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
5987 height > (context->getMaximumCubeTextureDimension() >> level))
5988 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005989 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005990 }
5991 break;
5992 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00005993 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00005994 }
5995
gman@chromium.org50c526d2011-08-10 05:19:44 +00005996 switch (format) {
5997 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
5998 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
5999 if (context->supportsDXT1Textures())
daniel@transgaming.com01868132010-08-24 19:21:17 +00006000 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006001 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com01868132010-08-24 19:21:17 +00006002 }
6003 else
6004 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006005 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com01868132010-08-24 19:21:17 +00006006 }
gman@chromium.org50c526d2011-08-10 05:19:44 +00006007 break;
6008 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
6009 if (context->supportsDXT3Textures())
6010 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006011 return gl::error(GL_INVALID_OPERATION);
gman@chromium.org50c526d2011-08-10 05:19:44 +00006012 }
6013 else
6014 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006015 return gl::error(GL_INVALID_ENUM);
gman@chromium.org50c526d2011-08-10 05:19:44 +00006016 }
6017 break;
6018 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
6019 if (context->supportsDXT5Textures())
6020 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006021 return gl::error(GL_INVALID_OPERATION);
gman@chromium.org50c526d2011-08-10 05:19:44 +00006022 }
6023 else
6024 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006025 return gl::error(GL_INVALID_ENUM);
gman@chromium.org50c526d2011-08-10 05:19:44 +00006026 }
6027 break;
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006028 case GL_DEPTH_COMPONENT:
6029 case GL_DEPTH_STENCIL_OES:
6030 if (!context->supportsDepthTextures())
6031 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006032 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006033 }
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006034 if (target != GL_TEXTURE_2D)
6035 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006036 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006037 }
daniel@transgaming.com797924b2012-06-05 19:50:01 +00006038 // OES_depth_texture supports loading depth data and multiple levels,
6039 // but ANGLE_depth_texture does not
6040 if (pixels != NULL || level != 0)
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006041 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006042 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006043 }
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006044 break;
gman@chromium.org50c526d2011-08-10 05:19:44 +00006045 default:
6046 break;
daniel@transgaming.com01868132010-08-24 19:21:17 +00006047 }
6048
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006049 if (type == GL_FLOAT)
6050 {
daniel@transgaming.combbeffbb2011-11-09 17:46:11 +00006051 if (!context->supportsFloat32Textures())
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006052 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006053 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006054 }
6055 }
6056 else if (type == GL_HALF_FLOAT_OES)
6057 {
daniel@transgaming.combbeffbb2011-11-09 17:46:11 +00006058 if (!context->supportsFloat16Textures())
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006059 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006060 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006061 }
6062 }
6063
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006064 if (target == GL_TEXTURE_2D)
6065 {
6066 gl::Texture2D *texture = context->getTexture2D();
6067
6068 if (!texture)
6069 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006070 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006071 }
6072
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006073 if (texture->isImmutable())
6074 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006075 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006076 }
6077
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006078 texture->setImage(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006079 }
6080 else
6081 {
6082 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6083
6084 if (!texture)
6085 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006086 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006087 }
6088
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006089 if (texture->isImmutable())
6090 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006091 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006092 }
6093
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006094 switch (target)
6095 {
6096 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006097 texture->setImagePosX(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006098 break;
6099 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006100 texture->setImageNegX(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006101 break;
6102 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006103 texture->setImagePosY(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006104 break;
6105 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006106 texture->setImageNegY(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006107 break;
6108 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006109 texture->setImagePosZ(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006110 break;
6111 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
daniel@transgaming.com8a0a2db2011-03-21 16:38:20 +00006112 texture->setImageNegZ(level, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006113 break;
6114 default: UNREACHABLE();
6115 }
6116 }
6117 }
6118 }
6119 catch(std::bad_alloc&)
6120 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006121 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006122 }
6123}
6124
6125void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
6126{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006127 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
6128
6129 try
6130 {
6131 gl::Context *context = gl::getNonLostContext();
6132
6133 if (context)
6134 {
6135 gl::Texture *texture;
6136
6137 switch (target)
6138 {
6139 case GL_TEXTURE_2D:
6140 texture = context->getTexture2D();
6141 break;
6142 case GL_TEXTURE_CUBE_MAP:
6143 texture = context->getTextureCubeMap();
6144 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006145 case GL_TEXTURE_3D:
6146 if (context->getClientVersion() < 3)
6147 {
6148 return gl::error(GL_INVALID_ENUM);
6149 }
6150 texture = context->getTexture3D();
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00006151 case GL_TEXTURE_2D_ARRAY:
6152 if (context->getClientVersion() < 3)
6153 {
6154 return gl::error(GL_INVALID_ENUM);
6155 }
6156 texture = context->getTexture2DArray();
6157 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006158 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006159 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006160 }
6161
6162 switch (pname)
6163 {
6164 case GL_TEXTURE_WRAP_S:
6165 if (!texture->setWrapS((GLenum)param))
6166 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006167 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006168 }
6169 break;
6170 case GL_TEXTURE_WRAP_T:
6171 if (!texture->setWrapT((GLenum)param))
6172 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006173 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006174 }
6175 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00006176 case GL_TEXTURE_WRAP_R:
6177 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
6178 {
6179 return gl::error(GL_INVALID_ENUM);
6180 }
6181 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006182 case GL_TEXTURE_MIN_FILTER:
6183 if (!texture->setMinFilter((GLenum)param))
6184 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006185 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006186 }
6187 break;
6188 case GL_TEXTURE_MAG_FILTER:
6189 if (!texture->setMagFilter((GLenum)param))
6190 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006191 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006192 }
6193 break;
6194 case GL_TEXTURE_USAGE_ANGLE:
6195 if (!texture->setUsage((GLenum)param))
6196 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006197 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006198 }
6199 break;
6200 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
6201 if (!context->supportsTextureFilterAnisotropy())
6202 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006203 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006204 }
6205 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
6206 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006207 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006208 }
6209 break;
6210 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006211 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006212 }
6213 }
6214 }
6215 catch(std::bad_alloc&)
6216 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006217 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006218 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006219}
6220
6221void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
6222{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006223 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006224}
6225
6226void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
6227{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006228 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006229
6230 try
6231 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006232 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006233
6234 if (context)
6235 {
6236 gl::Texture *texture;
6237
6238 switch (target)
6239 {
6240 case GL_TEXTURE_2D:
6241 texture = context->getTexture2D();
6242 break;
6243 case GL_TEXTURE_CUBE_MAP:
6244 texture = context->getTextureCubeMap();
6245 break;
shannon.woods%transgaming.com@gtempaccount.comc416e1c2013-04-13 03:45:05 +00006246 case GL_TEXTURE_3D:
6247 if (context->getClientVersion() < 3)
6248 {
6249 return gl::error(GL_INVALID_ENUM);
6250 }
6251 texture = context->getTexture3D();
6252 break;
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00006253 case GL_TEXTURE_2D_ARRAY:
6254 if (context->getClientVersion() < 3)
6255 {
6256 return gl::error(GL_INVALID_ENUM);
6257 }
6258 texture = context->getTexture2DArray();
6259 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006260 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006261 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006262 }
6263
6264 switch (pname)
6265 {
6266 case GL_TEXTURE_WRAP_S:
6267 if (!texture->setWrapS((GLenum)param))
6268 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006269 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006270 }
6271 break;
6272 case GL_TEXTURE_WRAP_T:
6273 if (!texture->setWrapT((GLenum)param))
6274 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006275 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006276 }
6277 break;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +00006278 case GL_TEXTURE_WRAP_R:
6279 if (context->getClientVersion() < 3 || !texture->setWrapR((GLenum)param))
6280 {
6281 return gl::error(GL_INVALID_ENUM);
6282 }
6283 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006284 case GL_TEXTURE_MIN_FILTER:
6285 if (!texture->setMinFilter((GLenum)param))
6286 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006287 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006288 }
6289 break;
6290 case GL_TEXTURE_MAG_FILTER:
6291 if (!texture->setMagFilter((GLenum)param))
6292 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006293 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006294 }
6295 break;
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00006296 case GL_TEXTURE_USAGE_ANGLE:
6297 if (!texture->setUsage((GLenum)param))
6298 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006299 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com7d18c172011-11-11 04:18:21 +00006300 }
6301 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006302 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
6303 if (!context->supportsTextureFilterAnisotropy())
6304 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006305 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006306 }
6307 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
6308 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006309 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00006310 }
6311 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006312 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006313 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006314 }
6315 }
6316 }
6317 catch(std::bad_alloc&)
6318 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006319 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006320 }
6321}
6322
6323void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
6324{
6325 glTexParameteri(target, pname, *params);
6326}
6327
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006328void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
6329{
6330 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
6331 target, levels, internalformat, width, height);
6332
6333 try
6334 {
6335 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP)
6336 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006337 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006338 }
6339
6340 if (width < 1 || height < 1 || levels < 1)
6341 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006342 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006343 }
6344
6345 if (target == GL_TEXTURE_CUBE_MAP && width != height)
6346 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006347 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006348 }
6349
daniel@transgaming.com45b888a2011-11-16 03:56:39 +00006350 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006351 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006352 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006353 }
6354
6355 GLenum format = gl::ExtractFormat(internalformat);
6356 GLenum type = gl::ExtractType(internalformat);
6357
6358 if (format == GL_NONE || type == GL_NONE)
6359 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006360 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006361 }
6362
6363 gl::Context *context = gl::getNonLostContext();
6364
6365 if (context)
6366 {
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006367 switch (target)
6368 {
6369 case GL_TEXTURE_2D:
shannon.woods%transgaming.com@gtempaccount.comc1fdf6b2013-04-13 03:44:41 +00006370 if (width > context->getMaximum2DTextureDimension() ||
6371 height > context->getMaximum2DTextureDimension())
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006372 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006373 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006374 }
6375 break;
6376 case GL_TEXTURE_CUBE_MAP:
6377 if (width > context->getMaximumCubeTextureDimension() ||
6378 height > context->getMaximumCubeTextureDimension())
6379 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006380 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006381 }
6382 break;
6383 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006384 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com21f05d72011-11-29 19:42:28 +00006385 }
6386
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006387 if (levels != 1 && !context->supportsNonPower2Texture())
6388 {
6389 if (!gl::isPow2(width) || !gl::isPow2(height))
6390 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006391 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006392 }
6393 }
6394
daniel@transgaming.come1077362011-11-11 04:16:50 +00006395 switch (internalformat)
6396 {
6397 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
6398 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
6399 if (!context->supportsDXT1Textures())
6400 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006401 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come1077362011-11-11 04:16:50 +00006402 }
6403 break;
6404 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
6405 if (!context->supportsDXT3Textures())
6406 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006407 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come1077362011-11-11 04:16:50 +00006408 }
6409 break;
6410 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
6411 if (!context->supportsDXT5Textures())
6412 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006413 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.come1077362011-11-11 04:16:50 +00006414 }
6415 break;
daniel@transgaming.comff941aa2011-11-11 04:17:09 +00006416 case GL_RGBA32F_EXT:
6417 case GL_RGB32F_EXT:
6418 case GL_ALPHA32F_EXT:
6419 case GL_LUMINANCE32F_EXT:
6420 case GL_LUMINANCE_ALPHA32F_EXT:
6421 if (!context->supportsFloat32Textures())
6422 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006423 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comff941aa2011-11-11 04:17:09 +00006424 }
6425 break;
6426 case GL_RGBA16F_EXT:
6427 case GL_RGB16F_EXT:
6428 case GL_ALPHA16F_EXT:
6429 case GL_LUMINANCE16F_EXT:
6430 case GL_LUMINANCE_ALPHA16F_EXT:
6431 if (!context->supportsFloat16Textures())
6432 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006433 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.comff941aa2011-11-11 04:17:09 +00006434 }
6435 break;
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006436 case GL_DEPTH_COMPONENT16:
6437 case GL_DEPTH_COMPONENT32_OES:
6438 case GL_DEPTH24_STENCIL8_OES:
6439 if (!context->supportsDepthTextures())
6440 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006441 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006442 }
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006443 if (target != GL_TEXTURE_2D)
6444 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006445 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006446 }
daniel@transgaming.com797924b2012-06-05 19:50:01 +00006447 // ANGLE_depth_texture only supports 1-level textures
6448 if (levels != 1)
6449 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006450 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com797924b2012-06-05 19:50:01 +00006451 }
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006452 break;
6453 default:
6454 break;
daniel@transgaming.come1077362011-11-11 04:16:50 +00006455 }
6456
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006457 if (target == GL_TEXTURE_2D)
6458 {
6459 gl::Texture2D *texture = context->getTexture2D();
6460
6461 if (!texture || texture->id() == 0)
6462 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006463 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006464 }
6465
6466 if (texture->isImmutable())
6467 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006468 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006469 }
6470
6471 texture->storage(levels, internalformat, width, height);
6472 }
6473 else if (target == GL_TEXTURE_CUBE_MAP)
6474 {
6475 gl::TextureCubeMap *texture = context->getTextureCubeMap();
6476
6477 if (!texture || texture->id() == 0)
6478 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006479 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006480 }
6481
6482 if (texture->isImmutable())
6483 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006484 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006485 }
6486
6487 texture->storage(levels, internalformat, width);
6488 }
6489 else UNREACHABLE();
6490 }
6491 }
6492 catch(std::bad_alloc&)
6493 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006494 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00006495 }
6496}
6497
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006498void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
6499 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006500{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006501 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006502 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00006503 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006504 target, level, xoffset, yoffset, width, height, format, type, pixels);
6505
6506 try
6507 {
apatrick@chromium.org551022e2012-01-23 19:56:54 +00006508 if (!gl::IsInternalTextureTarget(target))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006509 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006510 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006511 }
6512
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006513 if (level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006514 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006515 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006516 }
6517
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006518 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
6519 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006520 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006521 }
6522
daniel@transgaming.com8833dd22012-06-05 19:49:58 +00006523 if (!checkTextureFormatType(format, type))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006524 {
daniel@transgaming.com8833dd22012-06-05 19:49:58 +00006525 return; // error is set by helper function
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006526 }
6527
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006528 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006529
6530 if (context)
6531 {
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006532 if (level > context->getMaximumTextureLevel())
6533 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006534 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com5d752f22010-10-07 13:37:20 +00006535 }
6536
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006537 if (format == GL_FLOAT)
6538 {
daniel@transgaming.combbeffbb2011-11-09 17:46:11 +00006539 if (!context->supportsFloat32Textures())
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006540 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006541 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006542 }
6543 }
6544 else if (format == GL_HALF_FLOAT_OES)
6545 {
daniel@transgaming.combbeffbb2011-11-09 17:46:11 +00006546 if (!context->supportsFloat16Textures())
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006547 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006548 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006549 }
6550 }
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006551 else if (gl::IsDepthTexture(format))
6552 {
6553 if (!context->supportsDepthTextures())
6554 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006555 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006556 }
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006557 if (target != GL_TEXTURE_2D)
6558 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006559 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com0c854682012-05-31 01:14:11 +00006560 }
6561 // OES_depth_texture supports loading depth data, but ANGLE_depth_texture does not
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006562 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com835a95a2012-05-31 01:14:07 +00006563 }
daniel@transgaming.com0a337e92010-08-28 17:38:27 +00006564
daniel@transgaming.com1d2d3c42012-05-31 01:14:15 +00006565 if (width == 0 || height == 0 || pixels == NULL)
6566 {
6567 return;
6568 }
6569
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006570 if (target == GL_TEXTURE_2D)
6571 {
6572 gl::Texture2D *texture = context->getTexture2D();
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00006573 if (validateSubImageParams2D(false, width, height, xoffset, yoffset, level, format, type, texture))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006574 {
daniel@transgaming.com343373a2011-11-29 19:42:32 +00006575 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006576 }
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006577 }
daniel@transgaming.com19ffc242010-05-04 03:35:21 +00006578 else if (gl::IsCubemapTextureTarget(target))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006579 {
6580 gl::TextureCubeMap *texture = context->getTextureCubeMap();
daniel@transgaming.com6452adf2012-10-17 18:22:35 +00006581 if (validateSubImageParamsCube(false, width, height, xoffset, yoffset, target, level, format, type, texture))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006582 {
daniel@transgaming.com343373a2011-11-29 19:42:32 +00006583 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006584 }
daniel@transgaming.com00c75962010-03-11 20:36:15 +00006585 }
6586 else
6587 {
6588 UNREACHABLE();
6589 }
6590 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006591 }
6592 catch(std::bad_alloc&)
6593 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006594 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006595 }
6596}
6597
6598void __stdcall glUniform1f(GLint location, GLfloat x)
6599{
6600 glUniform1fv(location, 1, &x);
6601}
6602
6603void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
6604{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006605 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006606
6607 try
6608 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006609 if (count < 0)
6610 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006611 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006612 }
6613
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006614 if (location == -1)
6615 {
6616 return;
6617 }
6618
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006619 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006620
6621 if (context)
6622 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006623 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006624 if (!programBinary)
6625 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006626 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006627 }
6628
6629 if (!programBinary->setUniform1fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006630 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006631 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006632 }
6633 }
6634 }
6635 catch(std::bad_alloc&)
6636 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006637 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006638 }
6639}
6640
6641void __stdcall glUniform1i(GLint location, GLint x)
6642{
6643 glUniform1iv(location, 1, &x);
6644}
6645
6646void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
6647{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006648 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006649
6650 try
6651 {
6652 if (count < 0)
6653 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006654 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006655 }
6656
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006657 if (location == -1)
6658 {
6659 return;
6660 }
6661
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006662 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006663
6664 if (context)
6665 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006666 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006667 if (!programBinary)
6668 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006669 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006670 }
6671
6672 if (!programBinary->setUniform1iv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006673 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006674 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006675 }
6676 }
6677 }
6678 catch(std::bad_alloc&)
6679 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006680 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006681 }
6682}
6683
6684void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
6685{
6686 GLfloat xy[2] = {x, y};
6687
6688 glUniform2fv(location, 1, (GLfloat*)&xy);
6689}
6690
6691void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
6692{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006693 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006694
6695 try
6696 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006697 if (count < 0)
6698 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006699 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006700 }
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006701
6702 if (location == -1)
6703 {
6704 return;
6705 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006706
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006707 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006708
6709 if (context)
6710 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006711 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006712 if (!programBinary)
6713 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006714 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006715 }
6716
6717 if (!programBinary->setUniform2fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006718 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006719 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006720 }
6721 }
6722 }
6723 catch(std::bad_alloc&)
6724 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006725 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006726 }
6727}
6728
6729void __stdcall glUniform2i(GLint location, GLint x, GLint y)
6730{
6731 GLint xy[4] = {x, y};
6732
6733 glUniform2iv(location, 1, (GLint*)&xy);
6734}
6735
6736void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
6737{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006738 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006739
6740 try
6741 {
6742 if (count < 0)
6743 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006744 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006745 }
6746
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006747 if (location == -1)
6748 {
6749 return;
6750 }
6751
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006752 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006753
6754 if (context)
6755 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006756 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006757 if (!programBinary)
6758 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006759 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006760 }
6761
6762 if (!programBinary->setUniform2iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006763 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006764 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006765 }
6766 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006767 }
6768 catch(std::bad_alloc&)
6769 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006770 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006771 }
6772}
6773
6774void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
6775{
6776 GLfloat xyz[3] = {x, y, z};
6777
6778 glUniform3fv(location, 1, (GLfloat*)&xyz);
6779}
6780
6781void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
6782{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006783 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006784
6785 try
6786 {
6787 if (count < 0)
6788 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006789 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006790 }
6791
6792 if (location == -1)
6793 {
6794 return;
6795 }
6796
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006797 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006798
6799 if (context)
6800 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006801 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006802 if (!programBinary)
6803 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006804 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006805 }
6806
6807 if (!programBinary->setUniform3fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006808 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006809 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006810 }
6811 }
6812 }
6813 catch(std::bad_alloc&)
6814 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006815 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006816 }
6817}
6818
6819void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
6820{
6821 GLint xyz[3] = {x, y, z};
6822
6823 glUniform3iv(location, 1, (GLint*)&xyz);
6824}
6825
6826void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
6827{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006828 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006829
6830 try
6831 {
6832 if (count < 0)
6833 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006834 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006835 }
6836
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006837 if (location == -1)
6838 {
6839 return;
6840 }
6841
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006842 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006843
6844 if (context)
6845 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006846 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006847 if (!programBinary)
6848 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006849 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006850 }
6851
6852 if (!programBinary->setUniform3iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006853 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006854 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006855 }
6856 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006857 }
6858 catch(std::bad_alloc&)
6859 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006860 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006861 }
6862}
6863
6864void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6865{
6866 GLfloat xyzw[4] = {x, y, z, w};
6867
6868 glUniform4fv(location, 1, (GLfloat*)&xyzw);
6869}
6870
6871void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
6872{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006873 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006874
6875 try
6876 {
6877 if (count < 0)
6878 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006879 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006880 }
6881
6882 if (location == -1)
6883 {
6884 return;
6885 }
6886
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006887 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006888
6889 if (context)
6890 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006891 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006892 if (!programBinary)
6893 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006894 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006895 }
6896
6897 if (!programBinary->setUniform4fv(location, count, v))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006898 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006899 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006900 }
6901 }
6902 }
6903 catch(std::bad_alloc&)
6904 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006905 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006906 }
6907}
6908
6909void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
6910{
6911 GLint xyzw[4] = {x, y, z, w};
6912
6913 glUniform4iv(location, 1, (GLint*)&xyzw);
6914}
6915
6916void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
6917{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00006918 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006919
6920 try
6921 {
6922 if (count < 0)
6923 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006924 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006925 }
6926
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006927 if (location == -1)
6928 {
6929 return;
6930 }
6931
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006932 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006933
6934 if (context)
6935 {
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006936 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006937 if (!programBinary)
6938 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006939 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006940 }
6941
6942 if (!programBinary->setUniform4iv(location, count, v))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006943 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006944 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00006945 }
6946 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006947 }
6948 catch(std::bad_alloc&)
6949 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006950 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006951 }
6952}
6953
6954void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
6955{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006956 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00006957 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006958
6959 try
6960 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00006961 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006962 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006963 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006964 }
6965
6966 if (location == -1)
6967 {
6968 return;
6969 }
6970
daniel@transgaming.com9d788502011-11-09 17:46:55 +00006971 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006972
6973 if (context)
6974 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00006975 if (transpose != GL_FALSE && context->getClientVersion() < 3)
6976 {
6977 return gl::error(GL_INVALID_VALUE);
6978 }
6979
daniel@transgaming.com62a28462012-07-24 18:33:59 +00006980 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006981 if (!programBinary)
6982 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006983 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00006984 }
6985
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00006986 if (!programBinary->setUniformMatrix2fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006987 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006988 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006989 }
6990 }
6991 }
6992 catch(std::bad_alloc&)
6993 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00006994 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00006995 }
6996}
6997
6998void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
6999{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007000 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007001 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007002
7003 try
7004 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007005 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007006 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007007 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007008 }
7009
7010 if (location == -1)
7011 {
7012 return;
7013 }
7014
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007015 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007016
7017 if (context)
7018 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007019 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7020 {
7021 return gl::error(GL_INVALID_VALUE);
7022 }
7023
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007024 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007025 if (!programBinary)
7026 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007027 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007028 }
7029
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007030 if (!programBinary->setUniformMatrix3fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007031 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007032 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007033 }
7034 }
7035 }
7036 catch(std::bad_alloc&)
7037 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007038 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007039 }
7040}
7041
7042void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
7043{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007044 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007045 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007046
7047 try
7048 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007049 if (count < 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007050 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007051 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007052 }
7053
7054 if (location == -1)
7055 {
7056 return;
7057 }
7058
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007059 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007060
7061 if (context)
7062 {
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007063 if (transpose != GL_FALSE && context->getClientVersion() < 3)
7064 {
7065 return gl::error(GL_INVALID_VALUE);
7066 }
7067
daniel@transgaming.com62a28462012-07-24 18:33:59 +00007068 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007069 if (!programBinary)
7070 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007071 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +00007072 }
7073
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00007074 if (!programBinary->setUniformMatrix4fv(location, count, transpose, value))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007075 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007076 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007077 }
7078 }
7079 }
7080 catch(std::bad_alloc&)
7081 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007082 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007083 }
7084}
7085
7086void __stdcall glUseProgram(GLuint program)
7087{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007088 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007089
7090 try
7091 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007092 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007093
7094 if (context)
7095 {
7096 gl::Program *programObject = context->getProgram(program);
7097
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007098 if (!programObject && program != 0)
7099 {
7100 if (context->getShader(program))
7101 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007102 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007103 }
7104 else
7105 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007106 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comc8478202010-04-13 19:53:35 +00007107 }
7108 }
7109
daniel@transgaming.com716056c2012-07-24 18:38:59 +00007110 if (program != 0 && !programObject->isLinked())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007111 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007112 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007113 }
7114
7115 context->useProgram(program);
7116 }
7117 }
7118 catch(std::bad_alloc&)
7119 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007120 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007121 }
7122}
7123
7124void __stdcall glValidateProgram(GLuint program)
7125{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007126 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007127
7128 try
7129 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007130 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007131
7132 if (context)
7133 {
7134 gl::Program *programObject = context->getProgram(program);
7135
7136 if (!programObject)
7137 {
7138 if (context->getShader(program))
7139 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007140 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007141 }
7142 else
7143 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007144 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007145 }
7146 }
7147
apatrick@chromium.org253b8d22012-06-22 19:27:21 +00007148 programObject->validate();
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00007149 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007150 }
7151 catch(std::bad_alloc&)
7152 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007153 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007154 }
7155}
7156
7157void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
7158{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007159 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007160
7161 try
7162 {
7163 if (index >= gl::MAX_VERTEX_ATTRIBS)
7164 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007165 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007166 }
7167
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007168 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007169
7170 if (context)
7171 {
7172 GLfloat vals[4] = { x, 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007173 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007174 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007175 }
7176 catch(std::bad_alloc&)
7177 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007178 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007179 }
7180}
7181
7182void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
7183{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007184 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007185
7186 try
7187 {
7188 if (index >= gl::MAX_VERTEX_ATTRIBS)
7189 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007190 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007191 }
7192
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007193 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007194
7195 if (context)
7196 {
7197 GLfloat vals[4] = { values[0], 0, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007198 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007199 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007200 }
7201 catch(std::bad_alloc&)
7202 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007203 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007204 }
7205}
7206
7207void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
7208{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007209 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007210
7211 try
7212 {
7213 if (index >= gl::MAX_VERTEX_ATTRIBS)
7214 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007215 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007216 }
7217
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007218 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007219
7220 if (context)
7221 {
7222 GLfloat vals[4] = { x, y, 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007223 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007224 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007225 }
7226 catch(std::bad_alloc&)
7227 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007228 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007229 }
7230}
7231
7232void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
7233{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007234 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007235
7236 try
7237 {
7238 if (index >= gl::MAX_VERTEX_ATTRIBS)
7239 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007240 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007241 }
7242
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007243 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007244
7245 if (context)
7246 {
7247 GLfloat vals[4] = { values[0], values[1], 0, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007248 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007249 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007250 }
7251 catch(std::bad_alloc&)
7252 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007253 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007254 }
7255}
7256
7257void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
7258{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007259 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 +00007260
7261 try
7262 {
7263 if (index >= gl::MAX_VERTEX_ATTRIBS)
7264 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007265 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007266 }
7267
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007268 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007269
7270 if (context)
7271 {
7272 GLfloat vals[4] = { x, y, z, 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007273 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007274 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007275 }
7276 catch(std::bad_alloc&)
7277 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007278 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007279 }
7280}
7281
7282void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
7283{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007284 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007285
7286 try
7287 {
7288 if (index >= gl::MAX_VERTEX_ATTRIBS)
7289 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007290 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007291 }
7292
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007293 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007294
7295 if (context)
7296 {
7297 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007298 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007299 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007300 }
7301 catch(std::bad_alloc&)
7302 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007303 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007304 }
7305}
7306
7307void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
7308{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007309 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 +00007310
7311 try
7312 {
7313 if (index >= gl::MAX_VERTEX_ATTRIBS)
7314 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007315 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007316 }
7317
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007318 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007319
7320 if (context)
7321 {
7322 GLfloat vals[4] = { x, y, z, w };
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007323 context->setVertexAttribf(index, vals);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007324 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007325 }
7326 catch(std::bad_alloc&)
7327 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007328 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007329 }
7330}
7331
7332void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
7333{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007334 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007335
7336 try
7337 {
7338 if (index >= gl::MAX_VERTEX_ATTRIBS)
7339 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007340 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007341 }
7342
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007343 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007344
7345 if (context)
7346 {
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007347 context->setVertexAttribf(index, values);
daniel@transgaming.come4b08c82010-04-20 18:53:06 +00007348 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007349 }
7350 catch(std::bad_alloc&)
7351 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007352 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007353 }
7354}
7355
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007356void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
7357{
7358 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
7359
7360 try
7361 {
7362 if (index >= gl::MAX_VERTEX_ATTRIBS)
7363 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007364 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007365 }
7366
7367 gl::Context *context = gl::getNonLostContext();
7368
7369 if (context)
7370 {
7371 context->setVertexAttribDivisor(index, divisor);
7372 }
7373 }
7374 catch(std::bad_alloc&)
7375 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007376 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00007377 }
7378}
7379
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00007380void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007381{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007382 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007383 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00007384 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007385
7386 try
7387 {
7388 if (index >= gl::MAX_VERTEX_ATTRIBS)
7389 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007390 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007391 }
7392
7393 if (size < 1 || size > 4)
7394 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007395 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007396 }
7397
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007398 gl::Context *context = gl::getNonLostContext();
7399
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007400 switch (type)
7401 {
7402 case GL_BYTE:
7403 case GL_UNSIGNED_BYTE:
7404 case GL_SHORT:
7405 case GL_UNSIGNED_SHORT:
7406 case GL_FIXED:
7407 case GL_FLOAT:
7408 break;
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007409 case GL_HALF_FLOAT:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00007410 case GL_INT:
7411 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00007412 case GL_INT_2_10_10_10_REV:
7413 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.com1a4e09a2013-04-13 03:33:30 +00007414 if (context && context->getClientVersion() < 3)
7415 {
7416 return gl::error(GL_INVALID_ENUM);
7417 }
7418 else
7419 {
7420 break;
7421 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007422 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007423 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007424 }
7425
7426 if (stride < 0)
7427 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007428 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007429 }
7430
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00007431 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
7432 {
7433 return gl::error(GL_INVALID_OPERATION);
7434 }
7435
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007436 if (context)
7437 {
shannon.woods%transgaming.com@gtempaccount.com8de4e6a2013-04-13 03:37:44 +00007438 context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
7439 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007440 }
7441 }
7442 catch(std::bad_alloc&)
7443 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007444 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007445 }
7446}
7447
7448void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
7449{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00007450 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 +00007451
7452 try
7453 {
7454 if (width < 0 || height < 0)
7455 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007456 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007457 }
7458
daniel@transgaming.com9d788502011-11-09 17:46:55 +00007459 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007460
7461 if (context)
7462 {
daniel@transgaming.com428d1582010-05-04 03:35:25 +00007463 context->setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007464 }
7465 }
7466 catch(std::bad_alloc&)
7467 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +00007468 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007469 }
7470}
7471
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007472// OpenGL ES 3.0 functions
7473
7474void __stdcall glReadBuffer(GLenum mode)
7475{
7476 EVENT("(GLenum mode = 0x%X)", mode);
7477
7478 try
7479 {
7480 gl::Context *context = gl::getNonLostContext();
7481
7482 if (context)
7483 {
7484 if (context->getClientVersion() < 3)
7485 {
7486 return gl::error(GL_INVALID_OPERATION);
7487 }
7488 }
7489
7490 UNIMPLEMENTED();
7491 }
7492 catch(std::bad_alloc&)
7493 {
7494 return gl::error(GL_OUT_OF_MEMORY);
7495 }
7496}
7497
7498void __stdcall glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
7499{
7500 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
7501 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
7502
7503 try
7504 {
7505 gl::Context *context = gl::getNonLostContext();
7506
7507 if (context)
7508 {
7509 if (context->getClientVersion() < 3)
7510 {
7511 return gl::error(GL_INVALID_OPERATION);
7512 }
7513 }
7514
7515 UNIMPLEMENTED();
7516 }
7517 catch(std::bad_alloc&)
7518 {
7519 return gl::error(GL_OUT_OF_MEMORY);
7520 }
7521}
7522
7523void __stdcall glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
7524{
7525 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
7526 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
7527 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
7528 target, level, internalformat, width, height, depth, border, format, type, pixels);
7529
7530 try
7531 {
7532 gl::Context *context = gl::getNonLostContext();
7533
7534 if (context)
7535 {
7536 if (context->getClientVersion() < 3)
7537 {
7538 return gl::error(GL_INVALID_OPERATION);
7539 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007540
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007541 // validateES3TexImageFormat sets the error code if there is an error
7542 if (!validateES3TexImageFormat(context, target, level, internalformat, false, false,
7543 0, 0, 0, width, height, depth, border, format, type))
7544 {
7545 return;
7546 }
7547
7548 switch(target)
7549 {
7550 case GL_TEXTURE_3D:
7551 {
7552 gl::Texture3D *texture = context->getTexture3D();
7553 texture->setImage(level, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
7554 }
7555 break;
7556
7557 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00007558 {
7559 gl::Texture2DArray *texture = context->getTexture2DArray();
7560 texture->setImage(level, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
7561 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007562 break;
7563
7564 default:
7565 return gl::error(GL_INVALID_ENUM);
7566 }
7567 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007568 }
7569 catch(std::bad_alloc&)
7570 {
7571 return gl::error(GL_OUT_OF_MEMORY);
7572 }
7573}
7574
7575void __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)
7576{
7577 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
7578 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
7579 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
7580 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
7581
7582 try
7583 {
7584 gl::Context *context = gl::getNonLostContext();
7585
7586 if (context)
7587 {
7588 if (context->getClientVersion() < 3)
7589 {
7590 return gl::error(GL_INVALID_OPERATION);
7591 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007592
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007593 if (!pixels)
7594 {
7595 return gl::error(GL_INVALID_VALUE);
7596 }
7597
7598 // validateES3TexImageFormat sets the error code if there is an error
7599 if (!validateES3TexImageFormat(context, target, level, GL_NONE, false, true,
7600 xoffset, yoffset, zoffset, width, height, depth, 0,
7601 format, type))
7602 {
7603 return;
7604 }
7605
7606 switch(target)
7607 {
7608 case GL_TEXTURE_3D:
7609 {
7610 gl::Texture3D *texture = context->getTexture3D();
7611 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
7612 }
7613 break;
7614
7615 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00007616 {
7617 gl::Texture2DArray *texture = context->getTexture2DArray();
7618 texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackAlignment(), pixels);
7619 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007620 break;
7621
7622 default:
7623 return gl::error(GL_INVALID_ENUM);
7624 }
7625 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007626 }
7627 catch(std::bad_alloc&)
7628 {
7629 return gl::error(GL_OUT_OF_MEMORY);
7630 }
7631}
7632
7633void __stdcall glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
7634{
7635 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
7636 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
7637 target, level, xoffset, yoffset, zoffset, x, y, width, height);
7638
7639 try
7640 {
7641 gl::Context *context = gl::getNonLostContext();
7642
7643 if (context)
7644 {
7645 if (context->getClientVersion() < 3)
7646 {
7647 return gl::error(GL_INVALID_OPERATION);
7648 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007649
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007650 if (!validateCopyTexImageParameters(context, target, false, level, xoffset, yoffset, zoffset,
7651 x, y, width, height))
7652 {
7653 return;
7654 }
7655
7656 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
7657 gl::Texture *texture = NULL;
7658 switch (target)
7659 {
7660 case GL_TEXTURE_3D:
7661 texture = context->getTexture3D();
7662 break;
7663
7664 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00007665 texture = context->getTexture2DArray();
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007666 break;
7667
7668 default:
7669 return gl::error(GL_INVALID_ENUM);
7670 }
7671
7672 texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
7673 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007674 }
7675 catch(std::bad_alloc&)
7676 {
7677 return gl::error(GL_OUT_OF_MEMORY);
7678 }
7679}
7680
7681void __stdcall glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
7682{
7683 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
7684 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
7685 "const GLvoid* data = 0x%0.8p)",
7686 target, level, internalformat, width, height, depth, border, imageSize, data);
7687
7688 try
7689 {
7690 gl::Context *context = gl::getNonLostContext();
7691
7692 if (context)
7693 {
7694 if (context->getClientVersion() < 3)
7695 {
7696 return gl::error(GL_INVALID_OPERATION);
7697 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007698
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007699 if (imageSize < 0 || imageSize != gl::ComputeCompressedSize(width, height, internalformat))
7700 {
7701 return gl::error(GL_INVALID_VALUE);
7702 }
7703
7704 // validateES3TexImageFormat sets the error code if there is an error
7705 if (!validateES3TexImageFormat(context, target, level, internalformat, true, false,
7706 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE))
7707 {
7708 return;
7709 }
7710
7711 switch(target)
7712 {
7713 case GL_TEXTURE_3D:
7714 {
7715 gl::Texture3D *texture = context->getTexture3D();
7716 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
7717 }
7718 break;
7719
7720 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00007721 {
7722 gl::Texture2DArray *texture = context->getTexture2DArray();
7723 texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, data);
7724 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007725 break;
7726
7727 default:
7728 return gl::error(GL_INVALID_ENUM);
7729 }
7730 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007731 }
7732 catch(std::bad_alloc&)
7733 {
7734 return gl::error(GL_OUT_OF_MEMORY);
7735 }
7736}
7737
7738void __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)
7739{
7740 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
7741 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
7742 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
7743 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
7744
7745 try
7746 {
7747 gl::Context *context = gl::getNonLostContext();
7748
7749 if (context)
7750 {
7751 if (context->getClientVersion() < 3)
7752 {
7753 return gl::error(GL_INVALID_OPERATION);
7754 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007755
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007756 if (imageSize < 0 || imageSize != gl::ComputeCompressedSize(width, height, format))
7757 {
7758 return gl::error(GL_INVALID_VALUE);
7759 }
7760
7761 if (!data)
7762 {
7763 return gl::error(GL_INVALID_VALUE);
7764 }
7765
7766 // validateES3TexImageFormat sets the error code if there is an error
7767 if (!validateES3TexImageFormat(context, target, level, GL_NONE, true, true,
7768 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE))
7769 {
7770 return;
7771 }
7772
7773 switch(target)
7774 {
7775 case GL_TEXTURE_3D:
7776 {
7777 gl::Texture3D *texture = context->getTexture3D();
7778 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
7779 format, imageSize, data);
7780 }
7781 break;
7782
7783 case GL_TEXTURE_2D_ARRAY:
shannon.woods%transgaming.com@gtempaccount.com14e8f592013-04-13 03:46:21 +00007784 {
7785 gl::Texture2DArray *texture = context->getTexture2DArray();
7786 texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
7787 format, imageSize, data);
7788 }
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00007789 break;
7790
7791 default:
7792 return gl::error(GL_INVALID_ENUM);
7793 }
7794 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007795 }
7796 catch(std::bad_alloc&)
7797 {
7798 return gl::error(GL_OUT_OF_MEMORY);
7799 }
7800}
7801
7802void __stdcall glGenQueries(GLsizei n, GLuint* ids)
7803{
7804 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7805
7806 try
7807 {
7808 gl::Context *context = gl::getNonLostContext();
7809
7810 if (context)
7811 {
7812 if (context->getClientVersion() < 3)
7813 {
7814 return gl::error(GL_INVALID_OPERATION);
7815 }
7816 }
7817
7818 UNIMPLEMENTED();
7819 }
7820 catch(std::bad_alloc&)
7821 {
7822 return gl::error(GL_OUT_OF_MEMORY);
7823 }
7824}
7825
7826void __stdcall glDeleteQueries(GLsizei n, const GLuint* ids)
7827{
7828 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
7829
7830 try
7831 {
7832 gl::Context *context = gl::getNonLostContext();
7833
7834 if (context)
7835 {
7836 if (context->getClientVersion() < 3)
7837 {
7838 return gl::error(GL_INVALID_OPERATION);
7839 }
7840 }
7841
7842 UNIMPLEMENTED();
7843 }
7844 catch(std::bad_alloc&)
7845 {
7846 return gl::error(GL_OUT_OF_MEMORY);
7847 }
7848}
7849
7850GLboolean __stdcall glIsQuery(GLuint id)
7851{
7852 EVENT("(GLuint id = %u)", id);
7853
7854 try
7855 {
7856 gl::Context *context = gl::getNonLostContext();
7857
7858 if (context)
7859 {
7860 if (context->getClientVersion() < 3)
7861 {
7862 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
7863 }
7864 }
7865
7866 UNIMPLEMENTED();
7867 }
7868 catch(std::bad_alloc&)
7869 {
7870 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
7871 }
7872
7873 return GL_FALSE;
7874}
7875
7876void __stdcall glBeginQuery(GLenum target, GLuint id)
7877{
7878 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
7879
7880 try
7881 {
7882 gl::Context *context = gl::getNonLostContext();
7883
7884 if (context)
7885 {
7886 if (context->getClientVersion() < 3)
7887 {
7888 return gl::error(GL_INVALID_OPERATION);
7889 }
7890 }
7891
7892 UNIMPLEMENTED();
7893 }
7894 catch(std::bad_alloc&)
7895 {
7896 return gl::error(GL_OUT_OF_MEMORY);
7897 }
7898}
7899
7900void __stdcall glEndQuery(GLenum target)
7901{
7902 EVENT("(GLenum target = 0x%X)", target);
7903
7904 try
7905 {
7906 gl::Context *context = gl::getNonLostContext();
7907
7908 if (context)
7909 {
7910 if (context->getClientVersion() < 3)
7911 {
7912 return gl::error(GL_INVALID_OPERATION);
7913 }
7914 }
7915
7916 UNIMPLEMENTED();
7917 }
7918 catch(std::bad_alloc&)
7919 {
7920 return gl::error(GL_OUT_OF_MEMORY);
7921 }
7922}
7923
7924void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
7925{
7926 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
7927
7928 try
7929 {
7930 gl::Context *context = gl::getNonLostContext();
7931
7932 if (context)
7933 {
7934 if (context->getClientVersion() < 3)
7935 {
7936 return gl::error(GL_INVALID_OPERATION);
7937 }
7938 }
7939
7940 UNIMPLEMENTED();
7941 }
7942 catch(std::bad_alloc&)
7943 {
7944 return gl::error(GL_OUT_OF_MEMORY);
7945 }
7946}
7947
7948void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
7949{
7950 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
7951
7952 try
7953 {
7954 gl::Context *context = gl::getNonLostContext();
7955
7956 if (context)
7957 {
7958 if (context->getClientVersion() < 3)
7959 {
7960 return gl::error(GL_INVALID_OPERATION);
7961 }
7962 }
7963
7964 UNIMPLEMENTED();
7965 }
7966 catch(std::bad_alloc&)
7967 {
7968 return gl::error(GL_OUT_OF_MEMORY);
7969 }
7970}
7971
7972GLboolean __stdcall glUnmapBuffer(GLenum target)
7973{
7974 EVENT("(GLenum target = 0x%X)", target);
7975
7976 try
7977 {
7978 gl::Context *context = gl::getNonLostContext();
7979
7980 if (context)
7981 {
7982 if (context->getClientVersion() < 3)
7983 {
7984 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
7985 }
7986 }
7987
7988 UNIMPLEMENTED();
7989 }
7990 catch(std::bad_alloc&)
7991 {
7992 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
7993 }
7994
7995 return GL_FALSE;
7996}
7997
7998void __stdcall glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
7999{
8000 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8001
8002 try
8003 {
8004 gl::Context *context = gl::getNonLostContext();
8005
8006 if (context)
8007 {
8008 if (context->getClientVersion() < 3)
8009 {
8010 return gl::error(GL_INVALID_OPERATION);
8011 }
8012 }
8013
8014 UNIMPLEMENTED();
8015 }
8016 catch(std::bad_alloc&)
8017 {
8018 return gl::error(GL_OUT_OF_MEMORY);
8019 }
8020}
8021
8022void __stdcall glDrawBuffers(GLsizei n, const GLenum* bufs)
8023{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008024 try
8025 {
8026 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.com7948c5f2013-04-13 03:38:58 +00008035 glDrawBuffersEXT(n, bufs);
8036 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008037 }
8038 catch(std::bad_alloc&)
8039 {
8040 return gl::error(GL_OUT_OF_MEMORY);
8041 }
8042}
8043
8044void __stdcall glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8045{
8046 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8047 location, count, transpose, value);
8048
8049 try
8050 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008051 if (count < 0)
8052 {
8053 return gl::error(GL_INVALID_VALUE);
8054 }
8055
8056 if (location == -1)
8057 {
8058 return;
8059 }
8060
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008061 gl::Context *context = gl::getNonLostContext();
8062
8063 if (context)
8064 {
8065 if (context->getClientVersion() < 3)
8066 {
8067 return gl::error(GL_INVALID_OPERATION);
8068 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008069
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008070 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8071 if (!programBinary)
8072 {
8073 return gl::error(GL_INVALID_OPERATION);
8074 }
8075
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008076 if (!programBinary->setUniformMatrix2x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008077 {
8078 return gl::error(GL_INVALID_OPERATION);
8079 }
8080 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008081 }
8082 catch(std::bad_alloc&)
8083 {
8084 return gl::error(GL_OUT_OF_MEMORY);
8085 }
8086}
8087
8088void __stdcall glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8089{
8090 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8091 location, count, transpose, value);
8092
8093 try
8094 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008095 if (count < 0)
8096 {
8097 return gl::error(GL_INVALID_VALUE);
8098 }
8099
8100 if (location == -1)
8101 {
8102 return;
8103 }
8104
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008105 gl::Context *context = gl::getNonLostContext();
8106
8107 if (context)
8108 {
8109 if (context->getClientVersion() < 3)
8110 {
8111 return gl::error(GL_INVALID_OPERATION);
8112 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008113
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008114 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8115 if (!programBinary)
8116 {
8117 return gl::error(GL_INVALID_OPERATION);
8118 }
8119
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008120 if (!programBinary->setUniformMatrix3x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008121 {
8122 return gl::error(GL_INVALID_OPERATION);
8123 }
8124 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008125 }
8126 catch(std::bad_alloc&)
8127 {
8128 return gl::error(GL_OUT_OF_MEMORY);
8129 }
8130}
8131
8132void __stdcall glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8133{
8134 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8135 location, count, transpose, value);
8136
8137 try
8138 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008139 if (count < 0)
8140 {
8141 return gl::error(GL_INVALID_VALUE);
8142 }
8143
8144 if (location == -1)
8145 {
8146 return;
8147 }
8148
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008149 gl::Context *context = gl::getNonLostContext();
8150
8151 if (context)
8152 {
8153 if (context->getClientVersion() < 3)
8154 {
8155 return gl::error(GL_INVALID_OPERATION);
8156 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008157
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008158 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8159 if (!programBinary)
8160 {
8161 return gl::error(GL_INVALID_OPERATION);
8162 }
8163
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008164 if (!programBinary->setUniformMatrix2x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008165 {
8166 return gl::error(GL_INVALID_OPERATION);
8167 }
8168 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008169 }
8170 catch(std::bad_alloc&)
8171 {
8172 return gl::error(GL_OUT_OF_MEMORY);
8173 }
8174}
8175
8176void __stdcall glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8177{
8178 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8179 location, count, transpose, value);
8180
8181 try
8182 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008183 if (count < 0)
8184 {
8185 return gl::error(GL_INVALID_VALUE);
8186 }
8187
8188 if (location == -1)
8189 {
8190 return;
8191 }
8192
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008193 gl::Context *context = gl::getNonLostContext();
8194
8195 if (context)
8196 {
8197 if (context->getClientVersion() < 3)
8198 {
8199 return gl::error(GL_INVALID_OPERATION);
8200 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008201
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008202 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8203 if (!programBinary)
8204 {
8205 return gl::error(GL_INVALID_OPERATION);
8206 }
8207
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008208 if (!programBinary->setUniformMatrix4x2fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008209 {
8210 return gl::error(GL_INVALID_OPERATION);
8211 }
8212 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008213 }
8214 catch(std::bad_alloc&)
8215 {
8216 return gl::error(GL_OUT_OF_MEMORY);
8217 }
8218}
8219
8220void __stdcall glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8221{
8222 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8223 location, count, transpose, value);
8224
8225 try
8226 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008227 if (count < 0)
8228 {
8229 return gl::error(GL_INVALID_VALUE);
8230 }
8231
8232 if (location == -1)
8233 {
8234 return;
8235 }
8236
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008237 gl::Context *context = gl::getNonLostContext();
8238
8239 if (context)
8240 {
8241 if (context->getClientVersion() < 3)
8242 {
8243 return gl::error(GL_INVALID_OPERATION);
8244 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008245
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008246 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8247 if (!programBinary)
8248 {
8249 return gl::error(GL_INVALID_OPERATION);
8250 }
8251
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008252 if (!programBinary->setUniformMatrix3x4fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008253 {
8254 return gl::error(GL_INVALID_OPERATION);
8255 }
8256 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008257 }
8258 catch(std::bad_alloc&)
8259 {
8260 return gl::error(GL_OUT_OF_MEMORY);
8261 }
8262}
8263
8264void __stdcall glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
8265{
8266 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
8267 location, count, transpose, value);
8268
8269 try
8270 {
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008271 if (count < 0)
8272 {
8273 return gl::error(GL_INVALID_VALUE);
8274 }
8275
8276 if (location == -1)
8277 {
8278 return;
8279 }
8280
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008281 gl::Context *context = gl::getNonLostContext();
8282
8283 if (context)
8284 {
8285 if (context->getClientVersion() < 3)
8286 {
8287 return gl::error(GL_INVALID_OPERATION);
8288 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008289
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008290 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
8291 if (!programBinary)
8292 {
8293 return gl::error(GL_INVALID_OPERATION);
8294 }
8295
shannon.woods%transgaming.com@gtempaccount.coma741b642013-04-13 03:40:10 +00008296 if (!programBinary->setUniformMatrix4x3fv(location, count, transpose, value))
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00008297 {
8298 return gl::error(GL_INVALID_OPERATION);
8299 }
8300 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008301 }
8302 catch(std::bad_alloc&)
8303 {
8304 return gl::error(GL_OUT_OF_MEMORY);
8305 }
8306}
8307
8308void __stdcall glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
8309{
8310 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
8311 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
8312 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
8313
8314 try
8315 {
8316 gl::Context *context = gl::getNonLostContext();
8317
8318 if (context)
8319 {
8320 if (context->getClientVersion() < 3)
8321 {
8322 return gl::error(GL_INVALID_OPERATION);
8323 }
8324 }
8325
8326 UNIMPLEMENTED();
8327 }
8328 catch(std::bad_alloc&)
8329 {
8330 return gl::error(GL_OUT_OF_MEMORY);
8331 }
8332}
8333
8334void __stdcall glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
8335{
8336 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
8337 target, samples, internalformat, width, height);
8338
8339 try
8340 {
8341 gl::Context *context = gl::getNonLostContext();
8342
8343 if (context)
8344 {
8345 if (context->getClientVersion() < 3)
8346 {
8347 return gl::error(GL_INVALID_OPERATION);
8348 }
8349 }
8350
8351 UNIMPLEMENTED();
8352 }
8353 catch(std::bad_alloc&)
8354 {
8355 return gl::error(GL_OUT_OF_MEMORY);
8356 }
8357}
8358
8359void __stdcall glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
8360{
8361 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
8362 target, attachment, texture, level, layer);
8363
8364 try
8365 {
8366 gl::Context *context = gl::getNonLostContext();
8367
8368 if (context)
8369 {
8370 if (context->getClientVersion() < 3)
8371 {
8372 return gl::error(GL_INVALID_OPERATION);
8373 }
8374 }
8375
8376 UNIMPLEMENTED();
8377 }
8378 catch(std::bad_alloc&)
8379 {
8380 return gl::error(GL_OUT_OF_MEMORY);
8381 }
8382}
8383
8384GLvoid* __stdcall glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
8385{
8386 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8387 target, offset, length, access);
8388
8389 try
8390 {
8391 gl::Context *context = gl::getNonLostContext();
8392
8393 if (context)
8394 {
8395 if (context->getClientVersion() < 3)
8396 {
8397 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLvoid*>(NULL));
8398 }
8399 }
8400
8401 UNIMPLEMENTED();
8402 }
8403 catch(std::bad_alloc&)
8404 {
8405 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLvoid*>(NULL));
8406 }
8407
8408 return NULL;
8409}
8410
8411void __stdcall glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
8412{
8413 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8414
8415 try
8416 {
8417 gl::Context *context = gl::getNonLostContext();
8418
8419 if (context)
8420 {
8421 if (context->getClientVersion() < 3)
8422 {
8423 return gl::error(GL_INVALID_OPERATION);
8424 }
8425 }
8426
8427 UNIMPLEMENTED();
8428 }
8429 catch(std::bad_alloc&)
8430 {
8431 return gl::error(GL_OUT_OF_MEMORY);
8432 }
8433}
8434
8435void __stdcall glBindVertexArray(GLuint array)
8436{
8437 EVENT("(GLuint array = %u)", array);
8438
8439 try
8440 {
8441 gl::Context *context = gl::getNonLostContext();
8442
8443 if (context)
8444 {
8445 if (context->getClientVersion() < 3)
8446 {
8447 return gl::error(GL_INVALID_OPERATION);
8448 }
8449 }
8450
8451 UNIMPLEMENTED();
8452 }
8453 catch(std::bad_alloc&)
8454 {
8455 return gl::error(GL_OUT_OF_MEMORY);
8456 }
8457}
8458
8459void __stdcall glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
8460{
8461 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
8462
8463 try
8464 {
8465 gl::Context *context = gl::getNonLostContext();
8466
8467 if (context)
8468 {
8469 if (context->getClientVersion() < 3)
8470 {
8471 return gl::error(GL_INVALID_OPERATION);
8472 }
8473 }
8474
8475 UNIMPLEMENTED();
8476 }
8477 catch(std::bad_alloc&)
8478 {
8479 return gl::error(GL_OUT_OF_MEMORY);
8480 }
8481}
8482
8483void __stdcall glGenVertexArrays(GLsizei n, GLuint* arrays)
8484{
8485 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
8486
8487 try
8488 {
8489 gl::Context *context = gl::getNonLostContext();
8490
8491 if (context)
8492 {
8493 if (context->getClientVersion() < 3)
8494 {
8495 return gl::error(GL_INVALID_OPERATION);
8496 }
8497 }
8498
8499 UNIMPLEMENTED();
8500 }
8501 catch(std::bad_alloc&)
8502 {
8503 return gl::error(GL_OUT_OF_MEMORY);
8504 }
8505}
8506
8507GLboolean __stdcall glIsVertexArray(GLuint array)
8508{
8509 EVENT("(GLuint array = %u)", array);
8510
8511 try
8512 {
8513 gl::Context *context = gl::getNonLostContext();
8514
8515 if (context)
8516 {
8517 if (context->getClientVersion() < 3)
8518 {
8519 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
8520 }
8521 }
8522
8523 UNIMPLEMENTED();
8524 }
8525 catch(std::bad_alloc&)
8526 {
8527 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
8528 }
8529
8530 return GL_FALSE;
8531}
8532
8533void __stdcall glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
8534{
8535 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
8536 target, index, data);
8537
8538 try
8539 {
8540 gl::Context *context = gl::getNonLostContext();
8541
8542 if (context)
8543 {
8544 if (context->getClientVersion() < 3)
8545 {
8546 return gl::error(GL_INVALID_OPERATION);
8547 }
8548 }
8549
8550 UNIMPLEMENTED();
8551 }
8552 catch(std::bad_alloc&)
8553 {
8554 return gl::error(GL_OUT_OF_MEMORY);
8555 }
8556}
8557
8558void __stdcall glBeginTransformFeedback(GLenum primitiveMode)
8559{
8560 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
8561
8562 try
8563 {
8564 gl::Context *context = gl::getNonLostContext();
8565
8566 if (context)
8567 {
8568 if (context->getClientVersion() < 3)
8569 {
8570 return gl::error(GL_INVALID_OPERATION);
8571 }
8572 }
8573
8574 UNIMPLEMENTED();
8575 }
8576 catch(std::bad_alloc&)
8577 {
8578 return gl::error(GL_OUT_OF_MEMORY);
8579 }
8580}
8581
8582void __stdcall glEndTransformFeedback(void)
8583{
8584 EVENT("(void)");
8585
8586 try
8587 {
8588 gl::Context *context = gl::getNonLostContext();
8589
8590 if (context)
8591 {
8592 if (context->getClientVersion() < 3)
8593 {
8594 return gl::error(GL_INVALID_OPERATION);
8595 }
8596 }
8597
8598 UNIMPLEMENTED();
8599 }
8600 catch(std::bad_alloc&)
8601 {
8602 return gl::error(GL_OUT_OF_MEMORY);
8603 }
8604}
8605
8606void __stdcall glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
8607{
8608 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
8609 target, index, buffer, offset, size);
8610
8611 try
8612 {
8613 gl::Context *context = gl::getNonLostContext();
8614
8615 if (context)
8616 {
8617 if (context->getClientVersion() < 3)
8618 {
8619 return gl::error(GL_INVALID_OPERATION);
8620 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008621
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008622 switch (target)
8623 {
8624 case GL_TRANSFORM_FEEDBACK_BUFFER:
8625 if (index > context->getMaxTransformFeedbackBufferBindings())
8626 {
8627 return gl::error(GL_INVALID_VALUE);
8628 }
8629 break;
8630
8631 case GL_UNIFORM_BUFFER:
8632 if (index >= context->getMaximumCombinedUniformBufferBindings())
8633 {
8634 return gl::error(GL_INVALID_VALUE);
8635 }
8636 break;
8637
8638 default:
8639 return gl::error(GL_INVALID_ENUM);
8640 }
8641
8642 gl::Buffer *bufferObject = context->getBuffer(buffer);
8643 if (!bufferObject)
8644 {
8645 // Buffer index must not have been valid
8646 return gl::error(GL_INVALID_VALUE);
8647 }
8648
8649 if (size <= 0 || static_cast<unsigned int>(offset + size) > bufferObject->size())
8650 {
8651 return gl::error(GL_INVALID_VALUE);
8652 }
8653
8654 switch (target)
8655 {
8656 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00008657 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
8658 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008659 break;
8660
8661 case GL_UNIFORM_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00008662 context->bindIndexedUniformBuffer(buffer, index, offset, size);
8663 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008664 break;
8665
8666 default:
8667 UNREACHABLE();
8668 }
8669 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008670 }
8671 catch(std::bad_alloc&)
8672 {
8673 return gl::error(GL_OUT_OF_MEMORY);
8674 }
8675}
8676
8677void __stdcall glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
8678{
8679 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
8680 target, index, buffer);
8681
8682 try
8683 {
8684 gl::Context *context = gl::getNonLostContext();
8685
8686 if (context)
8687 {
8688 if (context->getClientVersion() < 3)
8689 {
8690 return gl::error(GL_INVALID_OPERATION);
8691 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008692
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008693 switch (target)
8694 {
8695 case GL_TRANSFORM_FEEDBACK_BUFFER:
8696 if (index > context->getMaxTransformFeedbackBufferBindings())
8697 {
8698 return gl::error(GL_INVALID_VALUE);
8699 }
8700 break;
8701
8702 case GL_UNIFORM_BUFFER:
8703 if (index > context->getMaximumCombinedUniformBufferBindings())
8704 {
8705 return gl::error(GL_INVALID_VALUE);
8706 }
8707 break;
8708
8709 default:
8710 return gl::error(GL_INVALID_ENUM);
8711 }
8712
8713 gl::Buffer *bufferObject = context->getBuffer(buffer);
8714 if (!bufferObject)
8715 {
8716 // Buffer index must not have been valid
8717 return gl::error(GL_INVALID_VALUE);
8718 }
8719
8720 switch (target)
8721 {
8722 case GL_TRANSFORM_FEEDBACK_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00008723 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, -1);
8724 context->bindGenericTransformFeedbackBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008725 break;
8726
8727 case GL_UNIFORM_BUFFER:
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00008728 context->bindIndexedUniformBuffer(buffer, index, 0, -1);
8729 context->bindGenericUniformBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00008730 break;
8731
8732 default:
8733 UNREACHABLE();
8734 }
8735 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008736 }
8737 catch(std::bad_alloc&)
8738 {
8739 return gl::error(GL_OUT_OF_MEMORY);
8740 }
8741}
8742
8743void __stdcall glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
8744{
8745 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
8746 program, count, varyings, bufferMode);
8747
8748 try
8749 {
8750 gl::Context *context = gl::getNonLostContext();
8751
8752 if (context)
8753 {
8754 if (context->getClientVersion() < 3)
8755 {
8756 return gl::error(GL_INVALID_OPERATION);
8757 }
8758 }
8759
8760 UNIMPLEMENTED();
8761 }
8762 catch(std::bad_alloc&)
8763 {
8764 return gl::error(GL_OUT_OF_MEMORY);
8765 }
8766}
8767
8768void __stdcall glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
8769{
8770 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
8771 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
8772 program, index, bufSize, length, size, type, name);
8773
8774 try
8775 {
8776 gl::Context *context = gl::getNonLostContext();
8777
8778 if (context)
8779 {
8780 if (context->getClientVersion() < 3)
8781 {
8782 return gl::error(GL_INVALID_OPERATION);
8783 }
8784 }
8785
8786 UNIMPLEMENTED();
8787 }
8788 catch(std::bad_alloc&)
8789 {
8790 return gl::error(GL_OUT_OF_MEMORY);
8791 }
8792}
8793
8794void __stdcall glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
8795{
8796 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
8797 index, size, type, stride, pointer);
8798
8799 try
8800 {
8801 gl::Context *context = gl::getNonLostContext();
8802
8803 if (context)
8804 {
8805 if (context->getClientVersion() < 3)
8806 {
8807 return gl::error(GL_INVALID_OPERATION);
8808 }
8809 }
8810
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008811 if (index >= gl::MAX_VERTEX_ATTRIBS)
8812 {
8813 return gl::error(GL_INVALID_VALUE);
8814 }
8815
8816 if (size < 1 || size > 4)
8817 {
8818 return gl::error(GL_INVALID_VALUE);
8819 }
8820
8821 switch (type)
8822 {
8823 case GL_BYTE:
8824 case GL_UNSIGNED_BYTE:
8825 case GL_SHORT:
8826 case GL_UNSIGNED_SHORT:
8827 case GL_INT:
8828 case GL_UNSIGNED_INT:
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008829 case GL_INT_2_10_10_10_REV:
8830 case GL_UNSIGNED_INT_2_10_10_10_REV:
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008831 break;
8832 default:
8833 return gl::error(GL_INVALID_ENUM);
8834 }
8835
8836 if (stride < 0)
8837 {
8838 return gl::error(GL_INVALID_VALUE);
8839 }
8840
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00008841 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
8842 {
8843 return gl::error(GL_INVALID_OPERATION);
8844 }
8845
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008846 if (context)
8847 {
8848 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
8849 stride, pointer);
8850 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008851 }
8852 catch(std::bad_alloc&)
8853 {
8854 return gl::error(GL_OUT_OF_MEMORY);
8855 }
8856}
8857
8858void __stdcall glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
8859{
8860 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
8861 index, pname, params);
8862
8863 try
8864 {
8865 gl::Context *context = gl::getNonLostContext();
8866
8867 if (context)
8868 {
8869 if (context->getClientVersion() < 3)
8870 {
8871 return gl::error(GL_INVALID_OPERATION);
8872 }
8873 }
8874
8875 UNIMPLEMENTED();
8876 }
8877 catch(std::bad_alloc&)
8878 {
8879 return gl::error(GL_OUT_OF_MEMORY);
8880 }
8881}
8882
8883void __stdcall glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
8884{
8885 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
8886 index, pname, params);
8887
8888 try
8889 {
8890 gl::Context *context = gl::getNonLostContext();
8891
8892 if (context)
8893 {
8894 if (context->getClientVersion() < 3)
8895 {
8896 return gl::error(GL_INVALID_OPERATION);
8897 }
8898 }
8899
8900 UNIMPLEMENTED();
8901 }
8902 catch(std::bad_alloc&)
8903 {
8904 return gl::error(GL_OUT_OF_MEMORY);
8905 }
8906}
8907
8908void __stdcall glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
8909{
8910 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
8911 index, x, y, z, w);
8912
8913 try
8914 {
8915 gl::Context *context = gl::getNonLostContext();
8916
8917 if (context)
8918 {
8919 if (context->getClientVersion() < 3)
8920 {
8921 return gl::error(GL_INVALID_OPERATION);
8922 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008923
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008924 if (index >= gl::MAX_VERTEX_ATTRIBS)
8925 {
8926 return gl::error(GL_INVALID_VALUE);
8927 }
8928
8929 GLint vals[4] = { x, y, z, w };
8930 context->setVertexAttribi(index, vals);
8931 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008932 }
8933 catch(std::bad_alloc&)
8934 {
8935 return gl::error(GL_OUT_OF_MEMORY);
8936 }
8937}
8938
8939void __stdcall glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
8940{
8941 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
8942 index, x, y, z, w);
8943
8944 try
8945 {
8946 gl::Context *context = gl::getNonLostContext();
8947
8948 if (context)
8949 {
8950 if (context->getClientVersion() < 3)
8951 {
8952 return gl::error(GL_INVALID_OPERATION);
8953 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008954
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008955 if (index >= gl::MAX_VERTEX_ATTRIBS)
8956 {
8957 return gl::error(GL_INVALID_VALUE);
8958 }
8959
8960 GLuint vals[4] = { x, y, z, w };
8961 context->setVertexAttribu(index, vals);
8962 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008963 }
8964 catch(std::bad_alloc&)
8965 {
8966 return gl::error(GL_OUT_OF_MEMORY);
8967 }
8968}
8969
8970void __stdcall glVertexAttribI4iv(GLuint index, const GLint* v)
8971{
8972 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
8973
8974 try
8975 {
8976 gl::Context *context = gl::getNonLostContext();
8977
8978 if (context)
8979 {
8980 if (context->getClientVersion() < 3)
8981 {
8982 return gl::error(GL_INVALID_OPERATION);
8983 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008984
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00008985 if (index >= gl::MAX_VERTEX_ATTRIBS)
8986 {
8987 return gl::error(GL_INVALID_VALUE);
8988 }
8989
8990 context->setVertexAttribi(index, v);
8991 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008992 }
8993 catch(std::bad_alloc&)
8994 {
8995 return gl::error(GL_OUT_OF_MEMORY);
8996 }
8997}
8998
8999void __stdcall glVertexAttribI4uiv(GLuint index, const GLuint* v)
9000{
9001 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
9002
9003 try
9004 {
9005 gl::Context *context = gl::getNonLostContext();
9006
9007 if (context)
9008 {
9009 if (context->getClientVersion() < 3)
9010 {
9011 return gl::error(GL_INVALID_OPERATION);
9012 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009013
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00009014 if (index >= gl::MAX_VERTEX_ATTRIBS)
9015 {
9016 return gl::error(GL_INVALID_VALUE);
9017 }
9018
9019 context->setVertexAttribu(index, v);
9020 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009021 }
9022 catch(std::bad_alloc&)
9023 {
9024 return gl::error(GL_OUT_OF_MEMORY);
9025 }
9026}
9027
9028void __stdcall glGetUniformuiv(GLuint program, GLint location, GLuint* params)
9029{
9030 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
9031 program, location, params);
9032
9033 try
9034 {
9035 gl::Context *context = gl::getNonLostContext();
9036
9037 if (context)
9038 {
9039 if (context->getClientVersion() < 3)
9040 {
9041 return gl::error(GL_INVALID_OPERATION);
9042 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009043
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00009044 if (program == 0)
9045 {
9046 return gl::error(GL_INVALID_VALUE);
9047 }
9048
9049 gl::Program *programObject = context->getProgram(program);
9050
9051 if (!programObject || !programObject->isLinked())
9052 {
9053 return gl::error(GL_INVALID_OPERATION);
9054 }
9055
9056 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
9057 if (!programBinary)
9058 {
9059 return gl::error(GL_INVALID_OPERATION);
9060 }
9061
9062 if (!programBinary->getUniformuiv(location, NULL, params))
9063 {
9064 return gl::error(GL_INVALID_OPERATION);
9065 }
9066 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009067 }
9068 catch(std::bad_alloc&)
9069 {
9070 return gl::error(GL_OUT_OF_MEMORY);
9071 }
9072}
9073
9074GLint __stdcall glGetFragDataLocation(GLuint program, const GLchar *name)
9075{
9076 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
9077 program, name);
9078
9079 try
9080 {
9081 gl::Context *context = gl::getNonLostContext();
9082
9083 if (context)
9084 {
9085 if (context->getClientVersion() < 3)
9086 {
9087 return gl::error(GL_INVALID_OPERATION, 0);
9088 }
9089 }
9090
9091 UNIMPLEMENTED();
9092 }
9093 catch(std::bad_alloc&)
9094 {
9095 return gl::error(GL_OUT_OF_MEMORY, 0);
9096 }
9097
9098 return 0;
9099}
9100
9101void __stdcall glUniform1ui(GLint location, GLuint v0)
9102{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009103 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009104}
9105
9106void __stdcall glUniform2ui(GLint location, GLuint v0, GLuint v1)
9107{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009108 const GLuint xy[] = { v0, v1 };
9109 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009110}
9111
9112void __stdcall glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
9113{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009114 const GLuint xyz[] = { v0, v1, v2 };
9115 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009116}
9117
9118void __stdcall glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
9119{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00009120 const GLuint xyzw[] = { v0, v1, v2, v3 };
9121 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009122}
9123
9124void __stdcall glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
9125{
9126 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9127 location, count, value);
9128
9129 try
9130 {
9131 gl::Context *context = gl::getNonLostContext();
9132
9133 if (context)
9134 {
9135 if (context->getClientVersion() < 3)
9136 {
9137 return gl::error(GL_INVALID_OPERATION);
9138 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009139
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009140 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9141 if (!programBinary)
9142 {
9143 return gl::error(GL_INVALID_OPERATION);
9144 }
9145
9146 if (!programBinary->setUniform1uiv(location, count, value))
9147 {
9148 return gl::error(GL_INVALID_OPERATION);
9149 }
9150 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009151 }
9152 catch(std::bad_alloc&)
9153 {
9154 return gl::error(GL_OUT_OF_MEMORY);
9155 }
9156}
9157
9158void __stdcall glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
9159{
9160 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9161 location, count, value);
9162
9163 try
9164 {
9165 gl::Context *context = gl::getNonLostContext();
9166
9167 if (context)
9168 {
9169 if (context->getClientVersion() < 3)
9170 {
9171 return gl::error(GL_INVALID_OPERATION);
9172 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009173
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009174 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9175 if (!programBinary)
9176 {
9177 return gl::error(GL_INVALID_OPERATION);
9178 }
9179
9180 if (!programBinary->setUniform2uiv(location, count, value))
9181 {
9182 return gl::error(GL_INVALID_OPERATION);
9183 }
9184 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009185 }
9186 catch(std::bad_alloc&)
9187 {
9188 return gl::error(GL_OUT_OF_MEMORY);
9189 }
9190}
9191
9192void __stdcall glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
9193{
9194 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
9195 location, count, value);
9196
9197 try
9198 {
9199 gl::Context *context = gl::getNonLostContext();
9200
9201 if (context)
9202 {
9203 if (context->getClientVersion() < 3)
9204 {
9205 return gl::error(GL_INVALID_OPERATION);
9206 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009207
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009208 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9209 if (!programBinary)
9210 {
9211 return gl::error(GL_INVALID_OPERATION);
9212 }
9213
9214 if (!programBinary->setUniform3uiv(location, count, value))
9215 {
9216 return gl::error(GL_INVALID_OPERATION);
9217 }
9218 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009219 }
9220 catch(std::bad_alloc&)
9221 {
9222 return gl::error(GL_OUT_OF_MEMORY);
9223 }
9224}
9225
9226void __stdcall glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
9227{
9228 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
9229 location, count, value);
9230
9231 try
9232 {
9233 gl::Context *context = gl::getNonLostContext();
9234
9235 if (context)
9236 {
9237 if (context->getClientVersion() < 3)
9238 {
9239 return gl::error(GL_INVALID_OPERATION);
9240 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009241
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00009242 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
9243 if (!programBinary)
9244 {
9245 return gl::error(GL_INVALID_OPERATION);
9246 }
9247
9248 if (!programBinary->setUniform4uiv(location, count, value))
9249 {
9250 return gl::error(GL_INVALID_OPERATION);
9251 }
9252 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009253 }
9254 catch(std::bad_alloc&)
9255 {
9256 return gl::error(GL_OUT_OF_MEMORY);
9257 }
9258}
9259
9260void __stdcall glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
9261{
9262 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
9263 buffer, drawbuffer, value);
9264
9265 try
9266 {
9267 gl::Context *context = gl::getNonLostContext();
9268
9269 if (context)
9270 {
9271 if (context->getClientVersion() < 3)
9272 {
9273 return gl::error(GL_INVALID_OPERATION);
9274 }
9275 }
9276
9277 UNIMPLEMENTED();
9278 }
9279 catch(std::bad_alloc&)
9280 {
9281 return gl::error(GL_OUT_OF_MEMORY);
9282 }
9283}
9284
9285void __stdcall glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
9286{
9287 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
9288 buffer, drawbuffer, value);
9289
9290 try
9291 {
9292 gl::Context *context = gl::getNonLostContext();
9293
9294 if (context)
9295 {
9296 if (context->getClientVersion() < 3)
9297 {
9298 return gl::error(GL_INVALID_OPERATION);
9299 }
9300 }
9301
9302 UNIMPLEMENTED();
9303 }
9304 catch(std::bad_alloc&)
9305 {
9306 return gl::error(GL_OUT_OF_MEMORY);
9307 }
9308}
9309
9310void __stdcall glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
9311{
9312 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
9313 buffer, drawbuffer, value);
9314
9315 try
9316 {
9317 gl::Context *context = gl::getNonLostContext();
9318
9319 if (context)
9320 {
9321 if (context->getClientVersion() < 3)
9322 {
9323 return gl::error(GL_INVALID_OPERATION);
9324 }
9325 }
9326
9327 UNIMPLEMENTED();
9328 }
9329 catch(std::bad_alloc&)
9330 {
9331 return gl::error(GL_OUT_OF_MEMORY);
9332 }
9333}
9334
9335void __stdcall glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
9336{
9337 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
9338 buffer, drawbuffer, depth, stencil);
9339
9340 try
9341 {
9342 gl::Context *context = gl::getNonLostContext();
9343
9344 if (context)
9345 {
9346 if (context->getClientVersion() < 3)
9347 {
9348 return gl::error(GL_INVALID_OPERATION);
9349 }
9350 }
9351
9352 UNIMPLEMENTED();
9353 }
9354 catch(std::bad_alloc&)
9355 {
9356 return gl::error(GL_OUT_OF_MEMORY);
9357 }
9358}
9359
9360const GLubyte* __stdcall glGetStringi(GLenum name, GLuint index)
9361{
9362 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
9363
9364 try
9365 {
9366 gl::Context *context = gl::getNonLostContext();
9367
9368 if (context)
9369 {
9370 if (context->getClientVersion() < 3)
9371 {
9372 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLubyte*>(NULL));
9373 }
9374 }
9375
9376 UNIMPLEMENTED();
9377 }
9378 catch(std::bad_alloc&)
9379 {
9380 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLubyte*>(NULL));
9381 }
9382
9383 return NULL;
9384}
9385
9386void __stdcall glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
9387{
9388 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
9389 readTarget, writeTarget, readOffset, writeOffset, size);
9390
9391 try
9392 {
9393 gl::Context *context = gl::getNonLostContext();
9394
9395 if (context)
9396 {
9397 if (context->getClientVersion() < 3)
9398 {
9399 return gl::error(GL_INVALID_OPERATION);
9400 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009401
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00009402 gl::Buffer *readBuffer = NULL;
9403 switch (readTarget)
9404 {
9405 case GL_ARRAY_BUFFER:
9406 readBuffer = context->getArrayBuffer();
9407 break;
9408 case GL_COPY_READ_BUFFER:
9409 readBuffer = context->getCopyReadBuffer();
9410 break;
9411 case GL_COPY_WRITE_BUFFER:
9412 readBuffer = context->getCopyWriteBuffer();
9413 break;
9414 case GL_ELEMENT_ARRAY_BUFFER:
9415 readBuffer = context->getElementArrayBuffer();
9416 break;
9417 case GL_PIXEL_PACK_BUFFER:
9418 readBuffer = context->getPixelPackBuffer();
9419 break;
9420 case GL_PIXEL_UNPACK_BUFFER:
9421 readBuffer = context->getPixelUnpackBuffer();
9422 break;
9423 case GL_TRANSFORM_FEEDBACK_BUFFER:
9424 readBuffer = context->getGenericTransformFeedbackBuffer();
9425 break;
9426 case GL_UNIFORM_BUFFER:
9427 readBuffer = context->getGenericUniformBuffer();
9428 break;
9429 default:
9430 return gl::error(GL_INVALID_ENUM);
9431 }
9432
9433 gl::Buffer *writeBuffer = NULL;
9434 switch (writeTarget)
9435 {
9436 case GL_ARRAY_BUFFER:
9437 writeBuffer = context->getArrayBuffer();
9438 break;
9439 case GL_COPY_READ_BUFFER:
9440 writeBuffer = context->getCopyReadBuffer();
9441 break;
9442 case GL_COPY_WRITE_BUFFER:
9443 writeBuffer = context->getCopyWriteBuffer();
9444 break;
9445 case GL_ELEMENT_ARRAY_BUFFER:
9446 writeBuffer = context->getElementArrayBuffer();
9447 break;
9448 case GL_PIXEL_PACK_BUFFER:
9449 writeBuffer = context->getPixelPackBuffer();
9450 break;
9451 case GL_PIXEL_UNPACK_BUFFER:
9452 writeBuffer = context->getPixelUnpackBuffer();
9453 break;
9454 case GL_TRANSFORM_FEEDBACK_BUFFER:
9455 writeBuffer = context->getGenericTransformFeedbackBuffer();
9456 break;
9457 case GL_UNIFORM_BUFFER:
9458 writeBuffer = context->getGenericUniformBuffer();
9459 break;
9460 default:
9461 return gl::error(GL_INVALID_ENUM);
9462 }
9463
9464 if (!readBuffer || !writeBuffer)
9465 {
9466 return gl::error(GL_INVALID_OPERATION);
9467 }
9468
9469 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
9470 static_cast<unsigned int>(readOffset + size) > readBuffer->size() ||
9471 static_cast<unsigned int>(writeOffset + size) > writeBuffer->size())
9472 {
9473 return gl::error(GL_INVALID_VALUE);
9474 }
9475
9476 if (readBuffer == writeBuffer && abs(readOffset - writeOffset) < size)
9477 {
9478 return gl::error(GL_INVALID_VALUE);
9479 }
9480
9481 // TODO: Verify that readBuffer and writeBuffer are not currently mapped (GL_INVALID_OPERATION)
9482
shannon.woods%transgaming.com@gtempaccount.comc53376a2013-04-13 03:41:23 +00009483 // if size is zero, the copy is a successful no-op
9484 if (size > 0)
9485 {
9486 writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
9487 }
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00009488 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00009489 }
9490 catch(std::bad_alloc&)
9491 {
9492 return gl::error(GL_OUT_OF_MEMORY);
9493 }
9494}
9495
9496void __stdcall glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
9497{
9498 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
9499 program, uniformCount, uniformNames, uniformIndices);
9500
9501 try
9502 {
9503 gl::Context *context = gl::getNonLostContext();
9504
9505 if (context)
9506 {
9507 if (context->getClientVersion() < 3)
9508 {
9509 return gl::error(GL_INVALID_OPERATION);
9510 }
9511 }
9512
9513 UNIMPLEMENTED();
9514 }
9515 catch(std::bad_alloc&)
9516 {
9517 return gl::error(GL_OUT_OF_MEMORY);
9518 }
9519}
9520
9521void __stdcall glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
9522{
9523 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9524 program, uniformCount, uniformIndices, pname, params);
9525
9526 try
9527 {
9528 gl::Context *context = gl::getNonLostContext();
9529
9530 if (context)
9531 {
9532 if (context->getClientVersion() < 3)
9533 {
9534 return gl::error(GL_INVALID_OPERATION);
9535 }
9536 }
9537
9538 UNIMPLEMENTED();
9539 }
9540 catch(std::bad_alloc&)
9541 {
9542 return gl::error(GL_OUT_OF_MEMORY);
9543 }
9544}
9545
9546GLuint __stdcall glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
9547{
9548 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
9549
9550 try
9551 {
9552 gl::Context *context = gl::getNonLostContext();
9553
9554 if (context)
9555 {
9556 if (context->getClientVersion() < 3)
9557 {
9558 return gl::error(GL_INVALID_OPERATION, 0);
9559 }
9560 }
9561
9562 UNIMPLEMENTED();
9563 }
9564 catch(std::bad_alloc&)
9565 {
9566 return gl::error(GL_OUT_OF_MEMORY, 0);
9567 }
9568
9569 return 0;
9570}
9571
9572void __stdcall glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
9573{
9574 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
9575 program, uniformBlockIndex, pname, params);
9576
9577 try
9578 {
9579 gl::Context *context = gl::getNonLostContext();
9580
9581 if (context)
9582 {
9583 if (context->getClientVersion() < 3)
9584 {
9585 return gl::error(GL_INVALID_OPERATION);
9586 }
9587 }
9588
9589 UNIMPLEMENTED();
9590 }
9591 catch(std::bad_alloc&)
9592 {
9593 return gl::error(GL_OUT_OF_MEMORY);
9594 }
9595}
9596
9597void __stdcall glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
9598{
9599 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
9600 program, uniformBlockIndex, bufSize, length, uniformBlockName);
9601
9602 try
9603 {
9604 gl::Context *context = gl::getNonLostContext();
9605
9606 if (context)
9607 {
9608 if (context->getClientVersion() < 3)
9609 {
9610 return gl::error(GL_INVALID_OPERATION);
9611 }
9612 }
9613
9614 UNIMPLEMENTED();
9615 }
9616 catch(std::bad_alloc&)
9617 {
9618 return gl::error(GL_OUT_OF_MEMORY);
9619 }
9620}
9621
9622void __stdcall glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
9623{
9624 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
9625 program, uniformBlockIndex, uniformBlockBinding);
9626
9627 try
9628 {
9629 gl::Context *context = gl::getNonLostContext();
9630
9631 if (context)
9632 {
9633 if (context->getClientVersion() < 3)
9634 {
9635 return gl::error(GL_INVALID_OPERATION);
9636 }
9637 }
9638
9639 UNIMPLEMENTED();
9640 }
9641 catch(std::bad_alloc&)
9642 {
9643 return gl::error(GL_OUT_OF_MEMORY);
9644 }
9645}
9646
9647void __stdcall glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
9648{
9649 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
9650 mode, first, count, instanceCount);
9651
9652 try
9653 {
9654 gl::Context *context = gl::getNonLostContext();
9655
9656 if (context)
9657 {
9658 if (context->getClientVersion() < 3)
9659 {
9660 return gl::error(GL_INVALID_OPERATION);
9661 }
9662 }
9663
9664 UNIMPLEMENTED();
9665 }
9666 catch(std::bad_alloc&)
9667 {
9668 return gl::error(GL_OUT_OF_MEMORY);
9669 }
9670}
9671
9672void __stdcall glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
9673{
9674 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
9675 mode, count, type, indices, instanceCount);
9676
9677 try
9678 {
9679 gl::Context *context = gl::getNonLostContext();
9680
9681 if (context)
9682 {
9683 if (context->getClientVersion() < 3)
9684 {
9685 return gl::error(GL_INVALID_OPERATION);
9686 }
9687 }
9688
9689 UNIMPLEMENTED();
9690 }
9691 catch(std::bad_alloc&)
9692 {
9693 return gl::error(GL_OUT_OF_MEMORY);
9694 }
9695}
9696
9697GLsync __stdcall glFenceSync(GLenum condition, GLbitfield flags)
9698{
9699 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
9700
9701 try
9702 {
9703 gl::Context *context = gl::getNonLostContext();
9704
9705 if (context)
9706 {
9707 if (context->getClientVersion() < 3)
9708 {
9709 return gl::error(GL_INVALID_OPERATION, reinterpret_cast<GLsync>(NULL));
9710 }
9711 }
9712
9713 UNIMPLEMENTED();
9714 }
9715 catch(std::bad_alloc&)
9716 {
9717 return gl::error(GL_OUT_OF_MEMORY, reinterpret_cast<GLsync>(NULL));
9718 }
9719
9720 return NULL;
9721}
9722
9723GLboolean __stdcall glIsSync(GLsync sync)
9724{
9725 EVENT("(GLsync sync = 0x%0.8p)", sync);
9726
9727 try
9728 {
9729 gl::Context *context = gl::getNonLostContext();
9730
9731 if (context)
9732 {
9733 if (context->getClientVersion() < 3)
9734 {
9735 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9736 }
9737 }
9738
9739 UNIMPLEMENTED();
9740 }
9741 catch(std::bad_alloc&)
9742 {
9743 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9744 }
9745
9746 return GL_FALSE;
9747}
9748
9749void __stdcall glDeleteSync(GLsync sync)
9750{
9751 EVENT("(GLsync sync = 0x%0.8p)", sync);
9752
9753 try
9754 {
9755 gl::Context *context = gl::getNonLostContext();
9756
9757 if (context)
9758 {
9759 if (context->getClientVersion() < 3)
9760 {
9761 return gl::error(GL_INVALID_OPERATION);
9762 }
9763 }
9764
9765 UNIMPLEMENTED();
9766 }
9767 catch(std::bad_alloc&)
9768 {
9769 return gl::error(GL_OUT_OF_MEMORY);
9770 }
9771}
9772
9773GLenum __stdcall glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
9774{
9775 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
9776 sync, flags, timeout);
9777
9778 try
9779 {
9780 gl::Context *context = gl::getNonLostContext();
9781
9782 if (context)
9783 {
9784 if (context->getClientVersion() < 3)
9785 {
9786 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9787 }
9788 }
9789
9790 UNIMPLEMENTED();
9791 }
9792 catch(std::bad_alloc&)
9793 {
9794 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9795 }
9796
9797 return GL_FALSE;
9798}
9799
9800void __stdcall glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
9801{
9802 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
9803 sync, flags, timeout);
9804
9805 try
9806 {
9807 gl::Context *context = gl::getNonLostContext();
9808
9809 if (context)
9810 {
9811 if (context->getClientVersion() < 3)
9812 {
9813 return gl::error(GL_INVALID_OPERATION);
9814 }
9815 }
9816
9817 UNIMPLEMENTED();
9818 }
9819 catch(std::bad_alloc&)
9820 {
9821 return gl::error(GL_OUT_OF_MEMORY);
9822 }
9823}
9824
9825void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
9826{
9827 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
9828 pname, params);
9829
9830 try
9831 {
9832 gl::Context *context = gl::getNonLostContext();
9833
9834 if (context)
9835 {
9836 if (context->getClientVersion() < 3)
9837 {
9838 return gl::error(GL_INVALID_OPERATION);
9839 }
9840 }
9841
9842 UNIMPLEMENTED();
9843 }
9844 catch(std::bad_alloc&)
9845 {
9846 return gl::error(GL_OUT_OF_MEMORY);
9847 }
9848}
9849
9850void __stdcall glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
9851{
9852 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
9853 sync, pname, bufSize, length, values);
9854
9855 try
9856 {
9857 gl::Context *context = gl::getNonLostContext();
9858
9859 if (context)
9860 {
9861 if (context->getClientVersion() < 3)
9862 {
9863 return gl::error(GL_INVALID_OPERATION);
9864 }
9865 }
9866
9867 UNIMPLEMENTED();
9868 }
9869 catch(std::bad_alloc&)
9870 {
9871 return gl::error(GL_OUT_OF_MEMORY);
9872 }
9873}
9874
9875void __stdcall glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
9876{
9877 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
9878 target, index, data);
9879
9880 try
9881 {
9882 gl::Context *context = gl::getNonLostContext();
9883
9884 if (context)
9885 {
9886 if (context->getClientVersion() < 3)
9887 {
9888 return gl::error(GL_INVALID_OPERATION);
9889 }
9890 }
9891
9892 UNIMPLEMENTED();
9893 }
9894 catch(std::bad_alloc&)
9895 {
9896 return gl::error(GL_OUT_OF_MEMORY);
9897 }
9898}
9899
9900void __stdcall glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
9901{
9902 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
9903 target, pname, params);
9904
9905 try
9906 {
9907 gl::Context *context = gl::getNonLostContext();
9908
9909 if (context)
9910 {
9911 if (context->getClientVersion() < 3)
9912 {
9913 return gl::error(GL_INVALID_OPERATION);
9914 }
9915 }
9916
9917 UNIMPLEMENTED();
9918 }
9919 catch(std::bad_alloc&)
9920 {
9921 return gl::error(GL_OUT_OF_MEMORY);
9922 }
9923}
9924
9925void __stdcall glGenSamplers(GLsizei count, GLuint* samplers)
9926{
9927 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
9928
9929 try
9930 {
9931 gl::Context *context = gl::getNonLostContext();
9932
9933 if (context)
9934 {
9935 if (context->getClientVersion() < 3)
9936 {
9937 return gl::error(GL_INVALID_OPERATION);
9938 }
9939 }
9940
9941 UNIMPLEMENTED();
9942 }
9943 catch(std::bad_alloc&)
9944 {
9945 return gl::error(GL_OUT_OF_MEMORY);
9946 }
9947}
9948
9949void __stdcall glDeleteSamplers(GLsizei count, const GLuint* samplers)
9950{
9951 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
9952
9953 try
9954 {
9955 gl::Context *context = gl::getNonLostContext();
9956
9957 if (context)
9958 {
9959 if (context->getClientVersion() < 3)
9960 {
9961 return gl::error(GL_INVALID_OPERATION);
9962 }
9963 }
9964
9965 UNIMPLEMENTED();
9966 }
9967 catch(std::bad_alloc&)
9968 {
9969 return gl::error(GL_OUT_OF_MEMORY);
9970 }
9971}
9972
9973GLboolean __stdcall glIsSampler(GLuint sampler)
9974{
9975 EVENT("(GLuint sampler = %u)", sampler);
9976
9977 try
9978 {
9979 gl::Context *context = gl::getNonLostContext();
9980
9981 if (context)
9982 {
9983 if (context->getClientVersion() < 3)
9984 {
9985 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
9986 }
9987 }
9988
9989 UNIMPLEMENTED();
9990 }
9991 catch(std::bad_alloc&)
9992 {
9993 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
9994 }
9995
9996 return GL_FALSE;
9997}
9998
9999void __stdcall glBindSampler(GLuint unit, GLuint sampler)
10000{
10001 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
10002
10003 try
10004 {
10005 gl::Context *context = gl::getNonLostContext();
10006
10007 if (context)
10008 {
10009 if (context->getClientVersion() < 3)
10010 {
10011 return gl::error(GL_INVALID_OPERATION);
10012 }
10013 }
10014
10015 UNIMPLEMENTED();
10016 }
10017 catch(std::bad_alloc&)
10018 {
10019 return gl::error(GL_OUT_OF_MEMORY);
10020 }
10021}
10022
10023void __stdcall glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
10024{
10025 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
10026
10027 try
10028 {
10029 gl::Context *context = gl::getNonLostContext();
10030
10031 if (context)
10032 {
10033 if (context->getClientVersion() < 3)
10034 {
10035 return gl::error(GL_INVALID_OPERATION);
10036 }
10037 }
10038
10039 UNIMPLEMENTED();
10040 }
10041 catch(std::bad_alloc&)
10042 {
10043 return gl::error(GL_OUT_OF_MEMORY);
10044 }
10045}
10046
10047void __stdcall glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
10048{
10049 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLint* param = 0x%0.8p)",
10050 sampler, pname, param);
10051
10052 try
10053 {
10054 gl::Context *context = gl::getNonLostContext();
10055
10056 if (context)
10057 {
10058 if (context->getClientVersion() < 3)
10059 {
10060 return gl::error(GL_INVALID_OPERATION);
10061 }
10062 }
10063
10064 UNIMPLEMENTED();
10065 }
10066 catch(std::bad_alloc&)
10067 {
10068 return gl::error(GL_OUT_OF_MEMORY);
10069 }
10070}
10071
10072void __stdcall glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
10073{
10074 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
10075
10076 try
10077 {
10078 gl::Context *context = gl::getNonLostContext();
10079
10080 if (context)
10081 {
10082 if (context->getClientVersion() < 3)
10083 {
10084 return gl::error(GL_INVALID_OPERATION);
10085 }
10086 }
10087
10088 UNIMPLEMENTED();
10089 }
10090 catch(std::bad_alloc&)
10091 {
10092 return gl::error(GL_OUT_OF_MEMORY);
10093 }
10094}
10095
10096void __stdcall glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
10097{
10098 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, const GLfloat* param = 0x%0.8p)", sampler, pname, param);
10099
10100 try
10101 {
10102 gl::Context *context = gl::getNonLostContext();
10103
10104 if (context)
10105 {
10106 if (context->getClientVersion() < 3)
10107 {
10108 return gl::error(GL_INVALID_OPERATION);
10109 }
10110 }
10111
10112 UNIMPLEMENTED();
10113 }
10114 catch(std::bad_alloc&)
10115 {
10116 return gl::error(GL_OUT_OF_MEMORY);
10117 }
10118}
10119
10120void __stdcall glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
10121{
10122 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
10123
10124 try
10125 {
10126 gl::Context *context = gl::getNonLostContext();
10127
10128 if (context)
10129 {
10130 if (context->getClientVersion() < 3)
10131 {
10132 return gl::error(GL_INVALID_OPERATION);
10133 }
10134 }
10135
10136 UNIMPLEMENTED();
10137 }
10138 catch(std::bad_alloc&)
10139 {
10140 return gl::error(GL_OUT_OF_MEMORY);
10141 }
10142}
10143
10144void __stdcall glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
10145{
10146 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
10147
10148 try
10149 {
10150 gl::Context *context = gl::getNonLostContext();
10151
10152 if (context)
10153 {
10154 if (context->getClientVersion() < 3)
10155 {
10156 return gl::error(GL_INVALID_OPERATION);
10157 }
10158 }
10159
10160 UNIMPLEMENTED();
10161 }
10162 catch(std::bad_alloc&)
10163 {
10164 return gl::error(GL_OUT_OF_MEMORY);
10165 }
10166}
10167
10168void __stdcall glVertexAttribDivisor(GLuint index, GLuint divisor)
10169{
10170 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
10171
10172 try
10173 {
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000010174 if (index >= gl::MAX_VERTEX_ATTRIBS)
10175 {
10176 return gl::error(GL_INVALID_VALUE);
10177 }
10178
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010179 gl::Context *context = gl::getNonLostContext();
10180
10181 if (context)
10182 {
10183 if (context->getClientVersion() < 3)
10184 {
10185 return gl::error(GL_INVALID_OPERATION);
10186 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010187
shannon.woods%transgaming.com@gtempaccount.com8736bd62013-04-13 03:35:41 +000010188 context->setVertexAttribDivisor(index, divisor);
10189 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010190 }
10191 catch(std::bad_alloc&)
10192 {
10193 return gl::error(GL_OUT_OF_MEMORY);
10194 }
10195}
10196
10197void __stdcall glBindTransformFeedback(GLenum target, GLuint id)
10198{
10199 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
10200
10201 try
10202 {
10203 gl::Context *context = gl::getNonLostContext();
10204
10205 if (context)
10206 {
10207 if (context->getClientVersion() < 3)
10208 {
10209 return gl::error(GL_INVALID_OPERATION);
10210 }
10211 }
10212
10213 UNIMPLEMENTED();
10214 }
10215 catch(std::bad_alloc&)
10216 {
10217 return gl::error(GL_OUT_OF_MEMORY);
10218 }
10219}
10220
10221void __stdcall glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
10222{
10223 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
10224
10225 try
10226 {
10227 gl::Context *context = gl::getNonLostContext();
10228
10229 if (context)
10230 {
10231 if (context->getClientVersion() < 3)
10232 {
10233 return gl::error(GL_INVALID_OPERATION);
10234 }
10235 }
10236
10237 UNIMPLEMENTED();
10238 }
10239 catch(std::bad_alloc&)
10240 {
10241 return gl::error(GL_OUT_OF_MEMORY);
10242 }
10243}
10244
10245void __stdcall glGenTransformFeedbacks(GLsizei n, GLuint* ids)
10246{
10247 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
10248
10249 try
10250 {
10251 gl::Context *context = gl::getNonLostContext();
10252
10253 if (context)
10254 {
10255 if (context->getClientVersion() < 3)
10256 {
10257 return gl::error(GL_INVALID_OPERATION);
10258 }
10259 }
10260
10261 UNIMPLEMENTED();
10262 }
10263 catch(std::bad_alloc&)
10264 {
10265 return gl::error(GL_OUT_OF_MEMORY);
10266 }
10267}
10268
10269GLboolean __stdcall glIsTransformFeedback(GLuint id)
10270{
10271 EVENT("(GLuint id = %u)", id);
10272
10273 try
10274 {
10275 gl::Context *context = gl::getNonLostContext();
10276
10277 if (context)
10278 {
10279 if (context->getClientVersion() < 3)
10280 {
10281 return gl::error(GL_INVALID_OPERATION, GL_FALSE);
10282 }
10283 }
10284
10285 UNIMPLEMENTED();
10286 }
10287 catch(std::bad_alloc&)
10288 {
10289 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
10290 }
10291
10292 return GL_FALSE;
10293}
10294
10295void __stdcall glPauseTransformFeedback(void)
10296{
10297 EVENT("(void)");
10298
10299 try
10300 {
10301 gl::Context *context = gl::getNonLostContext();
10302
10303 if (context)
10304 {
10305 if (context->getClientVersion() < 3)
10306 {
10307 return gl::error(GL_INVALID_OPERATION);
10308 }
10309 }
10310
10311 UNIMPLEMENTED();
10312 }
10313 catch(std::bad_alloc&)
10314 {
10315 return gl::error(GL_OUT_OF_MEMORY);
10316 }
10317}
10318
10319void __stdcall glResumeTransformFeedback(void)
10320{
10321 EVENT("(void)");
10322
10323 try
10324 {
10325 gl::Context *context = gl::getNonLostContext();
10326
10327 if (context)
10328 {
10329 if (context->getClientVersion() < 3)
10330 {
10331 return gl::error(GL_INVALID_OPERATION);
10332 }
10333 }
10334
10335 UNIMPLEMENTED();
10336 }
10337 catch(std::bad_alloc&)
10338 {
10339 return gl::error(GL_OUT_OF_MEMORY);
10340 }
10341}
10342
10343void __stdcall glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
10344{
10345 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
10346 program, bufSize, length, binaryFormat, binary);
10347
10348 try
10349 {
10350 gl::Context *context = gl::getNonLostContext();
10351
10352 if (context)
10353 {
10354 if (context->getClientVersion() < 3)
10355 {
10356 return gl::error(GL_INVALID_OPERATION);
10357 }
10358 }
10359
10360 UNIMPLEMENTED();
10361 }
10362 catch(std::bad_alloc&)
10363 {
10364 return gl::error(GL_OUT_OF_MEMORY);
10365 }
10366}
10367
10368void __stdcall glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
10369{
10370 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
10371 program, binaryFormat, binary, length);
10372
10373 try
10374 {
10375 gl::Context *context = gl::getNonLostContext();
10376
10377 if (context)
10378 {
10379 if (context->getClientVersion() < 3)
10380 {
10381 return gl::error(GL_INVALID_OPERATION);
10382 }
10383 }
10384
10385 UNIMPLEMENTED();
10386 }
10387 catch(std::bad_alloc&)
10388 {
10389 return gl::error(GL_OUT_OF_MEMORY);
10390 }
10391}
10392
10393void __stdcall glProgramParameteri(GLuint program, GLenum pname, GLint value)
10394{
10395 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
10396 program, pname, value);
10397
10398 try
10399 {
10400 gl::Context *context = gl::getNonLostContext();
10401
10402 if (context)
10403 {
10404 if (context->getClientVersion() < 3)
10405 {
10406 return gl::error(GL_INVALID_OPERATION);
10407 }
10408 }
10409
10410 UNIMPLEMENTED();
10411 }
10412 catch(std::bad_alloc&)
10413 {
10414 return gl::error(GL_OUT_OF_MEMORY);
10415 }
10416}
10417
10418void __stdcall glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
10419{
10420 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
10421 target, numAttachments, attachments);
10422
10423 try
10424 {
10425 gl::Context *context = gl::getNonLostContext();
10426
10427 if (context)
10428 {
10429 if (context->getClientVersion() < 3)
10430 {
10431 return gl::error(GL_INVALID_OPERATION);
10432 }
10433 }
10434
10435 UNIMPLEMENTED();
10436 }
10437 catch(std::bad_alloc&)
10438 {
10439 return gl::error(GL_OUT_OF_MEMORY);
10440 }
10441}
10442
10443void __stdcall glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
10444{
10445 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
10446 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
10447 target, numAttachments, attachments, x, y, width, height);
10448
10449 try
10450 {
10451 gl::Context *context = gl::getNonLostContext();
10452
10453 if (context)
10454 {
10455 if (context->getClientVersion() < 3)
10456 {
10457 return gl::error(GL_INVALID_OPERATION);
10458 }
10459 }
10460
10461 UNIMPLEMENTED();
10462 }
10463 catch(std::bad_alloc&)
10464 {
10465 return gl::error(GL_OUT_OF_MEMORY);
10466 }
10467}
10468
10469void __stdcall glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
10470{
10471 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
10472 target, levels, internalformat, width, height);
10473
10474 try
10475 {
10476 gl::Context *context = gl::getNonLostContext();
10477
10478 if (context)
10479 {
10480 if (context->getClientVersion() < 3)
10481 {
10482 return gl::error(GL_INVALID_OPERATION);
10483 }
10484 }
10485
10486 UNIMPLEMENTED();
10487 }
10488 catch(std::bad_alloc&)
10489 {
10490 return gl::error(GL_OUT_OF_MEMORY);
10491 }
10492}
10493
10494void __stdcall glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
10495{
10496 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
10497 "GLsizei height = %d, GLsizei depth = %d)",
10498 target, levels, internalformat, width, height, depth);
10499
10500 try
10501 {
10502 gl::Context *context = gl::getNonLostContext();
10503
10504 if (context)
10505 {
10506 if (context->getClientVersion() < 3)
10507 {
10508 return gl::error(GL_INVALID_OPERATION);
10509 }
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +000010510 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000010511 }
10512 catch(std::bad_alloc&)
10513 {
10514 return gl::error(GL_OUT_OF_MEMORY);
10515 }
10516}
10517
10518void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
10519{
10520 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
10521 "GLint* params = 0x%0.8p)",
10522 target, internalformat, pname, bufSize, params);
10523
10524 try
10525 {
10526 gl::Context *context = gl::getNonLostContext();
10527
10528 if (context)
10529 {
10530 if (context->getClientVersion() < 3)
10531 {
10532 return gl::error(GL_INVALID_OPERATION);
10533 }
10534 }
10535
10536 UNIMPLEMENTED();
10537 }
10538 catch(std::bad_alloc&)
10539 {
10540 return gl::error(GL_OUT_OF_MEMORY);
10541 }
10542}
10543
10544// Extension functions
10545
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010546void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
10547 GLbitfield mask, GLenum filter)
10548{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000010549 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010550 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
10551 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
10552 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
10553
10554 try
10555 {
10556 switch (filter)
10557 {
10558 case GL_NEAREST:
10559 break;
10560 default:
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010561 return gl::error(GL_INVALID_ENUM);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010562 }
10563
10564 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
10565 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010566 return gl::error(GL_INVALID_VALUE);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010567 }
10568
10569 if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0)
10570 {
10571 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation");
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010572 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010573 }
10574
daniel@transgaming.com9d788502011-11-09 17:46:55 +000010575 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010576
10577 if (context)
10578 {
10579 if (context->getReadFramebufferHandle() == context->getDrawFramebufferHandle())
10580 {
10581 ERR("Blits with the same source and destination framebuffer are not supported by this implementation.");
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010582 return gl::error(GL_INVALID_OPERATION);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010583 }
10584
10585 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask);
10586 }
10587 }
10588 catch(std::bad_alloc&)
10589 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010590 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000010591 }
10592}
10593
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000010594void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
10595 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000010596{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000010597 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +000010598 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +000010599 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000010600 target, level, internalformat, width, height, depth, border, format, type, pixels);
10601
10602 try
10603 {
10604 UNIMPLEMENTED(); // FIXME
10605 }
10606 catch(std::bad_alloc&)
10607 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010608 return gl::error(GL_OUT_OF_MEMORY);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000010609 }
10610}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000010611
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010612void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
10613 GLenum *binaryFormat, void *binary)
10614{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000010615 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 +000010616 program, bufSize, length, binaryFormat, binary);
10617
10618 try
10619 {
10620 gl::Context *context = gl::getNonLostContext();
10621
10622 if (context)
10623 {
10624 gl::Program *programObject = context->getProgram(program);
10625
daniel@transgaming.com716056c2012-07-24 18:38:59 +000010626 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010627 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010628 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010629 }
10630
10631 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
10632
10633 if (!programBinary)
10634 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010635 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010636 }
10637
apatrick@chromium.org90080e32012-07-09 22:15:33 +000010638 if (!programBinary->save(binary, bufSize, length))
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010639 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010640 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010641 }
apatrick@chromium.org90080e32012-07-09 22:15:33 +000010642
10643 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010644 }
10645 }
10646 catch(std::bad_alloc&)
10647 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010648 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010649 }
10650}
10651
10652void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
10653 const void *binary, GLint length)
10654{
10655 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
10656 program, binaryFormat, binary, length);
10657
10658 try
10659 {
10660 gl::Context *context = gl::getNonLostContext();
10661
10662 if (context)
10663 {
10664 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
10665 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010666 return gl::error(GL_INVALID_ENUM);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010667 }
10668
10669 gl::Program *programObject = context->getProgram(program);
10670
10671 if (!programObject)
10672 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010673 return gl::error(GL_INVALID_OPERATION);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010674 }
10675
daniel@transgaming.com95d29422012-07-24 18:36:10 +000010676 context->setProgramBinary(program, binary, length);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010677 }
10678 }
10679 catch(std::bad_alloc&)
10680 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010681 return gl::error(GL_OUT_OF_MEMORY);
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010682 }
10683}
10684
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000010685void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
10686{
10687 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
10688
10689 try
10690 {
10691 gl::Context *context = gl::getNonLostContext();
10692
10693 if (context)
10694 {
10695 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
10696 {
10697 return gl::error(GL_INVALID_VALUE);
10698 }
10699
10700 if (context->getDrawFramebufferHandle() == 0)
10701 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000010702 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000010703 {
10704 return gl::error(GL_INVALID_OPERATION);
10705 }
10706
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000010707 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000010708 {
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000010709 return gl::error(GL_INVALID_OPERATION);
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000010710 }
10711 }
10712 else
10713 {
10714 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
10715 {
10716 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
10717 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
10718 {
10719 return gl::error(GL_INVALID_OPERATION);
10720 }
10721 }
10722 }
10723
10724 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
10725
10726 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
10727 {
10728 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
10729 }
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +000010730
10731 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
10732 {
10733 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
10734 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +000010735 }
10736 }
10737 catch (std::bad_alloc&)
10738 {
10739 return gl::error(GL_OUT_OF_MEMORY);
10740 }
10741}
10742
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000010743__eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
10744{
10745 struct Extension
10746 {
10747 const char *name;
10748 __eglMustCastToProperFunctionPointerType address;
10749 };
10750
10751 static const Extension glExtensions[] =
10752 {
10753 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
daniel@transgaming.com01868132010-08-24 19:21:17 +000010754 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
daniel@transgaming.com1fe96c92011-01-14 15:08:44 +000010755 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +000010756 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
10757 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
10758 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
10759 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
10760 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
10761 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
10762 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
zmo@google.coma574f782011-10-03 21:45:23 +000010763 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
daniel@transgaming.com0bd1f2f2011-11-11 04:19:03 +000010764 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
daniel@transgaming.com709ed112011-11-12 03:18:10 +000010765 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
10766 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
10767 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
10768 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
daniel@transgaming.com86bdb822012-01-20 18:24:39 +000010769 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
10770 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
10771 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
10772 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
10773 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
10774 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
10775 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
shannon.woods%transgaming.com@gtempaccount.com77d94722013-04-13 03:34:22 +000010776 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
daniel@transgaming.comdce02fd2012-01-27 15:39:51 +000010777 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
10778 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
10779 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +000010780 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
10781 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000010782
shannon.woods@transgaming.comd438fd42013-02-28 23:17:45 +000010783 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +000010784 {
10785 if (strcmp(procname, glExtensions[ext].name) == 0)
10786 {
10787 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
10788 }
10789 }
10790
10791 return NULL;
10792}
10793
daniel@transgaming.com17f548c2011-11-09 17:47:02 +000010794// Non-public functions used by EGL
10795
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000010796bool __stdcall glBindTexImage(egl::Surface *surface)
jbauman@chromium.orgae345802011-03-30 22:04:25 +000010797{
10798 EVENT("(egl::Surface* surface = 0x%0.8p)",
10799 surface);
10800
10801 try
10802 {
daniel@transgaming.com9d788502011-11-09 17:46:55 +000010803 gl::Context *context = gl::getNonLostContext();
jbauman@chromium.orgae345802011-03-30 22:04:25 +000010804
10805 if (context)
10806 {
10807 gl::Texture2D *textureObject = context->getTexture2D();
10808
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000010809 if (textureObject->isImmutable())
10810 {
10811 return false;
10812 }
10813
jbauman@chromium.orgae345802011-03-30 22:04:25 +000010814 if (textureObject)
10815 {
10816 textureObject->bindTexImage(surface);
10817 }
10818 }
10819 }
10820 catch(std::bad_alloc&)
10821 {
shannon.woods@transgaming.com779aa262013-02-28 23:04:58 +000010822 return gl::error(GL_OUT_OF_MEMORY, false);
jbauman@chromium.orgae345802011-03-30 22:04:25 +000010823 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +000010824
10825 return true;
jbauman@chromium.orgae345802011-03-30 22:04:25 +000010826}
10827
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000010828}