diff options
Diffstat (limited to 'es_2_0/internal.c')
-rwxr-xr-x | es_2_0/internal.c | 226 |
1 files changed, 226 insertions, 0 deletions
diff --git a/es_2_0/internal.c b/es_2_0/internal.c new file mode 100755 index 0000000..65647d1 --- /dev/null +++ b/es_2_0/internal.c @@ -0,0 +1,226 @@ +/* + * Copyright (C) 2010 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * DongKyun Yun <dk77.yun@samsung.com> + * SangJin Kim <sangjin3.kim@samsung.com> + * HyunGoo Kang <hyungoo1.kang@samsung.com> + * + * 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" + +#if ! defined(WIN32) +#include <dlfcn.h> +#endif +#include <malloc.h> + +static struct es2Context s_defaultContext = { + GL_FALSE, + 0, + GL_NO_ERROR, + NULL, 0, 0, + NULL, 0, + NULL, 0, + NULL, 0, + (void*)(&(ES2INTER(NotBound))), +}; + +static struct es2Context s_context = { + GL_FALSE, + 0, + GL_NO_ERROR, + NULL, 0, 0, + NULL, 0, + NULL, 0, + NULL, 0, + (void*)(&(ES2INTER(NotBound))), +}; + +struct es2Context* ES2INTER(curContext) = &s_context; + +void GL_APIENTRY ES2INTER(NotBound)(void) { + fprintf(stderr, "ES2 internal error: you are calling not-bound function\n"); +} + +void GL_APIENTRY ES2INTER(ResetFnptrs)(struct es2Context* pContext) { +#define ACTION(name) do { \ + *(void**)(&pContext->fp##name) = (void*)(&(ES2INTER(NotBound))); \ + } while (0) +#include "funcaction.inl" +#undef ACTION +} + +void GL_APIENTRY ES2INTER(BindFnptrs)(struct es2Context* pContext) { +#if ! defined(WIN32) + void* dl; + if ((dl = dlopen("libGL.so", RTLD_NOW | RTLD_GLOBAL)) == 0) { + ES2INTER(SetError)(GL_INVALID_OPERATION); + return; + } +#define ACTION(name) do { \ + *(void**)(&pContext->fp##name) = dlsym(dl, "gl" #name ); \ + if (pContext->fp##name == NULL) { \ + *(void**)(&pContext->fp##name) = dlsym(dl, "gl" #name "EXT"); \ + assert(pContext->fp##name != NULL) ; \ + if (pContext->fp##name == NULL) { \ + *(void**)(&pContext->fp##name) = (void*)(&(ES2INTER(NotBound))); \ + } \ + } \ + } while (0) +#include "funcaction.inl" +#undef ACTION + dlclose(dl); +#endif +} + + +void* GL_APIENTRY EGLCROSS(CreateContext)(void) { + struct es2Context* pContext = malloc(sizeof(struct es2Context)); + if (pContext == NULL) { + ES2INTER(SetError)(GL_OUT_OF_MEMORY); + return NULL; + } + memcpy(pContext, &s_defaultContext, sizeof(struct es2Context)); + ES2INTER(ResetFnptrs)(pContext); + return pContext; +} + +void GL_APIENTRY EGLCROSS(MakeCurrent)(void* ptr) { + int i; + struct es2Context* pContext = (struct es2Context*)ptr; + if (ptr == NULL) { + ES2INTER(curContext) = &s_context; + return; + } + ES2INTER(BindFnptrs)(pContext); + ES2INTER(curContext) = pContext; + pContext->bShaderCompiler = GL_TRUE; + FNPTR(GetIntegerv)(GL_MAX_VERTEX_ATTRIBS, &pContext->nMaxVertexAttribs); + assert(8 <= pContext->nMaxVertexAttribs); + if (pContext->pVertexAttrib == NULL) { + pContext->pVertexAttrib = calloc(pContext->nMaxVertexAttribs, + sizeof(struct VertexAttribUnit)); + if (pContext->pVertexAttrib == NULL) { + ES2INTER(SetError)(GL_OUT_OF_MEMORY); + return; + } + for (i = 0; i < pContext->nMaxVertexAttribs; i++) { + ES2INTER(VertexAttribInit)(&(pContext->pVertexAttrib[i])); + } + pContext->uArrayBufferBinding = 0; + pContext->uElementArrayBufferBinding = 0; + } + if (pContext->pBufferObject == NULL) { + pContext->pBufferObject = calloc(INTERNAL_NUM_BUFFER_OBJECTS, + sizeof(struct BufferObjectUnit)); + if (pContext->pBufferObject == NULL) { + ES2INTER(SetError)(GL_OUT_OF_MEMORY); + return; + } + pContext->nBufferObjectAllocated = INTERNAL_NUM_BUFFER_OBJECTS; + for (i = 0; i < pContext->nBufferObjectAllocated; i++) { + ES2INTER(BufferObjectInit)(&(pContext->pBufferObject[i])); + } + pContext->pBufferObject[0].bGenerated = GL_TRUE; + } + if (pContext->pShaderObject == NULL) { + pContext->pShaderObject = calloc(INTERNAL_NUM_SHADER_OBJECTS, + sizeof(struct ShaderObjectUnit)); + if (pContext->pShaderObject == NULL) { + ES2INTER(SetError)(GL_OUT_OF_MEMORY); + return; + } + pContext->nShaderObjectAllocated = INTERNAL_NUM_SHADER_OBJECTS; + for (i = 0; i < pContext->nShaderObjectAllocated; i++) { + ES2INTER(ShaderObjectInit)(&(pContext->pShaderObject[i])); + } + } + if (pContext->pProgramObject == NULL) { + pContext->pProgramObject = calloc(INTERNAL_NUM_PROGRAM_OBJECTS, + sizeof(struct ProgramObjectUnit)); + if (pContext->pProgramObject == NULL) { + ES2INTER(SetError)(GL_OUT_OF_MEMORY); + return; + } + pContext->nProgramObjectAllocated = INTERNAL_NUM_PROGRAM_OBJECTS; + for (i = 0; i < pContext->nProgramObjectAllocated; i++) { + ES2INTER(ProgramObjectInit)(&(pContext->pProgramObject[i])); + } + } + /* from the sepc., + The values in gl_PointCoord are two-dimensional coordinates indicating + where within a point primitive the current fragment is located, when point + sprites are enabled. They range from 0.0 to 1.0 across the point. If the + current primitive is not a point, or if point sprites are not enabled, + then the values read from gl_PointCoord are undefined. + */ +#if ! defined(GL_POINT_SPRITE) +#define GL_POINT_SPRITE 0x8861 +#endif +#if ! defined(GL_VERTEX_PROGRAM_POINT_SIZE) +#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642 +#endif + FNPTR(Enable)(GL_POINT_SPRITE); + FNPTR(Enable)(GL_VERTEX_PROGRAM_POINT_SIZE); +} + +void GL_APIENTRY EGLCROSS(ReleaseContext)(void* ptr) { + int i; + struct es2Context* pContext = (struct es2Context*)ptr; + if (ptr == NULL) return; + if (pContext == &s_context) return; + if (pContext->pVertexAttrib != NULL) { + for (i = 0; i < pContext->nMaxVertexAttribs; i++) { + ES2INTER(VertexAttribRelease)(&(pContext->pVertexAttrib[i])); + } + free(pContext->pVertexAttrib); + pContext->pVertexAttrib = NULL; + } + if (pContext->pBufferObject == NULL) { + for (i = 0; i < pContext->nBufferObjectAllocated; i++) { + ES2INTER(BufferObjectRelease)(&(pContext->pBufferObject[i])); + } + free(pContext->pBufferObject); + pContext->pBufferObject = NULL; + } + if (pContext->pShaderObject == NULL) { + for (i = 0; i < pContext->nShaderObjectAllocated; i++) { + ES2INTER(ShaderObjectRelease)(&(pContext->pShaderObject[i])); + } + free(pContext->pShaderObject); + pContext->pShaderObject = NULL; + } + if (pContext->pProgramObject == NULL) { + for (i = 0; i < pContext->nProgramObjectAllocated; i++) { + ES2INTER(ProgramObjectRelease)(&(pContext->pProgramObject[i])); + } + free(pContext->pProgramObject); + pContext->pProgramObject = NULL; + } + free(pContext); + if (pContext == ES2INTER(curContext)) { + ES2INTER(curContext) = &s_context; + } +} |