| // SwiftShader Software Renderer | |
| // | |
| // Copyright(c) 2005-2013 TransGaming Inc. | |
| // | |
| // All rights reserved. No part of this software may be copied, distributed, transmitted, | |
| // transcribed, stored in a retrieval system, translated into any human or computer | |
| // language by any means, or disclosed to third parties without the explicit written | |
| // agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express | |
| // or implied, including but not limited to any patent rights, are granted to you. | |
| // | |
| // libGLES_CM.cpp: Implements the exported OpenGL ES 1.1 functions. | |
| #include "main.h" | |
| #include "mathutil.h" | |
| #include "utilities.h" | |
| #include "Buffer.h" | |
| #include "Context.h" | |
| #include "Framebuffer.h" | |
| #include "Renderbuffer.h" | |
| #include "Texture.h" | |
| #include "Query.h" | |
| #include "common/debug.h" | |
| #include "Common/Version.h" | |
| #include "Main/Register.hpp" | |
| #define GL_API | |
| #include <GLES/gl.h> | |
| #define GL_GLEXT_PROTOTYPES | |
| #include <GLES/glext.h> | |
| #include <exception> | |
| #include <limits> | |
| static bool validImageSize(GLint level, GLsizei width, GLsizei height) | |
| { | |
| if(level < 0 || level >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS || width < 0 || height < 0) | |
| { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool validateSubImageParams(bool compressed, GLsizei width, GLsizei height, GLint xoffset, GLint yoffset, GLenum target, GLint level, GLenum format, gl::Texture *texture) | |
| { | |
| if(!texture) | |
| { | |
| return error(GL_INVALID_OPERATION, false); | |
| } | |
| if(compressed != texture->isCompressed(target, level)) | |
| { | |
| return error(GL_INVALID_OPERATION, false); | |
| } | |
| if(format != GL_NONE_OES && format != texture->getFormat(target, level)) | |
| { | |
| return error(GL_INVALID_OPERATION, false); | |
| } | |
| if(compressed) | |
| { | |
| if((width % 4 != 0 && width != texture->getWidth(target, 0)) || | |
| (height % 4 != 0 && height != texture->getHeight(target, 0))) | |
| { | |
| return error(GL_INVALID_OPERATION, false); | |
| } | |
| } | |
| if(xoffset + width > texture->getWidth(target, level) || | |
| yoffset + height > texture->getHeight(target, level)) | |
| { | |
| return error(GL_INVALID_VALUE, false); | |
| } | |
| return true; | |
| } | |
| // Check for combinations of format and type that are valid for ReadPixels | |
| static bool validReadFormatType(GLenum format, GLenum type) | |
| { | |
| switch(format) | |
| { | |
| case GL_RGBA: | |
| switch (type) | |
| { | |
| case GL_UNSIGNED_BYTE: | |
| break; | |
| default: | |
| return false; | |
| } | |
| break; | |
| case GL_BGRA_EXT: | |
| switch (type) | |
| { | |
| case GL_UNSIGNED_BYTE: | |
| case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: | |
| case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: | |
| break; | |
| default: | |
| return false; | |
| } | |
| break; | |
| case gl::IMPLEMENTATION_COLOR_READ_FORMAT: | |
| switch (type) | |
| { | |
| case gl::IMPLEMENTATION_COLOR_READ_TYPE: | |
| break; | |
| default: | |
| return false; | |
| } | |
| break; | |
| default: | |
| return false; | |
| } | |
| return true; | |
| } | |
| extern "C" | |
| { | |
| void GL_APIENTRY glActiveTexture(GLenum texture) | |
| { | |
| TRACE("(GLenum texture = 0x%X)", texture); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| if(texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + gl::MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| context->setActiveSampler(texture - GL_TEXTURE0); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glAlphaFunc(GLenum func, GLclampf ref) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glAlphaFuncx(GLenum func, GLclampx ref) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glBindBuffer(GLenum target, GLuint buffer) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| switch(target) | |
| { | |
| case GL_ARRAY_BUFFER: | |
| context->bindArrayBuffer(buffer); | |
| return; | |
| case GL_ELEMENT_ARRAY_BUFFER: | |
| context->bindElementArrayBuffer(buffer); | |
| return; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glBindFramebuffer(GLenum target, GLuint framebuffer) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer); | |
| try | |
| { | |
| if(target != GL_FRAMEBUFFER_OES) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->bindFramebuffer(framebuffer); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glBindFramebufferOES(GLenum target, GLuint framebuffer) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer); | |
| try | |
| { | |
| if(target != GL_FRAMEBUFFER_OES) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->bindFramebuffer(framebuffer); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glBindRenderbufferOES(GLenum target, GLuint renderbuffer) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer); | |
| try | |
| { | |
| if(target != GL_RENDERBUFFER_OES) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->bindRenderbuffer(renderbuffer); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glBindTexture(GLenum target, GLuint texture) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLuint texture = %d)", target, texture); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| gl::Texture *textureObject = context->getTexture(texture); | |
| if(textureObject && textureObject->getTarget() != target && texture != 0) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| switch(target) | |
| { | |
| case GL_TEXTURE_2D: | |
| context->bindTexture2D(texture); | |
| return; | |
| case GL_TEXTURE_EXTERNAL_OES: | |
| context->bindTextureExternal(texture); | |
| return; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glBlendEquationSeparateOES(GLenum modeRGB, GLenum modeAlpha) | |
| { | |
| TRACE("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha); | |
| try | |
| { | |
| switch(modeRGB) | |
| { | |
| case GL_FUNC_ADD_OES: | |
| case GL_FUNC_SUBTRACT_OES: | |
| case GL_FUNC_REVERSE_SUBTRACT_OES: | |
| case GL_MIN_EXT: | |
| case GL_MAX_EXT: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| switch(modeAlpha) | |
| { | |
| case GL_FUNC_ADD_OES: | |
| case GL_FUNC_SUBTRACT_OES: | |
| case GL_FUNC_REVERSE_SUBTRACT_OES: | |
| case GL_MIN_EXT: | |
| case GL_MAX_EXT: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->setBlendEquation(modeRGB, modeAlpha); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor) | |
| { | |
| glBlendFuncSeparateOES(sfactor, dfactor, sfactor, dfactor); | |
| } | |
| void GL_APIENTRY glBlendFuncSeparateOES(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) | |
| { | |
| TRACE("(GLenum srcRGB = 0x%X, GLenum dstRGB = 0x%X, GLenum srcAlpha = 0x%X, GLenum dstAlpha = 0x%X)", | |
| srcRGB, dstRGB, srcAlpha, dstAlpha); | |
| try | |
| { | |
| switch(srcRGB) | |
| { | |
| case GL_ZERO: | |
| case GL_ONE: | |
| case GL_SRC_COLOR: | |
| case GL_ONE_MINUS_SRC_COLOR: | |
| case GL_DST_COLOR: | |
| case GL_ONE_MINUS_DST_COLOR: | |
| case GL_SRC_ALPHA: | |
| case GL_ONE_MINUS_SRC_ALPHA: | |
| case GL_DST_ALPHA: | |
| case GL_ONE_MINUS_DST_ALPHA: | |
| case GL_SRC_ALPHA_SATURATE: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| switch(dstRGB) | |
| { | |
| case GL_ZERO: | |
| case GL_ONE: | |
| case GL_SRC_COLOR: | |
| case GL_ONE_MINUS_SRC_COLOR: | |
| case GL_DST_COLOR: | |
| case GL_ONE_MINUS_DST_COLOR: | |
| case GL_SRC_ALPHA: | |
| case GL_ONE_MINUS_SRC_ALPHA: | |
| case GL_DST_ALPHA: | |
| case GL_ONE_MINUS_DST_ALPHA: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| switch(srcAlpha) | |
| { | |
| case GL_ZERO: | |
| case GL_ONE: | |
| case GL_SRC_COLOR: | |
| case GL_ONE_MINUS_SRC_COLOR: | |
| case GL_DST_COLOR: | |
| case GL_ONE_MINUS_DST_COLOR: | |
| case GL_SRC_ALPHA: | |
| case GL_ONE_MINUS_SRC_ALPHA: | |
| case GL_DST_ALPHA: | |
| case GL_ONE_MINUS_DST_ALPHA: | |
| case GL_SRC_ALPHA_SATURATE: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| switch(dstAlpha) | |
| { | |
| case GL_ZERO: | |
| case GL_ONE: | |
| case GL_SRC_COLOR: | |
| case GL_ONE_MINUS_SRC_COLOR: | |
| case GL_DST_COLOR: | |
| case GL_ONE_MINUS_DST_COLOR: | |
| case GL_SRC_ALPHA: | |
| case GL_ONE_MINUS_SRC_ALPHA: | |
| case GL_DST_ALPHA: | |
| case GL_ONE_MINUS_DST_ALPHA: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p, GLenum usage = %d)", | |
| target, size, data, usage); | |
| try | |
| { | |
| if(size < 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| switch(usage) | |
| { | |
| case GL_STATIC_DRAW: | |
| case GL_DYNAMIC_DRAW: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| gl::Buffer *buffer; | |
| switch(target) | |
| { | |
| case GL_ARRAY_BUFFER: | |
| buffer = context->getArrayBuffer(); | |
| break; | |
| case GL_ELEMENT_ARRAY_BUFFER: | |
| buffer = context->getElementArrayBuffer(); | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(!buffer) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| buffer->bufferData(data, size, usage); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p)", | |
| target, offset, size, data); | |
| try | |
| { | |
| if(size < 0 || offset < 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| if(data == NULL) | |
| { | |
| return; | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| gl::Buffer *buffer; | |
| switch(target) | |
| { | |
| case GL_ARRAY_BUFFER: | |
| buffer = context->getArrayBuffer(); | |
| break; | |
| case GL_ELEMENT_ARRAY_BUFFER: | |
| buffer = context->getElementArrayBuffer(); | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(!buffer) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| if((size_t)size + offset > buffer->size()) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| buffer->bufferSubData(data, size, offset); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| GLenum GL_APIENTRY glCheckFramebufferStatusOES(GLenum target) | |
| { | |
| TRACE("(GLenum target = 0x%X)", target); | |
| try | |
| { | |
| if(target != GL_FRAMEBUFFER_OES) | |
| { | |
| return error(GL_INVALID_ENUM, 0); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| gl::Framebuffer *framebuffer = context->getFramebuffer(); | |
| return framebuffer->completeness(); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY, 0); | |
| } | |
| return 0; | |
| } | |
| void GL_APIENTRY glClear(GLbitfield mask) | |
| { | |
| TRACE("(GLbitfield mask = %X)", mask); | |
| try | |
| { | |
| if((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->clear(mask); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) | |
| { | |
| TRACE("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)", | |
| red, green, blue, alpha); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->setClearColor(red, green, blue, alpha); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glClearColorx(GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glClearDepthf(GLclampf depth) | |
| { | |
| TRACE("(GLclampf depth = %f)", depth); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->setClearDepth(depth); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glClearDepthx(GLclampx depth) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glClearStencil(GLint s) | |
| { | |
| TRACE("(GLint s = %d)", s); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->setClearStencil(s); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glClientActiveTexture(GLenum texture) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glClipPlanef(GLenum plane, const GLfloat *equation) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glClipPlanex(GLenum plane, const GLfixed *equation) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glColor4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) | |
| { | |
| TRACE("(GLboolean red = %d, GLboolean green = %d, GLboolean blue = %d, GLboolean alpha = %d)", | |
| red, green, blue, alpha); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, | |
| GLint border, GLsizei imageSize, const GLvoid* data) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, " | |
| "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)", | |
| target, level, internalformat, width, height, border, imageSize, data); | |
| try | |
| { | |
| if(!validImageSize(level, width, height) || border != 0 || imageSize < 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| switch(internalformat) | |
| { | |
| case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: | |
| case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: | |
| if(!S3TC_SUPPORT) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| break; | |
| case GL_DEPTH_COMPONENT16_OES: | |
| case GL_DEPTH_COMPONENT32_OES: | |
| case GL_DEPTH_STENCIL_OES: | |
| case GL_DEPTH24_STENCIL8_OES: | |
| return error(GL_INVALID_OPERATION); | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(border != 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| if(level > gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| switch(target) | |
| { | |
| case GL_TEXTURE_2D: | |
| if(width > (gl::IMPLEMENTATION_MAX_TEXTURE_SIZE >> level) || | |
| height > (gl::IMPLEMENTATION_MAX_TEXTURE_SIZE >> level)) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(imageSize != gl::ComputeCompressedSize(width, height, internalformat)) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| if(target == GL_TEXTURE_2D) | |
| { | |
| gl::Texture2D *texture = context->getTexture2D(); | |
| if(!texture) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| texture->setCompressedImage(level, internalformat, width, height, imageSize, data); | |
| } | |
| else UNREACHABLE(); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, | |
| GLenum format, GLsizei imageSize, const GLvoid* data) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, " | |
| "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, " | |
| "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)", | |
| target, level, xoffset, yoffset, width, height, format, imageSize, data); | |
| try | |
| { | |
| if(!gl::IsTextureTarget(target)) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(xoffset < 0 || yoffset < 0 || !validImageSize(level, width, height) || imageSize < 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| switch(format) | |
| { | |
| case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: | |
| case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: | |
| if(!S3TC_SUPPORT) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(width == 0 || height == 0 || data == NULL) | |
| { | |
| return; | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| if(level > gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| if(imageSize != gl::ComputeCompressedSize(width, height, format)) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| if(xoffset % 4 != 0 || yoffset % 4 != 0) | |
| { | |
| // We wait to check the offsets until this point, because the multiple-of-four restriction does not exist unless DXT1 textures are supported | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| if(target == GL_TEXTURE_2D) | |
| { | |
| gl::Texture2D *texture = context->getTexture2D(); | |
| if(validateSubImageParams(true, width, height, xoffset, yoffset, target, level, format, texture)) | |
| { | |
| texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, data); | |
| } | |
| } | |
| else UNREACHABLE(); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, " | |
| "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)", | |
| target, level, internalformat, x, y, width, height, border); | |
| try | |
| { | |
| if(!validImageSize(level, width, height)) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| if(border != 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| switch(target) | |
| { | |
| case GL_TEXTURE_2D: | |
| if(width > (gl::IMPLEMENTATION_MAX_TEXTURE_SIZE >> level) || | |
| height > (gl::IMPLEMENTATION_MAX_TEXTURE_SIZE >> level)) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| gl::Framebuffer *framebuffer = context->getFramebuffer(); | |
| if(framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE_OES) | |
| { | |
| return error(GL_INVALID_FRAMEBUFFER_OPERATION_OES); | |
| } | |
| if(context->getFramebufferHandle() != 0 && framebuffer->getColorbuffer()->getSamples() > 1) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| gl::Renderbuffer *source = framebuffer->getColorbuffer(); | |
| GLenum colorbufferFormat = source->getFormat(); | |
| // [OpenGL ES 2.0.24] table 3.9 | |
| switch(internalformat) | |
| { | |
| case GL_ALPHA: | |
| if(colorbufferFormat != GL_ALPHA && | |
| colorbufferFormat != GL_RGBA && | |
| colorbufferFormat != GL_RGBA4_OES && | |
| colorbufferFormat != GL_RGB5_A1_OES && | |
| colorbufferFormat != GL_RGBA8_OES) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| break; | |
| case GL_LUMINANCE: | |
| case GL_RGB: | |
| if(colorbufferFormat != GL_RGB && | |
| colorbufferFormat != GL_RGB565_OES && | |
| colorbufferFormat != GL_RGB8_OES && | |
| colorbufferFormat != GL_RGBA && | |
| colorbufferFormat != GL_RGBA4_OES && | |
| colorbufferFormat != GL_RGB5_A1_OES && | |
| colorbufferFormat != GL_RGBA8_OES) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| break; | |
| case GL_LUMINANCE_ALPHA: | |
| case GL_RGBA: | |
| if(colorbufferFormat != GL_RGBA && | |
| colorbufferFormat != GL_RGBA4_OES && | |
| colorbufferFormat != GL_RGB5_A1_OES && | |
| colorbufferFormat != GL_RGBA8_OES) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| break; | |
| case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: | |
| case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: | |
| if(S3TC_SUPPORT) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| else | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(target == GL_TEXTURE_2D) | |
| { | |
| gl::Texture2D *texture = context->getTexture2D(); | |
| if(!texture) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| texture->copyImage(level, internalformat, x, y, width, height, framebuffer); | |
| } | |
| else UNREACHABLE(); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, " | |
| "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)", | |
| target, level, xoffset, yoffset, x, y, width, height); | |
| try | |
| { | |
| if(!gl::IsTextureTarget(target)) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| if(std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| if(width == 0 || height == 0) | |
| { | |
| return; | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| if(level > gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| gl::Framebuffer *framebuffer = context->getFramebuffer(); | |
| if(framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE_OES) | |
| { | |
| return error(GL_INVALID_FRAMEBUFFER_OPERATION_OES); | |
| } | |
| if(context->getFramebufferHandle() != 0 && framebuffer->getColorbuffer()->getSamples() > 1) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| gl::Renderbuffer *source = framebuffer->getColorbuffer(); | |
| GLenum colorbufferFormat = source->getFormat(); | |
| gl::Texture *texture = NULL; | |
| if(target == GL_TEXTURE_2D) | |
| { | |
| texture = context->getTexture2D(); | |
| } | |
| else UNREACHABLE(); | |
| if(!validateSubImageParams(false, width, height, xoffset, yoffset, target, level, GL_NONE_OES, texture)) | |
| { | |
| return; | |
| } | |
| GLenum textureFormat = texture->getFormat(target, level); | |
| // [OpenGL ES 2.0.24] table 3.9 | |
| switch(textureFormat) | |
| { | |
| case GL_ALPHA: | |
| if(colorbufferFormat != GL_ALPHA && | |
| colorbufferFormat != GL_RGBA && | |
| colorbufferFormat != GL_RGBA4_OES && | |
| colorbufferFormat != GL_RGB5_A1_OES && | |
| colorbufferFormat != GL_RGBA8_OES) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| break; | |
| case GL_LUMINANCE: | |
| case GL_RGB: | |
| if(colorbufferFormat != GL_RGB && | |
| colorbufferFormat != GL_RGB565_OES && | |
| colorbufferFormat != GL_RGB8_OES && | |
| colorbufferFormat != GL_RGBA && | |
| colorbufferFormat != GL_RGBA4_OES && | |
| colorbufferFormat != GL_RGB5_A1_OES && | |
| colorbufferFormat != GL_RGBA8_OES) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| break; | |
| case GL_LUMINANCE_ALPHA: | |
| case GL_RGBA: | |
| if(colorbufferFormat != GL_RGBA && | |
| colorbufferFormat != GL_RGBA4_OES && | |
| colorbufferFormat != GL_RGB5_A1_OES && | |
| colorbufferFormat != GL_RGBA8_OES) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| break; | |
| case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: | |
| case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: | |
| return error(GL_INVALID_OPERATION); | |
| case GL_DEPTH_STENCIL_OES: | |
| return error(GL_INVALID_OPERATION); | |
| default: | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| texture->copySubImage(target, level, xoffset, yoffset, x, y, width, height, framebuffer); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glCullFace(GLenum mode) | |
| { | |
| TRACE("(GLenum mode = 0x%X)", mode); | |
| try | |
| { | |
| switch(mode) | |
| { | |
| case GL_FRONT: | |
| case GL_BACK: | |
| case GL_FRONT_AND_BACK: | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->setCullMode(mode); | |
| } | |
| } | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glDeleteBuffers(GLsizei n, const GLuint* buffers) | |
| { | |
| TRACE("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers); | |
| try | |
| { | |
| if(n < 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| for(int i = 0; i < n; i++) | |
| { | |
| context->deleteBuffer(buffers[i]); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glDeleteFramebuffersOES(GLsizei n, const GLuint* framebuffers) | |
| { | |
| TRACE("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers); | |
| try | |
| { | |
| if(n < 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| for(int i = 0; i < n; i++) | |
| { | |
| if(framebuffers[i] != 0) | |
| { | |
| context->deleteFramebuffer(framebuffers[i]); | |
| } | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glDeleteRenderbuffersOES(GLsizei n, const GLuint* renderbuffers) | |
| { | |
| TRACE("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers); | |
| try | |
| { | |
| if(n < 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| for(int i = 0; i < n; i++) | |
| { | |
| context->deleteRenderbuffer(renderbuffers[i]); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glDeleteTextures(GLsizei n, const GLuint* textures) | |
| { | |
| TRACE("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures); | |
| try | |
| { | |
| if(n < 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| for(int i = 0; i < n; i++) | |
| { | |
| if(textures[i] != 0) | |
| { | |
| context->deleteTexture(textures[i]); | |
| } | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glDepthFunc(GLenum func) | |
| { | |
| TRACE("(GLenum func = 0x%X)", func); | |
| try | |
| { | |
| switch(func) | |
| { | |
| case GL_NEVER: | |
| case GL_ALWAYS: | |
| case GL_LESS: | |
| case GL_LEQUAL: | |
| case GL_EQUAL: | |
| case GL_GREATER: | |
| case GL_GEQUAL: | |
| case GL_NOTEQUAL: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->setDepthFunc(func); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glDepthMask(GLboolean flag) | |
| { | |
| TRACE("(GLboolean flag = %d)", flag); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->setDepthMask(flag != GL_FALSE); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glDepthRangex(GLclampx zNear, GLclampx zFar) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glDepthRangef(GLclampf zNear, GLclampf zFar) | |
| { | |
| TRACE("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->setDepthRange(zNear, zFar); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glDisable(GLenum cap) | |
| { | |
| TRACE("(GLenum cap = 0x%X)", cap); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| switch(cap) | |
| { | |
| case GL_CULL_FACE: context->setCullFace(false); break; | |
| case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(false); break; | |
| case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(false); break; | |
| case GL_SAMPLE_COVERAGE: context->setSampleCoverage(false); break; | |
| case GL_SCISSOR_TEST: context->setScissorTest(false); break; | |
| case GL_STENCIL_TEST: context->setStencilTest(false); break; | |
| case GL_DEPTH_TEST: context->setDepthTest(false); break; | |
| case GL_BLEND: context->setBlend(false); break; | |
| case GL_DITHER: context->setDither(false); break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glDisableClientState(GLenum array) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count) | |
| { | |
| TRACE("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count); | |
| try | |
| { | |
| if(count < 0 || first < 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->drawArrays(mode, first, count); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices) | |
| { | |
| TRACE("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p)", | |
| mode, count, type, indices); | |
| try | |
| { | |
| if(count < 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| switch(type) | |
| { | |
| case GL_UNSIGNED_BYTE: | |
| case GL_UNSIGNED_SHORT: | |
| case GL_UNSIGNED_INT: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| context->drawElements(mode, count, type, indices); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glEnable(GLenum cap) | |
| { | |
| TRACE("(GLenum cap = 0x%X)", cap); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| switch(cap) | |
| { | |
| case GL_CULL_FACE: context->setCullFace(true); break; | |
| case GL_POLYGON_OFFSET_FILL: context->setPolygonOffsetFill(true); break; | |
| case GL_SAMPLE_ALPHA_TO_COVERAGE: context->setSampleAlphaToCoverage(true); break; | |
| case GL_SAMPLE_COVERAGE: context->setSampleCoverage(true); break; | |
| case GL_SCISSOR_TEST: context->setScissorTest(true); break; | |
| case GL_STENCIL_TEST: context->setStencilTest(true); break; | |
| case GL_DEPTH_TEST: context->setDepthTest(true); break; | |
| case GL_BLEND: context->setBlend(true); break; | |
| case GL_DITHER: context->setDither(true); break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glEnableClientState(GLenum array) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glFinish(void) | |
| { | |
| TRACE("()"); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->finish(); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glFlush(void) | |
| { | |
| TRACE("()"); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->flush(); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glFramebufferRenderbufferOES(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, " | |
| "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer); | |
| try | |
| { | |
| if(target != GL_FRAMEBUFFER_OES || (renderbuffertarget != GL_RENDERBUFFER_OES && renderbuffer != 0)) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| gl::Framebuffer *framebuffer = context->getFramebuffer(); | |
| GLuint framebufferHandle = context->getFramebufferHandle(); | |
| if(!framebuffer || (framebufferHandle == 0 && renderbuffer != 0)) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| switch(attachment) | |
| { | |
| case GL_COLOR_ATTACHMENT0_OES: | |
| framebuffer->setColorbuffer(GL_RENDERBUFFER_OES, renderbuffer); | |
| break; | |
| case GL_DEPTH_ATTACHMENT_OES: | |
| framebuffer->setDepthbuffer(GL_RENDERBUFFER_OES, renderbuffer); | |
| break; | |
| case GL_STENCIL_ATTACHMENT_OES: | |
| framebuffer->setStencilbuffer(GL_RENDERBUFFER_OES, renderbuffer); | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glFramebufferTexture2DOES(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, " | |
| "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level); | |
| try | |
| { | |
| if(target != GL_FRAMEBUFFER_OES) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| switch(attachment) | |
| { | |
| case GL_COLOR_ATTACHMENT0_OES: | |
| case GL_DEPTH_ATTACHMENT_OES: | |
| case GL_STENCIL_ATTACHMENT_OES: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| if(texture == 0) | |
| { | |
| textarget = GL_NONE_OES; | |
| } | |
| else | |
| { | |
| gl::Texture *tex = context->getTexture(texture); | |
| if(tex == NULL) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| if(tex->isCompressed(textarget, level)) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| switch(textarget) | |
| { | |
| case GL_TEXTURE_2D: | |
| if(tex->getTarget() != GL_TEXTURE_2D) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(level != 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| } | |
| gl::Framebuffer *framebuffer = context->getFramebuffer(); | |
| GLuint framebufferHandle = context->getFramebufferHandle(); | |
| if(framebufferHandle == 0 || !framebuffer) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| switch(attachment) | |
| { | |
| case GL_COLOR_ATTACHMENT0_OES: framebuffer->setColorbuffer(textarget, texture); break; | |
| case GL_DEPTH_ATTACHMENT_OES: framebuffer->setDepthbuffer(textarget, texture); break; | |
| case GL_STENCIL_ATTACHMENT_OES: framebuffer->setStencilbuffer(textarget, texture); break; | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glFogf(GLenum pname, GLfloat param) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glFogfv(GLenum pname, const GLfloat *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glFogx(GLenum pname, GLfixed param) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glFogxv(GLenum pname, const GLfixed *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glFrontFace(GLenum mode) | |
| { | |
| TRACE("(GLenum mode = 0x%X)", mode); | |
| try | |
| { | |
| switch(mode) | |
| { | |
| case GL_CW: | |
| case GL_CCW: | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->setFrontFace(mode); | |
| } | |
| } | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glFrustumf(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glFrustumx(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glGenerateMipmapOES(GLenum target) | |
| { | |
| TRACE("(GLenum target = 0x%X)", target); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| gl::Texture *texture; | |
| switch(target) | |
| { | |
| case GL_TEXTURE_2D: | |
| texture = context->getTexture2D(); | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(texture->isCompressed(target, 0) || texture->isDepth(target, 0)) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| texture->generateMipmaps(); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glGenBuffers(GLsizei n, GLuint* buffers) | |
| { | |
| TRACE("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers); | |
| try | |
| { | |
| if(n < 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| for(int i = 0; i < n; i++) | |
| { | |
| buffers[i] = context->createBuffer(); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glGenFramebuffersOES(GLsizei n, GLuint* framebuffers) | |
| { | |
| TRACE("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers); | |
| try | |
| { | |
| if(n < 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| for(int i = 0; i < n; i++) | |
| { | |
| framebuffers[i] = context->createFramebuffer(); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glGenRenderbuffersOES(GLsizei n, GLuint* renderbuffers) | |
| { | |
| TRACE("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers); | |
| try | |
| { | |
| if(n < 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| for(int i = 0; i < n; i++) | |
| { | |
| renderbuffers[i] = context->createRenderbuffer(); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glGenTextures(GLsizei n, GLuint* textures) | |
| { | |
| TRACE("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures); | |
| try | |
| { | |
| if(n < 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| for(int i = 0; i < n; i++) | |
| { | |
| textures[i] = context->createTexture(); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glGetRenderbufferParameterivOES(GLenum target, GLenum pname, GLint* params) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| if(target != GL_RENDERBUFFER_OES) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(context->getRenderbufferHandle() == 0) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle()); | |
| switch(pname) | |
| { | |
| case GL_RENDERBUFFER_WIDTH_OES: *params = renderbuffer->getWidth(); break; | |
| case GL_RENDERBUFFER_HEIGHT_OES: *params = renderbuffer->getHeight(); break; | |
| case GL_RENDERBUFFER_INTERNAL_FORMAT_OES: *params = renderbuffer->getFormat(); break; | |
| case GL_RENDERBUFFER_RED_SIZE_OES: *params = renderbuffer->getRedSize(); break; | |
| case GL_RENDERBUFFER_GREEN_SIZE_OES: *params = renderbuffer->getGreenSize(); break; | |
| case GL_RENDERBUFFER_BLUE_SIZE_OES: *params = renderbuffer->getBlueSize(); break; | |
| case GL_RENDERBUFFER_ALPHA_SIZE_OES: *params = renderbuffer->getAlphaSize(); break; | |
| case GL_RENDERBUFFER_DEPTH_SIZE_OES: *params = renderbuffer->getDepthSize(); break; | |
| case GL_RENDERBUFFER_STENCIL_SIZE_OES: *params = renderbuffer->getStencilSize(); break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glGetBooleanv(GLenum pname, GLboolean* params) | |
| { | |
| TRACE("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| if(!(context->getBooleanv(pname, params))) | |
| { | |
| unsigned int numParams = context->getQueryParameterNum(pname); | |
| if(numParams < 0) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(numParams == 0) | |
| { | |
| return; | |
| } | |
| if(context->isQueryParameterFloat(pname)) | |
| { | |
| GLfloat *floatParams = NULL; | |
| floatParams = new GLfloat[numParams]; | |
| context->getFloatv(pname, floatParams); | |
| for(unsigned int i = 0; i < numParams; ++i) | |
| { | |
| if(floatParams[i] == 0.0f) | |
| params[i] = GL_FALSE; | |
| else | |
| params[i] = GL_TRUE; | |
| } | |
| delete [] floatParams; | |
| } | |
| else if(context->isQueryParameterInt(pname)) | |
| { | |
| GLint *intParams = NULL; | |
| intParams = new GLint[numParams]; | |
| context->getIntegerv(pname, intParams); | |
| for(unsigned int i = 0; i < numParams; ++i) | |
| { | |
| if(intParams[i] == 0) | |
| params[i] = GL_FALSE; | |
| else | |
| params[i] = GL_TRUE; | |
| } | |
| delete [] intParams; | |
| } | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| gl::Buffer *buffer; | |
| switch(target) | |
| { | |
| case GL_ARRAY_BUFFER: | |
| buffer = context->getArrayBuffer(); | |
| break; | |
| case GL_ELEMENT_ARRAY_BUFFER: | |
| buffer = context->getElementArrayBuffer(); | |
| break; | |
| default: return error(GL_INVALID_ENUM); | |
| } | |
| if(!buffer) | |
| { | |
| // A null buffer means that "0" is bound to the requested buffer target | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| switch(pname) | |
| { | |
| case GL_BUFFER_USAGE: | |
| *params = buffer->usage(); | |
| break; | |
| case GL_BUFFER_SIZE: | |
| *params = buffer->size(); | |
| break; | |
| default: return error(GL_INVALID_ENUM); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glGetClipPlanef(GLenum pname, GLfloat eqn[4]) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glGetClipPlanex(GLenum pname, GLfixed eqn[4]) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| GLenum GL_APIENTRY glGetError(void) | |
| { | |
| TRACE("()"); | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| return context->getError(); | |
| } | |
| return GL_NO_ERROR; | |
| } | |
| void GL_APIENTRY glGetFixedv(GLenum pname, GLfixed *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glGetFloatv(GLenum pname, GLfloat* params) | |
| { | |
| TRACE("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| if(!(context->getFloatv(pname, params))) | |
| { | |
| unsigned int numParams = context->getQueryParameterNum(pname); | |
| if(numParams < 0) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(numParams == 0) | |
| { | |
| return; | |
| } | |
| if(context->isQueryParameterBool(pname)) | |
| { | |
| GLboolean *boolParams = NULL; | |
| boolParams = new GLboolean[numParams]; | |
| context->getBooleanv(pname, boolParams); | |
| for(unsigned int i = 0; i < numParams; ++i) | |
| { | |
| if(boolParams[i] == GL_FALSE) | |
| params[i] = 0.0f; | |
| else | |
| params[i] = 1.0f; | |
| } | |
| delete [] boolParams; | |
| } | |
| else if(context->isQueryParameterInt(pname)) | |
| { | |
| GLint *intParams = NULL; | |
| intParams = new GLint[numParams]; | |
| context->getIntegerv(pname, intParams); | |
| for(unsigned int i = 0; i < numParams; ++i) | |
| { | |
| params[i] = (GLfloat)intParams[i]; | |
| } | |
| delete [] intParams; | |
| } | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glGetFramebufferAttachmentParameterivOES(GLenum target, GLenum attachment, GLenum pname, GLint* params) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", | |
| target, attachment, pname, params); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| if(target != GL_FRAMEBUFFER_OES) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(context->getFramebufferHandle() == 0) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| gl::Framebuffer *framebuffer = context->getFramebuffer(); | |
| GLenum attachmentType; | |
| GLuint attachmentHandle; | |
| switch(attachment) | |
| { | |
| case GL_COLOR_ATTACHMENT0_OES: | |
| attachmentType = framebuffer->getColorbufferType(); | |
| attachmentHandle = framebuffer->getColorbufferHandle(); | |
| break; | |
| case GL_DEPTH_ATTACHMENT_OES: | |
| attachmentType = framebuffer->getDepthbufferType(); | |
| attachmentHandle = framebuffer->getDepthbufferHandle(); | |
| break; | |
| case GL_STENCIL_ATTACHMENT_OES: | |
| attachmentType = framebuffer->getStencilbufferType(); | |
| attachmentHandle = framebuffer->getStencilbufferHandle(); | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| GLenum attachmentObjectType; // Type category | |
| if(attachmentType == GL_NONE_OES || attachmentType == GL_RENDERBUFFER_OES) | |
| { | |
| attachmentObjectType = attachmentType; | |
| } | |
| else if(gl::IsTextureTarget(attachmentType)) | |
| { | |
| attachmentObjectType = GL_TEXTURE; | |
| } | |
| else UNREACHABLE(); | |
| switch(pname) | |
| { | |
| case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_OES: | |
| *params = attachmentObjectType; | |
| break; | |
| case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_OES: | |
| if(attachmentObjectType == GL_RENDERBUFFER_OES || attachmentObjectType == GL_TEXTURE) | |
| { | |
| *params = attachmentHandle; | |
| } | |
| else | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| break; | |
| case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_OES: | |
| if(attachmentObjectType == GL_TEXTURE) | |
| { | |
| *params = 0; // FramebufferTexture2D will not allow level to be set to anything else in GL ES 2.0 | |
| } | |
| else | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glGetIntegerv(GLenum pname, GLint* params) | |
| { | |
| TRACE("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| if(!(context->getIntegerv(pname, params))) | |
| { | |
| unsigned int numParams = context->getQueryParameterNum(pname); | |
| if(numParams < 0) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(numParams == 0) | |
| { | |
| return; | |
| } | |
| if(context->isQueryParameterBool(pname)) | |
| { | |
| GLboolean *boolParams = NULL; | |
| boolParams = new GLboolean[numParams]; | |
| context->getBooleanv(pname, boolParams); | |
| for(unsigned int i = 0; i < numParams; ++i) | |
| { | |
| if(boolParams[i] == GL_FALSE) | |
| params[i] = 0; | |
| else | |
| params[i] = 1; | |
| } | |
| delete [] boolParams; | |
| } | |
| else if(context->isQueryParameterFloat(pname)) | |
| { | |
| GLfloat *floatParams = NULL; | |
| floatParams = new GLfloat[numParams]; | |
| context->getFloatv(pname, floatParams); | |
| for(unsigned int i = 0; i < numParams; ++i) | |
| { | |
| if(pname == GL_DEPTH_RANGE || pname == GL_COLOR_CLEAR_VALUE || pname == GL_DEPTH_CLEAR_VALUE) | |
| { | |
| params[i] = (GLint)(((GLfloat)(0xFFFFFFFF) * floatParams[i] - 1.0f) / 2.0f); | |
| } | |
| else | |
| params[i] = (GLint)(floatParams[i] > 0.0f ? floor(floatParams[i] + 0.5) : ceil(floatParams[i] - 0.5)); | |
| } | |
| delete [] floatParams; | |
| } | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glGetLightfv(GLenum light, GLenum pname, GLfloat *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glGetLightxv(GLenum light, GLenum pname, GLfixed *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glGetMaterialfv(GLenum face, GLenum pname, GLfloat *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glGetMaterialxv(GLenum face, GLenum pname, GLfixed *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glGetPointerv(GLenum pname, GLvoid **params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| const GLubyte* GL_APIENTRY glGetString(GLenum name) | |
| { | |
| TRACE("(GLenum name = 0x%X)", name); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| switch(name) | |
| { | |
| case GL_VENDOR: | |
| return (GLubyte*)"TransGaming Inc."; | |
| case GL_RENDERER: | |
| return (GLubyte*)"SwiftShader"; | |
| case GL_VERSION: | |
| return (GLubyte*)"OpenGL ES 1.1 SwiftShader "VERSION_STRING; | |
| case GL_EXTENSIONS: | |
| // Keep list sorted in following order: | |
| // OES extensions | |
| // EXT extensions | |
| // Vendor extensions | |
| return (GLubyte*) | |
| "GL_OES_blend_equation_separate " | |
| "GL_OES_blend_func_separate " | |
| "GL_OES_blend_subtract " | |
| "GL_OES_depth_texture " | |
| "GL_OES_EGL_image " | |
| "GL_OES_EGL_image_external " | |
| "GL_OES_element_index_uint " | |
| "GL_OES_framebuffer_object " | |
| "GL_OES_packed_depth_stencil " | |
| "GL_OES_rgb8_rgba8 " | |
| "GL_OES_stencil8 " | |
| "GL_OES_stencil_wrap " | |
| "GL_OES_texture_float " | |
| "GL_OES_texture_float_linear " | |
| "GL_OES_texture_half_float " | |
| "GL_OES_texture_half_float_linear " | |
| "GL_OES_texture_mirrored_repeat " | |
| "GL_OES_texture_npot " | |
| "GL_EXT_blend_minmax " | |
| "GL_EXT_read_format_bgra " | |
| #if (S3TC_SUPPORT) | |
| "GL_EXT_texture_compression_dxt1 " | |
| "GL_ANGLE_texture_compression_dxt3 " | |
| "GL_ANGLE_texture_compression_dxt5 " | |
| #endif | |
| "GL_EXT_texture_filter_anisotropic " | |
| "GL_EXT_texture_format_BGRA8888"; | |
| default: | |
| return error(GL_INVALID_ENUM, (GLubyte*)NULL); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY, (GLubyte*)NULL); | |
| } | |
| return NULL; | |
| } | |
| void GL_APIENTRY glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", target, pname, params); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| gl::Texture *texture; | |
| switch(target) | |
| { | |
| case GL_TEXTURE_2D: | |
| texture = context->getTexture2D(); | |
| break; | |
| case GL_TEXTURE_EXTERNAL_OES: | |
| texture = context->getTextureExternal(); | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| switch(pname) | |
| { | |
| case GL_TEXTURE_MAG_FILTER: | |
| *params = (GLfloat)texture->getMagFilter(); | |
| break; | |
| case GL_TEXTURE_MIN_FILTER: | |
| *params = (GLfloat)texture->getMinFilter(); | |
| break; | |
| case GL_TEXTURE_WRAP_S: | |
| *params = (GLfloat)texture->getWrapS(); | |
| break; | |
| case GL_TEXTURE_WRAP_T: | |
| *params = (GLfloat)texture->getWrapT(); | |
| break; | |
| case GL_TEXTURE_MAX_ANISOTROPY_EXT: | |
| *params = texture->getMaxAnisotropy(); | |
| break; | |
| case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES: | |
| *params = (GLfloat)1; | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glGetTexParameteriv(GLenum target, GLenum pname, GLint* params) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| gl::Texture *texture; | |
| switch(target) | |
| { | |
| case GL_TEXTURE_2D: | |
| texture = context->getTexture2D(); | |
| break; | |
| case GL_TEXTURE_EXTERNAL_OES: | |
| texture = context->getTextureExternal(); | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| switch(pname) | |
| { | |
| case GL_TEXTURE_MAG_FILTER: | |
| *params = texture->getMagFilter(); | |
| break; | |
| case GL_TEXTURE_MIN_FILTER: | |
| *params = texture->getMinFilter(); | |
| break; | |
| case GL_TEXTURE_WRAP_S: | |
| *params = texture->getWrapS(); | |
| break; | |
| case GL_TEXTURE_WRAP_T: | |
| *params = texture->getWrapT(); | |
| break; | |
| case GL_TEXTURE_MAX_ANISOTROPY_EXT: | |
| *params = (GLint)texture->getMaxAnisotropy(); | |
| break; | |
| case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES: | |
| *params = 1; | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glGetTexEnvfv(GLenum env, GLenum pname, GLfloat *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glGetTexEnviv(GLenum env, GLenum pname, GLint *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glGetTexEnvxv(GLenum env, GLenum pname, GLfixed *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glGetTexParameterxv(GLenum target, GLenum pname, GLfixed *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glHint(GLenum target, GLenum mode) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode); | |
| try | |
| { | |
| switch(mode) | |
| { | |
| case GL_FASTEST: | |
| case GL_NICEST: | |
| case GL_DONT_CARE: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| switch(target) | |
| { | |
| case GL_GENERATE_MIPMAP_HINT: | |
| if(context) context->setGenerateMipmapHint(mode); | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| GLboolean GL_APIENTRY glIsBuffer(GLuint buffer) | |
| { | |
| TRACE("(GLuint buffer = %d)", buffer); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context && buffer) | |
| { | |
| gl::Buffer *bufferObject = context->getBuffer(buffer); | |
| if(bufferObject) | |
| { | |
| return GL_TRUE; | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY, GL_FALSE); | |
| } | |
| return GL_FALSE; | |
| } | |
| GLboolean GL_APIENTRY glIsEnabled(GLenum cap) | |
| { | |
| TRACE("(GLenum cap = 0x%X)", cap); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| switch(cap) | |
| { | |
| case GL_CULL_FACE: return context->isCullFaceEnabled(); | |
| case GL_POLYGON_OFFSET_FILL: return context->isPolygonOffsetFillEnabled(); | |
| case GL_SAMPLE_ALPHA_TO_COVERAGE: return context->isSampleAlphaToCoverageEnabled(); | |
| case GL_SAMPLE_COVERAGE: return context->isSampleCoverageEnabled(); | |
| case GL_SCISSOR_TEST: return context->isScissorTestEnabled(); | |
| case GL_STENCIL_TEST: return context->isStencilTestEnabled(); | |
| case GL_DEPTH_TEST: return context->isDepthTestEnabled(); | |
| case GL_BLEND: return context->isBlendEnabled(); | |
| case GL_DITHER: return context->isDitherEnabled(); | |
| default: | |
| return error(GL_INVALID_ENUM, false); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY, false); | |
| } | |
| return false; | |
| } | |
| GLboolean GL_APIENTRY glIsFramebufferOES(GLuint framebuffer) | |
| { | |
| TRACE("(GLuint framebuffer = %d)", framebuffer); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context && framebuffer) | |
| { | |
| gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer); | |
| if(framebufferObject) | |
| { | |
| return GL_TRUE; | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY, GL_FALSE); | |
| } | |
| return GL_FALSE; | |
| } | |
| GLboolean GL_APIENTRY glIsTexture(GLuint texture) | |
| { | |
| TRACE("(GLuint texture = %d)", texture); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context && texture) | |
| { | |
| gl::Texture *textureObject = context->getTexture(texture); | |
| if(textureObject) | |
| { | |
| return GL_TRUE; | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY, GL_FALSE); | |
| } | |
| return GL_FALSE; | |
| } | |
| GLboolean GL_APIENTRY glIsRenderbufferOES(GLuint renderbuffer) | |
| { | |
| TRACE("(GLuint renderbuffer = %d)", renderbuffer); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context && renderbuffer) | |
| { | |
| gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer); | |
| if(renderbufferObject) | |
| { | |
| return GL_TRUE; | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY, GL_FALSE); | |
| } | |
| return GL_FALSE; | |
| } | |
| void GL_APIENTRY glLightModelf(GLenum pname, GLfloat param) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glLightModelfv(GLenum pname, const GLfloat *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glLightModelx(GLenum pname, GLfixed param) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glLightModelxv(GLenum pname, const GLfixed *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glLightf(GLenum light, GLenum pname, GLfloat param) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glLightfv(GLenum light, GLenum pname, const GLfloat *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glLightx(GLenum light, GLenum pname, GLfixed param) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glLightxv(GLenum light, GLenum pname, const GLfixed *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glLineWidth(GLfloat width) | |
| { | |
| TRACE("(GLfloat width = %f)", width); | |
| try | |
| { | |
| if(width <= 0.0f) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->setLineWidth(width); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glLineWidthx(GLfixed width) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glLoadIdentity(void) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glLoadMatrixf(const GLfloat *m) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glLoadMatrixx(const GLfixed *m) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glLogicOp(GLenum opcode) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glMaterialf(GLenum face, GLenum pname, GLfloat param) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glMaterialfv(GLenum face, GLenum pname, const GLfloat *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glMaterialx(GLenum face, GLenum pname, GLfixed param) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glMaterialxv(GLenum face, GLenum pname, const GLfixed *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glMatrixMode(GLenum mode) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glMultMatrixf(const GLfloat *m) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glMultMatrixx(const GLfixed *m) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glMultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glMultiTexCoord4x(GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glNormal3x(GLfixed nx, GLfixed ny, GLfixed nz) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glNormalPointer(GLenum type, GLsizei stride, const GLvoid *pointer) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glOrthof(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glOrthox(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glPixelStorei(GLenum pname, GLint param) | |
| { | |
| TRACE("(GLenum pname = 0x%X, GLint param = %d)", pname, param); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| switch(pname) | |
| { | |
| case GL_UNPACK_ALIGNMENT: | |
| if(param != 1 && param != 2 && param != 4 && param != 8) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| context->setUnpackAlignment(param); | |
| break; | |
| case GL_PACK_ALIGNMENT: | |
| if(param != 1 && param != 2 && param != 4 && param != 8) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| context->setPackAlignment(param); | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glPointParameterf(GLenum pname, GLfloat param) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glPointParameterfv(GLenum pname, const GLfloat *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glPointParameterx(GLenum pname, GLfixed param) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glPointParameterxv(GLenum pname, const GLfixed *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glPointSize(GLfloat size) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glPointSizex(GLfixed size) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glPolygonOffset(GLfloat factor, GLfloat units) | |
| { | |
| TRACE("(GLfloat factor = %f, GLfloat units = %f)", factor, units); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->setPolygonOffsetParams(factor, units); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glPolygonOffsetx(GLfixed factor, GLfixed units) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glPopMatrix(void) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glPushMatrix(void) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels) | |
| { | |
| TRACE("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, " | |
| "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)", | |
| x, y, width, height, format, type, pixels); | |
| try | |
| { | |
| if(width < 0 || height < 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| if(!validReadFormatType(format, type)) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->readPixels(x, y, width, height, format, type, NULL, pixels); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glRenderbufferStorageOES(GLenum target, GLenum internalformat, GLsizei width, GLsizei height) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)", | |
| target, internalformat, width, height); | |
| try | |
| { | |
| switch(target) | |
| { | |
| case GL_RENDERBUFFER_OES: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(!gl::IsColorRenderable(internalformat) && !gl::IsDepthRenderable(internalformat) && !gl::IsStencilRenderable(internalformat)) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(width < 0 || height < 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| if(width > gl::IMPLEMENTATION_MAX_RENDERBUFFER_SIZE || | |
| height > gl::IMPLEMENTATION_MAX_RENDERBUFFER_SIZE) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| GLuint handle = context->getRenderbufferHandle(); | |
| if(handle == 0) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| switch(internalformat) | |
| { | |
| case GL_DEPTH_COMPONENT16_OES: | |
| context->setRenderbufferStorage(new gl::Depthbuffer(width, height, 0)); | |
| break; | |
| case GL_RGBA4_OES: | |
| case GL_RGB5_A1_OES: | |
| case GL_RGB565_OES: | |
| case GL_RGB8_OES: | |
| case GL_RGBA8_OES: | |
| context->setRenderbufferStorage(new gl::Colorbuffer(width, height, internalformat, 0)); | |
| break; | |
| case GL_STENCIL_INDEX8_OES: | |
| context->setRenderbufferStorage(new gl::Stencilbuffer(width, height, 0)); | |
| break; | |
| case GL_DEPTH24_STENCIL8_OES: | |
| context->setRenderbufferStorage(new gl::DepthStencilbuffer(width, height, 0)); | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glRotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glSampleCoverage(GLclampf value, GLboolean invert) | |
| { | |
| TRACE("(GLclampf value = %f, GLboolean invert = %d)", value, invert); | |
| try | |
| { | |
| gl::Context* context = gl::getContext(); | |
| if(context) | |
| { | |
| context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glSampleCoveragex(GLclampx value, GLboolean invert) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glScalef(GLfloat x, GLfloat y, GLfloat z) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glScalex(GLfixed x, GLfixed y, GLfixed z) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glScissor(GLint x, GLint y, GLsizei width, GLsizei height) | |
| { | |
| TRACE("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)", x, y, width, height); | |
| try | |
| { | |
| if(width < 0 || height < 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| gl::Context* context = gl::getContext(); | |
| if(context) | |
| { | |
| context->setScissorParams(x, y, width, height); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glShadeModel(GLenum mode) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glStencilFunc(GLenum func, GLint ref, GLuint mask) | |
| { | |
| TRACE("(GLenum func = 0x%X, GLint ref = %d, GLuint mask = %d)", func, ref, mask); | |
| try | |
| { | |
| switch(func) | |
| { | |
| case GL_NEVER: | |
| case GL_ALWAYS: | |
| case GL_LESS: | |
| case GL_LEQUAL: | |
| case GL_EQUAL: | |
| case GL_GEQUAL: | |
| case GL_GREATER: | |
| case GL_NOTEQUAL: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->setStencilParams(func, ref, mask); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glStencilMask(GLuint mask) | |
| { | |
| TRACE("(GLuint mask = %d)", mask); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->setStencilWritemask(mask); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glStencilOp(GLenum fail, GLenum zfail, GLenum zpass) | |
| { | |
| TRACE("(GLenum fail = 0x%X, GLenum zfail = 0x%X, GLenum zpas = 0x%Xs)", fail, zfail, zpass); | |
| try | |
| { | |
| switch(fail) | |
| { | |
| case GL_ZERO: | |
| case GL_KEEP: | |
| case GL_REPLACE: | |
| case GL_INCR: | |
| case GL_DECR: | |
| case GL_INVERT: | |
| case GL_INCR_WRAP_OES: | |
| case GL_DECR_WRAP_OES: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| switch(zfail) | |
| { | |
| case GL_ZERO: | |
| case GL_KEEP: | |
| case GL_REPLACE: | |
| case GL_INCR: | |
| case GL_DECR: | |
| case GL_INVERT: | |
| case GL_INCR_WRAP_OES: | |
| case GL_DECR_WRAP_OES: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| switch(zpass) | |
| { | |
| case GL_ZERO: | |
| case GL_KEEP: | |
| case GL_REPLACE: | |
| case GL_INCR: | |
| case GL_DECR: | |
| case GL_INVERT: | |
| case GL_INCR_WRAP_OES: | |
| case GL_DECR_WRAP_OES: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->setStencilOperations(fail, zfail, zpass); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glTexEnvf(GLenum target, GLenum pname, GLfloat param) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glTexEnvfv(GLenum target, GLenum pname, const GLfloat *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glTexEnvi(GLenum target, GLenum pname, GLint param) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glTexEnvx(GLenum target, GLenum pname, GLfixed param) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glTexEnviv(GLenum target, GLenum pname, const GLint *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glTexEnvxv(GLenum target, GLenum pname, const GLfixed *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, | |
| GLint border, GLenum format, GLenum type, const GLvoid* pixels) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, " | |
| "GLint border = %d, GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)", | |
| target, level, internalformat, width, height, border, format, type, pixels); | |
| try | |
| { | |
| if(!validImageSize(level, width, height)) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| if(internalformat != format) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| switch(format) | |
| { | |
| case GL_ALPHA: | |
| case GL_LUMINANCE: | |
| case GL_LUMINANCE_ALPHA: | |
| switch(type) | |
| { | |
| case GL_UNSIGNED_BYTE: | |
| case GL_FLOAT: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| break; | |
| case GL_RGB: | |
| switch(type) | |
| { | |
| case GL_UNSIGNED_BYTE: | |
| case GL_UNSIGNED_SHORT_5_6_5: | |
| case GL_FLOAT: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| break; | |
| case GL_RGBA: | |
| switch(type) | |
| { | |
| case GL_UNSIGNED_BYTE: | |
| case GL_UNSIGNED_SHORT_4_4_4_4: | |
| case GL_UNSIGNED_SHORT_5_5_5_1: | |
| case GL_FLOAT: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| break; | |
| case GL_BGRA_EXT: | |
| switch(type) | |
| { | |
| case GL_UNSIGNED_BYTE: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| break; | |
| case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: // error cases for compressed textures are handled below | |
| case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: | |
| break; | |
| case GL_DEPTH_STENCIL_OES: | |
| switch(type) | |
| { | |
| case GL_UNSIGNED_INT_24_8_OES: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| break; | |
| default: | |
| return error(GL_INVALID_VALUE); | |
| } | |
| if(border != 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| switch(target) | |
| { | |
| case GL_TEXTURE_2D: | |
| if(width > (gl::IMPLEMENTATION_MAX_TEXTURE_SIZE >> level) || | |
| height > (gl::IMPLEMENTATION_MAX_TEXTURE_SIZE >> level)) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT || | |
| format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) | |
| { | |
| if(S3TC_SUPPORT) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| else | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| } | |
| if(target == GL_TEXTURE_2D) | |
| { | |
| gl::Texture2D *texture = context->getTexture2D(); | |
| if(!texture) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| texture->setImage(level, width, height, format, type, context->getUnpackAlignment(), pixels); | |
| } | |
| else UNREACHABLE(); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glTexParameterf(GLenum target, GLenum pname, GLfloat param) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLenum pname = 0x%X, GLfloat param = %f)", target, pname, param); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| gl::Texture *texture; | |
| switch(target) | |
| { | |
| case GL_TEXTURE_2D: | |
| texture = context->getTexture2D(); | |
| break; | |
| case GL_TEXTURE_EXTERNAL_OES: | |
| texture = context->getTextureExternal(); | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| switch(pname) | |
| { | |
| case GL_TEXTURE_WRAP_S: | |
| if(!texture->setWrapS((GLenum)param)) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| break; | |
| case GL_TEXTURE_WRAP_T: | |
| if(!texture->setWrapT((GLenum)param)) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| break; | |
| case GL_TEXTURE_MIN_FILTER: | |
| if(!texture->setMinFilter((GLenum)param)) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| break; | |
| case GL_TEXTURE_MAG_FILTER: | |
| if(!texture->setMagFilter((GLenum)param)) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| break; | |
| case GL_TEXTURE_MAX_ANISOTROPY_EXT: | |
| if(!texture->setMaxAnisotropy(param)) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params) | |
| { | |
| glTexParameterf(target, pname, *params); | |
| } | |
| void GL_APIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param); | |
| try | |
| { | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| gl::Texture *texture; | |
| switch(target) | |
| { | |
| case GL_TEXTURE_2D: | |
| texture = context->getTexture2D(); | |
| break; | |
| case GL_TEXTURE_EXTERNAL_OES: | |
| texture = context->getTextureExternal(); | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| switch(pname) | |
| { | |
| case GL_TEXTURE_WRAP_S: | |
| if(!texture->setWrapS((GLenum)param)) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| break; | |
| case GL_TEXTURE_WRAP_T: | |
| if(!texture->setWrapT((GLenum)param)) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| break; | |
| case GL_TEXTURE_MIN_FILTER: | |
| if(!texture->setMinFilter((GLenum)param)) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| break; | |
| case GL_TEXTURE_MAG_FILTER: | |
| if(!texture->setMagFilter((GLenum)param)) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| break; | |
| case GL_TEXTURE_MAX_ANISOTROPY_EXT: | |
| if(!texture->setMaxAnisotropy((GLfloat)param)) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glTexParameteriv(GLenum target, GLenum pname, const GLint* params) | |
| { | |
| glTexParameteri(target, pname, *params); | |
| } | |
| void GL_APIENTRY glTexParameterx(GLenum target, GLenum pname, GLfixed param) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glTexParameterxv(GLenum target, GLenum pname, const GLfixed *params) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, | |
| GLenum format, GLenum type, const GLvoid* pixels) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, " | |
| "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, " | |
| "const GLvoid* pixels = 0x%0.8p)", | |
| target, level, xoffset, yoffset, width, height, format, type, pixels); | |
| try | |
| { | |
| if(!gl::IsTextureTarget(target)) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(level < 0 || xoffset < 0 || yoffset < 0 || width < 0 || height < 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| if(std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| if(!gl::CheckTextureFormatType(format, type)) | |
| { | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(width == 0 || height == 0 || pixels == NULL) | |
| { | |
| return; | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| if(level > gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| if(target == GL_TEXTURE_2D) | |
| { | |
| gl::Texture2D *texture = context->getTexture2D(); | |
| if(validateSubImageParams(false, width, height, xoffset, yoffset, target, level, format, texture)) | |
| { | |
| texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels); | |
| } | |
| } | |
| else UNREACHABLE(); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glTranslatex(GLfixed x, GLfixed y, GLfixed z) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) | |
| { | |
| UNIMPLEMENTED(); | |
| } | |
| void GL_APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height) | |
| { | |
| TRACE("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)", x, y, width, height); | |
| try | |
| { | |
| if(width < 0 || height < 0) | |
| { | |
| return error(GL_INVALID_VALUE); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| context->setViewportParams(x, y, width, height); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| void GL_APIENTRY glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) | |
| { | |
| TRACE("(GLenum target = 0x%X, GLeglImageOES image = 0x%0.8p)", target, image); | |
| try | |
| { | |
| switch(target) | |
| { | |
| case GL_TEXTURE_EXTERNAL_OES: | |
| break; | |
| default: | |
| return error(GL_INVALID_ENUM); | |
| } | |
| if(!image) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| gl::Context *context = gl::getContext(); | |
| if(context) | |
| { | |
| gl::TextureExternal *texture = context->getTextureExternal(); | |
| if(!texture) | |
| { | |
| return error(GL_INVALID_OPERATION); | |
| } | |
| gl::Image *glImage = static_cast<gl::Image*>(image); | |
| texture->setImage(glImage); | |
| } | |
| } | |
| catch(std::bad_alloc&) | |
| { | |
| return error(GL_OUT_OF_MEMORY); | |
| } | |
| } | |
| __eglMustCastToProperFunctionPointerType glGetProcAddress(const char *procname) | |
| { | |
| struct Extension | |
| { | |
| const char *name; | |
| __eglMustCastToProperFunctionPointerType address; | |
| }; | |
| static const Extension glExtensions[] = | |
| { | |
| {"glEGLImageTargetTexture2DOES", (__eglMustCastToProperFunctionPointerType)glEGLImageTargetTexture2DOES}, | |
| {"glIsRenderbufferOES", (__eglMustCastToProperFunctionPointerType)glIsRenderbufferOES}, | |
| {"glBindRenderbufferOES", (__eglMustCastToProperFunctionPointerType)glBindRenderbufferOES}, | |
| {"glDeleteRenderbuffersOES", (__eglMustCastToProperFunctionPointerType)glDeleteRenderbuffersOES}, | |
| {"glGenRenderbuffersOES", (__eglMustCastToProperFunctionPointerType)glGenRenderbuffersOES}, | |
| {"glRenderbufferStorageOES", (__eglMustCastToProperFunctionPointerType)glRenderbufferStorageOES}, | |
| {"glGetRenderbufferParameterivOES", (__eglMustCastToProperFunctionPointerType)glGetRenderbufferParameterivOES}, | |
| {"glIsFramebufferOES", (__eglMustCastToProperFunctionPointerType)glIsFramebufferOES}, | |
| {"glBindFramebufferOES", (__eglMustCastToProperFunctionPointerType)glBindFramebufferOES}, | |
| {"glDeleteFramebuffersOES", (__eglMustCastToProperFunctionPointerType)glDeleteFramebuffersOES}, | |
| {"glGenFramebuffersOES", (__eglMustCastToProperFunctionPointerType)glGenFramebuffersOES}, | |
| {"glCheckFramebufferStatusOES", (__eglMustCastToProperFunctionPointerType)glCheckFramebufferStatusOES}, | |
| {"glFramebufferRenderbufferOES", (__eglMustCastToProperFunctionPointerType)glFramebufferRenderbufferOES}, | |
| {"glFramebufferTexture2DOES", (__eglMustCastToProperFunctionPointerType)glFramebufferTexture2DOES}, | |
| {"glGetFramebufferAttachmentParameterivOES", (__eglMustCastToProperFunctionPointerType)glGetFramebufferAttachmentParameterivOES}, | |
| {"glGenerateMipmapOES", (__eglMustCastToProperFunctionPointerType)glGenerateMipmapOES}, | |
| {"glBlendEquationSeparateOES", (__eglMustCastToProperFunctionPointerType)glBlendEquationSeparateOES}, | |
| {"glBlendFuncSeparateOES", (__eglMustCastToProperFunctionPointerType)glBlendFuncSeparateOES} | |
| }; | |
| for(int ext = 0; ext < sizeof(glExtensions) / sizeof(Extension); ext++) | |
| { | |
| if(strcmp(procname, glExtensions[ext].name) == 0) | |
| { | |
| return (__eglMustCastToProperFunctionPointerType)glExtensions[ext].address; | |
| } | |
| } | |
| return NULL; | |
| } | |
| void GL_APIENTRY Register(const char *licenseKey) | |
| { | |
| RegisterLicenseKey(licenseKey); | |
| } | |
| } |