gfx/angle/src/libGLESv2/libGLESv2.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 #include "precompiled.h"
michael@0 2 //
michael@0 3 // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
michael@0 4 // Use of this source code is governed by a BSD-style license that can be
michael@0 5 // found in the LICENSE file.
michael@0 6 //
michael@0 7
michael@0 8 // libGLESv2.cpp: Implements the exported OpenGL ES 2.0 functions.
michael@0 9
michael@0 10 #include "common/version.h"
michael@0 11
michael@0 12 #include <algorithm>
michael@0 13
michael@0 14 #include "libGLESv2/main.h"
michael@0 15 #include "libGLESv2/utilities.h"
michael@0 16 #include "libGLESv2/Buffer.h"
michael@0 17 #include "libGLESv2/Fence.h"
michael@0 18 #include "libGLESv2/Framebuffer.h"
michael@0 19 #include "libGLESv2/Renderbuffer.h"
michael@0 20 #include "libGLESv2/Program.h"
michael@0 21 #include "libGLESv2/ProgramBinary.h"
michael@0 22 #include "libGLESv2/Texture.h"
michael@0 23 #include "libGLESv2/Query.h"
michael@0 24 #include "libGLESv2/Context.h"
michael@0 25
michael@0 26 bool validImageSize(GLint level, GLsizei width, GLsizei height)
michael@0 27 {
michael@0 28 if (level < 0 || width < 0 || height < 0)
michael@0 29 {
michael@0 30 return false;
michael@0 31 }
michael@0 32
michael@0 33 if (gl::getContext() && gl::getContext()->supportsNonPower2Texture())
michael@0 34 {
michael@0 35 return true;
michael@0 36 }
michael@0 37
michael@0 38 if (level == 0)
michael@0 39 {
michael@0 40 return true;
michael@0 41 }
michael@0 42
michael@0 43 if (gl::isPow2(width) && gl::isPow2(height))
michael@0 44 {
michael@0 45 return true;
michael@0 46 }
michael@0 47
michael@0 48 return false;
michael@0 49 }
michael@0 50
michael@0 51 // Verify that format/type are one of the combinations from table 3.4.
michael@0 52 bool checkTextureFormatType(GLenum format, GLenum type)
michael@0 53 {
michael@0 54 // validate <format> by itself (used as secondary key below)
michael@0 55 switch (format)
michael@0 56 {
michael@0 57 case GL_RGBA:
michael@0 58 case GL_BGRA_EXT:
michael@0 59 case GL_RGB:
michael@0 60 case GL_ALPHA:
michael@0 61 case GL_LUMINANCE:
michael@0 62 case GL_LUMINANCE_ALPHA:
michael@0 63 case GL_DEPTH_COMPONENT:
michael@0 64 case GL_DEPTH_STENCIL_OES:
michael@0 65 break;
michael@0 66 default:
michael@0 67 return gl::error(GL_INVALID_ENUM, false);
michael@0 68 }
michael@0 69
michael@0 70 // invalid <type> -> sets INVALID_ENUM
michael@0 71 // invalid <format>+<type> combination -> sets INVALID_OPERATION
michael@0 72 switch (type)
michael@0 73 {
michael@0 74 case GL_UNSIGNED_BYTE:
michael@0 75 switch (format)
michael@0 76 {
michael@0 77 case GL_RGBA:
michael@0 78 case GL_BGRA_EXT:
michael@0 79 case GL_RGB:
michael@0 80 case GL_ALPHA:
michael@0 81 case GL_LUMINANCE:
michael@0 82 case GL_LUMINANCE_ALPHA:
michael@0 83 return true;
michael@0 84 default:
michael@0 85 return gl::error(GL_INVALID_OPERATION, false);
michael@0 86 }
michael@0 87
michael@0 88 case GL_FLOAT:
michael@0 89 case GL_HALF_FLOAT_OES:
michael@0 90 switch (format)
michael@0 91 {
michael@0 92 case GL_RGBA:
michael@0 93 case GL_RGB:
michael@0 94 case GL_ALPHA:
michael@0 95 case GL_LUMINANCE:
michael@0 96 case GL_LUMINANCE_ALPHA:
michael@0 97 return true;
michael@0 98 default:
michael@0 99 return gl::error(GL_INVALID_OPERATION, false);
michael@0 100 }
michael@0 101
michael@0 102 case GL_UNSIGNED_SHORT_4_4_4_4:
michael@0 103 case GL_UNSIGNED_SHORT_5_5_5_1:
michael@0 104 switch (format)
michael@0 105 {
michael@0 106 case GL_RGBA:
michael@0 107 return true;
michael@0 108 default:
michael@0 109 return gl::error(GL_INVALID_OPERATION, false);
michael@0 110 }
michael@0 111
michael@0 112 case GL_UNSIGNED_SHORT_5_6_5:
michael@0 113 switch (format)
michael@0 114 {
michael@0 115 case GL_RGB:
michael@0 116 return true;
michael@0 117 default:
michael@0 118 return gl::error(GL_INVALID_OPERATION, false);
michael@0 119 }
michael@0 120
michael@0 121 case GL_UNSIGNED_SHORT:
michael@0 122 case GL_UNSIGNED_INT:
michael@0 123 switch (format)
michael@0 124 {
michael@0 125 case GL_DEPTH_COMPONENT:
michael@0 126 return true;
michael@0 127 default:
michael@0 128 return gl::error(GL_INVALID_OPERATION, false);
michael@0 129 }
michael@0 130
michael@0 131 case GL_UNSIGNED_INT_24_8_OES:
michael@0 132 switch (format)
michael@0 133 {
michael@0 134 case GL_DEPTH_STENCIL_OES:
michael@0 135 return true;
michael@0 136 default:
michael@0 137 return gl::error(GL_INVALID_OPERATION, false);
michael@0 138 }
michael@0 139
michael@0 140 default:
michael@0 141 return gl::error(GL_INVALID_ENUM, false);
michael@0 142 }
michael@0 143 }
michael@0 144
michael@0 145 bool validateSubImageParams2D(bool compressed, GLsizei width, GLsizei height,
michael@0 146 GLint xoffset, GLint yoffset, GLint level, GLenum format, GLenum type,
michael@0 147 gl::Texture2D *texture)
michael@0 148 {
michael@0 149 if (!texture)
michael@0 150 {
michael@0 151 return gl::error(GL_INVALID_OPERATION, false);
michael@0 152 }
michael@0 153
michael@0 154 if (compressed != texture->isCompressed(level))
michael@0 155 {
michael@0 156 return gl::error(GL_INVALID_OPERATION, false);
michael@0 157 }
michael@0 158
michael@0 159 if (format != GL_NONE)
michael@0 160 {
michael@0 161 GLenum internalformat = gl::ConvertSizedInternalFormat(format, type);
michael@0 162 if (internalformat != texture->getInternalFormat(level))
michael@0 163 {
michael@0 164 return gl::error(GL_INVALID_OPERATION, false);
michael@0 165 }
michael@0 166 }
michael@0 167
michael@0 168 if (compressed)
michael@0 169 {
michael@0 170 if ((width % 4 != 0 && width != texture->getWidth(0)) ||
michael@0 171 (height % 4 != 0 && height != texture->getHeight(0)))
michael@0 172 {
michael@0 173 return gl::error(GL_INVALID_OPERATION, false);
michael@0 174 }
michael@0 175 }
michael@0 176
michael@0 177 if (xoffset + width > texture->getWidth(level) ||
michael@0 178 yoffset + height > texture->getHeight(level))
michael@0 179 {
michael@0 180 return gl::error(GL_INVALID_VALUE, false);
michael@0 181 }
michael@0 182
michael@0 183 return true;
michael@0 184 }
michael@0 185
michael@0 186 bool validateSubImageParamsCube(bool compressed, GLsizei width, GLsizei height,
michael@0 187 GLint xoffset, GLint yoffset, GLenum target, GLint level, GLenum format, GLenum type,
michael@0 188 gl::TextureCubeMap *texture)
michael@0 189 {
michael@0 190 if (!texture)
michael@0 191 {
michael@0 192 return gl::error(GL_INVALID_OPERATION, false);
michael@0 193 }
michael@0 194
michael@0 195 if (compressed != texture->isCompressed(target, level))
michael@0 196 {
michael@0 197 return gl::error(GL_INVALID_OPERATION, false);
michael@0 198 }
michael@0 199
michael@0 200 if (format != GL_NONE)
michael@0 201 {
michael@0 202 GLenum internalformat = gl::ConvertSizedInternalFormat(format, type);
michael@0 203 if (internalformat != texture->getInternalFormat(target, level))
michael@0 204 {
michael@0 205 return gl::error(GL_INVALID_OPERATION, false);
michael@0 206 }
michael@0 207 }
michael@0 208
michael@0 209 if (compressed)
michael@0 210 {
michael@0 211 if ((width % 4 != 0 && width != texture->getWidth(target, 0)) ||
michael@0 212 (height % 4 != 0 && height != texture->getHeight(target, 0)))
michael@0 213 {
michael@0 214 return gl::error(GL_INVALID_OPERATION, false);
michael@0 215 }
michael@0 216 }
michael@0 217
michael@0 218 if (xoffset + width > texture->getWidth(target, level) ||
michael@0 219 yoffset + height > texture->getHeight(target, level))
michael@0 220 {
michael@0 221 return gl::error(GL_INVALID_VALUE, false);
michael@0 222 }
michael@0 223
michael@0 224 return true;
michael@0 225 }
michael@0 226
michael@0 227 // check for combinations of format and type that are valid for ReadPixels
michael@0 228 bool validReadFormatType(GLenum format, GLenum type)
michael@0 229 {
michael@0 230 switch (format)
michael@0 231 {
michael@0 232 case GL_RGBA:
michael@0 233 switch (type)
michael@0 234 {
michael@0 235 case GL_UNSIGNED_BYTE:
michael@0 236 break;
michael@0 237 default:
michael@0 238 return false;
michael@0 239 }
michael@0 240 break;
michael@0 241 case GL_BGRA_EXT:
michael@0 242 switch (type)
michael@0 243 {
michael@0 244 case GL_UNSIGNED_BYTE:
michael@0 245 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
michael@0 246 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
michael@0 247 break;
michael@0 248 default:
michael@0 249 return false;
michael@0 250 }
michael@0 251 break;
michael@0 252 default:
michael@0 253 return false;
michael@0 254 }
michael@0 255 return true;
michael@0 256 }
michael@0 257
michael@0 258 extern "C"
michael@0 259 {
michael@0 260
michael@0 261 void __stdcall glActiveTexture(GLenum texture)
michael@0 262 {
michael@0 263 EVENT("(GLenum texture = 0x%X)", texture);
michael@0 264
michael@0 265 try
michael@0 266 {
michael@0 267 gl::Context *context = gl::getNonLostContext();
michael@0 268
michael@0 269 if (context)
michael@0 270 {
michael@0 271 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getMaximumCombinedTextureImageUnits() - 1)
michael@0 272 {
michael@0 273 return gl::error(GL_INVALID_ENUM);
michael@0 274 }
michael@0 275
michael@0 276 context->setActiveSampler(texture - GL_TEXTURE0);
michael@0 277 }
michael@0 278 }
michael@0 279 catch(std::bad_alloc&)
michael@0 280 {
michael@0 281 return gl::error(GL_OUT_OF_MEMORY);
michael@0 282 }
michael@0 283 }
michael@0 284
michael@0 285 void __stdcall glAttachShader(GLuint program, GLuint shader)
michael@0 286 {
michael@0 287 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
michael@0 288
michael@0 289 try
michael@0 290 {
michael@0 291 gl::Context *context = gl::getNonLostContext();
michael@0 292
michael@0 293 if (context)
michael@0 294 {
michael@0 295 gl::Program *programObject = context->getProgram(program);
michael@0 296 gl::Shader *shaderObject = context->getShader(shader);
michael@0 297
michael@0 298 if (!programObject)
michael@0 299 {
michael@0 300 if (context->getShader(program))
michael@0 301 {
michael@0 302 return gl::error(GL_INVALID_OPERATION);
michael@0 303 }
michael@0 304 else
michael@0 305 {
michael@0 306 return gl::error(GL_INVALID_VALUE);
michael@0 307 }
michael@0 308 }
michael@0 309
michael@0 310 if (!shaderObject)
michael@0 311 {
michael@0 312 if (context->getProgram(shader))
michael@0 313 {
michael@0 314 return gl::error(GL_INVALID_OPERATION);
michael@0 315 }
michael@0 316 else
michael@0 317 {
michael@0 318 return gl::error(GL_INVALID_VALUE);
michael@0 319 }
michael@0 320 }
michael@0 321
michael@0 322 if (!programObject->attachShader(shaderObject))
michael@0 323 {
michael@0 324 return gl::error(GL_INVALID_OPERATION);
michael@0 325 }
michael@0 326 }
michael@0 327 }
michael@0 328 catch(std::bad_alloc&)
michael@0 329 {
michael@0 330 return gl::error(GL_OUT_OF_MEMORY);
michael@0 331 }
michael@0 332 }
michael@0 333
michael@0 334 void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
michael@0 335 {
michael@0 336 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
michael@0 337
michael@0 338 try
michael@0 339 {
michael@0 340 switch (target)
michael@0 341 {
michael@0 342 case GL_ANY_SAMPLES_PASSED_EXT:
michael@0 343 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
michael@0 344 break;
michael@0 345 default:
michael@0 346 return gl::error(GL_INVALID_ENUM);
michael@0 347 }
michael@0 348
michael@0 349 if (id == 0)
michael@0 350 {
michael@0 351 return gl::error(GL_INVALID_OPERATION);
michael@0 352 }
michael@0 353
michael@0 354 gl::Context *context = gl::getNonLostContext();
michael@0 355
michael@0 356 if (context)
michael@0 357 {
michael@0 358 context->beginQuery(target, id);
michael@0 359 }
michael@0 360 }
michael@0 361 catch(std::bad_alloc&)
michael@0 362 {
michael@0 363 return gl::error(GL_OUT_OF_MEMORY);
michael@0 364 }
michael@0 365 }
michael@0 366
michael@0 367 void __stdcall glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
michael@0 368 {
michael@0 369 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
michael@0 370
michael@0 371 try
michael@0 372 {
michael@0 373 if (index >= gl::MAX_VERTEX_ATTRIBS)
michael@0 374 {
michael@0 375 return gl::error(GL_INVALID_VALUE);
michael@0 376 }
michael@0 377
michael@0 378 gl::Context *context = gl::getNonLostContext();
michael@0 379
michael@0 380 if (context)
michael@0 381 {
michael@0 382 gl::Program *programObject = context->getProgram(program);
michael@0 383
michael@0 384 if (!programObject)
michael@0 385 {
michael@0 386 if (context->getShader(program))
michael@0 387 {
michael@0 388 return gl::error(GL_INVALID_OPERATION);
michael@0 389 }
michael@0 390 else
michael@0 391 {
michael@0 392 return gl::error(GL_INVALID_VALUE);
michael@0 393 }
michael@0 394 }
michael@0 395
michael@0 396 if (strncmp(name, "gl_", 3) == 0)
michael@0 397 {
michael@0 398 return gl::error(GL_INVALID_OPERATION);
michael@0 399 }
michael@0 400
michael@0 401 programObject->bindAttributeLocation(index, name);
michael@0 402 }
michael@0 403 }
michael@0 404 catch(std::bad_alloc&)
michael@0 405 {
michael@0 406 return gl::error(GL_OUT_OF_MEMORY);
michael@0 407 }
michael@0 408 }
michael@0 409
michael@0 410 void __stdcall glBindBuffer(GLenum target, GLuint buffer)
michael@0 411 {
michael@0 412 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
michael@0 413
michael@0 414 try
michael@0 415 {
michael@0 416 gl::Context *context = gl::getNonLostContext();
michael@0 417
michael@0 418 if (context)
michael@0 419 {
michael@0 420 switch (target)
michael@0 421 {
michael@0 422 case GL_ARRAY_BUFFER:
michael@0 423 context->bindArrayBuffer(buffer);
michael@0 424 return;
michael@0 425 case GL_ELEMENT_ARRAY_BUFFER:
michael@0 426 context->bindElementArrayBuffer(buffer);
michael@0 427 return;
michael@0 428 default:
michael@0 429 return gl::error(GL_INVALID_ENUM);
michael@0 430 }
michael@0 431 }
michael@0 432 }
michael@0 433 catch(std::bad_alloc&)
michael@0 434 {
michael@0 435 return gl::error(GL_OUT_OF_MEMORY);
michael@0 436 }
michael@0 437 }
michael@0 438
michael@0 439 void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer)
michael@0 440 {
michael@0 441 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
michael@0 442
michael@0 443 try
michael@0 444 {
michael@0 445 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
michael@0 446 {
michael@0 447 return gl::error(GL_INVALID_ENUM);
michael@0 448 }
michael@0 449
michael@0 450 gl::Context *context = gl::getNonLostContext();
michael@0 451
michael@0 452 if (context)
michael@0 453 {
michael@0 454 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
michael@0 455 {
michael@0 456 context->bindReadFramebuffer(framebuffer);
michael@0 457 }
michael@0 458
michael@0 459 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
michael@0 460 {
michael@0 461 context->bindDrawFramebuffer(framebuffer);
michael@0 462 }
michael@0 463 }
michael@0 464 }
michael@0 465 catch(std::bad_alloc&)
michael@0 466 {
michael@0 467 return gl::error(GL_OUT_OF_MEMORY);
michael@0 468 }
michael@0 469 }
michael@0 470
michael@0 471 void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer)
michael@0 472 {
michael@0 473 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
michael@0 474
michael@0 475 try
michael@0 476 {
michael@0 477 if (target != GL_RENDERBUFFER)
michael@0 478 {
michael@0 479 return gl::error(GL_INVALID_ENUM);
michael@0 480 }
michael@0 481
michael@0 482 gl::Context *context = gl::getNonLostContext();
michael@0 483
michael@0 484 if (context)
michael@0 485 {
michael@0 486 context->bindRenderbuffer(renderbuffer);
michael@0 487 }
michael@0 488 }
michael@0 489 catch(std::bad_alloc&)
michael@0 490 {
michael@0 491 return gl::error(GL_OUT_OF_MEMORY);
michael@0 492 }
michael@0 493 }
michael@0 494
michael@0 495 void __stdcall glBindTexture(GLenum target, GLuint texture)
michael@0 496 {
michael@0 497 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
michael@0 498
michael@0 499 try
michael@0 500 {
michael@0 501 gl::Context *context = gl::getNonLostContext();
michael@0 502
michael@0 503 if (context)
michael@0 504 {
michael@0 505 gl::Texture *textureObject = context->getTexture(texture);
michael@0 506
michael@0 507 if (textureObject && textureObject->getTarget() != target && texture != 0)
michael@0 508 {
michael@0 509 return gl::error(GL_INVALID_OPERATION);
michael@0 510 }
michael@0 511
michael@0 512 switch (target)
michael@0 513 {
michael@0 514 case GL_TEXTURE_2D:
michael@0 515 context->bindTexture2D(texture);
michael@0 516 return;
michael@0 517 case GL_TEXTURE_CUBE_MAP:
michael@0 518 context->bindTextureCubeMap(texture);
michael@0 519 return;
michael@0 520 default:
michael@0 521 return gl::error(GL_INVALID_ENUM);
michael@0 522 }
michael@0 523 }
michael@0 524 }
michael@0 525 catch(std::bad_alloc&)
michael@0 526 {
michael@0 527 return gl::error(GL_OUT_OF_MEMORY);
michael@0 528 }
michael@0 529 }
michael@0 530
michael@0 531 void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
michael@0 532 {
michael@0 533 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
michael@0 534 red, green, blue, alpha);
michael@0 535
michael@0 536 try
michael@0 537 {
michael@0 538 gl::Context* context = gl::getNonLostContext();
michael@0 539
michael@0 540 if (context)
michael@0 541 {
michael@0 542 context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
michael@0 543 }
michael@0 544 }
michael@0 545 catch(std::bad_alloc&)
michael@0 546 {
michael@0 547 return gl::error(GL_OUT_OF_MEMORY);
michael@0 548 }
michael@0 549 }
michael@0 550
michael@0 551 void __stdcall glBlendEquation(GLenum mode)
michael@0 552 {
michael@0 553 glBlendEquationSeparate(mode, mode);
michael@0 554 }
michael@0 555
michael@0 556 void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
michael@0 557 {
michael@0 558 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
michael@0 559
michael@0 560 try
michael@0 561 {
michael@0 562 switch (modeRGB)
michael@0 563 {
michael@0 564 case GL_FUNC_ADD:
michael@0 565 case GL_FUNC_SUBTRACT:
michael@0 566 case GL_FUNC_REVERSE_SUBTRACT:
michael@0 567 break;
michael@0 568 default:
michael@0 569 return gl::error(GL_INVALID_ENUM);
michael@0 570 }
michael@0 571
michael@0 572 switch (modeAlpha)
michael@0 573 {
michael@0 574 case GL_FUNC_ADD:
michael@0 575 case GL_FUNC_SUBTRACT:
michael@0 576 case GL_FUNC_REVERSE_SUBTRACT:
michael@0 577 break;
michael@0 578 default:
michael@0 579 return gl::error(GL_INVALID_ENUM);
michael@0 580 }
michael@0 581
michael@0 582 gl::Context *context = gl::getNonLostContext();
michael@0 583
michael@0 584 if (context)
michael@0 585 {
michael@0 586 context->setBlendEquation(modeRGB, modeAlpha);
michael@0 587 }
michael@0 588 }
michael@0 589 catch(std::bad_alloc&)
michael@0 590 {
michael@0 591 return gl::error(GL_OUT_OF_MEMORY);
michael@0 592 }
michael@0 593 }
michael@0 594
michael@0 595 void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor)
michael@0 596 {
michael@0 597 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
michael@0 598 }
michael@0 599
michael@0 600 void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
michael@0 601 {
michael@0 602 EVENT("(GLenum srcRGB = 0x%X, GLenum dstRGB = 0x%X, GLenum srcAlpha = 0x%X, GLenum dstAlpha = 0x%X)",
michael@0 603 srcRGB, dstRGB, srcAlpha, dstAlpha);
michael@0 604
michael@0 605 try
michael@0 606 {
michael@0 607 switch (srcRGB)
michael@0 608 {
michael@0 609 case GL_ZERO:
michael@0 610 case GL_ONE:
michael@0 611 case GL_SRC_COLOR:
michael@0 612 case GL_ONE_MINUS_SRC_COLOR:
michael@0 613 case GL_DST_COLOR:
michael@0 614 case GL_ONE_MINUS_DST_COLOR:
michael@0 615 case GL_SRC_ALPHA:
michael@0 616 case GL_ONE_MINUS_SRC_ALPHA:
michael@0 617 case GL_DST_ALPHA:
michael@0 618 case GL_ONE_MINUS_DST_ALPHA:
michael@0 619 case GL_CONSTANT_COLOR:
michael@0 620 case GL_ONE_MINUS_CONSTANT_COLOR:
michael@0 621 case GL_CONSTANT_ALPHA:
michael@0 622 case GL_ONE_MINUS_CONSTANT_ALPHA:
michael@0 623 case GL_SRC_ALPHA_SATURATE:
michael@0 624 break;
michael@0 625 default:
michael@0 626 return gl::error(GL_INVALID_ENUM);
michael@0 627 }
michael@0 628
michael@0 629 switch (dstRGB)
michael@0 630 {
michael@0 631 case GL_ZERO:
michael@0 632 case GL_ONE:
michael@0 633 case GL_SRC_COLOR:
michael@0 634 case GL_ONE_MINUS_SRC_COLOR:
michael@0 635 case GL_DST_COLOR:
michael@0 636 case GL_ONE_MINUS_DST_COLOR:
michael@0 637 case GL_SRC_ALPHA:
michael@0 638 case GL_ONE_MINUS_SRC_ALPHA:
michael@0 639 case GL_DST_ALPHA:
michael@0 640 case GL_ONE_MINUS_DST_ALPHA:
michael@0 641 case GL_CONSTANT_COLOR:
michael@0 642 case GL_ONE_MINUS_CONSTANT_COLOR:
michael@0 643 case GL_CONSTANT_ALPHA:
michael@0 644 case GL_ONE_MINUS_CONSTANT_ALPHA:
michael@0 645 break;
michael@0 646 default:
michael@0 647 return gl::error(GL_INVALID_ENUM);
michael@0 648 }
michael@0 649
michael@0 650 switch (srcAlpha)
michael@0 651 {
michael@0 652 case GL_ZERO:
michael@0 653 case GL_ONE:
michael@0 654 case GL_SRC_COLOR:
michael@0 655 case GL_ONE_MINUS_SRC_COLOR:
michael@0 656 case GL_DST_COLOR:
michael@0 657 case GL_ONE_MINUS_DST_COLOR:
michael@0 658 case GL_SRC_ALPHA:
michael@0 659 case GL_ONE_MINUS_SRC_ALPHA:
michael@0 660 case GL_DST_ALPHA:
michael@0 661 case GL_ONE_MINUS_DST_ALPHA:
michael@0 662 case GL_CONSTANT_COLOR:
michael@0 663 case GL_ONE_MINUS_CONSTANT_COLOR:
michael@0 664 case GL_CONSTANT_ALPHA:
michael@0 665 case GL_ONE_MINUS_CONSTANT_ALPHA:
michael@0 666 case GL_SRC_ALPHA_SATURATE:
michael@0 667 break;
michael@0 668 default:
michael@0 669 return gl::error(GL_INVALID_ENUM);
michael@0 670 }
michael@0 671
michael@0 672 switch (dstAlpha)
michael@0 673 {
michael@0 674 case GL_ZERO:
michael@0 675 case GL_ONE:
michael@0 676 case GL_SRC_COLOR:
michael@0 677 case GL_ONE_MINUS_SRC_COLOR:
michael@0 678 case GL_DST_COLOR:
michael@0 679 case GL_ONE_MINUS_DST_COLOR:
michael@0 680 case GL_SRC_ALPHA:
michael@0 681 case GL_ONE_MINUS_SRC_ALPHA:
michael@0 682 case GL_DST_ALPHA:
michael@0 683 case GL_ONE_MINUS_DST_ALPHA:
michael@0 684 case GL_CONSTANT_COLOR:
michael@0 685 case GL_ONE_MINUS_CONSTANT_COLOR:
michael@0 686 case GL_CONSTANT_ALPHA:
michael@0 687 case GL_ONE_MINUS_CONSTANT_ALPHA:
michael@0 688 break;
michael@0 689 default:
michael@0 690 return gl::error(GL_INVALID_ENUM);
michael@0 691 }
michael@0 692
michael@0 693 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
michael@0 694 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
michael@0 695
michael@0 696 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
michael@0 697 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
michael@0 698
michael@0 699 if (constantColorUsed && constantAlphaUsed)
michael@0 700 {
michael@0 701 ERR("Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR invalid under WebGL");
michael@0 702 return gl::error(GL_INVALID_OPERATION);
michael@0 703 }
michael@0 704
michael@0 705 gl::Context *context = gl::getNonLostContext();
michael@0 706
michael@0 707 if (context)
michael@0 708 {
michael@0 709 context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
michael@0 710 }
michael@0 711 }
michael@0 712 catch(std::bad_alloc&)
michael@0 713 {
michael@0 714 return gl::error(GL_OUT_OF_MEMORY);
michael@0 715 }
michael@0 716 }
michael@0 717
michael@0 718 void __stdcall glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
michael@0 719 {
michael@0 720 EVENT("(GLenum target = 0x%X, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p, GLenum usage = %d)",
michael@0 721 target, size, data, usage);
michael@0 722
michael@0 723 try
michael@0 724 {
michael@0 725 if (size < 0)
michael@0 726 {
michael@0 727 return gl::error(GL_INVALID_VALUE);
michael@0 728 }
michael@0 729
michael@0 730 switch (usage)
michael@0 731 {
michael@0 732 case GL_STREAM_DRAW:
michael@0 733 case GL_STATIC_DRAW:
michael@0 734 case GL_DYNAMIC_DRAW:
michael@0 735 break;
michael@0 736 default:
michael@0 737 return gl::error(GL_INVALID_ENUM);
michael@0 738 }
michael@0 739
michael@0 740 gl::Context *context = gl::getNonLostContext();
michael@0 741
michael@0 742 if (context)
michael@0 743 {
michael@0 744 gl::Buffer *buffer;
michael@0 745
michael@0 746 switch (target)
michael@0 747 {
michael@0 748 case GL_ARRAY_BUFFER:
michael@0 749 buffer = context->getArrayBuffer();
michael@0 750 break;
michael@0 751 case GL_ELEMENT_ARRAY_BUFFER:
michael@0 752 buffer = context->getElementArrayBuffer();
michael@0 753 break;
michael@0 754 default:
michael@0 755 return gl::error(GL_INVALID_ENUM);
michael@0 756 }
michael@0 757
michael@0 758 if (!buffer)
michael@0 759 {
michael@0 760 return gl::error(GL_INVALID_OPERATION);
michael@0 761 }
michael@0 762
michael@0 763 buffer->bufferData(data, size, usage);
michael@0 764 }
michael@0 765 }
michael@0 766 catch(std::bad_alloc&)
michael@0 767 {
michael@0 768 return gl::error(GL_OUT_OF_MEMORY);
michael@0 769 }
michael@0 770 }
michael@0 771
michael@0 772 void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
michael@0 773 {
michael@0 774 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p)",
michael@0 775 target, offset, size, data);
michael@0 776
michael@0 777 try
michael@0 778 {
michael@0 779 if (size < 0 || offset < 0)
michael@0 780 {
michael@0 781 return gl::error(GL_INVALID_VALUE);
michael@0 782 }
michael@0 783
michael@0 784 if (data == NULL)
michael@0 785 {
michael@0 786 return;
michael@0 787 }
michael@0 788
michael@0 789 gl::Context *context = gl::getNonLostContext();
michael@0 790
michael@0 791 if (context)
michael@0 792 {
michael@0 793 gl::Buffer *buffer;
michael@0 794
michael@0 795 switch (target)
michael@0 796 {
michael@0 797 case GL_ARRAY_BUFFER:
michael@0 798 buffer = context->getArrayBuffer();
michael@0 799 break;
michael@0 800 case GL_ELEMENT_ARRAY_BUFFER:
michael@0 801 buffer = context->getElementArrayBuffer();
michael@0 802 break;
michael@0 803 default:
michael@0 804 return gl::error(GL_INVALID_ENUM);
michael@0 805 }
michael@0 806
michael@0 807 if (!buffer)
michael@0 808 {
michael@0 809 return gl::error(GL_INVALID_OPERATION);
michael@0 810 }
michael@0 811
michael@0 812 if ((size_t)size + offset > buffer->size())
michael@0 813 {
michael@0 814 return gl::error(GL_INVALID_VALUE);
michael@0 815 }
michael@0 816
michael@0 817 buffer->bufferSubData(data, size, offset);
michael@0 818 }
michael@0 819 }
michael@0 820 catch(std::bad_alloc&)
michael@0 821 {
michael@0 822 return gl::error(GL_OUT_OF_MEMORY);
michael@0 823 }
michael@0 824 }
michael@0 825
michael@0 826 GLenum __stdcall glCheckFramebufferStatus(GLenum target)
michael@0 827 {
michael@0 828 EVENT("(GLenum target = 0x%X)", target);
michael@0 829
michael@0 830 try
michael@0 831 {
michael@0 832 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
michael@0 833 {
michael@0 834 return gl::error(GL_INVALID_ENUM, 0);
michael@0 835 }
michael@0 836
michael@0 837 gl::Context *context = gl::getNonLostContext();
michael@0 838
michael@0 839 if (context)
michael@0 840 {
michael@0 841 gl::Framebuffer *framebuffer = NULL;
michael@0 842 if (target == GL_READ_FRAMEBUFFER_ANGLE)
michael@0 843 {
michael@0 844 framebuffer = context->getReadFramebuffer();
michael@0 845 }
michael@0 846 else
michael@0 847 {
michael@0 848 framebuffer = context->getDrawFramebuffer();
michael@0 849 }
michael@0 850
michael@0 851 return framebuffer->completeness();
michael@0 852 }
michael@0 853 }
michael@0 854 catch(std::bad_alloc&)
michael@0 855 {
michael@0 856 return gl::error(GL_OUT_OF_MEMORY, 0);
michael@0 857 }
michael@0 858
michael@0 859 return 0;
michael@0 860 }
michael@0 861
michael@0 862 void __stdcall glClear(GLbitfield mask)
michael@0 863 {
michael@0 864 EVENT("(GLbitfield mask = %X)", mask);
michael@0 865
michael@0 866 try
michael@0 867 {
michael@0 868 gl::Context *context = gl::getNonLostContext();
michael@0 869
michael@0 870 if (context)
michael@0 871 {
michael@0 872 context->clear(mask);
michael@0 873 }
michael@0 874 }
michael@0 875 catch(std::bad_alloc&)
michael@0 876 {
michael@0 877 return gl::error(GL_OUT_OF_MEMORY);
michael@0 878 }
michael@0 879 }
michael@0 880
michael@0 881 void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
michael@0 882 {
michael@0 883 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
michael@0 884 red, green, blue, alpha);
michael@0 885
michael@0 886 try
michael@0 887 {
michael@0 888 gl::Context *context = gl::getNonLostContext();
michael@0 889
michael@0 890 if (context)
michael@0 891 {
michael@0 892 context->setClearColor(red, green, blue, alpha);
michael@0 893 }
michael@0 894 }
michael@0 895 catch(std::bad_alloc&)
michael@0 896 {
michael@0 897 return gl::error(GL_OUT_OF_MEMORY);
michael@0 898 }
michael@0 899 }
michael@0 900
michael@0 901 void __stdcall glClearDepthf(GLclampf depth)
michael@0 902 {
michael@0 903 EVENT("(GLclampf depth = %f)", depth);
michael@0 904
michael@0 905 try
michael@0 906 {
michael@0 907 gl::Context *context = gl::getNonLostContext();
michael@0 908
michael@0 909 if (context)
michael@0 910 {
michael@0 911 context->setClearDepth(depth);
michael@0 912 }
michael@0 913 }
michael@0 914 catch(std::bad_alloc&)
michael@0 915 {
michael@0 916 return gl::error(GL_OUT_OF_MEMORY);
michael@0 917 }
michael@0 918 }
michael@0 919
michael@0 920 void __stdcall glClearStencil(GLint s)
michael@0 921 {
michael@0 922 EVENT("(GLint s = %d)", s);
michael@0 923
michael@0 924 try
michael@0 925 {
michael@0 926 gl::Context *context = gl::getNonLostContext();
michael@0 927
michael@0 928 if (context)
michael@0 929 {
michael@0 930 context->setClearStencil(s);
michael@0 931 }
michael@0 932 }
michael@0 933 catch(std::bad_alloc&)
michael@0 934 {
michael@0 935 return gl::error(GL_OUT_OF_MEMORY);
michael@0 936 }
michael@0 937 }
michael@0 938
michael@0 939 void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
michael@0 940 {
michael@0 941 EVENT("(GLboolean red = %d, GLboolean green = %d, GLboolean blue = %d, GLboolean alpha = %d)",
michael@0 942 red, green, blue, alpha);
michael@0 943
michael@0 944 try
michael@0 945 {
michael@0 946 gl::Context *context = gl::getNonLostContext();
michael@0 947
michael@0 948 if (context)
michael@0 949 {
michael@0 950 context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
michael@0 951 }
michael@0 952 }
michael@0 953 catch(std::bad_alloc&)
michael@0 954 {
michael@0 955 return gl::error(GL_OUT_OF_MEMORY);
michael@0 956 }
michael@0 957 }
michael@0 958
michael@0 959 void __stdcall glCompileShader(GLuint shader)
michael@0 960 {
michael@0 961 EVENT("(GLuint shader = %d)", shader);
michael@0 962
michael@0 963 try
michael@0 964 {
michael@0 965 gl::Context *context = gl::getNonLostContext();
michael@0 966
michael@0 967 if (context)
michael@0 968 {
michael@0 969 gl::Shader *shaderObject = context->getShader(shader);
michael@0 970
michael@0 971 if (!shaderObject)
michael@0 972 {
michael@0 973 if (context->getProgram(shader))
michael@0 974 {
michael@0 975 return gl::error(GL_INVALID_OPERATION);
michael@0 976 }
michael@0 977 else
michael@0 978 {
michael@0 979 return gl::error(GL_INVALID_VALUE);
michael@0 980 }
michael@0 981 }
michael@0 982
michael@0 983 shaderObject->compile();
michael@0 984 }
michael@0 985 }
michael@0 986 catch(std::bad_alloc&)
michael@0 987 {
michael@0 988 return gl::error(GL_OUT_OF_MEMORY);
michael@0 989 }
michael@0 990 }
michael@0 991
michael@0 992 void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
michael@0 993 GLint border, GLsizei imageSize, const GLvoid* data)
michael@0 994 {
michael@0 995 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
michael@0 996 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
michael@0 997 target, level, internalformat, width, height, border, imageSize, data);
michael@0 998
michael@0 999 try
michael@0 1000 {
michael@0 1001 if (!validImageSize(level, width, height) || border != 0 || imageSize < 0)
michael@0 1002 {
michael@0 1003 return gl::error(GL_INVALID_VALUE);
michael@0 1004 }
michael@0 1005
michael@0 1006 switch (internalformat)
michael@0 1007 {
michael@0 1008 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
michael@0 1009 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
michael@0 1010 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
michael@0 1011 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
michael@0 1012 break;
michael@0 1013 default:
michael@0 1014 return gl::error(GL_INVALID_ENUM);
michael@0 1015 }
michael@0 1016
michael@0 1017 if (border != 0)
michael@0 1018 {
michael@0 1019 return gl::error(GL_INVALID_OPERATION);
michael@0 1020 }
michael@0 1021
michael@0 1022 if (width != 1 && width != 2 && width % 4 != 0)
michael@0 1023 {
michael@0 1024 return gl::error(GL_INVALID_OPERATION);
michael@0 1025 }
michael@0 1026
michael@0 1027 if (height != 1 && height != 2 && height % 4 != 0)
michael@0 1028 {
michael@0 1029 return gl::error(GL_INVALID_OPERATION);
michael@0 1030 }
michael@0 1031
michael@0 1032 gl::Context *context = gl::getNonLostContext();
michael@0 1033
michael@0 1034 if (context)
michael@0 1035 {
michael@0 1036 if (level > context->getMaximumTextureLevel())
michael@0 1037 {
michael@0 1038 return gl::error(GL_INVALID_VALUE);
michael@0 1039 }
michael@0 1040
michael@0 1041 switch (target)
michael@0 1042 {
michael@0 1043 case GL_TEXTURE_2D:
michael@0 1044 if (width > (context->getMaximumTextureDimension() >> level) ||
michael@0 1045 height > (context->getMaximumTextureDimension() >> level))
michael@0 1046 {
michael@0 1047 return gl::error(GL_INVALID_VALUE);
michael@0 1048 }
michael@0 1049 break;
michael@0 1050 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
michael@0 1051 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
michael@0 1052 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
michael@0 1053 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
michael@0 1054 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
michael@0 1055 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
michael@0 1056 if (width != height)
michael@0 1057 {
michael@0 1058 return gl::error(GL_INVALID_VALUE);
michael@0 1059 }
michael@0 1060
michael@0 1061 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
michael@0 1062 height > (context->getMaximumCubeTextureDimension() >> level))
michael@0 1063 {
michael@0 1064 return gl::error(GL_INVALID_VALUE);
michael@0 1065 }
michael@0 1066 break;
michael@0 1067 default:
michael@0 1068 return gl::error(GL_INVALID_ENUM);
michael@0 1069 }
michael@0 1070
michael@0 1071 switch (internalformat) {
michael@0 1072 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
michael@0 1073 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
michael@0 1074 if (!context->supportsDXT1Textures())
michael@0 1075 {
michael@0 1076 return gl::error(GL_INVALID_ENUM); // in this case, it's as though the internal format switch failed
michael@0 1077 }
michael@0 1078 break;
michael@0 1079 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
michael@0 1080 if (!context->supportsDXT3Textures())
michael@0 1081 {
michael@0 1082 return gl::error(GL_INVALID_ENUM); // in this case, it's as though the internal format switch failed
michael@0 1083 }
michael@0 1084 break;
michael@0 1085 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
michael@0 1086 if (!context->supportsDXT5Textures())
michael@0 1087 {
michael@0 1088 return gl::error(GL_INVALID_ENUM); // in this case, it's as though the internal format switch failed
michael@0 1089 }
michael@0 1090 break;
michael@0 1091 default: UNREACHABLE();
michael@0 1092 }
michael@0 1093
michael@0 1094 if (imageSize != gl::ComputeCompressedSize(width, height, internalformat))
michael@0 1095 {
michael@0 1096 return gl::error(GL_INVALID_VALUE);
michael@0 1097 }
michael@0 1098
michael@0 1099 if (target == GL_TEXTURE_2D)
michael@0 1100 {
michael@0 1101 gl::Texture2D *texture = context->getTexture2D();
michael@0 1102
michael@0 1103 if (!texture)
michael@0 1104 {
michael@0 1105 return gl::error(GL_INVALID_OPERATION);
michael@0 1106 }
michael@0 1107
michael@0 1108 if (texture->isImmutable())
michael@0 1109 {
michael@0 1110 return gl::error(GL_INVALID_OPERATION);
michael@0 1111 }
michael@0 1112
michael@0 1113 texture->setCompressedImage(level, internalformat, width, height, imageSize, data);
michael@0 1114 }
michael@0 1115 else
michael@0 1116 {
michael@0 1117 gl::TextureCubeMap *texture = context->getTextureCubeMap();
michael@0 1118
michael@0 1119 if (!texture)
michael@0 1120 {
michael@0 1121 return gl::error(GL_INVALID_OPERATION);
michael@0 1122 }
michael@0 1123
michael@0 1124 if (texture->isImmutable())
michael@0 1125 {
michael@0 1126 return gl::error(GL_INVALID_OPERATION);
michael@0 1127 }
michael@0 1128
michael@0 1129 switch (target)
michael@0 1130 {
michael@0 1131 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
michael@0 1132 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
michael@0 1133 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
michael@0 1134 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
michael@0 1135 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
michael@0 1136 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
michael@0 1137 texture->setCompressedImage(target, level, internalformat, width, height, imageSize, data);
michael@0 1138 break;
michael@0 1139 default: UNREACHABLE();
michael@0 1140 }
michael@0 1141 }
michael@0 1142 }
michael@0 1143
michael@0 1144 }
michael@0 1145 catch(std::bad_alloc&)
michael@0 1146 {
michael@0 1147 return gl::error(GL_OUT_OF_MEMORY);
michael@0 1148 }
michael@0 1149 }
michael@0 1150
michael@0 1151 void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
michael@0 1152 GLenum format, GLsizei imageSize, const GLvoid* data)
michael@0 1153 {
michael@0 1154 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
michael@0 1155 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
michael@0 1156 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
michael@0 1157 target, level, xoffset, yoffset, width, height, format, imageSize, data);
michael@0 1158
michael@0 1159 try
michael@0 1160 {
michael@0 1161 if (!gl::IsInternalTextureTarget(target))
michael@0 1162 {
michael@0 1163 return gl::error(GL_INVALID_ENUM);
michael@0 1164 }
michael@0 1165
michael@0 1166 if (xoffset < 0 || yoffset < 0 || !validImageSize(level, width, height) || imageSize < 0)
michael@0 1167 {
michael@0 1168 return gl::error(GL_INVALID_VALUE);
michael@0 1169 }
michael@0 1170
michael@0 1171 switch (format)
michael@0 1172 {
michael@0 1173 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
michael@0 1174 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
michael@0 1175 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
michael@0 1176 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
michael@0 1177 break;
michael@0 1178 default:
michael@0 1179 return gl::error(GL_INVALID_ENUM);
michael@0 1180 }
michael@0 1181
michael@0 1182 if (width == 0 || height == 0 || data == NULL)
michael@0 1183 {
michael@0 1184 return;
michael@0 1185 }
michael@0 1186
michael@0 1187 gl::Context *context = gl::getNonLostContext();
michael@0 1188
michael@0 1189 if (context)
michael@0 1190 {
michael@0 1191 if (level > context->getMaximumTextureLevel())
michael@0 1192 {
michael@0 1193 return gl::error(GL_INVALID_VALUE);
michael@0 1194 }
michael@0 1195
michael@0 1196 switch (format) {
michael@0 1197 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
michael@0 1198 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
michael@0 1199 if (!context->supportsDXT1Textures())
michael@0 1200 {
michael@0 1201 return gl::error(GL_INVALID_ENUM); // in this case, it's as though the internal format switch failed
michael@0 1202 }
michael@0 1203 break;
michael@0 1204 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
michael@0 1205 if (!context->supportsDXT3Textures())
michael@0 1206 {
michael@0 1207 return gl::error(GL_INVALID_ENUM); // in this case, it's as though the internal format switch failed
michael@0 1208 }
michael@0 1209 break;
michael@0 1210 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
michael@0 1211 if (!context->supportsDXT5Textures())
michael@0 1212 {
michael@0 1213 return gl::error(GL_INVALID_ENUM); // in this case, it's as though the internal format switch failed
michael@0 1214 }
michael@0 1215 break;
michael@0 1216 default: UNREACHABLE();
michael@0 1217 }
michael@0 1218
michael@0 1219 if (imageSize != gl::ComputeCompressedSize(width, height, format))
michael@0 1220 {
michael@0 1221 return gl::error(GL_INVALID_VALUE);
michael@0 1222 }
michael@0 1223
michael@0 1224 if (xoffset % 4 != 0 || yoffset % 4 != 0)
michael@0 1225 {
michael@0 1226 return gl::error(GL_INVALID_OPERATION); // we wait to check the offsets until this point, because the multiple-of-four restriction
michael@0 1227 // does not exist unless DXT textures are supported.
michael@0 1228 }
michael@0 1229
michael@0 1230 if (target == GL_TEXTURE_2D)
michael@0 1231 {
michael@0 1232 gl::Texture2D *texture = context->getTexture2D();
michael@0 1233 if (validateSubImageParams2D(true, width, height, xoffset, yoffset, level, format, GL_NONE, texture))
michael@0 1234 {
michael@0 1235 texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data);
michael@0 1236 }
michael@0 1237 }
michael@0 1238 else if (gl::IsCubemapTextureTarget(target))
michael@0 1239 {
michael@0 1240 gl::TextureCubeMap *texture = context->getTextureCubeMap();
michael@0 1241 if (validateSubImageParamsCube(true, width, height, xoffset, yoffset, target, level, format, GL_NONE, texture))
michael@0 1242 {
michael@0 1243 texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, data);
michael@0 1244 }
michael@0 1245 }
michael@0 1246 else
michael@0 1247 {
michael@0 1248 UNREACHABLE();
michael@0 1249 }
michael@0 1250 }
michael@0 1251 }
michael@0 1252 catch(std::bad_alloc&)
michael@0 1253 {
michael@0 1254 return gl::error(GL_OUT_OF_MEMORY);
michael@0 1255 }
michael@0 1256 }
michael@0 1257
michael@0 1258 void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
michael@0 1259 {
michael@0 1260 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
michael@0 1261 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
michael@0 1262 target, level, internalformat, x, y, width, height, border);
michael@0 1263
michael@0 1264 try
michael@0 1265 {
michael@0 1266 if (!validImageSize(level, width, height))
michael@0 1267 {
michael@0 1268 return gl::error(GL_INVALID_VALUE);
michael@0 1269 }
michael@0 1270
michael@0 1271 if (border != 0)
michael@0 1272 {
michael@0 1273 return gl::error(GL_INVALID_VALUE);
michael@0 1274 }
michael@0 1275
michael@0 1276 gl::Context *context = gl::getNonLostContext();
michael@0 1277
michael@0 1278 if (context)
michael@0 1279 {
michael@0 1280 if (level > context->getMaximumTextureLevel())
michael@0 1281 {
michael@0 1282 return gl::error(GL_INVALID_VALUE);
michael@0 1283 }
michael@0 1284
michael@0 1285 switch (target)
michael@0 1286 {
michael@0 1287 case GL_TEXTURE_2D:
michael@0 1288 if (width > (context->getMaximumTextureDimension() >> level) ||
michael@0 1289 height > (context->getMaximumTextureDimension() >> level))
michael@0 1290 {
michael@0 1291 return gl::error(GL_INVALID_VALUE);
michael@0 1292 }
michael@0 1293 break;
michael@0 1294 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
michael@0 1295 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
michael@0 1296 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
michael@0 1297 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
michael@0 1298 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
michael@0 1299 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
michael@0 1300 if (width != height)
michael@0 1301 {
michael@0 1302 return gl::error(GL_INVALID_VALUE);
michael@0 1303 }
michael@0 1304
michael@0 1305 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
michael@0 1306 height > (context->getMaximumCubeTextureDimension() >> level))
michael@0 1307 {
michael@0 1308 return gl::error(GL_INVALID_VALUE);
michael@0 1309 }
michael@0 1310 break;
michael@0 1311 default:
michael@0 1312 return gl::error(GL_INVALID_ENUM);
michael@0 1313 }
michael@0 1314
michael@0 1315 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
michael@0 1316
michael@0 1317 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
michael@0 1318 {
michael@0 1319 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION);
michael@0 1320 }
michael@0 1321
michael@0 1322 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
michael@0 1323 {
michael@0 1324 return gl::error(GL_INVALID_OPERATION);
michael@0 1325 }
michael@0 1326
michael@0 1327 gl::Renderbuffer *source = framebuffer->getReadColorbuffer();
michael@0 1328 GLenum colorbufferFormat = source->getInternalFormat();
michael@0 1329
michael@0 1330 // [OpenGL ES 2.0.24] table 3.9
michael@0 1331 switch (internalformat)
michael@0 1332 {
michael@0 1333 case GL_ALPHA:
michael@0 1334 if (colorbufferFormat != GL_ALPHA8_EXT &&
michael@0 1335 colorbufferFormat != GL_RGBA4 &&
michael@0 1336 colorbufferFormat != GL_RGB5_A1 &&
michael@0 1337 colorbufferFormat != GL_BGRA8_EXT &&
michael@0 1338 colorbufferFormat != GL_RGBA8_OES)
michael@0 1339 {
michael@0 1340 return gl::error(GL_INVALID_OPERATION);
michael@0 1341 }
michael@0 1342 break;
michael@0 1343 case GL_LUMINANCE:
michael@0 1344 case GL_RGB:
michael@0 1345 if (colorbufferFormat != GL_RGB565 &&
michael@0 1346 colorbufferFormat != GL_RGB8_OES &&
michael@0 1347 colorbufferFormat != GL_RGBA4 &&
michael@0 1348 colorbufferFormat != GL_RGB5_A1 &&
michael@0 1349 colorbufferFormat != GL_BGRA8_EXT &&
michael@0 1350 colorbufferFormat != GL_RGBA8_OES)
michael@0 1351 {
michael@0 1352 return gl::error(GL_INVALID_OPERATION);
michael@0 1353 }
michael@0 1354 break;
michael@0 1355 case GL_LUMINANCE_ALPHA:
michael@0 1356 case GL_RGBA:
michael@0 1357 if (colorbufferFormat != GL_RGBA4 &&
michael@0 1358 colorbufferFormat != GL_RGB5_A1 &&
michael@0 1359 colorbufferFormat != GL_BGRA8_EXT &&
michael@0 1360 colorbufferFormat != GL_RGBA8_OES)
michael@0 1361 {
michael@0 1362 return gl::error(GL_INVALID_OPERATION);
michael@0 1363 }
michael@0 1364 break;
michael@0 1365 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
michael@0 1366 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
michael@0 1367 if (context->supportsDXT1Textures())
michael@0 1368 {
michael@0 1369 return gl::error(GL_INVALID_OPERATION);
michael@0 1370 }
michael@0 1371 else
michael@0 1372 {
michael@0 1373 return gl::error(GL_INVALID_ENUM);
michael@0 1374 }
michael@0 1375 break;
michael@0 1376 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
michael@0 1377 if (context->supportsDXT3Textures())
michael@0 1378 {
michael@0 1379 return gl::error(GL_INVALID_OPERATION);
michael@0 1380 }
michael@0 1381 else
michael@0 1382 {
michael@0 1383 return gl::error(GL_INVALID_ENUM);
michael@0 1384 }
michael@0 1385 break;
michael@0 1386 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
michael@0 1387 if (context->supportsDXT5Textures())
michael@0 1388 {
michael@0 1389 return gl::error(GL_INVALID_OPERATION);
michael@0 1390 }
michael@0 1391 else
michael@0 1392 {
michael@0 1393 return gl::error(GL_INVALID_ENUM);
michael@0 1394 }
michael@0 1395 break;
michael@0 1396 case GL_DEPTH_COMPONENT:
michael@0 1397 case GL_DEPTH_COMPONENT16:
michael@0 1398 case GL_DEPTH_COMPONENT32_OES:
michael@0 1399 case GL_DEPTH_STENCIL_OES:
michael@0 1400 case GL_DEPTH24_STENCIL8_OES:
michael@0 1401 if (context->supportsDepthTextures())
michael@0 1402 {
michael@0 1403 return gl::error(GL_INVALID_OPERATION);
michael@0 1404 }
michael@0 1405 else
michael@0 1406 {
michael@0 1407 return gl::error(GL_INVALID_ENUM);
michael@0 1408 }
michael@0 1409 default:
michael@0 1410 return gl::error(GL_INVALID_ENUM);
michael@0 1411 }
michael@0 1412
michael@0 1413 if (target == GL_TEXTURE_2D)
michael@0 1414 {
michael@0 1415 gl::Texture2D *texture = context->getTexture2D();
michael@0 1416
michael@0 1417 if (!texture)
michael@0 1418 {
michael@0 1419 return gl::error(GL_INVALID_OPERATION);
michael@0 1420 }
michael@0 1421
michael@0 1422 if (texture->isImmutable())
michael@0 1423 {
michael@0 1424 return gl::error(GL_INVALID_OPERATION);
michael@0 1425 }
michael@0 1426
michael@0 1427 texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
michael@0 1428 }
michael@0 1429 else if (gl::IsCubemapTextureTarget(target))
michael@0 1430 {
michael@0 1431 gl::TextureCubeMap *texture = context->getTextureCubeMap();
michael@0 1432
michael@0 1433 if (!texture)
michael@0 1434 {
michael@0 1435 return gl::error(GL_INVALID_OPERATION);
michael@0 1436 }
michael@0 1437
michael@0 1438 if (texture->isImmutable())
michael@0 1439 {
michael@0 1440 return gl::error(GL_INVALID_OPERATION);
michael@0 1441 }
michael@0 1442
michael@0 1443 texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
michael@0 1444 }
michael@0 1445 else UNREACHABLE();
michael@0 1446 }
michael@0 1447 }
michael@0 1448 catch(std::bad_alloc&)
michael@0 1449 {
michael@0 1450 return gl::error(GL_OUT_OF_MEMORY);
michael@0 1451 }
michael@0 1452 }
michael@0 1453
michael@0 1454 void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
michael@0 1455 {
michael@0 1456 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
michael@0 1457 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
michael@0 1458 target, level, xoffset, yoffset, x, y, width, height);
michael@0 1459
michael@0 1460 try
michael@0 1461 {
michael@0 1462 if (!gl::IsInternalTextureTarget(target))
michael@0 1463 {
michael@0 1464 return gl::error(GL_INVALID_ENUM);
michael@0 1465 }
michael@0 1466
michael@0 1467 if (level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
michael@0 1468 {
michael@0 1469 return gl::error(GL_INVALID_VALUE);
michael@0 1470 }
michael@0 1471
michael@0 1472 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
michael@0 1473 {
michael@0 1474 return gl::error(GL_INVALID_VALUE);
michael@0 1475 }
michael@0 1476
michael@0 1477 if (width == 0 || height == 0)
michael@0 1478 {
michael@0 1479 return;
michael@0 1480 }
michael@0 1481
michael@0 1482 gl::Context *context = gl::getNonLostContext();
michael@0 1483
michael@0 1484 if (context)
michael@0 1485 {
michael@0 1486 if (level > context->getMaximumTextureLevel())
michael@0 1487 {
michael@0 1488 return gl::error(GL_INVALID_VALUE);
michael@0 1489 }
michael@0 1490
michael@0 1491 gl::Framebuffer *framebuffer = context->getReadFramebuffer();
michael@0 1492
michael@0 1493 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
michael@0 1494 {
michael@0 1495 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION);
michael@0 1496 }
michael@0 1497
michael@0 1498 if (context->getReadFramebufferHandle() != 0 && framebuffer->getSamples() != 0)
michael@0 1499 {
michael@0 1500 return gl::error(GL_INVALID_OPERATION);
michael@0 1501 }
michael@0 1502
michael@0 1503 gl::Renderbuffer *source = framebuffer->getReadColorbuffer();
michael@0 1504 GLenum colorbufferFormat = source->getInternalFormat();
michael@0 1505 gl::Texture *texture = NULL;
michael@0 1506 GLenum textureFormat = GL_RGBA;
michael@0 1507
michael@0 1508 if (target == GL_TEXTURE_2D)
michael@0 1509 {
michael@0 1510 gl::Texture2D *tex2d = context->getTexture2D();
michael@0 1511
michael@0 1512 if (!validateSubImageParams2D(false, width, height, xoffset, yoffset, level, GL_NONE, GL_NONE, tex2d))
michael@0 1513 {
michael@0 1514 return; // error already registered by validateSubImageParams
michael@0 1515 }
michael@0 1516 textureFormat = gl::ExtractFormat(tex2d->getInternalFormat(level));
michael@0 1517 texture = tex2d;
michael@0 1518 }
michael@0 1519 else if (gl::IsCubemapTextureTarget(target))
michael@0 1520 {
michael@0 1521 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
michael@0 1522
michael@0 1523 if (!validateSubImageParamsCube(false, width, height, xoffset, yoffset, target, level, GL_NONE, GL_NONE, texcube))
michael@0 1524 {
michael@0 1525 return; // error already registered by validateSubImageParams
michael@0 1526 }
michael@0 1527 textureFormat = gl::ExtractFormat(texcube->getInternalFormat(target, level));
michael@0 1528 texture = texcube;
michael@0 1529 }
michael@0 1530 else UNREACHABLE();
michael@0 1531
michael@0 1532 // [OpenGL ES 2.0.24] table 3.9
michael@0 1533 switch (textureFormat)
michael@0 1534 {
michael@0 1535 case GL_ALPHA:
michael@0 1536 if (colorbufferFormat != GL_ALPHA8_EXT &&
michael@0 1537 colorbufferFormat != GL_RGBA4 &&
michael@0 1538 colorbufferFormat != GL_RGB5_A1 &&
michael@0 1539 colorbufferFormat != GL_RGBA8_OES)
michael@0 1540 {
michael@0 1541 return gl::error(GL_INVALID_OPERATION);
michael@0 1542 }
michael@0 1543 break;
michael@0 1544 case GL_LUMINANCE:
michael@0 1545 case GL_RGB:
michael@0 1546 if (colorbufferFormat != GL_RGB565 &&
michael@0 1547 colorbufferFormat != GL_RGB8_OES &&
michael@0 1548 colorbufferFormat != GL_RGBA4 &&
michael@0 1549 colorbufferFormat != GL_RGB5_A1 &&
michael@0 1550 colorbufferFormat != GL_RGBA8_OES)
michael@0 1551 {
michael@0 1552 return gl::error(GL_INVALID_OPERATION);
michael@0 1553 }
michael@0 1554 break;
michael@0 1555 case GL_LUMINANCE_ALPHA:
michael@0 1556 case GL_RGBA:
michael@0 1557 if (colorbufferFormat != GL_RGBA4 &&
michael@0 1558 colorbufferFormat != GL_RGB5_A1 &&
michael@0 1559 colorbufferFormat != GL_RGBA8_OES)
michael@0 1560 {
michael@0 1561 return gl::error(GL_INVALID_OPERATION);
michael@0 1562 }
michael@0 1563 break;
michael@0 1564 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
michael@0 1565 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
michael@0 1566 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
michael@0 1567 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
michael@0 1568 return gl::error(GL_INVALID_OPERATION);
michael@0 1569 case GL_DEPTH_COMPONENT:
michael@0 1570 case GL_DEPTH_STENCIL_OES:
michael@0 1571 return gl::error(GL_INVALID_OPERATION);
michael@0 1572 default:
michael@0 1573 return gl::error(GL_INVALID_OPERATION);
michael@0 1574 }
michael@0 1575
michael@0 1576 texture->copySubImage(target, level, xoffset, yoffset, x, y, width, height, framebuffer);
michael@0 1577 }
michael@0 1578 }
michael@0 1579
michael@0 1580 catch(std::bad_alloc&)
michael@0 1581 {
michael@0 1582 return gl::error(GL_OUT_OF_MEMORY);
michael@0 1583 }
michael@0 1584 }
michael@0 1585
michael@0 1586 GLuint __stdcall glCreateProgram(void)
michael@0 1587 {
michael@0 1588 EVENT("()");
michael@0 1589
michael@0 1590 try
michael@0 1591 {
michael@0 1592 gl::Context *context = gl::getNonLostContext();
michael@0 1593
michael@0 1594 if (context)
michael@0 1595 {
michael@0 1596 return context->createProgram();
michael@0 1597 }
michael@0 1598 }
michael@0 1599 catch(std::bad_alloc&)
michael@0 1600 {
michael@0 1601 return gl::error(GL_OUT_OF_MEMORY, 0);
michael@0 1602 }
michael@0 1603
michael@0 1604 return 0;
michael@0 1605 }
michael@0 1606
michael@0 1607 GLuint __stdcall glCreateShader(GLenum type)
michael@0 1608 {
michael@0 1609 EVENT("(GLenum type = 0x%X)", type);
michael@0 1610
michael@0 1611 try
michael@0 1612 {
michael@0 1613 gl::Context *context = gl::getNonLostContext();
michael@0 1614
michael@0 1615 if (context)
michael@0 1616 {
michael@0 1617 switch (type)
michael@0 1618 {
michael@0 1619 case GL_FRAGMENT_SHADER:
michael@0 1620 case GL_VERTEX_SHADER:
michael@0 1621 return context->createShader(type);
michael@0 1622 default:
michael@0 1623 return gl::error(GL_INVALID_ENUM, 0);
michael@0 1624 }
michael@0 1625 }
michael@0 1626 }
michael@0 1627 catch(std::bad_alloc&)
michael@0 1628 {
michael@0 1629 return gl::error(GL_OUT_OF_MEMORY, 0);
michael@0 1630 }
michael@0 1631
michael@0 1632 return 0;
michael@0 1633 }
michael@0 1634
michael@0 1635 void __stdcall glCullFace(GLenum mode)
michael@0 1636 {
michael@0 1637 EVENT("(GLenum mode = 0x%X)", mode);
michael@0 1638
michael@0 1639 try
michael@0 1640 {
michael@0 1641 switch (mode)
michael@0 1642 {
michael@0 1643 case GL_FRONT:
michael@0 1644 case GL_BACK:
michael@0 1645 case GL_FRONT_AND_BACK:
michael@0 1646 {
michael@0 1647 gl::Context *context = gl::getNonLostContext();
michael@0 1648
michael@0 1649 if (context)
michael@0 1650 {
michael@0 1651 context->setCullMode(mode);
michael@0 1652 }
michael@0 1653 }
michael@0 1654 break;
michael@0 1655 default:
michael@0 1656 return gl::error(GL_INVALID_ENUM);
michael@0 1657 }
michael@0 1658 }
michael@0 1659 catch(std::bad_alloc&)
michael@0 1660 {
michael@0 1661 return gl::error(GL_OUT_OF_MEMORY);
michael@0 1662 }
michael@0 1663 }
michael@0 1664
michael@0 1665 void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers)
michael@0 1666 {
michael@0 1667 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
michael@0 1668
michael@0 1669 try
michael@0 1670 {
michael@0 1671 if (n < 0)
michael@0 1672 {
michael@0 1673 return gl::error(GL_INVALID_VALUE);
michael@0 1674 }
michael@0 1675
michael@0 1676 gl::Context *context = gl::getNonLostContext();
michael@0 1677
michael@0 1678 if (context)
michael@0 1679 {
michael@0 1680 for (int i = 0; i < n; i++)
michael@0 1681 {
michael@0 1682 context->deleteBuffer(buffers[i]);
michael@0 1683 }
michael@0 1684 }
michael@0 1685 }
michael@0 1686 catch(std::bad_alloc&)
michael@0 1687 {
michael@0 1688 return gl::error(GL_OUT_OF_MEMORY);
michael@0 1689 }
michael@0 1690 }
michael@0 1691
michael@0 1692 void __stdcall glDeleteFencesNV(GLsizei n, const GLuint* fences)
michael@0 1693 {
michael@0 1694 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
michael@0 1695
michael@0 1696 try
michael@0 1697 {
michael@0 1698 if (n < 0)
michael@0 1699 {
michael@0 1700 return gl::error(GL_INVALID_VALUE);
michael@0 1701 }
michael@0 1702
michael@0 1703 gl::Context *context = gl::getNonLostContext();
michael@0 1704
michael@0 1705 if (context)
michael@0 1706 {
michael@0 1707 for (int i = 0; i < n; i++)
michael@0 1708 {
michael@0 1709 context->deleteFence(fences[i]);
michael@0 1710 }
michael@0 1711 }
michael@0 1712 }
michael@0 1713 catch(std::bad_alloc&)
michael@0 1714 {
michael@0 1715 return gl::error(GL_OUT_OF_MEMORY);
michael@0 1716 }
michael@0 1717 }
michael@0 1718
michael@0 1719 void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
michael@0 1720 {
michael@0 1721 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
michael@0 1722
michael@0 1723 try
michael@0 1724 {
michael@0 1725 if (n < 0)
michael@0 1726 {
michael@0 1727 return gl::error(GL_INVALID_VALUE);
michael@0 1728 }
michael@0 1729
michael@0 1730 gl::Context *context = gl::getNonLostContext();
michael@0 1731
michael@0 1732 if (context)
michael@0 1733 {
michael@0 1734 for (int i = 0; i < n; i++)
michael@0 1735 {
michael@0 1736 if (framebuffers[i] != 0)
michael@0 1737 {
michael@0 1738 context->deleteFramebuffer(framebuffers[i]);
michael@0 1739 }
michael@0 1740 }
michael@0 1741 }
michael@0 1742 }
michael@0 1743 catch(std::bad_alloc&)
michael@0 1744 {
michael@0 1745 return gl::error(GL_OUT_OF_MEMORY);
michael@0 1746 }
michael@0 1747 }
michael@0 1748
michael@0 1749 void __stdcall glDeleteProgram(GLuint program)
michael@0 1750 {
michael@0 1751 EVENT("(GLuint program = %d)", program);
michael@0 1752
michael@0 1753 try
michael@0 1754 {
michael@0 1755 if (program == 0)
michael@0 1756 {
michael@0 1757 return;
michael@0 1758 }
michael@0 1759
michael@0 1760 gl::Context *context = gl::getNonLostContext();
michael@0 1761
michael@0 1762 if (context)
michael@0 1763 {
michael@0 1764 if (!context->getProgram(program))
michael@0 1765 {
michael@0 1766 if(context->getShader(program))
michael@0 1767 {
michael@0 1768 return gl::error(GL_INVALID_OPERATION);
michael@0 1769 }
michael@0 1770 else
michael@0 1771 {
michael@0 1772 return gl::error(GL_INVALID_VALUE);
michael@0 1773 }
michael@0 1774 }
michael@0 1775
michael@0 1776 context->deleteProgram(program);
michael@0 1777 }
michael@0 1778 }
michael@0 1779 catch(std::bad_alloc&)
michael@0 1780 {
michael@0 1781 return gl::error(GL_OUT_OF_MEMORY);
michael@0 1782 }
michael@0 1783 }
michael@0 1784
michael@0 1785 void __stdcall glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
michael@0 1786 {
michael@0 1787 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
michael@0 1788
michael@0 1789 try
michael@0 1790 {
michael@0 1791 if (n < 0)
michael@0 1792 {
michael@0 1793 return gl::error(GL_INVALID_VALUE);
michael@0 1794 }
michael@0 1795
michael@0 1796 gl::Context *context = gl::getNonLostContext();
michael@0 1797
michael@0 1798 if (context)
michael@0 1799 {
michael@0 1800 for (int i = 0; i < n; i++)
michael@0 1801 {
michael@0 1802 context->deleteQuery(ids[i]);
michael@0 1803 }
michael@0 1804 }
michael@0 1805 }
michael@0 1806 catch(std::bad_alloc&)
michael@0 1807 {
michael@0 1808 return gl::error(GL_OUT_OF_MEMORY);
michael@0 1809 }
michael@0 1810 }
michael@0 1811
michael@0 1812 void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
michael@0 1813 {
michael@0 1814 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
michael@0 1815
michael@0 1816 try
michael@0 1817 {
michael@0 1818 if (n < 0)
michael@0 1819 {
michael@0 1820 return gl::error(GL_INVALID_VALUE);
michael@0 1821 }
michael@0 1822
michael@0 1823 gl::Context *context = gl::getNonLostContext();
michael@0 1824
michael@0 1825 if (context)
michael@0 1826 {
michael@0 1827 for (int i = 0; i < n; i++)
michael@0 1828 {
michael@0 1829 context->deleteRenderbuffer(renderbuffers[i]);
michael@0 1830 }
michael@0 1831 }
michael@0 1832 }
michael@0 1833 catch(std::bad_alloc&)
michael@0 1834 {
michael@0 1835 return gl::error(GL_OUT_OF_MEMORY);
michael@0 1836 }
michael@0 1837 }
michael@0 1838
michael@0 1839 void __stdcall glDeleteShader(GLuint shader)
michael@0 1840 {
michael@0 1841 EVENT("(GLuint shader = %d)", shader);
michael@0 1842
michael@0 1843 try
michael@0 1844 {
michael@0 1845 if (shader == 0)
michael@0 1846 {
michael@0 1847 return;
michael@0 1848 }
michael@0 1849
michael@0 1850 gl::Context *context = gl::getNonLostContext();
michael@0 1851
michael@0 1852 if (context)
michael@0 1853 {
michael@0 1854 if (!context->getShader(shader))
michael@0 1855 {
michael@0 1856 if(context->getProgram(shader))
michael@0 1857 {
michael@0 1858 return gl::error(GL_INVALID_OPERATION);
michael@0 1859 }
michael@0 1860 else
michael@0 1861 {
michael@0 1862 return gl::error(GL_INVALID_VALUE);
michael@0 1863 }
michael@0 1864 }
michael@0 1865
michael@0 1866 context->deleteShader(shader);
michael@0 1867 }
michael@0 1868 }
michael@0 1869 catch(std::bad_alloc&)
michael@0 1870 {
michael@0 1871 return gl::error(GL_OUT_OF_MEMORY);
michael@0 1872 }
michael@0 1873 }
michael@0 1874
michael@0 1875 void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures)
michael@0 1876 {
michael@0 1877 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
michael@0 1878
michael@0 1879 try
michael@0 1880 {
michael@0 1881 if (n < 0)
michael@0 1882 {
michael@0 1883 return gl::error(GL_INVALID_VALUE);
michael@0 1884 }
michael@0 1885
michael@0 1886 gl::Context *context = gl::getNonLostContext();
michael@0 1887
michael@0 1888 if (context)
michael@0 1889 {
michael@0 1890 for (int i = 0; i < n; i++)
michael@0 1891 {
michael@0 1892 if (textures[i] != 0)
michael@0 1893 {
michael@0 1894 context->deleteTexture(textures[i]);
michael@0 1895 }
michael@0 1896 }
michael@0 1897 }
michael@0 1898 }
michael@0 1899 catch(std::bad_alloc&)
michael@0 1900 {
michael@0 1901 return gl::error(GL_OUT_OF_MEMORY);
michael@0 1902 }
michael@0 1903 }
michael@0 1904
michael@0 1905 void __stdcall glDepthFunc(GLenum func)
michael@0 1906 {
michael@0 1907 EVENT("(GLenum func = 0x%X)", func);
michael@0 1908
michael@0 1909 try
michael@0 1910 {
michael@0 1911 switch (func)
michael@0 1912 {
michael@0 1913 case GL_NEVER:
michael@0 1914 case GL_ALWAYS:
michael@0 1915 case GL_LESS:
michael@0 1916 case GL_LEQUAL:
michael@0 1917 case GL_EQUAL:
michael@0 1918 case GL_GREATER:
michael@0 1919 case GL_GEQUAL:
michael@0 1920 case GL_NOTEQUAL:
michael@0 1921 break;
michael@0 1922 default:
michael@0 1923 return gl::error(GL_INVALID_ENUM);
michael@0 1924 }
michael@0 1925
michael@0 1926 gl::Context *context = gl::getNonLostContext();
michael@0 1927
michael@0 1928 if (context)
michael@0 1929 {
michael@0 1930 context->setDepthFunc(func);
michael@0 1931 }
michael@0 1932 }
michael@0 1933 catch(std::bad_alloc&)
michael@0 1934 {
michael@0 1935 return gl::error(GL_OUT_OF_MEMORY);
michael@0 1936 }
michael@0 1937 }
michael@0 1938
michael@0 1939 void __stdcall glDepthMask(GLboolean flag)
michael@0 1940 {
michael@0 1941 EVENT("(GLboolean flag = %d)", flag);
michael@0 1942
michael@0 1943 try
michael@0 1944 {
michael@0 1945 gl::Context *context = gl::getNonLostContext();
michael@0 1946
michael@0 1947 if (context)
michael@0 1948 {
michael@0 1949 context->setDepthMask(flag != GL_FALSE);
michael@0 1950 }
michael@0 1951 }
michael@0 1952 catch(std::bad_alloc&)
michael@0 1953 {
michael@0 1954 return gl::error(GL_OUT_OF_MEMORY);
michael@0 1955 }
michael@0 1956 }
michael@0 1957
michael@0 1958 void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar)
michael@0 1959 {
michael@0 1960 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
michael@0 1961
michael@0 1962 try
michael@0 1963 {
michael@0 1964 gl::Context *context = gl::getNonLostContext();
michael@0 1965
michael@0 1966 if (context)
michael@0 1967 {
michael@0 1968 context->setDepthRange(zNear, zFar);
michael@0 1969 }
michael@0 1970 }
michael@0 1971 catch(std::bad_alloc&)
michael@0 1972 {
michael@0 1973 return gl::error(GL_OUT_OF_MEMORY);
michael@0 1974 }
michael@0 1975 }
michael@0 1976
michael@0 1977 void __stdcall glDetachShader(GLuint program, GLuint shader)
michael@0 1978 {
michael@0 1979 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
michael@0 1980
michael@0 1981 try
michael@0 1982 {
michael@0 1983 gl::Context *context = gl::getNonLostContext();
michael@0 1984
michael@0 1985 if (context)
michael@0 1986 {
michael@0 1987
michael@0 1988 gl::Program *programObject = context->getProgram(program);
michael@0 1989 gl::Shader *shaderObject = context->getShader(shader);
michael@0 1990
michael@0 1991 if (!programObject)
michael@0 1992 {
michael@0 1993 gl::Shader *shaderByProgramHandle;
michael@0 1994 shaderByProgramHandle = context->getShader(program);
michael@0 1995 if (!shaderByProgramHandle)
michael@0 1996 {
michael@0 1997 return gl::error(GL_INVALID_VALUE);
michael@0 1998 }
michael@0 1999 else
michael@0 2000 {
michael@0 2001 return gl::error(GL_INVALID_OPERATION);
michael@0 2002 }
michael@0 2003 }
michael@0 2004
michael@0 2005 if (!shaderObject)
michael@0 2006 {
michael@0 2007 gl::Program *programByShaderHandle = context->getProgram(shader);
michael@0 2008 if (!programByShaderHandle)
michael@0 2009 {
michael@0 2010 return gl::error(GL_INVALID_VALUE);
michael@0 2011 }
michael@0 2012 else
michael@0 2013 {
michael@0 2014 return gl::error(GL_INVALID_OPERATION);
michael@0 2015 }
michael@0 2016 }
michael@0 2017
michael@0 2018 if (!programObject->detachShader(shaderObject))
michael@0 2019 {
michael@0 2020 return gl::error(GL_INVALID_OPERATION);
michael@0 2021 }
michael@0 2022 }
michael@0 2023 }
michael@0 2024 catch(std::bad_alloc&)
michael@0 2025 {
michael@0 2026 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2027 }
michael@0 2028 }
michael@0 2029
michael@0 2030 void __stdcall glDisable(GLenum cap)
michael@0 2031 {
michael@0 2032 EVENT("(GLenum cap = 0x%X)", cap);
michael@0 2033
michael@0 2034 try
michael@0 2035 {
michael@0 2036 gl::Context *context = gl::getNonLostContext();
michael@0 2037
michael@0 2038 if (context)
michael@0 2039 {
michael@0 2040 switch (cap)
michael@0 2041 {
michael@0 2042 case GL_CULL_FACE: context->setCullFace(false); break;
michael@0 2043 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break;
michael@0 2044 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break;
michael@0 2045 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break;
michael@0 2046 case GL_SCISSOR_TEST: context->setScissorTest(false); break;
michael@0 2047 case GL_STENCIL_TEST: context->setStencilTest(false); break;
michael@0 2048 case GL_DEPTH_TEST: context->setDepthTest(false); break;
michael@0 2049 case GL_BLEND: context->setBlend(false); break;
michael@0 2050 case GL_DITHER: context->setDither(false); break;
michael@0 2051 default:
michael@0 2052 return gl::error(GL_INVALID_ENUM);
michael@0 2053 }
michael@0 2054 }
michael@0 2055 }
michael@0 2056 catch(std::bad_alloc&)
michael@0 2057 {
michael@0 2058 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2059 }
michael@0 2060 }
michael@0 2061
michael@0 2062 void __stdcall glDisableVertexAttribArray(GLuint index)
michael@0 2063 {
michael@0 2064 EVENT("(GLuint index = %d)", index);
michael@0 2065
michael@0 2066 try
michael@0 2067 {
michael@0 2068 if (index >= gl::MAX_VERTEX_ATTRIBS)
michael@0 2069 {
michael@0 2070 return gl::error(GL_INVALID_VALUE);
michael@0 2071 }
michael@0 2072
michael@0 2073 gl::Context *context = gl::getNonLostContext();
michael@0 2074
michael@0 2075 if (context)
michael@0 2076 {
michael@0 2077 context->setEnableVertexAttribArray(index, false);
michael@0 2078 }
michael@0 2079 }
michael@0 2080 catch(std::bad_alloc&)
michael@0 2081 {
michael@0 2082 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2083 }
michael@0 2084 }
michael@0 2085
michael@0 2086 void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count)
michael@0 2087 {
michael@0 2088 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
michael@0 2089
michael@0 2090 try
michael@0 2091 {
michael@0 2092 if (count < 0 || first < 0)
michael@0 2093 {
michael@0 2094 return gl::error(GL_INVALID_VALUE);
michael@0 2095 }
michael@0 2096
michael@0 2097 gl::Context *context = gl::getNonLostContext();
michael@0 2098
michael@0 2099 if (context)
michael@0 2100 {
michael@0 2101 context->drawArrays(mode, first, count, 0);
michael@0 2102 }
michael@0 2103 }
michael@0 2104 catch(std::bad_alloc&)
michael@0 2105 {
michael@0 2106 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2107 }
michael@0 2108 }
michael@0 2109
michael@0 2110 void __stdcall glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
michael@0 2111 {
michael@0 2112 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
michael@0 2113
michael@0 2114 try
michael@0 2115 {
michael@0 2116 if (count < 0 || first < 0 || primcount < 0)
michael@0 2117 {
michael@0 2118 return gl::error(GL_INVALID_VALUE);
michael@0 2119 }
michael@0 2120
michael@0 2121 if (primcount > 0)
michael@0 2122 {
michael@0 2123 gl::Context *context = gl::getNonLostContext();
michael@0 2124
michael@0 2125 if (context)
michael@0 2126 {
michael@0 2127 context->drawArrays(mode, first, count, primcount);
michael@0 2128 }
michael@0 2129 }
michael@0 2130 }
michael@0 2131 catch(std::bad_alloc&)
michael@0 2132 {
michael@0 2133 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2134 }
michael@0 2135 }
michael@0 2136
michael@0 2137 void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
michael@0 2138 {
michael@0 2139 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p)",
michael@0 2140 mode, count, type, indices);
michael@0 2141
michael@0 2142 try
michael@0 2143 {
michael@0 2144 if (count < 0)
michael@0 2145 {
michael@0 2146 return gl::error(GL_INVALID_VALUE);
michael@0 2147 }
michael@0 2148
michael@0 2149 gl::Context *context = gl::getNonLostContext();
michael@0 2150
michael@0 2151 if (context)
michael@0 2152 {
michael@0 2153 switch (type)
michael@0 2154 {
michael@0 2155 case GL_UNSIGNED_BYTE:
michael@0 2156 case GL_UNSIGNED_SHORT:
michael@0 2157 break;
michael@0 2158 case GL_UNSIGNED_INT:
michael@0 2159 if (!context->supports32bitIndices())
michael@0 2160 {
michael@0 2161 return gl::error(GL_INVALID_ENUM);
michael@0 2162 }
michael@0 2163 break;
michael@0 2164 default:
michael@0 2165 return gl::error(GL_INVALID_ENUM);
michael@0 2166 }
michael@0 2167
michael@0 2168 context->drawElements(mode, count, type, indices, 0);
michael@0 2169 }
michael@0 2170 }
michael@0 2171 catch(std::bad_alloc&)
michael@0 2172 {
michael@0 2173 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2174 }
michael@0 2175 }
michael@0 2176
michael@0 2177 void __stdcall glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
michael@0 2178 {
michael@0 2179 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
michael@0 2180 mode, count, type, indices, primcount);
michael@0 2181
michael@0 2182 try
michael@0 2183 {
michael@0 2184 if (count < 0 || primcount < 0)
michael@0 2185 {
michael@0 2186 return gl::error(GL_INVALID_VALUE);
michael@0 2187 }
michael@0 2188
michael@0 2189 if (primcount > 0)
michael@0 2190 {
michael@0 2191 gl::Context *context = gl::getNonLostContext();
michael@0 2192
michael@0 2193 if (context)
michael@0 2194 {
michael@0 2195 switch (type)
michael@0 2196 {
michael@0 2197 case GL_UNSIGNED_BYTE:
michael@0 2198 case GL_UNSIGNED_SHORT:
michael@0 2199 break;
michael@0 2200 case GL_UNSIGNED_INT:
michael@0 2201 if (!context->supports32bitIndices())
michael@0 2202 {
michael@0 2203 return gl::error(GL_INVALID_ENUM);
michael@0 2204 }
michael@0 2205 break;
michael@0 2206 default:
michael@0 2207 return gl::error(GL_INVALID_ENUM);
michael@0 2208 }
michael@0 2209
michael@0 2210 context->drawElements(mode, count, type, indices, primcount);
michael@0 2211 }
michael@0 2212 }
michael@0 2213 }
michael@0 2214 catch(std::bad_alloc&)
michael@0 2215 {
michael@0 2216 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2217 }
michael@0 2218 }
michael@0 2219
michael@0 2220 void __stdcall glEnable(GLenum cap)
michael@0 2221 {
michael@0 2222 EVENT("(GLenum cap = 0x%X)", cap);
michael@0 2223
michael@0 2224 try
michael@0 2225 {
michael@0 2226 gl::Context *context = gl::getNonLostContext();
michael@0 2227
michael@0 2228 if (context)
michael@0 2229 {
michael@0 2230 switch (cap)
michael@0 2231 {
michael@0 2232 case GL_CULL_FACE: context->setCullFace(true); break;
michael@0 2233 case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break;
michael@0 2234 case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break;
michael@0 2235 case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break;
michael@0 2236 case GL_SCISSOR_TEST: context->setScissorTest(true); break;
michael@0 2237 case GL_STENCIL_TEST: context->setStencilTest(true); break;
michael@0 2238 case GL_DEPTH_TEST: context->setDepthTest(true); break;
michael@0 2239 case GL_BLEND: context->setBlend(true); break;
michael@0 2240 case GL_DITHER: context->setDither(true); break;
michael@0 2241 default:
michael@0 2242 return gl::error(GL_INVALID_ENUM);
michael@0 2243 }
michael@0 2244 }
michael@0 2245 }
michael@0 2246 catch(std::bad_alloc&)
michael@0 2247 {
michael@0 2248 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2249 }
michael@0 2250 }
michael@0 2251
michael@0 2252 void __stdcall glEnableVertexAttribArray(GLuint index)
michael@0 2253 {
michael@0 2254 EVENT("(GLuint index = %d)", index);
michael@0 2255
michael@0 2256 try
michael@0 2257 {
michael@0 2258 if (index >= gl::MAX_VERTEX_ATTRIBS)
michael@0 2259 {
michael@0 2260 return gl::error(GL_INVALID_VALUE);
michael@0 2261 }
michael@0 2262
michael@0 2263 gl::Context *context = gl::getNonLostContext();
michael@0 2264
michael@0 2265 if (context)
michael@0 2266 {
michael@0 2267 context->setEnableVertexAttribArray(index, true);
michael@0 2268 }
michael@0 2269 }
michael@0 2270 catch(std::bad_alloc&)
michael@0 2271 {
michael@0 2272 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2273 }
michael@0 2274 }
michael@0 2275
michael@0 2276 void __stdcall glEndQueryEXT(GLenum target)
michael@0 2277 {
michael@0 2278 EVENT("GLenum target = 0x%X)", target);
michael@0 2279
michael@0 2280 try
michael@0 2281 {
michael@0 2282 switch (target)
michael@0 2283 {
michael@0 2284 case GL_ANY_SAMPLES_PASSED_EXT:
michael@0 2285 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
michael@0 2286 break;
michael@0 2287 default:
michael@0 2288 return gl::error(GL_INVALID_ENUM);
michael@0 2289 }
michael@0 2290
michael@0 2291 gl::Context *context = gl::getNonLostContext();
michael@0 2292
michael@0 2293 if (context)
michael@0 2294 {
michael@0 2295 context->endQuery(target);
michael@0 2296 }
michael@0 2297 }
michael@0 2298 catch(std::bad_alloc&)
michael@0 2299 {
michael@0 2300 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2301 }
michael@0 2302 }
michael@0 2303
michael@0 2304 void __stdcall glFinishFenceNV(GLuint fence)
michael@0 2305 {
michael@0 2306 EVENT("(GLuint fence = %d)", fence);
michael@0 2307
michael@0 2308 try
michael@0 2309 {
michael@0 2310 gl::Context *context = gl::getNonLostContext();
michael@0 2311
michael@0 2312 if (context)
michael@0 2313 {
michael@0 2314 gl::Fence* fenceObject = context->getFence(fence);
michael@0 2315
michael@0 2316 if (fenceObject == NULL)
michael@0 2317 {
michael@0 2318 return gl::error(GL_INVALID_OPERATION);
michael@0 2319 }
michael@0 2320
michael@0 2321 fenceObject->finishFence();
michael@0 2322 }
michael@0 2323 }
michael@0 2324 catch(std::bad_alloc&)
michael@0 2325 {
michael@0 2326 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2327 }
michael@0 2328 }
michael@0 2329
michael@0 2330 void __stdcall glFinish(void)
michael@0 2331 {
michael@0 2332 EVENT("()");
michael@0 2333
michael@0 2334 try
michael@0 2335 {
michael@0 2336 gl::Context *context = gl::getNonLostContext();
michael@0 2337
michael@0 2338 if (context)
michael@0 2339 {
michael@0 2340 context->sync(true);
michael@0 2341 }
michael@0 2342 }
michael@0 2343 catch(std::bad_alloc&)
michael@0 2344 {
michael@0 2345 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2346 }
michael@0 2347 }
michael@0 2348
michael@0 2349 void __stdcall glFlush(void)
michael@0 2350 {
michael@0 2351 EVENT("()");
michael@0 2352
michael@0 2353 try
michael@0 2354 {
michael@0 2355 gl::Context *context = gl::getNonLostContext();
michael@0 2356
michael@0 2357 if (context)
michael@0 2358 {
michael@0 2359 context->sync(false);
michael@0 2360 }
michael@0 2361 }
michael@0 2362 catch(std::bad_alloc&)
michael@0 2363 {
michael@0 2364 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2365 }
michael@0 2366 }
michael@0 2367
michael@0 2368 void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
michael@0 2369 {
michael@0 2370 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
michael@0 2371 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
michael@0 2372
michael@0 2373 try
michael@0 2374 {
michael@0 2375 if ((target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
michael@0 2376 || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
michael@0 2377 {
michael@0 2378 return gl::error(GL_INVALID_ENUM);
michael@0 2379 }
michael@0 2380
michael@0 2381 gl::Context *context = gl::getNonLostContext();
michael@0 2382
michael@0 2383 if (context)
michael@0 2384 {
michael@0 2385 gl::Framebuffer *framebuffer = NULL;
michael@0 2386 GLuint framebufferHandle = 0;
michael@0 2387 if (target == GL_READ_FRAMEBUFFER_ANGLE)
michael@0 2388 {
michael@0 2389 framebuffer = context->getReadFramebuffer();
michael@0 2390 framebufferHandle = context->getReadFramebufferHandle();
michael@0 2391 }
michael@0 2392 else
michael@0 2393 {
michael@0 2394 framebuffer = context->getDrawFramebuffer();
michael@0 2395 framebufferHandle = context->getDrawFramebufferHandle();
michael@0 2396 }
michael@0 2397
michael@0 2398 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
michael@0 2399 {
michael@0 2400 return gl::error(GL_INVALID_OPERATION);
michael@0 2401 }
michael@0 2402
michael@0 2403 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
michael@0 2404 {
michael@0 2405 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
michael@0 2406
michael@0 2407 if (colorAttachment >= context->getMaximumRenderTargets())
michael@0 2408 {
michael@0 2409 return gl::error(GL_INVALID_VALUE);
michael@0 2410 }
michael@0 2411
michael@0 2412 framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer);
michael@0 2413 }
michael@0 2414 else
michael@0 2415 {
michael@0 2416 switch (attachment)
michael@0 2417 {
michael@0 2418 case GL_DEPTH_ATTACHMENT:
michael@0 2419 framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer);
michael@0 2420 break;
michael@0 2421 case GL_STENCIL_ATTACHMENT:
michael@0 2422 framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer);
michael@0 2423 break;
michael@0 2424 default:
michael@0 2425 return gl::error(GL_INVALID_ENUM);
michael@0 2426 }
michael@0 2427 }
michael@0 2428 }
michael@0 2429 }
michael@0 2430 catch(std::bad_alloc&)
michael@0 2431 {
michael@0 2432 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2433 }
michael@0 2434 }
michael@0 2435
michael@0 2436 void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
michael@0 2437 {
michael@0 2438 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
michael@0 2439 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
michael@0 2440
michael@0 2441 try
michael@0 2442 {
michael@0 2443 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
michael@0 2444 {
michael@0 2445 return gl::error(GL_INVALID_ENUM);
michael@0 2446 }
michael@0 2447
michael@0 2448 gl::Context *context = gl::getNonLostContext();
michael@0 2449
michael@0 2450 if (context)
michael@0 2451 {
michael@0 2452 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
michael@0 2453 {
michael@0 2454 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
michael@0 2455
michael@0 2456 if (colorAttachment >= context->getMaximumRenderTargets())
michael@0 2457 {
michael@0 2458 return gl::error(GL_INVALID_VALUE);
michael@0 2459 }
michael@0 2460 }
michael@0 2461 else
michael@0 2462 {
michael@0 2463 switch (attachment)
michael@0 2464 {
michael@0 2465 case GL_DEPTH_ATTACHMENT:
michael@0 2466 case GL_STENCIL_ATTACHMENT:
michael@0 2467 break;
michael@0 2468 default:
michael@0 2469 return gl::error(GL_INVALID_ENUM);
michael@0 2470 }
michael@0 2471 }
michael@0 2472
michael@0 2473 if (texture == 0)
michael@0 2474 {
michael@0 2475 textarget = GL_NONE;
michael@0 2476 }
michael@0 2477 else
michael@0 2478 {
michael@0 2479 gl::Texture *tex = context->getTexture(texture);
michael@0 2480
michael@0 2481 if (tex == NULL)
michael@0 2482 {
michael@0 2483 return gl::error(GL_INVALID_OPERATION);
michael@0 2484 }
michael@0 2485
michael@0 2486 switch (textarget)
michael@0 2487 {
michael@0 2488 case GL_TEXTURE_2D:
michael@0 2489 {
michael@0 2490 if (tex->getTarget() != GL_TEXTURE_2D)
michael@0 2491 {
michael@0 2492 return gl::error(GL_INVALID_OPERATION);
michael@0 2493 }
michael@0 2494 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
michael@0 2495 if (tex2d->isCompressed(0))
michael@0 2496 {
michael@0 2497 return gl::error(GL_INVALID_OPERATION);
michael@0 2498 }
michael@0 2499 break;
michael@0 2500 }
michael@0 2501
michael@0 2502 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
michael@0 2503 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
michael@0 2504 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
michael@0 2505 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
michael@0 2506 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
michael@0 2507 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
michael@0 2508 {
michael@0 2509 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
michael@0 2510 {
michael@0 2511 return gl::error(GL_INVALID_OPERATION);
michael@0 2512 }
michael@0 2513 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
michael@0 2514 if (texcube->isCompressed(textarget, level))
michael@0 2515 {
michael@0 2516 return gl::error(GL_INVALID_OPERATION);
michael@0 2517 }
michael@0 2518 break;
michael@0 2519 }
michael@0 2520
michael@0 2521 default:
michael@0 2522 return gl::error(GL_INVALID_ENUM);
michael@0 2523 }
michael@0 2524
michael@0 2525 if (level != 0)
michael@0 2526 {
michael@0 2527 return gl::error(GL_INVALID_VALUE);
michael@0 2528 }
michael@0 2529 }
michael@0 2530
michael@0 2531 gl::Framebuffer *framebuffer = NULL;
michael@0 2532 GLuint framebufferHandle = 0;
michael@0 2533 if (target == GL_READ_FRAMEBUFFER_ANGLE)
michael@0 2534 {
michael@0 2535 framebuffer = context->getReadFramebuffer();
michael@0 2536 framebufferHandle = context->getReadFramebufferHandle();
michael@0 2537 }
michael@0 2538 else
michael@0 2539 {
michael@0 2540 framebuffer = context->getDrawFramebuffer();
michael@0 2541 framebufferHandle = context->getDrawFramebufferHandle();
michael@0 2542 }
michael@0 2543
michael@0 2544 if (framebufferHandle == 0 || !framebuffer)
michael@0 2545 {
michael@0 2546 return gl::error(GL_INVALID_OPERATION);
michael@0 2547 }
michael@0 2548
michael@0 2549 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
michael@0 2550 {
michael@0 2551 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
michael@0 2552
michael@0 2553 if (colorAttachment >= context->getMaximumRenderTargets())
michael@0 2554 {
michael@0 2555 return gl::error(GL_INVALID_VALUE);
michael@0 2556 }
michael@0 2557
michael@0 2558 framebuffer->setColorbuffer(colorAttachment, textarget, texture);
michael@0 2559 }
michael@0 2560 else
michael@0 2561 {
michael@0 2562 switch (attachment)
michael@0 2563 {
michael@0 2564 case GL_DEPTH_ATTACHMENT: framebuffer->setDepthbuffer(textarget, texture); break;
michael@0 2565 case GL_STENCIL_ATTACHMENT: framebuffer->setStencilbuffer(textarget, texture); break;
michael@0 2566 }
michael@0 2567 }
michael@0 2568 }
michael@0 2569 }
michael@0 2570 catch(std::bad_alloc&)
michael@0 2571 {
michael@0 2572 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2573 }
michael@0 2574 }
michael@0 2575
michael@0 2576 void __stdcall glFrontFace(GLenum mode)
michael@0 2577 {
michael@0 2578 EVENT("(GLenum mode = 0x%X)", mode);
michael@0 2579
michael@0 2580 try
michael@0 2581 {
michael@0 2582 switch (mode)
michael@0 2583 {
michael@0 2584 case GL_CW:
michael@0 2585 case GL_CCW:
michael@0 2586 {
michael@0 2587 gl::Context *context = gl::getNonLostContext();
michael@0 2588
michael@0 2589 if (context)
michael@0 2590 {
michael@0 2591 context->setFrontFace(mode);
michael@0 2592 }
michael@0 2593 }
michael@0 2594 break;
michael@0 2595 default:
michael@0 2596 return gl::error(GL_INVALID_ENUM);
michael@0 2597 }
michael@0 2598 }
michael@0 2599 catch(std::bad_alloc&)
michael@0 2600 {
michael@0 2601 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2602 }
michael@0 2603 }
michael@0 2604
michael@0 2605 void __stdcall glGenBuffers(GLsizei n, GLuint* buffers)
michael@0 2606 {
michael@0 2607 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
michael@0 2608
michael@0 2609 try
michael@0 2610 {
michael@0 2611 if (n < 0)
michael@0 2612 {
michael@0 2613 return gl::error(GL_INVALID_VALUE);
michael@0 2614 }
michael@0 2615
michael@0 2616 gl::Context *context = gl::getNonLostContext();
michael@0 2617
michael@0 2618 if (context)
michael@0 2619 {
michael@0 2620 for (int i = 0; i < n; i++)
michael@0 2621 {
michael@0 2622 buffers[i] = context->createBuffer();
michael@0 2623 }
michael@0 2624 }
michael@0 2625 }
michael@0 2626 catch(std::bad_alloc&)
michael@0 2627 {
michael@0 2628 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2629 }
michael@0 2630 }
michael@0 2631
michael@0 2632 void __stdcall glGenerateMipmap(GLenum target)
michael@0 2633 {
michael@0 2634 EVENT("(GLenum target = 0x%X)", target);
michael@0 2635
michael@0 2636 try
michael@0 2637 {
michael@0 2638 gl::Context *context = gl::getNonLostContext();
michael@0 2639
michael@0 2640 if (context)
michael@0 2641 {
michael@0 2642 switch (target)
michael@0 2643 {
michael@0 2644 case GL_TEXTURE_2D:
michael@0 2645 {
michael@0 2646 gl::Texture2D *tex2d = context->getTexture2D();
michael@0 2647
michael@0 2648 if (tex2d->isCompressed(0))
michael@0 2649 {
michael@0 2650 return gl::error(GL_INVALID_OPERATION);
michael@0 2651 }
michael@0 2652 if (tex2d->isDepth(0))
michael@0 2653 {
michael@0 2654 return gl::error(GL_INVALID_OPERATION);
michael@0 2655 }
michael@0 2656
michael@0 2657 tex2d->generateMipmaps();
michael@0 2658 break;
michael@0 2659 }
michael@0 2660
michael@0 2661 case GL_TEXTURE_CUBE_MAP:
michael@0 2662 {
michael@0 2663 gl::TextureCubeMap *texcube = context->getTextureCubeMap();
michael@0 2664
michael@0 2665 if (texcube->isCompressed(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0))
michael@0 2666 {
michael@0 2667 return gl::error(GL_INVALID_OPERATION);
michael@0 2668 }
michael@0 2669
michael@0 2670 texcube->generateMipmaps();
michael@0 2671 break;
michael@0 2672 }
michael@0 2673
michael@0 2674 default:
michael@0 2675 return gl::error(GL_INVALID_ENUM);
michael@0 2676 }
michael@0 2677 }
michael@0 2678 }
michael@0 2679 catch(std::bad_alloc&)
michael@0 2680 {
michael@0 2681 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2682 }
michael@0 2683 }
michael@0 2684
michael@0 2685 void __stdcall glGenFencesNV(GLsizei n, GLuint* fences)
michael@0 2686 {
michael@0 2687 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
michael@0 2688
michael@0 2689 try
michael@0 2690 {
michael@0 2691 if (n < 0)
michael@0 2692 {
michael@0 2693 return gl::error(GL_INVALID_VALUE);
michael@0 2694 }
michael@0 2695
michael@0 2696 gl::Context *context = gl::getNonLostContext();
michael@0 2697
michael@0 2698 if (context)
michael@0 2699 {
michael@0 2700 for (int i = 0; i < n; i++)
michael@0 2701 {
michael@0 2702 fences[i] = context->createFence();
michael@0 2703 }
michael@0 2704 }
michael@0 2705 }
michael@0 2706 catch(std::bad_alloc&)
michael@0 2707 {
michael@0 2708 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2709 }
michael@0 2710 }
michael@0 2711
michael@0 2712 void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers)
michael@0 2713 {
michael@0 2714 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
michael@0 2715
michael@0 2716 try
michael@0 2717 {
michael@0 2718 if (n < 0)
michael@0 2719 {
michael@0 2720 return gl::error(GL_INVALID_VALUE);
michael@0 2721 }
michael@0 2722
michael@0 2723 gl::Context *context = gl::getNonLostContext();
michael@0 2724
michael@0 2725 if (context)
michael@0 2726 {
michael@0 2727 for (int i = 0; i < n; i++)
michael@0 2728 {
michael@0 2729 framebuffers[i] = context->createFramebuffer();
michael@0 2730 }
michael@0 2731 }
michael@0 2732 }
michael@0 2733 catch(std::bad_alloc&)
michael@0 2734 {
michael@0 2735 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2736 }
michael@0 2737 }
michael@0 2738
michael@0 2739 void __stdcall glGenQueriesEXT(GLsizei n, GLuint* ids)
michael@0 2740 {
michael@0 2741 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
michael@0 2742
michael@0 2743 try
michael@0 2744 {
michael@0 2745 if (n < 0)
michael@0 2746 {
michael@0 2747 return gl::error(GL_INVALID_VALUE);
michael@0 2748 }
michael@0 2749
michael@0 2750 gl::Context *context = gl::getNonLostContext();
michael@0 2751
michael@0 2752 if (context)
michael@0 2753 {
michael@0 2754 for (int i = 0; i < n; i++)
michael@0 2755 {
michael@0 2756 ids[i] = context->createQuery();
michael@0 2757 }
michael@0 2758 }
michael@0 2759 }
michael@0 2760 catch(std::bad_alloc&)
michael@0 2761 {
michael@0 2762 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2763 }
michael@0 2764 }
michael@0 2765
michael@0 2766 void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
michael@0 2767 {
michael@0 2768 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
michael@0 2769
michael@0 2770 try
michael@0 2771 {
michael@0 2772 if (n < 0)
michael@0 2773 {
michael@0 2774 return gl::error(GL_INVALID_VALUE);
michael@0 2775 }
michael@0 2776
michael@0 2777 gl::Context *context = gl::getNonLostContext();
michael@0 2778
michael@0 2779 if (context)
michael@0 2780 {
michael@0 2781 for (int i = 0; i < n; i++)
michael@0 2782 {
michael@0 2783 renderbuffers[i] = context->createRenderbuffer();
michael@0 2784 }
michael@0 2785 }
michael@0 2786 }
michael@0 2787 catch(std::bad_alloc&)
michael@0 2788 {
michael@0 2789 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2790 }
michael@0 2791 }
michael@0 2792
michael@0 2793 void __stdcall glGenTextures(GLsizei n, GLuint* textures)
michael@0 2794 {
michael@0 2795 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
michael@0 2796
michael@0 2797 try
michael@0 2798 {
michael@0 2799 if (n < 0)
michael@0 2800 {
michael@0 2801 return gl::error(GL_INVALID_VALUE);
michael@0 2802 }
michael@0 2803
michael@0 2804 gl::Context *context = gl::getNonLostContext();
michael@0 2805
michael@0 2806 if (context)
michael@0 2807 {
michael@0 2808 for (int i = 0; i < n; i++)
michael@0 2809 {
michael@0 2810 textures[i] = context->createTexture();
michael@0 2811 }
michael@0 2812 }
michael@0 2813 }
michael@0 2814 catch(std::bad_alloc&)
michael@0 2815 {
michael@0 2816 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2817 }
michael@0 2818 }
michael@0 2819
michael@0 2820 void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
michael@0 2821 {
michael@0 2822 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
michael@0 2823 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
michael@0 2824 program, index, bufsize, length, size, type, name);
michael@0 2825
michael@0 2826 try
michael@0 2827 {
michael@0 2828 if (bufsize < 0)
michael@0 2829 {
michael@0 2830 return gl::error(GL_INVALID_VALUE);
michael@0 2831 }
michael@0 2832
michael@0 2833 gl::Context *context = gl::getNonLostContext();
michael@0 2834
michael@0 2835 if (context)
michael@0 2836 {
michael@0 2837 gl::Program *programObject = context->getProgram(program);
michael@0 2838
michael@0 2839 if (!programObject)
michael@0 2840 {
michael@0 2841 if (context->getShader(program))
michael@0 2842 {
michael@0 2843 return gl::error(GL_INVALID_OPERATION);
michael@0 2844 }
michael@0 2845 else
michael@0 2846 {
michael@0 2847 return gl::error(GL_INVALID_VALUE);
michael@0 2848 }
michael@0 2849 }
michael@0 2850
michael@0 2851 if (index >= (GLuint)programObject->getActiveAttributeCount())
michael@0 2852 {
michael@0 2853 return gl::error(GL_INVALID_VALUE);
michael@0 2854 }
michael@0 2855
michael@0 2856 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
michael@0 2857 }
michael@0 2858 }
michael@0 2859 catch(std::bad_alloc&)
michael@0 2860 {
michael@0 2861 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2862 }
michael@0 2863 }
michael@0 2864
michael@0 2865 void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
michael@0 2866 {
michael@0 2867 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
michael@0 2868 "GLsizei* length = 0x%0.8p, GLint* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
michael@0 2869 program, index, bufsize, length, size, type, name);
michael@0 2870
michael@0 2871 try
michael@0 2872 {
michael@0 2873 if (bufsize < 0)
michael@0 2874 {
michael@0 2875 return gl::error(GL_INVALID_VALUE);
michael@0 2876 }
michael@0 2877
michael@0 2878 gl::Context *context = gl::getNonLostContext();
michael@0 2879
michael@0 2880 if (context)
michael@0 2881 {
michael@0 2882 gl::Program *programObject = context->getProgram(program);
michael@0 2883
michael@0 2884 if (!programObject)
michael@0 2885 {
michael@0 2886 if (context->getShader(program))
michael@0 2887 {
michael@0 2888 return gl::error(GL_INVALID_OPERATION);
michael@0 2889 }
michael@0 2890 else
michael@0 2891 {
michael@0 2892 return gl::error(GL_INVALID_VALUE);
michael@0 2893 }
michael@0 2894 }
michael@0 2895
michael@0 2896 if (index >= (GLuint)programObject->getActiveUniformCount())
michael@0 2897 {
michael@0 2898 return gl::error(GL_INVALID_VALUE);
michael@0 2899 }
michael@0 2900
michael@0 2901 programObject->getActiveUniform(index, bufsize, length, size, type, name);
michael@0 2902 }
michael@0 2903 }
michael@0 2904 catch(std::bad_alloc&)
michael@0 2905 {
michael@0 2906 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2907 }
michael@0 2908 }
michael@0 2909
michael@0 2910 void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
michael@0 2911 {
michael@0 2912 EVENT("(GLuint program = %d, GLsizei maxcount = %d, GLsizei* count = 0x%0.8p, GLuint* shaders = 0x%0.8p)",
michael@0 2913 program, maxcount, count, shaders);
michael@0 2914
michael@0 2915 try
michael@0 2916 {
michael@0 2917 if (maxcount < 0)
michael@0 2918 {
michael@0 2919 return gl::error(GL_INVALID_VALUE);
michael@0 2920 }
michael@0 2921
michael@0 2922 gl::Context *context = gl::getNonLostContext();
michael@0 2923
michael@0 2924 if (context)
michael@0 2925 {
michael@0 2926 gl::Program *programObject = context->getProgram(program);
michael@0 2927
michael@0 2928 if (!programObject)
michael@0 2929 {
michael@0 2930 if (context->getShader(program))
michael@0 2931 {
michael@0 2932 return gl::error(GL_INVALID_OPERATION);
michael@0 2933 }
michael@0 2934 else
michael@0 2935 {
michael@0 2936 return gl::error(GL_INVALID_VALUE);
michael@0 2937 }
michael@0 2938 }
michael@0 2939
michael@0 2940 return programObject->getAttachedShaders(maxcount, count, shaders);
michael@0 2941 }
michael@0 2942 }
michael@0 2943 catch(std::bad_alloc&)
michael@0 2944 {
michael@0 2945 return gl::error(GL_OUT_OF_MEMORY);
michael@0 2946 }
michael@0 2947 }
michael@0 2948
michael@0 2949 int __stdcall glGetAttribLocation(GLuint program, const GLchar* name)
michael@0 2950 {
michael@0 2951 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
michael@0 2952
michael@0 2953 try
michael@0 2954 {
michael@0 2955 gl::Context *context = gl::getNonLostContext();
michael@0 2956
michael@0 2957 if (context)
michael@0 2958 {
michael@0 2959
michael@0 2960 gl::Program *programObject = context->getProgram(program);
michael@0 2961
michael@0 2962 if (!programObject)
michael@0 2963 {
michael@0 2964 if (context->getShader(program))
michael@0 2965 {
michael@0 2966 return gl::error(GL_INVALID_OPERATION, -1);
michael@0 2967 }
michael@0 2968 else
michael@0 2969 {
michael@0 2970 return gl::error(GL_INVALID_VALUE, -1);
michael@0 2971 }
michael@0 2972 }
michael@0 2973
michael@0 2974 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
michael@0 2975 if (!programObject->isLinked() || !programBinary)
michael@0 2976 {
michael@0 2977 return gl::error(GL_INVALID_OPERATION, -1);
michael@0 2978 }
michael@0 2979
michael@0 2980 return programBinary->getAttributeLocation(name);
michael@0 2981 }
michael@0 2982 }
michael@0 2983 catch(std::bad_alloc&)
michael@0 2984 {
michael@0 2985 return gl::error(GL_OUT_OF_MEMORY, -1);
michael@0 2986 }
michael@0 2987
michael@0 2988 return -1;
michael@0 2989 }
michael@0 2990
michael@0 2991 void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
michael@0 2992 {
michael@0 2993 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
michael@0 2994
michael@0 2995 try
michael@0 2996 {
michael@0 2997 gl::Context *context = gl::getNonLostContext();
michael@0 2998
michael@0 2999 if (context)
michael@0 3000 {
michael@0 3001 if (!(context->getBooleanv(pname, params)))
michael@0 3002 {
michael@0 3003 GLenum nativeType;
michael@0 3004 unsigned int numParams = 0;
michael@0 3005 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
michael@0 3006 return gl::error(GL_INVALID_ENUM);
michael@0 3007
michael@0 3008 if (numParams == 0)
michael@0 3009 return; // it is known that the pname is valid, but there are no parameters to return
michael@0 3010
michael@0 3011 if (nativeType == GL_FLOAT)
michael@0 3012 {
michael@0 3013 GLfloat *floatParams = NULL;
michael@0 3014 floatParams = new GLfloat[numParams];
michael@0 3015
michael@0 3016 context->getFloatv(pname, floatParams);
michael@0 3017
michael@0 3018 for (unsigned int i = 0; i < numParams; ++i)
michael@0 3019 {
michael@0 3020 if (floatParams[i] == 0.0f)
michael@0 3021 params[i] = GL_FALSE;
michael@0 3022 else
michael@0 3023 params[i] = GL_TRUE;
michael@0 3024 }
michael@0 3025
michael@0 3026 delete [] floatParams;
michael@0 3027 }
michael@0 3028 else if (nativeType == GL_INT)
michael@0 3029 {
michael@0 3030 GLint *intParams = NULL;
michael@0 3031 intParams = new GLint[numParams];
michael@0 3032
michael@0 3033 context->getIntegerv(pname, intParams);
michael@0 3034
michael@0 3035 for (unsigned int i = 0; i < numParams; ++i)
michael@0 3036 {
michael@0 3037 if (intParams[i] == 0)
michael@0 3038 params[i] = GL_FALSE;
michael@0 3039 else
michael@0 3040 params[i] = GL_TRUE;
michael@0 3041 }
michael@0 3042
michael@0 3043 delete [] intParams;
michael@0 3044 }
michael@0 3045 }
michael@0 3046 }
michael@0 3047 }
michael@0 3048 catch(std::bad_alloc&)
michael@0 3049 {
michael@0 3050 return gl::error(GL_OUT_OF_MEMORY);
michael@0 3051 }
michael@0 3052 }
michael@0 3053
michael@0 3054 void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
michael@0 3055 {
michael@0 3056 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
michael@0 3057
michael@0 3058 try
michael@0 3059 {
michael@0 3060 gl::Context *context = gl::getNonLostContext();
michael@0 3061
michael@0 3062 if (context)
michael@0 3063 {
michael@0 3064 gl::Buffer *buffer;
michael@0 3065
michael@0 3066 switch (target)
michael@0 3067 {
michael@0 3068 case GL_ARRAY_BUFFER:
michael@0 3069 buffer = context->getArrayBuffer();
michael@0 3070 break;
michael@0 3071 case GL_ELEMENT_ARRAY_BUFFER:
michael@0 3072 buffer = context->getElementArrayBuffer();
michael@0 3073 break;
michael@0 3074 default: return gl::error(GL_INVALID_ENUM);
michael@0 3075 }
michael@0 3076
michael@0 3077 if (!buffer)
michael@0 3078 {
michael@0 3079 // A null buffer means that "0" is bound to the requested buffer target
michael@0 3080 return gl::error(GL_INVALID_OPERATION);
michael@0 3081 }
michael@0 3082
michael@0 3083 switch (pname)
michael@0 3084 {
michael@0 3085 case GL_BUFFER_USAGE:
michael@0 3086 *params = buffer->usage();
michael@0 3087 break;
michael@0 3088 case GL_BUFFER_SIZE:
michael@0 3089 *params = buffer->size();
michael@0 3090 break;
michael@0 3091 default: return gl::error(GL_INVALID_ENUM);
michael@0 3092 }
michael@0 3093 }
michael@0 3094 }
michael@0 3095 catch(std::bad_alloc&)
michael@0 3096 {
michael@0 3097 return gl::error(GL_OUT_OF_MEMORY);
michael@0 3098 }
michael@0 3099 }
michael@0 3100
michael@0 3101 GLenum __stdcall glGetError(void)
michael@0 3102 {
michael@0 3103 EVENT("()");
michael@0 3104
michael@0 3105 gl::Context *context = gl::getContext();
michael@0 3106
michael@0 3107 if (context)
michael@0 3108 {
michael@0 3109 return context->getError();
michael@0 3110 }
michael@0 3111
michael@0 3112 return GL_NO_ERROR;
michael@0 3113 }
michael@0 3114
michael@0 3115 void __stdcall glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
michael@0 3116 {
michael@0 3117 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
michael@0 3118
michael@0 3119 try
michael@0 3120 {
michael@0 3121
michael@0 3122 gl::Context *context = gl::getNonLostContext();
michael@0 3123
michael@0 3124 if (context)
michael@0 3125 {
michael@0 3126 gl::Fence *fenceObject = context->getFence(fence);
michael@0 3127
michael@0 3128 if (fenceObject == NULL)
michael@0 3129 {
michael@0 3130 return gl::error(GL_INVALID_OPERATION);
michael@0 3131 }
michael@0 3132
michael@0 3133 fenceObject->getFenceiv(pname, params);
michael@0 3134 }
michael@0 3135 }
michael@0 3136 catch(std::bad_alloc&)
michael@0 3137 {
michael@0 3138 return gl::error(GL_OUT_OF_MEMORY);
michael@0 3139 }
michael@0 3140 }
michael@0 3141
michael@0 3142 void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
michael@0 3143 {
michael@0 3144 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
michael@0 3145
michael@0 3146 try
michael@0 3147 {
michael@0 3148 gl::Context *context = gl::getNonLostContext();
michael@0 3149
michael@0 3150 if (context)
michael@0 3151 {
michael@0 3152 if (!(context->getFloatv(pname, params)))
michael@0 3153 {
michael@0 3154 GLenum nativeType;
michael@0 3155 unsigned int numParams = 0;
michael@0 3156 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
michael@0 3157 return gl::error(GL_INVALID_ENUM);
michael@0 3158
michael@0 3159 if (numParams == 0)
michael@0 3160 return; // it is known that the pname is valid, but that there are no parameters to return.
michael@0 3161
michael@0 3162 if (nativeType == GL_BOOL)
michael@0 3163 {
michael@0 3164 GLboolean *boolParams = NULL;
michael@0 3165 boolParams = new GLboolean[numParams];
michael@0 3166
michael@0 3167 context->getBooleanv(pname, boolParams);
michael@0 3168
michael@0 3169 for (unsigned int i = 0; i < numParams; ++i)
michael@0 3170 {
michael@0 3171 if (boolParams[i] == GL_FALSE)
michael@0 3172 params[i] = 0.0f;
michael@0 3173 else
michael@0 3174 params[i] = 1.0f;
michael@0 3175 }
michael@0 3176
michael@0 3177 delete [] boolParams;
michael@0 3178 }
michael@0 3179 else if (nativeType == GL_INT)
michael@0 3180 {
michael@0 3181 GLint *intParams = NULL;
michael@0 3182 intParams = new GLint[numParams];
michael@0 3183
michael@0 3184 context->getIntegerv(pname, intParams);
michael@0 3185
michael@0 3186 for (unsigned int i = 0; i < numParams; ++i)
michael@0 3187 {
michael@0 3188 params[i] = (GLfloat)intParams[i];
michael@0 3189 }
michael@0 3190
michael@0 3191 delete [] intParams;
michael@0 3192 }
michael@0 3193 }
michael@0 3194 }
michael@0 3195 }
michael@0 3196 catch(std::bad_alloc&)
michael@0 3197 {
michael@0 3198 return gl::error(GL_OUT_OF_MEMORY);
michael@0 3199 }
michael@0 3200 }
michael@0 3201
michael@0 3202 void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
michael@0 3203 {
michael@0 3204 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
michael@0 3205 target, attachment, pname, params);
michael@0 3206
michael@0 3207 try
michael@0 3208 {
michael@0 3209 gl::Context *context = gl::getNonLostContext();
michael@0 3210
michael@0 3211 if (context)
michael@0 3212 {
michael@0 3213 if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER_ANGLE && target != GL_READ_FRAMEBUFFER_ANGLE)
michael@0 3214 {
michael@0 3215 return gl::error(GL_INVALID_ENUM);
michael@0 3216 }
michael@0 3217
michael@0 3218 gl::Framebuffer *framebuffer = NULL;
michael@0 3219 if (target == GL_READ_FRAMEBUFFER_ANGLE)
michael@0 3220 {
michael@0 3221 if(context->getReadFramebufferHandle() == 0)
michael@0 3222 {
michael@0 3223 return gl::error(GL_INVALID_OPERATION);
michael@0 3224 }
michael@0 3225
michael@0 3226 framebuffer = context->getReadFramebuffer();
michael@0 3227 }
michael@0 3228 else
michael@0 3229 {
michael@0 3230 if (context->getDrawFramebufferHandle() == 0)
michael@0 3231 {
michael@0 3232 return gl::error(GL_INVALID_OPERATION);
michael@0 3233 }
michael@0 3234
michael@0 3235 framebuffer = context->getDrawFramebuffer();
michael@0 3236 }
michael@0 3237
michael@0 3238 GLenum attachmentType;
michael@0 3239 GLuint attachmentHandle;
michael@0 3240
michael@0 3241 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
michael@0 3242 {
michael@0 3243 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
michael@0 3244
michael@0 3245 if (colorAttachment >= context->getMaximumRenderTargets())
michael@0 3246 {
michael@0 3247 return gl::error(GL_INVALID_ENUM);
michael@0 3248 }
michael@0 3249
michael@0 3250 attachmentType = framebuffer->getColorbufferType(colorAttachment);
michael@0 3251 attachmentHandle = framebuffer->getColorbufferHandle(colorAttachment);
michael@0 3252 }
michael@0 3253 else
michael@0 3254 {
michael@0 3255 switch (attachment)
michael@0 3256 {
michael@0 3257 case GL_DEPTH_ATTACHMENT:
michael@0 3258 attachmentType = framebuffer->getDepthbufferType();
michael@0 3259 attachmentHandle = framebuffer->getDepthbufferHandle();
michael@0 3260 break;
michael@0 3261 case GL_STENCIL_ATTACHMENT:
michael@0 3262 attachmentType = framebuffer->getStencilbufferType();
michael@0 3263 attachmentHandle = framebuffer->getStencilbufferHandle();
michael@0 3264 break;
michael@0 3265 default: return gl::error(GL_INVALID_ENUM);
michael@0 3266 }
michael@0 3267 }
michael@0 3268
michael@0 3269 GLenum attachmentObjectType; // Type category
michael@0 3270 if (attachmentType == GL_NONE || attachmentType == GL_RENDERBUFFER)
michael@0 3271 {
michael@0 3272 attachmentObjectType = attachmentType;
michael@0 3273 }
michael@0 3274 else if (gl::IsInternalTextureTarget(attachmentType))
michael@0 3275 {
michael@0 3276 attachmentObjectType = GL_TEXTURE;
michael@0 3277 }
michael@0 3278 else
michael@0 3279 {
michael@0 3280 UNREACHABLE();
michael@0 3281 return;
michael@0 3282 }
michael@0 3283
michael@0 3284 switch (pname)
michael@0 3285 {
michael@0 3286 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
michael@0 3287 *params = attachmentObjectType;
michael@0 3288 break;
michael@0 3289 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
michael@0 3290 if (attachmentObjectType == GL_RENDERBUFFER || attachmentObjectType == GL_TEXTURE)
michael@0 3291 {
michael@0 3292 *params = attachmentHandle;
michael@0 3293 }
michael@0 3294 else
michael@0 3295 {
michael@0 3296 return gl::error(GL_INVALID_ENUM);
michael@0 3297 }
michael@0 3298 break;
michael@0 3299 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
michael@0 3300 if (attachmentObjectType == GL_TEXTURE)
michael@0 3301 {
michael@0 3302 *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0
michael@0 3303 }
michael@0 3304 else
michael@0 3305 {
michael@0 3306 return gl::error(GL_INVALID_ENUM);
michael@0 3307 }
michael@0 3308 break;
michael@0 3309 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
michael@0 3310 if (attachmentObjectType == GL_TEXTURE)
michael@0 3311 {
michael@0 3312 if (gl::IsCubemapTextureTarget(attachmentType))
michael@0 3313 {
michael@0 3314 *params = attachmentType;
michael@0 3315 }
michael@0 3316 else
michael@0 3317 {
michael@0 3318 *params = 0;
michael@0 3319 }
michael@0 3320 }
michael@0 3321 else
michael@0 3322 {
michael@0 3323 return gl::error(GL_INVALID_ENUM);
michael@0 3324 }
michael@0 3325 break;
michael@0 3326 default:
michael@0 3327 return gl::error(GL_INVALID_ENUM);
michael@0 3328 }
michael@0 3329 }
michael@0 3330 }
michael@0 3331 catch(std::bad_alloc&)
michael@0 3332 {
michael@0 3333 return gl::error(GL_OUT_OF_MEMORY);
michael@0 3334 }
michael@0 3335 }
michael@0 3336
michael@0 3337 GLenum __stdcall glGetGraphicsResetStatusEXT(void)
michael@0 3338 {
michael@0 3339 EVENT("()");
michael@0 3340
michael@0 3341 try
michael@0 3342 {
michael@0 3343 gl::Context *context = gl::getContext();
michael@0 3344
michael@0 3345 if (context)
michael@0 3346 {
michael@0 3347 return context->getResetStatus();
michael@0 3348 }
michael@0 3349
michael@0 3350 return GL_NO_ERROR;
michael@0 3351 }
michael@0 3352 catch(std::bad_alloc&)
michael@0 3353 {
michael@0 3354 return GL_OUT_OF_MEMORY;
michael@0 3355 }
michael@0 3356 }
michael@0 3357
michael@0 3358 void __stdcall glGetIntegerv(GLenum pname, GLint* params)
michael@0 3359 {
michael@0 3360 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
michael@0 3361
michael@0 3362 try
michael@0 3363 {
michael@0 3364 gl::Context *context = gl::getNonLostContext();
michael@0 3365
michael@0 3366 if (context)
michael@0 3367 {
michael@0 3368 if (!(context->getIntegerv(pname, params)))
michael@0 3369 {
michael@0 3370 GLenum nativeType;
michael@0 3371 unsigned int numParams = 0;
michael@0 3372 if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
michael@0 3373 return gl::error(GL_INVALID_ENUM);
michael@0 3374
michael@0 3375 if (numParams == 0)
michael@0 3376 return; // it is known that pname is valid, but there are no parameters to return
michael@0 3377
michael@0 3378 if (nativeType == GL_BOOL)
michael@0 3379 {
michael@0 3380 GLboolean *boolParams = NULL;
michael@0 3381 boolParams = new GLboolean[numParams];
michael@0 3382
michael@0 3383 context->getBooleanv(pname, boolParams);
michael@0 3384
michael@0 3385 for (unsigned int i = 0; i < numParams; ++i)
michael@0 3386 {
michael@0 3387 if (boolParams[i] == GL_FALSE)
michael@0 3388 params[i] = 0;
michael@0 3389 else
michael@0 3390 params[i] = 1;
michael@0 3391 }
michael@0 3392
michael@0 3393 delete [] boolParams;
michael@0 3394 }
michael@0 3395 else if (nativeType == GL_FLOAT)
michael@0 3396 {
michael@0 3397 GLfloat *floatParams = NULL;
michael@0 3398 floatParams = new GLfloat[numParams];
michael@0 3399
michael@0 3400 context->getFloatv(pname, floatParams);
michael@0 3401
michael@0 3402 for (unsigned int i = 0; i < numParams; ++i)
michael@0 3403 {
michael@0 3404 if (pname == GL_DEPTH_RANGE || pname == GL_COLOR_CLEAR_VALUE || pname == GL_DEPTH_CLEAR_VALUE || pname == GL_BLEND_COLOR)
michael@0 3405 {
michael@0 3406 params[i] = (GLint)(((GLfloat)(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f);
michael@0 3407 }
michael@0 3408 else
michael@0 3409 params[i] = (GLint)(floatParams[i] > 0.0f ? floor(floatParams[i] + 0.5) : ceil(floatParams[i] - 0.5));
michael@0 3410 }
michael@0 3411
michael@0 3412 delete [] floatParams;
michael@0 3413 }
michael@0 3414 }
michael@0 3415 }
michael@0 3416 }
michael@0 3417 catch(std::bad_alloc&)
michael@0 3418 {
michael@0 3419 return gl::error(GL_OUT_OF_MEMORY);
michael@0 3420 }
michael@0 3421 }
michael@0 3422
michael@0 3423 void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params)
michael@0 3424 {
michael@0 3425 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
michael@0 3426
michael@0 3427 try
michael@0 3428 {
michael@0 3429 gl::Context *context = gl::getNonLostContext();
michael@0 3430
michael@0 3431 if (context)
michael@0 3432 {
michael@0 3433 gl::Program *programObject = context->getProgram(program);
michael@0 3434
michael@0 3435 if (!programObject)
michael@0 3436 {
michael@0 3437 return gl::error(GL_INVALID_VALUE);
michael@0 3438 }
michael@0 3439
michael@0 3440 switch (pname)
michael@0 3441 {
michael@0 3442 case GL_DELETE_STATUS:
michael@0 3443 *params = programObject->isFlaggedForDeletion();
michael@0 3444 return;
michael@0 3445 case GL_LINK_STATUS:
michael@0 3446 *params = programObject->isLinked();
michael@0 3447 return;
michael@0 3448 case GL_VALIDATE_STATUS:
michael@0 3449 *params = programObject->isValidated();
michael@0 3450 return;
michael@0 3451 case GL_INFO_LOG_LENGTH:
michael@0 3452 *params = programObject->getInfoLogLength();
michael@0 3453 return;
michael@0 3454 case GL_ATTACHED_SHADERS:
michael@0 3455 *params = programObject->getAttachedShadersCount();
michael@0 3456 return;
michael@0 3457 case GL_ACTIVE_ATTRIBUTES:
michael@0 3458 *params = programObject->getActiveAttributeCount();
michael@0 3459 return;
michael@0 3460 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
michael@0 3461 *params = programObject->getActiveAttributeMaxLength();
michael@0 3462 return;
michael@0 3463 case GL_ACTIVE_UNIFORMS:
michael@0 3464 *params = programObject->getActiveUniformCount();
michael@0 3465 return;
michael@0 3466 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
michael@0 3467 *params = programObject->getActiveUniformMaxLength();
michael@0 3468 return;
michael@0 3469 case GL_PROGRAM_BINARY_LENGTH_OES:
michael@0 3470 *params = programObject->getProgramBinaryLength();
michael@0 3471 return;
michael@0 3472 default:
michael@0 3473 return gl::error(GL_INVALID_ENUM);
michael@0 3474 }
michael@0 3475 }
michael@0 3476 }
michael@0 3477 catch(std::bad_alloc&)
michael@0 3478 {
michael@0 3479 return gl::error(GL_OUT_OF_MEMORY);
michael@0 3480 }
michael@0 3481 }
michael@0 3482
michael@0 3483 void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
michael@0 3484 {
michael@0 3485 EVENT("(GLuint program = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* infolog = 0x%0.8p)",
michael@0 3486 program, bufsize, length, infolog);
michael@0 3487
michael@0 3488 try
michael@0 3489 {
michael@0 3490 if (bufsize < 0)
michael@0 3491 {
michael@0 3492 return gl::error(GL_INVALID_VALUE);
michael@0 3493 }
michael@0 3494
michael@0 3495 gl::Context *context = gl::getNonLostContext();
michael@0 3496
michael@0 3497 if (context)
michael@0 3498 {
michael@0 3499 gl::Program *programObject = context->getProgram(program);
michael@0 3500
michael@0 3501 if (!programObject)
michael@0 3502 {
michael@0 3503 return gl::error(GL_INVALID_VALUE);
michael@0 3504 }
michael@0 3505
michael@0 3506 programObject->getInfoLog(bufsize, length, infolog);
michael@0 3507 }
michael@0 3508 }
michael@0 3509 catch(std::bad_alloc&)
michael@0 3510 {
michael@0 3511 return gl::error(GL_OUT_OF_MEMORY);
michael@0 3512 }
michael@0 3513 }
michael@0 3514
michael@0 3515 void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
michael@0 3516 {
michael@0 3517 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
michael@0 3518
michael@0 3519 try
michael@0 3520 {
michael@0 3521 switch (pname)
michael@0 3522 {
michael@0 3523 case GL_CURRENT_QUERY_EXT:
michael@0 3524 break;
michael@0 3525 default:
michael@0 3526 return gl::error(GL_INVALID_ENUM);
michael@0 3527 }
michael@0 3528
michael@0 3529 gl::Context *context = gl::getNonLostContext();
michael@0 3530
michael@0 3531 if (context)
michael@0 3532 {
michael@0 3533 params[0] = context->getActiveQuery(target);
michael@0 3534 }
michael@0 3535 }
michael@0 3536 catch(std::bad_alloc&)
michael@0 3537 {
michael@0 3538 return gl::error(GL_OUT_OF_MEMORY);
michael@0 3539 }
michael@0 3540 }
michael@0 3541
michael@0 3542 void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
michael@0 3543 {
michael@0 3544 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
michael@0 3545
michael@0 3546 try
michael@0 3547 {
michael@0 3548 switch (pname)
michael@0 3549 {
michael@0 3550 case GL_QUERY_RESULT_EXT:
michael@0 3551 case GL_QUERY_RESULT_AVAILABLE_EXT:
michael@0 3552 break;
michael@0 3553 default:
michael@0 3554 return gl::error(GL_INVALID_ENUM);
michael@0 3555 }
michael@0 3556 gl::Context *context = gl::getNonLostContext();
michael@0 3557
michael@0 3558 if (context)
michael@0 3559 {
michael@0 3560 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
michael@0 3561
michael@0 3562 if (!queryObject)
michael@0 3563 {
michael@0 3564 return gl::error(GL_INVALID_OPERATION);
michael@0 3565 }
michael@0 3566
michael@0 3567 if (context->getActiveQuery(queryObject->getType()) == id)
michael@0 3568 {
michael@0 3569 return gl::error(GL_INVALID_OPERATION);
michael@0 3570 }
michael@0 3571
michael@0 3572 switch(pname)
michael@0 3573 {
michael@0 3574 case GL_QUERY_RESULT_EXT:
michael@0 3575 params[0] = queryObject->getResult();
michael@0 3576 break;
michael@0 3577 case GL_QUERY_RESULT_AVAILABLE_EXT:
michael@0 3578 params[0] = queryObject->isResultAvailable();
michael@0 3579 break;
michael@0 3580 default:
michael@0 3581 ASSERT(false);
michael@0 3582 }
michael@0 3583 }
michael@0 3584 }
michael@0 3585 catch(std::bad_alloc&)
michael@0 3586 {
michael@0 3587 return gl::error(GL_OUT_OF_MEMORY);
michael@0 3588 }
michael@0 3589 }
michael@0 3590
michael@0 3591 void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
michael@0 3592 {
michael@0 3593 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
michael@0 3594
michael@0 3595 try
michael@0 3596 {
michael@0 3597 gl::Context *context = gl::getNonLostContext();
michael@0 3598
michael@0 3599 if (context)
michael@0 3600 {
michael@0 3601 if (target != GL_RENDERBUFFER)
michael@0 3602 {
michael@0 3603 return gl::error(GL_INVALID_ENUM);
michael@0 3604 }
michael@0 3605
michael@0 3606 if (context->getRenderbufferHandle() == 0)
michael@0 3607 {
michael@0 3608 return gl::error(GL_INVALID_OPERATION);
michael@0 3609 }
michael@0 3610
michael@0 3611 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
michael@0 3612
michael@0 3613 switch (pname)
michael@0 3614 {
michael@0 3615 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
michael@0 3616 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
michael@0 3617 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
michael@0 3618 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
michael@0 3619 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
michael@0 3620 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
michael@0 3621 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
michael@0 3622 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
michael@0 3623 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
michael@0 3624 case GL_RENDERBUFFER_SAMPLES_ANGLE:
michael@0 3625 if (context->getMaxSupportedSamples() != 0)
michael@0 3626 {
michael@0 3627 *params = renderbuffer->getSamples();
michael@0 3628 }
michael@0 3629 else
michael@0 3630 {
michael@0 3631 return gl::error(GL_INVALID_ENUM);
michael@0 3632 }
michael@0 3633 break;
michael@0 3634 default:
michael@0 3635 return gl::error(GL_INVALID_ENUM);
michael@0 3636 }
michael@0 3637 }
michael@0 3638 }
michael@0 3639 catch(std::bad_alloc&)
michael@0 3640 {
michael@0 3641 return gl::error(GL_OUT_OF_MEMORY);
michael@0 3642 }
michael@0 3643 }
michael@0 3644
michael@0 3645 void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
michael@0 3646 {
michael@0 3647 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
michael@0 3648
michael@0 3649 try
michael@0 3650 {
michael@0 3651 gl::Context *context = gl::getNonLostContext();
michael@0 3652
michael@0 3653 if (context)
michael@0 3654 {
michael@0 3655 gl::Shader *shaderObject = context->getShader(shader);
michael@0 3656
michael@0 3657 if (!shaderObject)
michael@0 3658 {
michael@0 3659 return gl::error(GL_INVALID_VALUE);
michael@0 3660 }
michael@0 3661
michael@0 3662 switch (pname)
michael@0 3663 {
michael@0 3664 case GL_SHADER_TYPE:
michael@0 3665 *params = shaderObject->getType();
michael@0 3666 return;
michael@0 3667 case GL_DELETE_STATUS:
michael@0 3668 *params = shaderObject->isFlaggedForDeletion();
michael@0 3669 return;
michael@0 3670 case GL_COMPILE_STATUS:
michael@0 3671 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
michael@0 3672 return;
michael@0 3673 case GL_INFO_LOG_LENGTH:
michael@0 3674 *params = shaderObject->getInfoLogLength();
michael@0 3675 return;
michael@0 3676 case GL_SHADER_SOURCE_LENGTH:
michael@0 3677 *params = shaderObject->getSourceLength();
michael@0 3678 return;
michael@0 3679 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
michael@0 3680 *params = shaderObject->getTranslatedSourceLength();
michael@0 3681 return;
michael@0 3682 default:
michael@0 3683 return gl::error(GL_INVALID_ENUM);
michael@0 3684 }
michael@0 3685 }
michael@0 3686 }
michael@0 3687 catch(std::bad_alloc&)
michael@0 3688 {
michael@0 3689 return gl::error(GL_OUT_OF_MEMORY);
michael@0 3690 }
michael@0 3691 }
michael@0 3692
michael@0 3693 void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
michael@0 3694 {
michael@0 3695 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* infolog = 0x%0.8p)",
michael@0 3696 shader, bufsize, length, infolog);
michael@0 3697
michael@0 3698 try
michael@0 3699 {
michael@0 3700 if (bufsize < 0)
michael@0 3701 {
michael@0 3702 return gl::error(GL_INVALID_VALUE);
michael@0 3703 }
michael@0 3704
michael@0 3705 gl::Context *context = gl::getNonLostContext();
michael@0 3706
michael@0 3707 if (context)
michael@0 3708 {
michael@0 3709 gl::Shader *shaderObject = context->getShader(shader);
michael@0 3710
michael@0 3711 if (!shaderObject)
michael@0 3712 {
michael@0 3713 return gl::error(GL_INVALID_VALUE);
michael@0 3714 }
michael@0 3715
michael@0 3716 shaderObject->getInfoLog(bufsize, length, infolog);
michael@0 3717 }
michael@0 3718 }
michael@0 3719 catch(std::bad_alloc&)
michael@0 3720 {
michael@0 3721 return gl::error(GL_OUT_OF_MEMORY);
michael@0 3722 }
michael@0 3723 }
michael@0 3724
michael@0 3725 void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
michael@0 3726 {
michael@0 3727 EVENT("(GLenum shadertype = 0x%X, GLenum precisiontype = 0x%X, GLint* range = 0x%0.8p, GLint* precision = 0x%0.8p)",
michael@0 3728 shadertype, precisiontype, range, precision);
michael@0 3729
michael@0 3730 try
michael@0 3731 {
michael@0 3732 switch (shadertype)
michael@0 3733 {
michael@0 3734 case GL_VERTEX_SHADER:
michael@0 3735 case GL_FRAGMENT_SHADER:
michael@0 3736 break;
michael@0 3737 default:
michael@0 3738 return gl::error(GL_INVALID_ENUM);
michael@0 3739 }
michael@0 3740
michael@0 3741 switch (precisiontype)
michael@0 3742 {
michael@0 3743 case GL_LOW_FLOAT:
michael@0 3744 case GL_MEDIUM_FLOAT:
michael@0 3745 case GL_HIGH_FLOAT:
michael@0 3746 // Assume IEEE 754 precision
michael@0 3747 range[0] = 127;
michael@0 3748 range[1] = 127;
michael@0 3749 *precision = 23;
michael@0 3750 break;
michael@0 3751 case GL_LOW_INT:
michael@0 3752 case GL_MEDIUM_INT:
michael@0 3753 case GL_HIGH_INT:
michael@0 3754 // Some (most) hardware only supports single-precision floating-point numbers,
michael@0 3755 // which can accurately represent integers up to +/-16777216
michael@0 3756 range[0] = 24;
michael@0 3757 range[1] = 24;
michael@0 3758 *precision = 0;
michael@0 3759 break;
michael@0 3760 default:
michael@0 3761 return gl::error(GL_INVALID_ENUM);
michael@0 3762 }
michael@0 3763 }
michael@0 3764 catch(std::bad_alloc&)
michael@0 3765 {
michael@0 3766 return gl::error(GL_OUT_OF_MEMORY);
michael@0 3767 }
michael@0 3768 }
michael@0 3769
michael@0 3770 void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
michael@0 3771 {
michael@0 3772 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
michael@0 3773 shader, bufsize, length, source);
michael@0 3774
michael@0 3775 try
michael@0 3776 {
michael@0 3777 if (bufsize < 0)
michael@0 3778 {
michael@0 3779 return gl::error(GL_INVALID_VALUE);
michael@0 3780 }
michael@0 3781
michael@0 3782 gl::Context *context = gl::getNonLostContext();
michael@0 3783
michael@0 3784 if (context)
michael@0 3785 {
michael@0 3786 gl::Shader *shaderObject = context->getShader(shader);
michael@0 3787
michael@0 3788 if (!shaderObject)
michael@0 3789 {
michael@0 3790 return gl::error(GL_INVALID_OPERATION);
michael@0 3791 }
michael@0 3792
michael@0 3793 shaderObject->getSource(bufsize, length, source);
michael@0 3794 }
michael@0 3795 }
michael@0 3796 catch(std::bad_alloc&)
michael@0 3797 {
michael@0 3798 return gl::error(GL_OUT_OF_MEMORY);
michael@0 3799 }
michael@0 3800 }
michael@0 3801
michael@0 3802 void __stdcall glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
michael@0 3803 {
michael@0 3804 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
michael@0 3805 shader, bufsize, length, source);
michael@0 3806
michael@0 3807 try
michael@0 3808 {
michael@0 3809 if (bufsize < 0)
michael@0 3810 {
michael@0 3811 return gl::error(GL_INVALID_VALUE);
michael@0 3812 }
michael@0 3813
michael@0 3814 gl::Context *context = gl::getNonLostContext();
michael@0 3815
michael@0 3816 if (context)
michael@0 3817 {
michael@0 3818 gl::Shader *shaderObject = context->getShader(shader);
michael@0 3819
michael@0 3820 if (!shaderObject)
michael@0 3821 {
michael@0 3822 return gl::error(GL_INVALID_OPERATION);
michael@0 3823 }
michael@0 3824
michael@0 3825 shaderObject->getTranslatedSource(bufsize, length, source);
michael@0 3826 }
michael@0 3827 }
michael@0 3828 catch(std::bad_alloc&)
michael@0 3829 {
michael@0 3830 return gl::error(GL_OUT_OF_MEMORY);
michael@0 3831 }
michael@0 3832 }
michael@0 3833
michael@0 3834 const GLubyte* __stdcall glGetString(GLenum name)
michael@0 3835 {
michael@0 3836 EVENT("(GLenum name = 0x%X)", name);
michael@0 3837
michael@0 3838 try
michael@0 3839 {
michael@0 3840 gl::Context *context = gl::getNonLostContext();
michael@0 3841
michael@0 3842 switch (name)
michael@0 3843 {
michael@0 3844 case GL_VENDOR:
michael@0 3845 return (GLubyte*)"Google Inc.";
michael@0 3846 case GL_RENDERER:
michael@0 3847 return (GLubyte*)((context != NULL) ? context->getRendererString() : "ANGLE");
michael@0 3848 case GL_VERSION:
michael@0 3849 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " VERSION_STRING ")";
michael@0 3850 case GL_SHADING_LANGUAGE_VERSION:
michael@0 3851 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " VERSION_STRING ")";
michael@0 3852 case GL_EXTENSIONS:
michael@0 3853 return (GLubyte*)((context != NULL) ? context->getExtensionString() : "");
michael@0 3854 default:
michael@0 3855 return gl::error(GL_INVALID_ENUM, (GLubyte*)NULL);
michael@0 3856 }
michael@0 3857 }
michael@0 3858 catch(std::bad_alloc&)
michael@0 3859 {
michael@0 3860 return gl::error(GL_OUT_OF_MEMORY, (GLubyte*)NULL);
michael@0 3861 }
michael@0 3862 }
michael@0 3863
michael@0 3864 void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
michael@0 3865 {
michael@0 3866 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", target, pname, params);
michael@0 3867
michael@0 3868 try
michael@0 3869 {
michael@0 3870 gl::Context *context = gl::getNonLostContext();
michael@0 3871
michael@0 3872 if (context)
michael@0 3873 {
michael@0 3874 gl::Texture *texture;
michael@0 3875
michael@0 3876 switch (target)
michael@0 3877 {
michael@0 3878 case GL_TEXTURE_2D:
michael@0 3879 texture = context->getTexture2D();
michael@0 3880 break;
michael@0 3881 case GL_TEXTURE_CUBE_MAP:
michael@0 3882 texture = context->getTextureCubeMap();
michael@0 3883 break;
michael@0 3884 default:
michael@0 3885 return gl::error(GL_INVALID_ENUM);
michael@0 3886 }
michael@0 3887
michael@0 3888 switch (pname)
michael@0 3889 {
michael@0 3890 case GL_TEXTURE_MAG_FILTER:
michael@0 3891 *params = (GLfloat)texture->getMagFilter();
michael@0 3892 break;
michael@0 3893 case GL_TEXTURE_MIN_FILTER:
michael@0 3894 *params = (GLfloat)texture->getMinFilter();
michael@0 3895 break;
michael@0 3896 case GL_TEXTURE_WRAP_S:
michael@0 3897 *params = (GLfloat)texture->getWrapS();
michael@0 3898 break;
michael@0 3899 case GL_TEXTURE_WRAP_T:
michael@0 3900 *params = (GLfloat)texture->getWrapT();
michael@0 3901 break;
michael@0 3902 case GL_TEXTURE_IMMUTABLE_FORMAT_EXT:
michael@0 3903 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
michael@0 3904 break;
michael@0 3905 case GL_TEXTURE_USAGE_ANGLE:
michael@0 3906 *params = (GLfloat)texture->getUsage();
michael@0 3907 break;
michael@0 3908 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
michael@0 3909 if (!context->supportsTextureFilterAnisotropy())
michael@0 3910 {
michael@0 3911 return gl::error(GL_INVALID_ENUM);
michael@0 3912 }
michael@0 3913 *params = (GLfloat)texture->getMaxAnisotropy();
michael@0 3914 break;
michael@0 3915 default:
michael@0 3916 return gl::error(GL_INVALID_ENUM);
michael@0 3917 }
michael@0 3918 }
michael@0 3919 }
michael@0 3920 catch(std::bad_alloc&)
michael@0 3921 {
michael@0 3922 return gl::error(GL_OUT_OF_MEMORY);
michael@0 3923 }
michael@0 3924 }
michael@0 3925
michael@0 3926 void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
michael@0 3927 {
michael@0 3928 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
michael@0 3929
michael@0 3930 try
michael@0 3931 {
michael@0 3932 gl::Context *context = gl::getNonLostContext();
michael@0 3933
michael@0 3934 if (context)
michael@0 3935 {
michael@0 3936 gl::Texture *texture;
michael@0 3937
michael@0 3938 switch (target)
michael@0 3939 {
michael@0 3940 case GL_TEXTURE_2D:
michael@0 3941 texture = context->getTexture2D();
michael@0 3942 break;
michael@0 3943 case GL_TEXTURE_CUBE_MAP:
michael@0 3944 texture = context->getTextureCubeMap();
michael@0 3945 break;
michael@0 3946 default:
michael@0 3947 return gl::error(GL_INVALID_ENUM);
michael@0 3948 }
michael@0 3949
michael@0 3950 switch (pname)
michael@0 3951 {
michael@0 3952 case GL_TEXTURE_MAG_FILTER:
michael@0 3953 *params = texture->getMagFilter();
michael@0 3954 break;
michael@0 3955 case GL_TEXTURE_MIN_FILTER:
michael@0 3956 *params = texture->getMinFilter();
michael@0 3957 break;
michael@0 3958 case GL_TEXTURE_WRAP_S:
michael@0 3959 *params = texture->getWrapS();
michael@0 3960 break;
michael@0 3961 case GL_TEXTURE_WRAP_T:
michael@0 3962 *params = texture->getWrapT();
michael@0 3963 break;
michael@0 3964 case GL_TEXTURE_IMMUTABLE_FORMAT_EXT:
michael@0 3965 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
michael@0 3966 break;
michael@0 3967 case GL_TEXTURE_USAGE_ANGLE:
michael@0 3968 *params = texture->getUsage();
michael@0 3969 break;
michael@0 3970 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
michael@0 3971 if (!context->supportsTextureFilterAnisotropy())
michael@0 3972 {
michael@0 3973 return gl::error(GL_INVALID_ENUM);
michael@0 3974 }
michael@0 3975 *params = (GLint)texture->getMaxAnisotropy();
michael@0 3976 break;
michael@0 3977 default:
michael@0 3978 return gl::error(GL_INVALID_ENUM);
michael@0 3979 }
michael@0 3980 }
michael@0 3981 }
michael@0 3982 catch(std::bad_alloc&)
michael@0 3983 {
michael@0 3984 return gl::error(GL_OUT_OF_MEMORY);
michael@0 3985 }
michael@0 3986 }
michael@0 3987
michael@0 3988 void __stdcall glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
michael@0 3989 {
michael@0 3990 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
michael@0 3991 program, location, bufSize, params);
michael@0 3992
michael@0 3993 try
michael@0 3994 {
michael@0 3995 if (bufSize < 0)
michael@0 3996 {
michael@0 3997 return gl::error(GL_INVALID_VALUE);
michael@0 3998 }
michael@0 3999
michael@0 4000 gl::Context *context = gl::getNonLostContext();
michael@0 4001
michael@0 4002 if (context)
michael@0 4003 {
michael@0 4004 if (program == 0)
michael@0 4005 {
michael@0 4006 return gl::error(GL_INVALID_VALUE);
michael@0 4007 }
michael@0 4008
michael@0 4009 gl::Program *programObject = context->getProgram(program);
michael@0 4010
michael@0 4011 if (!programObject || !programObject->isLinked())
michael@0 4012 {
michael@0 4013 return gl::error(GL_INVALID_OPERATION);
michael@0 4014 }
michael@0 4015
michael@0 4016 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
michael@0 4017 if (!programBinary)
michael@0 4018 {
michael@0 4019 return gl::error(GL_INVALID_OPERATION);
michael@0 4020 }
michael@0 4021
michael@0 4022 if (!programBinary->getUniformfv(location, &bufSize, params))
michael@0 4023 {
michael@0 4024 return gl::error(GL_INVALID_OPERATION);
michael@0 4025 }
michael@0 4026 }
michael@0 4027 }
michael@0 4028 catch(std::bad_alloc&)
michael@0 4029 {
michael@0 4030 return gl::error(GL_OUT_OF_MEMORY);
michael@0 4031 }
michael@0 4032 }
michael@0 4033
michael@0 4034 void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params)
michael@0 4035 {
michael@0 4036 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
michael@0 4037
michael@0 4038 try
michael@0 4039 {
michael@0 4040 gl::Context *context = gl::getNonLostContext();
michael@0 4041
michael@0 4042 if (context)
michael@0 4043 {
michael@0 4044 if (program == 0)
michael@0 4045 {
michael@0 4046 return gl::error(GL_INVALID_VALUE);
michael@0 4047 }
michael@0 4048
michael@0 4049 gl::Program *programObject = context->getProgram(program);
michael@0 4050
michael@0 4051 if (!programObject || !programObject->isLinked())
michael@0 4052 {
michael@0 4053 return gl::error(GL_INVALID_OPERATION);
michael@0 4054 }
michael@0 4055
michael@0 4056 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
michael@0 4057 if (!programBinary)
michael@0 4058 {
michael@0 4059 return gl::error(GL_INVALID_OPERATION);
michael@0 4060 }
michael@0 4061
michael@0 4062 if (!programBinary->getUniformfv(location, NULL, params))
michael@0 4063 {
michael@0 4064 return gl::error(GL_INVALID_OPERATION);
michael@0 4065 }
michael@0 4066 }
michael@0 4067 }
michael@0 4068 catch(std::bad_alloc&)
michael@0 4069 {
michael@0 4070 return gl::error(GL_OUT_OF_MEMORY);
michael@0 4071 }
michael@0 4072 }
michael@0 4073
michael@0 4074 void __stdcall glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
michael@0 4075 {
michael@0 4076 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
michael@0 4077 program, location, bufSize, params);
michael@0 4078
michael@0 4079 try
michael@0 4080 {
michael@0 4081 if (bufSize < 0)
michael@0 4082 {
michael@0 4083 return gl::error(GL_INVALID_VALUE);
michael@0 4084 }
michael@0 4085
michael@0 4086 gl::Context *context = gl::getNonLostContext();
michael@0 4087
michael@0 4088 if (context)
michael@0 4089 {
michael@0 4090 if (program == 0)
michael@0 4091 {
michael@0 4092 return gl::error(GL_INVALID_VALUE);
michael@0 4093 }
michael@0 4094
michael@0 4095 gl::Program *programObject = context->getProgram(program);
michael@0 4096
michael@0 4097 if (!programObject || !programObject->isLinked())
michael@0 4098 {
michael@0 4099 return gl::error(GL_INVALID_OPERATION);
michael@0 4100 }
michael@0 4101
michael@0 4102 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
michael@0 4103 if (!programBinary)
michael@0 4104 {
michael@0 4105 return gl::error(GL_INVALID_OPERATION);
michael@0 4106 }
michael@0 4107
michael@0 4108 if (!programBinary->getUniformiv(location, &bufSize, params))
michael@0 4109 {
michael@0 4110 return gl::error(GL_INVALID_OPERATION);
michael@0 4111 }
michael@0 4112 }
michael@0 4113 }
michael@0 4114 catch(std::bad_alloc&)
michael@0 4115 {
michael@0 4116 return gl::error(GL_OUT_OF_MEMORY);
michael@0 4117 }
michael@0 4118 }
michael@0 4119
michael@0 4120 void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params)
michael@0 4121 {
michael@0 4122 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
michael@0 4123
michael@0 4124 try
michael@0 4125 {
michael@0 4126 gl::Context *context = gl::getNonLostContext();
michael@0 4127
michael@0 4128 if (context)
michael@0 4129 {
michael@0 4130 if (program == 0)
michael@0 4131 {
michael@0 4132 return gl::error(GL_INVALID_VALUE);
michael@0 4133 }
michael@0 4134
michael@0 4135 gl::Program *programObject = context->getProgram(program);
michael@0 4136
michael@0 4137 if (!programObject || !programObject->isLinked())
michael@0 4138 {
michael@0 4139 return gl::error(GL_INVALID_OPERATION);
michael@0 4140 }
michael@0 4141
michael@0 4142 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
michael@0 4143 if (!programBinary)
michael@0 4144 {
michael@0 4145 return gl::error(GL_INVALID_OPERATION);
michael@0 4146 }
michael@0 4147
michael@0 4148 if (!programBinary->getUniformiv(location, NULL, params))
michael@0 4149 {
michael@0 4150 return gl::error(GL_INVALID_OPERATION);
michael@0 4151 }
michael@0 4152 }
michael@0 4153 }
michael@0 4154 catch(std::bad_alloc&)
michael@0 4155 {
michael@0 4156 return gl::error(GL_OUT_OF_MEMORY);
michael@0 4157 }
michael@0 4158 }
michael@0 4159
michael@0 4160 int __stdcall glGetUniformLocation(GLuint program, const GLchar* name)
michael@0 4161 {
michael@0 4162 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
michael@0 4163
michael@0 4164 try
michael@0 4165 {
michael@0 4166 gl::Context *context = gl::getNonLostContext();
michael@0 4167
michael@0 4168 if (strstr(name, "gl_") == name)
michael@0 4169 {
michael@0 4170 return -1;
michael@0 4171 }
michael@0 4172
michael@0 4173 if (context)
michael@0 4174 {
michael@0 4175 gl::Program *programObject = context->getProgram(program);
michael@0 4176
michael@0 4177 if (!programObject)
michael@0 4178 {
michael@0 4179 if (context->getShader(program))
michael@0 4180 {
michael@0 4181 return gl::error(GL_INVALID_OPERATION, -1);
michael@0 4182 }
michael@0 4183 else
michael@0 4184 {
michael@0 4185 return gl::error(GL_INVALID_VALUE, -1);
michael@0 4186 }
michael@0 4187 }
michael@0 4188
michael@0 4189 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
michael@0 4190 if (!programObject->isLinked() || !programBinary)
michael@0 4191 {
michael@0 4192 return gl::error(GL_INVALID_OPERATION, -1);
michael@0 4193 }
michael@0 4194
michael@0 4195 return programBinary->getUniformLocation(name);
michael@0 4196 }
michael@0 4197 }
michael@0 4198 catch(std::bad_alloc&)
michael@0 4199 {
michael@0 4200 return gl::error(GL_OUT_OF_MEMORY, -1);
michael@0 4201 }
michael@0 4202
michael@0 4203 return -1;
michael@0 4204 }
michael@0 4205
michael@0 4206 void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
michael@0 4207 {
michael@0 4208 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
michael@0 4209
michael@0 4210 try
michael@0 4211 {
michael@0 4212 gl::Context *context = gl::getNonLostContext();
michael@0 4213
michael@0 4214 if (context)
michael@0 4215 {
michael@0 4216 if (index >= gl::MAX_VERTEX_ATTRIBS)
michael@0 4217 {
michael@0 4218 return gl::error(GL_INVALID_VALUE);
michael@0 4219 }
michael@0 4220
michael@0 4221 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
michael@0 4222
michael@0 4223 switch (pname)
michael@0 4224 {
michael@0 4225 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
michael@0 4226 *params = (GLfloat)(attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
michael@0 4227 break;
michael@0 4228 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
michael@0 4229 *params = (GLfloat)attribState.mSize;
michael@0 4230 break;
michael@0 4231 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
michael@0 4232 *params = (GLfloat)attribState.mStride;
michael@0 4233 break;
michael@0 4234 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
michael@0 4235 *params = (GLfloat)attribState.mType;
michael@0 4236 break;
michael@0 4237 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
michael@0 4238 *params = (GLfloat)(attribState.mNormalized ? GL_TRUE : GL_FALSE);
michael@0 4239 break;
michael@0 4240 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
michael@0 4241 *params = (GLfloat)attribState.mBoundBuffer.id();
michael@0 4242 break;
michael@0 4243 case GL_CURRENT_VERTEX_ATTRIB:
michael@0 4244 for (int i = 0; i < 4; ++i)
michael@0 4245 {
michael@0 4246 params[i] = attribState.mCurrentValue[i];
michael@0 4247 }
michael@0 4248 break;
michael@0 4249 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE:
michael@0 4250 *params = (GLfloat)attribState.mDivisor;
michael@0 4251 break;
michael@0 4252 default: return gl::error(GL_INVALID_ENUM);
michael@0 4253 }
michael@0 4254 }
michael@0 4255 }
michael@0 4256 catch(std::bad_alloc&)
michael@0 4257 {
michael@0 4258 return gl::error(GL_OUT_OF_MEMORY);
michael@0 4259 }
michael@0 4260 }
michael@0 4261
michael@0 4262 void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
michael@0 4263 {
michael@0 4264 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
michael@0 4265
michael@0 4266 try
michael@0 4267 {
michael@0 4268 gl::Context *context = gl::getNonLostContext();
michael@0 4269
michael@0 4270 if (context)
michael@0 4271 {
michael@0 4272 if (index >= gl::MAX_VERTEX_ATTRIBS)
michael@0 4273 {
michael@0 4274 return gl::error(GL_INVALID_VALUE);
michael@0 4275 }
michael@0 4276
michael@0 4277 const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
michael@0 4278
michael@0 4279 switch (pname)
michael@0 4280 {
michael@0 4281 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
michael@0 4282 *params = (attribState.mArrayEnabled ? GL_TRUE : GL_FALSE);
michael@0 4283 break;
michael@0 4284 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
michael@0 4285 *params = attribState.mSize;
michael@0 4286 break;
michael@0 4287 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
michael@0 4288 *params = attribState.mStride;
michael@0 4289 break;
michael@0 4290 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
michael@0 4291 *params = attribState.mType;
michael@0 4292 break;
michael@0 4293 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
michael@0 4294 *params = (attribState.mNormalized ? GL_TRUE : GL_FALSE);
michael@0 4295 break;
michael@0 4296 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
michael@0 4297 *params = attribState.mBoundBuffer.id();
michael@0 4298 break;
michael@0 4299 case GL_CURRENT_VERTEX_ATTRIB:
michael@0 4300 for (int i = 0; i < 4; ++i)
michael@0 4301 {
michael@0 4302 float currentValue = attribState.mCurrentValue[i];
michael@0 4303 params[i] = (GLint)(currentValue > 0.0f ? floor(currentValue + 0.5f) : ceil(currentValue - 0.5f));
michael@0 4304 }
michael@0 4305 break;
michael@0 4306 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE:
michael@0 4307 *params = (GLint)attribState.mDivisor;
michael@0 4308 break;
michael@0 4309 default: return gl::error(GL_INVALID_ENUM);
michael@0 4310 }
michael@0 4311 }
michael@0 4312 }
michael@0 4313 catch(std::bad_alloc&)
michael@0 4314 {
michael@0 4315 return gl::error(GL_OUT_OF_MEMORY);
michael@0 4316 }
michael@0 4317 }
michael@0 4318
michael@0 4319 void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
michael@0 4320 {
michael@0 4321 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
michael@0 4322
michael@0 4323 try
michael@0 4324 {
michael@0 4325 gl::Context *context = gl::getNonLostContext();
michael@0 4326
michael@0 4327 if (context)
michael@0 4328 {
michael@0 4329 if (index >= gl::MAX_VERTEX_ATTRIBS)
michael@0 4330 {
michael@0 4331 return gl::error(GL_INVALID_VALUE);
michael@0 4332 }
michael@0 4333
michael@0 4334 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
michael@0 4335 {
michael@0 4336 return gl::error(GL_INVALID_ENUM);
michael@0 4337 }
michael@0 4338
michael@0 4339 *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
michael@0 4340 }
michael@0 4341 }
michael@0 4342 catch(std::bad_alloc&)
michael@0 4343 {
michael@0 4344 return gl::error(GL_OUT_OF_MEMORY);
michael@0 4345 }
michael@0 4346 }
michael@0 4347
michael@0 4348 void __stdcall glHint(GLenum target, GLenum mode)
michael@0 4349 {
michael@0 4350 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
michael@0 4351
michael@0 4352 try
michael@0 4353 {
michael@0 4354 switch (mode)
michael@0 4355 {
michael@0 4356 case GL_FASTEST:
michael@0 4357 case GL_NICEST:
michael@0 4358 case GL_DONT_CARE:
michael@0 4359 break;
michael@0 4360 default:
michael@0 4361 return gl::error(GL_INVALID_ENUM);
michael@0 4362 }
michael@0 4363
michael@0 4364 gl::Context *context = gl::getNonLostContext();
michael@0 4365 switch (target)
michael@0 4366 {
michael@0 4367 case GL_GENERATE_MIPMAP_HINT:
michael@0 4368 if (context) context->setGenerateMipmapHint(mode);
michael@0 4369 break;
michael@0 4370 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
michael@0 4371 if (context) context->setFragmentShaderDerivativeHint(mode);
michael@0 4372 break;
michael@0 4373 default:
michael@0 4374 return gl::error(GL_INVALID_ENUM);
michael@0 4375 }
michael@0 4376 }
michael@0 4377 catch(std::bad_alloc&)
michael@0 4378 {
michael@0 4379 return gl::error(GL_OUT_OF_MEMORY);
michael@0 4380 }
michael@0 4381 }
michael@0 4382
michael@0 4383 GLboolean __stdcall glIsBuffer(GLuint buffer)
michael@0 4384 {
michael@0 4385 EVENT("(GLuint buffer = %d)", buffer);
michael@0 4386
michael@0 4387 try
michael@0 4388 {
michael@0 4389 gl::Context *context = gl::getNonLostContext();
michael@0 4390
michael@0 4391 if (context && buffer)
michael@0 4392 {
michael@0 4393 gl::Buffer *bufferObject = context->getBuffer(buffer);
michael@0 4394
michael@0 4395 if (bufferObject)
michael@0 4396 {
michael@0 4397 return GL_TRUE;
michael@0 4398 }
michael@0 4399 }
michael@0 4400 }
michael@0 4401 catch(std::bad_alloc&)
michael@0 4402 {
michael@0 4403 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
michael@0 4404 }
michael@0 4405
michael@0 4406 return GL_FALSE;
michael@0 4407 }
michael@0 4408
michael@0 4409 GLboolean __stdcall glIsEnabled(GLenum cap)
michael@0 4410 {
michael@0 4411 EVENT("(GLenum cap = 0x%X)", cap);
michael@0 4412
michael@0 4413 try
michael@0 4414 {
michael@0 4415 gl::Context *context = gl::getNonLostContext();
michael@0 4416
michael@0 4417 if (context)
michael@0 4418 {
michael@0 4419 switch (cap)
michael@0 4420 {
michael@0 4421 case GL_CULL_FACE: return context->isCullFaceEnabled();
michael@0 4422 case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled();
michael@0 4423 case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled();
michael@0 4424 case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled();
michael@0 4425 case GL_SCISSOR_TEST: return context->isScissorTestEnabled();
michael@0 4426 case GL_STENCIL_TEST: return context->isStencilTestEnabled();
michael@0 4427 case GL_DEPTH_TEST: return context->isDepthTestEnabled();
michael@0 4428 case GL_BLEND: return context->isBlendEnabled();
michael@0 4429 case GL_DITHER: return context->isDitherEnabled();
michael@0 4430 default:
michael@0 4431 return gl::error(GL_INVALID_ENUM, false);
michael@0 4432 }
michael@0 4433 }
michael@0 4434 }
michael@0 4435 catch(std::bad_alloc&)
michael@0 4436 {
michael@0 4437 return gl::error(GL_OUT_OF_MEMORY, false);
michael@0 4438 }
michael@0 4439
michael@0 4440 return false;
michael@0 4441 }
michael@0 4442
michael@0 4443 GLboolean __stdcall glIsFenceNV(GLuint fence)
michael@0 4444 {
michael@0 4445 EVENT("(GLuint fence = %d)", fence);
michael@0 4446
michael@0 4447 try
michael@0 4448 {
michael@0 4449 gl::Context *context = gl::getNonLostContext();
michael@0 4450
michael@0 4451 if (context)
michael@0 4452 {
michael@0 4453 gl::Fence *fenceObject = context->getFence(fence);
michael@0 4454
michael@0 4455 if (fenceObject == NULL)
michael@0 4456 {
michael@0 4457 return GL_FALSE;
michael@0 4458 }
michael@0 4459
michael@0 4460 return fenceObject->isFence();
michael@0 4461 }
michael@0 4462 }
michael@0 4463 catch(std::bad_alloc&)
michael@0 4464 {
michael@0 4465 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
michael@0 4466 }
michael@0 4467
michael@0 4468 return GL_FALSE;
michael@0 4469 }
michael@0 4470
michael@0 4471 GLboolean __stdcall glIsFramebuffer(GLuint framebuffer)
michael@0 4472 {
michael@0 4473 EVENT("(GLuint framebuffer = %d)", framebuffer);
michael@0 4474
michael@0 4475 try
michael@0 4476 {
michael@0 4477 gl::Context *context = gl::getNonLostContext();
michael@0 4478
michael@0 4479 if (context && framebuffer)
michael@0 4480 {
michael@0 4481 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
michael@0 4482
michael@0 4483 if (framebufferObject)
michael@0 4484 {
michael@0 4485 return GL_TRUE;
michael@0 4486 }
michael@0 4487 }
michael@0 4488 }
michael@0 4489 catch(std::bad_alloc&)
michael@0 4490 {
michael@0 4491 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
michael@0 4492 }
michael@0 4493
michael@0 4494 return GL_FALSE;
michael@0 4495 }
michael@0 4496
michael@0 4497 GLboolean __stdcall glIsProgram(GLuint program)
michael@0 4498 {
michael@0 4499 EVENT("(GLuint program = %d)", program);
michael@0 4500
michael@0 4501 try
michael@0 4502 {
michael@0 4503 gl::Context *context = gl::getNonLostContext();
michael@0 4504
michael@0 4505 if (context && program)
michael@0 4506 {
michael@0 4507 gl::Program *programObject = context->getProgram(program);
michael@0 4508
michael@0 4509 if (programObject)
michael@0 4510 {
michael@0 4511 return GL_TRUE;
michael@0 4512 }
michael@0 4513 }
michael@0 4514 }
michael@0 4515 catch(std::bad_alloc&)
michael@0 4516 {
michael@0 4517 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
michael@0 4518 }
michael@0 4519
michael@0 4520 return GL_FALSE;
michael@0 4521 }
michael@0 4522
michael@0 4523 GLboolean __stdcall glIsQueryEXT(GLuint id)
michael@0 4524 {
michael@0 4525 EVENT("(GLuint id = %d)", id);
michael@0 4526
michael@0 4527 try
michael@0 4528 {
michael@0 4529 if (id == 0)
michael@0 4530 {
michael@0 4531 return GL_FALSE;
michael@0 4532 }
michael@0 4533
michael@0 4534 gl::Context *context = gl::getNonLostContext();
michael@0 4535
michael@0 4536 if (context)
michael@0 4537 {
michael@0 4538 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
michael@0 4539
michael@0 4540 if (queryObject)
michael@0 4541 {
michael@0 4542 return GL_TRUE;
michael@0 4543 }
michael@0 4544 }
michael@0 4545 }
michael@0 4546 catch(std::bad_alloc&)
michael@0 4547 {
michael@0 4548 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
michael@0 4549 }
michael@0 4550
michael@0 4551 return GL_FALSE;
michael@0 4552 }
michael@0 4553
michael@0 4554 GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
michael@0 4555 {
michael@0 4556 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
michael@0 4557
michael@0 4558 try
michael@0 4559 {
michael@0 4560 gl::Context *context = gl::getNonLostContext();
michael@0 4561
michael@0 4562 if (context && renderbuffer)
michael@0 4563 {
michael@0 4564 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
michael@0 4565
michael@0 4566 if (renderbufferObject)
michael@0 4567 {
michael@0 4568 return GL_TRUE;
michael@0 4569 }
michael@0 4570 }
michael@0 4571 }
michael@0 4572 catch(std::bad_alloc&)
michael@0 4573 {
michael@0 4574 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
michael@0 4575 }
michael@0 4576
michael@0 4577 return GL_FALSE;
michael@0 4578 }
michael@0 4579
michael@0 4580 GLboolean __stdcall glIsShader(GLuint shader)
michael@0 4581 {
michael@0 4582 EVENT("(GLuint shader = %d)", shader);
michael@0 4583
michael@0 4584 try
michael@0 4585 {
michael@0 4586 gl::Context *context = gl::getNonLostContext();
michael@0 4587
michael@0 4588 if (context && shader)
michael@0 4589 {
michael@0 4590 gl::Shader *shaderObject = context->getShader(shader);
michael@0 4591
michael@0 4592 if (shaderObject)
michael@0 4593 {
michael@0 4594 return GL_TRUE;
michael@0 4595 }
michael@0 4596 }
michael@0 4597 }
michael@0 4598 catch(std::bad_alloc&)
michael@0 4599 {
michael@0 4600 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
michael@0 4601 }
michael@0 4602
michael@0 4603 return GL_FALSE;
michael@0 4604 }
michael@0 4605
michael@0 4606 GLboolean __stdcall glIsTexture(GLuint texture)
michael@0 4607 {
michael@0 4608 EVENT("(GLuint texture = %d)", texture);
michael@0 4609
michael@0 4610 try
michael@0 4611 {
michael@0 4612 gl::Context *context = gl::getNonLostContext();
michael@0 4613
michael@0 4614 if (context && texture)
michael@0 4615 {
michael@0 4616 gl::Texture *textureObject = context->getTexture(texture);
michael@0 4617
michael@0 4618 if (textureObject)
michael@0 4619 {
michael@0 4620 return GL_TRUE;
michael@0 4621 }
michael@0 4622 }
michael@0 4623 }
michael@0 4624 catch(std::bad_alloc&)
michael@0 4625 {
michael@0 4626 return gl::error(GL_OUT_OF_MEMORY, GL_FALSE);
michael@0 4627 }
michael@0 4628
michael@0 4629 return GL_FALSE;
michael@0 4630 }
michael@0 4631
michael@0 4632 void __stdcall glLineWidth(GLfloat width)
michael@0 4633 {
michael@0 4634 EVENT("(GLfloat width = %f)", width);
michael@0 4635
michael@0 4636 try
michael@0 4637 {
michael@0 4638 if (width <= 0.0f)
michael@0 4639 {
michael@0 4640 return gl::error(GL_INVALID_VALUE);
michael@0 4641 }
michael@0 4642
michael@0 4643 gl::Context *context = gl::getNonLostContext();
michael@0 4644
michael@0 4645 if (context)
michael@0 4646 {
michael@0 4647 context->setLineWidth(width);
michael@0 4648 }
michael@0 4649 }
michael@0 4650 catch(std::bad_alloc&)
michael@0 4651 {
michael@0 4652 return gl::error(GL_OUT_OF_MEMORY);
michael@0 4653 }
michael@0 4654 }
michael@0 4655
michael@0 4656 void __stdcall glLinkProgram(GLuint program)
michael@0 4657 {
michael@0 4658 EVENT("(GLuint program = %d)", program);
michael@0 4659
michael@0 4660 try
michael@0 4661 {
michael@0 4662 gl::Context *context = gl::getNonLostContext();
michael@0 4663
michael@0 4664 if (context)
michael@0 4665 {
michael@0 4666 gl::Program *programObject = context->getProgram(program);
michael@0 4667
michael@0 4668 if (!programObject)
michael@0 4669 {
michael@0 4670 if (context->getShader(program))
michael@0 4671 {
michael@0 4672 return gl::error(GL_INVALID_OPERATION);
michael@0 4673 }
michael@0 4674 else
michael@0 4675 {
michael@0 4676 return gl::error(GL_INVALID_VALUE);
michael@0 4677 }
michael@0 4678 }
michael@0 4679
michael@0 4680 context->linkProgram(program);
michael@0 4681 }
michael@0 4682 }
michael@0 4683 catch(std::bad_alloc&)
michael@0 4684 {
michael@0 4685 return gl::error(GL_OUT_OF_MEMORY);
michael@0 4686 }
michael@0 4687 }
michael@0 4688
michael@0 4689 void __stdcall glPixelStorei(GLenum pname, GLint param)
michael@0 4690 {
michael@0 4691 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
michael@0 4692
michael@0 4693 try
michael@0 4694 {
michael@0 4695 gl::Context *context = gl::getNonLostContext();
michael@0 4696
michael@0 4697 if (context)
michael@0 4698 {
michael@0 4699 switch (pname)
michael@0 4700 {
michael@0 4701 case GL_UNPACK_ALIGNMENT:
michael@0 4702 if (param != 1 && param != 2 && param != 4 && param != 8)
michael@0 4703 {
michael@0 4704 return gl::error(GL_INVALID_VALUE);
michael@0 4705 }
michael@0 4706
michael@0 4707 context->setUnpackAlignment(param);
michael@0 4708 break;
michael@0 4709
michael@0 4710 case GL_PACK_ALIGNMENT:
michael@0 4711 if (param != 1 && param != 2 && param != 4 && param != 8)
michael@0 4712 {
michael@0 4713 return gl::error(GL_INVALID_VALUE);
michael@0 4714 }
michael@0 4715
michael@0 4716 context->setPackAlignment(param);
michael@0 4717 break;
michael@0 4718
michael@0 4719 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
michael@0 4720 context->setPackReverseRowOrder(param != 0);
michael@0 4721 break;
michael@0 4722
michael@0 4723 default:
michael@0 4724 return gl::error(GL_INVALID_ENUM);
michael@0 4725 }
michael@0 4726 }
michael@0 4727 }
michael@0 4728 catch(std::bad_alloc&)
michael@0 4729 {
michael@0 4730 return gl::error(GL_OUT_OF_MEMORY);
michael@0 4731 }
michael@0 4732 }
michael@0 4733
michael@0 4734 void __stdcall glPolygonOffset(GLfloat factor, GLfloat units)
michael@0 4735 {
michael@0 4736 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
michael@0 4737
michael@0 4738 try
michael@0 4739 {
michael@0 4740 gl::Context *context = gl::getNonLostContext();
michael@0 4741
michael@0 4742 if (context)
michael@0 4743 {
michael@0 4744 context->setPolygonOffsetParams(factor, units);
michael@0 4745 }
michael@0 4746 }
michael@0 4747 catch(std::bad_alloc&)
michael@0 4748 {
michael@0 4749 return gl::error(GL_OUT_OF_MEMORY);
michael@0 4750 }
michael@0 4751 }
michael@0 4752
michael@0 4753 void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
michael@0 4754 GLenum format, GLenum type, GLsizei bufSize,
michael@0 4755 GLvoid *data)
michael@0 4756 {
michael@0 4757 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
michael@0 4758 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
michael@0 4759 x, y, width, height, format, type, bufSize, data);
michael@0 4760
michael@0 4761 try
michael@0 4762 {
michael@0 4763 if (width < 0 || height < 0 || bufSize < 0)
michael@0 4764 {
michael@0 4765 return gl::error(GL_INVALID_VALUE);
michael@0 4766 }
michael@0 4767
michael@0 4768 gl::Context *context = gl::getNonLostContext();
michael@0 4769
michael@0 4770 if (context)
michael@0 4771 {
michael@0 4772 GLenum currentFormat, currentType;
michael@0 4773
michael@0 4774 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
michael@0 4775 // and attempting to read back if that's the case is an error. The error will be registered
michael@0 4776 // by getCurrentReadFormat.
michael@0 4777 if (!context->getCurrentReadFormatType(&currentFormat, &currentType))
michael@0 4778 return;
michael@0 4779
michael@0 4780 if (!(currentFormat == format && currentType == type) && !validReadFormatType(format, type))
michael@0 4781 {
michael@0 4782 return gl::error(GL_INVALID_OPERATION);
michael@0 4783 }
michael@0 4784
michael@0 4785 context->readPixels(x, y, width, height, format, type, &bufSize, data);
michael@0 4786 }
michael@0 4787 }
michael@0 4788 catch(std::bad_alloc&)
michael@0 4789 {
michael@0 4790 return gl::error(GL_OUT_OF_MEMORY);
michael@0 4791 }
michael@0 4792 }
michael@0 4793
michael@0 4794 void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
michael@0 4795 GLenum format, GLenum type, GLvoid* pixels)
michael@0 4796 {
michael@0 4797 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
michael@0 4798 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
michael@0 4799 x, y, width, height, format, type, pixels);
michael@0 4800
michael@0 4801 try
michael@0 4802 {
michael@0 4803 if (width < 0 || height < 0)
michael@0 4804 {
michael@0 4805 return gl::error(GL_INVALID_VALUE);
michael@0 4806 }
michael@0 4807
michael@0 4808 gl::Context *context = gl::getNonLostContext();
michael@0 4809
michael@0 4810 if (context)
michael@0 4811 {
michael@0 4812 GLenum currentFormat, currentType;
michael@0 4813
michael@0 4814 // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
michael@0 4815 // and attempting to read back if that's the case is an error. The error will be registered
michael@0 4816 // by getCurrentReadFormat.
michael@0 4817 if (!context->getCurrentReadFormatType(&currentFormat, &currentType))
michael@0 4818 return;
michael@0 4819
michael@0 4820 if (!(currentFormat == format && currentType == type) && !validReadFormatType(format, type))
michael@0 4821 {
michael@0 4822 return gl::error(GL_INVALID_OPERATION);
michael@0 4823 }
michael@0 4824
michael@0 4825 context->readPixels(x, y, width, height, format, type, NULL, pixels);
michael@0 4826 }
michael@0 4827 }
michael@0 4828 catch(std::bad_alloc&)
michael@0 4829 {
michael@0 4830 return gl::error(GL_OUT_OF_MEMORY);
michael@0 4831 }
michael@0 4832 }
michael@0 4833
michael@0 4834 void __stdcall glReleaseShaderCompiler(void)
michael@0 4835 {
michael@0 4836 EVENT("()");
michael@0 4837
michael@0 4838 try
michael@0 4839 {
michael@0 4840 gl::Shader::releaseCompiler();
michael@0 4841 }
michael@0 4842 catch(std::bad_alloc&)
michael@0 4843 {
michael@0 4844 return gl::error(GL_OUT_OF_MEMORY);
michael@0 4845 }
michael@0 4846 }
michael@0 4847
michael@0 4848 void __stdcall glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
michael@0 4849 {
michael@0 4850 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
michael@0 4851 target, samples, internalformat, width, height);
michael@0 4852
michael@0 4853 try
michael@0 4854 {
michael@0 4855 switch (target)
michael@0 4856 {
michael@0 4857 case GL_RENDERBUFFER:
michael@0 4858 break;
michael@0 4859 default:
michael@0 4860 return gl::error(GL_INVALID_ENUM);
michael@0 4861 }
michael@0 4862
michael@0 4863 if (!gl::IsColorRenderable(internalformat) && !gl::IsDepthRenderable(internalformat) && !gl::IsStencilRenderable(internalformat))
michael@0 4864 {
michael@0 4865 return gl::error(GL_INVALID_ENUM);
michael@0 4866 }
michael@0 4867
michael@0 4868 if (width < 0 || height < 0 || samples < 0)
michael@0 4869 {
michael@0 4870 return gl::error(GL_INVALID_VALUE);
michael@0 4871 }
michael@0 4872
michael@0 4873 gl::Context *context = gl::getNonLostContext();
michael@0 4874
michael@0 4875 if (context)
michael@0 4876 {
michael@0 4877 if (width > context->getMaximumRenderbufferDimension() ||
michael@0 4878 height > context->getMaximumRenderbufferDimension() ||
michael@0 4879 samples > context->getMaxSupportedSamples())
michael@0 4880 {
michael@0 4881 return gl::error(GL_INVALID_VALUE);
michael@0 4882 }
michael@0 4883
michael@0 4884 GLuint handle = context->getRenderbufferHandle();
michael@0 4885 if (handle == 0)
michael@0 4886 {
michael@0 4887 return gl::error(GL_INVALID_OPERATION);
michael@0 4888 }
michael@0 4889
michael@0 4890 switch (internalformat)
michael@0 4891 {
michael@0 4892 case GL_DEPTH_COMPONENT16:
michael@0 4893 case GL_RGBA4:
michael@0 4894 case GL_RGB5_A1:
michael@0 4895 case GL_RGB565:
michael@0 4896 case GL_RGB8_OES:
michael@0 4897 case GL_RGBA8_OES:
michael@0 4898 case GL_STENCIL_INDEX8:
michael@0 4899 case GL_DEPTH24_STENCIL8_OES:
michael@0 4900 context->setRenderbufferStorage(width, height, internalformat, samples);
michael@0 4901 break;
michael@0 4902 default:
michael@0 4903 return gl::error(GL_INVALID_ENUM);
michael@0 4904 }
michael@0 4905 }
michael@0 4906 }
michael@0 4907 catch(std::bad_alloc&)
michael@0 4908 {
michael@0 4909 return gl::error(GL_OUT_OF_MEMORY);
michael@0 4910 }
michael@0 4911 }
michael@0 4912
michael@0 4913 void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
michael@0 4914 {
michael@0 4915 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
michael@0 4916 }
michael@0 4917
michael@0 4918 void __stdcall glSampleCoverage(GLclampf value, GLboolean invert)
michael@0 4919 {
michael@0 4920 EVENT("(GLclampf value = %f, GLboolean invert = %d)", value, invert);
michael@0 4921
michael@0 4922 try
michael@0 4923 {
michael@0 4924 gl::Context* context = gl::getNonLostContext();
michael@0 4925
michael@0 4926 if (context)
michael@0 4927 {
michael@0 4928 context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
michael@0 4929 }
michael@0 4930 }
michael@0 4931 catch(std::bad_alloc&)
michael@0 4932 {
michael@0 4933 return gl::error(GL_OUT_OF_MEMORY);
michael@0 4934 }
michael@0 4935 }
michael@0 4936
michael@0 4937 void __stdcall glSetFenceNV(GLuint fence, GLenum condition)
michael@0 4938 {
michael@0 4939 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
michael@0 4940
michael@0 4941 try
michael@0 4942 {
michael@0 4943 if (condition != GL_ALL_COMPLETED_NV)
michael@0 4944 {
michael@0 4945 return gl::error(GL_INVALID_ENUM);
michael@0 4946 }
michael@0 4947
michael@0 4948 gl::Context *context = gl::getNonLostContext();
michael@0 4949
michael@0 4950 if (context)
michael@0 4951 {
michael@0 4952 gl::Fence *fenceObject = context->getFence(fence);
michael@0 4953
michael@0 4954 if (fenceObject == NULL)
michael@0 4955 {
michael@0 4956 return gl::error(GL_INVALID_OPERATION);
michael@0 4957 }
michael@0 4958
michael@0 4959 fenceObject->setFence(condition);
michael@0 4960 }
michael@0 4961 }
michael@0 4962 catch(std::bad_alloc&)
michael@0 4963 {
michael@0 4964 return gl::error(GL_OUT_OF_MEMORY);
michael@0 4965 }
michael@0 4966 }
michael@0 4967
michael@0 4968 void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
michael@0 4969 {
michael@0 4970 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)", x, y, width, height);
michael@0 4971
michael@0 4972 try
michael@0 4973 {
michael@0 4974 if (width < 0 || height < 0)
michael@0 4975 {
michael@0 4976 return gl::error(GL_INVALID_VALUE);
michael@0 4977 }
michael@0 4978
michael@0 4979 gl::Context* context = gl::getNonLostContext();
michael@0 4980
michael@0 4981 if (context)
michael@0 4982 {
michael@0 4983 context->setScissorParams(x, y, width, height);
michael@0 4984 }
michael@0 4985 }
michael@0 4986 catch(std::bad_alloc&)
michael@0 4987 {
michael@0 4988 return gl::error(GL_OUT_OF_MEMORY);
michael@0 4989 }
michael@0 4990 }
michael@0 4991
michael@0 4992 void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
michael@0 4993 {
michael@0 4994 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
michael@0 4995 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
michael@0 4996 n, shaders, binaryformat, binary, length);
michael@0 4997
michael@0 4998 try
michael@0 4999 {
michael@0 5000 // No binary shader formats are supported.
michael@0 5001 return gl::error(GL_INVALID_ENUM);
michael@0 5002 }
michael@0 5003 catch(std::bad_alloc&)
michael@0 5004 {
michael@0 5005 return gl::error(GL_OUT_OF_MEMORY);
michael@0 5006 }
michael@0 5007 }
michael@0 5008
michael@0 5009 void __stdcall glShaderSource(GLuint shader, GLsizei count, const GLchar** string, const GLint* length)
michael@0 5010 {
michael@0 5011 EVENT("(GLuint shader = %d, GLsizei count = %d, const GLchar** string = 0x%0.8p, const GLint* length = 0x%0.8p)",
michael@0 5012 shader, count, string, length);
michael@0 5013
michael@0 5014 try
michael@0 5015 {
michael@0 5016 if (count < 0)
michael@0 5017 {
michael@0 5018 return gl::error(GL_INVALID_VALUE);
michael@0 5019 }
michael@0 5020
michael@0 5021 gl::Context *context = gl::getNonLostContext();
michael@0 5022
michael@0 5023 if (context)
michael@0 5024 {
michael@0 5025 gl::Shader *shaderObject = context->getShader(shader);
michael@0 5026
michael@0 5027 if (!shaderObject)
michael@0 5028 {
michael@0 5029 if (context->getProgram(shader))
michael@0 5030 {
michael@0 5031 return gl::error(GL_INVALID_OPERATION);
michael@0 5032 }
michael@0 5033 else
michael@0 5034 {
michael@0 5035 return gl::error(GL_INVALID_VALUE);
michael@0 5036 }
michael@0 5037 }
michael@0 5038
michael@0 5039 shaderObject->setSource(count, string, length);
michael@0 5040 }
michael@0 5041 }
michael@0 5042 catch(std::bad_alloc&)
michael@0 5043 {
michael@0 5044 return gl::error(GL_OUT_OF_MEMORY);
michael@0 5045 }
michael@0 5046 }
michael@0 5047
michael@0 5048 void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask)
michael@0 5049 {
michael@0 5050 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
michael@0 5051 }
michael@0 5052
michael@0 5053 void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
michael@0 5054 {
michael@0 5055 EVENT("(GLenum face = 0x%X, GLenum func = 0x%X, GLint ref = %d, GLuint mask = %d)", face, func, ref, mask);
michael@0 5056
michael@0 5057 try
michael@0 5058 {
michael@0 5059 switch (face)
michael@0 5060 {
michael@0 5061 case GL_FRONT:
michael@0 5062 case GL_BACK:
michael@0 5063 case GL_FRONT_AND_BACK:
michael@0 5064 break;
michael@0 5065 default:
michael@0 5066 return gl::error(GL_INVALID_ENUM);
michael@0 5067 }
michael@0 5068
michael@0 5069 switch (func)
michael@0 5070 {
michael@0 5071 case GL_NEVER:
michael@0 5072 case GL_ALWAYS:
michael@0 5073 case GL_LESS:
michael@0 5074 case GL_LEQUAL:
michael@0 5075 case GL_EQUAL:
michael@0 5076 case GL_GEQUAL:
michael@0 5077 case GL_GREATER:
michael@0 5078 case GL_NOTEQUAL:
michael@0 5079 break;
michael@0 5080 default:
michael@0 5081 return gl::error(GL_INVALID_ENUM);
michael@0 5082 }
michael@0 5083
michael@0 5084 gl::Context *context = gl::getNonLostContext();
michael@0 5085
michael@0 5086 if (context)
michael@0 5087 {
michael@0 5088 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
michael@0 5089 {
michael@0 5090 context->setStencilParams(func, ref, mask);
michael@0 5091 }
michael@0 5092
michael@0 5093 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
michael@0 5094 {
michael@0 5095 context->setStencilBackParams(func, ref, mask);
michael@0 5096 }
michael@0 5097 }
michael@0 5098 }
michael@0 5099 catch(std::bad_alloc&)
michael@0 5100 {
michael@0 5101 return gl::error(GL_OUT_OF_MEMORY);
michael@0 5102 }
michael@0 5103 }
michael@0 5104
michael@0 5105 void __stdcall glStencilMask(GLuint mask)
michael@0 5106 {
michael@0 5107 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
michael@0 5108 }
michael@0 5109
michael@0 5110 void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask)
michael@0 5111 {
michael@0 5112 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
michael@0 5113
michael@0 5114 try
michael@0 5115 {
michael@0 5116 switch (face)
michael@0 5117 {
michael@0 5118 case GL_FRONT:
michael@0 5119 case GL_BACK:
michael@0 5120 case GL_FRONT_AND_BACK:
michael@0 5121 break;
michael@0 5122 default:
michael@0 5123 return gl::error(GL_INVALID_ENUM);
michael@0 5124 }
michael@0 5125
michael@0 5126 gl::Context *context = gl::getNonLostContext();
michael@0 5127
michael@0 5128 if (context)
michael@0 5129 {
michael@0 5130 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
michael@0 5131 {
michael@0 5132 context->setStencilWritemask(mask);
michael@0 5133 }
michael@0 5134
michael@0 5135 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
michael@0 5136 {
michael@0 5137 context->setStencilBackWritemask(mask);
michael@0 5138 }
michael@0 5139 }
michael@0 5140 }
michael@0 5141 catch(std::bad_alloc&)
michael@0 5142 {
michael@0 5143 return gl::error(GL_OUT_OF_MEMORY);
michael@0 5144 }
michael@0 5145 }
michael@0 5146
michael@0 5147 void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
michael@0 5148 {
michael@0 5149 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
michael@0 5150 }
michael@0 5151
michael@0 5152 void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
michael@0 5153 {
michael@0 5154 EVENT("(GLenum face = 0x%X, GLenum fail = 0x%X, GLenum zfail = 0x%X, GLenum zpas = 0x%Xs)",
michael@0 5155 face, fail, zfail, zpass);
michael@0 5156
michael@0 5157 try
michael@0 5158 {
michael@0 5159 switch (face)
michael@0 5160 {
michael@0 5161 case GL_FRONT:
michael@0 5162 case GL_BACK:
michael@0 5163 case GL_FRONT_AND_BACK:
michael@0 5164 break;
michael@0 5165 default:
michael@0 5166 return gl::error(GL_INVALID_ENUM);
michael@0 5167 }
michael@0 5168
michael@0 5169 switch (fail)
michael@0 5170 {
michael@0 5171 case GL_ZERO:
michael@0 5172 case GL_KEEP:
michael@0 5173 case GL_REPLACE:
michael@0 5174 case GL_INCR:
michael@0 5175 case GL_DECR:
michael@0 5176 case GL_INVERT:
michael@0 5177 case GL_INCR_WRAP:
michael@0 5178 case GL_DECR_WRAP:
michael@0 5179 break;
michael@0 5180 default:
michael@0 5181 return gl::error(GL_INVALID_ENUM);
michael@0 5182 }
michael@0 5183
michael@0 5184 switch (zfail)
michael@0 5185 {
michael@0 5186 case GL_ZERO:
michael@0 5187 case GL_KEEP:
michael@0 5188 case GL_REPLACE:
michael@0 5189 case GL_INCR:
michael@0 5190 case GL_DECR:
michael@0 5191 case GL_INVERT:
michael@0 5192 case GL_INCR_WRAP:
michael@0 5193 case GL_DECR_WRAP:
michael@0 5194 break;
michael@0 5195 default:
michael@0 5196 return gl::error(GL_INVALID_ENUM);
michael@0 5197 }
michael@0 5198
michael@0 5199 switch (zpass)
michael@0 5200 {
michael@0 5201 case GL_ZERO:
michael@0 5202 case GL_KEEP:
michael@0 5203 case GL_REPLACE:
michael@0 5204 case GL_INCR:
michael@0 5205 case GL_DECR:
michael@0 5206 case GL_INVERT:
michael@0 5207 case GL_INCR_WRAP:
michael@0 5208 case GL_DECR_WRAP:
michael@0 5209 break;
michael@0 5210 default:
michael@0 5211 return gl::error(GL_INVALID_ENUM);
michael@0 5212 }
michael@0 5213
michael@0 5214 gl::Context *context = gl::getNonLostContext();
michael@0 5215
michael@0 5216 if (context)
michael@0 5217 {
michael@0 5218 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
michael@0 5219 {
michael@0 5220 context->setStencilOperations(fail, zfail, zpass);
michael@0 5221 }
michael@0 5222
michael@0 5223 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
michael@0 5224 {
michael@0 5225 context->setStencilBackOperations(fail, zfail, zpass);
michael@0 5226 }
michael@0 5227 }
michael@0 5228 }
michael@0 5229 catch(std::bad_alloc&)
michael@0 5230 {
michael@0 5231 return gl::error(GL_OUT_OF_MEMORY);
michael@0 5232 }
michael@0 5233 }
michael@0 5234
michael@0 5235 GLboolean __stdcall glTestFenceNV(GLuint fence)
michael@0 5236 {
michael@0 5237 EVENT("(GLuint fence = %d)", fence);
michael@0 5238
michael@0 5239 try
michael@0 5240 {
michael@0 5241 gl::Context *context = gl::getNonLostContext();
michael@0 5242
michael@0 5243 if (context)
michael@0 5244 {
michael@0 5245 gl::Fence *fenceObject = context->getFence(fence);
michael@0 5246
michael@0 5247 if (fenceObject == NULL)
michael@0 5248 {
michael@0 5249 return gl::error(GL_INVALID_OPERATION, GL_TRUE);
michael@0 5250 }
michael@0 5251
michael@0 5252 return fenceObject->testFence();
michael@0 5253 }
michael@0 5254 }
michael@0 5255 catch(std::bad_alloc&)
michael@0 5256 {
michael@0 5257 gl::error(GL_OUT_OF_MEMORY);
michael@0 5258 }
michael@0 5259
michael@0 5260 return GL_TRUE;
michael@0 5261 }
michael@0 5262
michael@0 5263 void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
michael@0 5264 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
michael@0 5265 {
michael@0 5266 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
michael@0 5267 "GLint border = %d, GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
michael@0 5268 target, level, internalformat, width, height, border, format, type, pixels);
michael@0 5269
michael@0 5270 try
michael@0 5271 {
michael@0 5272 if (!validImageSize(level, width, height))
michael@0 5273 {
michael@0 5274 return gl::error(GL_INVALID_VALUE);
michael@0 5275 }
michael@0 5276
michael@0 5277 if (internalformat != GLint(format))
michael@0 5278 {
michael@0 5279 return gl::error(GL_INVALID_OPERATION);
michael@0 5280 }
michael@0 5281
michael@0 5282 // validate <type> by itself (used as secondary key below)
michael@0 5283 switch (type)
michael@0 5284 {
michael@0 5285 case GL_UNSIGNED_BYTE:
michael@0 5286 case GL_UNSIGNED_SHORT_5_6_5:
michael@0 5287 case GL_UNSIGNED_SHORT_4_4_4_4:
michael@0 5288 case GL_UNSIGNED_SHORT_5_5_5_1:
michael@0 5289 case GL_UNSIGNED_SHORT:
michael@0 5290 case GL_UNSIGNED_INT:
michael@0 5291 case GL_UNSIGNED_INT_24_8_OES:
michael@0 5292 case GL_HALF_FLOAT_OES:
michael@0 5293 case GL_FLOAT:
michael@0 5294 break;
michael@0 5295 default:
michael@0 5296 return gl::error(GL_INVALID_ENUM);
michael@0 5297 }
michael@0 5298
michael@0 5299 // validate <format> + <type> combinations
michael@0 5300 // - invalid <format> -> sets INVALID_ENUM
michael@0 5301 // - invalid <format>+<type> combination -> sets INVALID_OPERATION
michael@0 5302 switch (format)
michael@0 5303 {
michael@0 5304 case GL_ALPHA:
michael@0 5305 case GL_LUMINANCE:
michael@0 5306 case GL_LUMINANCE_ALPHA:
michael@0 5307 switch (type)
michael@0 5308 {
michael@0 5309 case GL_UNSIGNED_BYTE:
michael@0 5310 case GL_FLOAT:
michael@0 5311 case GL_HALF_FLOAT_OES:
michael@0 5312 break;
michael@0 5313 default:
michael@0 5314 return gl::error(GL_INVALID_OPERATION);
michael@0 5315 }
michael@0 5316 break;
michael@0 5317 case GL_RGB:
michael@0 5318 switch (type)
michael@0 5319 {
michael@0 5320 case GL_UNSIGNED_BYTE:
michael@0 5321 case GL_UNSIGNED_SHORT_5_6_5:
michael@0 5322 case GL_FLOAT:
michael@0 5323 case GL_HALF_FLOAT_OES:
michael@0 5324 break;
michael@0 5325 default:
michael@0 5326 return gl::error(GL_INVALID_OPERATION);
michael@0 5327 }
michael@0 5328 break;
michael@0 5329 case GL_RGBA:
michael@0 5330 switch (type)
michael@0 5331 {
michael@0 5332 case GL_UNSIGNED_BYTE:
michael@0 5333 case GL_UNSIGNED_SHORT_4_4_4_4:
michael@0 5334 case GL_UNSIGNED_SHORT_5_5_5_1:
michael@0 5335 case GL_FLOAT:
michael@0 5336 case GL_HALF_FLOAT_OES:
michael@0 5337 break;
michael@0 5338 default:
michael@0 5339 return gl::error(GL_INVALID_OPERATION);
michael@0 5340 }
michael@0 5341 break;
michael@0 5342 case GL_BGRA_EXT:
michael@0 5343 switch (type)
michael@0 5344 {
michael@0 5345 case GL_UNSIGNED_BYTE:
michael@0 5346 break;
michael@0 5347 default:
michael@0 5348 return gl::error(GL_INVALID_OPERATION);
michael@0 5349 }
michael@0 5350 break;
michael@0 5351 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are handled below
michael@0 5352 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
michael@0 5353 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
michael@0 5354 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
michael@0 5355 break;
michael@0 5356 case GL_DEPTH_COMPONENT:
michael@0 5357 switch (type)
michael@0 5358 {
michael@0 5359 case GL_UNSIGNED_SHORT:
michael@0 5360 case GL_UNSIGNED_INT:
michael@0 5361 break;
michael@0 5362 default:
michael@0 5363 return gl::error(GL_INVALID_OPERATION);
michael@0 5364 }
michael@0 5365 break;
michael@0 5366 case GL_DEPTH_STENCIL_OES:
michael@0 5367 switch (type)
michael@0 5368 {
michael@0 5369 case GL_UNSIGNED_INT_24_8_OES:
michael@0 5370 break;
michael@0 5371 default:
michael@0 5372 return gl::error(GL_INVALID_OPERATION);
michael@0 5373 }
michael@0 5374 break;
michael@0 5375 default:
michael@0 5376 return gl::error(GL_INVALID_ENUM);
michael@0 5377 }
michael@0 5378
michael@0 5379 if (border != 0)
michael@0 5380 {
michael@0 5381 return gl::error(GL_INVALID_VALUE);
michael@0 5382 }
michael@0 5383
michael@0 5384 gl::Context *context = gl::getNonLostContext();
michael@0 5385
michael@0 5386 if (context)
michael@0 5387 {
michael@0 5388 if (level > context->getMaximumTextureLevel())
michael@0 5389 {
michael@0 5390 return gl::error(GL_INVALID_VALUE);
michael@0 5391 }
michael@0 5392
michael@0 5393 switch (target)
michael@0 5394 {
michael@0 5395 case GL_TEXTURE_2D:
michael@0 5396 if (width > (context->getMaximumTextureDimension() >> level) ||
michael@0 5397 height > (context->getMaximumTextureDimension() >> level))
michael@0 5398 {
michael@0 5399 return gl::error(GL_INVALID_VALUE);
michael@0 5400 }
michael@0 5401 break;
michael@0 5402 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
michael@0 5403 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
michael@0 5404 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
michael@0 5405 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
michael@0 5406 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
michael@0 5407 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
michael@0 5408 if (width != height)
michael@0 5409 {
michael@0 5410 return gl::error(GL_INVALID_VALUE);
michael@0 5411 }
michael@0 5412
michael@0 5413 if (width > (context->getMaximumCubeTextureDimension() >> level) ||
michael@0 5414 height > (context->getMaximumCubeTextureDimension() >> level))
michael@0 5415 {
michael@0 5416 return gl::error(GL_INVALID_VALUE);
michael@0 5417 }
michael@0 5418 break;
michael@0 5419 default:
michael@0 5420 return gl::error(GL_INVALID_ENUM);
michael@0 5421 }
michael@0 5422
michael@0 5423 switch (format) {
michael@0 5424 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
michael@0 5425 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
michael@0 5426 if (context->supportsDXT1Textures())
michael@0 5427 {
michael@0 5428 return gl::error(GL_INVALID_OPERATION);
michael@0 5429 }
michael@0 5430 else
michael@0 5431 {
michael@0 5432 return gl::error(GL_INVALID_ENUM);
michael@0 5433 }
michael@0 5434 break;
michael@0 5435 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
michael@0 5436 if (context->supportsDXT3Textures())
michael@0 5437 {
michael@0 5438 return gl::error(GL_INVALID_OPERATION);
michael@0 5439 }
michael@0 5440 else
michael@0 5441 {
michael@0 5442 return gl::error(GL_INVALID_ENUM);
michael@0 5443 }
michael@0 5444 break;
michael@0 5445 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
michael@0 5446 if (context->supportsDXT5Textures())
michael@0 5447 {
michael@0 5448 return gl::error(GL_INVALID_OPERATION);
michael@0 5449 }
michael@0 5450 else
michael@0 5451 {
michael@0 5452 return gl::error(GL_INVALID_ENUM);
michael@0 5453 }
michael@0 5454 break;
michael@0 5455 case GL_DEPTH_COMPONENT:
michael@0 5456 case GL_DEPTH_STENCIL_OES:
michael@0 5457 if (!context->supportsDepthTextures())
michael@0 5458 {
michael@0 5459 return gl::error(GL_INVALID_VALUE);
michael@0 5460 }
michael@0 5461 if (target != GL_TEXTURE_2D)
michael@0 5462 {
michael@0 5463 return gl::error(GL_INVALID_OPERATION);
michael@0 5464 }
michael@0 5465 // OES_depth_texture supports loading depth data and multiple levels,
michael@0 5466 // but ANGLE_depth_texture does not
michael@0 5467 if (pixels != NULL || level != 0)
michael@0 5468 {
michael@0 5469 return gl::error(GL_INVALID_OPERATION);
michael@0 5470 }
michael@0 5471 break;
michael@0 5472 default:
michael@0 5473 break;
michael@0 5474 }
michael@0 5475
michael@0 5476 if (type == GL_FLOAT)
michael@0 5477 {
michael@0 5478 if (!context->supportsFloat32Textures())
michael@0 5479 {
michael@0 5480 return gl::error(GL_INVALID_ENUM);
michael@0 5481 }
michael@0 5482 }
michael@0 5483 else if (type == GL_HALF_FLOAT_OES)
michael@0 5484 {
michael@0 5485 if (!context->supportsFloat16Textures())
michael@0 5486 {
michael@0 5487 return gl::error(GL_INVALID_ENUM);
michael@0 5488 }
michael@0 5489 }
michael@0 5490
michael@0 5491 if (target == GL_TEXTURE_2D)
michael@0 5492 {
michael@0 5493 gl::Texture2D *texture = context->getTexture2D();
michael@0 5494
michael@0 5495 if (!texture)
michael@0 5496 {
michael@0 5497 return gl::error(GL_INVALID_OPERATION);
michael@0 5498 }
michael@0 5499
michael@0 5500 if (texture->isImmutable())
michael@0 5501 {
michael@0 5502 return gl::error(GL_INVALID_OPERATION);
michael@0 5503 }
michael@0 5504
michael@0 5505 texture->setImage(level, width, height, format, type, context->getUnpackAlignment(), pixels);
michael@0 5506 }
michael@0 5507 else
michael@0 5508 {
michael@0 5509 gl::TextureCubeMap *texture = context->getTextureCubeMap();
michael@0 5510
michael@0 5511 if (!texture)
michael@0 5512 {
michael@0 5513 return gl::error(GL_INVALID_OPERATION);
michael@0 5514 }
michael@0 5515
michael@0 5516 if (texture->isImmutable())
michael@0 5517 {
michael@0 5518 return gl::error(GL_INVALID_OPERATION);
michael@0 5519 }
michael@0 5520
michael@0 5521 switch (target)
michael@0 5522 {
michael@0 5523 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
michael@0 5524 texture->setImagePosX(level, width, height, format, type, context->getUnpackAlignment(), pixels);
michael@0 5525 break;
michael@0 5526 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
michael@0 5527 texture->setImageNegX(level, width, height, format, type, context->getUnpackAlignment(), pixels);
michael@0 5528 break;
michael@0 5529 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
michael@0 5530 texture->setImagePosY(level, width, height, format, type, context->getUnpackAlignment(), pixels);
michael@0 5531 break;
michael@0 5532 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
michael@0 5533 texture->setImageNegY(level, width, height, format, type, context->getUnpackAlignment(), pixels);
michael@0 5534 break;
michael@0 5535 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
michael@0 5536 texture->setImagePosZ(level, width, height, format, type, context->getUnpackAlignment(), pixels);
michael@0 5537 break;
michael@0 5538 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
michael@0 5539 texture->setImageNegZ(level, width, height, format, type, context->getUnpackAlignment(), pixels);
michael@0 5540 break;
michael@0 5541 default: UNREACHABLE();
michael@0 5542 }
michael@0 5543 }
michael@0 5544 }
michael@0 5545 }
michael@0 5546 catch(std::bad_alloc&)
michael@0 5547 {
michael@0 5548 return gl::error(GL_OUT_OF_MEMORY);
michael@0 5549 }
michael@0 5550 }
michael@0 5551
michael@0 5552 void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param)
michael@0 5553 {
michael@0 5554 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
michael@0 5555
michael@0 5556 try
michael@0 5557 {
michael@0 5558 gl::Context *context = gl::getNonLostContext();
michael@0 5559
michael@0 5560 if (context)
michael@0 5561 {
michael@0 5562 gl::Texture *texture;
michael@0 5563
michael@0 5564 switch (target)
michael@0 5565 {
michael@0 5566 case GL_TEXTURE_2D:
michael@0 5567 texture = context->getTexture2D();
michael@0 5568 break;
michael@0 5569 case GL_TEXTURE_CUBE_MAP:
michael@0 5570 texture = context->getTextureCubeMap();
michael@0 5571 break;
michael@0 5572 default:
michael@0 5573 return gl::error(GL_INVALID_ENUM);
michael@0 5574 }
michael@0 5575
michael@0 5576 switch (pname)
michael@0 5577 {
michael@0 5578 case GL_TEXTURE_WRAP_S:
michael@0 5579 if (!texture->setWrapS((GLenum)param))
michael@0 5580 {
michael@0 5581 return gl::error(GL_INVALID_ENUM);
michael@0 5582 }
michael@0 5583 break;
michael@0 5584 case GL_TEXTURE_WRAP_T:
michael@0 5585 if (!texture->setWrapT((GLenum)param))
michael@0 5586 {
michael@0 5587 return gl::error(GL_INVALID_ENUM);
michael@0 5588 }
michael@0 5589 break;
michael@0 5590 case GL_TEXTURE_MIN_FILTER:
michael@0 5591 if (!texture->setMinFilter((GLenum)param))
michael@0 5592 {
michael@0 5593 return gl::error(GL_INVALID_ENUM);
michael@0 5594 }
michael@0 5595 break;
michael@0 5596 case GL_TEXTURE_MAG_FILTER:
michael@0 5597 if (!texture->setMagFilter((GLenum)param))
michael@0 5598 {
michael@0 5599 return gl::error(GL_INVALID_ENUM);
michael@0 5600 }
michael@0 5601 break;
michael@0 5602 case GL_TEXTURE_USAGE_ANGLE:
michael@0 5603 if (!texture->setUsage((GLenum)param))
michael@0 5604 {
michael@0 5605 return gl::error(GL_INVALID_ENUM);
michael@0 5606 }
michael@0 5607 break;
michael@0 5608 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
michael@0 5609 if (!context->supportsTextureFilterAnisotropy())
michael@0 5610 {
michael@0 5611 return gl::error(GL_INVALID_ENUM);
michael@0 5612 }
michael@0 5613 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
michael@0 5614 {
michael@0 5615 return gl::error(GL_INVALID_VALUE);
michael@0 5616 }
michael@0 5617 break;
michael@0 5618 default:
michael@0 5619 return gl::error(GL_INVALID_ENUM);
michael@0 5620 }
michael@0 5621 }
michael@0 5622 }
michael@0 5623 catch(std::bad_alloc&)
michael@0 5624 {
michael@0 5625 return gl::error(GL_OUT_OF_MEMORY);
michael@0 5626 }
michael@0 5627 }
michael@0 5628
michael@0 5629 void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
michael@0 5630 {
michael@0 5631 glTexParameterf(target, pname, (GLfloat)*params);
michael@0 5632 }
michael@0 5633
michael@0 5634 void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param)
michael@0 5635 {
michael@0 5636 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
michael@0 5637
michael@0 5638 try
michael@0 5639 {
michael@0 5640 gl::Context *context = gl::getNonLostContext();
michael@0 5641
michael@0 5642 if (context)
michael@0 5643 {
michael@0 5644 gl::Texture *texture;
michael@0 5645
michael@0 5646 switch (target)
michael@0 5647 {
michael@0 5648 case GL_TEXTURE_2D:
michael@0 5649 texture = context->getTexture2D();
michael@0 5650 break;
michael@0 5651 case GL_TEXTURE_CUBE_MAP:
michael@0 5652 texture = context->getTextureCubeMap();
michael@0 5653 break;
michael@0 5654 default:
michael@0 5655 return gl::error(GL_INVALID_ENUM);
michael@0 5656 }
michael@0 5657
michael@0 5658 switch (pname)
michael@0 5659 {
michael@0 5660 case GL_TEXTURE_WRAP_S:
michael@0 5661 if (!texture->setWrapS((GLenum)param))
michael@0 5662 {
michael@0 5663 return gl::error(GL_INVALID_ENUM);
michael@0 5664 }
michael@0 5665 break;
michael@0 5666 case GL_TEXTURE_WRAP_T:
michael@0 5667 if (!texture->setWrapT((GLenum)param))
michael@0 5668 {
michael@0 5669 return gl::error(GL_INVALID_ENUM);
michael@0 5670 }
michael@0 5671 break;
michael@0 5672 case GL_TEXTURE_MIN_FILTER:
michael@0 5673 if (!texture->setMinFilter((GLenum)param))
michael@0 5674 {
michael@0 5675 return gl::error(GL_INVALID_ENUM);
michael@0 5676 }
michael@0 5677 break;
michael@0 5678 case GL_TEXTURE_MAG_FILTER:
michael@0 5679 if (!texture->setMagFilter((GLenum)param))
michael@0 5680 {
michael@0 5681 return gl::error(GL_INVALID_ENUM);
michael@0 5682 }
michael@0 5683 break;
michael@0 5684 case GL_TEXTURE_USAGE_ANGLE:
michael@0 5685 if (!texture->setUsage((GLenum)param))
michael@0 5686 {
michael@0 5687 return gl::error(GL_INVALID_ENUM);
michael@0 5688 }
michael@0 5689 break;
michael@0 5690 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
michael@0 5691 if (!context->supportsTextureFilterAnisotropy())
michael@0 5692 {
michael@0 5693 return gl::error(GL_INVALID_ENUM);
michael@0 5694 }
michael@0 5695 if (!texture->setMaxAnisotropy((float)param, context->getTextureMaxAnisotropy()))
michael@0 5696 {
michael@0 5697 return gl::error(GL_INVALID_VALUE);
michael@0 5698 }
michael@0 5699 break;
michael@0 5700 default:
michael@0 5701 return gl::error(GL_INVALID_ENUM);
michael@0 5702 }
michael@0 5703 }
michael@0 5704 }
michael@0 5705 catch(std::bad_alloc&)
michael@0 5706 {
michael@0 5707 return gl::error(GL_OUT_OF_MEMORY);
michael@0 5708 }
michael@0 5709 }
michael@0 5710
michael@0 5711 void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
michael@0 5712 {
michael@0 5713 glTexParameteri(target, pname, *params);
michael@0 5714 }
michael@0 5715
michael@0 5716 void __stdcall glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
michael@0 5717 {
michael@0 5718 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
michael@0 5719 target, levels, internalformat, width, height);
michael@0 5720
michael@0 5721 try
michael@0 5722 {
michael@0 5723 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_CUBE_MAP)
michael@0 5724 {
michael@0 5725 return gl::error(GL_INVALID_ENUM);
michael@0 5726 }
michael@0 5727
michael@0 5728 if (width < 1 || height < 1 || levels < 1)
michael@0 5729 {
michael@0 5730 return gl::error(GL_INVALID_VALUE);
michael@0 5731 }
michael@0 5732
michael@0 5733 if (target == GL_TEXTURE_CUBE_MAP && width != height)
michael@0 5734 {
michael@0 5735 return gl::error(GL_INVALID_VALUE);
michael@0 5736 }
michael@0 5737
michael@0 5738 if (levels != 1 && levels != gl::log2(std::max(width, height)) + 1)
michael@0 5739 {
michael@0 5740 return gl::error(GL_INVALID_OPERATION);
michael@0 5741 }
michael@0 5742
michael@0 5743 GLenum format = gl::ExtractFormat(internalformat);
michael@0 5744 GLenum type = gl::ExtractType(internalformat);
michael@0 5745
michael@0 5746 if (format == GL_NONE || type == GL_NONE)
michael@0 5747 {
michael@0 5748 return gl::error(GL_INVALID_ENUM);
michael@0 5749 }
michael@0 5750
michael@0 5751 gl::Context *context = gl::getNonLostContext();
michael@0 5752
michael@0 5753 if (context)
michael@0 5754 {
michael@0 5755 switch (target)
michael@0 5756 {
michael@0 5757 case GL_TEXTURE_2D:
michael@0 5758 if (width > context->getMaximumTextureDimension() ||
michael@0 5759 height > context->getMaximumTextureDimension())
michael@0 5760 {
michael@0 5761 return gl::error(GL_INVALID_VALUE);
michael@0 5762 }
michael@0 5763 break;
michael@0 5764 case GL_TEXTURE_CUBE_MAP:
michael@0 5765 if (width > context->getMaximumCubeTextureDimension() ||
michael@0 5766 height > context->getMaximumCubeTextureDimension())
michael@0 5767 {
michael@0 5768 return gl::error(GL_INVALID_VALUE);
michael@0 5769 }
michael@0 5770 break;
michael@0 5771 default:
michael@0 5772 return gl::error(GL_INVALID_ENUM);
michael@0 5773 }
michael@0 5774
michael@0 5775 if (levels != 1 && !context->supportsNonPower2Texture())
michael@0 5776 {
michael@0 5777 if (!gl::isPow2(width) || !gl::isPow2(height))
michael@0 5778 {
michael@0 5779 return gl::error(GL_INVALID_OPERATION);
michael@0 5780 }
michael@0 5781 }
michael@0 5782
michael@0 5783 switch (internalformat)
michael@0 5784 {
michael@0 5785 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
michael@0 5786 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
michael@0 5787 if (!context->supportsDXT1Textures())
michael@0 5788 {
michael@0 5789 return gl::error(GL_INVALID_ENUM);
michael@0 5790 }
michael@0 5791 break;
michael@0 5792 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
michael@0 5793 if (!context->supportsDXT3Textures())
michael@0 5794 {
michael@0 5795 return gl::error(GL_INVALID_ENUM);
michael@0 5796 }
michael@0 5797 break;
michael@0 5798 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
michael@0 5799 if (!context->supportsDXT5Textures())
michael@0 5800 {
michael@0 5801 return gl::error(GL_INVALID_ENUM);
michael@0 5802 }
michael@0 5803 break;
michael@0 5804 case GL_RGBA32F_EXT:
michael@0 5805 case GL_RGB32F_EXT:
michael@0 5806 case GL_ALPHA32F_EXT:
michael@0 5807 case GL_LUMINANCE32F_EXT:
michael@0 5808 case GL_LUMINANCE_ALPHA32F_EXT:
michael@0 5809 if (!context->supportsFloat32Textures())
michael@0 5810 {
michael@0 5811 return gl::error(GL_INVALID_ENUM);
michael@0 5812 }
michael@0 5813 break;
michael@0 5814 case GL_RGBA16F_EXT:
michael@0 5815 case GL_RGB16F_EXT:
michael@0 5816 case GL_ALPHA16F_EXT:
michael@0 5817 case GL_LUMINANCE16F_EXT:
michael@0 5818 case GL_LUMINANCE_ALPHA16F_EXT:
michael@0 5819 if (!context->supportsFloat16Textures())
michael@0 5820 {
michael@0 5821 return gl::error(GL_INVALID_ENUM);
michael@0 5822 }
michael@0 5823 break;
michael@0 5824 case GL_DEPTH_COMPONENT16:
michael@0 5825 case GL_DEPTH_COMPONENT32_OES:
michael@0 5826 case GL_DEPTH24_STENCIL8_OES:
michael@0 5827 if (!context->supportsDepthTextures())
michael@0 5828 {
michael@0 5829 return gl::error(GL_INVALID_ENUM);
michael@0 5830 }
michael@0 5831 if (target != GL_TEXTURE_2D)
michael@0 5832 {
michael@0 5833 return gl::error(GL_INVALID_OPERATION);
michael@0 5834 }
michael@0 5835 // ANGLE_depth_texture only supports 1-level textures
michael@0 5836 if (levels != 1)
michael@0 5837 {
michael@0 5838 return gl::error(GL_INVALID_OPERATION);
michael@0 5839 }
michael@0 5840 break;
michael@0 5841 default:
michael@0 5842 break;
michael@0 5843 }
michael@0 5844
michael@0 5845 if (target == GL_TEXTURE_2D)
michael@0 5846 {
michael@0 5847 gl::Texture2D *texture = context->getTexture2D();
michael@0 5848
michael@0 5849 if (!texture || texture->id() == 0)
michael@0 5850 {
michael@0 5851 return gl::error(GL_INVALID_OPERATION);
michael@0 5852 }
michael@0 5853
michael@0 5854 if (texture->isImmutable())
michael@0 5855 {
michael@0 5856 return gl::error(GL_INVALID_OPERATION);
michael@0 5857 }
michael@0 5858
michael@0 5859 texture->storage(levels, internalformat, width, height);
michael@0 5860 }
michael@0 5861 else if (target == GL_TEXTURE_CUBE_MAP)
michael@0 5862 {
michael@0 5863 gl::TextureCubeMap *texture = context->getTextureCubeMap();
michael@0 5864
michael@0 5865 if (!texture || texture->id() == 0)
michael@0 5866 {
michael@0 5867 return gl::error(GL_INVALID_OPERATION);
michael@0 5868 }
michael@0 5869
michael@0 5870 if (texture->isImmutable())
michael@0 5871 {
michael@0 5872 return gl::error(GL_INVALID_OPERATION);
michael@0 5873 }
michael@0 5874
michael@0 5875 texture->storage(levels, internalformat, width);
michael@0 5876 }
michael@0 5877 else UNREACHABLE();
michael@0 5878 }
michael@0 5879 }
michael@0 5880 catch(std::bad_alloc&)
michael@0 5881 {
michael@0 5882 return gl::error(GL_OUT_OF_MEMORY);
michael@0 5883 }
michael@0 5884 }
michael@0 5885
michael@0 5886 void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
michael@0 5887 GLenum format, GLenum type, const GLvoid* pixels)
michael@0 5888 {
michael@0 5889 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
michael@0 5890 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
michael@0 5891 "const GLvoid* pixels = 0x%0.8p)",
michael@0 5892 target, level, xoffset, yoffset, width, height, format, type, pixels);
michael@0 5893
michael@0 5894 try
michael@0 5895 {
michael@0 5896 if (!gl::IsInternalTextureTarget(target))
michael@0 5897 {
michael@0 5898 return gl::error(GL_INVALID_ENUM);
michael@0 5899 }
michael@0 5900
michael@0 5901 if (level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
michael@0 5902 {
michael@0 5903 return gl::error(GL_INVALID_VALUE);
michael@0 5904 }
michael@0 5905
michael@0 5906 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
michael@0 5907 {
michael@0 5908 return gl::error(GL_INVALID_VALUE);
michael@0 5909 }
michael@0 5910
michael@0 5911 if (!checkTextureFormatType(format, type))
michael@0 5912 {
michael@0 5913 return; // error is set by helper function
michael@0 5914 }
michael@0 5915
michael@0 5916 gl::Context *context = gl::getNonLostContext();
michael@0 5917
michael@0 5918 if (context)
michael@0 5919 {
michael@0 5920 if (level > context->getMaximumTextureLevel())
michael@0 5921 {
michael@0 5922 return gl::error(GL_INVALID_VALUE);
michael@0 5923 }
michael@0 5924
michael@0 5925 if (format == GL_FLOAT)
michael@0 5926 {
michael@0 5927 if (!context->supportsFloat32Textures())
michael@0 5928 {
michael@0 5929 return gl::error(GL_INVALID_ENUM);
michael@0 5930 }
michael@0 5931 }
michael@0 5932 else if (format == GL_HALF_FLOAT_OES)
michael@0 5933 {
michael@0 5934 if (!context->supportsFloat16Textures())
michael@0 5935 {
michael@0 5936 return gl::error(GL_INVALID_ENUM);
michael@0 5937 }
michael@0 5938 }
michael@0 5939 else if (gl::IsDepthTexture(format))
michael@0 5940 {
michael@0 5941 if (!context->supportsDepthTextures())
michael@0 5942 {
michael@0 5943 return gl::error(GL_INVALID_ENUM);
michael@0 5944 }
michael@0 5945 if (target != GL_TEXTURE_2D)
michael@0 5946 {
michael@0 5947 return gl::error(GL_INVALID_OPERATION);
michael@0 5948 }
michael@0 5949 // OES_depth_texture supports loading depth data, but ANGLE_depth_texture does not
michael@0 5950 return gl::error(GL_INVALID_OPERATION);
michael@0 5951 }
michael@0 5952
michael@0 5953 if (width == 0 || height == 0 || pixels == NULL)
michael@0 5954 {
michael@0 5955 return;
michael@0 5956 }
michael@0 5957
michael@0 5958 if (target == GL_TEXTURE_2D)
michael@0 5959 {
michael@0 5960 gl::Texture2D *texture = context->getTexture2D();
michael@0 5961 if (validateSubImageParams2D(false, width, height, xoffset, yoffset, level, format, type, texture))
michael@0 5962 {
michael@0 5963 texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
michael@0 5964 }
michael@0 5965 }
michael@0 5966 else if (gl::IsCubemapTextureTarget(target))
michael@0 5967 {
michael@0 5968 gl::TextureCubeMap *texture = context->getTextureCubeMap();
michael@0 5969 if (validateSubImageParamsCube(false, width, height, xoffset, yoffset, target, level, format, type, texture))
michael@0 5970 {
michael@0 5971 texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
michael@0 5972 }
michael@0 5973 }
michael@0 5974 else
michael@0 5975 {
michael@0 5976 UNREACHABLE();
michael@0 5977 }
michael@0 5978 }
michael@0 5979 }
michael@0 5980 catch(std::bad_alloc&)
michael@0 5981 {
michael@0 5982 return gl::error(GL_OUT_OF_MEMORY);
michael@0 5983 }
michael@0 5984 }
michael@0 5985
michael@0 5986 void __stdcall glUniform1f(GLint location, GLfloat x)
michael@0 5987 {
michael@0 5988 glUniform1fv(location, 1, &x);
michael@0 5989 }
michael@0 5990
michael@0 5991 void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
michael@0 5992 {
michael@0 5993 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
michael@0 5994
michael@0 5995 try
michael@0 5996 {
michael@0 5997 if (count < 0)
michael@0 5998 {
michael@0 5999 return gl::error(GL_INVALID_VALUE);
michael@0 6000 }
michael@0 6001
michael@0 6002 if (location == -1)
michael@0 6003 {
michael@0 6004 return;
michael@0 6005 }
michael@0 6006
michael@0 6007 gl::Context *context = gl::getNonLostContext();
michael@0 6008
michael@0 6009 if (context)
michael@0 6010 {
michael@0 6011 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
michael@0 6012 if (!programBinary)
michael@0 6013 {
michael@0 6014 return gl::error(GL_INVALID_OPERATION);
michael@0 6015 }
michael@0 6016
michael@0 6017 if (!programBinary->setUniform1fv(location, count, v))
michael@0 6018 {
michael@0 6019 return gl::error(GL_INVALID_OPERATION);
michael@0 6020 }
michael@0 6021 }
michael@0 6022 }
michael@0 6023 catch(std::bad_alloc&)
michael@0 6024 {
michael@0 6025 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6026 }
michael@0 6027 }
michael@0 6028
michael@0 6029 void __stdcall glUniform1i(GLint location, GLint x)
michael@0 6030 {
michael@0 6031 glUniform1iv(location, 1, &x);
michael@0 6032 }
michael@0 6033
michael@0 6034 void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v)
michael@0 6035 {
michael@0 6036 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
michael@0 6037
michael@0 6038 try
michael@0 6039 {
michael@0 6040 if (count < 0)
michael@0 6041 {
michael@0 6042 return gl::error(GL_INVALID_VALUE);
michael@0 6043 }
michael@0 6044
michael@0 6045 if (location == -1)
michael@0 6046 {
michael@0 6047 return;
michael@0 6048 }
michael@0 6049
michael@0 6050 gl::Context *context = gl::getNonLostContext();
michael@0 6051
michael@0 6052 if (context)
michael@0 6053 {
michael@0 6054 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
michael@0 6055 if (!programBinary)
michael@0 6056 {
michael@0 6057 return gl::error(GL_INVALID_OPERATION);
michael@0 6058 }
michael@0 6059
michael@0 6060 if (!programBinary->setUniform1iv(location, count, v))
michael@0 6061 {
michael@0 6062 return gl::error(GL_INVALID_OPERATION);
michael@0 6063 }
michael@0 6064 }
michael@0 6065 }
michael@0 6066 catch(std::bad_alloc&)
michael@0 6067 {
michael@0 6068 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6069 }
michael@0 6070 }
michael@0 6071
michael@0 6072 void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y)
michael@0 6073 {
michael@0 6074 GLfloat xy[2] = {x, y};
michael@0 6075
michael@0 6076 glUniform2fv(location, 1, (GLfloat*)&xy);
michael@0 6077 }
michael@0 6078
michael@0 6079 void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
michael@0 6080 {
michael@0 6081 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
michael@0 6082
michael@0 6083 try
michael@0 6084 {
michael@0 6085 if (count < 0)
michael@0 6086 {
michael@0 6087 return gl::error(GL_INVALID_VALUE);
michael@0 6088 }
michael@0 6089
michael@0 6090 if (location == -1)
michael@0 6091 {
michael@0 6092 return;
michael@0 6093 }
michael@0 6094
michael@0 6095 gl::Context *context = gl::getNonLostContext();
michael@0 6096
michael@0 6097 if (context)
michael@0 6098 {
michael@0 6099 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
michael@0 6100 if (!programBinary)
michael@0 6101 {
michael@0 6102 return gl::error(GL_INVALID_OPERATION);
michael@0 6103 }
michael@0 6104
michael@0 6105 if (!programBinary->setUniform2fv(location, count, v))
michael@0 6106 {
michael@0 6107 return gl::error(GL_INVALID_OPERATION);
michael@0 6108 }
michael@0 6109 }
michael@0 6110 }
michael@0 6111 catch(std::bad_alloc&)
michael@0 6112 {
michael@0 6113 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6114 }
michael@0 6115 }
michael@0 6116
michael@0 6117 void __stdcall glUniform2i(GLint location, GLint x, GLint y)
michael@0 6118 {
michael@0 6119 GLint xy[4] = {x, y};
michael@0 6120
michael@0 6121 glUniform2iv(location, 1, (GLint*)&xy);
michael@0 6122 }
michael@0 6123
michael@0 6124 void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v)
michael@0 6125 {
michael@0 6126 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
michael@0 6127
michael@0 6128 try
michael@0 6129 {
michael@0 6130 if (count < 0)
michael@0 6131 {
michael@0 6132 return gl::error(GL_INVALID_VALUE);
michael@0 6133 }
michael@0 6134
michael@0 6135 if (location == -1)
michael@0 6136 {
michael@0 6137 return;
michael@0 6138 }
michael@0 6139
michael@0 6140 gl::Context *context = gl::getNonLostContext();
michael@0 6141
michael@0 6142 if (context)
michael@0 6143 {
michael@0 6144 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
michael@0 6145 if (!programBinary)
michael@0 6146 {
michael@0 6147 return gl::error(GL_INVALID_OPERATION);
michael@0 6148 }
michael@0 6149
michael@0 6150 if (!programBinary->setUniform2iv(location, count, v))
michael@0 6151 {
michael@0 6152 return gl::error(GL_INVALID_OPERATION);
michael@0 6153 }
michael@0 6154 }
michael@0 6155 }
michael@0 6156 catch(std::bad_alloc&)
michael@0 6157 {
michael@0 6158 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6159 }
michael@0 6160 }
michael@0 6161
michael@0 6162 void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
michael@0 6163 {
michael@0 6164 GLfloat xyz[3] = {x, y, z};
michael@0 6165
michael@0 6166 glUniform3fv(location, 1, (GLfloat*)&xyz);
michael@0 6167 }
michael@0 6168
michael@0 6169 void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
michael@0 6170 {
michael@0 6171 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
michael@0 6172
michael@0 6173 try
michael@0 6174 {
michael@0 6175 if (count < 0)
michael@0 6176 {
michael@0 6177 return gl::error(GL_INVALID_VALUE);
michael@0 6178 }
michael@0 6179
michael@0 6180 if (location == -1)
michael@0 6181 {
michael@0 6182 return;
michael@0 6183 }
michael@0 6184
michael@0 6185 gl::Context *context = gl::getNonLostContext();
michael@0 6186
michael@0 6187 if (context)
michael@0 6188 {
michael@0 6189 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
michael@0 6190 if (!programBinary)
michael@0 6191 {
michael@0 6192 return gl::error(GL_INVALID_OPERATION);
michael@0 6193 }
michael@0 6194
michael@0 6195 if (!programBinary->setUniform3fv(location, count, v))
michael@0 6196 {
michael@0 6197 return gl::error(GL_INVALID_OPERATION);
michael@0 6198 }
michael@0 6199 }
michael@0 6200 }
michael@0 6201 catch(std::bad_alloc&)
michael@0 6202 {
michael@0 6203 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6204 }
michael@0 6205 }
michael@0 6206
michael@0 6207 void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z)
michael@0 6208 {
michael@0 6209 GLint xyz[3] = {x, y, z};
michael@0 6210
michael@0 6211 glUniform3iv(location, 1, (GLint*)&xyz);
michael@0 6212 }
michael@0 6213
michael@0 6214 void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v)
michael@0 6215 {
michael@0 6216 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
michael@0 6217
michael@0 6218 try
michael@0 6219 {
michael@0 6220 if (count < 0)
michael@0 6221 {
michael@0 6222 return gl::error(GL_INVALID_VALUE);
michael@0 6223 }
michael@0 6224
michael@0 6225 if (location == -1)
michael@0 6226 {
michael@0 6227 return;
michael@0 6228 }
michael@0 6229
michael@0 6230 gl::Context *context = gl::getNonLostContext();
michael@0 6231
michael@0 6232 if (context)
michael@0 6233 {
michael@0 6234 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
michael@0 6235 if (!programBinary)
michael@0 6236 {
michael@0 6237 return gl::error(GL_INVALID_OPERATION);
michael@0 6238 }
michael@0 6239
michael@0 6240 if (!programBinary->setUniform3iv(location, count, v))
michael@0 6241 {
michael@0 6242 return gl::error(GL_INVALID_OPERATION);
michael@0 6243 }
michael@0 6244 }
michael@0 6245 }
michael@0 6246 catch(std::bad_alloc&)
michael@0 6247 {
michael@0 6248 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6249 }
michael@0 6250 }
michael@0 6251
michael@0 6252 void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
michael@0 6253 {
michael@0 6254 GLfloat xyzw[4] = {x, y, z, w};
michael@0 6255
michael@0 6256 glUniform4fv(location, 1, (GLfloat*)&xyzw);
michael@0 6257 }
michael@0 6258
michael@0 6259 void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
michael@0 6260 {
michael@0 6261 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
michael@0 6262
michael@0 6263 try
michael@0 6264 {
michael@0 6265 if (count < 0)
michael@0 6266 {
michael@0 6267 return gl::error(GL_INVALID_VALUE);
michael@0 6268 }
michael@0 6269
michael@0 6270 if (location == -1)
michael@0 6271 {
michael@0 6272 return;
michael@0 6273 }
michael@0 6274
michael@0 6275 gl::Context *context = gl::getNonLostContext();
michael@0 6276
michael@0 6277 if (context)
michael@0 6278 {
michael@0 6279 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
michael@0 6280 if (!programBinary)
michael@0 6281 {
michael@0 6282 return gl::error(GL_INVALID_OPERATION);
michael@0 6283 }
michael@0 6284
michael@0 6285 if (!programBinary->setUniform4fv(location, count, v))
michael@0 6286 {
michael@0 6287 return gl::error(GL_INVALID_OPERATION);
michael@0 6288 }
michael@0 6289 }
michael@0 6290 }
michael@0 6291 catch(std::bad_alloc&)
michael@0 6292 {
michael@0 6293 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6294 }
michael@0 6295 }
michael@0 6296
michael@0 6297 void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
michael@0 6298 {
michael@0 6299 GLint xyzw[4] = {x, y, z, w};
michael@0 6300
michael@0 6301 glUniform4iv(location, 1, (GLint*)&xyzw);
michael@0 6302 }
michael@0 6303
michael@0 6304 void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v)
michael@0 6305 {
michael@0 6306 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
michael@0 6307
michael@0 6308 try
michael@0 6309 {
michael@0 6310 if (count < 0)
michael@0 6311 {
michael@0 6312 return gl::error(GL_INVALID_VALUE);
michael@0 6313 }
michael@0 6314
michael@0 6315 if (location == -1)
michael@0 6316 {
michael@0 6317 return;
michael@0 6318 }
michael@0 6319
michael@0 6320 gl::Context *context = gl::getNonLostContext();
michael@0 6321
michael@0 6322 if (context)
michael@0 6323 {
michael@0 6324 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
michael@0 6325 if (!programBinary)
michael@0 6326 {
michael@0 6327 return gl::error(GL_INVALID_OPERATION);
michael@0 6328 }
michael@0 6329
michael@0 6330 if (!programBinary->setUniform4iv(location, count, v))
michael@0 6331 {
michael@0 6332 return gl::error(GL_INVALID_OPERATION);
michael@0 6333 }
michael@0 6334 }
michael@0 6335 }
michael@0 6336 catch(std::bad_alloc&)
michael@0 6337 {
michael@0 6338 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6339 }
michael@0 6340 }
michael@0 6341
michael@0 6342 void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
michael@0 6343 {
michael@0 6344 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %d, const GLfloat* value = 0x%0.8p)",
michael@0 6345 location, count, transpose, value);
michael@0 6346
michael@0 6347 try
michael@0 6348 {
michael@0 6349 if (count < 0 || transpose != GL_FALSE)
michael@0 6350 {
michael@0 6351 return gl::error(GL_INVALID_VALUE);
michael@0 6352 }
michael@0 6353
michael@0 6354 if (location == -1)
michael@0 6355 {
michael@0 6356 return;
michael@0 6357 }
michael@0 6358
michael@0 6359 gl::Context *context = gl::getNonLostContext();
michael@0 6360
michael@0 6361 if (context)
michael@0 6362 {
michael@0 6363 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
michael@0 6364 if (!programBinary)
michael@0 6365 {
michael@0 6366 return gl::error(GL_INVALID_OPERATION);
michael@0 6367 }
michael@0 6368
michael@0 6369 if (!programBinary->setUniformMatrix2fv(location, count, value))
michael@0 6370 {
michael@0 6371 return gl::error(GL_INVALID_OPERATION);
michael@0 6372 }
michael@0 6373 }
michael@0 6374 }
michael@0 6375 catch(std::bad_alloc&)
michael@0 6376 {
michael@0 6377 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6378 }
michael@0 6379 }
michael@0 6380
michael@0 6381 void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
michael@0 6382 {
michael@0 6383 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %d, const GLfloat* value = 0x%0.8p)",
michael@0 6384 location, count, transpose, value);
michael@0 6385
michael@0 6386 try
michael@0 6387 {
michael@0 6388 if (count < 0 || transpose != GL_FALSE)
michael@0 6389 {
michael@0 6390 return gl::error(GL_INVALID_VALUE);
michael@0 6391 }
michael@0 6392
michael@0 6393 if (location == -1)
michael@0 6394 {
michael@0 6395 return;
michael@0 6396 }
michael@0 6397
michael@0 6398 gl::Context *context = gl::getNonLostContext();
michael@0 6399
michael@0 6400 if (context)
michael@0 6401 {
michael@0 6402 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
michael@0 6403 if (!programBinary)
michael@0 6404 {
michael@0 6405 return gl::error(GL_INVALID_OPERATION);
michael@0 6406 }
michael@0 6407
michael@0 6408 if (!programBinary->setUniformMatrix3fv(location, count, value))
michael@0 6409 {
michael@0 6410 return gl::error(GL_INVALID_OPERATION);
michael@0 6411 }
michael@0 6412 }
michael@0 6413 }
michael@0 6414 catch(std::bad_alloc&)
michael@0 6415 {
michael@0 6416 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6417 }
michael@0 6418 }
michael@0 6419
michael@0 6420 void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
michael@0 6421 {
michael@0 6422 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %d, const GLfloat* value = 0x%0.8p)",
michael@0 6423 location, count, transpose, value);
michael@0 6424
michael@0 6425 try
michael@0 6426 {
michael@0 6427 if (count < 0 || transpose != GL_FALSE)
michael@0 6428 {
michael@0 6429 return gl::error(GL_INVALID_VALUE);
michael@0 6430 }
michael@0 6431
michael@0 6432 if (location == -1)
michael@0 6433 {
michael@0 6434 return;
michael@0 6435 }
michael@0 6436
michael@0 6437 gl::Context *context = gl::getNonLostContext();
michael@0 6438
michael@0 6439 if (context)
michael@0 6440 {
michael@0 6441 gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
michael@0 6442 if (!programBinary)
michael@0 6443 {
michael@0 6444 return gl::error(GL_INVALID_OPERATION);
michael@0 6445 }
michael@0 6446
michael@0 6447 if (!programBinary->setUniformMatrix4fv(location, count, value))
michael@0 6448 {
michael@0 6449 return gl::error(GL_INVALID_OPERATION);
michael@0 6450 }
michael@0 6451 }
michael@0 6452 }
michael@0 6453 catch(std::bad_alloc&)
michael@0 6454 {
michael@0 6455 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6456 }
michael@0 6457 }
michael@0 6458
michael@0 6459 void __stdcall glUseProgram(GLuint program)
michael@0 6460 {
michael@0 6461 EVENT("(GLuint program = %d)", program);
michael@0 6462
michael@0 6463 try
michael@0 6464 {
michael@0 6465 gl::Context *context = gl::getNonLostContext();
michael@0 6466
michael@0 6467 if (context)
michael@0 6468 {
michael@0 6469 gl::Program *programObject = context->getProgram(program);
michael@0 6470
michael@0 6471 if (!programObject && program != 0)
michael@0 6472 {
michael@0 6473 if (context->getShader(program))
michael@0 6474 {
michael@0 6475 return gl::error(GL_INVALID_OPERATION);
michael@0 6476 }
michael@0 6477 else
michael@0 6478 {
michael@0 6479 return gl::error(GL_INVALID_VALUE);
michael@0 6480 }
michael@0 6481 }
michael@0 6482
michael@0 6483 if (program != 0 && !programObject->isLinked())
michael@0 6484 {
michael@0 6485 return gl::error(GL_INVALID_OPERATION);
michael@0 6486 }
michael@0 6487
michael@0 6488 context->useProgram(program);
michael@0 6489 }
michael@0 6490 }
michael@0 6491 catch(std::bad_alloc&)
michael@0 6492 {
michael@0 6493 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6494 }
michael@0 6495 }
michael@0 6496
michael@0 6497 void __stdcall glValidateProgram(GLuint program)
michael@0 6498 {
michael@0 6499 EVENT("(GLuint program = %d)", program);
michael@0 6500
michael@0 6501 try
michael@0 6502 {
michael@0 6503 gl::Context *context = gl::getNonLostContext();
michael@0 6504
michael@0 6505 if (context)
michael@0 6506 {
michael@0 6507 gl::Program *programObject = context->getProgram(program);
michael@0 6508
michael@0 6509 if (!programObject)
michael@0 6510 {
michael@0 6511 if (context->getShader(program))
michael@0 6512 {
michael@0 6513 return gl::error(GL_INVALID_OPERATION);
michael@0 6514 }
michael@0 6515 else
michael@0 6516 {
michael@0 6517 return gl::error(GL_INVALID_VALUE);
michael@0 6518 }
michael@0 6519 }
michael@0 6520
michael@0 6521 programObject->validate();
michael@0 6522 }
michael@0 6523 }
michael@0 6524 catch(std::bad_alloc&)
michael@0 6525 {
michael@0 6526 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6527 }
michael@0 6528 }
michael@0 6529
michael@0 6530 void __stdcall glVertexAttrib1f(GLuint index, GLfloat x)
michael@0 6531 {
michael@0 6532 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
michael@0 6533
michael@0 6534 try
michael@0 6535 {
michael@0 6536 if (index >= gl::MAX_VERTEX_ATTRIBS)
michael@0 6537 {
michael@0 6538 return gl::error(GL_INVALID_VALUE);
michael@0 6539 }
michael@0 6540
michael@0 6541 gl::Context *context = gl::getNonLostContext();
michael@0 6542
michael@0 6543 if (context)
michael@0 6544 {
michael@0 6545 GLfloat vals[4] = { x, 0, 0, 1 };
michael@0 6546 context->setVertexAttrib(index, vals);
michael@0 6547 }
michael@0 6548 }
michael@0 6549 catch(std::bad_alloc&)
michael@0 6550 {
michael@0 6551 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6552 }
michael@0 6553 }
michael@0 6554
michael@0 6555 void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values)
michael@0 6556 {
michael@0 6557 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
michael@0 6558
michael@0 6559 try
michael@0 6560 {
michael@0 6561 if (index >= gl::MAX_VERTEX_ATTRIBS)
michael@0 6562 {
michael@0 6563 return gl::error(GL_INVALID_VALUE);
michael@0 6564 }
michael@0 6565
michael@0 6566 gl::Context *context = gl::getNonLostContext();
michael@0 6567
michael@0 6568 if (context)
michael@0 6569 {
michael@0 6570 GLfloat vals[4] = { values[0], 0, 0, 1 };
michael@0 6571 context->setVertexAttrib(index, vals);
michael@0 6572 }
michael@0 6573 }
michael@0 6574 catch(std::bad_alloc&)
michael@0 6575 {
michael@0 6576 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6577 }
michael@0 6578 }
michael@0 6579
michael@0 6580 void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
michael@0 6581 {
michael@0 6582 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
michael@0 6583
michael@0 6584 try
michael@0 6585 {
michael@0 6586 if (index >= gl::MAX_VERTEX_ATTRIBS)
michael@0 6587 {
michael@0 6588 return gl::error(GL_INVALID_VALUE);
michael@0 6589 }
michael@0 6590
michael@0 6591 gl::Context *context = gl::getNonLostContext();
michael@0 6592
michael@0 6593 if (context)
michael@0 6594 {
michael@0 6595 GLfloat vals[4] = { x, y, 0, 1 };
michael@0 6596 context->setVertexAttrib(index, vals);
michael@0 6597 }
michael@0 6598 }
michael@0 6599 catch(std::bad_alloc&)
michael@0 6600 {
michael@0 6601 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6602 }
michael@0 6603 }
michael@0 6604
michael@0 6605 void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values)
michael@0 6606 {
michael@0 6607 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
michael@0 6608
michael@0 6609 try
michael@0 6610 {
michael@0 6611 if (index >= gl::MAX_VERTEX_ATTRIBS)
michael@0 6612 {
michael@0 6613 return gl::error(GL_INVALID_VALUE);
michael@0 6614 }
michael@0 6615
michael@0 6616 gl::Context *context = gl::getNonLostContext();
michael@0 6617
michael@0 6618 if (context)
michael@0 6619 {
michael@0 6620 GLfloat vals[4] = { values[0], values[1], 0, 1 };
michael@0 6621 context->setVertexAttrib(index, vals);
michael@0 6622 }
michael@0 6623 }
michael@0 6624 catch(std::bad_alloc&)
michael@0 6625 {
michael@0 6626 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6627 }
michael@0 6628 }
michael@0 6629
michael@0 6630 void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
michael@0 6631 {
michael@0 6632 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f, GLfloat z = %f)", index, x, y, z);
michael@0 6633
michael@0 6634 try
michael@0 6635 {
michael@0 6636 if (index >= gl::MAX_VERTEX_ATTRIBS)
michael@0 6637 {
michael@0 6638 return gl::error(GL_INVALID_VALUE);
michael@0 6639 }
michael@0 6640
michael@0 6641 gl::Context *context = gl::getNonLostContext();
michael@0 6642
michael@0 6643 if (context)
michael@0 6644 {
michael@0 6645 GLfloat vals[4] = { x, y, z, 1 };
michael@0 6646 context->setVertexAttrib(index, vals);
michael@0 6647 }
michael@0 6648 }
michael@0 6649 catch(std::bad_alloc&)
michael@0 6650 {
michael@0 6651 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6652 }
michael@0 6653 }
michael@0 6654
michael@0 6655 void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values)
michael@0 6656 {
michael@0 6657 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
michael@0 6658
michael@0 6659 try
michael@0 6660 {
michael@0 6661 if (index >= gl::MAX_VERTEX_ATTRIBS)
michael@0 6662 {
michael@0 6663 return gl::error(GL_INVALID_VALUE);
michael@0 6664 }
michael@0 6665
michael@0 6666 gl::Context *context = gl::getNonLostContext();
michael@0 6667
michael@0 6668 if (context)
michael@0 6669 {
michael@0 6670 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
michael@0 6671 context->setVertexAttrib(index, vals);
michael@0 6672 }
michael@0 6673 }
michael@0 6674 catch(std::bad_alloc&)
michael@0 6675 {
michael@0 6676 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6677 }
michael@0 6678 }
michael@0 6679
michael@0 6680 void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
michael@0 6681 {
michael@0 6682 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f, GLfloat z = %f, GLfloat w = %f)", index, x, y, z, w);
michael@0 6683
michael@0 6684 try
michael@0 6685 {
michael@0 6686 if (index >= gl::MAX_VERTEX_ATTRIBS)
michael@0 6687 {
michael@0 6688 return gl::error(GL_INVALID_VALUE);
michael@0 6689 }
michael@0 6690
michael@0 6691 gl::Context *context = gl::getNonLostContext();
michael@0 6692
michael@0 6693 if (context)
michael@0 6694 {
michael@0 6695 GLfloat vals[4] = { x, y, z, w };
michael@0 6696 context->setVertexAttrib(index, vals);
michael@0 6697 }
michael@0 6698 }
michael@0 6699 catch(std::bad_alloc&)
michael@0 6700 {
michael@0 6701 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6702 }
michael@0 6703 }
michael@0 6704
michael@0 6705 void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values)
michael@0 6706 {
michael@0 6707 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
michael@0 6708
michael@0 6709 try
michael@0 6710 {
michael@0 6711 if (index >= gl::MAX_VERTEX_ATTRIBS)
michael@0 6712 {
michael@0 6713 return gl::error(GL_INVALID_VALUE);
michael@0 6714 }
michael@0 6715
michael@0 6716 gl::Context *context = gl::getNonLostContext();
michael@0 6717
michael@0 6718 if (context)
michael@0 6719 {
michael@0 6720 context->setVertexAttrib(index, values);
michael@0 6721 }
michael@0 6722 }
michael@0 6723 catch(std::bad_alloc&)
michael@0 6724 {
michael@0 6725 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6726 }
michael@0 6727 }
michael@0 6728
michael@0 6729 void __stdcall glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
michael@0 6730 {
michael@0 6731 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
michael@0 6732
michael@0 6733 try
michael@0 6734 {
michael@0 6735 if (index >= gl::MAX_VERTEX_ATTRIBS)
michael@0 6736 {
michael@0 6737 return gl::error(GL_INVALID_VALUE);
michael@0 6738 }
michael@0 6739
michael@0 6740 gl::Context *context = gl::getNonLostContext();
michael@0 6741
michael@0 6742 if (context)
michael@0 6743 {
michael@0 6744 context->setVertexAttribDivisor(index, divisor);
michael@0 6745 }
michael@0 6746 }
michael@0 6747 catch(std::bad_alloc&)
michael@0 6748 {
michael@0 6749 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6750 }
michael@0 6751 }
michael@0 6752
michael@0 6753 void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
michael@0 6754 {
michael@0 6755 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
michael@0 6756 "GLboolean normalized = %d, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
michael@0 6757 index, size, type, normalized, stride, ptr);
michael@0 6758
michael@0 6759 try
michael@0 6760 {
michael@0 6761 if (index >= gl::MAX_VERTEX_ATTRIBS)
michael@0 6762 {
michael@0 6763 return gl::error(GL_INVALID_VALUE);
michael@0 6764 }
michael@0 6765
michael@0 6766 if (size < 1 || size > 4)
michael@0 6767 {
michael@0 6768 return gl::error(GL_INVALID_VALUE);
michael@0 6769 }
michael@0 6770
michael@0 6771 switch (type)
michael@0 6772 {
michael@0 6773 case GL_BYTE:
michael@0 6774 case GL_UNSIGNED_BYTE:
michael@0 6775 case GL_SHORT:
michael@0 6776 case GL_UNSIGNED_SHORT:
michael@0 6777 case GL_FIXED:
michael@0 6778 case GL_FLOAT:
michael@0 6779 break;
michael@0 6780 default:
michael@0 6781 return gl::error(GL_INVALID_ENUM);
michael@0 6782 }
michael@0 6783
michael@0 6784 if (stride < 0)
michael@0 6785 {
michael@0 6786 return gl::error(GL_INVALID_VALUE);
michael@0 6787 }
michael@0 6788
michael@0 6789 gl::Context *context = gl::getNonLostContext();
michael@0 6790
michael@0 6791 if (context)
michael@0 6792 {
michael@0 6793 context->setVertexAttribState(index, context->getArrayBuffer(), size, type, (normalized == GL_TRUE), stride, ptr);
michael@0 6794 }
michael@0 6795 }
michael@0 6796 catch(std::bad_alloc&)
michael@0 6797 {
michael@0 6798 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6799 }
michael@0 6800 }
michael@0 6801
michael@0 6802 void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
michael@0 6803 {
michael@0 6804 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)", x, y, width, height);
michael@0 6805
michael@0 6806 try
michael@0 6807 {
michael@0 6808 if (width < 0 || height < 0)
michael@0 6809 {
michael@0 6810 return gl::error(GL_INVALID_VALUE);
michael@0 6811 }
michael@0 6812
michael@0 6813 gl::Context *context = gl::getNonLostContext();
michael@0 6814
michael@0 6815 if (context)
michael@0 6816 {
michael@0 6817 context->setViewportParams(x, y, width, height);
michael@0 6818 }
michael@0 6819 }
michael@0 6820 catch(std::bad_alloc&)
michael@0 6821 {
michael@0 6822 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6823 }
michael@0 6824 }
michael@0 6825
michael@0 6826 void __stdcall glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
michael@0 6827 GLbitfield mask, GLenum filter)
michael@0 6828 {
michael@0 6829 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
michael@0 6830 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
michael@0 6831 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
michael@0 6832 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
michael@0 6833
michael@0 6834 try
michael@0 6835 {
michael@0 6836 switch (filter)
michael@0 6837 {
michael@0 6838 case GL_NEAREST:
michael@0 6839 break;
michael@0 6840 default:
michael@0 6841 return gl::error(GL_INVALID_ENUM);
michael@0 6842 }
michael@0 6843
michael@0 6844 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
michael@0 6845 {
michael@0 6846 return gl::error(GL_INVALID_VALUE);
michael@0 6847 }
michael@0 6848
michael@0 6849 if (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0)
michael@0 6850 {
michael@0 6851 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation");
michael@0 6852 return gl::error(GL_INVALID_OPERATION);
michael@0 6853 }
michael@0 6854
michael@0 6855 gl::Context *context = gl::getNonLostContext();
michael@0 6856
michael@0 6857 if (context)
michael@0 6858 {
michael@0 6859 if (context->getReadFramebufferHandle() == context->getDrawFramebufferHandle())
michael@0 6860 {
michael@0 6861 ERR("Blits with the same source and destination framebuffer are not supported by this implementation.");
michael@0 6862 return gl::error(GL_INVALID_OPERATION);
michael@0 6863 }
michael@0 6864
michael@0 6865 context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask);
michael@0 6866 }
michael@0 6867 }
michael@0 6868 catch(std::bad_alloc&)
michael@0 6869 {
michael@0 6870 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6871 }
michael@0 6872 }
michael@0 6873
michael@0 6874 void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
michael@0 6875 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
michael@0 6876 {
michael@0 6877 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
michael@0 6878 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
michael@0 6879 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
michael@0 6880 target, level, internalformat, width, height, depth, border, format, type, pixels);
michael@0 6881
michael@0 6882 try
michael@0 6883 {
michael@0 6884 UNIMPLEMENTED(); // FIXME
michael@0 6885 }
michael@0 6886 catch(std::bad_alloc&)
michael@0 6887 {
michael@0 6888 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6889 }
michael@0 6890 }
michael@0 6891
michael@0 6892 void __stdcall glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
michael@0 6893 GLenum *binaryFormat, void *binary)
michael@0 6894 {
michael@0 6895 EVENT("(GLenum program = 0x%X, bufSize = %d, length = 0x%0.8p, binaryFormat = 0x%0.8p, binary = 0x%0.8p)",
michael@0 6896 program, bufSize, length, binaryFormat, binary);
michael@0 6897
michael@0 6898 try
michael@0 6899 {
michael@0 6900 gl::Context *context = gl::getNonLostContext();
michael@0 6901
michael@0 6902 if (context)
michael@0 6903 {
michael@0 6904 gl::Program *programObject = context->getProgram(program);
michael@0 6905
michael@0 6906 if (!programObject || !programObject->isLinked())
michael@0 6907 {
michael@0 6908 return gl::error(GL_INVALID_OPERATION);
michael@0 6909 }
michael@0 6910
michael@0 6911 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
michael@0 6912
michael@0 6913 if (!programBinary)
michael@0 6914 {
michael@0 6915 return gl::error(GL_INVALID_OPERATION);
michael@0 6916 }
michael@0 6917
michael@0 6918 if (!programBinary->save(binary, bufSize, length))
michael@0 6919 {
michael@0 6920 return gl::error(GL_INVALID_OPERATION);
michael@0 6921 }
michael@0 6922
michael@0 6923 *binaryFormat = GL_PROGRAM_BINARY_ANGLE;
michael@0 6924 }
michael@0 6925 }
michael@0 6926 catch(std::bad_alloc&)
michael@0 6927 {
michael@0 6928 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6929 }
michael@0 6930 }
michael@0 6931
michael@0 6932 void __stdcall glProgramBinaryOES(GLuint program, GLenum binaryFormat,
michael@0 6933 const void *binary, GLint length)
michael@0 6934 {
michael@0 6935 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
michael@0 6936 program, binaryFormat, binary, length);
michael@0 6937
michael@0 6938 try
michael@0 6939 {
michael@0 6940 gl::Context *context = gl::getNonLostContext();
michael@0 6941
michael@0 6942 if (context)
michael@0 6943 {
michael@0 6944 if (binaryFormat != GL_PROGRAM_BINARY_ANGLE)
michael@0 6945 {
michael@0 6946 return gl::error(GL_INVALID_ENUM);
michael@0 6947 }
michael@0 6948
michael@0 6949 gl::Program *programObject = context->getProgram(program);
michael@0 6950
michael@0 6951 if (!programObject)
michael@0 6952 {
michael@0 6953 return gl::error(GL_INVALID_OPERATION);
michael@0 6954 }
michael@0 6955
michael@0 6956 context->setProgramBinary(program, binary, length);
michael@0 6957 }
michael@0 6958 }
michael@0 6959 catch(std::bad_alloc&)
michael@0 6960 {
michael@0 6961 return gl::error(GL_OUT_OF_MEMORY);
michael@0 6962 }
michael@0 6963 }
michael@0 6964
michael@0 6965 void __stdcall glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
michael@0 6966 {
michael@0 6967 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
michael@0 6968
michael@0 6969 try
michael@0 6970 {
michael@0 6971 gl::Context *context = gl::getNonLostContext();
michael@0 6972
michael@0 6973 if (context)
michael@0 6974 {
michael@0 6975 if (n < 0 || (unsigned int)n > context->getMaximumRenderTargets())
michael@0 6976 {
michael@0 6977 return gl::error(GL_INVALID_VALUE);
michael@0 6978 }
michael@0 6979
michael@0 6980 if (context->getDrawFramebufferHandle() == 0)
michael@0 6981 {
michael@0 6982 if (n != 1)
michael@0 6983 {
michael@0 6984 return gl::error(GL_INVALID_OPERATION);
michael@0 6985 }
michael@0 6986
michael@0 6987 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
michael@0 6988 {
michael@0 6989 return gl::error(GL_INVALID_OPERATION);
michael@0 6990 }
michael@0 6991 }
michael@0 6992 else
michael@0 6993 {
michael@0 6994 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
michael@0 6995 {
michael@0 6996 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
michael@0 6997 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
michael@0 6998 {
michael@0 6999 return gl::error(GL_INVALID_OPERATION);
michael@0 7000 }
michael@0 7001 }
michael@0 7002 }
michael@0 7003
michael@0 7004 gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
michael@0 7005
michael@0 7006 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
michael@0 7007 {
michael@0 7008 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
michael@0 7009 }
michael@0 7010
michael@0 7011 for (int colorAttachment = n; colorAttachment < (int)context->getMaximumRenderTargets(); colorAttachment++)
michael@0 7012 {
michael@0 7013 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
michael@0 7014 }
michael@0 7015 }
michael@0 7016 }
michael@0 7017 catch (std::bad_alloc&)
michael@0 7018 {
michael@0 7019 return gl::error(GL_OUT_OF_MEMORY);
michael@0 7020 }
michael@0 7021 }
michael@0 7022
michael@0 7023 __eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname)
michael@0 7024 {
michael@0 7025 struct Extension
michael@0 7026 {
michael@0 7027 const char *name;
michael@0 7028 __eglMustCastToProperFunctionPointerType address;
michael@0 7029 };
michael@0 7030
michael@0 7031 static const Extension glExtensions[] =
michael@0 7032 {
michael@0 7033 {"glTexImage3DOES", (__eglMustCastToProperFunctionPointerType)glTexImage3DOES},
michael@0 7034 {"glBlitFramebufferANGLE", (__eglMustCastToProperFunctionPointerType)glBlitFramebufferANGLE},
michael@0 7035 {"glRenderbufferStorageMultisampleANGLE", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageMultisampleANGLE},
michael@0 7036 {"glDeleteFencesNV", (__eglMustCastToProperFunctionPointerType)glDeleteFencesNV},
michael@0 7037 {"glGenFencesNV", (__eglMustCastToProperFunctionPointerType)glGenFencesNV},
michael@0 7038 {"glIsFenceNV", (__eglMustCastToProperFunctionPointerType)glIsFenceNV},
michael@0 7039 {"glTestFenceNV", (__eglMustCastToProperFunctionPointerType)glTestFenceNV},
michael@0 7040 {"glGetFenceivNV", (__eglMustCastToProperFunctionPointerType)glGetFenceivNV},
michael@0 7041 {"glFinishFenceNV", (__eglMustCastToProperFunctionPointerType)glFinishFenceNV},
michael@0 7042 {"glSetFenceNV", (__eglMustCastToProperFunctionPointerType)glSetFenceNV},
michael@0 7043 {"glGetTranslatedShaderSourceANGLE", (__eglMustCastToProperFunctionPointerType)glGetTranslatedShaderSourceANGLE},
michael@0 7044 {"glTexStorage2DEXT", (__eglMustCastToProperFunctionPointerType)glTexStorage2DEXT},
michael@0 7045 {"glGetGraphicsResetStatusEXT", (__eglMustCastToProperFunctionPointerType)glGetGraphicsResetStatusEXT},
michael@0 7046 {"glReadnPixelsEXT", (__eglMustCastToProperFunctionPointerType)glReadnPixelsEXT},
michael@0 7047 {"glGetnUniformfvEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformfvEXT},
michael@0 7048 {"glGetnUniformivEXT", (__eglMustCastToProperFunctionPointerType)glGetnUniformivEXT},
michael@0 7049 {"glGenQueriesEXT", (__eglMustCastToProperFunctionPointerType)glGenQueriesEXT},
michael@0 7050 {"glDeleteQueriesEXT", (__eglMustCastToProperFunctionPointerType)glDeleteQueriesEXT},
michael@0 7051 {"glIsQueryEXT", (__eglMustCastToProperFunctionPointerType)glIsQueryEXT},
michael@0 7052 {"glBeginQueryEXT", (__eglMustCastToProperFunctionPointerType)glBeginQueryEXT},
michael@0 7053 {"glEndQueryEXT", (__eglMustCastToProperFunctionPointerType)glEndQueryEXT},
michael@0 7054 {"glGetQueryivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryivEXT},
michael@0 7055 {"glGetQueryObjectuivEXT", (__eglMustCastToProperFunctionPointerType)glGetQueryObjectuivEXT},
michael@0 7056 {"glDrawBuffersEXT", (__eglMustCastToProperFunctionPointerType)glDrawBuffersEXT},
michael@0 7057 {"glVertexAttribDivisorANGLE", (__eglMustCastToProperFunctionPointerType)glVertexAttribDivisorANGLE},
michael@0 7058 {"glDrawArraysInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawArraysInstancedANGLE},
michael@0 7059 {"glDrawElementsInstancedANGLE", (__eglMustCastToProperFunctionPointerType)glDrawElementsInstancedANGLE},
michael@0 7060 {"glGetProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glGetProgramBinaryOES},
michael@0 7061 {"glProgramBinaryOES", (__eglMustCastToProperFunctionPointerType)glProgramBinaryOES}, };
michael@0 7062
michael@0 7063 for (unsigned int ext = 0; ext < ArraySize(glExtensions); ext++)
michael@0 7064 {
michael@0 7065 if (strcmp(procname, glExtensions[ext].name) == 0)
michael@0 7066 {
michael@0 7067 return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address;
michael@0 7068 }
michael@0 7069 }
michael@0 7070
michael@0 7071 return NULL;
michael@0 7072 }
michael@0 7073
michael@0 7074 // Non-public functions used by EGL
michael@0 7075
michael@0 7076 bool __stdcall glBindTexImage(egl::Surface *surface)
michael@0 7077 {
michael@0 7078 EVENT("(egl::Surface* surface = 0x%0.8p)",
michael@0 7079 surface);
michael@0 7080
michael@0 7081 try
michael@0 7082 {
michael@0 7083 gl::Context *context = gl::getNonLostContext();
michael@0 7084
michael@0 7085 if (context)
michael@0 7086 {
michael@0 7087 gl::Texture2D *textureObject = context->getTexture2D();
michael@0 7088
michael@0 7089 if (textureObject->isImmutable())
michael@0 7090 {
michael@0 7091 return false;
michael@0 7092 }
michael@0 7093
michael@0 7094 if (textureObject)
michael@0 7095 {
michael@0 7096 textureObject->bindTexImage(surface);
michael@0 7097 }
michael@0 7098 }
michael@0 7099 }
michael@0 7100 catch(std::bad_alloc&)
michael@0 7101 {
michael@0 7102 return gl::error(GL_OUT_OF_MEMORY, false);
michael@0 7103 }
michael@0 7104
michael@0 7105 return true;
michael@0 7106 }
michael@0 7107
michael@0 7108 }

mercurial