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