/* * 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 "gl_imp.h" #include #include #if ! defined(GL_BUFFER_ACCESS) #define GL_BUFFER_ACCESS 0x88BB #endif #if ! defined(GL_WRITE_ONLY) #define GL_WRITE_ONLY 0x88B9 #endif static void INTFN(ResizeBuffer)(int n) { if (CCV(nBuffer) <= n) { int newSize = CCV(nBuffer); while (newSize <= n) { newSize *= 2; } CCV(pBufferStatus) = realloc(CCV(pBufferStatus), newSize * sizeof(GLint)); memset(CCV(pBufferStatus) + CCV(nBuffer), 0, (newSize - CCV(nBuffer)) * sizeof(GLint)); CCV(nBuffer) = newSize; } } #if ALEXGL_INTERNAL_VERSION >= 110 GL_API void GL_APIENTRY EXTFN(GenBuffers)(GLsizei n, GLuint* buffers) { int max; int i; FNPTR(GenBuffers)(n, buffers); max = 0; for (i = 0; buffers != NULL && i < n; i++) { if (buffers[i] > max) max = buffers[i]; } INTFN(ResizeBuffer)(max); for (i = 0; buffers != NULL && i < n; i++) { CCV(pBufferStatus)[buffers[i]] = ALEXGL_BUFFER_GENERATED; } } #endif #if ALEXGL_INTERNAL_VERSION >= 110 GL_API void GL_APIENTRY EXTFN(BindBuffer)(GLenum target, GLuint buffer) { if (target != GL_ARRAY_BUFFER && target != GL_ELEMENT_ARRAY_BUFFER) { INTFN(SetError)(GL_INVALID_ENUM); return; } FNPTR(BindBuffer)(target, buffer); INTFN(ResizeBuffer)(buffer); CCV(pBufferStatus)[buffer] = ALEXGL_BUFFER_BOUND; } #endif #if ALEXGL_INTERNAL_VERSION >= 110 GL_API void GL_APIENTRY EXTFN(DeleteBuffers)(GLsizei n, const GLuint* buffers) { int max; int i; FNPTR(DeleteBuffers)(n, buffers); max = 0; for (i = 0; buffers != NULL && i < n; i++) { if (buffers[i] > max) max = buffers[i]; } INTFN(ResizeBuffer)(max); for (i = 0; buffers != NULL && i < n; i++) { CCV(pBufferStatus)[buffers[i]] = ALEXGL_BUFFER_NULL; } } #endif #if ALEXGL_INTERNAL_VERSION >= 110 GL_API GLboolean GL_APIENTRY EXTFN(IsBuffer)(GLuint buffer) { register GLboolean bAnswer; bAnswer = FNPTR(IsBuffer)(buffer); INTFN(ResizeBuffer)(buffer); if (bAnswer == GL_TRUE && CCV(pBufferStatus)[buffer] != ALEXGL_BUFFER_BOUND) { bAnswer = GL_FALSE; } return (bAnswer == GL_FALSE) ? GL_FALSE : GL_TRUE; } #endif #if ALEXGL_INTERNAL_VERSION >= 110 GL_API void GL_APIENTRY EXTFN(GetBufferParameteriv)(GLenum target, GLenum pname, GLint* params) { if (target != GL_ARRAY_BUFFER && target != GL_ELEMENT_ARRAY_BUFFER) { INTFN(SetError)(GL_INVALID_ENUM); return; } if (pname != GL_BUFFER_SIZE && pname != GL_BUFFER_USAGE && pname != GL_BUFFER_ACCESS) { INTFN(SetError)(GL_INVALID_ENUM); return; } FNPTR(GetBufferParameteriv)(target, pname, params); if (pname == GL_BUFFER_ACCESS && *params == GL_READ_WRITE) { *params = GL_WRITE_ONLY; } } #endif #if ALEXGL_INTERNAL_VERSION >= 110 GL_API void GL_APIENTRY EXTFN(BufferData)(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage) { if (target != GL_ARRAY_BUFFER && target != GL_ELEMENT_ARRAY_BUFFER) { INTFN(SetError)(GL_INVALID_ENUM); return; } if (usage != GL_STATIC_DRAW && usage != GL_DYNAMIC_DRAW) { INTFN(SetError)(GL_INVALID_ENUM); return; } FNPTR(BufferData)(target, size, data, usage); } #endif #if ALEXGL_INTERNAL_VERSION >= 110 GL_API void GL_APIENTRY EXTFN(BufferSubData)(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data) { if (target != GL_ARRAY_BUFFER && target != GL_ELEMENT_ARRAY_BUFFER) { INTFN(SetError)(GL_INVALID_ENUM); return; } FNPTR(BufferSubData)(target, offset, size, data); } #endif