/* * Copyright (C) 2010 - 2011 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: * DongKyun Yun * SangJin Kim * HyunGoo Kang * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * Contributors: * - S-Core Co., Ltd * */ #include "es2front.h" #include #ifndef GL_TEXTURE_WIDTH #define GL_TEXTURE_WIDTH 0x1000 #endif #ifndef GL_TEXTURE_HEIGHT #define GL_TEXTURE_HEIGHT 0x1001 #endif #ifndef GL_TEXTURE_INTERNAL_FORMAT #define GL_TEXTURE_INTERNAL_FORMAT 0x1003 #endif static GLint ES2INTER(mapFormat)[] = { 0, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA }; int GL_APIENTRY ES2INTER(Log2)(GLint x) { register int val = 0; if (x <= 0) return -1; if ((x & 0xFFFF0000) != 0) { val += 16; x >>= 16; } if ((x & 0x0000FF00) != 0) { val += 8; x >>= 8; } if ((x & 0x000000F0) != 0) { val += 4; x >>= 4; } if ((x & 0x0000000C) != 0) { val += 2; x >>= 2; } if ((x & 0x00000002) != 0) { val += 1; x >>= 1; } return val; } void GL_APIENTRY ES2ENTRY(TexImage2D)(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pixels) { int iMaxSize; if (1 <= internalformat && internalformat <= 4) { internalformat = ES2INTER(mapFormat)[internalformat]; } if (1 <= format && format <= 4) { format = ES2INTER(mapFormat)[format]; } switch (target) { default: ES2INTER(SetError)(GL_INVALID_ENUM); return; case GL_TEXTURE_2D: FNPTR(GetIntegerv)(GL_MAX_TEXTURE_SIZE, &iMaxSize); break; case GL_TEXTURE_CUBE_MAP_POSITIVE_X: case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: if (width != height) { ES2INTER(SetError)(GL_INVALID_VALUE); return; } FNPTR(GetIntegerv)(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &iMaxSize); break; } switch (format) { default: ES2INTER(SetError)(GL_INVALID_ENUM); return; #if defined(PROVIDING_OES_packed_depth_stencil) case GL_DEPTH_STENCIL_OES: #endif case GL_ALPHA: case GL_LUMINANCE: case GL_LUMINANCE_ALPHA: case GL_RGB: case GL_RGBA: break; } switch (internalformat) { default: ES2INTER(SetError)(GL_INVALID_ENUM); return; #if defined(PROVIDING_OES_packed_depth_stencil) case GL_DEPTH_STENCIL_OES: #endif case GL_ALPHA: case GL_LUMINANCE: case GL_LUMINANCE_ALPHA: case GL_RGB: case GL_RGBA: break; } switch (type) { default: ES2INTER(SetError)(GL_INVALID_ENUM); return; #if defined(PROVIDING_OES_packed_depth_stencil) case GL_UNSIGNED_INT_24_8_OES: #endif case GL_UNSIGNED_BYTE: break; case GL_UNSIGNED_SHORT_5_6_5: if (format != GL_RGB) { ES2INTER(SetError)(GL_INVALID_OPERATION); return; } break; case GL_UNSIGNED_SHORT_4_4_4_4: case GL_UNSIGNED_SHORT_5_5_5_1: if (format != GL_RGBA) { ES2INTER(SetError)(GL_INVALID_OPERATION); return; } break; } if (level < 0) { ES2INTER(SetError)(GL_INVALID_VALUE); return; } else if (ES2INTER(Log2)(iMaxSize) < level) { ES2INTER(SetError)(GL_INVALID_VALUE); return; } if (width < 0 || iMaxSize < width || height < 0 || iMaxSize < height) { ES2INTER(SetError)(GL_INVALID_VALUE); return; } if (border != 0) { ES2INTER(SetError)(GL_INVALID_VALUE); return; } FNPTR(TexImage2D)(target, level, internalformat, width, height, border, format, type, pixels); } void GL_APIENTRY ES2ENTRY(TexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels) { int iMaxSize; int iWidth, iHeight; int iInternalFormat; if (1 <= format && format <= 4) { format = ES2INTER(mapFormat)[format]; } switch (target) { default: ES2INTER(SetError)(GL_INVALID_ENUM); return; case GL_TEXTURE_2D: FNPTR(GetIntegerv)(GL_MAX_TEXTURE_SIZE, &iMaxSize); break; case GL_TEXTURE_CUBE_MAP_POSITIVE_X: case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: if (width != height) { ES2INTER(SetError)(GL_INVALID_VALUE); return; } FNPTR(GetIntegerv)(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &iMaxSize); break; } switch (format) { default: ES2INTER(SetError)(GL_INVALID_ENUM); return; #if defined(PROVIDING_OES_packed_depth_stencil) case GL_DEPTH_STENCIL_OES: #endif case GL_ALPHA: case GL_LUMINANCE: case GL_LUMINANCE_ALPHA: case GL_RGB: case GL_RGBA: break; } switch (type) { default: ES2INTER(SetError)(GL_INVALID_ENUM); return; #if defined(PROVIDING_OES_packed_depth_stencil) case GL_UNSIGNED_INT_24_8_OES: #endif case GL_UNSIGNED_BYTE: break; case GL_UNSIGNED_SHORT_5_6_5: if (format != GL_RGB) { ES2INTER(SetError)(GL_INVALID_OPERATION); return; } break; case GL_UNSIGNED_SHORT_4_4_4_4: case GL_UNSIGNED_SHORT_5_5_5_1: if (format != GL_RGBA) { ES2INTER(SetError)(GL_INVALID_OPERATION); return; } break; } if (level < 0) { ES2INTER(SetError)(GL_INVALID_VALUE); return; } else if (ES2INTER(Log2)(iMaxSize) < level) { ES2INTER(SetError)(GL_INVALID_VALUE); return; } if (width < 0 || height < 0) { ES2INTER(SetError)(GL_INVALID_VALUE); return; } FNPTR(GetTexLevelParameteriv)(target, level, GL_TEXTURE_WIDTH, &iWidth); FNPTR(GetTexLevelParameteriv)(target, level, GL_TEXTURE_HEIGHT, &iHeight); if (xoffset < 0 || iWidth < (xoffset + width) || yoffset < 0 || iHeight < (yoffset + height)) { ES2INTER(SetError)(GL_INVALID_VALUE); } FNPTR(TexSubImage2D)(target, level, xoffset, yoffset, width, height, format, type, pixels); } void GL_APIENTRY ES2ENTRY(CopyTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) { int iMaxSize; if (1 <= internalformat && internalformat <= 4) { internalformat = ES2INTER(mapFormat)[internalformat]; } switch (target) { default: ES2INTER(SetError)(GL_INVALID_ENUM); return; case GL_TEXTURE_2D: FNPTR(GetIntegerv)(GL_MAX_TEXTURE_SIZE, &iMaxSize); break; case GL_TEXTURE_CUBE_MAP_POSITIVE_X: case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: if (width != height) { ES2INTER(SetError)(GL_INVALID_VALUE); return; } FNPTR(GetIntegerv)(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &iMaxSize); break; } switch (internalformat) { default: ES2INTER(SetError)(GL_INVALID_ENUM); return; case GL_ALPHA: case GL_LUMINANCE: case GL_LUMINANCE_ALPHA: case GL_RGB: case GL_RGBA: break; } if (level < 0) { ES2INTER(SetError)(GL_INVALID_VALUE); return; } else if (ES2INTER(Log2)(iMaxSize) < level) { ES2INTER(SetError)(GL_INVALID_VALUE); return; } if (width < 0 || iMaxSize < width || height < 0 || iMaxSize < height) { ES2INTER(SetError)(GL_INVALID_VALUE); return; } if (border != 0) { ES2INTER(SetError)(GL_INVALID_VALUE); return; } FNPTR(CopyTexImage2D)(target, level, internalformat, x, y, width, height, border); } void GL_APIENTRY ES2ENTRY(CopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) { int iMaxSize; int iWidth, iHeight; int iInternalFormat; switch (target) { default: ES2INTER(SetError)(GL_INVALID_ENUM); return; case GL_TEXTURE_2D: FNPTR(GetIntegerv)(GL_MAX_TEXTURE_SIZE, &iMaxSize); break; case GL_TEXTURE_CUBE_MAP_POSITIVE_X: case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: if (width != height) { ES2INTER(SetError)(GL_INVALID_VALUE); return; } FNPTR(GetIntegerv)(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &iMaxSize); break; } if (level < 0) { ES2INTER(SetError)(GL_INVALID_VALUE); return; } else if (ES2INTER(Log2)(iMaxSize) < level) { ES2INTER(SetError)(GL_INVALID_VALUE); return; } if (width < 0 || height < 0) { ES2INTER(SetError)(GL_INVALID_VALUE); return; } FNPTR(GetTexLevelParameteriv)(target, level, GL_TEXTURE_WIDTH, &iWidth); FNPTR(GetTexLevelParameteriv)(target, level, GL_TEXTURE_HEIGHT, &iHeight); if (xoffset < 0 || iWidth < (xoffset + width) || yoffset < 0 || iHeight < (yoffset + height)) { ES2INTER(SetError)(GL_INVALID_VALUE); } FNPTR(CopyTexSubImage2D)(target, level, xoffset, yoffset, x, y, width, height); }