daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // libGLESv2.cpp: Implements the exported OpenGL ES 2.0 functions. |
| 8 | |
| 9 | #define GL_APICALL |
| 10 | #include <GLES2/gl2.h> |
| 11 | #include <GLES2/gl2ext.h> |
| 12 | |
| 13 | #include "Context.h" |
| 14 | #include "main.h" |
| 15 | #include "Program.h" |
| 16 | #include "Shader.h" |
| 17 | #include "Buffer.h" |
| 18 | #include "Texture.h" |
| 19 | #include "Renderbuffer.h" |
| 20 | #include "Framebuffer.h" |
| 21 | #include "mathutil.h" |
| 22 | #include "debug.h" |
| 23 | |
| 24 | #include <exception> |
| 25 | |
| 26 | extern "C" |
| 27 | { |
| 28 | |
| 29 | void __stdcall glActiveTexture(GLenum texture) |
| 30 | { |
| 31 | TRACE("GLenum texture = 0x%X", texture); |
| 32 | |
| 33 | try |
| 34 | { |
| 35 | if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + gl::MAX_TEXTURE_IMAGE_UNITS - 1) |
| 36 | { |
| 37 | return error(GL_INVALID_ENUM); |
| 38 | } |
| 39 | |
| 40 | gl::Context *context = gl::getContext(); |
| 41 | |
| 42 | if (context) |
| 43 | { |
| 44 | context->activeSampler = texture - GL_TEXTURE0; |
| 45 | } |
| 46 | } |
| 47 | catch(std::bad_alloc&) |
| 48 | { |
| 49 | return error(GL_OUT_OF_MEMORY); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | void __stdcall glAttachShader(GLuint program, GLuint shader) |
| 54 | { |
| 55 | TRACE("GLuint program = %d, GLuint shader = %d", program, shader); |
| 56 | |
| 57 | try |
| 58 | { |
| 59 | gl::Context *context = gl::getContext(); |
| 60 | |
| 61 | if (context) |
| 62 | { |
| 63 | gl::Program *programObject = context->getProgram(program); |
| 64 | gl::Shader *shaderObject = context->getShader(shader); |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 65 | |
daniel@transgaming.com | e2b2212 | 2010-03-11 19:22:14 +0000 | [diff] [blame] | 66 | if (!programObject || !shaderObject) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 67 | { |
| 68 | return error(GL_INVALID_VALUE); |
| 69 | } |
| 70 | |
| 71 | if (!programObject->attachShader(shaderObject)) |
| 72 | { |
| 73 | return error(GL_INVALID_OPERATION); |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | catch(std::bad_alloc&) |
| 78 | { |
| 79 | return error(GL_OUT_OF_MEMORY); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | void __stdcall glBindAttribLocation(GLuint program, GLuint index, const char* name) |
| 84 | { |
| 85 | TRACE("GLuint program = %d, GLuint index = %d, const char* name = 0x%0.8p", program, index, name); |
| 86 | |
| 87 | try |
| 88 | { |
| 89 | if (index >= gl::MAX_VERTEX_ATTRIBS) |
| 90 | { |
| 91 | return error(GL_INVALID_VALUE); |
| 92 | } |
| 93 | |
| 94 | gl::Context *context = gl::getContext(); |
| 95 | |
| 96 | if (context) |
| 97 | { |
| 98 | gl::Program *programObject = context->getProgram(program); |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 99 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 100 | if (!programObject) |
| 101 | { |
| 102 | return error(GL_INVALID_VALUE); |
| 103 | } |
| 104 | |
| 105 | programObject->bindAttributeLocation(index, name); |
| 106 | } |
| 107 | } |
| 108 | catch(std::bad_alloc&) |
| 109 | { |
| 110 | return error(GL_OUT_OF_MEMORY); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | void __stdcall glBindBuffer(GLenum target, GLuint buffer) |
| 115 | { |
| 116 | TRACE("GLenum target = 0x%X, GLuint buffer = %d", target, buffer); |
| 117 | |
| 118 | try |
| 119 | { |
| 120 | gl::Context *context = gl::getContext(); |
| 121 | |
| 122 | if (context) |
| 123 | { |
| 124 | switch (target) |
| 125 | { |
| 126 | case GL_ARRAY_BUFFER: |
| 127 | context->bindArrayBuffer(buffer); |
| 128 | return; |
| 129 | case GL_ELEMENT_ARRAY_BUFFER: |
| 130 | context->bindElementArrayBuffer(buffer); |
| 131 | return; |
| 132 | default: |
| 133 | return error(GL_INVALID_ENUM); |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | catch(std::bad_alloc&) |
| 138 | { |
| 139 | return error(GL_OUT_OF_MEMORY); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | void __stdcall glBindFramebuffer(GLenum target, GLuint framebuffer) |
| 144 | { |
| 145 | TRACE("GLenum target = 0x%X, GLuint framebuffer = %d", target, framebuffer); |
| 146 | |
| 147 | try |
| 148 | { |
| 149 | if (target != GL_FRAMEBUFFER) |
| 150 | { |
| 151 | return error(GL_INVALID_ENUM); |
| 152 | } |
| 153 | |
| 154 | gl::Context *context = gl::getContext(); |
| 155 | |
| 156 | if (context) |
| 157 | { |
| 158 | context->bindFramebuffer(framebuffer); |
| 159 | } |
| 160 | } |
| 161 | catch(std::bad_alloc&) |
| 162 | { |
| 163 | return error(GL_OUT_OF_MEMORY); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | void __stdcall glBindRenderbuffer(GLenum target, GLuint renderbuffer) |
| 168 | { |
| 169 | TRACE("GLenum target = 0x%X, GLuint renderbuffer = %d", target, renderbuffer); |
| 170 | |
| 171 | try |
| 172 | { |
| 173 | if (target != GL_RENDERBUFFER) |
| 174 | { |
| 175 | return error(GL_INVALID_ENUM); |
| 176 | } |
| 177 | |
| 178 | gl::Context *context = gl::getContext(); |
| 179 | |
| 180 | if (context) |
| 181 | { |
| 182 | context->bindRenderbuffer(renderbuffer); |
| 183 | } |
| 184 | } |
| 185 | catch(std::bad_alloc&) |
| 186 | { |
| 187 | return error(GL_OUT_OF_MEMORY); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | void __stdcall glBindTexture(GLenum target, GLuint texture) |
| 192 | { |
| 193 | TRACE("GLenum target = 0x%X, GLuint texture = %d", target, texture); |
| 194 | |
| 195 | try |
| 196 | { |
| 197 | gl::Context *context = gl::getContext(); |
| 198 | |
| 199 | if (context) |
| 200 | { |
| 201 | gl::Texture *textureObject = context->getTexture(texture); |
| 202 | |
| 203 | if (textureObject && textureObject->getTarget() != target && texture != 0) |
| 204 | { |
| 205 | return error(GL_INVALID_OPERATION); |
| 206 | } |
| 207 | |
| 208 | switch (target) |
| 209 | { |
| 210 | case GL_TEXTURE_2D: |
| 211 | context->bindTexture2D(texture); |
| 212 | return; |
| 213 | case GL_TEXTURE_CUBE_MAP: |
| 214 | context->bindTextureCubeMap(texture); |
| 215 | return; |
| 216 | default: |
| 217 | return error(GL_INVALID_ENUM); |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | catch(std::bad_alloc&) |
| 222 | { |
| 223 | return error(GL_OUT_OF_MEMORY); |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | void __stdcall glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) |
| 228 | { |
| 229 | TRACE("GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f", red, green, blue, alpha); |
| 230 | |
| 231 | try |
| 232 | { |
| 233 | gl::Context* context = gl::getContext(); |
| 234 | |
| 235 | if (context) |
| 236 | { |
| 237 | context->blendColor.red = gl::clamp01(red); |
| 238 | context->blendColor.blue = gl::clamp01(blue); |
| 239 | context->blendColor.green = gl::clamp01(green); |
| 240 | context->blendColor.alpha = gl::clamp01(alpha); |
| 241 | } |
| 242 | } |
| 243 | catch(std::bad_alloc&) |
| 244 | { |
| 245 | return error(GL_OUT_OF_MEMORY); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | void __stdcall glBlendEquation(GLenum mode) |
| 250 | { |
| 251 | glBlendEquationSeparate(mode, mode); |
| 252 | } |
| 253 | |
| 254 | void __stdcall glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) |
| 255 | { |
| 256 | TRACE("GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X", modeRGB, modeAlpha); |
| 257 | |
| 258 | try |
| 259 | { |
| 260 | switch (modeRGB) |
| 261 | { |
| 262 | case GL_FUNC_ADD: |
| 263 | case GL_FUNC_SUBTRACT: |
| 264 | case GL_FUNC_REVERSE_SUBTRACT: |
| 265 | break; |
| 266 | default: |
| 267 | return error(GL_INVALID_ENUM); |
| 268 | } |
| 269 | |
| 270 | switch (modeAlpha) |
| 271 | { |
| 272 | case GL_FUNC_ADD: |
| 273 | case GL_FUNC_SUBTRACT: |
| 274 | case GL_FUNC_REVERSE_SUBTRACT: |
| 275 | break; |
| 276 | default: |
| 277 | return error(GL_INVALID_ENUM); |
| 278 | } |
| 279 | |
| 280 | gl::Context *context = gl::getContext(); |
| 281 | |
| 282 | if (context) |
| 283 | { |
| 284 | context->blendEquationRGB = modeRGB; |
| 285 | context->blendEquationAlpha = modeAlpha; |
| 286 | } |
| 287 | } |
| 288 | catch(std::bad_alloc&) |
| 289 | { |
| 290 | return error(GL_OUT_OF_MEMORY); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | void __stdcall glBlendFunc(GLenum sfactor, GLenum dfactor) |
| 295 | { |
| 296 | glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor); |
| 297 | } |
| 298 | |
| 299 | void __stdcall glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) |
| 300 | { |
| 301 | TRACE("GLenum srcRGB = 0x%X, GLenum dstRGB = 0x%X, GLenum srcAlpha = 0x%X, GLenum dstAlpha = 0x%X", srcRGB, dstRGB, srcAlpha, dstAlpha); |
| 302 | |
| 303 | try |
| 304 | { |
| 305 | switch (srcRGB) |
| 306 | { |
| 307 | case GL_ZERO: |
| 308 | case GL_ONE: |
| 309 | case GL_SRC_COLOR: |
| 310 | case GL_ONE_MINUS_SRC_COLOR: |
| 311 | case GL_DST_COLOR: |
| 312 | case GL_ONE_MINUS_DST_COLOR: |
| 313 | case GL_SRC_ALPHA: |
| 314 | case GL_ONE_MINUS_SRC_ALPHA: |
| 315 | case GL_DST_ALPHA: |
| 316 | case GL_ONE_MINUS_DST_ALPHA: |
| 317 | case GL_CONSTANT_COLOR: |
| 318 | case GL_ONE_MINUS_CONSTANT_COLOR: |
| 319 | case GL_CONSTANT_ALPHA: |
| 320 | case GL_ONE_MINUS_CONSTANT_ALPHA: |
| 321 | case GL_SRC_ALPHA_SATURATE: |
| 322 | break; |
| 323 | default: |
| 324 | return error(GL_INVALID_ENUM); |
| 325 | } |
| 326 | |
| 327 | switch (dstRGB) |
| 328 | { |
| 329 | case GL_ZERO: |
| 330 | case GL_ONE: |
| 331 | case GL_SRC_COLOR: |
| 332 | case GL_ONE_MINUS_SRC_COLOR: |
| 333 | case GL_DST_COLOR: |
| 334 | case GL_ONE_MINUS_DST_COLOR: |
| 335 | case GL_SRC_ALPHA: |
| 336 | case GL_ONE_MINUS_SRC_ALPHA: |
| 337 | case GL_DST_ALPHA: |
| 338 | case GL_ONE_MINUS_DST_ALPHA: |
| 339 | case GL_CONSTANT_COLOR: |
| 340 | case GL_ONE_MINUS_CONSTANT_COLOR: |
| 341 | case GL_CONSTANT_ALPHA: |
| 342 | case GL_ONE_MINUS_CONSTANT_ALPHA: |
| 343 | break; |
| 344 | default: |
| 345 | return error(GL_INVALID_ENUM); |
| 346 | } |
| 347 | |
| 348 | switch (srcAlpha) |
| 349 | { |
| 350 | case GL_ZERO: |
| 351 | case GL_ONE: |
| 352 | case GL_SRC_COLOR: |
| 353 | case GL_ONE_MINUS_SRC_COLOR: |
| 354 | case GL_DST_COLOR: |
| 355 | case GL_ONE_MINUS_DST_COLOR: |
| 356 | case GL_SRC_ALPHA: |
| 357 | case GL_ONE_MINUS_SRC_ALPHA: |
| 358 | case GL_DST_ALPHA: |
| 359 | case GL_ONE_MINUS_DST_ALPHA: |
| 360 | case GL_CONSTANT_COLOR: |
| 361 | case GL_ONE_MINUS_CONSTANT_COLOR: |
| 362 | case GL_CONSTANT_ALPHA: |
| 363 | case GL_ONE_MINUS_CONSTANT_ALPHA: |
| 364 | case GL_SRC_ALPHA_SATURATE: |
| 365 | break; |
| 366 | default: |
| 367 | return error(GL_INVALID_ENUM); |
| 368 | } |
| 369 | |
| 370 | switch (dstAlpha) |
| 371 | { |
| 372 | case GL_ZERO: |
| 373 | case GL_ONE: |
| 374 | case GL_SRC_COLOR: |
| 375 | case GL_ONE_MINUS_SRC_COLOR: |
| 376 | case GL_DST_COLOR: |
| 377 | case GL_ONE_MINUS_DST_COLOR: |
| 378 | case GL_SRC_ALPHA: |
| 379 | case GL_ONE_MINUS_SRC_ALPHA: |
| 380 | case GL_DST_ALPHA: |
| 381 | case GL_ONE_MINUS_DST_ALPHA: |
| 382 | case GL_CONSTANT_COLOR: |
| 383 | case GL_ONE_MINUS_CONSTANT_COLOR: |
| 384 | case GL_CONSTANT_ALPHA: |
| 385 | case GL_ONE_MINUS_CONSTANT_ALPHA: |
| 386 | break; |
| 387 | default: |
| 388 | return error(GL_INVALID_ENUM); |
| 389 | } |
| 390 | |
| 391 | if ((srcRGB == GL_CONSTANT_COLOR && dstRGB == GL_CONSTANT_ALPHA) || |
| 392 | (srcRGB == GL_CONSTANT_ALPHA && dstRGB == GL_CONSTANT_COLOR)) |
| 393 | { |
| 394 | UNIMPLEMENTED(); |
| 395 | } |
| 396 | |
| 397 | gl::Context *context = gl::getContext(); |
| 398 | |
| 399 | if (context) |
| 400 | { |
| 401 | context->sourceBlendRGB = srcRGB; |
| 402 | context->sourceBlendAlpha = srcAlpha; |
| 403 | context->destBlendRGB = dstRGB; |
| 404 | context->destBlendAlpha = dstAlpha; |
| 405 | } |
| 406 | } |
| 407 | catch(std::bad_alloc&) |
| 408 | { |
| 409 | return error(GL_OUT_OF_MEMORY); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | void __stdcall glBufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage) |
| 414 | { |
| 415 | TRACE("GLenum target = 0x%X, GLsizeiptr size = %d, const void* data = 0x%0.8p, GLenum usage = %d", target, size, data, usage); |
| 416 | |
| 417 | try |
| 418 | { |
| 419 | if (size < 0) |
| 420 | { |
| 421 | return error(GL_INVALID_VALUE); |
| 422 | } |
| 423 | |
| 424 | switch (usage) |
| 425 | { |
| 426 | case GL_STREAM_DRAW: |
| 427 | case GL_STATIC_DRAW: |
| 428 | case GL_DYNAMIC_DRAW: |
| 429 | break; |
| 430 | default: |
| 431 | return error(GL_INVALID_ENUM); |
| 432 | } |
| 433 | |
| 434 | gl::Context *context = gl::getContext(); |
| 435 | |
| 436 | if (context) |
| 437 | { |
| 438 | gl::Buffer *buffer; |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 439 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 440 | switch (target) |
| 441 | { |
| 442 | case GL_ARRAY_BUFFER: |
| 443 | buffer = context->getArrayBuffer(); |
| 444 | break; |
| 445 | case GL_ELEMENT_ARRAY_BUFFER: |
| 446 | buffer = context->getElementArrayBuffer(); |
| 447 | break; |
| 448 | default: |
| 449 | return error(GL_INVALID_ENUM); |
| 450 | } |
| 451 | |
| 452 | if (!buffer) |
| 453 | { |
| 454 | return error(GL_INVALID_OPERATION); |
| 455 | } |
| 456 | |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 457 | buffer->bufferData(data, size, usage); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 458 | } |
| 459 | } |
| 460 | catch(std::bad_alloc&) |
| 461 | { |
| 462 | return error(GL_OUT_OF_MEMORY); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | void __stdcall glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data) |
| 467 | { |
| 468 | TRACE("GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr size = %d, const void* data = 0x%0.8p", target, offset, size, data); |
| 469 | |
| 470 | try |
| 471 | { |
| 472 | if (size < 0) |
| 473 | { |
| 474 | return error(GL_INVALID_VALUE); |
| 475 | } |
| 476 | |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 477 | gl::Context *context = gl::getContext(); |
| 478 | |
| 479 | if (context) |
| 480 | { |
| 481 | gl::Buffer *buffer; |
| 482 | |
| 483 | switch (target) |
| 484 | { |
| 485 | case GL_ARRAY_BUFFER: |
| 486 | buffer = context->getArrayBuffer(); |
| 487 | break; |
| 488 | case GL_ELEMENT_ARRAY_BUFFER: |
| 489 | buffer = context->getElementArrayBuffer(); |
| 490 | break; |
| 491 | default: |
| 492 | return error(GL_INVALID_ENUM); |
| 493 | } |
| 494 | |
| 495 | if (!buffer) |
| 496 | { |
| 497 | return error(GL_INVALID_OPERATION); |
| 498 | } |
| 499 | |
| 500 | GLenum err = buffer->bufferSubData(data, size, offset); |
| 501 | |
| 502 | if (err != GL_NO_ERROR) |
| 503 | { |
| 504 | return error(err); |
| 505 | } |
| 506 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 507 | } |
| 508 | catch(std::bad_alloc&) |
| 509 | { |
| 510 | return error(GL_OUT_OF_MEMORY); |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | GLenum __stdcall glCheckFramebufferStatus(GLenum target) |
| 515 | { |
| 516 | TRACE("GLenum target = 0x%X", target); |
| 517 | |
| 518 | try |
| 519 | { |
| 520 | if (target != GL_FRAMEBUFFER) |
| 521 | { |
| 522 | return error(GL_INVALID_ENUM, 0); |
| 523 | } |
| 524 | |
| 525 | gl::Context *context = gl::getContext(); |
| 526 | |
| 527 | if (context) |
| 528 | { |
| 529 | gl::Framebuffer *framebuffer = context->getFramebuffer(); |
| 530 | |
| 531 | return framebuffer->completeness(); |
| 532 | } |
| 533 | } |
| 534 | catch(std::bad_alloc&) |
| 535 | { |
| 536 | return error(GL_OUT_OF_MEMORY, 0); |
| 537 | } |
| 538 | |
| 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | void __stdcall glClear(GLbitfield mask) |
| 543 | { |
| 544 | TRACE("GLbitfield mask = %X", mask); |
| 545 | |
| 546 | try |
| 547 | { |
| 548 | gl::Context *context = gl::getContext(); |
| 549 | |
| 550 | if (context) |
| 551 | { |
| 552 | context->clear(mask); |
| 553 | } |
| 554 | } |
| 555 | catch(std::bad_alloc&) |
| 556 | { |
| 557 | return error(GL_OUT_OF_MEMORY); |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | void __stdcall glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) |
| 562 | { |
| 563 | TRACE("GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f", red, green, blue, alpha); |
| 564 | |
| 565 | try |
| 566 | { |
| 567 | gl::Context *context = gl::getContext(); |
| 568 | |
| 569 | if (context) |
| 570 | { |
| 571 | context->setClearColor(red, green, blue, alpha); |
| 572 | } |
| 573 | } |
| 574 | catch(std::bad_alloc&) |
| 575 | { |
| 576 | return error(GL_OUT_OF_MEMORY); |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | void __stdcall glClearDepthf(GLclampf depth) |
| 581 | { |
| 582 | TRACE("GLclampf depth = %f", depth); |
| 583 | |
| 584 | try |
| 585 | { |
| 586 | gl::Context *context = gl::getContext(); |
| 587 | |
| 588 | if (context) |
| 589 | { |
| 590 | context->setClearDepth(depth); |
| 591 | } |
| 592 | } |
| 593 | catch(std::bad_alloc&) |
| 594 | { |
| 595 | return error(GL_OUT_OF_MEMORY); |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | void __stdcall glClearStencil(GLint s) |
| 600 | { |
| 601 | TRACE("GLint s = %d", s); |
| 602 | |
| 603 | try |
| 604 | { |
| 605 | gl::Context *context = gl::getContext(); |
| 606 | |
| 607 | if (context) |
| 608 | { |
| 609 | context->setClearStencil(s); |
| 610 | } |
| 611 | } |
| 612 | catch(std::bad_alloc&) |
| 613 | { |
| 614 | return error(GL_OUT_OF_MEMORY); |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | void __stdcall glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) |
| 619 | { |
| 620 | TRACE("GLboolean red = %d, GLboolean green = %d, GLboolean blue = %d, GLboolean alpha = %d", red, green, blue, alpha); |
| 621 | |
| 622 | try |
| 623 | { |
| 624 | gl::Context *context = gl::getContext(); |
| 625 | |
| 626 | if (context) |
| 627 | { |
| 628 | context->colorMaskRed = red != GL_FALSE; |
| 629 | context->colorMaskGreen = green != GL_FALSE; |
| 630 | context->colorMaskBlue = blue != GL_FALSE; |
| 631 | context->colorMaskAlpha = alpha != GL_FALSE; |
| 632 | } |
| 633 | } |
| 634 | catch(std::bad_alloc&) |
| 635 | { |
| 636 | return error(GL_OUT_OF_MEMORY); |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | void __stdcall glCompileShader(GLuint shader) |
| 641 | { |
| 642 | TRACE("GLuint shader = %d", shader); |
| 643 | |
| 644 | try |
| 645 | { |
| 646 | gl::Context *context = gl::getContext(); |
| 647 | |
| 648 | if (context) |
| 649 | { |
| 650 | gl::Shader *shaderObject = context->getShader(shader); |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 651 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 652 | if (!shaderObject) |
| 653 | { |
| 654 | return error(GL_INVALID_VALUE); |
| 655 | } |
| 656 | |
| 657 | shaderObject->compile(); |
| 658 | } |
| 659 | } |
| 660 | catch(std::bad_alloc&) |
| 661 | { |
| 662 | return error(GL_OUT_OF_MEMORY); |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | void __stdcall glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void* data) |
| 667 | { |
| 668 | TRACE("GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const void* data = 0x%0.8p", |
| 669 | target, level, internalformat, width, height, border, imageSize, data); |
| 670 | |
| 671 | try |
| 672 | { |
| 673 | if (width < 0 || height < 0 || imageSize < 0) |
| 674 | { |
| 675 | return error(GL_INVALID_VALUE); |
| 676 | } |
| 677 | |
| 678 | UNIMPLEMENTED(); // FIXME |
| 679 | } |
| 680 | catch(std::bad_alloc&) |
| 681 | { |
| 682 | return error(GL_OUT_OF_MEMORY); |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | void __stdcall glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void* data) |
| 687 | { |
| 688 | TRACE("GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLsizei imageSize = %d, const void* data = 0x%0.8p", |
| 689 | target, level, xoffset, yoffset, width, height, format, imageSize, data); |
| 690 | |
| 691 | try |
| 692 | { |
| 693 | if (width < 0 || height < 0 || imageSize < 0) |
| 694 | { |
| 695 | return error(GL_INVALID_VALUE); |
| 696 | } |
| 697 | |
| 698 | UNIMPLEMENTED(); // FIXME |
| 699 | } |
| 700 | catch(std::bad_alloc&) |
| 701 | { |
| 702 | return error(GL_OUT_OF_MEMORY); |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) |
| 707 | { |
| 708 | TRACE("GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d", |
| 709 | target, level, internalformat, x, y, width, height, border); |
| 710 | |
| 711 | try |
| 712 | { |
| 713 | if (width < 0 || height < 0) |
| 714 | { |
| 715 | return error(GL_INVALID_VALUE); |
| 716 | } |
| 717 | |
| 718 | UNIMPLEMENTED(); // FIXME |
| 719 | } |
| 720 | catch(std::bad_alloc&) |
| 721 | { |
| 722 | return error(GL_OUT_OF_MEMORY); |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | void __stdcall glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) |
| 727 | { |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 728 | TRACE("GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d", |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 729 | target, level, xoffset, yoffset, x, y, width, height); |
| 730 | |
| 731 | try |
| 732 | { |
| 733 | if (width < 0 || height < 0) |
| 734 | { |
| 735 | return error(GL_INVALID_VALUE); |
| 736 | } |
| 737 | |
| 738 | UNIMPLEMENTED(); // FIXME |
| 739 | } |
| 740 | catch(std::bad_alloc&) |
| 741 | { |
| 742 | return error(GL_OUT_OF_MEMORY); |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | GLuint __stdcall glCreateProgram(void) |
| 747 | { |
| 748 | TRACE(""); |
| 749 | |
| 750 | try |
| 751 | { |
| 752 | gl::Context *context = gl::getContext(); |
| 753 | |
| 754 | if (context) |
| 755 | { |
| 756 | return context->createProgram(); |
| 757 | } |
| 758 | } |
| 759 | catch(std::bad_alloc&) |
| 760 | { |
| 761 | return error(GL_OUT_OF_MEMORY, 0); |
| 762 | } |
| 763 | |
| 764 | return 0; |
| 765 | } |
| 766 | |
| 767 | GLuint __stdcall glCreateShader(GLenum type) |
| 768 | { |
| 769 | TRACE("GLenum type = 0x%X", type); |
| 770 | |
| 771 | try |
| 772 | { |
| 773 | gl::Context *context = gl::getContext(); |
| 774 | |
| 775 | if (context) |
| 776 | { |
| 777 | switch (type) |
| 778 | { |
| 779 | case GL_FRAGMENT_SHADER: |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 780 | case GL_VERTEX_SHADER: |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 781 | return context->createShader(type); |
| 782 | default: |
| 783 | return error(GL_INVALID_ENUM, 0); |
| 784 | } |
| 785 | } |
| 786 | } |
| 787 | catch(std::bad_alloc&) |
| 788 | { |
| 789 | return error(GL_OUT_OF_MEMORY, 0); |
| 790 | } |
| 791 | |
| 792 | return 0; |
| 793 | } |
| 794 | |
| 795 | void __stdcall glCullFace(GLenum mode) |
| 796 | { |
| 797 | TRACE("GLenum mode = 0x%X", mode); |
| 798 | |
| 799 | try |
| 800 | { |
| 801 | switch (mode) |
| 802 | { |
| 803 | case GL_FRONT: |
| 804 | case GL_BACK: |
| 805 | case GL_FRONT_AND_BACK: |
| 806 | { |
| 807 | gl::Context *context = gl::getContext(); |
| 808 | |
| 809 | if (context) |
| 810 | { |
| 811 | context->cullMode = mode; |
| 812 | } |
| 813 | } |
| 814 | break; |
| 815 | default: |
| 816 | return error(GL_INVALID_ENUM); |
| 817 | } |
| 818 | } |
| 819 | catch(std::bad_alloc&) |
| 820 | { |
| 821 | return error(GL_OUT_OF_MEMORY); |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | void __stdcall glDeleteBuffers(GLsizei n, const GLuint* buffers) |
| 826 | { |
| 827 | TRACE("GLsizei n = %d, const GLuint* buffers = 0x%0.8p", n, buffers); |
| 828 | |
| 829 | try |
| 830 | { |
| 831 | if (n < 0) |
| 832 | { |
| 833 | return error(GL_INVALID_VALUE); |
| 834 | } |
| 835 | |
| 836 | gl::Context *context = gl::getContext(); |
| 837 | |
| 838 | if (context) |
| 839 | { |
| 840 | for (int i = 0; i < n; i++) |
| 841 | { |
| 842 | context->deleteBuffer(buffers[i]); |
| 843 | } |
| 844 | } |
| 845 | } |
| 846 | catch(std::bad_alloc&) |
| 847 | { |
| 848 | return error(GL_OUT_OF_MEMORY); |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | void __stdcall glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers) |
| 853 | { |
| 854 | TRACE("GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p", n, framebuffers); |
| 855 | |
| 856 | try |
| 857 | { |
| 858 | if (n < 0) |
| 859 | { |
| 860 | return error(GL_INVALID_VALUE); |
| 861 | } |
| 862 | |
| 863 | gl::Context *context = gl::getContext(); |
| 864 | |
| 865 | if (context) |
| 866 | { |
| 867 | for (int i = 0; i < n; i++) |
| 868 | { |
| 869 | if (framebuffers[i] != 0) |
| 870 | { |
| 871 | context->deleteFramebuffer(framebuffers[i]); |
| 872 | } |
| 873 | } |
| 874 | } |
| 875 | } |
| 876 | catch(std::bad_alloc&) |
| 877 | { |
| 878 | return error(GL_OUT_OF_MEMORY); |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | void __stdcall glDeleteProgram(GLuint program) |
| 883 | { |
| 884 | TRACE("GLuint program = %d", program); |
| 885 | |
| 886 | try |
| 887 | { |
| 888 | gl::Context *context = gl::getContext(); |
| 889 | |
| 890 | if (context) |
| 891 | { |
| 892 | context->deleteProgram(program); |
| 893 | } |
| 894 | } |
| 895 | catch(std::bad_alloc&) |
| 896 | { |
| 897 | return error(GL_OUT_OF_MEMORY); |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | void __stdcall glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers) |
| 902 | { |
| 903 | TRACE("GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p", n, renderbuffers); |
| 904 | |
| 905 | try |
| 906 | { |
| 907 | if (n < 0) |
| 908 | { |
| 909 | return error(GL_INVALID_VALUE); |
| 910 | } |
| 911 | |
| 912 | gl::Context *context = gl::getContext(); |
| 913 | |
| 914 | if (context) |
| 915 | { |
daniel@transgaming.com | e2b2212 | 2010-03-11 19:22:14 +0000 | [diff] [blame] | 916 | for (int i = 0; i < n; i++) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 917 | { |
| 918 | context->deleteRenderbuffer(renderbuffers[i]); |
| 919 | } |
| 920 | } |
| 921 | } |
| 922 | catch(std::bad_alloc&) |
| 923 | { |
| 924 | return error(GL_OUT_OF_MEMORY); |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | void __stdcall glDeleteShader(GLuint shader) |
| 929 | { |
| 930 | TRACE("GLuint shader = %d", shader); |
| 931 | |
| 932 | try |
| 933 | { |
| 934 | gl::Context *context = gl::getContext(); |
| 935 | |
| 936 | if (context) |
| 937 | { |
| 938 | context->deleteShader(shader); |
| 939 | } |
| 940 | } |
| 941 | catch(std::bad_alloc&) |
| 942 | { |
| 943 | return error(GL_OUT_OF_MEMORY); |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | void __stdcall glDeleteTextures(GLsizei n, const GLuint* textures) |
| 948 | { |
| 949 | TRACE("GLsizei n = %d, const GLuint* textures = 0x%0.8p", n, textures); |
| 950 | |
| 951 | try |
| 952 | { |
| 953 | if (n < 0) |
| 954 | { |
| 955 | return error(GL_INVALID_VALUE); |
| 956 | } |
| 957 | |
| 958 | gl::Context *context = gl::getContext(); |
| 959 | |
| 960 | if (context) |
| 961 | { |
| 962 | for (int i = 0; i < n; i++) |
| 963 | { |
| 964 | if (textures[i] != 0) |
| 965 | { |
| 966 | context->deleteTexture(textures[i]); |
| 967 | } |
| 968 | } |
| 969 | } |
| 970 | } |
| 971 | catch(std::bad_alloc&) |
| 972 | { |
| 973 | return error(GL_OUT_OF_MEMORY); |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | void __stdcall glDepthFunc(GLenum func) |
| 978 | { |
| 979 | TRACE("GLenum func = 0x%X", func); |
| 980 | |
| 981 | try |
| 982 | { |
| 983 | switch (func) |
| 984 | { |
| 985 | case GL_NEVER: |
| 986 | case GL_ALWAYS: |
| 987 | case GL_LESS: |
| 988 | case GL_LEQUAL: |
| 989 | case GL_EQUAL: |
| 990 | case GL_GREATER: |
| 991 | case GL_GEQUAL: |
| 992 | case GL_NOTEQUAL: |
| 993 | break; |
| 994 | default: |
| 995 | return error(GL_INVALID_ENUM); |
| 996 | } |
| 997 | |
| 998 | gl::Context *context = gl::getContext(); |
| 999 | |
| 1000 | if (context) |
| 1001 | { |
| 1002 | context->depthFunc = func; |
| 1003 | } |
| 1004 | } |
| 1005 | catch(std::bad_alloc&) |
| 1006 | { |
| 1007 | return error(GL_OUT_OF_MEMORY); |
| 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | void __stdcall glDepthMask(GLboolean flag) |
| 1012 | { |
| 1013 | TRACE("GLboolean flag = %d", flag); |
| 1014 | |
| 1015 | try |
| 1016 | { |
| 1017 | gl::Context *context = gl::getContext(); |
| 1018 | |
| 1019 | if (context) |
| 1020 | { |
| 1021 | context->depthMask = flag != GL_FALSE; |
| 1022 | } |
| 1023 | } |
| 1024 | catch(std::bad_alloc&) |
| 1025 | { |
| 1026 | return error(GL_OUT_OF_MEMORY); |
| 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | void __stdcall glDepthRangef(GLclampf zNear, GLclampf zFar) |
| 1031 | { |
| 1032 | TRACE("GLclampf zNear = %f, GLclampf zFar = %f", zNear, zFar); |
| 1033 | |
| 1034 | try |
| 1035 | { |
| 1036 | gl::Context *context = gl::getContext(); |
| 1037 | |
| 1038 | if (context) |
| 1039 | { |
| 1040 | context->zNear = zNear; |
| 1041 | context->zFar = zFar; |
| 1042 | } |
| 1043 | } |
| 1044 | catch(std::bad_alloc&) |
| 1045 | { |
| 1046 | return error(GL_OUT_OF_MEMORY); |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | void __stdcall glDetachShader(GLuint program, GLuint shader) |
| 1051 | { |
| 1052 | TRACE("GLuint program = %d, GLuint shader = %d", program, shader); |
| 1053 | |
| 1054 | try |
| 1055 | { |
| 1056 | gl::Context *context = gl::getContext(); |
| 1057 | |
| 1058 | if (context) |
| 1059 | { |
| 1060 | gl::Program *programObject = context->getProgram(program); |
| 1061 | gl::Shader *shaderObject = context->getShader(shader); |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 1062 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1063 | if (!programObject || !shaderObject) |
| 1064 | { |
| 1065 | return error(GL_INVALID_VALUE); |
| 1066 | } |
| 1067 | |
| 1068 | if (!programObject->detachShader(shaderObject)) |
| 1069 | { |
| 1070 | return error(GL_INVALID_OPERATION); |
| 1071 | } |
| 1072 | |
| 1073 | if (shaderObject->isDeletable()) |
| 1074 | { |
| 1075 | context->deleteShader(shader); |
| 1076 | } |
| 1077 | } |
| 1078 | } |
| 1079 | catch(std::bad_alloc&) |
| 1080 | { |
| 1081 | return error(GL_OUT_OF_MEMORY); |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | void __stdcall glDisable(GLenum cap) |
| 1086 | { |
| 1087 | TRACE("GLenum cap = 0x%X", cap); |
| 1088 | |
| 1089 | try |
| 1090 | { |
| 1091 | gl::Context *context = gl::getContext(); |
| 1092 | |
| 1093 | if (context) |
| 1094 | { |
| 1095 | switch (cap) |
| 1096 | { |
| 1097 | case GL_CULL_FACE: context->cullFace = false; break; |
| 1098 | case GL_POLYGON_OFFSET_FILL: context->polygonOffsetFill = false; break; |
| 1099 | case GL_SAMPLE_ALPHA_TO_COVERAGE: context->sampleAlphaToCoverage = false; break; |
| 1100 | case GL_SAMPLE_COVERAGE: context->sampleCoverage = false; break; |
| 1101 | case GL_SCISSOR_TEST: context->scissorTest = false; break; |
| 1102 | case GL_STENCIL_TEST: context->stencilTest = false; break; |
| 1103 | case GL_DEPTH_TEST: context->depthTest = false; break; |
| 1104 | case GL_BLEND: context->blend = false; break; |
| 1105 | case GL_DITHER: context->dither = false; break; |
| 1106 | default: |
| 1107 | return error(GL_INVALID_ENUM); |
| 1108 | } |
| 1109 | } |
| 1110 | } |
| 1111 | catch(std::bad_alloc&) |
| 1112 | { |
| 1113 | return error(GL_OUT_OF_MEMORY); |
| 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | void __stdcall glDisableVertexAttribArray(GLuint index) |
| 1118 | { |
| 1119 | TRACE("GLuint index = %d", index); |
| 1120 | |
| 1121 | try |
| 1122 | { |
| 1123 | if (index >= gl::MAX_VERTEX_ATTRIBS) |
| 1124 | { |
| 1125 | return error(GL_INVALID_VALUE); |
| 1126 | } |
| 1127 | |
| 1128 | gl::Context *context = gl::getContext(); |
| 1129 | |
| 1130 | if (context) |
| 1131 | { |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 1132 | context->vertexAttribute[index].mEnabled = false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1133 | } |
| 1134 | } |
| 1135 | catch(std::bad_alloc&) |
| 1136 | { |
| 1137 | return error(GL_OUT_OF_MEMORY); |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | void __stdcall glDrawArrays(GLenum mode, GLint first, GLsizei count) |
| 1142 | { |
| 1143 | TRACE("GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d", mode, first, count); |
| 1144 | |
| 1145 | try |
| 1146 | { |
| 1147 | if (count < 0 || first < 0) |
| 1148 | { |
| 1149 | return error(GL_INVALID_VALUE); |
| 1150 | } |
| 1151 | |
| 1152 | gl::Context *context = gl::getContext(); |
| 1153 | |
| 1154 | if (context) |
| 1155 | { |
| 1156 | context->drawArrays(mode, first, count); |
| 1157 | } |
| 1158 | } |
| 1159 | catch(std::bad_alloc&) |
| 1160 | { |
| 1161 | return error(GL_OUT_OF_MEMORY); |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | void __stdcall glDrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices) |
| 1166 | { |
| 1167 | TRACE("GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const void* indices = 0x%0.8p", mode, count, type, indices); |
| 1168 | |
| 1169 | try |
| 1170 | { |
| 1171 | if (count < 0) |
| 1172 | { |
| 1173 | return error(GL_INVALID_VALUE); |
| 1174 | } |
| 1175 | |
| 1176 | switch (type) |
| 1177 | { |
| 1178 | case GL_UNSIGNED_BYTE: |
| 1179 | UNIMPLEMENTED(); // FIXME |
| 1180 | case GL_UNSIGNED_SHORT: |
| 1181 | break; |
| 1182 | default: |
| 1183 | return error(GL_INVALID_ENUM); |
| 1184 | } |
| 1185 | |
| 1186 | gl::Context *context = gl::getContext(); |
| 1187 | |
| 1188 | if (context) |
| 1189 | { |
| 1190 | context->drawElements(mode, count, type, indices); |
| 1191 | } |
| 1192 | } |
| 1193 | catch(std::bad_alloc&) |
| 1194 | { |
| 1195 | return error(GL_OUT_OF_MEMORY); |
| 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | void __stdcall glEnable(GLenum cap) |
| 1200 | { |
| 1201 | TRACE("GLenum cap = 0x%X", cap); |
| 1202 | |
| 1203 | try |
| 1204 | { |
| 1205 | gl::Context *context = gl::getContext(); |
| 1206 | |
| 1207 | if (context) |
| 1208 | { |
| 1209 | switch (cap) |
| 1210 | { |
| 1211 | case GL_CULL_FACE: context->cullFace = true; break; |
| 1212 | case GL_POLYGON_OFFSET_FILL: context->polygonOffsetFill = true; break; |
| 1213 | case GL_SAMPLE_ALPHA_TO_COVERAGE: context->sampleAlphaToCoverage = true; break; |
| 1214 | case GL_SAMPLE_COVERAGE: context->sampleCoverage = true; break; |
| 1215 | case GL_SCISSOR_TEST: context->scissorTest = true; break; |
| 1216 | case GL_STENCIL_TEST: context->stencilTest = true; break; |
| 1217 | case GL_DEPTH_TEST: context->depthTest = true; break; |
| 1218 | case GL_BLEND: context->blend = true; break; |
| 1219 | case GL_DITHER: context->dither = true; break; |
| 1220 | default: |
| 1221 | return error(GL_INVALID_ENUM); |
| 1222 | } |
| 1223 | } |
| 1224 | } |
| 1225 | catch(std::bad_alloc&) |
| 1226 | { |
| 1227 | return error(GL_OUT_OF_MEMORY); |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | void __stdcall glEnableVertexAttribArray(GLuint index) |
| 1232 | { |
| 1233 | TRACE("GLuint index = %d", index); |
| 1234 | |
| 1235 | try |
| 1236 | { |
| 1237 | if (index >= gl::MAX_VERTEX_ATTRIBS) |
| 1238 | { |
| 1239 | return error(GL_INVALID_VALUE); |
| 1240 | } |
| 1241 | |
| 1242 | gl::Context *context = gl::getContext(); |
| 1243 | |
| 1244 | if (context) |
| 1245 | { |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 1246 | context->vertexAttribute[index].mEnabled = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1247 | } |
| 1248 | } |
| 1249 | catch(std::bad_alloc&) |
| 1250 | { |
| 1251 | return error(GL_OUT_OF_MEMORY); |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | void __stdcall glFinish(void) |
| 1256 | { |
| 1257 | TRACE(""); |
| 1258 | |
| 1259 | try |
| 1260 | { |
| 1261 | gl::Context *context = gl::getContext(); |
| 1262 | |
| 1263 | if (context) |
| 1264 | { |
| 1265 | context->finish(); |
| 1266 | } |
| 1267 | } |
| 1268 | catch(std::bad_alloc&) |
| 1269 | { |
| 1270 | return error(GL_OUT_OF_MEMORY); |
| 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | void __stdcall glFlush(void) |
| 1275 | { |
| 1276 | TRACE(""); |
| 1277 | |
| 1278 | try |
| 1279 | { |
| 1280 | gl::Context *context = gl::getContext(); |
| 1281 | |
| 1282 | if (context) |
| 1283 | { |
| 1284 | context->flush(); |
| 1285 | } |
| 1286 | } |
| 1287 | catch(std::bad_alloc&) |
| 1288 | { |
| 1289 | return error(GL_OUT_OF_MEMORY); |
| 1290 | } |
| 1291 | } |
| 1292 | |
| 1293 | void __stdcall glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) |
| 1294 | { |
| 1295 | TRACE("GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, GLuint renderbuffer = %d", target, attachment, renderbuffertarget, renderbuffer); |
| 1296 | |
| 1297 | try |
| 1298 | { |
| 1299 | if (target != GL_FRAMEBUFFER || renderbuffertarget != GL_RENDERBUFFER) |
| 1300 | { |
| 1301 | return error(GL_INVALID_ENUM); |
| 1302 | } |
| 1303 | |
| 1304 | gl::Context *context = gl::getContext(); |
| 1305 | |
| 1306 | if (context) |
| 1307 | { |
| 1308 | gl::Framebuffer *framebuffer = context->getFramebuffer(); |
| 1309 | |
| 1310 | if (context->framebuffer == 0 || !framebuffer) |
| 1311 | { |
| 1312 | return error(GL_INVALID_OPERATION); |
| 1313 | } |
| 1314 | |
| 1315 | switch (attachment) |
| 1316 | { |
| 1317 | case GL_COLOR_ATTACHMENT0: |
| 1318 | framebuffer->setColorbuffer(GL_RENDERBUFFER, renderbuffer); |
| 1319 | break; |
| 1320 | case GL_DEPTH_ATTACHMENT: |
| 1321 | framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer); |
| 1322 | break; |
| 1323 | case GL_STENCIL_ATTACHMENT: |
| 1324 | framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer); |
| 1325 | break; |
| 1326 | default: |
| 1327 | return error(GL_INVALID_ENUM); |
| 1328 | } |
| 1329 | } |
| 1330 | } |
| 1331 | catch(std::bad_alloc&) |
| 1332 | { |
| 1333 | return error(GL_OUT_OF_MEMORY); |
| 1334 | } |
| 1335 | } |
| 1336 | |
| 1337 | void __stdcall glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) |
| 1338 | { |
| 1339 | TRACE("GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, GLuint texture = %d, GLint level = %d", target, attachment, textarget, texture, level); |
| 1340 | |
| 1341 | try |
| 1342 | { |
| 1343 | if (target != GL_FRAMEBUFFER) |
| 1344 | { |
| 1345 | return error(GL_INVALID_ENUM); |
| 1346 | } |
| 1347 | |
| 1348 | switch (attachment) |
| 1349 | { |
| 1350 | case GL_COLOR_ATTACHMENT0: |
| 1351 | break; |
| 1352 | default: |
| 1353 | return error(GL_INVALID_ENUM); |
| 1354 | } |
| 1355 | |
| 1356 | gl::Context *context = gl::getContext(); |
| 1357 | |
| 1358 | if (context) |
| 1359 | { |
| 1360 | if (texture) |
| 1361 | { |
| 1362 | switch (textarget) |
| 1363 | { |
| 1364 | case GL_TEXTURE_2D: |
| 1365 | if (!context->getTexture2D()) |
| 1366 | { |
| 1367 | return error(GL_INVALID_OPERATION); |
| 1368 | } |
| 1369 | break; |
| 1370 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 1371 | UNIMPLEMENTED(); // FIXME |
| 1372 | break; |
| 1373 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 1374 | UNIMPLEMENTED(); // FIXME |
| 1375 | break; |
| 1376 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 1377 | UNIMPLEMENTED(); // FIXME |
| 1378 | break; |
| 1379 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 1380 | UNIMPLEMENTED(); // FIXME |
| 1381 | break; |
| 1382 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 1383 | UNIMPLEMENTED(); // FIXME |
| 1384 | break; |
| 1385 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 1386 | UNIMPLEMENTED(); // FIXME |
| 1387 | break; |
| 1388 | default: |
| 1389 | return error(GL_INVALID_ENUM); |
| 1390 | } |
| 1391 | |
| 1392 | if (level != 0) |
| 1393 | { |
| 1394 | return error(GL_INVALID_VALUE); |
| 1395 | } |
| 1396 | } |
| 1397 | |
| 1398 | gl::Framebuffer *framebuffer = context->getFramebuffer(); |
| 1399 | |
| 1400 | if (context->framebuffer == 0 || !framebuffer) |
| 1401 | { |
| 1402 | return error(GL_INVALID_OPERATION); |
| 1403 | } |
| 1404 | |
| 1405 | framebuffer->setColorbuffer(GL_TEXTURE, texture); |
| 1406 | } |
| 1407 | } |
| 1408 | catch(std::bad_alloc&) |
| 1409 | { |
| 1410 | return error(GL_OUT_OF_MEMORY); |
| 1411 | } |
| 1412 | } |
| 1413 | |
| 1414 | void __stdcall glFrontFace(GLenum mode) |
| 1415 | { |
| 1416 | TRACE("GLenum mode = 0x%X", mode); |
| 1417 | |
| 1418 | try |
| 1419 | { |
| 1420 | switch (mode) |
| 1421 | { |
| 1422 | case GL_CW: |
| 1423 | case GL_CCW: |
| 1424 | { |
| 1425 | gl::Context *context = gl::getContext(); |
| 1426 | |
| 1427 | if (context) |
| 1428 | { |
| 1429 | context->frontFace = mode; |
| 1430 | } |
| 1431 | } |
| 1432 | break; |
| 1433 | default: |
| 1434 | return error(GL_INVALID_ENUM); |
| 1435 | } |
| 1436 | } |
| 1437 | catch(std::bad_alloc&) |
| 1438 | { |
| 1439 | return error(GL_OUT_OF_MEMORY); |
| 1440 | } |
| 1441 | } |
| 1442 | |
| 1443 | void __stdcall glGenBuffers(GLsizei n, GLuint* buffers) |
| 1444 | { |
| 1445 | TRACE("GLsizei n = %d, GLuint* buffers = 0x%0.8p", n, buffers); |
| 1446 | |
| 1447 | try |
| 1448 | { |
| 1449 | if (n < 0) |
| 1450 | { |
| 1451 | return error(GL_INVALID_VALUE); |
| 1452 | } |
| 1453 | |
| 1454 | gl::Context *context = gl::getContext(); |
| 1455 | |
| 1456 | if (context) |
| 1457 | { |
| 1458 | for (int i = 0; i < n; i++) |
| 1459 | { |
| 1460 | buffers[i] = context->createBuffer(); |
| 1461 | } |
| 1462 | } |
| 1463 | } |
| 1464 | catch(std::bad_alloc&) |
| 1465 | { |
| 1466 | return error(GL_OUT_OF_MEMORY); |
| 1467 | } |
| 1468 | } |
| 1469 | |
| 1470 | void __stdcall glGenerateMipmap(GLenum target) |
| 1471 | { |
| 1472 | TRACE("GLenum target = 0x%X", target); |
| 1473 | |
| 1474 | try |
| 1475 | { |
| 1476 | UNIMPLEMENTED(); // FIXME |
| 1477 | } |
| 1478 | catch(std::bad_alloc&) |
| 1479 | { |
| 1480 | return error(GL_OUT_OF_MEMORY); |
| 1481 | } |
| 1482 | } |
| 1483 | |
| 1484 | void __stdcall glGenFramebuffers(GLsizei n, GLuint* framebuffers) |
| 1485 | { |
| 1486 | TRACE("GLsizei n = %d, GLuint* framebuffers = 0x%0.8p", n, framebuffers); |
| 1487 | |
| 1488 | try |
| 1489 | { |
| 1490 | if (n < 0) |
| 1491 | { |
| 1492 | return error(GL_INVALID_VALUE); |
| 1493 | } |
| 1494 | |
| 1495 | gl::Context *context = gl::getContext(); |
| 1496 | |
| 1497 | if (context) |
| 1498 | { |
| 1499 | for (int i = 0; i < n; i++) |
| 1500 | { |
| 1501 | framebuffers[i] = context->createFramebuffer(); |
| 1502 | } |
| 1503 | } |
| 1504 | } |
| 1505 | catch(std::bad_alloc&) |
| 1506 | { |
| 1507 | return error(GL_OUT_OF_MEMORY); |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | void __stdcall glGenRenderbuffers(GLsizei n, GLuint* renderbuffers) |
| 1512 | { |
| 1513 | TRACE("GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p", n, renderbuffers); |
| 1514 | |
| 1515 | try |
| 1516 | { |
| 1517 | if (n < 0) |
| 1518 | { |
| 1519 | return error(GL_INVALID_VALUE); |
| 1520 | } |
| 1521 | |
| 1522 | gl::Context *context = gl::getContext(); |
| 1523 | |
| 1524 | if (context) |
| 1525 | { |
| 1526 | for (int i = 0; i < n; i++) |
| 1527 | { |
| 1528 | renderbuffers[i] = context->createRenderbuffer(); |
| 1529 | } |
| 1530 | } |
| 1531 | } |
| 1532 | catch(std::bad_alloc&) |
| 1533 | { |
| 1534 | return error(GL_OUT_OF_MEMORY); |
| 1535 | } |
| 1536 | } |
| 1537 | |
| 1538 | void __stdcall glGenTextures(GLsizei n, GLuint* textures) |
| 1539 | { |
| 1540 | TRACE("GLsizei n = %d, GLuint* textures = 0x%0.8p", n, textures); |
| 1541 | |
| 1542 | try |
| 1543 | { |
| 1544 | if (n < 0) |
| 1545 | { |
| 1546 | return error(GL_INVALID_VALUE); |
| 1547 | } |
| 1548 | |
| 1549 | gl::Context *context = gl::getContext(); |
| 1550 | |
| 1551 | if (context) |
| 1552 | { |
| 1553 | for (int i = 0; i < n; i++) |
| 1554 | { |
| 1555 | textures[i] = context->createTexture(); |
| 1556 | } |
| 1557 | } |
| 1558 | } |
| 1559 | catch(std::bad_alloc&) |
| 1560 | { |
| 1561 | return error(GL_OUT_OF_MEMORY); |
| 1562 | } |
| 1563 | } |
| 1564 | |
| 1565 | void __stdcall glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name) |
| 1566 | { |
| 1567 | TRACE("GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLint* size = 0x%0.8p, GLenum* type = %0.8p, char* name = %0.8p", |
| 1568 | program, index, bufsize, length, size, type, name); |
| 1569 | |
| 1570 | try |
| 1571 | { |
| 1572 | if (bufsize < 0) |
| 1573 | { |
| 1574 | return error(GL_INVALID_VALUE); |
| 1575 | } |
| 1576 | |
| 1577 | UNIMPLEMENTED(); // FIXME |
| 1578 | } |
| 1579 | catch(std::bad_alloc&) |
| 1580 | { |
| 1581 | return error(GL_OUT_OF_MEMORY); |
| 1582 | } |
| 1583 | } |
| 1584 | |
| 1585 | void __stdcall glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name) |
| 1586 | { |
| 1587 | TRACE("GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLint* size = 0x%0.8p, GLenum* type = 0x%0.8p, char* name = 0x%0.8p", |
| 1588 | program, index, bufsize, length, size, type, name); |
| 1589 | |
| 1590 | try |
| 1591 | { |
| 1592 | if (bufsize < 0) |
| 1593 | { |
| 1594 | return error(GL_INVALID_VALUE); |
| 1595 | } |
| 1596 | |
| 1597 | UNIMPLEMENTED(); // FIXME |
| 1598 | } |
| 1599 | catch(std::bad_alloc&) |
| 1600 | { |
| 1601 | return error(GL_OUT_OF_MEMORY); |
| 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | void __stdcall glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders) |
| 1606 | { |
| 1607 | TRACE("GLuint program = %d, GLsizei maxcount = %d, GLsizei* count = 0x%0.8p, GLuint* shaders = 0x%0.8p", program, maxcount, count, shaders); |
| 1608 | |
| 1609 | try |
| 1610 | { |
| 1611 | if (maxcount < 0) |
| 1612 | { |
| 1613 | return error(GL_INVALID_VALUE); |
| 1614 | } |
| 1615 | |
| 1616 | UNIMPLEMENTED(); // FIXME |
| 1617 | } |
| 1618 | catch(std::bad_alloc&) |
| 1619 | { |
| 1620 | return error(GL_OUT_OF_MEMORY); |
| 1621 | } |
| 1622 | } |
| 1623 | |
| 1624 | int __stdcall glGetAttribLocation(GLuint program, const char* name) |
| 1625 | { |
| 1626 | TRACE("GLuint program = %d, const char* name = %s", program, name); |
| 1627 | |
| 1628 | try |
| 1629 | { |
| 1630 | gl::Context *context = gl::getContext(); |
| 1631 | |
| 1632 | if (context) |
| 1633 | { |
| 1634 | gl::Program *programObject = context->getProgram(program); |
| 1635 | |
| 1636 | if (!programObject) |
| 1637 | { |
| 1638 | return error(GL_INVALID_VALUE, -1); |
| 1639 | } |
| 1640 | |
| 1641 | return programObject->getAttributeLocation(name); |
| 1642 | } |
| 1643 | } |
| 1644 | catch(std::bad_alloc&) |
| 1645 | { |
| 1646 | return error(GL_OUT_OF_MEMORY, -1); |
| 1647 | } |
| 1648 | |
| 1649 | return -1; |
| 1650 | } |
| 1651 | |
| 1652 | void __stdcall glGetBooleanv(GLenum pname, GLboolean* params) |
| 1653 | { |
| 1654 | TRACE("GLenum pname = 0x%X, GLboolean* params = 0x%0.8p", pname, params); |
| 1655 | |
| 1656 | try |
| 1657 | { |
| 1658 | switch (pname) |
| 1659 | { |
| 1660 | case GL_SHADER_COMPILER: *params = GL_TRUE; break; |
| 1661 | default: |
| 1662 | UNIMPLEMENTED(); // FIXME |
| 1663 | return error(GL_INVALID_ENUM); |
| 1664 | } |
| 1665 | } |
| 1666 | catch(std::bad_alloc&) |
| 1667 | { |
| 1668 | return error(GL_OUT_OF_MEMORY); |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | void __stdcall glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params) |
| 1673 | { |
| 1674 | TRACE("GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p", target, pname, params); |
| 1675 | |
| 1676 | try |
| 1677 | { |
| 1678 | UNIMPLEMENTED(); // FIXME |
| 1679 | } |
| 1680 | catch(std::bad_alloc&) |
| 1681 | { |
| 1682 | return error(GL_OUT_OF_MEMORY); |
| 1683 | } |
| 1684 | } |
| 1685 | |
| 1686 | GLenum __stdcall glGetError(void) |
| 1687 | { |
| 1688 | TRACE(""); |
| 1689 | |
| 1690 | gl::Context *context = gl::getContext(); |
| 1691 | |
| 1692 | if (context) |
| 1693 | { |
| 1694 | return context->getError(); |
| 1695 | } |
| 1696 | |
| 1697 | return GL_NO_ERROR; |
| 1698 | } |
| 1699 | |
| 1700 | void __stdcall glGetFloatv(GLenum pname, GLfloat* params) |
| 1701 | { |
| 1702 | TRACE("GLenum pname = 0x%X, GLfloat* params = 0x%0.8p", pname, params); |
| 1703 | |
| 1704 | try |
| 1705 | { |
| 1706 | UNIMPLEMENTED(); // FIXME |
| 1707 | } |
| 1708 | catch(std::bad_alloc&) |
| 1709 | { |
| 1710 | return error(GL_OUT_OF_MEMORY); |
| 1711 | } |
| 1712 | } |
| 1713 | |
| 1714 | void __stdcall glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params) |
| 1715 | { |
| 1716 | TRACE("GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p", target, attachment, pname, params); |
| 1717 | |
| 1718 | try |
| 1719 | { |
| 1720 | gl::Context *context = gl::getContext(); |
| 1721 | |
| 1722 | if (context) |
| 1723 | { |
| 1724 | if (context->framebuffer == 0) |
| 1725 | { |
| 1726 | return error(GL_INVALID_OPERATION); |
| 1727 | } |
| 1728 | |
| 1729 | UNIMPLEMENTED(); // FIXME |
| 1730 | } |
| 1731 | } |
| 1732 | catch(std::bad_alloc&) |
| 1733 | { |
| 1734 | return error(GL_OUT_OF_MEMORY); |
| 1735 | } |
| 1736 | } |
| 1737 | |
| 1738 | void __stdcall glGetIntegerv(GLenum pname, GLint* params) |
| 1739 | { |
| 1740 | TRACE("GLenum pname = 0x%X, GLint* params = 0x%0.8p", pname, params); |
| 1741 | |
| 1742 | try |
| 1743 | { |
| 1744 | gl::Context *context = gl::getContext(); |
| 1745 | |
| 1746 | if (context) |
| 1747 | { |
| 1748 | switch (pname) |
| 1749 | { |
| 1750 | case GL_MAX_VERTEX_ATTRIBS: *params = gl::MAX_VERTEX_ATTRIBS; break; |
| 1751 | case GL_MAX_VERTEX_UNIFORM_VECTORS: *params = gl::MAX_VERTEX_UNIFORM_VECTORS; break; |
| 1752 | case GL_MAX_VARYING_VECTORS: *params = gl::MAX_VARYING_VECTORS; break; |
| 1753 | case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: *params = gl::MAX_COMBINED_TEXTURE_IMAGE_UNITS; break; |
| 1754 | case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: *params = gl::MAX_VERTEX_TEXTURE_IMAGE_UNITS; break; |
| 1755 | case GL_MAX_TEXTURE_IMAGE_UNITS: *params = gl::MAX_TEXTURE_IMAGE_UNITS; break; |
| 1756 | case GL_MAX_FRAGMENT_UNIFORM_VECTORS: *params = gl::MAX_FRAGMENT_UNIFORM_VECTORS; break; |
| 1757 | case GL_MAX_RENDERBUFFER_SIZE: *params = gl::MAX_RENDERBUFFER_SIZE; break; |
| 1758 | case GL_NUM_SHADER_BINARY_FORMATS: *params = 0; break; |
| 1759 | case GL_ARRAY_BUFFER_BINDING: *params = context->arrayBuffer; break; |
| 1760 | case GL_FRAMEBUFFER_BINDING: *params = context->framebuffer; break; |
| 1761 | case GL_RENDERBUFFER_BINDING: *params = context->renderbuffer; break; |
| 1762 | case GL_CURRENT_PROGRAM: *params = context->currentProgram; break; |
| 1763 | case GL_RED_BITS: |
| 1764 | case GL_GREEN_BITS: |
| 1765 | case GL_BLUE_BITS: |
| 1766 | case GL_ALPHA_BITS: |
| 1767 | { |
| 1768 | gl::Framebuffer *framebuffer = context->getFramebuffer(); |
| 1769 | gl::Colorbuffer *colorbuffer = framebuffer->getColorbuffer(); |
| 1770 | |
| 1771 | if (colorbuffer) |
| 1772 | { |
| 1773 | switch (pname) |
| 1774 | { |
| 1775 | case GL_RED_BITS: *params = colorbuffer->getRedSize(); break; |
| 1776 | case GL_GREEN_BITS: *params = colorbuffer->getGreenSize(); break; |
| 1777 | case GL_BLUE_BITS: *params = colorbuffer->getBlueSize(); break; |
| 1778 | case GL_ALPHA_BITS: *params = colorbuffer->getAlphaSize(); break; |
| 1779 | } |
| 1780 | } |
| 1781 | else |
| 1782 | { |
| 1783 | *params = 0; |
| 1784 | } |
| 1785 | } |
| 1786 | break; |
| 1787 | case GL_DEPTH_BITS: |
| 1788 | { |
| 1789 | gl::Framebuffer *framebuffer = context->getFramebuffer(); |
| 1790 | gl::Depthbuffer *depthbuffer = framebuffer->getDepthbuffer(); |
| 1791 | |
| 1792 | if (depthbuffer) |
| 1793 | { |
| 1794 | *params = depthbuffer->getDepthSize(); |
| 1795 | } |
| 1796 | else |
| 1797 | { |
| 1798 | *params = 0; |
| 1799 | } |
| 1800 | } |
| 1801 | break; |
| 1802 | case GL_STENCIL_BITS: |
| 1803 | { |
| 1804 | gl::Framebuffer *framebuffer = context->getFramebuffer(); |
| 1805 | gl::Stencilbuffer *stencilbuffer = framebuffer->getStencilbuffer(); |
| 1806 | |
| 1807 | if (stencilbuffer) |
| 1808 | { |
| 1809 | *params = stencilbuffer->getStencilSize(); |
| 1810 | } |
| 1811 | else |
| 1812 | { |
| 1813 | *params = 0; |
| 1814 | } |
| 1815 | } |
| 1816 | break; |
| 1817 | default: |
| 1818 | UNIMPLEMENTED(); // FIXME |
| 1819 | return error(GL_INVALID_ENUM); |
| 1820 | } |
| 1821 | } |
| 1822 | } |
| 1823 | catch(std::bad_alloc&) |
| 1824 | { |
| 1825 | return error(GL_OUT_OF_MEMORY); |
| 1826 | } |
| 1827 | } |
| 1828 | |
| 1829 | void __stdcall glGetProgramiv(GLuint program, GLenum pname, GLint* params) |
| 1830 | { |
| 1831 | TRACE("GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p", program, pname, params); |
| 1832 | |
| 1833 | try |
| 1834 | { |
| 1835 | gl::Context *context = gl::getContext(); |
| 1836 | |
| 1837 | if (context) |
| 1838 | { |
| 1839 | gl::Program *programObject = context->getProgram(program); |
| 1840 | |
| 1841 | if (!programObject) |
| 1842 | { |
| 1843 | return error(GL_INVALID_VALUE); |
| 1844 | } |
| 1845 | |
| 1846 | switch (pname) |
| 1847 | { |
| 1848 | case GL_DELETE_STATUS: |
| 1849 | UNIMPLEMENTED(); // FIXME |
| 1850 | *params = GL_FALSE; |
| 1851 | return; |
| 1852 | case GL_LINK_STATUS: |
| 1853 | *params = programObject->isLinked(); |
| 1854 | return; |
| 1855 | case GL_VALIDATE_STATUS: |
| 1856 | UNIMPLEMENTED(); // FIXME |
| 1857 | *params = GL_TRUE; |
| 1858 | return; |
| 1859 | case GL_INFO_LOG_LENGTH: |
| 1860 | UNIMPLEMENTED(); // FIXME |
| 1861 | *params = 0; |
| 1862 | return; |
| 1863 | case GL_ATTACHED_SHADERS: |
| 1864 | UNIMPLEMENTED(); // FIXME |
| 1865 | *params = 2; |
| 1866 | return; |
| 1867 | case GL_ACTIVE_ATTRIBUTES: |
| 1868 | UNIMPLEMENTED(); // FIXME |
| 1869 | *params = 0; |
| 1870 | return; |
| 1871 | case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: |
| 1872 | UNIMPLEMENTED(); // FIXME |
| 1873 | *params = 0; |
| 1874 | return; |
| 1875 | case GL_ACTIVE_UNIFORMS: |
| 1876 | UNIMPLEMENTED(); // FIXME |
| 1877 | *params = 0; |
| 1878 | return; |
| 1879 | case GL_ACTIVE_UNIFORM_MAX_LENGTH: |
| 1880 | UNIMPLEMENTED(); // FIXME |
| 1881 | *params = 0; |
| 1882 | return; |
| 1883 | default: |
| 1884 | return error(GL_INVALID_ENUM); |
| 1885 | } |
| 1886 | } |
| 1887 | } |
| 1888 | catch(std::bad_alloc&) |
| 1889 | { |
| 1890 | return error(GL_OUT_OF_MEMORY); |
| 1891 | } |
| 1892 | } |
| 1893 | |
| 1894 | void __stdcall glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, char* infolog) |
| 1895 | { |
| 1896 | TRACE("GLuint program = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, char* infolog = 0x%0.8p", program, bufsize, length, infolog); |
| 1897 | |
| 1898 | try |
| 1899 | { |
| 1900 | if (bufsize < 0) |
| 1901 | { |
| 1902 | return error(GL_INVALID_VALUE); |
| 1903 | } |
| 1904 | |
| 1905 | UNIMPLEMENTED(); // FIXME |
| 1906 | } |
| 1907 | catch(std::bad_alloc&) |
| 1908 | { |
| 1909 | return error(GL_OUT_OF_MEMORY); |
| 1910 | } |
| 1911 | } |
| 1912 | |
| 1913 | void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params) |
| 1914 | { |
| 1915 | TRACE("GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p", target, pname, params); |
| 1916 | |
| 1917 | try |
| 1918 | { |
| 1919 | UNIMPLEMENTED(); // FIXME |
| 1920 | } |
| 1921 | catch(std::bad_alloc&) |
| 1922 | { |
| 1923 | return error(GL_OUT_OF_MEMORY); |
| 1924 | } |
| 1925 | } |
| 1926 | |
| 1927 | void __stdcall glGetShaderiv(GLuint shader, GLenum pname, GLint* params) |
| 1928 | { |
| 1929 | TRACE("GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p", shader, pname, params); |
| 1930 | |
| 1931 | try |
| 1932 | { |
| 1933 | gl::Context *context = gl::getContext(); |
| 1934 | |
| 1935 | if (context) |
| 1936 | { |
| 1937 | gl::Shader *shaderObject = context->getShader(shader); |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 1938 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1939 | if (!shaderObject) |
| 1940 | { |
| 1941 | return error(GL_INVALID_VALUE); |
| 1942 | } |
| 1943 | |
| 1944 | switch (pname) |
| 1945 | { |
| 1946 | case GL_SHADER_TYPE: |
| 1947 | *params = shaderObject->getType(); |
| 1948 | return; |
| 1949 | case GL_DELETE_STATUS: |
| 1950 | UNIMPLEMENTED(); // FIXME |
| 1951 | *params = GL_FALSE; |
| 1952 | return; |
| 1953 | case GL_COMPILE_STATUS: |
| 1954 | *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE; |
| 1955 | return; |
| 1956 | case GL_INFO_LOG_LENGTH: |
| 1957 | UNIMPLEMENTED(); // FIXME |
| 1958 | *params = 0; |
| 1959 | return; |
| 1960 | case GL_SHADER_SOURCE_LENGTH: |
| 1961 | UNIMPLEMENTED(); // FIXME |
| 1962 | *params = 1; |
| 1963 | return; |
| 1964 | default: |
| 1965 | return error(GL_INVALID_ENUM); |
| 1966 | } |
| 1967 | } |
| 1968 | } |
| 1969 | catch(std::bad_alloc&) |
| 1970 | { |
| 1971 | return error(GL_OUT_OF_MEMORY); |
| 1972 | } |
| 1973 | } |
| 1974 | |
| 1975 | void __stdcall glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, char* infolog) |
| 1976 | { |
| 1977 | TRACE("GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, char* infolog = 0x%0.8p", shader, bufsize, length, infolog); |
| 1978 | |
| 1979 | try |
| 1980 | { |
| 1981 | if (bufsize < 0) |
| 1982 | { |
| 1983 | return error(GL_INVALID_VALUE); |
| 1984 | } |
| 1985 | |
| 1986 | UNIMPLEMENTED(); // FIXME |
| 1987 | } |
| 1988 | catch(std::bad_alloc&) |
| 1989 | { |
| 1990 | return error(GL_OUT_OF_MEMORY); |
| 1991 | } |
| 1992 | } |
| 1993 | |
| 1994 | void __stdcall glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision) |
| 1995 | { |
| 1996 | TRACE("GLenum shadertype = 0x%X, GLenum precisiontype = 0x%X, GLint* range = 0x%0.8p, GLint* precision = 0x%0.8p", shadertype, precisiontype, range, precision); |
| 1997 | |
| 1998 | try |
| 1999 | { |
| 2000 | UNIMPLEMENTED(); // FIXME |
| 2001 | } |
| 2002 | catch(std::bad_alloc&) |
| 2003 | { |
| 2004 | return error(GL_OUT_OF_MEMORY); |
| 2005 | } |
| 2006 | } |
| 2007 | |
| 2008 | void __stdcall glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, char* source) |
| 2009 | { |
| 2010 | TRACE("GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, char* source = 0x%0.8p", shader, bufsize, length, source); |
| 2011 | |
| 2012 | try |
| 2013 | { |
| 2014 | if (bufsize < 0) |
| 2015 | { |
| 2016 | return error(GL_INVALID_VALUE); |
| 2017 | } |
| 2018 | |
| 2019 | UNIMPLEMENTED(); // FIXME |
| 2020 | } |
| 2021 | catch(std::bad_alloc&) |
| 2022 | { |
| 2023 | return error(GL_OUT_OF_MEMORY); |
| 2024 | } |
| 2025 | } |
| 2026 | |
| 2027 | const GLubyte* __stdcall glGetString(GLenum name) |
| 2028 | { |
| 2029 | TRACE("GLenum name = 0x%X", name); |
| 2030 | |
| 2031 | try |
| 2032 | { |
| 2033 | switch (name) |
| 2034 | { |
| 2035 | case GL_VENDOR: |
| 2036 | return (GLubyte*)"TransGaming Inc."; |
| 2037 | case GL_RENDERER: |
| 2038 | return (GLubyte*)"ANGLE"; |
| 2039 | case GL_VERSION: |
| 2040 | return (GLubyte*)"OpenGL ES 2.0 (git-devel "__DATE__ " " __TIME__")"; |
| 2041 | case GL_SHADING_LANGUAGE_VERSION: |
| 2042 | return (GLubyte*)"OpenGL ES GLSL ES 1.00 (git-devel "__DATE__ " " __TIME__")"; |
| 2043 | case GL_EXTENSIONS: |
| 2044 | return (GLubyte*)""; |
| 2045 | default: |
| 2046 | return error(GL_INVALID_ENUM, (GLubyte*)NULL); |
| 2047 | } |
| 2048 | } |
| 2049 | catch(std::bad_alloc&) |
| 2050 | { |
| 2051 | return error(GL_OUT_OF_MEMORY, (GLubyte*)NULL); |
| 2052 | } |
| 2053 | |
| 2054 | return NULL; |
| 2055 | } |
| 2056 | |
| 2057 | void __stdcall glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params) |
| 2058 | { |
| 2059 | TRACE("GLenum target = 0x%X, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p", target, pname, params); |
| 2060 | |
| 2061 | try |
| 2062 | { |
| 2063 | UNIMPLEMENTED(); // FIXME |
| 2064 | } |
| 2065 | catch(std::bad_alloc&) |
| 2066 | { |
| 2067 | return error(GL_OUT_OF_MEMORY); |
| 2068 | } |
| 2069 | } |
| 2070 | |
| 2071 | void __stdcall glGetTexParameteriv(GLenum target, GLenum pname, GLint* params) |
| 2072 | { |
| 2073 | TRACE("GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p", target, pname, params); |
| 2074 | |
| 2075 | try |
| 2076 | { |
| 2077 | UNIMPLEMENTED(); // FIXME |
| 2078 | } |
| 2079 | catch(std::bad_alloc&) |
| 2080 | { |
| 2081 | return error(GL_OUT_OF_MEMORY); |
| 2082 | } |
| 2083 | } |
| 2084 | |
| 2085 | void __stdcall glGetUniformfv(GLuint program, GLint location, GLfloat* params) |
| 2086 | { |
| 2087 | TRACE("GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p", program, location, params); |
| 2088 | |
| 2089 | try |
| 2090 | { |
| 2091 | UNIMPLEMENTED(); // FIXME |
| 2092 | } |
| 2093 | catch(std::bad_alloc&) |
| 2094 | { |
| 2095 | return error(GL_OUT_OF_MEMORY); |
| 2096 | } |
| 2097 | } |
| 2098 | |
| 2099 | void __stdcall glGetUniformiv(GLuint program, GLint location, GLint* params) |
| 2100 | { |
| 2101 | TRACE("GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p", program, location, params); |
| 2102 | |
| 2103 | try |
| 2104 | { |
| 2105 | UNIMPLEMENTED(); // FIXME |
| 2106 | } |
| 2107 | catch(std::bad_alloc&) |
| 2108 | { |
| 2109 | return error(GL_OUT_OF_MEMORY); |
| 2110 | } |
| 2111 | } |
| 2112 | |
| 2113 | int __stdcall glGetUniformLocation(GLuint program, const char* name) |
| 2114 | { |
| 2115 | TRACE("GLuint program = %d, const char* name = 0x%0.8p", program, name); |
| 2116 | |
| 2117 | try |
| 2118 | { |
| 2119 | gl::Context *context = gl::getContext(); |
| 2120 | |
| 2121 | if (strstr(name, "gl_") == name) |
| 2122 | { |
| 2123 | return -1; |
| 2124 | } |
| 2125 | |
| 2126 | if (context) |
| 2127 | { |
| 2128 | gl::Program *programObject = context->getProgram(program); |
| 2129 | |
| 2130 | if (!programObject) |
| 2131 | { |
| 2132 | return error(GL_INVALID_VALUE, -1); |
| 2133 | } |
| 2134 | |
| 2135 | if (!programObject->isLinked()) |
| 2136 | { |
| 2137 | return error(GL_INVALID_OPERATION, -1); |
| 2138 | } |
| 2139 | |
| 2140 | return programObject->getUniformLocation(name); |
| 2141 | } |
| 2142 | } |
| 2143 | catch(std::bad_alloc&) |
| 2144 | { |
| 2145 | return error(GL_OUT_OF_MEMORY, -1); |
| 2146 | } |
| 2147 | |
| 2148 | return -1; |
| 2149 | } |
| 2150 | |
| 2151 | void __stdcall glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params) |
| 2152 | { |
| 2153 | TRACE("GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p", index, pname, params); |
| 2154 | |
| 2155 | try |
| 2156 | { |
| 2157 | if (index >= gl::MAX_VERTEX_ATTRIBS) |
| 2158 | { |
| 2159 | return error(GL_INVALID_VALUE); |
| 2160 | } |
| 2161 | |
| 2162 | UNIMPLEMENTED(); // FIXME |
| 2163 | } |
| 2164 | catch(std::bad_alloc&) |
| 2165 | { |
| 2166 | return error(GL_OUT_OF_MEMORY); |
| 2167 | } |
| 2168 | } |
| 2169 | |
| 2170 | void __stdcall glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params) |
| 2171 | { |
| 2172 | TRACE("GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p", index, pname, params); |
| 2173 | |
| 2174 | try |
| 2175 | { |
| 2176 | if (index >= gl::MAX_VERTEX_ATTRIBS) |
| 2177 | { |
| 2178 | return error(GL_INVALID_VALUE); |
| 2179 | } |
| 2180 | |
| 2181 | UNIMPLEMENTED(); // FIXME |
| 2182 | } |
| 2183 | catch(std::bad_alloc&) |
| 2184 | { |
| 2185 | return error(GL_OUT_OF_MEMORY); |
| 2186 | } |
| 2187 | } |
| 2188 | |
| 2189 | void __stdcall glGetVertexAttribPointerv(GLuint index, GLenum pname, void** pointer) |
| 2190 | { |
| 2191 | TRACE("GLuint index = %d, GLenum pname = 0x%X, void** pointer = 0x%0.8p", index, pname, pointer); |
| 2192 | |
| 2193 | try |
| 2194 | { |
| 2195 | if (index >= gl::MAX_VERTEX_ATTRIBS) |
| 2196 | { |
| 2197 | return error(GL_INVALID_VALUE); |
| 2198 | } |
| 2199 | |
| 2200 | UNIMPLEMENTED(); // FIXME |
| 2201 | } |
| 2202 | catch(std::bad_alloc&) |
| 2203 | { |
| 2204 | return error(GL_OUT_OF_MEMORY); |
| 2205 | } |
| 2206 | } |
| 2207 | |
| 2208 | void __stdcall glHint(GLenum target, GLenum mode) |
| 2209 | { |
| 2210 | TRACE("GLenum target = 0x%X, GLenum mode = 0x%X", target, mode); |
| 2211 | |
| 2212 | try |
| 2213 | { |
| 2214 | UNIMPLEMENTED(); // FIXME |
| 2215 | } |
| 2216 | catch(std::bad_alloc&) |
| 2217 | { |
| 2218 | return error(GL_OUT_OF_MEMORY); |
| 2219 | } |
| 2220 | } |
| 2221 | |
| 2222 | GLboolean __stdcall glIsBuffer(GLuint buffer) |
| 2223 | { |
| 2224 | TRACE("GLuint buffer = %d", buffer); |
| 2225 | |
| 2226 | try |
| 2227 | { |
| 2228 | gl::Context *context = gl::getContext(); |
| 2229 | |
| 2230 | if (context && buffer) |
| 2231 | { |
| 2232 | gl::Buffer *bufferObject = context->getBuffer(buffer); |
| 2233 | |
| 2234 | if (bufferObject) |
| 2235 | { |
| 2236 | return GL_TRUE; |
| 2237 | } |
| 2238 | } |
| 2239 | } |
| 2240 | catch(std::bad_alloc&) |
| 2241 | { |
| 2242 | return error(GL_OUT_OF_MEMORY, GL_FALSE); |
| 2243 | } |
| 2244 | |
| 2245 | return GL_FALSE; |
| 2246 | } |
| 2247 | |
| 2248 | GLboolean __stdcall glIsEnabled(GLenum cap) |
| 2249 | { |
| 2250 | TRACE("GLenum cap = 0x%X", cap); |
| 2251 | |
| 2252 | try |
| 2253 | { |
| 2254 | gl::Context *context = gl::getContext(); |
| 2255 | |
| 2256 | if (context) |
| 2257 | { |
| 2258 | switch (cap) |
| 2259 | { |
| 2260 | case GL_CULL_FACE: return context->cullFace; |
| 2261 | case GL_POLYGON_OFFSET_FILL: return context->polygonOffsetFill; |
| 2262 | case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->sampleAlphaToCoverage; |
| 2263 | case GL_SAMPLE_COVERAGE: return context->sampleCoverage; |
| 2264 | case GL_SCISSOR_TEST: return context->scissorTest; |
| 2265 | case GL_STENCIL_TEST: return context->stencilTest; |
| 2266 | case GL_DEPTH_TEST: return context->depthTest; |
| 2267 | case GL_BLEND: return context->blend; |
| 2268 | case GL_DITHER: return context->dither; |
| 2269 | default: |
| 2270 | return error(GL_INVALID_ENUM, false); |
| 2271 | } |
| 2272 | } |
| 2273 | } |
| 2274 | catch(std::bad_alloc&) |
| 2275 | { |
| 2276 | return error(GL_OUT_OF_MEMORY, false); |
| 2277 | } |
| 2278 | |
| 2279 | return false; |
| 2280 | } |
| 2281 | |
| 2282 | GLboolean __stdcall glIsFramebuffer(GLuint framebuffer) |
| 2283 | { |
| 2284 | TRACE("GLuint framebuffer = %d", framebuffer); |
| 2285 | |
| 2286 | try |
| 2287 | { |
| 2288 | gl::Context *context = gl::getContext(); |
| 2289 | |
| 2290 | if (context && framebuffer) |
| 2291 | { |
| 2292 | gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer); |
| 2293 | |
| 2294 | if (framebufferObject) |
| 2295 | { |
| 2296 | return GL_TRUE; |
| 2297 | } |
| 2298 | } |
| 2299 | } |
| 2300 | catch(std::bad_alloc&) |
| 2301 | { |
| 2302 | return error(GL_OUT_OF_MEMORY, GL_FALSE); |
| 2303 | } |
| 2304 | |
| 2305 | return GL_FALSE; |
| 2306 | } |
| 2307 | |
| 2308 | GLboolean __stdcall glIsProgram(GLuint program) |
| 2309 | { |
| 2310 | TRACE("GLuint program = %d", program); |
| 2311 | |
| 2312 | try |
| 2313 | { |
| 2314 | gl::Context *context = gl::getContext(); |
| 2315 | |
| 2316 | if (context && program) |
| 2317 | { |
| 2318 | gl::Program *programObject = context->getProgram(program); |
| 2319 | |
| 2320 | if (programObject) |
| 2321 | { |
| 2322 | return GL_TRUE; |
| 2323 | } |
| 2324 | } |
| 2325 | } |
| 2326 | catch(std::bad_alloc&) |
| 2327 | { |
| 2328 | return error(GL_OUT_OF_MEMORY, GL_FALSE); |
| 2329 | } |
| 2330 | |
| 2331 | return GL_FALSE; |
| 2332 | } |
| 2333 | |
| 2334 | GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer) |
| 2335 | { |
| 2336 | TRACE("GLuint renderbuffer = %d", renderbuffer); |
| 2337 | |
| 2338 | try |
| 2339 | { |
| 2340 | gl::Context *context = gl::getContext(); |
| 2341 | |
| 2342 | if (context && renderbuffer) |
| 2343 | { |
| 2344 | gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer); |
| 2345 | |
| 2346 | if (renderbufferObject) |
| 2347 | { |
| 2348 | return GL_TRUE; |
| 2349 | } |
| 2350 | } |
| 2351 | } |
| 2352 | catch(std::bad_alloc&) |
| 2353 | { |
| 2354 | return error(GL_OUT_OF_MEMORY, GL_FALSE); |
| 2355 | } |
| 2356 | |
| 2357 | return GL_FALSE; |
| 2358 | } |
| 2359 | |
| 2360 | GLboolean __stdcall glIsShader(GLuint shader) |
| 2361 | { |
| 2362 | TRACE("GLuint shader = %d", shader); |
| 2363 | |
| 2364 | try |
| 2365 | { |
| 2366 | gl::Context *context = gl::getContext(); |
| 2367 | |
| 2368 | if (context && shader) |
| 2369 | { |
| 2370 | gl::Shader *shaderObject = context->getShader(shader); |
| 2371 | |
| 2372 | if (shaderObject) |
| 2373 | { |
| 2374 | return GL_TRUE; |
| 2375 | } |
| 2376 | } |
| 2377 | } |
| 2378 | catch(std::bad_alloc&) |
| 2379 | { |
| 2380 | return error(GL_OUT_OF_MEMORY, GL_FALSE); |
| 2381 | } |
| 2382 | |
| 2383 | return GL_FALSE; |
| 2384 | } |
| 2385 | |
| 2386 | GLboolean __stdcall glIsTexture(GLuint texture) |
| 2387 | { |
| 2388 | TRACE("GLuint texture = %d", texture); |
| 2389 | |
| 2390 | try |
| 2391 | { |
| 2392 | gl::Context *context = gl::getContext(); |
| 2393 | |
| 2394 | if (context && texture) |
| 2395 | { |
| 2396 | gl::Texture *textureObject = context->getTexture(texture); |
| 2397 | |
| 2398 | if (textureObject) |
| 2399 | { |
| 2400 | return GL_TRUE; |
| 2401 | } |
| 2402 | } |
| 2403 | } |
| 2404 | catch(std::bad_alloc&) |
| 2405 | { |
| 2406 | return error(GL_OUT_OF_MEMORY, GL_FALSE); |
| 2407 | } |
| 2408 | |
| 2409 | return GL_FALSE; |
| 2410 | } |
| 2411 | |
| 2412 | void __stdcall glLineWidth(GLfloat width) |
| 2413 | { |
| 2414 | TRACE("GLfloat width = %f", width); |
| 2415 | |
| 2416 | try |
| 2417 | { |
| 2418 | if (width <= 0.0f) |
| 2419 | { |
| 2420 | return error(GL_INVALID_VALUE); |
| 2421 | } |
| 2422 | |
| 2423 | if (width != 1.0f) |
| 2424 | { |
| 2425 | UNIMPLEMENTED(); // FIXME |
| 2426 | } |
| 2427 | } |
| 2428 | catch(std::bad_alloc&) |
| 2429 | { |
| 2430 | return error(GL_OUT_OF_MEMORY); |
| 2431 | } |
| 2432 | } |
| 2433 | |
| 2434 | void __stdcall glLinkProgram(GLuint program) |
| 2435 | { |
| 2436 | TRACE("GLuint program = %d", program); |
| 2437 | |
| 2438 | try |
| 2439 | { |
| 2440 | gl::Context *context = gl::getContext(); |
| 2441 | |
| 2442 | if (context) |
| 2443 | { |
| 2444 | gl::Program *programObject = context->getProgram(program); |
| 2445 | |
| 2446 | if (!programObject) |
| 2447 | { |
| 2448 | return error(GL_INVALID_VALUE); |
| 2449 | } |
| 2450 | |
| 2451 | programObject->link(); |
| 2452 | } |
| 2453 | } |
| 2454 | catch(std::bad_alloc&) |
| 2455 | { |
| 2456 | return error(GL_OUT_OF_MEMORY); |
| 2457 | } |
| 2458 | } |
| 2459 | |
| 2460 | void __stdcall glPixelStorei(GLenum pname, GLint param) |
| 2461 | { |
| 2462 | TRACE("GLenum pname = 0x%X, GLint param = %d", pname, param); |
| 2463 | |
| 2464 | try |
| 2465 | { |
| 2466 | switch (pname) |
| 2467 | { |
| 2468 | case GL_UNPACK_ALIGNMENT: |
| 2469 | // UNIMPLEMENTED(); // FIXME |
| 2470 | break; |
| 2471 | case GL_PACK_ALIGNMENT: |
| 2472 | // UNIMPLEMENTED(); // FIXME |
| 2473 | break; |
| 2474 | default: |
| 2475 | return error(GL_INVALID_ENUM); |
| 2476 | } |
| 2477 | } |
| 2478 | catch(std::bad_alloc&) |
| 2479 | { |
| 2480 | return error(GL_OUT_OF_MEMORY); |
| 2481 | } |
| 2482 | } |
| 2483 | |
| 2484 | void __stdcall glPolygonOffset(GLfloat factor, GLfloat units) |
| 2485 | { |
| 2486 | TRACE("GLfloat factor = %f, GLfloat units = %f", factor, units); |
| 2487 | |
| 2488 | try |
| 2489 | { |
| 2490 | if (factor != 0.0f || units != 0.0f) |
| 2491 | { |
| 2492 | UNIMPLEMENTED(); // FIXME |
| 2493 | } |
| 2494 | } |
| 2495 | catch(std::bad_alloc&) |
| 2496 | { |
| 2497 | return error(GL_OUT_OF_MEMORY); |
| 2498 | } |
| 2499 | } |
| 2500 | |
| 2501 | void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels) |
| 2502 | { |
| 2503 | TRACE("GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, void* pixels = 0x%0.8p", x, y, width, height, format, type, pixels); |
| 2504 | |
| 2505 | try |
| 2506 | { |
| 2507 | if (width < 0 || height < 0) |
| 2508 | { |
| 2509 | return error(GL_INVALID_VALUE); |
| 2510 | } |
| 2511 | |
| 2512 | switch (format) |
| 2513 | { |
| 2514 | case GL_RGBA: |
| 2515 | switch (type) |
| 2516 | { |
| 2517 | case GL_UNSIGNED_BYTE: |
| 2518 | break; |
| 2519 | default: |
| 2520 | return error(GL_INVALID_OPERATION); |
| 2521 | } |
| 2522 | break; |
| 2523 | case gl::IMPLEMENTATION_COLOR_READ_FORMAT: |
| 2524 | switch (type) |
| 2525 | { |
| 2526 | case gl::IMPLEMENTATION_COLOR_READ_TYPE: |
| 2527 | break; |
| 2528 | default: |
| 2529 | return error(GL_INVALID_OPERATION); |
| 2530 | } |
| 2531 | break; |
| 2532 | default: |
| 2533 | return error(GL_INVALID_OPERATION); |
| 2534 | } |
| 2535 | |
| 2536 | gl::Context *context = gl::getContext(); |
| 2537 | |
| 2538 | if (context) |
| 2539 | { |
| 2540 | context->readPixels(x, y, width, height, format, type, pixels); |
| 2541 | } |
| 2542 | } |
| 2543 | catch(std::bad_alloc&) |
| 2544 | { |
| 2545 | return error(GL_OUT_OF_MEMORY); |
| 2546 | } |
| 2547 | } |
| 2548 | |
| 2549 | void __stdcall glReleaseShaderCompiler(void) |
| 2550 | { |
| 2551 | TRACE(""); |
| 2552 | |
| 2553 | try |
| 2554 | { |
| 2555 | gl::Shader::releaseCompiler(); |
| 2556 | } |
| 2557 | catch(std::bad_alloc&) |
| 2558 | { |
| 2559 | return error(GL_OUT_OF_MEMORY); |
| 2560 | } |
| 2561 | } |
| 2562 | |
| 2563 | void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height) |
| 2564 | { |
| 2565 | TRACE("GLenum target = 0x%X, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d", target, internalformat, width, height); |
| 2566 | |
| 2567 | try |
| 2568 | { |
| 2569 | switch (target) |
| 2570 | { |
| 2571 | case GL_RENDERBUFFER: |
| 2572 | break; |
| 2573 | default: |
| 2574 | return error(GL_INVALID_ENUM); |
| 2575 | } |
| 2576 | |
| 2577 | switch (internalformat) |
| 2578 | { |
| 2579 | case GL_DEPTH_COMPONENT16: |
| 2580 | case GL_RGBA4: |
| 2581 | case GL_RGB5_A1: |
| 2582 | case GL_RGB565: |
| 2583 | case GL_STENCIL_INDEX8: |
| 2584 | break; |
| 2585 | default: |
| 2586 | return error(GL_INVALID_ENUM); |
| 2587 | } |
| 2588 | |
| 2589 | if (width < 0 || height < 0 || width > gl::MAX_RENDERBUFFER_SIZE || height > gl::MAX_RENDERBUFFER_SIZE) |
| 2590 | { |
| 2591 | return error(GL_INVALID_VALUE); |
| 2592 | } |
| 2593 | |
| 2594 | gl::Context *context = gl::getContext(); |
| 2595 | |
| 2596 | if (context) |
| 2597 | { |
| 2598 | if (context->framebuffer == 0 || context->renderbuffer == 0) |
| 2599 | { |
| 2600 | return error(GL_INVALID_OPERATION); |
| 2601 | } |
| 2602 | |
| 2603 | switch (internalformat) |
| 2604 | { |
| 2605 | case GL_DEPTH_COMPONENT16: |
| 2606 | context->setRenderbuffer(new gl::Depthbuffer(width, height)); |
| 2607 | break; |
| 2608 | case GL_RGBA4: |
| 2609 | case GL_RGB5_A1: |
| 2610 | case GL_RGB565: |
| 2611 | UNIMPLEMENTED(); // FIXME |
daniel@transgaming.com | 4a9d65c | 2010-03-08 21:30:56 +0000 | [diff] [blame] | 2612 | // context->setRenderbuffer(new Colorbuffer(renderTarget)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2613 | break; |
| 2614 | case GL_STENCIL_INDEX8: |
daniel@transgaming.com | 4a9d65c | 2010-03-08 21:30:56 +0000 | [diff] [blame] | 2615 | context->setRenderbuffer(new gl::Stencilbuffer(width, height)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2616 | break; |
| 2617 | default: |
| 2618 | return error(GL_INVALID_ENUM); |
| 2619 | } |
| 2620 | } |
| 2621 | } |
| 2622 | catch(std::bad_alloc&) |
| 2623 | { |
| 2624 | return error(GL_OUT_OF_MEMORY); |
| 2625 | } |
| 2626 | } |
| 2627 | |
| 2628 | void __stdcall glSampleCoverage(GLclampf value, GLboolean invert) |
| 2629 | { |
| 2630 | TRACE("GLclampf value = %f, GLboolean invert = %d", value, invert); |
| 2631 | |
| 2632 | try |
| 2633 | { |
| 2634 | gl::Context* context = gl::getContext(); |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 2635 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2636 | if (context) |
| 2637 | { |
| 2638 | context->sampleCoverageValue = gl::clamp01(value); |
| 2639 | context->sampleCoverageInvert = invert; |
| 2640 | } |
| 2641 | } |
| 2642 | catch(std::bad_alloc&) |
| 2643 | { |
| 2644 | return error(GL_OUT_OF_MEMORY); |
| 2645 | } |
| 2646 | } |
| 2647 | |
| 2648 | void __stdcall glScissor(GLint x, GLint y, GLsizei width, GLsizei height) |
| 2649 | { |
| 2650 | TRACE("GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d", x, y, width, height); |
| 2651 | |
| 2652 | try |
| 2653 | { |
| 2654 | if (width < 0 || height < 0) |
| 2655 | { |
| 2656 | return error(GL_INVALID_VALUE); |
| 2657 | } |
| 2658 | |
| 2659 | gl::Context* context = gl::getContext(); |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 2660 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2661 | if (context) |
| 2662 | { |
| 2663 | context->scissorX = x; |
| 2664 | context->scissorY = y; |
| 2665 | context->scissorWidth = width; |
| 2666 | context->scissorHeight = height; |
| 2667 | } |
| 2668 | } |
| 2669 | catch(std::bad_alloc&) |
| 2670 | { |
| 2671 | return error(GL_OUT_OF_MEMORY); |
| 2672 | } |
| 2673 | } |
| 2674 | |
| 2675 | void __stdcall glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const void* binary, GLsizei length) |
| 2676 | { |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 2677 | TRACE("GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, const void* binary = 0x%0.8p, GLsizei length = %d", |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2678 | n, shaders, binaryformat, binary, length); |
| 2679 | |
| 2680 | try |
| 2681 | { |
| 2682 | if (n < 0 || length < 0) |
| 2683 | { |
| 2684 | return error(GL_INVALID_VALUE); |
| 2685 | } |
| 2686 | |
| 2687 | UNIMPLEMENTED(); // FIXME |
| 2688 | } |
| 2689 | catch(std::bad_alloc&) |
| 2690 | { |
| 2691 | return error(GL_OUT_OF_MEMORY); |
| 2692 | } |
| 2693 | } |
| 2694 | |
| 2695 | void __stdcall glShaderSource(GLuint shader, GLsizei count, const char** string, const GLint* length) |
| 2696 | { |
| 2697 | TRACE("GLuint shader = %d, GLsizei count = %d, const char** string = 0x%0.8p, const GLint* length = 0x%0.8p", shader, count, string, length); |
| 2698 | |
| 2699 | try |
| 2700 | { |
| 2701 | if (count < 0) |
| 2702 | { |
| 2703 | return error(GL_INVALID_VALUE); |
| 2704 | } |
| 2705 | |
| 2706 | gl::Context *context = gl::getContext(); |
| 2707 | |
| 2708 | if (context) |
| 2709 | { |
| 2710 | gl::Shader *shaderObject = context->getShader(shader); |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 2711 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2712 | if (!shaderObject) |
| 2713 | { |
| 2714 | return error(GL_INVALID_VALUE); |
| 2715 | } |
| 2716 | |
| 2717 | shaderObject->setSource(count, string, length); |
| 2718 | } |
| 2719 | } |
| 2720 | catch(std::bad_alloc&) |
| 2721 | { |
| 2722 | return error(GL_OUT_OF_MEMORY); |
| 2723 | } |
| 2724 | } |
| 2725 | |
| 2726 | void __stdcall glStencilFunc(GLenum func, GLint ref, GLuint mask) |
| 2727 | { |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 2728 | glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2729 | } |
| 2730 | |
| 2731 | void __stdcall glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask) |
| 2732 | { |
| 2733 | TRACE("GLenum face = 0x%X, GLenum func = 0x%X, GLint ref = %d, GLuint mask = %d", face, func, ref, mask); |
| 2734 | |
| 2735 | try |
| 2736 | { |
| 2737 | switch (face) |
| 2738 | { |
| 2739 | case GL_FRONT: |
| 2740 | case GL_BACK: |
| 2741 | case GL_FRONT_AND_BACK: |
| 2742 | break; |
| 2743 | default: |
| 2744 | return error(GL_INVALID_ENUM); |
| 2745 | } |
| 2746 | |
| 2747 | switch (func) |
| 2748 | { |
| 2749 | case GL_NEVER: |
| 2750 | case GL_ALWAYS: |
| 2751 | case GL_LESS: |
| 2752 | case GL_LEQUAL: |
| 2753 | case GL_EQUAL: |
| 2754 | case GL_GEQUAL: |
| 2755 | case GL_GREATER: |
| 2756 | case GL_NOTEQUAL: |
| 2757 | break; |
| 2758 | default: |
| 2759 | return error(GL_INVALID_ENUM); |
| 2760 | } |
| 2761 | |
| 2762 | gl::Context *context = gl::getContext(); |
| 2763 | |
| 2764 | if (context) |
| 2765 | { |
| 2766 | if (face == GL_FRONT || face == GL_FRONT_AND_BACK) |
| 2767 | { |
| 2768 | context->stencilFunc = func; |
| 2769 | context->stencilRef = ref; |
| 2770 | context->stencilMask = mask; |
| 2771 | } |
| 2772 | |
| 2773 | if (face == GL_BACK || face == GL_FRONT_AND_BACK) |
| 2774 | { |
| 2775 | context->stencilBackFunc = func; |
| 2776 | context->stencilBackRef = ref; |
| 2777 | context->stencilBackMask = mask; |
| 2778 | } |
| 2779 | } |
| 2780 | } |
| 2781 | catch(std::bad_alloc&) |
| 2782 | { |
| 2783 | return error(GL_OUT_OF_MEMORY); |
| 2784 | } |
| 2785 | } |
| 2786 | |
| 2787 | void __stdcall glStencilMask(GLuint mask) |
| 2788 | { |
| 2789 | glStencilMaskSeparate(GL_FRONT_AND_BACK, mask); |
| 2790 | } |
| 2791 | |
| 2792 | void __stdcall glStencilMaskSeparate(GLenum face, GLuint mask) |
| 2793 | { |
| 2794 | TRACE("GLenum face = 0x%X, GLuint mask = %d", face, mask); |
| 2795 | |
| 2796 | try |
| 2797 | { |
| 2798 | switch (face) |
| 2799 | { |
| 2800 | case GL_FRONT: |
| 2801 | case GL_BACK: |
| 2802 | case GL_FRONT_AND_BACK: |
| 2803 | break; |
| 2804 | default: |
| 2805 | return error(GL_INVALID_ENUM); |
| 2806 | } |
| 2807 | |
| 2808 | gl::Context *context = gl::getContext(); |
| 2809 | |
| 2810 | if (context) |
| 2811 | { |
| 2812 | if (face == GL_FRONT || face == GL_FRONT_AND_BACK) |
| 2813 | { |
| 2814 | context->stencilWritemask = mask; |
| 2815 | } |
| 2816 | |
| 2817 | if (face == GL_BACK || face == GL_FRONT_AND_BACK) |
| 2818 | { |
| 2819 | context->stencilBackWritemask = mask; |
| 2820 | } |
| 2821 | } |
| 2822 | } |
| 2823 | catch(std::bad_alloc&) |
| 2824 | { |
| 2825 | return error(GL_OUT_OF_MEMORY); |
| 2826 | } |
| 2827 | } |
| 2828 | |
| 2829 | void __stdcall glStencilOp(GLenum fail, GLenum zfail, GLenum zpass) |
| 2830 | { |
| 2831 | glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass); |
| 2832 | } |
| 2833 | |
| 2834 | void __stdcall glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass) |
| 2835 | { |
| 2836 | TRACE("GLenum face = 0x%X, GLenum fail = 0x%X, GLenum zfail = 0x%X, GLenum zpas = 0x%Xs", face, fail, zfail, zpass); |
| 2837 | |
| 2838 | try |
| 2839 | { |
| 2840 | switch (face) |
| 2841 | { |
| 2842 | case GL_FRONT: |
| 2843 | case GL_BACK: |
| 2844 | case GL_FRONT_AND_BACK: |
| 2845 | break; |
| 2846 | default: |
| 2847 | return error(GL_INVALID_ENUM); |
| 2848 | } |
| 2849 | |
| 2850 | switch (fail) |
| 2851 | { |
| 2852 | case GL_ZERO: |
| 2853 | case GL_KEEP: |
| 2854 | case GL_REPLACE: |
| 2855 | case GL_INCR: |
| 2856 | case GL_DECR: |
| 2857 | case GL_INVERT: |
| 2858 | case GL_INCR_WRAP: |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 2859 | case GL_DECR_WRAP: |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2860 | break; |
| 2861 | default: |
| 2862 | return error(GL_INVALID_ENUM); |
| 2863 | } |
| 2864 | |
| 2865 | switch (zfail) |
| 2866 | { |
| 2867 | case GL_ZERO: |
| 2868 | case GL_KEEP: |
| 2869 | case GL_REPLACE: |
| 2870 | case GL_INCR: |
| 2871 | case GL_DECR: |
| 2872 | case GL_INVERT: |
| 2873 | case GL_INCR_WRAP: |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 2874 | case GL_DECR_WRAP: |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2875 | break; |
| 2876 | default: |
| 2877 | return error(GL_INVALID_ENUM); |
| 2878 | } |
| 2879 | |
| 2880 | switch (zpass) |
| 2881 | { |
| 2882 | case GL_ZERO: |
| 2883 | case GL_KEEP: |
| 2884 | case GL_REPLACE: |
| 2885 | case GL_INCR: |
| 2886 | case GL_DECR: |
| 2887 | case GL_INVERT: |
| 2888 | case GL_INCR_WRAP: |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 2889 | case GL_DECR_WRAP: |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2890 | break; |
| 2891 | default: |
| 2892 | return error(GL_INVALID_ENUM); |
| 2893 | } |
| 2894 | |
| 2895 | gl::Context *context = gl::getContext(); |
| 2896 | |
| 2897 | if (context) |
| 2898 | { |
| 2899 | if (face == GL_FRONT || face == GL_FRONT_AND_BACK) |
| 2900 | { |
| 2901 | context->stencilFail = fail; |
| 2902 | context->stencilPassDepthFail = zfail; |
| 2903 | context->stencilPassDepthPass = zpass; |
| 2904 | } |
| 2905 | |
| 2906 | if (face == GL_BACK || face == GL_FRONT_AND_BACK) |
| 2907 | { |
| 2908 | context->stencilBackFail = fail; |
| 2909 | context->stencilBackPassDepthFail = zfail; |
| 2910 | context->stencilBackPassDepthPass = zpass; |
| 2911 | } |
| 2912 | } |
| 2913 | } |
| 2914 | catch(std::bad_alloc&) |
| 2915 | { |
| 2916 | return error(GL_OUT_OF_MEMORY); |
| 2917 | } |
| 2918 | } |
| 2919 | |
| 2920 | void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pixels) |
| 2921 | { |
| 2922 | TRACE("GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d, GLenum format = 0x%X, GLenum type = 0x%X, const void* pixels = 0x%0.8p", target, level, internalformat, width, height, border, format, type, pixels); |
| 2923 | |
| 2924 | try |
| 2925 | { |
| 2926 | if (level < 0 || width < 0 || height < 0) |
| 2927 | { |
| 2928 | return error(GL_INVALID_VALUE); |
| 2929 | } |
| 2930 | |
| 2931 | if (level > 0 && (!gl::isPow2(width) || !gl::isPow2(height))) |
| 2932 | { |
| 2933 | return error(GL_INVALID_VALUE); |
| 2934 | } |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 2935 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2936 | switch (target) |
| 2937 | { |
| 2938 | case GL_TEXTURE_2D: |
| 2939 | if (width > (gl::MAX_TEXTURE_SIZE >> level) || height > (gl::MAX_TEXTURE_SIZE >> level)) |
| 2940 | { |
| 2941 | return error(GL_INVALID_VALUE); |
| 2942 | } |
| 2943 | break; |
| 2944 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 2945 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 2946 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 2947 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 2948 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 2949 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 2950 | if (!gl::isPow2(width) || !gl::isPow2(height)) |
| 2951 | { |
| 2952 | return error(GL_INVALID_VALUE); |
| 2953 | } |
| 2954 | |
| 2955 | if (width > (gl::MAX_CUBE_MAP_TEXTURE_SIZE >> level) || height > (gl::MAX_CUBE_MAP_TEXTURE_SIZE >> level)) |
| 2956 | { |
| 2957 | return error(GL_INVALID_VALUE); |
| 2958 | } |
| 2959 | break; |
| 2960 | default: |
| 2961 | return error(GL_INVALID_ENUM); |
| 2962 | } |
| 2963 | |
| 2964 | if (internalformat != format) |
| 2965 | { |
| 2966 | return error(GL_INVALID_OPERATION); |
| 2967 | } |
| 2968 | |
| 2969 | switch (internalformat) |
| 2970 | { |
| 2971 | case GL_ALPHA: |
| 2972 | case GL_LUMINANCE: |
| 2973 | case GL_LUMINANCE_ALPHA: |
| 2974 | switch (type) |
| 2975 | { |
| 2976 | case GL_UNSIGNED_BYTE: |
| 2977 | break; |
| 2978 | default: |
| 2979 | return error(GL_INVALID_ENUM); |
| 2980 | } |
| 2981 | break; |
| 2982 | case GL_RGB: |
| 2983 | switch (type) |
| 2984 | { |
| 2985 | case GL_UNSIGNED_BYTE: |
| 2986 | case GL_UNSIGNED_SHORT_5_6_5: |
| 2987 | break; |
| 2988 | default: |
| 2989 | return error(GL_INVALID_ENUM); |
| 2990 | } |
| 2991 | break; |
| 2992 | case GL_RGBA: |
| 2993 | switch (type) |
| 2994 | { |
| 2995 | case GL_UNSIGNED_BYTE: |
| 2996 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 2997 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 2998 | break; |
| 2999 | default: |
| 3000 | return error(GL_INVALID_ENUM); |
| 3001 | } |
| 3002 | break; |
| 3003 | default: |
| 3004 | return error(GL_INVALID_VALUE); |
| 3005 | } |
| 3006 | |
| 3007 | if (border != 0) |
| 3008 | { |
| 3009 | return error(GL_INVALID_VALUE); |
| 3010 | } |
| 3011 | |
| 3012 | gl::Context *context = gl::getContext(); |
| 3013 | |
| 3014 | if (context) |
| 3015 | { |
| 3016 | if (target == GL_TEXTURE_2D) |
| 3017 | { |
| 3018 | gl::Texture2D *texture = context->getTexture2D(); |
| 3019 | |
| 3020 | if (!texture) |
| 3021 | { |
| 3022 | return error(GL_INVALID_OPERATION); |
| 3023 | } |
| 3024 | |
| 3025 | texture->setImage(level, internalformat, width, height, format, type, pixels); |
| 3026 | } |
| 3027 | else |
| 3028 | { |
| 3029 | gl::TextureCubeMap *texture = context->getTextureCubeMap(); |
| 3030 | |
| 3031 | if (!texture) |
| 3032 | { |
| 3033 | return error(GL_INVALID_OPERATION); |
| 3034 | } |
| 3035 | |
| 3036 | switch (target) |
| 3037 | { |
| 3038 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 3039 | texture->setImagePosX(level, internalformat, width, height, format, type, pixels); |
| 3040 | break; |
| 3041 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 3042 | texture->setImageNegX(level, internalformat, width, height, format, type, pixels); |
| 3043 | break; |
| 3044 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 3045 | texture->setImagePosY(level, internalformat, width, height, format, type, pixels); |
| 3046 | break; |
| 3047 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 3048 | texture->setImageNegY(level, internalformat, width, height, format, type, pixels); |
| 3049 | break; |
| 3050 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 3051 | texture->setImagePosZ(level, internalformat, width, height, format, type, pixels); |
| 3052 | break; |
| 3053 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 3054 | texture->setImageNegZ(level, internalformat, width, height, format, type, pixels); |
| 3055 | break; |
| 3056 | default: UNREACHABLE(); |
| 3057 | } |
| 3058 | } |
| 3059 | } |
| 3060 | } |
| 3061 | catch(std::bad_alloc&) |
| 3062 | { |
| 3063 | return error(GL_OUT_OF_MEMORY); |
| 3064 | } |
| 3065 | } |
| 3066 | |
| 3067 | void __stdcall glTexParameterf(GLenum target, GLenum pname, GLfloat param) |
| 3068 | { |
| 3069 | glTexParameteri(target, pname, (GLint)param); |
| 3070 | } |
| 3071 | |
| 3072 | void __stdcall glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params) |
| 3073 | { |
| 3074 | glTexParameteri(target, pname, (GLint)*params); |
| 3075 | } |
| 3076 | |
| 3077 | void __stdcall glTexParameteri(GLenum target, GLenum pname, GLint param) |
| 3078 | { |
| 3079 | TRACE("GLenum target = 0x%X, GLenum pname = 0x%X, GLfloat param = %f", target, pname, param); |
| 3080 | |
| 3081 | try |
| 3082 | { |
| 3083 | gl::Context *context = gl::getContext(); |
| 3084 | |
| 3085 | if (context) |
| 3086 | { |
| 3087 | gl::Texture *texture; |
| 3088 | |
| 3089 | switch (target) |
| 3090 | { |
| 3091 | case GL_TEXTURE_2D: |
| 3092 | texture = context->getTexture2D(); |
| 3093 | break; |
| 3094 | case GL_TEXTURE_CUBE_MAP: |
| 3095 | texture = context->getTextureCubeMap(); |
| 3096 | break; |
| 3097 | default: |
| 3098 | return error(GL_INVALID_ENUM); |
| 3099 | } |
| 3100 | |
| 3101 | switch (pname) |
| 3102 | { |
| 3103 | case GL_TEXTURE_WRAP_S: |
| 3104 | if (!texture->setWrapS((GLenum)param)) |
| 3105 | { |
| 3106 | return error(GL_INVALID_ENUM); |
| 3107 | } |
| 3108 | break; |
| 3109 | case GL_TEXTURE_WRAP_T: |
| 3110 | if (!texture->setWrapT((GLenum)param)) |
| 3111 | { |
| 3112 | return error(GL_INVALID_ENUM); |
| 3113 | } |
| 3114 | break; |
| 3115 | case GL_TEXTURE_MIN_FILTER: |
| 3116 | if (!texture->setMinFilter((GLenum)param)) |
| 3117 | { |
| 3118 | return error(GL_INVALID_ENUM); |
| 3119 | } |
| 3120 | break; |
| 3121 | case GL_TEXTURE_MAG_FILTER: |
| 3122 | if (!texture->setMagFilter((GLenum)param)) |
| 3123 | { |
| 3124 | return error(GL_INVALID_ENUM); |
| 3125 | } |
| 3126 | break; |
| 3127 | default: |
| 3128 | return error(GL_INVALID_ENUM); |
| 3129 | } |
| 3130 | } |
| 3131 | } |
| 3132 | catch(std::bad_alloc&) |
| 3133 | { |
| 3134 | return error(GL_OUT_OF_MEMORY); |
| 3135 | } |
| 3136 | } |
| 3137 | |
| 3138 | void __stdcall glTexParameteriv(GLenum target, GLenum pname, const GLint* params) |
| 3139 | { |
| 3140 | glTexParameteri(target, pname, *params); |
| 3141 | } |
| 3142 | |
| 3143 | void __stdcall glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pixels) |
| 3144 | { |
| 3145 | TRACE("GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, const void* pixels = 0x%0.8p", |
| 3146 | target, level, xoffset, yoffset, width, height, format, type, pixels); |
| 3147 | |
| 3148 | try |
| 3149 | { |
| 3150 | if (width < 0 || height < 0) |
| 3151 | { |
| 3152 | return error(GL_INVALID_VALUE); |
| 3153 | } |
| 3154 | |
| 3155 | UNIMPLEMENTED(); // FIXME |
| 3156 | } |
| 3157 | catch(std::bad_alloc&) |
| 3158 | { |
| 3159 | return error(GL_OUT_OF_MEMORY); |
| 3160 | } |
| 3161 | } |
| 3162 | |
| 3163 | void __stdcall glUniform1f(GLint location, GLfloat x) |
| 3164 | { |
| 3165 | glUniform1fv(location, 1, &x); |
| 3166 | } |
| 3167 | |
| 3168 | void __stdcall glUniform1fv(GLint location, GLsizei count, const GLfloat* v) |
| 3169 | { |
| 3170 | TRACE("GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p", location, count, v); |
| 3171 | |
| 3172 | try |
| 3173 | { |
| 3174 | if (location == -1) |
| 3175 | { |
| 3176 | return; |
| 3177 | } |
| 3178 | |
| 3179 | if (count < 0) |
| 3180 | { |
| 3181 | return error(GL_INVALID_VALUE); |
| 3182 | } |
| 3183 | |
| 3184 | gl::Context *context = gl::getContext(); |
| 3185 | |
| 3186 | if (context) |
| 3187 | { |
| 3188 | gl::Program *program = context->getCurrentProgram(); |
| 3189 | |
| 3190 | if (!program) |
| 3191 | { |
| 3192 | return error(GL_INVALID_OPERATION); |
| 3193 | } |
| 3194 | |
| 3195 | if (!program->setUniform1fv(location, count, v)) |
| 3196 | { |
| 3197 | return error(GL_INVALID_OPERATION); |
| 3198 | } |
| 3199 | } |
| 3200 | } |
| 3201 | catch(std::bad_alloc&) |
| 3202 | { |
| 3203 | return error(GL_OUT_OF_MEMORY); |
| 3204 | } |
| 3205 | } |
| 3206 | |
| 3207 | void __stdcall glUniform1i(GLint location, GLint x) |
| 3208 | { |
| 3209 | glUniform1iv(location, 1, &x); |
| 3210 | } |
| 3211 | |
| 3212 | void __stdcall glUniform1iv(GLint location, GLsizei count, const GLint* v) |
| 3213 | { |
| 3214 | TRACE("GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p", location, count, v); |
| 3215 | |
| 3216 | try |
| 3217 | { |
| 3218 | if (count < 0) |
| 3219 | { |
| 3220 | return error(GL_INVALID_VALUE); |
| 3221 | } |
| 3222 | |
| 3223 | gl::Context *context = gl::getContext(); |
| 3224 | |
| 3225 | if (context) |
| 3226 | { |
| 3227 | gl::Program *program = context->getCurrentProgram(); |
| 3228 | |
| 3229 | if (!program) |
| 3230 | { |
| 3231 | return error(GL_INVALID_OPERATION); |
| 3232 | } |
| 3233 | |
| 3234 | if (!program->setUniform1iv(location, count, v)) |
| 3235 | { |
| 3236 | return error(GL_INVALID_OPERATION); |
| 3237 | } |
| 3238 | } |
| 3239 | } |
| 3240 | catch(std::bad_alloc&) |
| 3241 | { |
| 3242 | return error(GL_OUT_OF_MEMORY); |
| 3243 | } |
| 3244 | } |
| 3245 | |
| 3246 | void __stdcall glUniform2f(GLint location, GLfloat x, GLfloat y) |
| 3247 | { |
| 3248 | GLfloat xy[2] = {x, y}; |
| 3249 | |
| 3250 | glUniform2fv(location, 1, (GLfloat*)&xy); |
| 3251 | } |
| 3252 | |
| 3253 | void __stdcall glUniform2fv(GLint location, GLsizei count, const GLfloat* v) |
| 3254 | { |
| 3255 | TRACE("GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p", location, count, v); |
| 3256 | |
| 3257 | try |
| 3258 | { |
| 3259 | if (location == -1) |
| 3260 | { |
| 3261 | return; |
| 3262 | } |
| 3263 | |
| 3264 | if (count < 0) |
| 3265 | { |
| 3266 | return error(GL_INVALID_VALUE); |
| 3267 | } |
| 3268 | |
| 3269 | gl::Context *context = gl::getContext(); |
| 3270 | |
| 3271 | if (context) |
| 3272 | { |
| 3273 | gl::Program *program = context->getCurrentProgram(); |
| 3274 | |
| 3275 | if (!program) |
| 3276 | { |
| 3277 | return error(GL_INVALID_OPERATION); |
| 3278 | } |
| 3279 | |
| 3280 | if (!program->setUniform2fv(location, count, v)) |
| 3281 | { |
| 3282 | return error(GL_INVALID_OPERATION); |
| 3283 | } |
| 3284 | } |
| 3285 | } |
| 3286 | catch(std::bad_alloc&) |
| 3287 | { |
| 3288 | return error(GL_OUT_OF_MEMORY); |
| 3289 | } |
| 3290 | } |
| 3291 | |
| 3292 | void __stdcall glUniform2i(GLint location, GLint x, GLint y) |
| 3293 | { |
| 3294 | GLint xy[4] = {x, y}; |
| 3295 | |
| 3296 | glUniform2iv(location, 1, (GLint*)&xy); |
| 3297 | } |
| 3298 | |
| 3299 | void __stdcall glUniform2iv(GLint location, GLsizei count, const GLint* v) |
| 3300 | { |
| 3301 | TRACE("GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p", location, count, v); |
| 3302 | |
| 3303 | try |
| 3304 | { |
| 3305 | if (count < 0) |
| 3306 | { |
| 3307 | return error(GL_INVALID_VALUE); |
| 3308 | } |
| 3309 | |
| 3310 | UNIMPLEMENTED(); // FIXME |
| 3311 | } |
| 3312 | catch(std::bad_alloc&) |
| 3313 | { |
| 3314 | return error(GL_OUT_OF_MEMORY); |
| 3315 | } |
| 3316 | } |
| 3317 | |
| 3318 | void __stdcall glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z) |
| 3319 | { |
| 3320 | GLfloat xyz[3] = {x, y, z}; |
| 3321 | |
| 3322 | glUniform3fv(location, 1, (GLfloat*)&xyz); |
| 3323 | } |
| 3324 | |
| 3325 | void __stdcall glUniform3fv(GLint location, GLsizei count, const GLfloat* v) |
| 3326 | { |
| 3327 | TRACE("GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p", location, count, v); |
| 3328 | |
| 3329 | try |
| 3330 | { |
| 3331 | if (count < 0) |
| 3332 | { |
| 3333 | return error(GL_INVALID_VALUE); |
| 3334 | } |
| 3335 | |
| 3336 | if (location == -1) |
| 3337 | { |
| 3338 | return; |
| 3339 | } |
| 3340 | |
| 3341 | gl::Context *context = gl::getContext(); |
| 3342 | |
| 3343 | if (context) |
| 3344 | { |
| 3345 | gl::Program *program = context->getCurrentProgram(); |
| 3346 | |
| 3347 | if (!program) |
| 3348 | { |
| 3349 | return error(GL_INVALID_OPERATION); |
| 3350 | } |
| 3351 | |
| 3352 | if (!program->setUniform3fv(location, count, v)) |
| 3353 | { |
| 3354 | return error(GL_INVALID_OPERATION); |
| 3355 | } |
| 3356 | } |
| 3357 | } |
| 3358 | catch(std::bad_alloc&) |
| 3359 | { |
| 3360 | return error(GL_OUT_OF_MEMORY); |
| 3361 | } |
| 3362 | } |
| 3363 | |
| 3364 | void __stdcall glUniform3i(GLint location, GLint x, GLint y, GLint z) |
| 3365 | { |
| 3366 | GLint xyz[3] = {x, y, z}; |
| 3367 | |
| 3368 | glUniform3iv(location, 1, (GLint*)&xyz); |
| 3369 | } |
| 3370 | |
| 3371 | void __stdcall glUniform3iv(GLint location, GLsizei count, const GLint* v) |
| 3372 | { |
| 3373 | TRACE("GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p", location, count, v); |
| 3374 | |
| 3375 | try |
| 3376 | { |
| 3377 | if (count < 0) |
| 3378 | { |
| 3379 | return error(GL_INVALID_VALUE); |
| 3380 | } |
| 3381 | |
| 3382 | UNIMPLEMENTED(); // FIXME |
| 3383 | } |
| 3384 | catch(std::bad_alloc&) |
| 3385 | { |
| 3386 | return error(GL_OUT_OF_MEMORY); |
| 3387 | } |
| 3388 | } |
| 3389 | |
| 3390 | void __stdcall glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w) |
| 3391 | { |
| 3392 | GLfloat xyzw[4] = {x, y, z, w}; |
| 3393 | |
| 3394 | glUniform4fv(location, 1, (GLfloat*)&xyzw); |
| 3395 | } |
| 3396 | |
| 3397 | void __stdcall glUniform4fv(GLint location, GLsizei count, const GLfloat* v) |
| 3398 | { |
| 3399 | TRACE("GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p", location, count, v); |
| 3400 | |
| 3401 | try |
| 3402 | { |
| 3403 | if (count < 0) |
| 3404 | { |
| 3405 | return error(GL_INVALID_VALUE); |
| 3406 | } |
| 3407 | |
| 3408 | if (location == -1) |
| 3409 | { |
| 3410 | return; |
| 3411 | } |
| 3412 | |
| 3413 | gl::Context *context = gl::getContext(); |
| 3414 | |
| 3415 | if (context) |
| 3416 | { |
| 3417 | gl::Program *program = context->getCurrentProgram(); |
| 3418 | |
| 3419 | if (!program) |
| 3420 | { |
| 3421 | return error(GL_INVALID_OPERATION); |
| 3422 | } |
| 3423 | |
| 3424 | if (!program->setUniform4fv(location, count, v)) |
| 3425 | { |
| 3426 | return error(GL_INVALID_OPERATION); |
| 3427 | } |
| 3428 | } |
| 3429 | } |
| 3430 | catch(std::bad_alloc&) |
| 3431 | { |
| 3432 | return error(GL_OUT_OF_MEMORY); |
| 3433 | } |
| 3434 | } |
| 3435 | |
| 3436 | void __stdcall glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w) |
| 3437 | { |
| 3438 | GLint xyzw[4] = {x, y, z, w}; |
| 3439 | |
| 3440 | glUniform4iv(location, 1, (GLint*)&xyzw); |
| 3441 | } |
| 3442 | |
| 3443 | void __stdcall glUniform4iv(GLint location, GLsizei count, const GLint* v) |
| 3444 | { |
| 3445 | TRACE("GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p", location, count, v); |
| 3446 | |
| 3447 | try |
| 3448 | { |
| 3449 | if (count < 0) |
| 3450 | { |
| 3451 | return error(GL_INVALID_VALUE); |
| 3452 | } |
| 3453 | |
| 3454 | UNIMPLEMENTED(); // FIXME |
| 3455 | } |
| 3456 | catch(std::bad_alloc&) |
| 3457 | { |
| 3458 | return error(GL_OUT_OF_MEMORY); |
| 3459 | } |
| 3460 | } |
| 3461 | |
| 3462 | void __stdcall glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) |
| 3463 | { |
| 3464 | TRACE("GLint location = %d, GLsizei count = %d, GLboolean transpose = %d, const GLfloat* value = 0x%0.8p", location, count, transpose, value); |
| 3465 | |
| 3466 | try |
| 3467 | { |
| 3468 | if (count < 0 || transpose != GL_FALSE) |
| 3469 | { |
| 3470 | return error(GL_INVALID_VALUE); |
| 3471 | } |
| 3472 | |
| 3473 | if (location == -1) |
| 3474 | { |
| 3475 | return; |
| 3476 | } |
| 3477 | |
| 3478 | gl::Context *context = gl::getContext(); |
| 3479 | |
| 3480 | if (context) |
| 3481 | { |
| 3482 | gl::Program *program = context->getCurrentProgram(); |
| 3483 | |
| 3484 | if (!program) |
| 3485 | { |
| 3486 | return error(GL_INVALID_OPERATION); |
| 3487 | } |
| 3488 | |
| 3489 | if (!program->setUniformMatrix2fv(location, count, value)) |
| 3490 | { |
| 3491 | return error(GL_INVALID_OPERATION); |
| 3492 | } |
| 3493 | } |
| 3494 | } |
| 3495 | catch(std::bad_alloc&) |
| 3496 | { |
| 3497 | return error(GL_OUT_OF_MEMORY); |
| 3498 | } |
| 3499 | } |
| 3500 | |
| 3501 | void __stdcall glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) |
| 3502 | { |
| 3503 | TRACE("GLint location = %d, GLsizei count = %d, GLboolean transpose = %d, const GLfloat* value = 0x%0.8p", location, count, transpose, value); |
| 3504 | |
| 3505 | try |
| 3506 | { |
| 3507 | if (count < 0 || transpose != GL_FALSE) |
| 3508 | { |
| 3509 | return error(GL_INVALID_VALUE); |
| 3510 | } |
| 3511 | |
| 3512 | if (location == -1) |
| 3513 | { |
| 3514 | return; |
| 3515 | } |
| 3516 | |
| 3517 | gl::Context *context = gl::getContext(); |
| 3518 | |
| 3519 | if (context) |
| 3520 | { |
| 3521 | gl::Program *program = context->getCurrentProgram(); |
| 3522 | |
| 3523 | if (!program) |
| 3524 | { |
| 3525 | return error(GL_INVALID_OPERATION); |
| 3526 | } |
| 3527 | |
| 3528 | if (!program->setUniformMatrix3fv(location, count, value)) |
| 3529 | { |
| 3530 | return error(GL_INVALID_OPERATION); |
| 3531 | } |
| 3532 | } |
| 3533 | } |
| 3534 | catch(std::bad_alloc&) |
| 3535 | { |
| 3536 | return error(GL_OUT_OF_MEMORY); |
| 3537 | } |
| 3538 | } |
| 3539 | |
| 3540 | void __stdcall glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) |
| 3541 | { |
| 3542 | TRACE("GLint location = %d, GLsizei count = %d, GLboolean transpose = %d, const GLfloat* value = 0x%0.8p", location, count, transpose, value); |
| 3543 | |
| 3544 | try |
| 3545 | { |
| 3546 | if (count < 0 || transpose != GL_FALSE) |
| 3547 | { |
| 3548 | return error(GL_INVALID_VALUE); |
| 3549 | } |
| 3550 | |
| 3551 | if (location == -1) |
| 3552 | { |
| 3553 | return; |
| 3554 | } |
| 3555 | |
| 3556 | gl::Context *context = gl::getContext(); |
| 3557 | |
| 3558 | if (context) |
| 3559 | { |
| 3560 | gl::Program *program = context->getCurrentProgram(); |
| 3561 | |
| 3562 | if (!program) |
| 3563 | { |
| 3564 | return error(GL_INVALID_OPERATION); |
| 3565 | } |
| 3566 | |
| 3567 | if (!program->setUniformMatrix4fv(location, count, value)) |
| 3568 | { |
| 3569 | return error(GL_INVALID_OPERATION); |
| 3570 | } |
| 3571 | } |
| 3572 | } |
| 3573 | catch(std::bad_alloc&) |
| 3574 | { |
| 3575 | return error(GL_OUT_OF_MEMORY); |
| 3576 | } |
| 3577 | } |
| 3578 | |
| 3579 | void __stdcall glUseProgram(GLuint program) |
| 3580 | { |
| 3581 | TRACE("GLuint program = %d", program); |
| 3582 | |
| 3583 | try |
| 3584 | { |
| 3585 | gl::Context *context = gl::getContext(); |
| 3586 | |
| 3587 | if (context) |
| 3588 | { |
| 3589 | gl::Program *programObject = context->getProgram(program); |
| 3590 | |
| 3591 | if (programObject && !programObject->isLinked()) |
| 3592 | { |
| 3593 | return error(GL_INVALID_OPERATION); |
| 3594 | } |
| 3595 | |
| 3596 | context->useProgram(program); |
| 3597 | } |
| 3598 | } |
| 3599 | catch(std::bad_alloc&) |
| 3600 | { |
| 3601 | return error(GL_OUT_OF_MEMORY); |
| 3602 | } |
| 3603 | } |
| 3604 | |
| 3605 | void __stdcall glValidateProgram(GLuint program) |
| 3606 | { |
| 3607 | TRACE("GLuint program = %d", program); |
| 3608 | |
| 3609 | try |
| 3610 | { |
| 3611 | UNIMPLEMENTED(); // FIXME |
| 3612 | } |
| 3613 | catch(std::bad_alloc&) |
| 3614 | { |
| 3615 | return error(GL_OUT_OF_MEMORY); |
| 3616 | } |
| 3617 | } |
| 3618 | |
| 3619 | void __stdcall glVertexAttrib1f(GLuint index, GLfloat x) |
| 3620 | { |
| 3621 | TRACE("GLuint index = %d, GLfloat x = %f", index, x); |
| 3622 | |
| 3623 | try |
| 3624 | { |
| 3625 | if (index >= gl::MAX_VERTEX_ATTRIBS) |
| 3626 | { |
| 3627 | return error(GL_INVALID_VALUE); |
| 3628 | } |
| 3629 | |
| 3630 | UNIMPLEMENTED(); // FIXME |
| 3631 | } |
| 3632 | catch(std::bad_alloc&) |
| 3633 | { |
| 3634 | return error(GL_OUT_OF_MEMORY); |
| 3635 | } |
| 3636 | } |
| 3637 | |
| 3638 | void __stdcall glVertexAttrib1fv(GLuint index, const GLfloat* values) |
| 3639 | { |
| 3640 | TRACE("GLuint index = %d, const GLfloat* values = 0x%0.8p", index, values); |
| 3641 | |
| 3642 | try |
| 3643 | { |
| 3644 | if (index >= gl::MAX_VERTEX_ATTRIBS) |
| 3645 | { |
| 3646 | return error(GL_INVALID_VALUE); |
| 3647 | } |
| 3648 | |
| 3649 | UNIMPLEMENTED(); // FIXME |
| 3650 | } |
| 3651 | catch(std::bad_alloc&) |
| 3652 | { |
| 3653 | return error(GL_OUT_OF_MEMORY); |
| 3654 | } |
| 3655 | } |
| 3656 | |
| 3657 | void __stdcall glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y) |
| 3658 | { |
| 3659 | TRACE("GLuint index = %d, GLfloat x = %f, GLfloat y = %f", index, x, y); |
| 3660 | |
| 3661 | try |
| 3662 | { |
| 3663 | if (index >= gl::MAX_VERTEX_ATTRIBS) |
| 3664 | { |
| 3665 | return error(GL_INVALID_VALUE); |
| 3666 | } |
| 3667 | |
| 3668 | UNIMPLEMENTED(); // FIXME |
| 3669 | } |
| 3670 | catch(std::bad_alloc&) |
| 3671 | { |
| 3672 | return error(GL_OUT_OF_MEMORY); |
| 3673 | } |
| 3674 | } |
| 3675 | |
| 3676 | void __stdcall glVertexAttrib2fv(GLuint index, const GLfloat* values) |
| 3677 | { |
| 3678 | TRACE("GLuint index = %d, const GLfloat* values = 0x%0.8p", index, values); |
| 3679 | |
| 3680 | try |
| 3681 | { |
| 3682 | if (index >= gl::MAX_VERTEX_ATTRIBS) |
| 3683 | { |
| 3684 | return error(GL_INVALID_VALUE); |
| 3685 | } |
| 3686 | |
| 3687 | UNIMPLEMENTED(); // FIXME |
| 3688 | } |
| 3689 | catch(std::bad_alloc&) |
| 3690 | { |
| 3691 | return error(GL_OUT_OF_MEMORY); |
| 3692 | } |
| 3693 | } |
| 3694 | |
| 3695 | void __stdcall glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z) |
| 3696 | { |
| 3697 | TRACE("GLuint index = %d, GLfloat x = %f, GLfloat y = %f, GLfloat z = %f", index, x, y, z); |
| 3698 | |
| 3699 | try |
| 3700 | { |
| 3701 | if (index >= gl::MAX_VERTEX_ATTRIBS) |
| 3702 | { |
| 3703 | return error(GL_INVALID_VALUE); |
| 3704 | } |
| 3705 | |
| 3706 | UNIMPLEMENTED(); // FIXME |
| 3707 | } |
| 3708 | catch(std::bad_alloc&) |
| 3709 | { |
| 3710 | return error(GL_OUT_OF_MEMORY); |
| 3711 | } |
| 3712 | } |
| 3713 | |
| 3714 | void __stdcall glVertexAttrib3fv(GLuint index, const GLfloat* values) |
| 3715 | { |
| 3716 | TRACE("GLuint index = %d, const GLfloat* values = 0x%0.8p", index, values); |
| 3717 | |
| 3718 | try |
| 3719 | { |
| 3720 | if (index >= gl::MAX_VERTEX_ATTRIBS) |
| 3721 | { |
| 3722 | return error(GL_INVALID_VALUE); |
| 3723 | } |
| 3724 | |
| 3725 | UNIMPLEMENTED(); // FIXME |
| 3726 | } |
| 3727 | catch(std::bad_alloc&) |
| 3728 | { |
| 3729 | return error(GL_OUT_OF_MEMORY); |
| 3730 | } |
| 3731 | } |
| 3732 | |
| 3733 | void __stdcall glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) |
| 3734 | { |
| 3735 | TRACE("GLuint index = %d, GLfloat x = %f, GLfloat y = %f, GLfloat z = %f, GLfloat w = %f", index, x, y, z, w); |
| 3736 | |
| 3737 | try |
| 3738 | { |
| 3739 | if (index >= gl::MAX_VERTEX_ATTRIBS) |
| 3740 | { |
| 3741 | return error(GL_INVALID_VALUE); |
| 3742 | } |
| 3743 | |
| 3744 | UNIMPLEMENTED(); // FIXME |
| 3745 | } |
| 3746 | catch(std::bad_alloc&) |
| 3747 | { |
| 3748 | return error(GL_OUT_OF_MEMORY); |
| 3749 | } |
| 3750 | } |
| 3751 | |
| 3752 | void __stdcall glVertexAttrib4fv(GLuint index, const GLfloat* values) |
| 3753 | { |
| 3754 | TRACE("GLuint index = %d, const GLfloat* values = 0x%0.8p", index, values); |
| 3755 | |
| 3756 | try |
| 3757 | { |
| 3758 | if (index >= gl::MAX_VERTEX_ATTRIBS) |
| 3759 | { |
| 3760 | return error(GL_INVALID_VALUE); |
| 3761 | } |
| 3762 | |
| 3763 | UNIMPLEMENTED(); // FIXME |
| 3764 | } |
| 3765 | catch(std::bad_alloc&) |
| 3766 | { |
| 3767 | return error(GL_OUT_OF_MEMORY); |
| 3768 | } |
| 3769 | } |
| 3770 | |
| 3771 | void __stdcall glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr) |
| 3772 | { |
| 3773 | TRACE("GLuint index = %d, GLint size = %d, GLenum type = 0x%X, GLboolean normalized = %d, GLsizei stride = %d, const void* ptr = 0x%0.8p", index, size, type, normalized, stride, ptr); |
| 3774 | |
| 3775 | try |
| 3776 | { |
| 3777 | if (index >= gl::MAX_VERTEX_ATTRIBS) |
| 3778 | { |
| 3779 | return error(GL_INVALID_VALUE); |
| 3780 | } |
| 3781 | |
| 3782 | if (size < 1 || size > 4) |
| 3783 | { |
| 3784 | return error(GL_INVALID_VALUE); |
| 3785 | } |
| 3786 | |
| 3787 | switch (type) |
| 3788 | { |
| 3789 | case GL_BYTE: |
| 3790 | case GL_UNSIGNED_BYTE: |
| 3791 | case GL_SHORT: |
| 3792 | case GL_UNSIGNED_SHORT: |
| 3793 | case GL_FIXED: |
| 3794 | case GL_FLOAT: |
| 3795 | break; |
| 3796 | default: |
| 3797 | return error(GL_INVALID_ENUM); |
| 3798 | } |
| 3799 | |
| 3800 | if (stride < 0) |
| 3801 | { |
| 3802 | return error(GL_INVALID_VALUE); |
| 3803 | } |
| 3804 | |
| 3805 | gl::Context *context = gl::getContext(); |
| 3806 | |
| 3807 | if (context) |
| 3808 | { |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 3809 | context->vertexAttribute[index].mBoundBuffer = context->arrayBuffer; |
| 3810 | context->vertexAttribute[index].mSize = size; |
| 3811 | context->vertexAttribute[index].mType = type; |
| 3812 | context->vertexAttribute[index].mNormalized = normalized; |
| 3813 | context->vertexAttribute[index].mStride = stride; |
| 3814 | context->vertexAttribute[index].mPointer = ptr; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3815 | } |
| 3816 | } |
| 3817 | catch(std::bad_alloc&) |
| 3818 | { |
| 3819 | return error(GL_OUT_OF_MEMORY); |
| 3820 | } |
| 3821 | } |
| 3822 | |
| 3823 | void __stdcall glViewport(GLint x, GLint y, GLsizei width, GLsizei height) |
| 3824 | { |
| 3825 | TRACE("GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d", x, y, width, height); |
| 3826 | |
| 3827 | try |
| 3828 | { |
| 3829 | if (width < 0 || height < 0) |
| 3830 | { |
| 3831 | return error(GL_INVALID_VALUE); |
| 3832 | } |
| 3833 | |
| 3834 | gl::Context *context = gl::getContext(); |
| 3835 | |
| 3836 | if (context) |
| 3837 | { |
| 3838 | context->viewportX = x; |
| 3839 | context->viewportY = y; |
| 3840 | context->viewportWidth = width; |
| 3841 | context->viewportHeight = height; |
| 3842 | } |
| 3843 | } |
| 3844 | catch(std::bad_alloc&) |
| 3845 | { |
| 3846 | return error(GL_OUT_OF_MEMORY); |
| 3847 | } |
| 3848 | } |
| 3849 | |
| 3850 | void __stdcall glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void* pixels) |
| 3851 | { |
| 3852 | TRACE("GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, GLenum type = 0x%x, const void* pixels = 0x%0.8p", |
| 3853 | target, level, internalformat, width, height, depth, border, format, type, pixels); |
| 3854 | |
| 3855 | try |
| 3856 | { |
| 3857 | UNIMPLEMENTED(); // FIXME |
| 3858 | } |
| 3859 | catch(std::bad_alloc&) |
| 3860 | { |
| 3861 | return error(GL_OUT_OF_MEMORY); |
| 3862 | } |
| 3863 | } |
| 3864 | } |