diff options
Diffstat (limited to 'emulator/opengl/host')
158 files changed, 31331 insertions, 0 deletions
diff --git a/emulator/opengl/host/include/libOpenglRender/IOStream.h b/emulator/opengl/host/include/libOpenglRender/IOStream.h new file mode 100644 index 0000000..445ec17 --- /dev/null +++ b/emulator/opengl/host/include/libOpenglRender/IOStream.h @@ -0,0 +1,102 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef __IO_STREAM_H__ +#define __IO_STREAM_H__ + +#include <stdlib.h> +#include <stdio.h> + +#include "ErrorLog.h" + +class IOStream { +public: + + IOStream(size_t bufSize) { + m_buf = NULL; + m_bufsize = bufSize; + m_free = 0; + } + + virtual void *allocBuffer(size_t minSize) = 0; + virtual int commitBuffer(size_t size) = 0; + virtual const unsigned char *readFully( void *buf, size_t len) = 0; + virtual const unsigned char *read( void *buf, size_t *inout_len) = 0; + virtual int writeFully(const void* buf, size_t len) = 0; + + virtual ~IOStream() { + + // NOTE: m_buf is 'owned' by the child class thus we expect it to be released by it + } + + unsigned char *alloc(size_t len) { + + if (m_buf && len > m_free) { + if (flush() < 0) { + ERR("Failed to flush in alloc\n"); + return NULL; // we failed to flush so something is wrong + } + } + + if (!m_buf || len > m_bufsize) { + int allocLen = m_bufsize < len ? len : m_bufsize; + m_buf = (unsigned char *)allocBuffer(allocLen); + if (!m_buf) { + ERR("Alloc (%u bytes) failed\n", allocLen); + return NULL; + } + m_bufsize = m_free = allocLen; + } + + unsigned char *ptr; + + ptr = m_buf + (m_bufsize - m_free); + m_free -= len; + + return ptr; + } + + int flush() { + + if (!m_buf || m_free == m_bufsize) return 0; + + int stat = commitBuffer(m_bufsize - m_free); + m_buf = NULL; + m_free = 0; + return stat; + } + + const unsigned char *readback(void *buf, size_t len) { + flush(); + return readFully(buf, len); + } + + +private: + unsigned char *m_buf; + size_t m_bufsize; + size_t m_free; +}; + +// +// When a client opens a connection to the renderer, it should +// send unsigned int value indicating the "clientFlags". +// The following are the bitmask of the clientFlags. +// currently only one bit is used which flags the server +// it should exit. +// +#define IOSTREAM_CLIENT_EXIT_SERVER 1 + +#endif diff --git a/emulator/opengl/host/include/libOpenglRender/render_api.h b/emulator/opengl/host/include/libOpenglRender/render_api.h new file mode 100644 index 0000000..9c76b3e --- /dev/null +++ b/emulator/opengl/host/include/libOpenglRender/render_api.h @@ -0,0 +1,136 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _OPENGL_RENDERER_RENDER_API_H +#define _OPENGL_RENDERER_RENDER_API_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "render_api_platform_types.h" + +/* If a function with this signature is passed to initOpenGLRenderer(), + * it will be called by the renderer just before each new frame is displayed, + * providing a copy of the framebuffer contents. + * + * The callback will be called from one of the renderer's threads, so will + * probably need synchronization on any data structures it modifies. The + * pixels buffer may be overwritten as soon as the callback returns; if it needs + * the pixels afterwards it must copy them. + * + * The pixels buffer is intentionally not const: the callback may modify the + * data without copying to another buffer if it wants, e.g. in-place RGBA to RGB + * conversion, or in-place y-inversion. + * + * Parameters are: + * context The pointer optionally provided when the callback was + * registered. The client can use this to pass whatever + * information it wants to the callback. + * width, height Dimensions of the image, in pixels. Rows are tightly packed; + * there is no inter-row padding. + * ydir Indicates row order: 1 means top-to-bottom order, -1 means + * bottom-to-top order. + * format, type Format and type GL enums, as used in glTexImage2D() or + * glReadPixels(), describing the pixel format. + * pixels The framebuffer image. + * + * In the first implementation, ydir is always -1 (bottom to top), format and + * type are always GL_RGBA and GL_UNSIGNED_BYTE, and the width and height will + * always be the same as the ones passed to initOpenGLRenderer(). + */ +typedef void (*OnPostFn)(void* context, int width, int height, int ydir, + int format, int type, unsigned char* pixels); + +// initLibrary - initialize the library and tries to load the corresponding +// GLES translator libraries. This function must be called before anything +// else to ensure that everything works. If it returns an error, then +// you cannot use the library at all (this can happen under certain +// environments where the desktop GL libraries are not available) +// +// returns true if the library could be initialized successfully; +// +bool initLibrary(void); + +// list of constants to be passed to setStreamMode, which determines +// which +#define STREAM_MODE_DEFAULT 0 +#define STREAM_MODE_TCP 1 +#define STREAM_MODE_UNIX 2 +#define STREAM_MODE_PIPE 3 + +// Change the stream mode. This must be called before initOpenGLRenderer +int setStreamMode(int mode); + +// +// initOpenGLRenderer - initialize the OpenGL renderer process. +// portNum is the tcp port number the renderer is listening to. +// width and height are the framebuffer dimensions that will be +// reported to the guest display driver. +// +// returns true if renderer has been started successfully; +// +// This function is *NOT* thread safe and should be called first +// to initialize the renderer after initLibrary(). +// +bool initOpenGLRenderer(int width, int height, int portNum, + OnPostFn onPost, void* onPostContext); + +// +// createOpenGLSubwindow - +// Create a native subwindow which is a child of 'window' +// to be used for framebuffer display. +// Framebuffer will not get displayed if a subwindow is not +// created. +// x,y,width,height are the dimensions of the rendering subwindow. +// zRot is the rotation to apply on the framebuffer display image. +// +bool createOpenGLSubwindow(FBNativeWindowType window, + int x, int y, int width, int height, float zRot); + +// +// destroyOpenGLSubwindow - +// destroys the created native subwindow. Once destroyed, +// Framebuffer content will not be visible until a new +// subwindow will be created. +// +bool destroyOpenGLSubwindow(); + +// +// setOpenGLDisplayRotation - +// set the framebuffer display image rotation in units +// of degrees around the z axis +// +void setOpenGLDisplayRotation(float zRot); + +// +// repaintOpenGLDisplay - +// causes the OpenGL subwindow to get repainted with the +// latest framebuffer content. +// +void repaintOpenGLDisplay(); + +// +// stopOpenGLRenderer - stops the OpenGL renderer process. +// This functions is *NOT* thread safe and should be called +// only if previous initOpenGLRenderer has returned true. +// +bool stopOpenGLRenderer(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/emulator/opengl/host/include/libOpenglRender/render_api_platform_types.h b/emulator/opengl/host/include/libOpenglRender/render_api_platform_types.h new file mode 100644 index 0000000..38324e1 --- /dev/null +++ b/emulator/opengl/host/include/libOpenglRender/render_api_platform_types.h @@ -0,0 +1,41 @@ +/* +* Copyright 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef _RENDER_API_PLATFORM_TYPES_H +#define _RENDER_API_PLATFORM_TYPES_H + +#if defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */ +#include <windows.h> + +typedef HDC FBNativeDisplayType; +typedef HWND FBNativeWindowType; + +#elif defined(__linux__) + +#include <X11/Xlib.h> +#include <X11/Xutil.h> + +typedef Window FBNativeWindowType; + +#elif defined(__APPLE__) + +typedef void* FBNativeWindowType; + +#else +#warning "Unsupported platform" +#endif + +#endif // of _RENDER_API_PLATFORM_TYPES_H diff --git a/emulator/opengl/host/libs/GLESv1_dec/Android.mk b/emulator/opengl/host/libs/GLESv1_dec/Android.mk new file mode 100644 index 0000000..57dc429 --- /dev/null +++ b/emulator/opengl/host/libs/GLESv1_dec/Android.mk @@ -0,0 +1,43 @@ +LOCAL_PATH := $(call my-dir) + +host_common_debug_CFLAGS := + +#For gl debbuging +#host_common_debug_CFLAGS += -DCHECK_GL_ERROR +#host_common_debug_CFLAGS += -DDEBUG_PRINTOUT + + +### host library ######################################### +$(call emugl-begin-host-static-library,libGLESv1_dec) + +$(call emugl-import, libOpenglCodecCommon libOpenglOsUtils) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) + +$(call emugl-gen-decoder,$(EMUGL_PATH)/system/GLESv1_enc,gl) + +LOCAL_SRC_FILES := GLDecoder.cpp + +# for gl_types.h ! +$(call emugl-export,C_INCLUDES,$(EMUGL_PATH)/system/GLESv1_enc) + +$(call emugl-export,CFLAGS,$(host_common_debug_CFLAGS)) + +$(call emugl-end-module) + + +### host library, 64-bit #################################### +$(call emugl-begin-host-static-library,lib64GLESv1_dec) + +$(call emugl-import, lib64OpenglCodecCommon lib64OpenglOsUtils) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) + +$(call emugl-gen-decoder,$(EMUGL_PATH)/system/GLESv1_enc,gl) + +LOCAL_SRC_FILES := GLDecoder.cpp + +# for gl_types.h ! +$(call emugl-export,C_INCLUDES,$(EMUGL_PATH)/system/GLESv1_enc) + +$(call emugl-export,CFLAGS,$(host_common_debug_CFLAGS) -m64) + +$(call emugl-end-module) diff --git a/emulator/opengl/host/libs/GLESv1_dec/GLDecoder.cpp b/emulator/opengl/host/libs/GLESv1_dec/GLDecoder.cpp new file mode 100644 index 0000000..5399445 --- /dev/null +++ b/emulator/opengl/host/libs/GLESv1_dec/GLDecoder.cpp @@ -0,0 +1,238 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "GLDecoder.h" +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <EGL/egl.h> +#include <GLES/gl.h> +#include <GLES/glext.h> + +GLDecoder::GLDecoder() +{ + m_contextData = NULL; + m_glesDso = NULL; +} + +GLDecoder::~GLDecoder() +{ + if (m_glesDso != NULL) { + delete m_glesDso; + } +} + + +int GLDecoder::initGL(get_proc_func_t getProcFunc, void *getProcFuncData) +{ + if (getProcFunc == NULL) { + const char *libname = GLES_LIBNAME; + if (getenv(GLES_LIBNAME_VAR) != NULL) { + libname = getenv(GLES_LIBNAME_VAR); + } + + m_glesDso = osUtils::dynLibrary::open(libname); + if (m_glesDso == NULL) { + fprintf(stderr, "Couldn't find %s \n", GLES_LIBNAME); + return -1; + } + + this->initDispatchByName(s_getProc, this); + } else { + this->initDispatchByName(getProcFunc, getProcFuncData); + } + + set_glGetCompressedTextureFormats(s_glGetCompressedTextureFormats); + set_glVertexPointerOffset(s_glVertexPointerOffset); + set_glColorPointerOffset(s_glColorPointerOffset); + set_glNormalPointerOffset(s_glNormalPointerOffset); + set_glTexCoordPointerOffset(s_glTexCoordPointerOffset); + set_glPointSizePointerOffset(s_glPointSizePointerOffset); + set_glWeightPointerOffset(s_glWeightPointerOffset); + set_glMatrixIndexPointerOffset(s_glMatrixIndexPointerOffset); + + set_glVertexPointerData(s_glVertexPointerData); + set_glColorPointerData(s_glColorPointerData); + set_glNormalPointerData(s_glNormalPointerData); + set_glTexCoordPointerData(s_glTexCoordPointerData); + set_glPointSizePointerData(s_glPointSizePointerData); + set_glWeightPointerData(s_glWeightPointerData); + set_glMatrixIndexPointerData(s_glMatrixIndexPointerData); + + set_glDrawElementsOffset(s_glDrawElementsOffset); + set_glDrawElementsData(s_glDrawElementsData); + set_glFinishRoundTrip(s_glFinishRoundTrip); + + return 0; +} + +int GLDecoder::s_glFinishRoundTrip(void *self) +{ + GLDecoder *ctx = (GLDecoder *)self; + ctx->glFinish(); + return 0; +} + +void GLDecoder::s_glVertexPointerOffset(void *self, GLint size, GLenum type, GLsizei stride, GLuint offset) +{ + GLDecoder *ctx = (GLDecoder *)self; + ctx->glVertexPointer(size, type, stride, (void *)offset); +} + +void GLDecoder::s_glColorPointerOffset(void *self, GLint size, GLenum type, GLsizei stride, GLuint offset) +{ + GLDecoder *ctx = (GLDecoder *)self; + ctx->glColorPointer(size, type, stride, (void *)offset); +} + +void GLDecoder::s_glTexCoordPointerOffset(void *self, GLint size, GLenum type, GLsizei stride, GLuint offset) +{ + GLDecoder *ctx = (GLDecoder *)self; + ctx->glTexCoordPointer(size, type, stride, (void *) offset); +} + +void GLDecoder::s_glNormalPointerOffset(void *self, GLenum type, GLsizei stride, GLuint offset) +{ + GLDecoder *ctx = (GLDecoder *)self; + ctx->glNormalPointer(type, stride, (void *)offset); +} + +void GLDecoder::s_glPointSizePointerOffset(void *self, GLenum type, GLsizei stride, GLuint offset) +{ + GLDecoder *ctx = (GLDecoder *)self; + ctx->glPointSizePointerOES(type, stride, (void *)offset); +} + +void GLDecoder::s_glWeightPointerOffset(void * self, GLint size, GLenum type, GLsizei stride, GLuint offset) +{ + GLDecoder *ctx = (GLDecoder *)self; + ctx->glWeightPointerOES(size, type, stride, (void*)offset); +} + +void GLDecoder::s_glMatrixIndexPointerOffset(void * self, GLint size, GLenum type, GLsizei stride, GLuint offset) +{ + GLDecoder *ctx = (GLDecoder *)self; + ctx->glMatrixIndexPointerOES(size, type, stride, (void*)offset); +} + + + +#define STORE_POINTER_DATA_OR_ABORT(location) \ + if (ctx->m_contextData != NULL) { \ + ctx->m_contextData->storePointerData((location), data, datalen); \ + } else { \ + return; \ + } + +void GLDecoder::s_glVertexPointerData(void *self, GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen) +{ + GLDecoder *ctx = (GLDecoder *)self; + + STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::VERTEX_LOCATION); + + ctx->glVertexPointer(size, type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::VERTEX_LOCATION)); +} + +void GLDecoder::s_glColorPointerData(void *self, GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen) +{ + GLDecoder *ctx = (GLDecoder *)self; + + STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::COLOR_LOCATION); + + ctx->glColorPointer(size, type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::COLOR_LOCATION)); +} + +void GLDecoder::s_glTexCoordPointerData(void *self, GLint unit, GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen) +{ + GLDecoder *ctx = (GLDecoder *)self; + STORE_POINTER_DATA_OR_ABORT((GLDecoderContextData::PointerDataLocation) + (GLDecoderContextData::TEXCOORD0_LOCATION + unit)); + + ctx->glTexCoordPointer(size, type, 0, + ctx->m_contextData->pointerData((GLDecoderContextData::PointerDataLocation) + (GLDecoderContextData::TEXCOORD0_LOCATION + unit))); +} + +void GLDecoder::s_glNormalPointerData(void *self, GLenum type, GLsizei stride, void *data, GLuint datalen) +{ + GLDecoder *ctx = (GLDecoder *)self; + + STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::NORMAL_LOCATION); + + ctx->glNormalPointer(type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::NORMAL_LOCATION)); +} + +void GLDecoder::s_glPointSizePointerData(void *self, GLenum type, GLsizei stride, void *data, GLuint datalen) +{ + GLDecoder *ctx = (GLDecoder *)self; + + STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::POINTSIZE_LOCATION); + + ctx->glPointSizePointerOES(type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::POINTSIZE_LOCATION)); +} + +void GLDecoder::s_glWeightPointerData(void * self, GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen) +{ + GLDecoder *ctx = (GLDecoder *)self; + + STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::WEIGHT_LOCATION); + + ctx->glWeightPointerOES(size, type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::WEIGHT_LOCATION)); +} + +void GLDecoder::s_glMatrixIndexPointerData(void * self, GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen) +{ + GLDecoder *ctx = (GLDecoder *)self; + + STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::MATRIXINDEX_LOCATION); + + ctx->glMatrixIndexPointerOES(size, type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::MATRIXINDEX_LOCATION)); +} + +void GLDecoder::s_glDrawElementsOffset(void *self, GLenum mode, GLsizei count, GLenum type, GLuint offset) +{ + GLDecoder *ctx = (GLDecoder *)self; + ctx->glDrawElements(mode, count, type, (void *)offset); +} + +void GLDecoder::s_glDrawElementsData(void *self, GLenum mode, GLsizei count, GLenum type, void * data, GLuint datalen) +{ + GLDecoder *ctx = (GLDecoder *)self; + ctx->glDrawElements(mode, count, type, data); +} + +void GLDecoder::s_glGetCompressedTextureFormats(void *self, GLint count, GLint *data) +{ + GLDecoder *ctx = (GLDecoder *) self; + ctx->glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, data); +} + +void *GLDecoder::s_getProc(const char *name, void *userData) +{ + GLDecoder *ctx = (GLDecoder *)userData; + + if (ctx == NULL || ctx->m_glesDso == NULL) { + return NULL; + } + + void *func = NULL; +#ifdef USE_EGL_GETPROCADDRESS + func = (void *) eglGetProcAddress(name); +#endif + if (func == NULL) { + func = (void *)(ctx->m_glesDso->findSymbol(name)); + } + return func; +} diff --git a/emulator/opengl/host/libs/GLESv1_dec/GLDecoder.h b/emulator/opengl/host/libs/GLESv1_dec/GLDecoder.h new file mode 100644 index 0000000..14ca222 --- /dev/null +++ b/emulator/opengl/host/libs/GLESv1_dec/GLDecoder.h @@ -0,0 +1,71 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _GL_DECODER_H_ +#define _GL_DECODER_H_ + +#include "gl_dec.h" +#include "FixedBuffer.h" +#include "GLDecoderContextData.h" +#include <osDynLibrary.h> + +#define GLES_LIBNAME_VAR "ANDROID_GLESv1_LIB" +#define GLES_LIBNAME "libGLES_CM.so" + +class GLDecoder : public gl_decoder_context_t +{ +public: + typedef void *(*get_proc_func_t)(const char *name, void *userData); + + GLDecoder(); + ~GLDecoder(); + int initGL(get_proc_func_t getProcFunc = NULL, void *getProcFuncData = NULL); + void setContextData(GLDecoderContextData *contextData) { m_contextData = contextData; } + +private: + static void gl_APIENTRY s_glGetCompressedTextureFormats(void * self, GLint cont, GLint *data); + static void gl_APIENTRY s_glVertexPointerData(void *self, GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen); + static void gl_APIENTRY s_glVertexPointerOffset(void *self, GLint size, GLenum type, GLsizei stride, GLuint offset); + + static void gl_APIENTRY s_glColorPointerData(void *self, GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen); + static void gl_APIENTRY s_glColorPointerOffset(void *self, GLint size, GLenum type, GLsizei stride, GLuint offset); + + static void gl_APIENTRY s_glTexCoordPointerData(void *self, GLint unit, GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen); + static void gl_APIENTRY s_glTexCoordPointerOffset(void *self, GLint size, GLenum type, GLsizei stride, GLuint offset); + + static void gl_APIENTRY s_glNormalPointerData(void *self, GLenum type, GLsizei stride, void *data, GLuint datalen); + static void gl_APIENTRY s_glNormalPointerOffset(void *self, GLenum type, GLsizei stride, GLuint offset); + + static void gl_APIENTRY s_glPointSizePointerData(void *self, GLenum type, GLsizei stride, void *data, GLuint datalen); + static void gl_APIENTRY s_glPointSizePointerOffset(void *self, GLenum type, GLsizei stride, GLuint offset); + + static void gl_APIENTRY s_glDrawElementsOffset(void *self, GLenum mode, GLsizei count, GLenum type, GLuint offset); + static void gl_APIENTRY s_glDrawElementsData(void *self, GLenum mode, GLsizei count, GLenum type, void * data, GLuint datalen); + + static void gl_APIENTRY s_glWeightPointerData(void * self, GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen); + static void gl_APIENTRY s_glWeightPointerOffset(void * self, GLint size, GLenum type, GLsizei stride, GLuint offset); + + static void gl_APIENTRY s_glMatrixIndexPointerData(void * self, GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen); + static void gl_APIENTRY s_glMatrixIndexPointerOffset(void * self, GLint size, GLenum type, GLsizei stride, GLuint offset); + + static int gl_APIENTRY s_glFinishRoundTrip(void *self); + + static void * s_getProc(const char *name, void *userData); + + GLDecoderContextData *m_contextData; + osUtils::dynLibrary* m_glesDso; +}; + +#endif diff --git a/emulator/opengl/host/libs/GLESv2_dec/Android.mk b/emulator/opengl/host/libs/GLESv2_dec/Android.mk new file mode 100644 index 0000000..f9a83ae --- /dev/null +++ b/emulator/opengl/host/libs/GLESv2_dec/Android.mk @@ -0,0 +1,38 @@ +LOCAL_PATH := $(call my-dir) + +host_common_debug_CFLAGS := + +#For gl debbuging +#host_common_debug_CFLAGS += -DCHECK_GL_ERROR +#host_common_debug_CFLAGS += -DDEBUG_PRINTOUT + + +### host library ########################################## +$(call emugl-begin-host-static-library,libGLESv2_dec) +$(call emugl-import, libOpenglCodecCommon libOpenglOsUtils) +$(call emugl-gen-decoder,$(EMUGL_PATH)/system/GLESv2_enc,gl2) + +# For gl2_types.h ! +$(call emugl-export,C_INCLUDES,$(EMUGL_PATH)/system/GLESv2_enc) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) + +$(call emugl-export,CFLAGS,$(host_common_debug_CFLAGS)) + +LOCAL_SRC_FILES := GL2Decoder.cpp + +$(call emugl-end-module) + +### host library, 64-bit #################################### +$(call emugl-begin-host-static-library,lib64GLESv2_dec) +$(call emugl-import, lib64OpenglCodecCommon lib64OpenglOsUtils) +$(call emugl-gen-decoder,$(EMUGL_PATH)/system/GLESv2_enc,gl2) + +# For gl2_types.h ! +$(call emugl-export,C_INCLUDES,$(EMUGL_PATH)/system/GLESv2_enc) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) + +$(call emugl-export,CFLAGS,$(host_common_debug_CFLAGS) -m64) + +LOCAL_SRC_FILES := GL2Decoder.cpp + +$(call emugl-end-module) diff --git a/emulator/opengl/host/libs/GLESv2_dec/GL2Decoder.cpp b/emulator/opengl/host/libs/GLESv2_dec/GL2Decoder.cpp new file mode 100644 index 0000000..a777c50 --- /dev/null +++ b/emulator/opengl/host/libs/GLESv2_dec/GL2Decoder.cpp @@ -0,0 +1,139 @@ +/* +* Copyright 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "GL2Decoder.h" +#include <EGL/egl.h> +#include <GLES2/gl2.h> +#include <GLES2/gl2ext.h> + + +GL2Decoder::GL2Decoder() +{ + m_contextData = NULL; + m_GL2library = NULL; +} + +GL2Decoder::~GL2Decoder() +{ + delete m_GL2library; +} + +void *GL2Decoder::s_getProc(const char *name, void *userData) +{ + GL2Decoder *ctx = (GL2Decoder *) userData; + + if (ctx == NULL || ctx->m_GL2library == NULL) { + return NULL; + } + + void *func = NULL; +#ifdef USE_EGL_GETPROCADDRESS + func = (void *) eglGetProcAddress(name); +#endif + if (func == NULL) { + func = (void *) ctx->m_GL2library->findSymbol(name); + } + return func; +} + +int GL2Decoder::initGL(get_proc_func_t getProcFunc, void *getProcFuncData) +{ + if (getProcFunc == NULL) { + const char *libname = GLES2_LIBNAME; + if (getenv(GLES2_LIBNAME_VAR) != NULL) { + libname = getenv(GLES2_LIBNAME_VAR); + } + + m_GL2library = osUtils::dynLibrary::open(libname); + if (m_GL2library == NULL) { + fprintf(stderr, "%s: Couldn't find %s \n", __FUNCTION__, libname); + return -1; + } + this->initDispatchByName(s_getProc, this); + } else { + this->initDispatchByName(getProcFunc, getProcFuncData); + } + + set_glGetCompressedTextureFormats(s_glGetCompressedTextureFormats); + set_glVertexAttribPointerData(s_glVertexAttribPointerData); + set_glVertexAttribPointerOffset(s_glVertexAttribPointerOffset); + + set_glDrawElementsOffset(s_glDrawElementsOffset); + set_glDrawElementsData(s_glDrawElementsData); + set_glShaderString(s_glShaderString); + set_glFinishRoundTrip(s_glFinishRoundTrip); + return 0; + +} + +int GL2Decoder::s_glFinishRoundTrip(void *self) +{ + GL2Decoder *ctx = (GL2Decoder *)self; + ctx->glFinish(); + return 0; +} + +void GL2Decoder::s_glGetCompressedTextureFormats(void *self, int count, GLint *formats) +{ + GL2Decoder *ctx = (GL2Decoder *) self; + + int nFormats; + ctx->glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &nFormats); + if (nFormats > count) { + fprintf(stderr, "%s: GetCompressedTextureFormats: The requested number of formats does not match the number that is reported by OpenGL\n", __FUNCTION__); + } else { + ctx->glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, formats); + } +} + +void GL2Decoder::s_glVertexAttribPointerData(void *self, GLuint indx, GLint size, GLenum type, + GLboolean normalized, GLsizei stride, void * data, GLuint datalen) +{ + GL2Decoder *ctx = (GL2Decoder *) self; + if (ctx->m_contextData != NULL) { + ctx->m_contextData->storePointerData(indx, data, datalen); + // note - the stride of the data is always zero when it comes out of the codec. + // See gl2.attrib for the packing function call. + ctx->glVertexAttribPointer(indx, size, type, normalized, 0, ctx->m_contextData->pointerData(indx)); + } +} + +void GL2Decoder::s_glVertexAttribPointerOffset(void *self, GLuint indx, GLint size, GLenum type, + GLboolean normalized, GLsizei stride, GLuint data) +{ + GL2Decoder *ctx = (GL2Decoder *) self; + ctx->glVertexAttribPointer(indx, size, type, normalized, stride, (GLvoid *)data); +} + + +void GL2Decoder::s_glDrawElementsData(void *self, GLenum mode, GLsizei count, GLenum type, void * data, GLuint datalen) +{ + GL2Decoder *ctx = (GL2Decoder *)self; + ctx->glDrawElements(mode, count, type, data); +} + + +void GL2Decoder::s_glDrawElementsOffset(void *self, GLenum mode, GLsizei count, GLenum type, GLuint offset) +{ + GL2Decoder *ctx = (GL2Decoder *)self; + ctx->glDrawElements(mode, count, type, (void *)offset); +} + +void GL2Decoder::s_glShaderString(void *self, GLuint shader, const GLchar* string, GLsizei len) +{ + GL2Decoder *ctx = (GL2Decoder *)self; + ctx->glShaderSource(shader, 1, &string, NULL); +} diff --git a/emulator/opengl/host/libs/GLESv2_dec/GL2Decoder.h b/emulator/opengl/host/libs/GLESv2_dec/GL2Decoder.h new file mode 100644 index 0000000..dcf2c07 --- /dev/null +++ b/emulator/opengl/host/libs/GLESv2_dec/GL2Decoder.h @@ -0,0 +1,52 @@ +/* +* Copyright 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef _GL2_DECODER_H_ +#define _GL2_DECODER_H_ + +#define GLES2_LIBNAME_VAR "ANDROID_GLESv2_LIB" +#define GLES2_LIBNAME "libGLESv2.so" + +#include "gl2_dec.h" +#include "osDynLibrary.h" +#include "GLDecoderContextData.h" + + +class GL2Decoder : public gl2_decoder_context_t +{ +public: + typedef void *(*get_proc_func_t)(const char *name, void *userData); + GL2Decoder(); + ~GL2Decoder(); + int initGL(get_proc_func_t getProcFunc = NULL, void *getProcFuncData = NULL); + void setContextData(GLDecoderContextData *contextData) { m_contextData = contextData; } +private: + GLDecoderContextData *m_contextData; + osUtils::dynLibrary * m_GL2library; + + static void *s_getProc(const char *name, void *userData); + static void gl2_APIENTRY s_glGetCompressedTextureFormats(void *self, int count, GLint *formats); + static void gl2_APIENTRY s_glVertexAttribPointerData(void *self, GLuint indx, GLint size, GLenum type, + GLboolean normalized, GLsizei stride, void * data, GLuint datalen); + static void gl2_APIENTRY s_glVertexAttribPointerOffset(void *self, GLuint indx, GLint size, GLenum type, + GLboolean normalized, GLsizei stride, GLuint offset); + + static void gl2_APIENTRY s_glDrawElementsOffset(void *self, GLenum mode, GLsizei count, GLenum type, GLuint offset); + static void gl2_APIENTRY s_glDrawElementsData(void *self, GLenum mode, GLsizei count, GLenum type, void * data, GLuint datalen); + static void gl2_APIENTRY s_glShaderString(void *self, GLuint shader, const GLchar* string, GLsizei len); + static int gl2_APIENTRY s_glFinishRoundTrip(void *self); +}; +#endif diff --git a/emulator/opengl/host/libs/Translator/EGL/Android.mk b/emulator/opengl/host/libs/Translator/EGL/Android.mk new file mode 100644 index 0000000..f1a6d3a --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/Android.mk @@ -0,0 +1,57 @@ +LOCAL_PATH := $(call my-dir) + +host_OS_SRCS := +host_common_LDLIBS := + +ifeq ($(HOST_OS),linux) + host_OS_SRCS = EglX11Api.cpp + host_common_LDLIBS += -lX11 -lGL -ldl -lpthread +endif + +ifeq ($(HOST_OS),darwin) + host_OS_SRCS = EglMacApi.cpp \ + MacNative.m \ + MacPixelFormatsAttribs.m + + host_common_LDLIBS += -Wl,-framework,AppKit +endif + +ifeq ($(HOST_OS),windows) + host_OS_SRCS = EglWindowsApi.cpp + host_common_LDLIBS += -lopengl32 -lgdi32 +endif + +host_common_SRC_FILES := \ + $(host_OS_SRCS) \ + ThreadInfo.cpp \ + EglImp.cpp \ + EglConfig.cpp \ + EglContext.cpp \ + EglGlobalInfo.cpp \ + EglValidate.cpp \ + EglSurface.cpp \ + EglWindowSurface.cpp \ + EglPbufferSurface.cpp \ + EglPixmapSurface.cpp \ + EglThreadInfo.cpp \ + EglDisplay.cpp \ + ClientAPIExts.cpp + +### EGL host implementation ######################## +$(call emugl-begin-host-shared-library,libEGL_translator) +$(call emugl-import,libGLcommon) + +LOCAL_LDLIBS += $(host_common_LDLIBS) +LOCAL_SRC_FILES := $(host_common_SRC_FILES) + +$(call emugl-end-module) + +### EGL host implementation, 64-bit ######################## +$(call emugl-begin-host-shared-library,lib64EGL_translator) +$(call emugl-import,lib64GLcommon) + +LOCAL_LDLIBS += $(host_common_LDLIBS) -m64 +LOCAL_SRC_FILES := $(host_common_SRC_FILES) + +$(call emugl-end-module) + diff --git a/emulator/opengl/host/libs/Translator/EGL/ClientAPIExts.cpp b/emulator/opengl/host/libs/Translator/EGL/ClientAPIExts.cpp new file mode 100644 index 0000000..42d5764 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/ClientAPIExts.cpp @@ -0,0 +1,159 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "ClientAPIExts.h" +#include "EglGlobalInfo.h" +#include "GLcommon/GLutils.h" +#include "GLcommon/TranslatorIfaces.h" +#include "ThreadInfo.h" +#include <GLES/gl.h> +#include <GLES/glext.h> + +namespace ClientAPIExts +{ + +// +// define function pointer type for each extention function +// typename has the form __egl_{funcname}_t +// +#define FUNC_TYPE(fname) __egl_ ## fname ## _t +#define API_ENTRY(fname,params,args) \ + typedef void (GL_APIENTRY *FUNC_TYPE(fname)) params; + +#define API_ENTRY_RET(rtype,fname,params,args) \ + typedef rtype (GL_APIENTRY *FUNC_TYPE(fname)) params; + +#include "ClientAPIExts.in" +#undef API_ENTRY +#undef API_ENTRY_RET + +///// +// Define static table to store the function value for each +// client API. functions pointers will get initialized through +// ClientAPIExts::initClientFuncs function after each client API has been +// loaded. +///// +#define API_ENTRY(fname,params,args) \ + FUNC_TYPE(fname) fname; + +#define API_ENTRY_RET(rtype,fname,params,args) \ + API_ENTRY(fname,params,args) + +static struct _ext_table +{ +#include "ClientAPIExts.in" +} s_client_extensions[MAX_GLES_VERSION-1]; + +#undef API_ENTRY +#undef API_ENTRY_RET + +// +// This function initialized each entry in the s_client_extensions +// struct at the givven index using the givven client interface +// +void initClientFuncs(GLESiface *iface, int idx) +{ +#define API_ENTRY(fname,params,args) \ + s_client_extensions[idx].fname = \ + (FUNC_TYPE(fname))iface->getProcAddress(#fname); + +#define API_ENTRY_RET(rtype,fname,params,args) \ + API_ENTRY(fname,params,args) + + // + // reset all func pointers to NULL + // + memset(&s_client_extensions[idx], 0, sizeof(struct _ext_table)); + + // + // And now query the GLES library for each proc address + // +#include "ClientAPIExts.in" +#undef API_ENTRY +#undef API_ENTRY_RET +} + +// +// Define implementation for each extension function which checks +// the current context version and calls to the correct client API +// function. +// +#define API_ENTRY(fname,params,args) \ + static void _egl_ ## fname params \ + { \ + ThreadInfo* thread = getThreadInfo(); \ + if (!thread->eglContext.Ptr()) { \ + return; \ + } \ + int idx = (int)thread->eglContext->version() - 1; \ + if (!s_client_extensions[idx].fname) { \ + return; \ + } \ + (*s_client_extensions[idx].fname) args; \ + } + +#define API_ENTRY_RET(rtype,fname,params,args) \ + static rtype _egl_ ## fname params \ + { \ + ThreadInfo* thread = getThreadInfo(); \ + if (!thread->eglContext.Ptr()) { \ + return (rtype)0; \ + } \ + int idx = (int)thread->eglContext->version() - 1; \ + if (!s_client_extensions[idx].fname) { \ + return (rtype)0; \ + } \ + return (*s_client_extensions[idx].fname) args; \ + } + +#include "ClientAPIExts.in" +#undef API_ENTRY +#undef API_ENTRY_RET + +// +// Define a table to map function names to the local _egl_ version of +// the extension function, to be used in eglGetProcAddress. +// +#define API_ENTRY(fname,params,args) \ + { #fname, (__translatorMustCastToProperFunctionPointerType)_egl_ ## fname}, +#define API_ENTRY_RET(rtype,fname,params,args) \ + API_ENTRY(fname,params,args) + +static struct _client_ext_funcs { + const char *fname; + __translatorMustCastToProperFunctionPointerType proc; +} s_client_ext_funcs[] = { +#include "ClientAPIExts.in" +}; +static const int numExtFuncs = sizeof(s_client_ext_funcs) / + sizeof(s_client_ext_funcs[0]); + +#undef API_ENTRY +#undef API_ENTRY_RET + +// +// returns the __egl_ version of the givven extension function name. +// +__translatorMustCastToProperFunctionPointerType getProcAddress(const char *fname) +{ + for (int i=0; i<numExtFuncs; i++) { + if (!strcmp(fname, s_client_ext_funcs[i].fname)) { + return s_client_ext_funcs[i].proc; + } + } + return NULL; +} + +} // of namespace ClientAPIExts diff --git a/emulator/opengl/host/libs/Translator/EGL/ClientAPIExts.h b/emulator/opengl/host/libs/Translator/EGL/ClientAPIExts.h new file mode 100644 index 0000000..130b44a --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/ClientAPIExts.h @@ -0,0 +1,29 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _CLIENT_APIS_EXTS_H +#define _CLIENT_APIS_EXTS_H + +#include "GLcommon/TranslatorIfaces.h" + +namespace ClientAPIExts +{ + +void initClientFuncs(GLESiface *iface, int idx); +__translatorMustCastToProperFunctionPointerType getProcAddress(const char *fname); + +} // of namespace ClientAPIExts + +#endif diff --git a/emulator/opengl/host/libs/Translator/EGL/ClientAPIExts.in b/emulator/opengl/host/libs/Translator/EGL/ClientAPIExts.in new file mode 100644 index 0000000..c3162eb --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/ClientAPIExts.in @@ -0,0 +1,201 @@ +// +// Each extension function should have one of the following +// macro definitions: +// API_ENTRY(funcname, paramlist, arglist) +// -or- (in case funciton has return value) +// API_ENTRY_RET(return_type,funcname, paramlist, arglist) +// +API_ENTRY(glEGLImageTargetTexture2DOES, + (GLenum target, GLeglImageOES image), + (target, image)) + +API_ENTRY(glEGLImageTargetRenderbufferStorageOES, + (GLenum target, GLeglImageOES image), + (target, image)) + +API_ENTRY(glBlendEquationSeparateOES, + (GLenum modeRGB, GLenum modeAlpha), + (modeRGB, modeAlpha)) + +API_ENTRY(glBlendFuncSeparateOES, + (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha), + (srcRGB, dstRGB, srcAlpha, dstAlpha)) + +API_ENTRY(glBlendEquationOES, + (GLenum mode), + (mode)) + +API_ENTRY(glCurrentPaletteMatrixOES, + (GLuint matrixpaletteindex), + (matrixpaletteindex)) + +API_ENTRY(glLoadPaletteFromModelViewMatrixOES, + (void), + ()) + +API_ENTRY(glMatrixIndexPointerOES, + (GLint size, GLenum type, GLsizei stride, const GLvoid * pointer), + (size, type, stride, pointer)) + +API_ENTRY(glWeightPointerOES, + (GLint size, GLenum type, GLsizei stride, const GLvoid * pointer), + (size, type, stride, pointer)) + +API_ENTRY(glDepthRangefOES, + (GLclampf zNear, GLclampf zFar), + (zNear, zFar)) + +API_ENTRY(glFrustumfOES, + (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar), + (left, right, bottom, top, zNear, zFar)) + +API_ENTRY(glOrthofOES, + (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar), + (left, right, bottom, top, zNear, zFar)) + +API_ENTRY(glClipPlanefOES, + (GLenum plane, const GLfloat *equation), + (plane, equation)) + +API_ENTRY(glGetClipPlanefOES, + (GLenum pname, GLfloat * eqn), + (pname, eqn)) + +API_ENTRY(glClearDepthfOES, + (GLclampf depth), + (depth)) + +API_ENTRY(glPointSizePointerOES, + (GLenum type, GLsizei stride, const GLvoid *pointer), + (type, stride, pointer)) + +API_ENTRY(glTexGenfOES, + (GLenum coord, GLenum pname, GLfloat param), + (coord, pname, param)) + +API_ENTRY(glTexGenfvOES, + (GLenum coord, GLenum pname, const GLfloat *params), + (coord, pname, params)) + +API_ENTRY(glTexGeniOES, + (GLenum coord, GLenum pname, GLint param), + (coord, pname, param)) + +API_ENTRY(glTexGenivOES, + (GLenum coord, GLenum pname, const GLint *params), + (coord, pname, params)) + +API_ENTRY(glTexGenxOES, + (GLenum coord, GLenum pname, GLfixed param), + (coord, pname, param)) + +API_ENTRY(glTexGenxvOES, + (GLenum coord, GLenum pname, const GLfixed *params), + (coord, pname, params)) + +API_ENTRY(glGetTexGenfvOES, + (GLenum coord, GLenum pname, GLfloat *params), + (coord, pname, params)) + +API_ENTRY(glGetTexGenivOES, + (GLenum coord, GLenum pname, GLint *params), + (coord, pname, params)) + +API_ENTRY(glGetTexGenxvOES, + (GLenum coord, GLenum pname, GLfixed *params), + (coord, pname, params)) + +API_ENTRY_RET(GLboolean, + glIsRenderbufferOES, + (GLuint renderbuffer), + (renderbuffer)) + +API_ENTRY(glBindRenderbufferOES, + (GLenum target, GLuint renderbuffer), + (target, renderbuffer)) + +API_ENTRY(glDeleteRenderbuffersOES, + (GLsizei n, const GLuint* renderbuffers), + (n, renderbuffers)) + +API_ENTRY(glGenRenderbuffersOES, + (GLsizei n, GLuint* renderbuffers), + (n, renderbuffers)) + +API_ENTRY(glRenderbufferStorageOES, + (GLenum target, GLenum internalformat, GLsizei width, GLsizei height), + (target, internalformat, width, height)) + +API_ENTRY(glGetRenderbufferParameterivOES, + (GLenum target, GLenum pname, GLint* params), + (target, pname, params)) + +API_ENTRY_RET(GLboolean, + glIsFramebufferOES, + (GLuint framebuffer), + (framebuffer)) + +API_ENTRY(glBindFramebufferOES, + (GLenum target, GLuint framebuffer), + (target, framebuffer)) + +API_ENTRY(glDeleteFramebuffersOES, + (GLsizei n, const GLuint* framebuffers), + (n, framebuffers)) + +API_ENTRY(glGenFramebuffersOES, + (GLsizei n, GLuint* framebuffers), + (n, framebuffers)) + +API_ENTRY_RET(GLenum, + glCheckFramebufferStatusOES, + (GLenum target), + (target)) + +API_ENTRY(glFramebufferTexture2DOES, + (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level), + (target, attachment, textarget, texture, level)) + +API_ENTRY(glFramebufferRenderbufferOES, + (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer), + (target, attachment, renderbuffertarget, renderbuffer)) + +API_ENTRY(glGetFramebufferAttachmentParameterivOES, + (GLenum target, GLenum attachment, GLenum pname, GLint* params), + (target, attachment, pname, params)) + +API_ENTRY(glGenerateMipmapOES, + (GLenum target), + (target)) + +API_ENTRY(glDrawTexsOES, + (GLshort x, GLshort y, GLshort z, GLshort width, GLshort height), + (x, y, z, width, height)) + +API_ENTRY(glDrawTexiOES, + (GLint x, GLint y, GLint z, GLint width, GLint height), + (x, y, z, width, height)) + +API_ENTRY(glDrawTexfOES, + (GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height), + (x, y, z, width, height)) + +API_ENTRY(glDrawTexxOES, + (GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height), + (x, y, z, width, height)) + +API_ENTRY(glDrawTexsvOES, + (const GLshort *coords), + (coords)) + +API_ENTRY(glDrawTexivOES, + (const GLint *coords), + (coords)) + +API_ENTRY(glDrawTexfvOES, + (const GLfloat *coords), + (coords)) + +API_ENTRY(glDrawTexxvOES, + (const GLfixed *coords), + (coords)) diff --git a/emulator/opengl/host/libs/Translator/EGL/EglConfig.cpp b/emulator/opengl/host/libs/Translator/EGL/EglConfig.cpp new file mode 100644 index 0000000..66a691c --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglConfig.cpp @@ -0,0 +1,348 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "EglConfig.h" + +EglConfig::EglConfig(EGLint red_size, + EGLint green_size, + EGLint blue_size, + EGLint alpha_size, + EGLenum caveat, + EGLint config_id, + EGLint depth_size, + EGLint frame_buffer_level, + EGLint max_pbuffer_width, + EGLint max_pbuffer_height, + EGLint max_pbuffer_size, + EGLBoolean native_renderable, + EGLint renderable_type, + EGLint native_visual_id, + EGLint native_visual_type, + EGLint samples_per_pixel, + EGLint stencil_size, + EGLint surface_type, + EGLenum transparent_type, + EGLint trans_red_val, + EGLint trans_green_val, + EGLint trans_blue_val, + EGLNativePixelFormatType frmt): + + m_buffer_size(red_size + green_size + blue_size + alpha_size), + m_red_size(red_size), + m_green_size(green_size), + m_blue_size(blue_size), + m_alpha_size(alpha_size), + m_bind_to_tex_rgb(EGL_FALSE), //not supported for now + m_bind_to_tex_rgba(EGL_FALSE), //not supported for now + m_caveat(caveat), + m_config_id(config_id), + m_native_config_id(config_id), + m_frame_buffer_level(frame_buffer_level), + m_depth_size(depth_size), + m_max_pbuffer_width(max_pbuffer_width), + m_max_pbuffer_height(max_pbuffer_height), + m_max_pbuffer_size(max_pbuffer_size), + m_max_swap_interval(MAX_SWAP_INTERVAL), + m_min_swap_interval(MIN_SWAP_INTERVAL), + m_native_renderable(native_renderable), + m_renderable_type(renderable_type), + m_native_visual_id(native_visual_id), + m_native_visual_type(native_visual_type), + m_sample_buffers_num(samples_per_pixel > 0 ?1:0), + m_samples_per_pixel(samples_per_pixel), + m_stencil_size(stencil_size), + m_surface_type(surface_type), + m_transparent_type(transparent_type), + m_trans_red_val(trans_red_val), + m_trans_green_val(trans_green_val), + m_trans_blue_val(trans_blue_val), + m_conformant(((red_size + green_size + blue_size + alpha_size > 0) && + (caveat!=EGL_NON_CONFORMANT_CONFIG)) ? + m_renderable_type : 0), + m_nativeFormat(frmt) {}; + + + EglConfig::EglConfig(const EglConfig& conf):m_buffer_size(conf.m_buffer_size), + m_red_size(conf.m_red_size), + m_green_size(conf.m_green_size), + m_blue_size(conf.m_blue_size), + m_alpha_size(conf.m_alpha_size), + m_bind_to_tex_rgb(conf.m_bind_to_tex_rgb), + m_bind_to_tex_rgba(conf.m_bind_to_tex_rgba), + m_caveat(conf.m_caveat), + m_config_id(conf.m_config_id), + m_native_config_id(conf.m_native_config_id), + m_frame_buffer_level(conf.m_frame_buffer_level), + m_depth_size(conf.m_depth_size), + m_max_pbuffer_width(conf.m_max_pbuffer_width), + m_max_pbuffer_height(conf.m_max_pbuffer_height), + m_max_pbuffer_size(conf.m_max_pbuffer_size), + m_max_swap_interval(conf.m_max_swap_interval), + m_min_swap_interval(conf.m_min_swap_interval), + m_native_renderable(conf.m_native_renderable), + m_renderable_type(conf.m_renderable_type), + m_native_visual_id(conf.m_native_visual_id), + m_native_visual_type(conf.m_native_visual_type), + m_sample_buffers_num(conf.m_sample_buffers_num), + m_samples_per_pixel(conf.m_samples_per_pixel), + m_stencil_size(conf.m_stencil_size), + m_surface_type(conf.m_surface_type), + m_transparent_type(conf.m_transparent_type), + m_trans_red_val(conf.m_trans_red_val), + m_trans_green_val(conf.m_trans_green_val), + m_trans_blue_val(conf.m_trans_blue_val), + m_conformant(conf.m_conformant), + m_nativeFormat(conf.m_nativeFormat) {}; + + +EglConfig::EglConfig(const EglConfig& conf, + EGLint config_id, + EGLint red_size, + EGLint green_size, + EGLint blue_size, + EGLint alpha_size): + + m_buffer_size(red_size + green_size + blue_size + alpha_size), + m_red_size(red_size), + m_green_size(green_size), + m_blue_size(blue_size), + m_alpha_size(alpha_size), + m_bind_to_tex_rgb(conf.m_bind_to_tex_rgb), + m_bind_to_tex_rgba(conf.m_bind_to_tex_rgba), + m_caveat(conf.m_caveat), + m_config_id(config_id), + m_native_config_id(conf.m_native_config_id), + m_frame_buffer_level(conf.m_frame_buffer_level), + m_depth_size(conf.m_depth_size), + m_max_pbuffer_width(conf.m_max_pbuffer_width), + m_max_pbuffer_height(conf.m_max_pbuffer_height), + m_max_pbuffer_size(conf.m_max_pbuffer_size), + m_max_swap_interval(conf.m_max_swap_interval), + m_min_swap_interval(conf.m_min_swap_interval), + m_native_renderable(conf.m_native_renderable), + m_renderable_type(conf.m_renderable_type), + m_native_visual_id(conf.m_native_visual_id), + m_native_visual_type(conf.m_native_visual_type), + m_sample_buffers_num(conf.m_sample_buffers_num), + m_samples_per_pixel(conf.m_samples_per_pixel), + m_stencil_size(conf.m_stencil_size), + m_surface_type(conf.m_surface_type), + m_transparent_type(conf.m_transparent_type), + m_trans_red_val(conf.m_trans_red_val), + m_trans_green_val(conf.m_trans_green_val), + m_trans_blue_val(conf.m_trans_blue_val), + m_conformant(conf.m_conformant), + m_nativeFormat(conf.m_nativeFormat) {}; + + +bool EglConfig::getConfAttrib(EGLint attrib,EGLint* val) const { + switch(attrib) { + case EGL_BUFFER_SIZE: + *val = m_buffer_size; + break; + case EGL_RED_SIZE: + *val = m_red_size; + break; + case EGL_GREEN_SIZE: + *val = m_green_size; + break; + case EGL_BLUE_SIZE: + *val = m_blue_size; + break; + case EGL_ALPHA_SIZE: + *val = m_alpha_size; + break; + case EGL_BIND_TO_TEXTURE_RGB: + *val = m_bind_to_tex_rgb; + break; + case EGL_BIND_TO_TEXTURE_RGBA: + *val = m_bind_to_tex_rgba; + break; + case EGL_CONFIG_CAVEAT: + *val = m_caveat; + break; + case EGL_CONFIG_ID: + *val = m_config_id; + break; + case EGL_DEPTH_SIZE: + *val = m_depth_size; + break; + case EGL_LEVEL: + *val = m_frame_buffer_level; + break; + case EGL_MAX_PBUFFER_WIDTH: + *val = m_max_pbuffer_width; + break; + case EGL_MAX_PBUFFER_HEIGHT: + *val = m_max_pbuffer_height; + break; + case EGL_MAX_PBUFFER_PIXELS: + *val = m_max_pbuffer_size; + break; + case EGL_MAX_SWAP_INTERVAL: + *val = m_max_swap_interval; + break; + case EGL_MIN_SWAP_INTERVAL: + *val = m_min_swap_interval; + break; + case EGL_NATIVE_RENDERABLE: + *val = m_native_renderable; + break; + case EGL_NATIVE_VISUAL_ID: + *val = m_native_visual_id; + break; + case EGL_NATIVE_VISUAL_TYPE: + *val = m_native_visual_type; + break; + case EGL_RENDERABLE_TYPE: + *val = m_renderable_type; + break; + case EGL_SAMPLE_BUFFERS: + *val = m_sample_buffers_num; + break; + case EGL_SAMPLES: + *val = m_samples_per_pixel; + break; + case EGL_STENCIL_SIZE: + *val = m_stencil_size; + break; + case EGL_SURFACE_TYPE: + *val = m_surface_type; + break; + case EGL_TRANSPARENT_TYPE: + *val =m_transparent_type; + break; + case EGL_TRANSPARENT_RED_VALUE: + *val = m_trans_red_val; + break; + case EGL_TRANSPARENT_GREEN_VALUE: + *val = m_trans_green_val; + break; + case EGL_TRANSPARENT_BLUE_VALUE: + *val = m_trans_blue_val; + break; + case EGL_CONFORMANT: + *val = m_conformant; + break; + default: + return false; + } + return true; +} + +// checking compitabilty between *this configuration and another configuration +// the compitability is checked againsed red,green,blue,buffer stencil and depth sizes +bool EglConfig::compitableWith(const EglConfig& conf) const { + + if(m_buffer_size != conf.m_buffer_size) return false; + if(m_red_size != conf.m_red_size) return false; + if(m_green_size != conf.m_green_size) return false; + if(m_blue_size != conf.m_blue_size) return false; + if(m_depth_size != conf.m_depth_size) return false; + if(m_stencil_size != conf.m_stencil_size) return false; + + return true; +} + +//following the sorting EGLconfig as in spec +bool EglConfig::operator<(const EglConfig& conf) const { + //0 + if(m_conformant != conf.m_conformant) { + return m_conformant != 0; //We want the conformant ones first + } + //1 + if(m_caveat != conf.m_caveat) { + return m_caveat < conf.m_caveat; // EGL_NONE < EGL_SLOW_CONFIG < EGL_NON_CONFORMANT_CONFIG + } + //2 TODO: + + //3 + if(m_buffer_size != conf.m_buffer_size) { + return m_buffer_size < conf.m_buffer_size; + } + //4 + if(m_sample_buffers_num != conf.m_sample_buffers_num) { + return m_sample_buffers_num < conf.m_sample_buffers_num; + } + //5 + if(m_samples_per_pixel != conf.m_samples_per_pixel) { + return m_samples_per_pixel < conf.m_samples_per_pixel; + } + //6 + if(m_depth_size != conf.m_depth_size) { + return m_depth_size < conf.m_depth_size; + } + //7 + if(m_stencil_size != conf.m_stencil_size) { + return m_stencil_size < conf.m_stencil_size; + } + //8 implementation defined + if(m_native_visual_type != conf.m_native_visual_type) { + return m_native_visual_type < conf.m_native_visual_type; + } + //9 + return m_config_id < conf.m_config_id; +} + +bool EglConfig::operator>=(const EglConfig& conf) const { + return !((*this) < conf); +} +#define CHECK_PROP(dummy,prop_name,op) \ + if((dummy.prop_name != EGL_DONT_CARE) && (dummy.prop_name op prop_name)) return false; +#define CHECK_PROP_CAST(dummy,prop_name,op) \ + if((((EGLint)dummy.prop_name) != EGL_DONT_CARE) && (dummy.prop_name op prop_name)) return false; +//checking if config stands for all the selection crateria of dummy as defined by EGL spec +bool EglConfig::choosen(const EglConfig& dummy) { + + //atleast + CHECK_PROP(dummy,m_buffer_size,>); + CHECK_PROP(dummy,m_red_size,>); + CHECK_PROP(dummy,m_green_size,>); + CHECK_PROP(dummy,m_blue_size,>); + CHECK_PROP(dummy,m_alpha_size,>); + CHECK_PROP(dummy,m_depth_size,>); + CHECK_PROP(dummy,m_stencil_size,>); + CHECK_PROP(dummy,m_sample_buffers_num,>); + CHECK_PROP(dummy,m_samples_per_pixel,>); + + //exact + CHECK_PROP(dummy,m_frame_buffer_level,!=); + CHECK_PROP(dummy,m_config_id,!=); + CHECK_PROP(dummy,m_native_visual_type,!=); + CHECK_PROP(dummy,m_max_swap_interval ,!=); + CHECK_PROP(dummy,m_min_swap_interval ,!=); + CHECK_PROP(dummy,m_trans_red_val ,!=); + CHECK_PROP(dummy,m_trans_green_val ,!=); + CHECK_PROP(dummy,m_trans_blue_val ,!=); + //exact - when cast to EGLint is needed when comparing to EGL_DONT_CARE + CHECK_PROP_CAST(dummy,m_bind_to_tex_rgb ,!=); + CHECK_PROP_CAST(dummy,m_bind_to_tex_rgba,!=); + CHECK_PROP_CAST(dummy,m_caveat,!=); + CHECK_PROP_CAST(dummy,m_native_renderable ,!=); + CHECK_PROP_CAST(dummy,m_transparent_type ,!=); + + //mask + if(dummy.m_surface_type != EGL_DONT_CARE && + ((dummy.m_surface_type & m_surface_type) != dummy.m_surface_type)) return false; + + if(dummy.m_conformant != (EGLenum)EGL_DONT_CARE && + ((dummy.m_conformant & m_conformant) != dummy.m_conformant)) return false; + + if(dummy.m_renderable_type != EGL_DONT_CARE && + ((dummy.m_renderable_type & m_renderable_type) != dummy.m_renderable_type)) return false; + + //passed all checks + return true; +} diff --git a/emulator/opengl/host/libs/Translator/EGL/EglConfig.h b/emulator/opengl/host/libs/Translator/EGL/EglConfig.h new file mode 100644 index 0000000..3d733f9 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglConfig.h @@ -0,0 +1,107 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef EGL_CONFIG_H +#define EGL_CONFIG_H + +#include<EGL/egl.h> +#include<EGL/eglinternalplatform.h> + +#define MIN_SWAP_INTERVAL 1 +#define MAX_SWAP_INTERVAL 10 + + +class EglConfig { +public: + bool getConfAttrib(EGLint attrib,EGLint* val) const; + bool operator<(const EglConfig& conf) const; + bool operator>=(const EglConfig& conf) const; + bool compitableWith(const EglConfig& conf) const; //compitability + bool choosen(const EglConfig& dummy); + EGLint surfaceType(){ return m_surface_type;}; + EGLint id(){return m_config_id;}; + EGLint nativeId(){return m_native_config_id;}; + EGLNativePixelFormatType nativeConfig(){ return m_nativeFormat;} + + EglConfig(EGLint red_size, + EGLint green_size, + EGLint blue_size, + EGLint alpha_size, + EGLenum caveat, + EGLint config_id, + EGLint depth_size, + EGLint frame_buffer_level, + EGLint max_pbuffer_width, + EGLint max_pbuffer_height, + EGLint max_pbuffer_size, + EGLBoolean native_renderable, + EGLint renderable_type, + EGLint native_visual_id, + EGLint native_visual_type, + EGLint samples_per_pixel, + EGLint stencil_size, + EGLint surface_type, + EGLenum transparent_type, + EGLint trans_red_val, + EGLint trans_green_val, + EGLint trans_blue_val, + EGLNativePixelFormatType frmt); + + EglConfig(const EglConfig& conf); + + EglConfig(const EglConfig& conf, + EGLint config_id, + EGLint red_size, + EGLint green_size, + EGLint blue_size, + EGLint alpha_size); + +private: + + const EGLint m_buffer_size; + const EGLint m_red_size; + const EGLint m_green_size; + const EGLint m_blue_size; + const EGLint m_alpha_size; + const EGLBoolean m_bind_to_tex_rgb; + const EGLBoolean m_bind_to_tex_rgba; + const EGLenum m_caveat; + const EGLint m_config_id; + const EGLint m_native_config_id; + const EGLint m_frame_buffer_level; + const EGLint m_depth_size; + const EGLint m_max_pbuffer_width; + const EGLint m_max_pbuffer_height; + const EGLint m_max_pbuffer_size; + const EGLint m_max_swap_interval; + const EGLint m_min_swap_interval; + const EGLBoolean m_native_renderable; + const EGLint m_renderable_type; + const EGLint m_native_visual_id; + const EGLint m_native_visual_type; + const EGLint m_sample_buffers_num; + const EGLint m_samples_per_pixel; + const EGLint m_stencil_size; + const EGLint m_surface_type; + const EGLenum m_transparent_type; + const EGLint m_trans_red_val; + const EGLint m_trans_green_val; + const EGLint m_trans_blue_val; + const EGLenum m_conformant; + + const EGLNativePixelFormatType m_nativeFormat; +}; + +#endif diff --git a/emulator/opengl/host/libs/Translator/EGL/EglContext.cpp b/emulator/opengl/host/libs/Translator/EGL/EglContext.cpp new file mode 100644 index 0000000..bc33f1f --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglContext.cpp @@ -0,0 +1,93 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "EglContext.h" +#include "EglDisplay.h" +#include "EglGlobalInfo.h" +#include "EglOsApi.h" + +unsigned int EglContext::s_nextContextHndl = 0; + +extern EglGlobalInfo* g_eglInfo; // defined in EglImp.cpp + +bool EglContext::usingSurface(SurfacePtr surface) { + return surface.Ptr() == m_read.Ptr() || surface.Ptr() == m_draw.Ptr(); +} + +EglContext::EglContext(EglDisplay *dpy, EGLNativeContextType context,ContextPtr shared_context, + EglConfig* config,GLEScontext* glesCtx,GLESVersion ver,ObjectNameManager* mngr): +m_dpy(dpy), +m_native(context), +m_config(config), +m_glesContext(glesCtx), +m_read(NULL), +m_draw(NULL), +m_version(ver), +m_mngr(mngr) +{ + m_shareGroup = shared_context.Ptr()? + mngr->attachShareGroup(context,shared_context->nativeType()): + mngr->createShareGroup(context); + m_hndl = ++s_nextContextHndl; +} + +EglContext::~EglContext() +{ + + // + // remove the context in the underlying OS layer + // + EglOS::destroyContext(m_dpy->nativeType(),m_native); + + // + // call the client-api to remove the GLES context + // + g_eglInfo->getIface(version())->deleteGLESContext(m_glesContext); + + if (m_mngr) + { + m_mngr->deleteShareGroup(m_native); + } +} + +void EglContext::setSurfaces(SurfacePtr read,SurfacePtr draw) +{ + m_read = read; + m_draw = draw; +} + +bool EglContext::getAttrib(EGLint attrib,EGLint* value) { + switch(attrib) { + case EGL_CONFIG_ID: + *value = m_config->id(); + break; + default: + return false; + } + return true; +} + +bool EglContext::attachImage(unsigned int imageId,ImagePtr img){ + if(m_attachedImages.find(imageId) == m_attachedImages.end()){ + m_attachedImages[imageId] = img; + return true; + } + return false; +} + +void EglContext::detachImage(unsigned int imageId){ + m_attachedImages.erase(imageId); +} + diff --git a/emulator/opengl/host/libs/Translator/EGL/EglContext.h b/emulator/opengl/host/libs/Translator/EGL/EglContext.h new file mode 100644 index 0000000..e4917c6 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglContext.h @@ -0,0 +1,73 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef EGL_CONTEXT_H +#define EGL_CONTEXT_H + +#include <map> +#include <EGL/egl.h> +#include <GLcommon/GLutils.h> +#include <GLcommon/SmartPtr.h> +#include <GLcommon/TranslatorIfaces.h> +#include <GLcommon/objectNameManager.h> + + +#include "EglConfig.h" +#include "EglSurface.h" + + + +class EglContext; +typedef SmartPtr<EglContext> ContextPtr; + +class EglDisplay; + +class EglContext { + +public: + + EglContext(EglDisplay *dpy, EGLNativeContextType context,ContextPtr shared_context,EglConfig* config,GLEScontext* glesCtx,GLESVersion ver,ObjectNameManager* mngr); + bool usingSurface(SurfacePtr surface); + EGLNativeContextType nativeType(){return m_native;}; + bool getAttrib(EGLint attrib,EGLint* value); + SurfacePtr read(){ return m_read;}; + SurfacePtr draw(){ return m_draw;}; + ShareGroupPtr getShareGroup(){return m_shareGroup;} + EglConfig* getConfig(){ return m_config;}; + GLESVersion version(){return m_version;}; + GLEScontext* getGlesContext(){return m_glesContext;} + void setSurfaces(SurfacePtr read,SurfacePtr draw); + unsigned int getHndl(){return m_hndl;} + bool attachImage(unsigned int imageId,ImagePtr img); + void detachImage(unsigned int imageId); + + ~EglContext(); + +private: + static unsigned int s_nextContextHndl; + EglDisplay *m_dpy; + EGLNativeContextType m_native; + EglConfig* m_config; + GLEScontext* m_glesContext; + ShareGroupPtr m_shareGroup; + SurfacePtr m_read; + SurfacePtr m_draw; + GLESVersion m_version; + ObjectNameManager *m_mngr; + unsigned int m_hndl; + ImagesHndlMap m_attachedImages; +}; + +#endif diff --git a/emulator/opengl/host/libs/Translator/EGL/EglDisplay.cpp b/emulator/opengl/host/libs/Translator/EGL/EglDisplay.cpp new file mode 100644 index 0000000..99f9d8b --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglDisplay.cpp @@ -0,0 +1,344 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "EglDisplay.h" +#include "EglOsApi.h" +#include <GLcommon/GLutils.h> +#include <utils/threads.h> + +EglDisplay::EglDisplay(EGLNativeInternalDisplayType dpy,bool isDefault) : + m_dpy(dpy), + m_initialized(false), + m_configInitialized(false), + m_isDefault(isDefault), + m_nextEglImageId(0), + m_globalSharedContext(NULL) +{ + m_manager[GLES_1_1] = new ObjectNameManager(&m_globalNameSpace); + m_manager[GLES_2_0] = new ObjectNameManager(&m_globalNameSpace); +}; + +EglDisplay::~EglDisplay() { + android::Mutex::Autolock mutex(m_lock); + + // + // Destroy the global context if one was created. + // (should be true for windows platform only) + // + if (m_globalSharedContext != NULL) { + EglOS::destroyContext( m_dpy, m_globalSharedContext); + } + + if(m_isDefault) { + EglOS::releaseDisplay(m_dpy); + } + + + for(ConfigsList::iterator it = m_configs.begin(); it != m_configs.end(); it++) { + EglConfig* pConfig = *it; + if(pConfig) delete pConfig; + } + + delete m_manager[GLES_1_1]; + delete m_manager[GLES_2_0]; + EglOS::deleteDisplay(m_dpy); +} + +EGLNativeInternalDisplayType EglDisplay::nativeType(){return m_dpy;} + +void EglDisplay::initialize(int renderableType) { + android::Mutex::Autolock mutex(m_lock); + m_initialized = true; + initConfigurations(renderableType); + m_configInitialized = true; +} + +bool EglDisplay::isInitialize() { return m_initialized;} + +void EglDisplay::terminate(){ + android::Mutex::Autolock mutex(m_lock); + m_contexts.clear(); + m_surfaces.clear(); + m_initialized = false; +} + +static bool compareEglConfigsPtrs(EglConfig* first,EglConfig* second) { + return *first < *second ; +} + +void EglDisplay::addMissingConfigs(void) +{ + m_configs.sort(compareEglConfigsPtrs); + + EGLConfig match; + EGLNativePixelFormatType tmpfrmt = PIXEL_FORMAT_INITIALIZER; + EglConfig dummy(5, 6, 5, 0, // RGB_565 + EGL_DONT_CARE,EGL_DONT_CARE, + 16, // Depth + EGL_DONT_CARE,EGL_DONT_CARE,EGL_DONT_CARE,EGL_DONT_CARE,EGL_DONT_CARE,EGL_DONT_CARE,EGL_DONT_CARE,EGL_DONT_CARE,EGL_DONT_CARE, + EGL_DONT_CARE, EGL_DONT_CARE,EGL_DONT_CARE,EGL_DONT_CARE,EGL_DONT_CARE,EGL_DONT_CARE,tmpfrmt); + + if(!doChooseConfigs(dummy, &match, 1)) + { + return; + } + + const EglConfig* config = (EglConfig*)match; + + int bSize; + config->getConfAttrib(EGL_BUFFER_SIZE,&bSize); + + if(bSize == 16) + { + return; + } + + int max_config_id = 0; + + for(ConfigsList::iterator it = m_configs.begin(); it != m_configs.end() ;it++) { + EGLint id; + (*it)->getConfAttrib(EGL_CONFIG_ID, &id); + if(id > max_config_id) + max_config_id = id; + } + + EglConfig* newConfig = new EglConfig(*config,max_config_id+1,5,6,5,0); + + m_configs.push_back(newConfig); +} + +void EglDisplay::initConfigurations(int renderableType) { + if(m_configInitialized) return; + EglOS::queryConfigs(m_dpy,renderableType,m_configs); + + addMissingConfigs(); + m_configs.sort(compareEglConfigsPtrs); +} + +EglConfig* EglDisplay::getConfig(EGLConfig conf) { + android::Mutex::Autolock mutex(m_lock); + + for(ConfigsList::iterator it = m_configs.begin(); it != m_configs.end() ;it++) { + if(static_cast<EGLConfig>(*it) == conf) { + return (*it); + + } + } + return NULL; +} + +SurfacePtr EglDisplay::getSurface(EGLSurface surface) { + android::Mutex::Autolock mutex(m_lock); + /* surface is "key" in map<unsigned int, SurfacePtr>. */ + unsigned int hndl = ToTargetCompatibleHandle((uintptr_t)surface); + SurfacesHndlMap::iterator it = m_surfaces.find(hndl); + return it != m_surfaces.end() ? + (*it).second : + SurfacePtr(NULL); +} + +ContextPtr EglDisplay::getContext(EGLContext ctx) { + android::Mutex::Autolock mutex(m_lock); + /* ctx is "key" in map<unsigned int, ContextPtr>. */ + unsigned int hndl = ToTargetCompatibleHandle((uintptr_t)ctx); + ContextsHndlMap::iterator it = m_contexts.find(hndl); + return it != m_contexts.end() ? + (*it).second : + ContextPtr(NULL); +} + +bool EglDisplay::removeSurface(EGLSurface s) { + android::Mutex::Autolock mutex(m_lock); + /* s is "key" in map<unsigned int, SurfacePtr>. */ + unsigned int hndl = ToTargetCompatibleHandle((uintptr_t)s); + SurfacesHndlMap::iterator it = m_surfaces.find(hndl); + if(it != m_surfaces.end()) { + m_surfaces.erase(it); + return true; + } + return false; +} + +bool EglDisplay::removeSurface(SurfacePtr s) { + android::Mutex::Autolock mutex(m_lock); + + SurfacesHndlMap::iterator it; + for(it = m_surfaces.begin(); it!= m_surfaces.end();it++) + { + if((*it).second.Ptr() == s.Ptr()) { + break; + } + } + if(it != m_surfaces.end()) { + m_surfaces.erase(it); + return true; + } + return false; +} + +bool EglDisplay::removeContext(EGLContext ctx) { + android::Mutex::Autolock mutex(m_lock); + /* ctx is "key" in map<unsigned int, ContextPtr>. */ + unsigned int hndl = ToTargetCompatibleHandle((uintptr_t)ctx); + ContextsHndlMap::iterator it = m_contexts.find(hndl); + if(it != m_contexts.end()) { + m_contexts.erase(it); + return true; + } + return false; +} + +bool EglDisplay::removeContext(ContextPtr ctx) { + android::Mutex::Autolock mutex(m_lock); + + ContextsHndlMap::iterator it; + for(it = m_contexts.begin(); it != m_contexts.end();it++) { + if((*it).second.Ptr() == ctx.Ptr()){ + break; + } + } + if(it != m_contexts.end()) { + m_contexts.erase(it); + return true; + } + return false; +} + +EglConfig* EglDisplay::getConfig(EGLint id) { + android::Mutex::Autolock mutex(m_lock); + + for(ConfigsList::iterator it = m_configs.begin(); it != m_configs.end() ;it++) { + if((*it)->id() == id) { + return (*it); + + } + } + return NULL; +} + +int EglDisplay::getConfigs(EGLConfig* configs,int config_size) { + android::Mutex::Autolock mutex(m_lock); + int i = 0; + for(ConfigsList::iterator it = m_configs.begin(); it != m_configs.end() && i < config_size ;i++,it++) { + configs[i] = static_cast<EGLConfig>(*it); + } + return i; +} + +int EglDisplay::chooseConfigs(const EglConfig& dummy,EGLConfig* configs,int config_size) { + android::Mutex::Autolock mutex(m_lock); + return doChooseConfigs(dummy, configs, config_size); +} + +int EglDisplay::doChooseConfigs(const EglConfig& dummy,EGLConfig* configs,int config_size) { + int added = 0; + for(ConfigsList::iterator it = m_configs.begin(); it != m_configs.end() && (added < config_size || !configs);it++) { + + if( (*it)->choosen(dummy)){ + if(configs) { + configs[added] = static_cast<EGLConfig>(*it); + } + added++; + } + } + //no need to sort since the configurations are saved already in sorted maner + return added; +} + +EGLSurface EglDisplay::addSurface(SurfacePtr s ) { + android::Mutex::Autolock mutex(m_lock); + unsigned int hndl = s.Ptr()->getHndl(); + EGLSurface ret =reinterpret_cast<EGLSurface> (hndl); + + if(m_surfaces.find(hndl) != m_surfaces.end()) { + return ret; + } + + m_surfaces[hndl] = s; + return ret; +} + +EGLContext EglDisplay::addContext(ContextPtr ctx ) { + android::Mutex::Autolock mutex(m_lock); + + unsigned int hndl = ctx.Ptr()->getHndl(); + EGLContext ret = reinterpret_cast<EGLContext> (hndl); + + if(m_contexts.find(hndl) != m_contexts.end()) { + return ret; + } + m_contexts[hndl] = ctx; + return ret; +} + + +EGLImageKHR EglDisplay::addImageKHR(ImagePtr img) { + android::Mutex::Autolock mutex(m_lock); + do { ++m_nextEglImageId; } while(m_nextEglImageId == 0); + img->imageId = m_nextEglImageId; + m_eglImages[m_nextEglImageId] = img; + return reinterpret_cast<EGLImageKHR>(m_nextEglImageId); +} + +ImagePtr EglDisplay::getImage(EGLImageKHR img) { + android::Mutex::Autolock mutex(m_lock); + /* img is "key" in map<unsigned int, ImagePtr>. */ + unsigned int hndl = ToTargetCompatibleHandle((uintptr_t)img); + ImagesHndlMap::iterator i( m_eglImages.find(hndl) ); + return (i != m_eglImages.end()) ? (*i).second :ImagePtr(NULL); +} + +bool EglDisplay:: destroyImageKHR(EGLImageKHR img) { + android::Mutex::Autolock mutex(m_lock); + /* img is "key" in map<unsigned int, ImagePtr>. */ + unsigned int hndl = ToTargetCompatibleHandle((uintptr_t)img); + ImagesHndlMap::iterator i( m_eglImages.find(hndl) ); + if (i != m_eglImages.end()) + { + m_eglImages.erase(i); + return true; + } + return false; +} + +EGLNativeContextType EglDisplay::getGlobalSharedContext(){ + android::Mutex::Autolock mutex(m_lock); +#ifndef _WIN32 + // find an existing OpenGL context to share with, if exist + EGLNativeContextType ret = + (EGLNativeContextType)m_manager[GLES_1_1]->getGlobalContext(); + if (!ret) + ret = (EGLNativeContextType)m_manager[GLES_2_0]->getGlobalContext(); + return ret; +#else + if (!m_globalSharedContext) { + // + // On windows we create a dummy context to serve as the + // "global context" which all contexts share with. + // This is because on windows it is not possible to share + // with a context which is already current. This dummy context + // will never be current to any thread so it is safe to share with. + // Create that context using the first config + if (m_configs.size() < 1) { + // Should not happen! config list should be initialized at this point + return NULL; + } + EglConfig *cfg = (*m_configs.begin()); + m_globalSharedContext = EglOS::createContext(m_dpy,cfg,NULL); + } + + return m_globalSharedContext; +#endif +} diff --git a/emulator/opengl/host/libs/Translator/EGL/EglDisplay.h b/emulator/opengl/host/libs/Translator/EGL/EglDisplay.h new file mode 100644 index 0000000..587e92a --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglDisplay.h @@ -0,0 +1,92 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef EGL_DISPLAY_H +#define EGL_DISPLAY_H + +#include <list> +#include <map> +#include <EGL/egl.h> +#include <EGL/eglext.h> +#include <utils/threads.h> +#include <GLcommon/SmartPtr.h> + +#include "EglConfig.h" +#include "EglContext.h" +#include "EglSurface.h" +#include "EglWindowSurface.h" + + + +typedef std::list<EglConfig*> ConfigsList; +typedef std::map< unsigned int, ContextPtr> ContextsHndlMap; +typedef std::map< unsigned int, SurfacePtr> SurfacesHndlMap; + +class EglDisplay { +public: + + + EglDisplay(EGLNativeInternalDisplayType dpy,bool isDefault = true); + EGLNativeInternalDisplayType nativeType(); + int nConfigs(){ return m_configs.size();} + int getConfigs(EGLConfig* configs,int config_size); + int chooseConfigs(const EglConfig& dummy,EGLConfig* configs,int config_size); + EglConfig* getConfig(EGLConfig conf); + EglConfig* getConfig(EGLint id ); + + EGLSurface addSurface(SurfacePtr s ); + SurfacePtr getSurface(EGLSurface surface); + bool removeSurface(EGLSurface s); + bool removeSurface(SurfacePtr s); + + EGLContext addContext(ContextPtr ctx ); + ContextPtr getContext(EGLContext ctx); + bool removeContext(EGLContext ctx); + bool removeContext(ContextPtr ctx); + ObjectNameManager* getManager(GLESVersion ver){ return m_manager[ver];} + + ~EglDisplay(); + void initialize(int renderableType); + void terminate(); + bool isInitialize(); + + ImagePtr getImage(EGLImageKHR img); + EGLImageKHR addImageKHR(ImagePtr); + bool destroyImageKHR(EGLImageKHR img); + EGLNativeContextType getGlobalSharedContext(); + +private: + int doChooseConfigs(const EglConfig& dummy,EGLConfig* configs,int config_size); + void addMissingConfigs(void); + void initConfigurations(int renderableType); + + EGLNativeInternalDisplayType m_dpy; + bool m_initialized; + bool m_configInitialized; + bool m_isDefault; + ConfigsList m_configs; + ContextsHndlMap m_contexts; + SurfacesHndlMap m_surfaces; + GlobalNameSpace m_globalNameSpace; + ObjectNameManager *m_manager[MAX_GLES_VERSION]; + android::Mutex m_lock; + ImagesHndlMap m_eglImages; + unsigned int m_nextEglImageId; + EGLNativeContextType m_globalSharedContext; +}; + +#endif + + diff --git a/emulator/opengl/host/libs/Translator/EGL/EglGlobalInfo.cpp b/emulator/opengl/host/libs/Translator/EGL/EglGlobalInfo.cpp new file mode 100644 index 0000000..f39b36e --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglGlobalInfo.cpp @@ -0,0 +1,104 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "EglGlobalInfo.h" +#include "EglOsApi.h" +#include <string.h> +#include "ClientAPIExts.h" + +int EglGlobalInfo::m_refCount = 0; +EglGlobalInfo* EglGlobalInfo::m_singleton = NULL; + + +EglGlobalInfo::EglGlobalInfo(){ + m_default = EglOS::getDefaultDisplay(); +#ifdef _WIN32 + EglOS::initPtrToWglFunctions(); +#endif + memset(m_gles_ifaces,0,sizeof(m_gles_ifaces)); + memset(m_gles_extFuncs_inited,0,sizeof(m_gles_extFuncs_inited)); +} + +EglGlobalInfo* EglGlobalInfo::getInstance() { + if(!m_singleton) { + m_singleton = new EglGlobalInfo(); + m_refCount = 0; + } + m_refCount++; + return m_singleton; +} + +void EglGlobalInfo::delInstance() { + m_refCount--; + if(m_refCount <= 0 && m_singleton) { + delete m_singleton; + m_singleton = NULL; + } + +} + +EglDisplay* EglGlobalInfo::addDisplay(EGLNativeDisplayType dpy,EGLNativeInternalDisplayType idpy) { + //search if it is not already exists + android::Mutex::Autolock mutex(m_lock); + for(DisplaysMap::iterator it = m_displays.begin(); it != m_displays.end() ;it++) { + if((*it).second == dpy) return (*it).first; + } + + EglDisplay* p_dpy = new EglDisplay(idpy); + if(p_dpy) { + m_displays[p_dpy] = dpy; + return p_dpy; + } + return NULL; +} + +bool EglGlobalInfo::removeDisplay(EGLDisplay dpy) { + android::Mutex::Autolock mutex(m_lock); + for(DisplaysMap::iterator it = m_displays.begin(); it != m_displays.end() ;it++) { + if(static_cast<EGLDisplay>((*it).first) == dpy) { + delete (*it).first; + m_displays.erase(it); + return true; + } + } + return false; +} + +EglDisplay* EglGlobalInfo::getDisplay(EGLNativeDisplayType dpy) { + android::Mutex::Autolock mutex(m_lock); + for(DisplaysMap::iterator it = m_displays.begin(); it != m_displays.end() ;it++) { + if((*it).second == dpy) return (*it).first; + } + return NULL; +} + +EglDisplay* EglGlobalInfo::getDisplay(EGLDisplay dpy) { + android::Mutex::Autolock mutex(m_lock); + DisplaysMap::iterator it = m_displays.find(static_cast<EglDisplay*>(dpy)); + return (it != m_displays.end() ? (*it).first : NULL); +} + +EGLNativeInternalDisplayType EglGlobalInfo::generateInternalDisplay(EGLNativeDisplayType dpy){ + return EglOS::getInternalDisplay(dpy); +} + +void EglGlobalInfo::initClientExtFuncTable(GLESVersion ver) +{ + android::Mutex::Autolock mutex(m_lock); + if (!m_gles_extFuncs_inited[ver]) { + ClientAPIExts::initClientFuncs(m_gles_ifaces[ver], (int)ver - 1); + m_gles_extFuncs_inited[ver] = true; + } +} diff --git a/emulator/opengl/host/libs/Translator/EGL/EglGlobalInfo.h b/emulator/opengl/host/libs/Translator/EGL/EglGlobalInfo.h new file mode 100644 index 0000000..ec07ffe --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglGlobalInfo.h @@ -0,0 +1,64 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef EGL_GLOBAL_INFO +#define EGL_GLOBAL_INFO + +#include <list> +#include <EGL/egl.h> +#include <utils/threads.h> +#include <GLcommon/TranslatorIfaces.h> +#include "EglDisplay.h" +#include "EglConfig.h" +#include "EglContext.h" + +typedef std::map<EglDisplay*,EGLNativeDisplayType>DisplaysMap; + + +class EglGlobalInfo { + +public: + EglDisplay* addDisplay(EGLNativeDisplayType dpy,EGLNativeInternalDisplayType idpy); + EglDisplay* getDisplay(EGLNativeDisplayType dpy); + EglDisplay* getDisplay(EGLDisplay dpy); + bool removeDisplay(EGLDisplay dpy); + EGLNativeInternalDisplayType getDefaultNativeDisplay(){ return m_default;}; + EGLNativeInternalDisplayType generateInternalDisplay(EGLNativeDisplayType dpy); + + void setIface(GLESiface* iface,GLESVersion ver) { m_gles_ifaces[ver] = iface;}; + GLESiface* getIface(GLESVersion ver){ return m_gles_ifaces[ver];} + + int nDisplays() const { return m_displays.size();}; + + void initClientExtFuncTable(GLESVersion ver); + + static EglGlobalInfo* getInstance(); + static void delInstance(); + +private: + EglGlobalInfo(); + ~EglGlobalInfo(){}; + + static EglGlobalInfo* m_singleton; + static int m_refCount; + + DisplaysMap m_displays; + EGLNativeInternalDisplayType m_default; + GLESiface* m_gles_ifaces[MAX_GLES_VERSION]; + bool m_gles_extFuncs_inited[MAX_GLES_VERSION]; + android::Mutex m_lock; +}; + +#endif diff --git a/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp b/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp new file mode 100644 index 0000000..d03c9db --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp @@ -0,0 +1,1066 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifdef _WIN32 +#undef EGLAPI +#define EGLAPI __declspec(dllexport) +#endif + +#include <EGL/egl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <stdio.h> +#include "ThreadInfo.h" +#include <GLcommon/TranslatorIfaces.h> +#include <OpenglOsUtils/osDynLibrary.h> + +#include "EglWindowSurface.h" +#include "EglPbufferSurface.h" +#include "EglPixmapSurface.h" +#include "EglGlobalInfo.h" +#include "EglThreadInfo.h" +#include "EglValidate.h" +#include "EglDisplay.h" +#include "EglContext.h" +#include "EglConfig.h" +#include "EglOsApi.h" +#include "ClientAPIExts.h" + +#define MAJOR 1 +#define MINOR 4 + +//declarations + +EglImage *attachEGLImage(unsigned int imageId); +void detachEGLImage(unsigned int imageId); +GLEScontext* getGLESContext(); + +#define tls_thread EglThreadInfo::get() + +EglGlobalInfo* g_eglInfo = NULL; +android::Mutex s_eglLock; + +void initGlobalInfo() +{ + android::Mutex::Autolock mutex(s_eglLock); + if (!g_eglInfo) { + g_eglInfo = EglGlobalInfo::getInstance(); + } +} + +static EGLiface s_eglIface = { + getGLESContext : getGLESContext, + eglAttachEGLImage:attachEGLImage, + eglDetachEGLImage:detachEGLImage +}; + +/***************************************** supported extentions ***********************************************************************/ + +//extentions +#define EGL_EXTENTIONS 2 + +//decleration +EGLImageKHR eglCreateImageKHR(EGLDisplay display, EGLContext context, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list); +EGLBoolean eglDestroyImageKHR(EGLDisplay display, EGLImageKHR image); + +// extentions descriptors +static ExtentionDescriptor s_eglExtentions[] = { + {"eglCreateImageKHR" ,(__eglMustCastToProperFunctionPointerType)eglCreateImageKHR}, + {"eglDestroyImageKHR",(__eglMustCastToProperFunctionPointerType)eglDestroyImageKHR} + }; +static int s_eglExtentionsSize = sizeof(s_eglExtentions) / + sizeof(ExtentionDescriptor); + +/****************************************************************************************************************************************/ +//macros for accessing global egl info & tls objects + +#define CURRENT_THREAD() do {} while (0); + +#define RETURN_ERROR(ret,err) \ + CURRENT_THREAD() \ + if(tls_thread->getError() == EGL_SUCCESS) { \ + tls_thread->setError(err); \ + } \ + return ret; + +#define VALIDATE_DISPLAY_RETURN(EGLDisplay,ret) \ + EglDisplay* dpy = g_eglInfo->getDisplay(EGLDisplay); \ + if(!dpy){ \ + RETURN_ERROR(ret,EGL_BAD_DISPLAY); \ + } \ + if(!dpy->isInitialize()) { \ + RETURN_ERROR(ret,EGL_NOT_INITIALIZED); \ + } + +#define VALIDATE_CONFIG_RETURN(EGLConfig,ret) \ + EglConfig* cfg = dpy->getConfig(EGLConfig); \ + if(!cfg) { \ + RETURN_ERROR(ret,EGL_BAD_CONFIG); \ + } + +#define VALIDATE_SURFACE_RETURN(EGLSurface,ret,varName) \ + SurfacePtr varName = dpy->getSurface(EGLSurface); \ + if(!varName.Ptr()) { \ + RETURN_ERROR(ret,EGL_BAD_SURFACE); \ + } + +#define VALIDATE_CONTEXT_RETURN(EGLContext,ret) \ + ContextPtr ctx = dpy->getContext(EGLContext); \ + if(!ctx.Ptr()) { \ + RETURN_ERROR(ret,EGL_BAD_CONTEXT); \ + } + + +#define VALIDATE_DISPLAY(EGLDisplay) \ + VALIDATE_DISPLAY_RETURN(EGLDisplay,EGL_FALSE) + +#define VALIDATE_CONFIG(EGLConfig) \ + VALIDATE_CONFIG_RETURN(EGLConfig,EGL_FALSE) + +#define VALIDATE_SURFACE(EGLSurface,varName) \ + VALIDATE_SURFACE_RETURN(EGLSurface,EGL_FALSE,varName) + +#define VALIDATE_CONTEXT(EGLContext) \ + VALIDATE_CONTEXT_RETURN(EGLContext,EGL_FALSE) + + +GLEScontext* getGLESContext() +{ + ThreadInfo* thread = getThreadInfo(); + return thread->glesContext; +} + +EGLAPI EGLint EGLAPIENTRY eglGetError(void) { + CURRENT_THREAD(); + EGLint err = tls_thread->getError(); + tls_thread->setError(EGL_SUCCESS); + return err; +} + +EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id) { + EglDisplay* dpy = NULL; + EGLNativeInternalDisplayType internalDisplay = NULL; + + initGlobalInfo(); + + if ((dpy = g_eglInfo->getDisplay(display_id))) { + return dpy; + } else { + + if( display_id == EGL_DEFAULT_DISPLAY) { + internalDisplay = g_eglInfo->getDefaultNativeDisplay(); + } else { + internalDisplay = g_eglInfo->generateInternalDisplay(display_id); + } + + dpy = g_eglInfo->addDisplay(display_id,internalDisplay); + if(dpy) return dpy; + return EGL_NO_DISPLAY; + } +} + + +#define TRANSLATOR_GETIFACE_NAME "__translator_getIfaces" + +static __translator_getGLESIfaceFunc loadIfaces(const char* libName){ + osUtils::dynLibrary* libGLES = osUtils::dynLibrary::open(libName); + + if(!libGLES) return NULL; + __translator_getGLESIfaceFunc func = (__translator_getGLESIfaceFunc)libGLES->findSymbol(TRANSLATOR_GETIFACE_NAME); + if(!func) return NULL; + return func; +} + +#define LIB_GLES_CM_NAME EMUGL_LIBNAME("GLES_CM_translator") +#define LIB_GLES_V2_NAME EMUGL_LIBNAME("GLES_V2_translator") + +EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay display, EGLint *major, EGLint *minor) { + + initGlobalInfo(); + + EglDisplay* dpy = g_eglInfo->getDisplay(display); + if(!dpy) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_DISPLAY); + } + + if(major) *major = MAJOR; + if(minor) *minor = MINOR; + + __translator_getGLESIfaceFunc func = NULL; + int renderableType = EGL_OPENGL_ES_BIT; + + if(!g_eglInfo->getIface(GLES_1_1)) { + func = loadIfaces(LIB_GLES_CM_NAME); + if(func){ + g_eglInfo->setIface(func(&s_eglIface),GLES_1_1); + } else { + fprintf(stderr,"could not find ifaces for GLES CM 1.1\n"); + return EGL_FALSE; + } + } + if(!g_eglInfo->getIface(GLES_2_0)) { + func = loadIfaces(LIB_GLES_V2_NAME); + if(func){ + renderableType |= EGL_OPENGL_ES2_BIT; + g_eglInfo->setIface(func(&s_eglIface),GLES_2_0); + } else { + fprintf(stderr,"could not find ifaces for GLES 2.0\n"); + } + } + dpy->initialize(renderableType); + return EGL_TRUE; +} + +EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay display) { + VALIDATE_DISPLAY(display); + dpy->terminate(); + return EGL_TRUE; +} + +EGLAPI const char * EGLAPIENTRY eglQueryString(EGLDisplay display, EGLint name) { + VALIDATE_DISPLAY(display); + static const char* vendor = "Google"; + static const char* version = "1.4"; + static const char* extensions = "EGL_KHR_image_base EGL_KHR_gl_texture_2D_image"; + if(!EglValidate::stringName(name)) { + RETURN_ERROR(NULL,EGL_BAD_PARAMETER); + } + switch(name) { + case EGL_VENDOR: + return vendor; + case EGL_VERSION: + return version; + case EGL_EXTENSIONS: + return extensions; + } + return NULL; +} + +EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs(EGLDisplay display, EGLConfig *configs, + EGLint config_size, EGLint *num_config) { + VALIDATE_DISPLAY(display); + if(!num_config) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_PARAMETER); + } + + if(configs == NULL) { + *num_config = dpy->nConfigs(); + } else { + *num_config = dpy->getConfigs(configs,config_size); + } + + return EGL_TRUE; +} + +EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay display, const EGLint *attrib_list, + EGLConfig *configs, EGLint config_size, + EGLint *num_config) { + VALIDATE_DISPLAY(display); + if(!num_config) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_PARAMETER); + } + + //selection defaults + EGLint surface_type = EGL_WINDOW_BIT; + EGLint renderable_type = EGL_OPENGL_ES_BIT; + EGLBoolean bind_to_tex_rgb = EGL_DONT_CARE; + EGLBoolean bind_to_tex_rgba = EGL_DONT_CARE; + EGLenum caveat = EGL_DONT_CARE; + EGLint config_id = EGL_DONT_CARE; + EGLBoolean native_renderable = EGL_DONT_CARE; + EGLint native_visual_type = EGL_DONT_CARE; + EGLint max_swap_interval = EGL_DONT_CARE; + EGLint min_swap_interval = EGL_DONT_CARE; + EGLint trans_red_val = EGL_DONT_CARE; + EGLint trans_green_val = EGL_DONT_CARE; + EGLint trans_blue_val = EGL_DONT_CARE; + EGLenum transparent_type = EGL_NONE; + EGLint buffer_size = 0; + EGLint red_size = 0; + EGLint green_size = 0; + EGLint blue_size = 0; + EGLint alpha_size = 0; + EGLint depth_size = 0; + EGLint frame_buffer_level = 0; + EGLint sample_buffers_num = 0; + EGLint samples_per_pixel = 0; + EGLint stencil_size = 0; + + if(!EglValidate::noAttribs(attrib_list)) { //there are attribs + int i = 0 ; + bool hasConfigId = false; + while(attrib_list[i] != EGL_NONE && !hasConfigId) { + switch(attrib_list[i]) { + case EGL_MAX_PBUFFER_WIDTH: + case EGL_MAX_PBUFFER_HEIGHT: + case EGL_MAX_PBUFFER_PIXELS: + case EGL_NATIVE_VISUAL_ID: + break; //we dont care from those selection crateria + case EGL_LEVEL: + if(attrib_list[i+1] == EGL_DONT_CARE) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + frame_buffer_level = attrib_list[i+1]; + break; + case EGL_BUFFER_SIZE: + if(attrib_list[i+1] < 0) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + buffer_size = attrib_list[i+1]; + break; + case EGL_RED_SIZE: + if(attrib_list[i+1] < 0) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + red_size = attrib_list[i+1]; + break; + case EGL_GREEN_SIZE: + if(attrib_list[i+1] < 0) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + green_size = attrib_list[i+1]; + break; + case EGL_BLUE_SIZE: + if(attrib_list[i+1] < 0) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + blue_size = attrib_list[i+1]; + break; + case EGL_ALPHA_SIZE: + if(attrib_list[i+1] < 0) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + alpha_size = attrib_list[i+1]; + break; + case EGL_BIND_TO_TEXTURE_RGB: + bind_to_tex_rgb = attrib_list[i+1]; + break; + case EGL_BIND_TO_TEXTURE_RGBA: + bind_to_tex_rgba = attrib_list[i+1]; + break; + case EGL_CONFIG_CAVEAT: + if(attrib_list[i+1] != EGL_NONE && attrib_list[i+1] != EGL_SLOW_CONFIG && attrib_list[i+1] != EGL_NON_CONFORMANT_CONFIG) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + caveat = attrib_list[i+1]; + break; + case EGL_CONFIG_ID: + if(attrib_list[i+1] < 0) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + config_id = attrib_list[i+1]; + hasConfigId = true; + break; + case EGL_DEPTH_SIZE: + if(attrib_list[i+1] < 0) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + depth_size = attrib_list[i+1]; + break; + case EGL_MAX_SWAP_INTERVAL: + if(attrib_list[i+1] < 0) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + max_swap_interval = attrib_list[i+1]; + break; + case EGL_MIN_SWAP_INTERVAL: + if(attrib_list[i+1] < 0) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + min_swap_interval = attrib_list[i+1]; + break; + case EGL_NATIVE_RENDERABLE: + native_renderable = attrib_list[i+1]; + break; + case EGL_RENDERABLE_TYPE: + renderable_type = attrib_list[i+1]; + break; + case EGL_NATIVE_VISUAL_TYPE: + native_visual_type = attrib_list[i+1]; + break; + if(attrib_list[i+1] < 0 || attrib_list[i+1] > 1 ) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + case EGL_SAMPLE_BUFFERS: + sample_buffers_num = attrib_list[i+1]; + break; + if(attrib_list[i+1] < 0) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + case EGL_SAMPLES: + if(attrib_list[i+1] < 0) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + samples_per_pixel = attrib_list[i+1]; + break; + case EGL_STENCIL_SIZE: + if(attrib_list[i+1] < 0) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + stencil_size = attrib_list[i+1]; + break; + case EGL_SURFACE_TYPE: + surface_type = attrib_list[i+1]; + break; + case EGL_TRANSPARENT_TYPE: + if(attrib_list[i+1] != EGL_NONE && attrib_list[i+1] != EGL_TRANSPARENT_RGB ) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + transparent_type = attrib_list[i+1]; + break; + case EGL_TRANSPARENT_RED_VALUE: + trans_red_val = attrib_list[i+1]; + break; + case EGL_TRANSPARENT_GREEN_VALUE: + trans_green_val = attrib_list[i+1]; + break; + case EGL_TRANSPARENT_BLUE_VALUE: + trans_blue_val = attrib_list[i+1]; + break; + default: + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + i+=2; + } + if(hasConfigId) { + EglConfig* pConfig = dpy->getConfig(config_id); + if(pConfig) { + if(configs) { + configs[0] = static_cast<EGLConfig>(pConfig); + } + *num_config = 1; + return EGL_TRUE; + } else { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + } + } + EGLNativePixelFormatType tmpfrmt = PIXEL_FORMAT_INITIALIZER; + EglConfig dummy(red_size,green_size,blue_size,alpha_size,caveat,config_id,depth_size, + frame_buffer_level,0,0,0,native_renderable,renderable_type,0,native_visual_type, + samples_per_pixel,stencil_size,surface_type,transparent_type, + trans_red_val,trans_green_val,trans_blue_val,tmpfrmt); + + *num_config = dpy->chooseConfigs(dummy,configs,config_size); + + + return EGL_TRUE; +} + +EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay display, EGLConfig config, + EGLint attribute, EGLint *value) { + VALIDATE_DISPLAY(display); + VALIDATE_CONFIG(config); + if(!EglValidate::confAttrib(attribute)){ + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + return cfg->getConfAttrib(attribute,value)? EGL_TRUE:EGL_FALSE; +} + +EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay display, EGLConfig config, + EGLNativeWindowType win, + const EGLint *attrib_list) { + VALIDATE_DISPLAY_RETURN(display,EGL_NO_SURFACE); + VALIDATE_CONFIG_RETURN(config,EGL_NO_SURFACE); + + if(!(cfg->surfaceType() & EGL_WINDOW_BIT)) { + RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_MATCH); + } + if(!EglOS::validNativeWin(dpy->nativeType(),win)) { + RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_NATIVE_WINDOW); + } + if(!EglValidate::noAttribs(attrib_list)) { + RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_ATTRIBUTE); + } + if(EglWindowSurface::alreadyAssociatedWithConfig(win)) { + RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_ALLOC); + } + + unsigned int width,height; + if(!EglOS::checkWindowPixelFormatMatch(dpy->nativeType(),win,cfg,&width,&height)) { + RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_ALLOC); + } + SurfacePtr wSurface(new EglWindowSurface(dpy, win,cfg,width,height)); + if(!wSurface.Ptr()) { + RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_ALLOC); + } + return dpy->addSurface(wSurface); +} + +EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, + const EGLint *attrib_list) { + VALIDATE_DISPLAY_RETURN(display,EGL_NO_SURFACE); + VALIDATE_CONFIG_RETURN(config,EGL_NO_SURFACE); + if(!(cfg->surfaceType() & EGL_PBUFFER_BIT)) { + RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_MATCH); + } + + + SurfacePtr pbSurface(new EglPbufferSurface(dpy,cfg)); + if(!pbSurface.Ptr()) { + RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_ALLOC); + } + + if(!EglValidate::noAttribs(attrib_list)) { //there are attribs + int i = 0 ; + while(attrib_list[i] != EGL_NONE) { + if(!pbSurface->setAttrib(attrib_list[i],attrib_list[i+1])) { + RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_ATTRIBUTE); + } + i+=2; + } + } + + EGLint width,height,largest,texTarget,texFormat; + EglPbufferSurface* tmpPbSurfacePtr = static_cast<EglPbufferSurface*>(pbSurface.Ptr()); + tmpPbSurfacePtr->getDim(&width,&height,&largest); + tmpPbSurfacePtr->getTexInfo(&texTarget,&texFormat); + + if(!EglValidate::pbufferAttribs(width,height,texFormat == EGL_NO_TEXTURE,texTarget == EGL_NO_TEXTURE)) { + //TODO: RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_VALUE); dont have bad_value + RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_ATTRIBUTE); + } + + EGLNativeSurfaceType pb = EglOS::createPbufferSurface(dpy->nativeType(),cfg,tmpPbSurfacePtr); + if(!pb) { + //TODO: RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_VALUE); dont have bad value + RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_ATTRIBUTE); + } + + tmpPbSurfacePtr->setNativePbuffer(pb); + return dpy->addSurface(pbSurface); +} + +EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurface(EGLDisplay display, EGLConfig config, + EGLNativePixmapType pixmap, + const EGLint *attrib_list) { + VALIDATE_DISPLAY_RETURN(display,EGL_NO_SURFACE); + VALIDATE_CONFIG_RETURN(config,EGL_NO_SURFACE); + if(!(cfg->surfaceType() & EGL_PIXMAP_BIT)) { + RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_MATCH); + } + if(!EglValidate::noAttribs(attrib_list)) { + RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_ATTRIBUTE); + } + if(EglPixmapSurface::alreadyAssociatedWithConfig(pixmap)) { + RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_ALLOC); + } + + unsigned int width,height; + if(!EglOS::checkPixmapPixelFormatMatch(dpy->nativeType(),pixmap,cfg,&width,&height)) { + RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_ALLOC); + } + SurfacePtr pixSurface(new EglPixmapSurface(dpy, pixmap,cfg)); + if(!pixSurface.Ptr()) { + RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_ALLOC); + } + + return dpy->addSurface(pixSurface); +} + +EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay display, EGLSurface surface) { + VALIDATE_DISPLAY(display); + SurfacePtr srfc = dpy->getSurface(surface); + if(!srfc.Ptr()) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE); + } + + dpy->removeSurface(surface); + return EGL_TRUE; +} + +EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface(EGLDisplay display, EGLSurface surface, + EGLint attribute, EGLint *value) { + VALIDATE_DISPLAY(display); + VALIDATE_SURFACE(surface,srfc); + + if(!srfc->getAttrib(attribute,value)) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + return EGL_TRUE; +} + +EGLAPI EGLBoolean EGLAPIENTRY eglSurfaceAttrib(EGLDisplay display, EGLSurface surface, + EGLint attribute, EGLint value) { + VALIDATE_DISPLAY(display); + VALIDATE_SURFACE(surface,srfc); + if(!srfc->setAttrib(attribute,value)) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + return EGL_TRUE; +} + +EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay display, EGLConfig config, + EGLContext share_context, + const EGLint *attrib_list) { + VALIDATE_DISPLAY_RETURN(display,EGL_NO_CONTEXT); + VALIDATE_CONFIG_RETURN(config,EGL_NO_CONTEXT); + + GLESVersion version = GLES_1_1; + if(!EglValidate::noAttribs(attrib_list)) { + int i = 0; + while(attrib_list[i] != EGL_NONE) { + switch(attrib_list[i]) { + case EGL_CONTEXT_CLIENT_VERSION: + if(attrib_list[i+1] == 2) { + version = GLES_2_0; + } else { + version = GLES_1_1; + } + break; + default: + RETURN_ERROR(EGL_NO_CONTEXT,EGL_BAD_ATTRIBUTE); + } + i+=2; + } + } + GLESiface* iface = g_eglInfo->getIface(version); + GLEScontext* glesCtx = NULL; + if(iface) { + glesCtx = iface->createGLESContext(); + } else { // there is no interface for this gles version + RETURN_ERROR(EGL_NO_CONTEXT,EGL_BAD_ATTRIBUTE); + } + + ContextPtr sharedCtxPtr; + EGLNativeContextType nativeShared = NULL; + if(share_context != EGL_NO_CONTEXT) { + sharedCtxPtr = dpy->getContext(share_context); + if(!sharedCtxPtr.Ptr()) { + RETURN_ERROR(EGL_NO_CONTEXT,EGL_BAD_CONTEXT); + } + nativeShared = sharedCtxPtr->nativeType(); + } + + EGLNativeContextType globalSharedContext = dpy->getGlobalSharedContext(); + EGLNativeContextType nativeContext = EglOS::createContext(dpy->nativeType(),cfg,globalSharedContext); + + if(nativeContext) { + ContextPtr ctx(new EglContext(dpy, nativeContext,sharedCtxPtr,cfg,glesCtx,version,dpy->getManager(version))); + return dpy->addContext(ctx); + } else { + iface->deleteGLESContext(glesCtx); + } + +return EGL_NO_CONTEXT; +} + +EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay display, EGLContext context) { + VALIDATE_DISPLAY(display); + VALIDATE_CONTEXT(context); + + dpy->removeContext(context); + return EGL_TRUE; +} + +EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay display, EGLSurface draw, + EGLSurface read, EGLContext context) { + VALIDATE_DISPLAY(display); + + + bool releaseContext = EglValidate::releaseContext(context,read,draw); + if(!releaseContext && EglValidate::badContextMatch(context,read,draw)) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_MATCH); + } + + ThreadInfo* thread = getThreadInfo(); + ContextPtr prevCtx = thread->eglContext; + + if(releaseContext) { //releasing current context + if(prevCtx.Ptr()) { + g_eglInfo->getIface(prevCtx->version())->flush(); + if(!EglOS::makeCurrent(dpy->nativeType(),NULL,NULL,NULL)) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ACCESS); + } + thread->updateInfo(ContextPtr(NULL),dpy,NULL,ShareGroupPtr(NULL),dpy->getManager(prevCtx->version())); + } + } else { //assining new context + VALIDATE_CONTEXT(context); + VALIDATE_SURFACE(draw,newDrawSrfc); + VALIDATE_SURFACE(read,newReadSrfc); + + EglSurface* newDrawPtr = newDrawSrfc.Ptr(); + EglSurface* newReadPtr = newReadSrfc.Ptr(); + ContextPtr newCtx = ctx; + + if (newCtx.Ptr() && prevCtx.Ptr()) { + if (newCtx.Ptr() == prevCtx.Ptr()) { + if (newDrawPtr == prevCtx->draw().Ptr() && + newReadPtr == prevCtx->read().Ptr()) { + // nothing to do + return EGL_TRUE; + } + } + else { + // Make sure previous context is detached from surfaces + releaseContext = true; + } + } + + //surfaces compitability check + if(!((*ctx->getConfig()).compitableWith((*newDrawPtr->getConfig()))) || + !((*ctx->getConfig()).compitableWith((*newReadPtr->getConfig())))) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_MATCH); + } + + EGLNativeInternalDisplayType nativeDisplay = dpy->nativeType(); + EGLNativeSurfaceType nativeRead = newReadPtr->native(); + EGLNativeSurfaceType nativeDraw = newDrawPtr->native(); + //checking native window validity + if(newReadPtr->type() == EglSurface::WINDOW && !EglOS::validNativeWin(nativeDisplay,nativeRead)) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_WINDOW); + } + if(newDrawPtr->type() == EglSurface::WINDOW && !EglOS::validNativeWin(nativeDisplay,nativeDraw)) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_WINDOW); + } + + //checking native pixmap validity + if(newReadPtr->type() == EglSurface::PIXMAP && !EglOS::validNativePixmap(nativeDisplay,nativeRead)) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_PIXMAP); + } + if(newDrawPtr->type() == EglSurface::PIXMAP && !EglOS::validNativePixmap(nativeDisplay,nativeDraw)) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_PIXMAP); + } + if(prevCtx.Ptr()) { + g_eglInfo->getIface(prevCtx->version())->flush(); + } + if(!EglOS::makeCurrent(dpy->nativeType(),newReadPtr,newDrawPtr,newCtx->nativeType())) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_ACCESS); + } + //TODO: handle the following errors + // EGL_BAD_CURRENT_SURFACE , EGL_CONTEXT_LOST , EGL_BAD_ACCESS + + thread->updateInfo(newCtx,dpy,newCtx->getGlesContext(),newCtx->getShareGroup(),dpy->getManager(newCtx->version())); + newCtx->setSurfaces(newReadSrfc,newDrawSrfc); + g_eglInfo->getIface(newCtx->version())->initContext(newCtx->getGlesContext(),newCtx->getShareGroup()); + + // Initialize the GLES extension function table used in + // eglGetProcAddress for the context's GLES version if not + // yet initialized. We initialize it here to make sure we call the + // GLES getProcAddress after when a context is bound. + g_eglInfo->initClientExtFuncTable(newCtx->version()); + } + + // release previous context surface binding + if(prevCtx.Ptr() && releaseContext) { + prevCtx->setSurfaces(SurfacePtr(NULL),SurfacePtr(NULL)); + } + + return EGL_TRUE; +} + +EGLAPI EGLBoolean EGLAPIENTRY eglQueryContext(EGLDisplay display, EGLContext context, + EGLint attribute, EGLint *value) { + VALIDATE_DISPLAY(display); + VALIDATE_CONTEXT(context); + + if(!ctx->getAttrib(attribute,value)){ + RETURN_ERROR(EGL_FALSE,EGL_BAD_ATTRIBUTE); + } + return EGL_TRUE; +} + +EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay display, EGLSurface surface) { + VALIDATE_DISPLAY(display); + VALIDATE_SURFACE(surface,Srfc); + ThreadInfo* thread = getThreadInfo(); + ContextPtr currentCtx = thread->eglContext; + + + //if surface not window return + if(Srfc->type() != EglSurface::WINDOW){ + RETURN_ERROR(EGL_TRUE,EGL_SUCCESS); + } + + if(!currentCtx.Ptr() || !currentCtx->usingSurface(Srfc) || !EglOS::validNativeWin(dpy->nativeType(),Srfc.Ptr()->native())) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE); + } + + EglOS::swapBuffers(dpy->nativeType(),Srfc->native()); + return EGL_TRUE; +} + +EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay display, EGLint interval) { + VALIDATE_DISPLAY(display); + ThreadInfo* thread = getThreadInfo(); + ContextPtr currCtx = thread->eglContext; + if(currCtx.Ptr()) { + if(!currCtx->read().Ptr() || !currCtx->draw().Ptr() || currCtx->draw()->type()!=EglSurface::WINDOW) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_CURRENT_SURFACE); + } + EglOS::swapInterval(dpy->nativeType(),currCtx->draw()->native(),interval); + } else { + RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE); + } + return EGL_TRUE; +} + + +EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext(void) { + ThreadInfo* thread = getThreadInfo(); + EglDisplay* dpy = static_cast<EglDisplay*>(thread->eglDisplay); + ContextPtr ctx = thread->eglContext; + if(dpy && ctx.Ptr()){ + // This double check is required because a context might still be current after it is destroyed - in which case + // its handle should be invalid, that is EGL_NO_CONTEXT should be returned even though the context is current + EGLContext c = (EGLContext)ctx->getHndl(); + if(dpy->getContext(c).Ptr()) + { + return c; + } + } + return EGL_NO_CONTEXT; +} + +EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface(EGLint readdraw) { + if(!EglValidate::surfaceTarget(readdraw)) return EGL_NO_SURFACE; + + ThreadInfo* thread = getThreadInfo(); + EglDisplay* dpy = static_cast<EglDisplay*>(thread->eglDisplay); + ContextPtr ctx = thread->eglContext; + + if(dpy && ctx.Ptr()) { + SurfacePtr surface = readdraw == EGL_READ ? ctx->read() : ctx->draw(); + if(surface.Ptr()) + { + // This double check is required because a surface might still be + // current after it is destroyed - in which case its handle should + // be invalid, that is EGL_NO_SURFACE should be returned even + // though the surface is current. + EGLSurface s = (EGLSurface)surface->getHndl(); + surface = dpy->getSurface(s); + if(surface.Ptr()) + { + return s; + } + } + } + return EGL_NO_SURFACE; +} + +EGLAPI EGLDisplay EGLAPIENTRY eglGetCurrentDisplay(void) { + ThreadInfo* thread = getThreadInfo(); + return (thread->eglContext.Ptr()) ? thread->eglDisplay : EGL_NO_DISPLAY; +} + +EGLAPI EGLBoolean EGLAPIENTRY eglWaitGL(void) { + EGLenum api = eglQueryAPI(); + eglBindAPI(EGL_OPENGL_ES_API); + return eglWaitClient(); +} + +EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative(EGLint engine) { + if(!EglValidate::engine(engine)) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_PARAMETER); + } + ThreadInfo* thread = getThreadInfo(); + ContextPtr currCtx = thread->eglContext; + EglDisplay* dpy = static_cast<EglDisplay*>(thread->eglDisplay); + if(currCtx.Ptr()) { + SurfacePtr read = currCtx->read(); + SurfacePtr draw = currCtx->draw(); + + EGLNativeInternalDisplayType nativeDisplay = dpy->nativeType(); + if(read.Ptr()) { + if(read->type() == EglSurface::WINDOW && + !EglOS::validNativeWin(nativeDisplay,read->native())) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE); + } + if(read->type() == EglSurface::PIXMAP && + !EglOS::validNativePixmap(nativeDisplay,read->native())) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE); + } + } + if(draw.Ptr()) { + if(draw->type() == EglSurface::WINDOW && + !EglOS::validNativeWin(nativeDisplay,draw->native())) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE); + } + if(draw->type() == EglSurface::PIXMAP && + !EglOS::validNativePixmap(nativeDisplay,draw->native())) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE); + } + } + } + EglOS::waitNative(); + return EGL_TRUE; +} + +EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI(EGLenum api) { + if(!EglValidate::supportedApi(api)) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_PARAMETER); + } + CURRENT_THREAD(); + tls_thread->setApi(api); + return EGL_TRUE; +} + +EGLAPI EGLenum EGLAPIENTRY eglQueryAPI(void) { + CURRENT_THREAD(); + return tls_thread->getApi(); +} + +EGLAPI EGLBoolean EGLAPIENTRY eglWaitClient(void) { + ThreadInfo* thread = getThreadInfo(); + ContextPtr currCtx = thread->eglContext; + if(currCtx.Ptr()) { + if(!currCtx->read().Ptr() || !currCtx->draw().Ptr()) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_CURRENT_SURFACE); + } + g_eglInfo->getIface(currCtx->version())->finish(); + } + return EGL_TRUE; +} + +EGLAPI EGLBoolean EGLAPIENTRY eglReleaseThread(void) { + ThreadInfo* thread = getThreadInfo(); + EglDisplay* dpy = static_cast<EglDisplay*>(thread->eglDisplay); + return eglMakeCurrent(dpy,EGL_NO_SURFACE,EGL_NO_SURFACE,EGL_NO_CONTEXT); +} + +EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY + eglGetProcAddress(const char *procname){ + __eglMustCastToProperFunctionPointerType retVal = NULL; + + initGlobalInfo(); + + if(!strncmp(procname,"egl",3)) { //EGL proc + for(int i=0;i < s_eglExtentionsSize;i++){ + if(strcmp(procname,s_eglExtentions[i].name) == 0){ + retVal = s_eglExtentions[i].address; + break; + } + } + } + else { + // Look at the clientAPI (GLES) supported extension + // function table. + retVal = ClientAPIExts::getProcAddress(procname); + } + return retVal; +} + +//not supported for now +/************************* NOT SUPPORTED FOR NOW ***********************/ +EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferFromClientBuffer( + EGLDisplay display, EGLenum buftype, EGLClientBuffer buffer, + EGLConfig config, const EGLint *attrib_list) { + VALIDATE_DISPLAY(display); + VALIDATE_CONFIG(config); + //we do not support for now openVG, and the only client API resources which may be bound in this fashion are OpenVG + RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_PARAMETER); +} + +EGLAPI EGLBoolean EGLAPIENTRY eglCopyBuffers(EGLDisplay display, EGLSurface surface, + EGLNativePixmapType target) { + VALIDATE_DISPLAY(display); + VALIDATE_SURFACE(surface,srfc); + if(!EglOS::validNativePixmap(dpy->nativeType(),NULL)) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_PIXMAP); + } + + //we do not need to support this for android , since we are not gonna use pixmaps + RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_PIXMAP); +} + +/***********************************************************************/ + + + +//do last ( only if needed) +/*********************************************************************************************************/ +EGLAPI EGLBoolean EGLAPIENTRY eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) { +//TODO: +return 0; +} + +EGLAPI EGLBoolean EGLAPIENTRY eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) { +//TODO: +return 0; +} +/*********************************************************************************************************/ + + +/************************** KHR IMAGE *************************************************************/ +EglImage *attachEGLImage(unsigned int imageId) +{ + ThreadInfo* thread = getThreadInfo(); + EglDisplay* dpy = static_cast<EglDisplay*>(thread->eglDisplay); + ContextPtr ctx = thread->eglContext; + if (ctx.Ptr()) { + ImagePtr img = dpy->getImage(reinterpret_cast<EGLImageKHR>(imageId)); + if(img.Ptr()) { + ctx->attachImage(imageId,img); + return img.Ptr(); + } + } + return NULL; +} + +void detachEGLImage(unsigned int imageId) +{ + ThreadInfo* thread = getThreadInfo(); + EglDisplay* dpy = static_cast<EglDisplay*>(thread->eglDisplay); + ContextPtr ctx = thread->eglContext; + if (ctx.Ptr()) { + ctx->detachImage(imageId); + } +} + + +EGLImageKHR eglCreateImageKHR(EGLDisplay display, EGLContext context, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list) +{ + VALIDATE_DISPLAY(display); + VALIDATE_CONTEXT(context); + + // We only support EGL_GL_TEXTURE_2D images + if (target != EGL_GL_TEXTURE_2D_KHR) { + RETURN_ERROR(EGL_NO_IMAGE_KHR,EGL_BAD_PARAMETER); + } + + ThreadInfo* thread = getThreadInfo(); + ShareGroupPtr sg = thread->shareGroup; + if (sg.Ptr() != NULL) { + unsigned int globalTexName = sg->getGlobalName(TEXTURE, (uintptr_t)buffer); + if (!globalTexName) return EGL_NO_IMAGE_KHR; + + ImagePtr img( new EglImage() ); + if (img.Ptr() != NULL) { + + ObjectDataPtr objData = sg->getObjectData(TEXTURE, (uintptr_t)buffer); + if (!objData.Ptr()) return EGL_NO_IMAGE_KHR; + + TextureData *texData = (TextureData *)objData.Ptr(); + if(!texData->width || !texData->height) return EGL_NO_IMAGE_KHR; + img->width = texData->width; + img->height = texData->height; + img->border = texData->border; + img->internalFormat = texData->internalFormat; + img->globalTexName = globalTexName; + return dpy->addImageKHR(img); + } + } + + return EGL_NO_IMAGE_KHR; +} + + +EGLBoolean eglDestroyImageKHR(EGLDisplay display, EGLImageKHR image) +{ + VALIDATE_DISPLAY(display); + return dpy->destroyImageKHR(image) ? EGL_TRUE:EGL_FALSE; +} + +/*********************************************************************************/ diff --git a/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp b/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp new file mode 100644 index 0000000..b5e7d67 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp @@ -0,0 +1,223 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "EglOsApi.h" +#include "MacNative.h" +#define MAX_PBUFFER_MIPMAP_LEVEL 1 + +namespace EglOS { + +static std::list<EGLNativePixelFormatType> s_nativeConfigs; + +EGLNativeDisplayType getDefaultDisplay() {return 0;} + +bool releaseDisplay(EGLNativeDisplayType dpy) { + return true; +} + +static EglConfig* pixelFormatToConfig(int index,int renderableType,EGLNativePixelFormatType* frmt){ + if(!frmt) return NULL; + + EGLint red,green,blue,alpha,depth,stencil; + EGLint supportedSurfaces,visualType,visualId; + EGLint transparentType,samples; + EGLint tRed,tGreen,tBlue; + EGLint pMaxWidth,pMaxHeight,pMaxPixels; + EGLint configId,level; + EGLint window,pbuffer; + EGLint doubleBuffer,colorSize; + + getPixelFormatAttrib(*frmt,MAC_HAS_DOUBLE_BUFFER,&doubleBuffer); + if(!doubleBuffer) return NULL; //pixel double buffer + + supportedSurfaces = 0; + + getPixelFormatAttrib(*frmt,MAC_DRAW_TO_WINDOW,&window); + getPixelFormatAttrib(*frmt,MAC_DRAW_TO_PBUFFER,&pbuffer); + + if(window) supportedSurfaces |= EGL_WINDOW_BIT; + if(pbuffer) supportedSurfaces |= EGL_PBUFFER_BIT; + + if(!supportedSurfaces) return NULL; + + //default values + visualId = 0; + visualType = EGL_NONE; + EGLenum caveat = EGL_NONE; + EGLBoolean renderable = EGL_FALSE; + pMaxWidth = PBUFFER_MAX_WIDTH; + pMaxHeight = PBUFFER_MAX_HEIGHT; + pMaxPixels = PBUFFER_MAX_PIXELS; + samples = 0; + level = 0; + tRed = tGreen = tBlue = 0; + + transparentType = EGL_NONE; + + getPixelFormatAttrib(*frmt,MAC_SAMPLES_PER_PIXEL,&samples); + getPixelFormatAttrib(*frmt,MAC_COLOR_SIZE,&colorSize); + getPixelFormatAttrib(*frmt,MAC_ALPHA_SIZE,&alpha); + getPixelFormatAttrib(*frmt,MAC_DEPTH_SIZE,&depth); + getPixelFormatAttrib(*frmt,MAC_STENCIL_SIZE,&stencil); + + red = green = blue = (colorSize / 4); //TODO: ask guy if it is OK + + return new EglConfig(red,green,blue,alpha,caveat,(EGLint)index,depth,level,pMaxWidth,pMaxHeight,pMaxPixels,renderable,renderableType, + visualId,visualType,samples,stencil,supportedSurfaces,transparentType,tRed,tGreen,tBlue,*frmt); +} + + +static void initNativeConfigs(){ + int nConfigs = getNumPixelFormats(); + if(s_nativeConfigs.empty()){ + for(int i=0; i < nConfigs ;i++){ + EGLNativePixelFormatType frmt = getPixelFormat(i); + if(frmt){ + s_nativeConfigs.push_back(frmt); + } + } + } +} + +void queryConfigs(EGLNativeDisplayType dpy,int renderableType,ConfigsList& listOut) { + int i = 0 ; + initNativeConfigs(); + for(std::list<EGLNativePixelFormatType>::iterator it = s_nativeConfigs.begin(); it != s_nativeConfigs.end();it++){ + EGLNativePixelFormatType frmt = *it; + EglConfig* conf = pixelFormatToConfig(i++,renderableType,&frmt); + if(conf){ + listOut.push_front(conf); + }; + } +} + +bool validNativeWin(EGLNativeDisplayType dpy, EGLNativeWindowType win) { + unsigned int width,height; + return nsGetWinDims(win,&width,&height); +} + +bool validNativeWin(EGLNativeDisplayType dpy, EGLNativeSurfaceType win) { + return validNativeWin(dpy,(EGLNativeWindowType)win); +} + +//no support for pixmap in mac +bool validNativePixmap(EGLNativeDisplayType dpy, EGLNativeSurfaceType pix) { + + return true; +} + +bool checkWindowPixelFormatMatch(EGLNativeDisplayType dpy,EGLNativeWindowType win,EglConfig* cfg,unsigned int* width,unsigned int* height) { + int r,g,b; + bool ret = nsGetWinDims(win,width,height); + + cfg->getConfAttrib(EGL_RED_SIZE,&r); + cfg->getConfAttrib(EGL_GREEN_SIZE,&g); + cfg->getConfAttrib(EGL_BLUE_SIZE,&b); + bool match = nsCheckColor(win,r + g + b); + + return ret && match; +} + +//no support for pixmap in mac +bool checkPixmapPixelFormatMatch(EGLNativeDisplayType dpy,EGLNativePixmapType pix,EglConfig* cfg,unsigned int* width,unsigned int* height) { + return false; +} + +EGLNativeSurfaceType createPbufferSurface(EGLNativeDisplayType dpy,EglConfig* cfg,EglPbufferSurface* srfc){ + EGLint width,height,hasMipmap,tmp; + EGLint target,format; + srfc->getDim(&width,&height,&tmp); + srfc->getTexInfo(&format,&target); + srfc->getAttrib(EGL_MIPMAP_TEXTURE,&hasMipmap); + EGLint maxMipmap = hasMipmap ? MAX_PBUFFER_MIPMAP_LEVEL:0; + return (EGLNativeSurfaceType)nsCreatePBuffer(target,format,maxMipmap,width,height); +} + +bool releasePbuffer(EGLNativeDisplayType dis,EGLNativeSurfaceType pb) { + nsDestroyPBuffer(pb); + return true; +} + +EGLNativeContextType createContext(EGLNativeDisplayType dpy,EglConfig* cfg,EGLNativeContextType sharedContext) { + return nsCreateContext(cfg->nativeConfig(),sharedContext); +} + +bool destroyContext(EGLNativeDisplayType dpy,EGLNativeContextType ctx) { + nsDestroyContext(ctx); + return true; +} + +bool makeCurrent(EGLNativeDisplayType dpy,EglSurface* read,EglSurface* draw,EGLNativeContextType ctx){ + + // check for unbind + if (ctx == NULL && read == NULL && draw == NULL) { + nsWindowMakeCurrent(NULL, NULL); + return true; + } + else if (ctx == NULL || read == NULL || draw == NULL) { + // error ! + return false; + } + + //dont supporting diffrent read & draw surfaces on Mac + if(read->native() != draw->native()) return false; + switch(draw->type()){ + case EglSurface::WINDOW: + nsWindowMakeCurrent(ctx,draw->native()); + break; + case EglSurface::PBUFFER: + { + EGLint hasMipmap; + draw->getAttrib(EGL_MIPMAP_TEXTURE,&hasMipmap); + int mipmapLevel = hasMipmap ? MAX_PBUFFER_MIPMAP_LEVEL:0; + nsPBufferMakeCurrent(ctx,draw->native(),mipmapLevel); + break; + } + case EglSurface::PIXMAP: // not supported on Mac + default: + return false; + } + return true; +} + +void swapBuffers(EGLNativeDisplayType dpy,EGLNativeSurfaceType srfc){ + nsSwapBuffers(); +} + +void waitNative(){} + +void swapInterval(EGLNativeDisplayType dpy,EGLNativeSurfaceType win,int interval){ + nsSwapInterval(&interval); +} + +EGLNativeSurfaceType createWindowSurface(EGLNativeWindowType wnd){ + return (EGLNativeSurfaceType)wnd; +} + +EGLNativeSurfaceType createPixmapSurface(EGLNativePixmapType pix){ + return (EGLNativeSurfaceType)pix; +} + +void destroySurface(EGLNativeSurfaceType srfc){ +} + +EGLNativeInternalDisplayType getInternalDisplay(EGLNativeDisplayType dpy){ + return (EGLNativeInternalDisplayType)dpy; +} + +void deleteDisplay(EGLNativeInternalDisplayType idpy){ +} + +}; diff --git a/emulator/opengl/host/libs/Translator/EGL/EglOsApi.h b/emulator/opengl/host/libs/Translator/EGL/EglOsApi.h new file mode 100644 index 0000000..c166220 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglOsApi.h @@ -0,0 +1,63 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef EGL_OS_API_H +#define EGL_OS_API_H + +#include <EGL/egl.h> +#include <EGL/eglinternalplatform.h> +#ifdef __APPLE__ +#include <OpenGL/gl.h> +#else +#include <GL/gl.h> +#endif +#include "EglConfig.h" +#include "EglDisplay.h" +#include "EglPbufferSurface.h" + +#define PBUFFER_MAX_WIDTH 32767 +#define PBUFFER_MAX_HEIGHT 32767 +#define PBUFFER_MAX_PIXELS 32767*32767 + +namespace EglOS{ + + void queryConfigs(EGLNativeInternalDisplayType dpy,int renderable_type,ConfigsList& listOut); + bool releasePbuffer(EGLNativeInternalDisplayType dis,EGLNativeSurfaceType pb); + bool destroyContext(EGLNativeInternalDisplayType dpy,EGLNativeContextType ctx); + bool releaseDisplay(EGLNativeInternalDisplayType dpy); + bool validNativeWin(EGLNativeInternalDisplayType dpy,EGLNativeSurfaceType win); + bool validNativeWin(EGLNativeInternalDisplayType dpy,EGLNativeWindowType win); + bool validNativePixmap(EGLNativeInternalDisplayType dpy,EGLNativeSurfaceType pix); + bool checkWindowPixelFormatMatch(EGLNativeInternalDisplayType dpy,EGLNativeWindowType win,EglConfig* cfg,unsigned int* width,unsigned int* height); + bool checkPixmapPixelFormatMatch(EGLNativeInternalDisplayType dpy,EGLNativePixmapType pix,EglConfig* cfg,unsigned int* width,unsigned int* height); + bool makeCurrent(EGLNativeInternalDisplayType dpy,EglSurface* read,EglSurface* draw,EGLNativeContextType); + void swapBuffers(EGLNativeInternalDisplayType dpy,EGLNativeSurfaceType srfc); + void swapInterval(EGLNativeInternalDisplayType dpy,EGLNativeSurfaceType win,int interval); + void waitNative(); + + EGLNativeInternalDisplayType getDefaultDisplay(); + EGLNativeInternalDisplayType getInternalDisplay(EGLNativeDisplayType dpy); + void deleteDisplay(EGLNativeInternalDisplayType idpy); + EGLNativeSurfaceType createPbufferSurface(EGLNativeInternalDisplayType dpy,EglConfig* cfg,EglPbufferSurface* pb); + EGLNativeContextType createContext(EGLNativeInternalDisplayType dpy,EglConfig* cfg,EGLNativeContextType sharedContext); + EGLNativeSurfaceType createWindowSurface(EGLNativeWindowType wnd); + EGLNativeSurfaceType createPixmapSurface(EGLNativePixmapType pix); + void destroySurface(EGLNativeSurfaceType srfc); +#ifdef _WIN32 + void initPtrToWglFunctions(); +#endif +}; + +#endif diff --git a/emulator/opengl/host/libs/Translator/EGL/EglPbufferSurface.cpp b/emulator/opengl/host/libs/Translator/EGL/EglPbufferSurface.cpp new file mode 100644 index 0000000..8bcb31a --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglPbufferSurface.cpp @@ -0,0 +1,75 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "EglPbufferSurface.h" + +bool EglPbufferSurface::setAttrib(EGLint attrib,EGLint val) { + switch(attrib) { + case EGL_WIDTH: + if(val < 0) return false; + m_width = val; + break; + case EGL_HEIGHT: + if(val < 0) return false; + m_height = val; + break; + case EGL_LARGEST_PBUFFER: + m_largest = val; + break; + case EGL_TEXTURE_FORMAT: + if(val != EGL_NO_TEXTURE && val != EGL_TEXTURE_RGB && val != EGL_TEXTURE_RGBA) return false; + m_texFormat = val; + break; + case EGL_TEXTURE_TARGET: + if(val != EGL_NO_TEXTURE && val != EGL_TEXTURE_2D) return false; + m_texTarget = val; + break; + case EGL_MIPMAP_TEXTURE: + m_texMipmap = val; + break; + default: + return false; + } + return true; +} + +bool EglPbufferSurface::getAttrib(EGLint attrib,EGLint* val) { + switch(attrib) { + case EGL_CONFIG_ID: + *val = m_config->id(); + break; + case EGL_WIDTH: + *val = m_width; + break; + case EGL_HEIGHT: + *val = m_height; + break; + case EGL_LARGEST_PBUFFER: + *val = m_largest; + break; + case EGL_TEXTURE_FORMAT: + *val = m_texFormat; + break; + case EGL_TEXTURE_TARGET: + *val = m_texTarget; + break; + case EGL_MIPMAP_TEXTURE: + *val = m_texMipmap; + break; + default: + return false; + } + return true; +} diff --git a/emulator/opengl/host/libs/Translator/EGL/EglPbufferSurface.h b/emulator/opengl/host/libs/Translator/EGL/EglPbufferSurface.h new file mode 100644 index 0000000..9740170 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglPbufferSurface.h @@ -0,0 +1,49 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef EGL_PBUFFER_SURFACE_H +#define EGL_PBUFFER_SURFACE_H + +#include "EglSurface.h" + +class EglDisplay; + +class EglPbufferSurface:public EglSurface { +public: + EglPbufferSurface(EglDisplay *dpy, EglConfig* config): + EglSurface(dpy,PBUFFER,config,0,0), + m_texFormat(EGL_NO_TEXTURE), + m_texTarget(EGL_NO_TEXTURE), + m_texMipmap(EGL_FALSE), + m_largest(EGL_FALSE){}; + + void setNativePbuffer(EGLNativeSurfaceType srfc){ m_native = srfc;}; + bool setAttrib(EGLint attrib,EGLint val); + bool getAttrib(EGLint attrib,EGLint* val); + void getDim(EGLint* width,EGLint* height,EGLint* largest){ + *width = m_width; + *height = m_height; + *largest = m_largest; + }; + + void getTexInfo(EGLint* format,EGLint* target){ *format = m_texFormat; *target = m_texTarget;} + +private: + EGLint m_texFormat; + EGLint m_texTarget; + EGLint m_texMipmap; + EGLint m_largest; +}; +#endif diff --git a/emulator/opengl/host/libs/Translator/EGL/EglPixmapSurface.cpp b/emulator/opengl/host/libs/Translator/EGL/EglPixmapSurface.cpp new file mode 100644 index 0000000..2087594 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglPixmapSurface.cpp @@ -0,0 +1,60 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "EglPixmapSurface.h" +#include "EglOsApi.h" + +std::set<EGLNativePixmapType> EglPixmapSurface::s_associatedPixmaps; + +bool EglPixmapSurface::alreadyAssociatedWithConfig(EGLNativePixmapType pix) { + return s_associatedPixmaps.find(pix) != s_associatedPixmaps.end(); + +} + +EglPixmapSurface::EglPixmapSurface(EglDisplay *dpy, + EGLNativePixmapType pix, + EglConfig* config) : + EglSurface(dpy, PIXMAP,config,0,0), + m_pixmap(pix) +{ + s_associatedPixmaps.insert(pix); + m_native = EglOS::createPixmapSurface(pix); +} + +EglPixmapSurface::~EglPixmapSurface() { + s_associatedPixmaps.erase(m_pixmap); +} + +bool EglPixmapSurface::getAttrib(EGLint attrib,EGLint* val) { + switch(attrib) { + case EGL_CONFIG_ID: + *val = m_config->id(); + break; + case EGL_WIDTH: + *val = m_width; + break; + case EGL_HEIGHT: + *val = m_height; + break; + case EGL_LARGEST_PBUFFER: + case EGL_TEXTURE_FORMAT: + case EGL_TEXTURE_TARGET: + case EGL_MIPMAP_TEXTURE: + break; + default: + return false; + } + return true; +} diff --git a/emulator/opengl/host/libs/Translator/EGL/EglPixmapSurface.h b/emulator/opengl/host/libs/Translator/EGL/EglPixmapSurface.h new file mode 100644 index 0000000..f027eab --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglPixmapSurface.h @@ -0,0 +1,37 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef EGL_PIXMAP_SURFACE_H +#define EGL_PIXMAP_SURFACE_H + +#include <set> +#include <EGL/egl.h> +#include "EglSurface.h" + +class EglDisplay; + +class EglPixmapSurface: public EglSurface { +public: + EglPixmapSurface(EglDisplay *dpy, EGLNativePixmapType pix,EglConfig* config); + ~EglPixmapSurface(); + + bool getAttrib(EGLint attrib,EGLint* val); + + static bool alreadyAssociatedWithConfig(EGLNativePixmapType pix); +private: + EGLNativePixmapType m_pixmap; + static std::set<EGLNativePixmapType> s_associatedPixmaps; +}; +#endif diff --git a/emulator/opengl/host/libs/Translator/EGL/EglSurface.cpp b/emulator/opengl/host/libs/Translator/EGL/EglSurface.cpp new file mode 100644 index 0000000..7f658b6 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglSurface.cpp @@ -0,0 +1,43 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "EglSurface.h" +#include "EglOsApi.h" + +unsigned int EglSurface::s_nextSurfaceHndl = 0; + +EglSurface::~EglSurface(){ + + if(m_type == EglSurface::PBUFFER) { + EglOS::releasePbuffer(m_dpy->nativeType(),m_native); + } + + if(m_native) EglOS::destroySurface(m_native); +} + +bool EglSurface::setAttrib(EGLint attrib,EGLint val) { + switch(attrib) { + case EGL_WIDTH: + case EGL_HEIGHT: + case EGL_LARGEST_PBUFFER: + case EGL_TEXTURE_FORMAT: + case EGL_TEXTURE_TARGET: + case EGL_MIPMAP_TEXTURE: + break; + default: + return false; + } + return true; +} diff --git a/emulator/opengl/host/libs/Translator/EGL/EglSurface.h b/emulator/opengl/host/libs/Translator/EGL/EglSurface.h new file mode 100644 index 0000000..d65f480 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglSurface.h @@ -0,0 +1,74 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef EGL_SURFACE_H +#define EGL_SURFACE_H + +#include <EGL/egl.h> +#include <EGL/eglinternalplatform.h> +#include <map> +#include <GLcommon/SmartPtr.h> +#include "EglConfig.h" + +class EglSurface; +typedef SmartPtr<EglSurface> SurfacePtr; + +class EglDisplay; + +class EglSurface { +public: + typedef enum { + WINDOW = 0, + PBUFFER = 1, + PIXMAP = 3 + } ESurfaceType; + ESurfaceType type(){ return m_type;}; + EGLNativeSurfaceType native(){return m_native;} + virtual bool setAttrib(EGLint attrib,EGLint val); + virtual bool getAttrib(EGLint attrib,EGLint* val) = 0; + void setDim(int width,int height){ m_width = width; m_height = height;}; + EglConfig* getConfig(){return m_config;}; + unsigned int getHndl(){return m_hndl;}; + virtual ~EglSurface(); + +private: + static unsigned int s_nextSurfaceHndl; + ESurfaceType m_type; + unsigned int m_hndl; + +protected: + EglSurface(EglDisplay *dpy, + ESurfaceType type, + EglConfig* config, + EGLint width, + EGLint height) : + m_type(type), + m_config(config), + m_width(width), + m_height(height), + m_native(NULL), + m_dpy(dpy) + { + m_hndl = ++s_nextSurfaceHndl; + } + +protected: + EglConfig* m_config; + EGLint m_width; + EGLint m_height; + EGLNativeSurfaceType m_native; + EglDisplay *m_dpy; +}; +#endif diff --git a/emulator/opengl/host/libs/Translator/EGL/EglThreadInfo.cpp b/emulator/opengl/host/libs/Translator/EGL/EglThreadInfo.cpp new file mode 100644 index 0000000..1b403f2 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglThreadInfo.cpp @@ -0,0 +1,42 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "EglThreadInfo.h" +#include "EglOsApi.h" + +EglThreadInfo::EglThreadInfo():m_err(EGL_SUCCESS),m_api(EGL_OPENGL_ES_API) {} + +#include <cutils/threads.h> + +static thread_store_t s_tls = THREAD_STORE_INITIALIZER; + +static void tlsDestruct(void *ptr) +{ + if (ptr) { + EglThreadInfo *ti = (EglThreadInfo *)ptr; + delete ti; + } +} + +EglThreadInfo* EglThreadInfo::get(void) +{ + EglThreadInfo *ti = (EglThreadInfo *)thread_store_get(&s_tls); + if (!ti) { + ti = new EglThreadInfo(); + thread_store_set(&s_tls, ti, tlsDestruct); + } + return ti; +} + diff --git a/emulator/opengl/host/libs/Translator/EGL/EglThreadInfo.h b/emulator/opengl/host/libs/Translator/EGL/EglThreadInfo.h new file mode 100644 index 0000000..9d2df10 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglThreadInfo.h @@ -0,0 +1,43 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef EGL_THREAD_INFO_H +#define EGL_THREAD_INFO_H + +#include <EGL/egl.h> +#include "EglDisplay.h" +#include "EglContext.h" +#include "EglSurface.h" +#include "EglPbufferSurface.h" + +class EglThreadInfo { +public: + + EglThreadInfo(); + void setError(EGLint err) { m_err = err;} + EGLint getError(){ return m_err;} + void destroyContextIfNotCurrent(ContextPtr context ); + void setApi(EGLenum api){m_api = api;} + EGLenum getApi(){return m_api;} + + static EglThreadInfo* get(void) __attribute__((const)); + +private: + EglDisplay* m_currentDisplay; + EGLint m_err; + EGLenum m_api; +}; + +#endif diff --git a/emulator/opengl/host/libs/Translator/EGL/EglValidate.cpp b/emulator/opengl/host/libs/Translator/EGL/EglValidate.cpp new file mode 100644 index 0000000..d87f9b9 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglValidate.cpp @@ -0,0 +1,93 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "EglValidate.h" +#include <GLcommon/GLutils.h> + +bool EglValidate::confAttrib(EGLint attrib) { + switch(attrib) { + case EGL_BUFFER_SIZE: + case EGL_RED_SIZE: + case EGL_GREEN_SIZE: + case EGL_BLUE_SIZE: + case EGL_ALPHA_SIZE: + case EGL_BIND_TO_TEXTURE_RGB: + case EGL_BIND_TO_TEXTURE_RGBA: + case EGL_CONFIG_CAVEAT: + case EGL_CONFIG_ID: + case EGL_DEPTH_SIZE: + case EGL_LEVEL: + case EGL_MAX_PBUFFER_WIDTH: + case EGL_MAX_PBUFFER_HEIGHT: + case EGL_MAX_PBUFFER_PIXELS: + case EGL_MAX_SWAP_INTERVAL: + case EGL_MIN_SWAP_INTERVAL: + case EGL_RENDERABLE_TYPE: + case EGL_NATIVE_RENDERABLE: + case EGL_NATIVE_VISUAL_ID: + case EGL_NATIVE_VISUAL_TYPE: + case EGL_SAMPLE_BUFFERS: + case EGL_SAMPLES: + case EGL_STENCIL_SIZE: + case EGL_SURFACE_TYPE: + case EGL_TRANSPARENT_TYPE: + case EGL_TRANSPARENT_RED_VALUE: + case EGL_TRANSPARENT_GREEN_VALUE: + case EGL_TRANSPARENT_BLUE_VALUE: + case EGL_CONFORMANT: + return true; + } + return false; +} + +bool EglValidate::noAttribs(const EGLint* attrib) { + return !attrib || attrib[0] == EGL_NONE ; +} + +bool EglValidate::pbufferAttribs(EGLint width,EGLint height,bool isTexFormatNoTex,bool isTexTargetNoTex) { + if(!isTexFormatNoTex) { + if (!(isPowerOf2(width) && isPowerOf2(height))) return false; + } + return isTexFormatNoTex == isTexTargetNoTex ; +} + +bool EglValidate::releaseContext(EGLContext ctx,EGLSurface s1,EGLSurface s2) { + return (ctx == EGL_NO_CONTEXT) && + (s1 == EGL_NO_SURFACE) && + (s2 == EGL_NO_SURFACE); +} + +bool EglValidate::badContextMatch(EGLContext ctx,EGLSurface s1,EGLSurface s2) { + return ctx != EGL_NO_CONTEXT ? (s1 == EGL_NO_SURFACE || s2 == EGL_NO_SURFACE): + (s1 != EGL_NO_SURFACE || s2 != EGL_NO_SURFACE); +} + +bool EglValidate::surfaceTarget(EGLint target) { + return target == EGL_READ || target == EGL_DRAW; +} + +bool EglValidate::engine(EGLint engine) { + return engine == EGL_CORE_NATIVE_ENGINE; +} + +bool EglValidate::stringName(EGLint name) { + return name == EGL_VENDOR || + name == EGL_VERSION || + name == EGL_EXTENSIONS; +} + +bool EglValidate::supportedApi(EGLenum api) { + return api == EGL_OPENGL_ES_API; +} diff --git a/emulator/opengl/host/libs/Translator/EGL/EglValidate.h b/emulator/opengl/host/libs/Translator/EGL/EglValidate.h new file mode 100644 index 0000000..532584f --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglValidate.h @@ -0,0 +1,33 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef EGL_VALIDATE_H +#define EGL_VALIDATE_H + +#include <EGL/egl.h> + +class EglValidate { +public: + static bool confAttrib(EGLint attrib); + static bool noAttribs(const EGLint* attrib); + static bool pbufferAttribs(EGLint width,EGLint height,bool texFormatIsNoTex,bool texTargetIsNoTex); + static bool releaseContext(EGLContext ctx,EGLSurface s1,EGLSurface s2); + static bool badContextMatch(EGLContext ctx,EGLSurface s1,EGLSurface s2); + static bool surfaceTarget(EGLint target); + static bool engine(EGLint engine); + static bool stringName(EGLint name); + static bool supportedApi(EGLenum api); +}; +#endif diff --git a/emulator/opengl/host/libs/Translator/EGL/EglWindowSurface.cpp b/emulator/opengl/host/libs/Translator/EGL/EglWindowSurface.cpp new file mode 100644 index 0000000..7bff896 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglWindowSurface.cpp @@ -0,0 +1,61 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "EglWindowSurface.h" +#include "EglOsApi.h" + +std::set<EGLNativeWindowType> EglWindowSurface::s_associatedWins; + +bool EglWindowSurface::alreadyAssociatedWithConfig(EGLNativeWindowType win) { + return s_associatedWins.find(win) != s_associatedWins.end(); + +} + +EglWindowSurface::EglWindowSurface(EglDisplay *dpy, + EGLNativeWindowType win, + EglConfig* config, + unsigned int width,unsigned int height) : + EglSurface(dpy, WINDOW,config,width,height), + m_win(win) +{ + s_associatedWins.insert(win); + m_native = EglOS::createWindowSurface(win); +} + +EglWindowSurface:: ~EglWindowSurface() { + s_associatedWins.erase(m_win); +} + +bool EglWindowSurface::getAttrib(EGLint attrib,EGLint* val) { + switch(attrib) { + case EGL_CONFIG_ID: + *val = m_config->id(); + break; + case EGL_WIDTH: + *val = m_width; + break; + case EGL_HEIGHT: + *val = m_height; + break; + case EGL_LARGEST_PBUFFER: + case EGL_TEXTURE_FORMAT: + case EGL_TEXTURE_TARGET: + case EGL_MIPMAP_TEXTURE: + break; + default: + return false; + } + return true; +} diff --git a/emulator/opengl/host/libs/Translator/EGL/EglWindowSurface.h b/emulator/opengl/host/libs/Translator/EGL/EglWindowSurface.h new file mode 100644 index 0000000..460a293 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglWindowSurface.h @@ -0,0 +1,37 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef EGL_WINDOW_SURFACE_H +#define EGL_WINDOW_SURFACE_H + +#include <set> +#include <EGL/egl.h> +#include "EglSurface.h" +#include "EglConfig.h" + +class EglDisplay; + +class EglWindowSurface: public EglSurface { +public: + EglWindowSurface(EglDisplay *dpy, EGLNativeWindowType win,EglConfig* config,unsigned width,unsigned int height); + ~EglWindowSurface(); + bool getAttrib(EGLint attrib,EGLint* val); + + static bool alreadyAssociatedWithConfig(EGLNativeWindowType win); +private: + EGLNativeWindowType m_win; + static std::set<EGLNativeWindowType> s_associatedWins; +}; +#endif diff --git a/emulator/opengl/host/libs/Translator/EGL/EglWindowsApi.cpp b/emulator/opengl/host/libs/Translator/EGL/EglWindowsApi.cpp new file mode 100644 index 0000000..c11c547 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglWindowsApi.cpp @@ -0,0 +1,592 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "EglOsApi.h" +#include <windows.h> +#include <wingdi.h> +#include <GL/wglext.h> +#include <stdio.h> + +#define IS_TRUE(a) \ + if(a != true) return false; + + +struct DisplayInfo{ + DisplayInfo():dc(NULL),hwnd(NULL),isPixelFormatSet(false){}; + DisplayInfo(HDC hdc,HWND wnd):isPixelFormatSet(false){dc = hdc; hwnd = wnd;}; + HDC dc; + HWND hwnd; + bool isPixelFormatSet; +}; + +struct TlsData { + std::map<int,DisplayInfo> m_map; +}; + +static DWORD s_tlsIndex = 0; + +static TlsData *getTLS() { + TlsData *tls = (TlsData *)TlsGetValue(s_tlsIndex); + if (!tls) { + tls = new TlsData(); + TlsSetValue(s_tlsIndex, tls); + } + return tls; +} + +class WinDisplay{ +public: + typedef enum { + DEFAULT_DISPLAY = 0 + }; + WinDisplay(){}; + DisplayInfo& getInfo(int configurationIndex){ return getTLS()->m_map[configurationIndex];} + HDC getDC(int configId){return getTLS()->m_map[configId].dc;} + void setInfo(int configurationIndex,const DisplayInfo& info); + bool isPixelFormatSet(int cfgId){ return getTLS()->m_map[cfgId].isPixelFormatSet;} + void pixelFormatWasSet(int cfgId){getTLS()->m_map[cfgId].isPixelFormatSet = true;} + bool infoExists(int configurationIndex); + void releaseAll(); +}; + +void WinDisplay::releaseAll(){ + TlsData * tls = getTLS(); + + for(std::map<int,DisplayInfo>::iterator it = tls->m_map.begin(); it != tls->m_map.end();it++){ + if((*it).second.hwnd){ + DestroyWindow((*it).second.hwnd); + } + DeleteDC((*it).second.dc); + } +} + +bool WinDisplay::infoExists(int configurationIndex){ + return getTLS()->m_map.find(configurationIndex) != getTLS()->m_map.end(); +} + +void WinDisplay::setInfo(int configurationIndex,const DisplayInfo& info){ + getTLS()->m_map[configurationIndex] = info; +} + +struct WglExtProcs{ + PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB; + PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB; + PFNWGLCREATEPBUFFERARBPROC wglCreatePbufferARB; + PFNWGLRELEASEPBUFFERDCARBPROC wglReleasePbufferDCARB; + PFNWGLDESTROYPBUFFERARBPROC wglDestroyPbufferARB; + PFNWGLGETPBUFFERDCARBPROC wglGetPbufferDCARB; + PFNWGLMAKECONTEXTCURRENTARBPROC wglMakeContextCurrentARB; + PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT; +}; + +static WglExtProcs* s_wglExtProcs = NULL; + +class SrfcInfo{ +public: + typedef enum { + WINDOW = 0, + PBUFFER = 1, + PIXMAP = 2 + }SurfaceType; + explicit SrfcInfo(HWND wnd); + explicit SrfcInfo(HPBUFFERARB pb); + explicit SrfcInfo(HBITMAP bmap); + HWND getHwnd(){ return m_hwnd;}; + HDC getDC(){ return m_hdc;}; + HBITMAP getBmap(){ return m_bmap;}; + HPBUFFERARB getPbuffer(){ return m_pb;}; + ~SrfcInfo(); +private: + HWND m_hwnd; + HPBUFFERARB m_pb; + HBITMAP m_bmap; + HDC m_hdc; + SurfaceType m_type; +}; + +SrfcInfo::SrfcInfo(HBITMAP bmap):m_hwnd(NULL), + m_pb(NULL), + m_hdc(NULL), + m_type(PIXMAP){ + m_bmap = bmap; +} + +SrfcInfo::SrfcInfo(HWND wnd):m_pb(NULL), + m_bmap(NULL), + m_type(WINDOW){ + m_hwnd = wnd; + m_hdc = GetDC(wnd); +} + +SrfcInfo::SrfcInfo(HPBUFFERARB pb):m_hwnd(NULL), + m_bmap(NULL), + m_type(PBUFFER){ + m_pb = pb; + if(s_wglExtProcs->wglGetPbufferDCARB){ + m_hdc = s_wglExtProcs->wglGetPbufferDCARB(pb); + } +} + +SrfcInfo::~SrfcInfo(){ + if(m_type == WINDOW){ + ReleaseDC(m_hwnd,m_hdc); + } +} + +namespace EglOS{ + + + +PROC wglGetExtentionsProcAddress(HDC hdc,const char *extension_name,const char* proc_name) +{ + // this is pointer to function which returns pointer to string with list of all wgl extensions + PFNWGLGETEXTENSIONSSTRINGARBPROC _wglGetExtensionsStringARB = NULL; + + // determine pointer to wglGetExtensionsStringEXT function + _wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress("wglGetExtensionsStringARB"); + if(!_wglGetExtensionsStringARB){ + fprintf(stderr,"could not get wglGetExtensionsStringARB\n"); + return NULL; + } + + if (!_wglGetExtensionsStringARB || strstr(_wglGetExtensionsStringARB(hdc), extension_name) == NULL) + { + fprintf(stderr,"extension %s was not found\n",extension_name); + // string was not found + return NULL; + } + + // extension is supported + return wglGetProcAddress(proc_name); +} + +LRESULT CALLBACK dummyWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) +{ + return DefWindowProc(hwnd, uMsg, wParam, lParam); +} + +HWND createDummyWindow(){ + + WNDCLASSEX wcx; + wcx.cbSize = sizeof(wcx); // size of structure + wcx.style = CS_OWNDC |CS_HREDRAW |CS_VREDRAW; // redraw if size changes + wcx.lpfnWndProc = dummyWndProc; // points to window procedure + wcx.cbClsExtra = 0; // no extra class memory + wcx.cbWndExtra = sizeof(void*); // save extra window memory, to store VasWindow instance + wcx.hInstance = NULL; // handle to instance + wcx.hIcon = NULL; // predefined app. icon + wcx.hCursor = NULL; + wcx.hbrBackground = NULL; // no background brush + wcx.lpszMenuName = NULL; // name of menu resource + wcx.lpszClassName = "DummyWin"; // name of window class + wcx.hIconSm = (HICON) NULL; // small class icon + + ATOM winClass = RegisterClassEx(&wcx); + HWND hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, + "DummyWin", + "Dummy", + WS_POPUP, + 0, + 0, + 1, + 1, + NULL, + NULL, + 0,0); + return hwnd; +} + +EGLNativeInternalDisplayType getDefaultDisplay() { + if (!s_tlsIndex) s_tlsIndex = TlsAlloc(); + WinDisplay* dpy = new WinDisplay(); + + HWND hwnd = createDummyWindow(); + HDC hdc = GetDC(hwnd); + dpy->setInfo(WinDisplay::DEFAULT_DISPLAY,DisplayInfo(hdc,hwnd)); + return static_cast<EGLNativeInternalDisplayType>(dpy); +} + +EGLNativeInternalDisplayType getInternalDisplay(EGLNativeDisplayType display){ + if (!s_tlsIndex) s_tlsIndex = TlsAlloc(); + WinDisplay* dpy = new WinDisplay(); + dpy->setInfo(WinDisplay::DEFAULT_DISPLAY,DisplayInfo(display,NULL)); + return dpy; +} + +static HDC getDummyDC(EGLNativeInternalDisplayType display,int cfgId){ + + HDC dpy = NULL; + if(!display->infoExists(cfgId)){ + HWND hwnd = createDummyWindow(); + dpy = GetDC(hwnd); + display->setInfo(cfgId,DisplayInfo(dpy,hwnd)); + } else { + dpy = display->getDC(cfgId); + } + return dpy; +} +void initPtrToWglFunctions(){ + HWND hwnd = createDummyWindow(); + HDC dpy = GetDC(hwnd); + if(!hwnd || !dpy){ + fprintf(stderr,"error while getting DC\n"); + return; + } + EGLNativeContextType ctx = NULL; + PIXELFORMATDESCRIPTOR pfd = { + sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd + 1, // version number + PFD_DRAW_TO_WINDOW | // support window + PFD_SUPPORT_OPENGL | // support OpenGL + PFD_DOUBLEBUFFER, // double buffered + PFD_TYPE_RGBA, // RGBA type + 24, // 24-bit color depth + 0, 0, 0, 0, 0, 0, // color bits ignored + 0, // no alpha buffer + 0, // shift bit ignored + 0, // no accumulation buffer + 0, 0, 0, 0, // accum bits ignored + 32, // 32-bit z-buffer + 0, // no stencil buffer + 0, // no auxiliary buffer + PFD_MAIN_PLANE, // main layer + 0, // reserved + 0, 0, 0 // layer masks ignored + }; + + int iPixelFormat,err; + iPixelFormat = ChoosePixelFormat(dpy, &pfd); + if(iPixelFormat < 0){ + fprintf(stderr,"error while choosing pixel format\n"); + return; + } + if(!SetPixelFormat(dpy,iPixelFormat,&pfd)){ + + int err = GetLastError(); + fprintf(stderr,"error while setting pixel format 0x%x\n",err); + return; + } + + + ctx = wglCreateContext(dpy); + if(!ctx){ + err = GetLastError(); + fprintf(stderr,"error while creating dummy context %d\n",err); + } + if(!wglMakeCurrent(dpy,ctx)){ + err = GetLastError(); + fprintf(stderr,"error while making dummy context current %d\n",err); + } + + if(!s_wglExtProcs){ + s_wglExtProcs = new WglExtProcs(); + s_wglExtProcs->wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)wglGetExtentionsProcAddress(dpy,"WGL_ARB_pixel_format","wglGetPixelFormatAttribivARB"); + s_wglExtProcs->wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetExtentionsProcAddress(dpy,"WGL_ARB_pixel_format","wglChoosePixelFormatARB"); + s_wglExtProcs->wglCreatePbufferARB = (PFNWGLCREATEPBUFFERARBPROC)wglGetExtentionsProcAddress(dpy,"WGL_ARB_pbuffer","wglCreatePbufferARB"); + s_wglExtProcs->wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC)wglGetExtentionsProcAddress(dpy,"WGL_ARB_pbuffer","wglReleasePbufferDCARB"); + s_wglExtProcs->wglDestroyPbufferARB = (PFNWGLDESTROYPBUFFERARBPROC)wglGetExtentionsProcAddress(dpy,"WGL_ARB_pbuffer","wglDestroyPbufferARB"); + s_wglExtProcs->wglGetPbufferDCARB = (PFNWGLGETPBUFFERDCARBPROC)wglGetExtentionsProcAddress(dpy,"WGL_ARB_pbuffer","wglGetPbufferDCARB"); + s_wglExtProcs->wglMakeContextCurrentARB = (PFNWGLMAKECONTEXTCURRENTARBPROC)wglGetExtentionsProcAddress(dpy,"WGL_ARB_make_current_read","wglMakeContextCurrentARB"); + s_wglExtProcs->wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetExtentionsProcAddress(dpy,"WGL_EXT_swap_control","wglSwapIntervalEXT"); + } + + wglMakeCurrent(dpy,NULL); + DestroyWindow(hwnd); + DeleteDC(dpy); +} + +bool releaseDisplay(EGLNativeInternalDisplayType dpy) { + dpy->releaseAll(); + return true; +} + +void deleteDisplay(EGLNativeInternalDisplayType idpy){ + if(idpy){ + delete idpy; + } +} + + +static bool initPixelFormat(HDC dc){ + PIXELFORMATDESCRIPTOR pfd; + unsigned int numpf; + int iPixelFormat; + + if(s_wglExtProcs->wglChoosePixelFormatARB) { + int i0 = 0; + float f0 = 0.0f; + return s_wglExtProcs->wglChoosePixelFormatARB(dc,&i0, &f0, 1, &iPixelFormat, &numpf); + } else { + return ChoosePixelFormat(dc,&pfd); + } +} + +EglConfig* pixelFormatToConfig(EGLNativeInternalDisplayType display,int renderableType,EGLNativePixelFormatType* frmt,int index){ + + EGLint red,green,blue,alpha,depth,stencil; + EGLint supportedSurfaces,visualType,visualId; + EGLint transparentType,samples; + EGLint tRed,tGreen,tBlue; + EGLint pMaxWidth,pMaxHeight,pMaxPixels; + EGLint configId,level; + EGLint window,bitmap,pbuffer,transparent; + HDC dpy = getDummyDC(display,WinDisplay::DEFAULT_DISPLAY); + + if(frmt->iPixelType != PFD_TYPE_RGBA) return NULL; // other formats are not supported yet + if(!((frmt->dwFlags & PFD_SUPPORT_OPENGL) && (frmt->dwFlags & PFD_DOUBLEBUFFER))) return NULL; //pixel format does not supports opengl or double buffer + if( 0 != (frmt->dwFlags & (PFD_GENERIC_FORMAT | PFD_NEED_PALETTE )) ) return NULL; //discard generic pixel formats as well as pallete pixel formats + + int attribs [] = { + WGL_DRAW_TO_WINDOW_ARB, + WGL_DRAW_TO_BITMAP_ARB, + WGL_DRAW_TO_PBUFFER_ARB, + WGL_TRANSPARENT_ARB, + WGL_TRANSPARENT_RED_VALUE_ARB, + WGL_TRANSPARENT_GREEN_VALUE_ARB, + WGL_TRANSPARENT_BLUE_VALUE_ARB + }; + + supportedSurfaces = 0; + if(!s_wglExtProcs->wglGetPixelFormatAttribivARB) return NULL; + + IS_TRUE(s_wglExtProcs->wglGetPixelFormatAttribivARB(dpy,index,0,1,&attribs[0],&window)); + IS_TRUE(s_wglExtProcs->wglGetPixelFormatAttribivARB(dpy,index,0,1,&attribs[1],&bitmap)); + IS_TRUE(s_wglExtProcs->wglGetPixelFormatAttribivARB(dpy,index,0,1,&attribs[2],&pbuffer)); + if(window) supportedSurfaces |= EGL_WINDOW_BIT; + if(bitmap) supportedSurfaces |= EGL_PIXMAP_BIT; + if(pbuffer) supportedSurfaces |= EGL_PBUFFER_BIT; + + + if(!supportedSurfaces) return NULL; + + //default values + visualId = 0; + visualType = EGL_NONE; + EGLenum caveat = EGL_NONE; + EGLBoolean renderable = EGL_FALSE; + pMaxWidth = PBUFFER_MAX_WIDTH; + pMaxHeight = PBUFFER_MAX_HEIGHT; + pMaxPixels = PBUFFER_MAX_PIXELS; + samples = 0 ; + level = 0 ; + + IS_TRUE(s_wglExtProcs->wglGetPixelFormatAttribivARB(dpy,index,0,1,&attribs[3],&transparent)); + if(transparent) { + transparentType = EGL_TRANSPARENT_RGB; + IS_TRUE(s_wglExtProcs->wglGetPixelFormatAttribivARB(dpy,index,0,1,&attribs[4],&tRed)); + IS_TRUE(s_wglExtProcs->wglGetPixelFormatAttribivARB(dpy,index,0,1,&attribs[5],&tGreen)); + IS_TRUE(s_wglExtProcs->wglGetPixelFormatAttribivARB(dpy,index,0,1,&attribs[6],&tBlue)); + } else { + transparentType = EGL_NONE; + } + + red = frmt->cRedBits; + green = frmt->cGreenBits; + blue = frmt->cBlueBits; + alpha = frmt->cAlphaBits; + depth = frmt->cDepthBits; + stencil = frmt->cStencilBits; + return new EglConfig(red,green,blue,alpha,caveat,(EGLint)index,depth,level,pMaxWidth,pMaxHeight,pMaxPixels,renderable,renderableType, + visualId,visualType,samples,stencil,supportedSurfaces,transparentType,tRed,tGreen,tBlue,*frmt); +} + + +void queryConfigs(EGLNativeInternalDisplayType display,int renderableType,ConfigsList& listOut) { + PIXELFORMATDESCRIPTOR pfd; + int iPixelFormat = 1; + HDC dpy = getDummyDC(display,WinDisplay::DEFAULT_DISPLAY); + + // + // We need to call wglChoosePixelFormat at least once, + // seems that the driver needs to initialize itself. + // do it here during initialization. + // + initPixelFormat(dpy); + + //quering num of formats + int nFormats = DescribePixelFormat(dpy, iPixelFormat,sizeof(PIXELFORMATDESCRIPTOR), &pfd); + + //inserting rest of formats + for(iPixelFormat;iPixelFormat < nFormats; iPixelFormat++) { + DescribePixelFormat(dpy, iPixelFormat,sizeof(PIXELFORMATDESCRIPTOR), &pfd); + EglConfig* pConfig = pixelFormatToConfig(display,renderableType,&pfd,iPixelFormat); + if(pConfig) listOut.push_back(pConfig); + } +} + +bool validNativeWin(EGLNativeInternalDisplayType dpy,EGLNativeWindowType win) { + return IsWindow(win); +} + +bool validNativeWin(EGLNativeInternalDisplayType dpy,EGLNativeSurfaceType win) { + if (!win) return false; + return validNativeWin(dpy,win->getHwnd()); +} + +bool validNativePixmap(EGLNativeInternalDisplayType dpy,EGLNativeSurfaceType pix) { + BITMAP bm; + if (!pix) return false; + return GetObject(pix->getBmap(), sizeof(BITMAP), (LPSTR)&bm); +} + +bool checkWindowPixelFormatMatch(EGLNativeInternalDisplayType dpy,EGLNativeWindowType win,EglConfig* cfg,unsigned int* width,unsigned int* height) { + RECT r; + if(!GetClientRect(win,&r)) return false; + *width = r.right - r.left; + *height = r.bottom - r.top; + HDC dc = GetDC(win); + EGLNativePixelFormatType nativeConfig = cfg->nativeConfig(); + bool ret = SetPixelFormat(dc,cfg->nativeId(),&nativeConfig); + DeleteDC(dc); + return ret; +} + +bool checkPixmapPixelFormatMatch(EGLNativeInternalDisplayType dpy,EGLNativePixmapType pix,EglConfig* cfg,unsigned int* width,unsigned int* height){ + + BITMAP bm; + if(!GetObject(pix, sizeof(BITMAP), (LPSTR)&bm)) return false; + + *width = bm.bmWidth; + *height = bm.bmHeight; + + return true; +} + +EGLNativeSurfaceType createPbufferSurface(EGLNativeInternalDisplayType display,EglConfig* cfg,EglPbufferSurface* pbSurface) { + + + HDC dpy = getDummyDC(display,cfg->nativeId()); + EGLint width,height,largest,texTarget,texFormat; + pbSurface->getDim(&width,&height,&largest); + pbSurface->getTexInfo(&texTarget,&texFormat); + + int wglTexFormat = WGL_NO_TEXTURE_ARB; + int wglTexTarget = (texTarget == EGL_TEXTURE_2D)? WGL_TEXTURE_2D_ARB: + WGL_NO_TEXTURE_ARB; + + switch(texFormat) { + case EGL_TEXTURE_RGB: + wglTexFormat = WGL_TEXTURE_RGB_ARB; + break; + case EGL_TEXTURE_RGBA: + wglTexFormat = WGL_TEXTURE_RGBA_ARB; + break; + } + + int pbAttribs[] = { + WGL_TEXTURE_TARGET_ARB ,wglTexTarget, + WGL_TEXTURE_FORMAT_ARB ,wglTexFormat, + 0 + }; + if(!s_wglExtProcs->wglCreatePbufferARB) return NULL; + EGLNativePbufferType pb = s_wglExtProcs->wglCreatePbufferARB(dpy,cfg->nativeId(),width,height,pbAttribs); + if(!pb) { + DWORD err = GetLastError(); + return NULL; + } + return new SrfcInfo(pb); +} + +bool releasePbuffer(EGLNativeInternalDisplayType display,EGLNativeSurfaceType pb) { + if (!pb) return false; + if(!s_wglExtProcs->wglReleasePbufferDCARB || !s_wglExtProcs->wglDestroyPbufferARB) return false; + if(!s_wglExtProcs->wglReleasePbufferDCARB(pb->getPbuffer(),pb->getDC()) || !s_wglExtProcs->wglDestroyPbufferARB(pb->getPbuffer())){ + DWORD err = GetLastError(); + return false; + } + return true; +} + +EGLNativeContextType createContext(EGLNativeInternalDisplayType display,EglConfig* cfg,EGLNativeContextType sharedContext) { + + EGLNativeContextType ctx = NULL; + HDC dpy = getDummyDC(display,cfg->nativeId()); + + if(!display->isPixelFormatSet(cfg->nativeId())){ + EGLNativePixelFormatType nativeConfig = cfg->nativeConfig(); + if(!SetPixelFormat(dpy,cfg->nativeId(),&nativeConfig)){ + return NULL; + } + display->pixelFormatWasSet(cfg->nativeId()); + } + + ctx = wglCreateContext(dpy); + + if(ctx && sharedContext) { + if(!wglShareLists(sharedContext,ctx)) { + wglDeleteContext(ctx); + return NULL; + } + } + return ctx; +} + +bool destroyContext(EGLNativeInternalDisplayType dpy,EGLNativeContextType ctx) { + if(!wglDeleteContext(ctx)) { + DWORD err = GetLastError(); + return false; + } + return true; +} + + +bool makeCurrent(EGLNativeInternalDisplayType display,EglSurface* read,EglSurface* draw,EGLNativeContextType ctx) { + + HDC hdcRead = read ? read->native()->getDC(): NULL; + HDC hdcDraw = draw ? draw->native()->getDC(): NULL; + bool retVal = false; + + + if(hdcRead == hdcDraw){ + bool ret = wglMakeCurrent(hdcDraw,ctx); + return ret; + } else if (!s_wglExtProcs->wglMakeContextCurrentARB ) { + return false; + } + retVal = s_wglExtProcs->wglMakeContextCurrentARB(hdcDraw,hdcRead,ctx); + + return retVal; +} + +void swapBuffers(EGLNativeInternalDisplayType display,EGLNativeSurfaceType srfc){ + if(srfc && !SwapBuffers(srfc->getDC())) { + DWORD err = GetLastError(); + } +} + + +void waitNative(){} + +void swapInterval(EGLNativeInternalDisplayType dpy,EGLNativeSurfaceType win,int interval) { + + if (s_wglExtProcs->wglSwapIntervalEXT){ + s_wglExtProcs->wglSwapIntervalEXT(interval); + } +} + +EGLNativeSurfaceType createWindowSurface(EGLNativeWindowType wnd){ + return new SrfcInfo(wnd); +} + +EGLNativeSurfaceType createPixmapSurface(EGLNativePixmapType pix){ + return new SrfcInfo(pix); +} + +void destroySurface(EGLNativeSurfaceType srfc){ + delete srfc; +} + + +}; diff --git a/emulator/opengl/host/libs/Translator/EGL/EglX11Api.cpp b/emulator/opengl/host/libs/Translator/EGL/EglX11Api.cpp new file mode 100644 index 0000000..a421db9 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/EglX11Api.cpp @@ -0,0 +1,310 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "EglOsApi.h" +#include <string.h> +#include <X11/Xlib.h> +#include <GL/glx.h> +#include <utils/threads.h> + + +class ErrorHandler{ +public: +ErrorHandler(EGLNativeDisplayType dpy); +~ErrorHandler(); +int getLastError(){ return s_lastErrorCode;}; + +private: +static int s_lastErrorCode; +int (*m_oldErrorHandler) (Display *, XErrorEvent *); +static android::Mutex s_lock; +static int errorHandlerProc(EGLNativeDisplayType dpy,XErrorEvent* event); + +}; + +class SrfcInfo{ +public: + typedef enum{ + WINDOW = 0, + PBUFFER = 1, + PIXMAP + }SurfaceType; + SrfcInfo(GLXDrawable drawable,SurfaceType type):m_type(type), + m_srfc(drawable){}; + GLXDrawable srfc(){return m_srfc;}; +private: + SurfaceType m_type; + GLXDrawable m_srfc; +}; + +int ErrorHandler::s_lastErrorCode = 0; +android::Mutex ErrorHandler::s_lock; + +ErrorHandler::ErrorHandler(EGLNativeDisplayType dpy){ + android::Mutex::Autolock mutex(s_lock); + XSync(dpy,False); + s_lastErrorCode = 0; + m_oldErrorHandler = XSetErrorHandler(errorHandlerProc); +} + +ErrorHandler::~ErrorHandler(){ + android::Mutex::Autolock mutex(s_lock); + XSetErrorHandler(m_oldErrorHandler); + s_lastErrorCode = 0; +} + +int ErrorHandler::errorHandlerProc(EGLNativeDisplayType dpy,XErrorEvent* event){ + android::Mutex::Autolock mutex(s_lock); + s_lastErrorCode = event->error_code; + return 0; +} + +#define IS_SUCCESS(a) \ + if(a != Success) return false; + +namespace EglOS { + +EGLNativeDisplayType getDefaultDisplay() {return XOpenDisplay(0);} + +bool releaseDisplay(EGLNativeDisplayType dpy) { + return XCloseDisplay(dpy); +} + +EglConfig* pixelFormatToConfig(EGLNativeDisplayType dpy,int renderableType,EGLNativePixelFormatType* frmt){ + + int bSize,red,green,blue,alpha,depth,stencil; + int supportedSurfaces,visualType,visualId; + int caveat,transparentType,samples; + int tRed=0,tGreen=0,tBlue=0; + int pMaxWidth,pMaxHeight,pMaxPixels; + int tmp; + int configId,level,renderable; + int doubleBuffer; + + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_TRANSPARENT_TYPE,&tmp)); + if(tmp == GLX_TRANSPARENT_INDEX) { + return NULL; // not supporting transparent index + } else if( tmp == GLX_NONE) { + transparentType = EGL_NONE; + } else { + transparentType = EGL_TRANSPARENT_RGB; + + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_TRANSPARENT_RED_VALUE,&tRed)); + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_TRANSPARENT_GREEN_VALUE,&tGreen)); + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_TRANSPARENT_BLUE_VALUE,&tBlue)); + } + + + // + // filter out single buffer configurations + // + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_DOUBLEBUFFER,&doubleBuffer)); + if (!doubleBuffer) return NULL; + + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_BUFFER_SIZE,&bSize)); + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_RED_SIZE,&red)); + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_GREEN_SIZE,&green)); + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_BLUE_SIZE,&blue)); + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_ALPHA_SIZE,&alpha)); + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_DEPTH_SIZE,&depth)); + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_STENCIL_SIZE,&stencil)); + + + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_X_RENDERABLE,&renderable)); + + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_X_VISUAL_TYPE,&visualType)); + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_VISUAL_ID,&visualId)); + + //supported surfaces types + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_DRAWABLE_TYPE,&tmp)); + supportedSurfaces = 0; + if(tmp & GLX_WINDOW_BIT && visualId != 0) { + supportedSurfaces |= EGL_WINDOW_BIT; + } else { + visualId = 0; + visualType = EGL_NONE; + } + if(tmp & GLX_PBUFFER_BIT) supportedSurfaces |= EGL_PBUFFER_BIT; + + caveat = 0; + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_CONFIG_CAVEAT,&tmp)); + if (tmp == GLX_NONE) caveat = EGL_NONE; + else if(tmp == GLX_SLOW_CONFIG) caveat = EGL_SLOW_CONFIG; + else if(tmp == GLX_NON_CONFORMANT_CONFIG) caveat = EGL_NON_CONFORMANT_CONFIG; + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_MAX_PBUFFER_WIDTH,&pMaxWidth)); + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_MAX_PBUFFER_HEIGHT,&pMaxHeight)); + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_MAX_PBUFFER_HEIGHT,&pMaxPixels)); + + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_LEVEL,&level)); + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_FBCONFIG_ID,&configId)); + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_SAMPLES,&samples)); + //Filter out configs that does not support RGBA + IS_SUCCESS(glXGetFBConfigAttrib(dpy,*frmt,GLX_RENDER_TYPE,&tmp)); + if (!(tmp & GLX_RGBA_BIT)) { + return NULL; + } + + return new EglConfig(red,green,blue,alpha,caveat,configId,depth,level,pMaxWidth,pMaxHeight, + pMaxPixels,renderable,renderableType,visualId,visualType,samples,stencil, + supportedSurfaces,transparentType,tRed,tGreen,tBlue,*frmt); +} + +void queryConfigs(EGLNativeDisplayType dpy,int renderableType,ConfigsList& listOut) { + int n; + EGLNativePixelFormatType* frmtList = glXGetFBConfigs(dpy,0,&n); + for(int i =0 ;i < n ; i++) { + EglConfig* conf = pixelFormatToConfig(dpy,renderableType,&frmtList[i]); + if(conf) listOut.push_back(conf); + } + XFree(frmtList); +} + +bool validNativeWin(EGLNativeDisplayType dpy,EGLNativeWindowType win) { + Window root; + int tmp; + unsigned int utmp; + ErrorHandler handler(dpy); + if(!XGetGeometry(dpy,win,&root,&tmp,&tmp,&utmp,&utmp,&utmp,&utmp)) return false; + return handler.getLastError() == 0; +} + +bool validNativeWin(EGLNativeDisplayType dpy,EGLNativeSurfaceType win) { + if (!win) return false; + return validNativeWin(dpy,win->srfc()); +} + +bool validNativePixmap(EGLNativeDisplayType dpy,EGLNativeSurfaceType pix) { + Window root; + int tmp; + unsigned int utmp; + ErrorHandler handler(dpy); + if(!XGetGeometry(dpy,pix ? pix->srfc() : NULL,&root,&tmp,&tmp,&utmp,&utmp,&utmp,&utmp)) return false; + return handler.getLastError() == 0; +} + +bool checkWindowPixelFormatMatch(EGLNativeDisplayType dpy,EGLNativeWindowType win,EglConfig* cfg,unsigned int* width,unsigned int* height) { +//TODO: to check what does ATI & NVIDIA enforce on win pixelformat + unsigned int depth,configDepth,border; + int r,g,b,x,y; + IS_SUCCESS(glXGetFBConfigAttrib(dpy,cfg->nativeConfig(),GLX_RED_SIZE,&r)); + IS_SUCCESS(glXGetFBConfigAttrib(dpy,cfg->nativeConfig(),GLX_GREEN_SIZE,&g)); + IS_SUCCESS(glXGetFBConfigAttrib(dpy,cfg->nativeConfig(),GLX_BLUE_SIZE,&b)); + configDepth = r + g + b; + Window root; + if(!XGetGeometry(dpy,win,&root,&x,&y,width,height,&border,&depth)) return false; + return depth >= configDepth; +} + +bool checkPixmapPixelFormatMatch(EGLNativeDisplayType dpy,EGLNativePixmapType pix,EglConfig* cfg,unsigned int* width,unsigned int* height) { + unsigned int depth,configDepth,border; + int r,g,b,x,y; + IS_SUCCESS(glXGetFBConfigAttrib(dpy,cfg->nativeConfig(),GLX_RED_SIZE,&r)); + IS_SUCCESS(glXGetFBConfigAttrib(dpy,cfg->nativeConfig(),GLX_GREEN_SIZE,&g)); + IS_SUCCESS(glXGetFBConfigAttrib(dpy,cfg->nativeConfig(),GLX_BLUE_SIZE,&b)); + configDepth = r + g + b; + Window root; + if(!XGetGeometry(dpy,pix,&root,&x,&y,width,height,&border,&depth)) return false; + return depth >= configDepth; +} + +EGLNativeSurfaceType createPbufferSurface(EGLNativeDisplayType dpy,EglConfig* cfg,EglPbufferSurface* srfc){ + EGLint width,height,largest; + srfc->getDim(&width,&height,&largest); + + int attribs[] = { + GLX_PBUFFER_WIDTH ,width, + GLX_PBUFFER_HEIGHT ,height, + GLX_LARGEST_PBUFFER ,largest, + None + }; + GLXPbuffer pb = glXCreatePbuffer(dpy,cfg->nativeConfig(),attribs); + return pb ? new SrfcInfo(pb,SrfcInfo::PBUFFER) : NULL; +} + +bool releasePbuffer(EGLNativeDisplayType dis,EGLNativeSurfaceType pb) { + if (!pb) return false; + glXDestroyPbuffer(dis,pb->srfc()); + + return true; +} + +EGLNativeContextType createContext(EGLNativeDisplayType dpy,EglConfig* cfg,EGLNativeContextType sharedContext) { + ErrorHandler handler(dpy); + EGLNativeContextType retVal = glXCreateNewContext(dpy,cfg->nativeConfig(),GLX_RGBA_TYPE,sharedContext,true); + return handler.getLastError() == 0 ? retVal : NULL; +} + +bool destroyContext(EGLNativeDisplayType dpy,EGLNativeContextType ctx) { + glXDestroyContext(dpy,ctx); + return true; +} + +bool makeCurrent(EGLNativeDisplayType dpy,EglSurface* read,EglSurface* draw,EGLNativeContextType ctx){ + + ErrorHandler handler(dpy); + bool retval = false; + if (!ctx && !read && !draw) { + // unbind + retval = glXMakeContextCurrent(dpy, NULL, NULL, NULL); + } + else if (ctx && read && draw) { + retval = glXMakeContextCurrent(dpy,draw->native()->srfc(),read->native()->srfc(),ctx); + } + return (handler.getLastError() == 0) && retval; +} + +void swapBuffers(EGLNativeDisplayType dpy,EGLNativeSurfaceType srfc){ + if (srfc) { + glXSwapBuffers(dpy,srfc->srfc()); + } +} + +void waitNative() { + glXWaitX(); +} + +void swapInterval(EGLNativeDisplayType dpy,EGLNativeSurfaceType win,int interval){ + const char* extensions = glXQueryExtensionsString(dpy,DefaultScreen(dpy)); + typedef void (*GLXSWAPINTERVALEXT)(Display*,GLXDrawable,int); + GLXSWAPINTERVALEXT glXSwapIntervalEXT = NULL; + + if(strstr(extensions,"EXT_swap_control")) { + glXSwapIntervalEXT = (GLXSWAPINTERVALEXT)glXGetProcAddress((const GLubyte*)"glXSwapIntervalEXT"); + } + if(glXSwapIntervalEXT && win) { + glXSwapIntervalEXT(dpy,win->srfc(),interval); + } +} + +EGLNativeSurfaceType createWindowSurface(EGLNativeWindowType wnd){ + return new SrfcInfo(wnd,SrfcInfo::WINDOW); +} + +EGLNativeSurfaceType createPixmapSurface(EGLNativePixmapType pix){ + return new SrfcInfo(pix,SrfcInfo::PIXMAP); +} + +void destroySurface(EGLNativeSurfaceType srfc){ + delete srfc; +}; + +EGLNativeInternalDisplayType getInternalDisplay(EGLNativeDisplayType dpy){ + return dpy; +} + +void deleteDisplay(EGLNativeInternalDisplayType idpy){ +} + +}; diff --git a/emulator/opengl/host/libs/Translator/EGL/MacNative.h b/emulator/opengl/host/libs/Translator/EGL/MacNative.h new file mode 100644 index 0000000..82ab667 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/MacNative.h @@ -0,0 +1,50 @@ +/* +* Copyright 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef MAC_NATIVE_H +#define MAC_NATIVE_H + +typedef enum { // Mac equivalence + MAC_HAS_DOUBLE_BUFFER = 5, // NSOpenGLPFADoubleBuffer + MAC_DRAW_TO_WINDOW = 80, // NSOpenGLPFAWindow + MAC_DRAW_TO_PBUFFER = 90, // NSOpenGLPFAPixelBuffer + MAC_SAMPLES_PER_PIXEL = 56, // NSOpenGLPFASamples + MAC_COLOR_SIZE = 8, // NSOpenGLPFAColorSize + MAC_ALPHA_SIZE = 11, // NSOpenGLPFAAlphaSize + MAC_DEPTH_SIZE = 12, // NSOpenGLPFADepthSize + MAC_STENCIL_SIZE = 13 // NSOpenGLPFAStencilSize + } MacPixelFormatAttribs; + + +extern "C"{ + +int getNumPixelFormats(); +void* getPixelFormat(int i); +void getPixelFormatAttrib(void* pixelFormat,int attrib,int* val); +void* nsCreateContext(void* format,void* share); +void nsWindowMakeCurrent(void* context,void* nativeWin); +void nsPBufferMakeCurrent(void* context,void* nativePBuffer,int level); +void nsSwapBuffers(); +void nsSwapInterval(int *interval); +void nsDestroyContext(void* context); +void* nsCreatePBuffer(GLenum target,GLenum format,int maxMip,int width,int height); +void nsDestroyPBuffer(void* pbuffer); +bool nsGetWinDims(void* win,unsigned int* width,unsigned int* height); +bool nsCheckColor(void* win,int colorSize); + +} + +#endif diff --git a/emulator/opengl/host/libs/Translator/EGL/MacNative.m b/emulator/opengl/host/libs/Translator/EGL/MacNative.m new file mode 100644 index 0000000..6828655 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/MacNative.m @@ -0,0 +1,179 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include <stdio.h> +#include <Cocoa/Cocoa.h> +#include <OpenGL/OpenGL.h> +#include "MacPixelFormatsAttribs.h" + +// +// EmuGLContext inherit from NSOpenGLContext +// and adds binding state for the context to know +// if it was last bounded to a pbuffer or a window. +// This is because after the context was bounded to +// a Pbuffer, before we bind it to a window we must +// release it form the pbuffer by calling the +// clearDrawable method. We do not want to call clearDrawable +// more than really needed since when it is called at a time +// that a window is bounded to the context it will clear the +// window content causing flickering effect. +// Thererfore we call clearDrawable only when we bind the context +// to a window and it was previously bound to a Pbuffer. +// +@interface EmuGLContext : NSOpenGLContext { + @private + int boundToPbuffer; + int boundToWin; +} + +- (id) initWithFormat:(NSOpenGLPixelFormat *)pixelFormat shareContext:(NSOpenGLContext *)share; +- (void) preBind:(int)forPbuffer; +@end + +@implementation EmuGLContext +- (id) initWithFormat:(NSOpenGLPixelFormat *)pixelFormat shareContext:(NSOpenGLContext *)share +{ + self = [super initWithFormat:pixelFormat shareContext:share]; + if (self != nil) { + boundToPbuffer = 0; + boundToWin = 0; + } + return self; +} + +- (void) preBind:(int)forPbuffer +{ + if ((!forPbuffer && boundToPbuffer)) { + [self clearDrawable]; + } + boundToPbuffer = forPbuffer; + boundToWin = !boundToPbuffer; +} +@end + +int getNumPixelFormats(){ + int size; + NSOpenGLPixelFormatAttribute** attrib_lists = getPixelFormatsAttributes(&size); + return size; +} + +void* getPixelFormat(int i){ + int size; + NSOpenGLPixelFormatAttribute** attrib_lists = getPixelFormatsAttributes(&size); + return [[NSOpenGLPixelFormat alloc] initWithAttributes:attrib_lists[i]]; +} + +void getPixelFormatAttrib(void* pixelFormat,int attrib,int* val){ + NSOpenGLPixelFormat *frmt = (NSOpenGLPixelFormat *)pixelFormat; + [frmt getValues:val forAttribute:attrib forVirtualScreen:0]; +} + +void* nsCreateContext(void* format,void* share){ + NSOpenGLPixelFormat* frmt = (NSOpenGLPixelFormat*)format; + return [[EmuGLContext alloc] initWithFormat:frmt shareContext:share]; +} + +void nsPBufferMakeCurrent(void* context,void* nativePBuffer,int level){ + EmuGLContext* ctx = (EmuGLContext *)context; + NSOpenGLPixelBuffer* pbuff = (NSOpenGLPixelBuffer *)nativePBuffer; + if(ctx == nil){ + [NSOpenGLContext clearCurrentContext]; + } else { + if(pbuff != nil){ + [ctx preBind:1]; + [ctx setPixelBuffer:pbuff cubeMapFace:0 mipMapLevel:level currentVirtualScreen:0]; + [ctx makeCurrentContext]; + } + } +} + +void nsWindowMakeCurrent(void* context,void* nativeWin){ + EmuGLContext* ctx = (EmuGLContext *)context; + NSView* win = (NSView *)nativeWin; + if(ctx == nil){ + [NSOpenGLContext clearCurrentContext]; + } else if (win != nil) { + [ctx preBind:0]; + [ctx setView: win]; + [ctx makeCurrentContext]; + } +} + +void nsSwapBuffers(){ + NSOpenGLContext* ctx = [NSOpenGLContext currentContext]; + if(ctx != nil){ + [ctx flushBuffer]; + } +} + +void nsSwapInterval(int *interval){ + NSOpenGLContext* ctx = [NSOpenGLContext currentContext]; + if( ctx != nil){ + [ctx setValues:interval forParameter:NSOpenGLCPSwapInterval]; + } +} + + +void nsDestroyContext(void* context){ + EmuGLContext *ctx = (EmuGLContext*)context; + if(ctx != nil){ + [ctx release]; + } +} + + +void* nsCreatePBuffer(GLenum target,GLenum format,int maxMip,int width,int height){ + return [[NSOpenGLPixelBuffer alloc] initWithTextureTarget:target + textureInternalFormat:format + textureMaxMipMapLevel:maxMip + pixelsWide:width pixelsHigh:height]; + +} + +void nsDestroyPBuffer(void* pbuffer){ + NSOpenGLPixelBuffer *pbuf = (NSOpenGLPixelBuffer*)pbuffer; + if(pbuf != nil){ + [pbuf release]; + } +} + +bool nsGetWinDims(void* win,unsigned int* width,unsigned int* height){ + NSView* view = (NSView*)win; + if(view != nil){ + NSRect rect = [view bounds]; + *width = rect.size.width; + *height = rect.size.height; + return true; + } + return false; +} + +bool nsCheckColor(void* win,int colorSize){ + NSView* view = (NSView*)win; + if(view != nil){ + NSWindow* wnd = [view window]; + if(wnd != nil){ + NSWindowDepth limit = [wnd depthLimit]; + NSWindowDepth defaultLimit = [NSWindow defaultDepthLimit]; + + int depth = (limit != 0) ? NSBitsPerPixelFromDepth(limit): + NSBitsPerPixelFromDepth(defaultLimit); + return depth >= colorSize; + + } + } + return false; + +} diff --git a/emulator/opengl/host/libs/Translator/EGL/MacPixelFormatsAttribs.h b/emulator/opengl/host/libs/Translator/EGL/MacPixelFormatsAttribs.h new file mode 100644 index 0000000..692ac22 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/MacPixelFormatsAttribs.h @@ -0,0 +1,23 @@ +/* +* Copyright 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef MAC_PIXELS_FORMATS_ATTRIBS_H +#define MAC_PIXELS_FORMATS_ATTRIBS_H + +#include <Cocoa/Cocoa.h> +NSOpenGLPixelFormatAttribute** getPixelFormatsAttributes(int* size); + +#endif diff --git a/emulator/opengl/host/libs/Translator/EGL/MacPixelFormatsAttribs.m b/emulator/opengl/host/libs/Translator/EGL/MacPixelFormatsAttribs.m new file mode 100644 index 0000000..f5bc49c --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/MacPixelFormatsAttribs.m @@ -0,0 +1,214 @@ +/* +* Copyright 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "MacPixelFormatsAttribs.h" + +static NSOpenGLPixelFormatAttribute attrs32_1[] = +{ + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAWindow, + NSOpenGLPFAPixelBuffer, + NSOpenGLPFAColorSize ,32, + NSOpenGLPFADepthSize ,24, + NSOpenGLPFAStencilSize ,8, + 0 +}; + +static NSOpenGLPixelFormatAttribute attrs32_2[] = +{ + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAWindow, + NSOpenGLPFAPixelBuffer, + NSOpenGLPFAColorSize ,32, + NSOpenGLPFAAlphaSize ,8, + NSOpenGLPFADepthSize ,24, + NSOpenGLPFAStencilSize ,8, + 0 +}; + +static NSOpenGLPixelFormatAttribute attrs32_3[] = +{ + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAWindow, + NSOpenGLPFAPixelBuffer, + NSOpenGLPFAColorSize ,32, + NSOpenGLPFAAlphaSize ,8, + 0 +}; + +static NSOpenGLPixelFormatAttribute attrs32_4[] = +{ + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAWindow, + NSOpenGLPFAPixelBuffer, + NSOpenGLPFAColorSize ,32, + 0 +}; + +static NSOpenGLPixelFormatAttribute attrs32_5[] = +{ + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAWindow, + NSOpenGLPFAPixelBuffer, + NSOpenGLPFAColorSize ,32, + NSOpenGLPFADepthSize ,24, + NSOpenGLPFASamples ,2, + 0 +}; + +static NSOpenGLPixelFormatAttribute attrs32_6[] = +{ + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAWindow, + NSOpenGLPFAPixelBuffer, + NSOpenGLPFAColorSize ,32, + NSOpenGLPFADepthSize ,24, + NSOpenGLPFASamples ,4, + 0 +}; + +static NSOpenGLPixelFormatAttribute attrs32_7[] = +{ + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAWindow, + NSOpenGLPFAPixelBuffer, + NSOpenGLPFAColorSize ,32, + NSOpenGLPFAAlphaSize ,8, + NSOpenGLPFADepthSize ,24, + NSOpenGLPFAStencilSize ,8, + NSOpenGLPFASamples ,4, + 0 +}; + +static NSOpenGLPixelFormatAttribute attrs16_1[] = +{ + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAWindow, + NSOpenGLPFAPixelBuffer, + NSOpenGLPFAColorSize ,16, + NSOpenGLPFADepthSize ,24, + 0 +}; + +static NSOpenGLPixelFormatAttribute attrs16_2[] = +{ + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAWindow, + NSOpenGLPFAPixelBuffer, + NSOpenGLPFAColorSize ,16, + NSOpenGLPFADepthSize ,24, + NSOpenGLPFAStencilSize ,8, + 0 +}; + +static NSOpenGLPixelFormatAttribute attrs64_1[] = +{ + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAWindow, + NSOpenGLPFAPixelBuffer, + NSOpenGLPFAColorSize ,64, + NSOpenGLPFAAlphaSize ,16, + 0 +}; + +static NSOpenGLPixelFormatAttribute attrs64_2[] = +{ + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAWindow, + NSOpenGLPFAPixelBuffer, + NSOpenGLPFAColorSize ,64, + NSOpenGLPFAAlphaSize ,16, + NSOpenGLPFADepthSize ,24, + NSOpenGLPFAStencilSize ,8, + 0 +}; + +static NSOpenGLPixelFormatAttribute attrs64_3[] = +{ + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAWindow, + NSOpenGLPFAPixelBuffer, + NSOpenGLPFAColorSize ,64, + NSOpenGLPFAAlphaSize ,16, + NSOpenGLPFADepthSize ,24, + 0 +}; + +static NSOpenGLPixelFormatAttribute attrs64_4[] = +{ + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAWindow, + NSOpenGLPFAPixelBuffer, + NSOpenGLPFAColorSize ,64, + NSOpenGLPFADepthSize ,24, + 0 +}; + +static NSOpenGLPixelFormatAttribute attrs64_5[] = +{ + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAWindow, + NSOpenGLPFAPixelBuffer, + NSOpenGLPFAColorSize ,64, + NSOpenGLPFADepthSize ,24, + NSOpenGLPFAStencilSize ,8, + 0 +}; + +static NSOpenGLPixelFormatAttribute attrs128_1[] = +{ + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAWindow, + NSOpenGLPFAPixelBuffer, + NSOpenGLPFAColorSize ,128, + NSOpenGLPFAAlphaSize ,32, + 0 +}; + +static NSOpenGLPixelFormatAttribute attrs128_2[] = +{ + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAWindow, + NSOpenGLPFAPixelBuffer, + NSOpenGLPFAColorSize ,128, + NSOpenGLPFAAlphaSize ,32, + NSOpenGLPFADepthSize ,24, + 0 +}; + +NSOpenGLPixelFormatAttribute** getPixelFormatsAttributes(int* size){ +static NSOpenGLPixelFormatAttribute* arr[] = +{ + attrs16_1, + attrs16_2, + attrs32_1, + attrs32_2, + attrs32_3, + attrs32_4, + attrs32_5, + attrs32_6, + attrs32_7, + attrs64_1, + attrs64_2, + attrs64_3, + attrs64_4, + attrs64_5, + attrs128_1, + attrs128_2 +}; + *size = sizeof(arr)/sizeof(arr[0]); + return arr; +} diff --git a/emulator/opengl/host/libs/Translator/EGL/ThreadInfo.cpp b/emulator/opengl/host/libs/Translator/EGL/ThreadInfo.cpp new file mode 100644 index 0000000..d1d018f --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/ThreadInfo.cpp @@ -0,0 +1,67 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "ThreadInfo.h" + + +void ThreadInfo::updateInfo(ContextPtr eglCtx, + EglDisplay* dpy, + GLEScontext* glesCtx, + ShareGroupPtr share, + ObjectNameManager* manager) { + + eglContext = eglCtx; + eglDisplay = dpy; + glesContext = glesCtx; + shareGroup = share; + objManager = manager; +} + +#ifdef __linux__ + +__thread ThreadInfo* thread = NULL; + +ThreadInfo* getThreadInfo(){ + if(!thread) { + thread = new ThreadInfo(); + } + return thread; +} + +#else + +#include <cutils/threads.h> +static thread_store_t s_tls = THREAD_STORE_INITIALIZER; + +static void tlsDestruct(void *ptr) +{ + if (ptr) { + ThreadInfo *ti = (ThreadInfo *)ptr; + delete ti; + } +} + +ThreadInfo *getThreadInfo() +{ + ThreadInfo *ti = (ThreadInfo *)thread_store_get(&s_tls); + if (!ti) { + ti = new ThreadInfo(); + thread_store_set(&s_tls, ti, tlsDestruct); + } + return ti; +} + +#endif diff --git a/emulator/opengl/host/libs/Translator/EGL/ThreadInfo.h b/emulator/opengl/host/libs/Translator/EGL/ThreadInfo.h new file mode 100644 index 0000000..ffc6e5f --- /dev/null +++ b/emulator/opengl/host/libs/Translator/EGL/ThreadInfo.h @@ -0,0 +1,42 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef THREAD_INFO_H +#define THREAD_INFO_H + +#include "EglContext.h" + +class EglDisplay; +class GLEScontext; + +struct ThreadInfo { + ThreadInfo():eglDisplay(NULL),glesContext(NULL),objManager(NULL){} + + void updateInfo(ContextPtr eglctx, + EglDisplay* dpy, + GLEScontext* glesCtx, + ShareGroupPtr share, + ObjectNameManager* manager); + + ContextPtr eglContext; + EglDisplay* eglDisplay; + GLEScontext* glesContext; + ShareGroupPtr shareGroup; + ObjectNameManager* objManager; +}; + +ThreadInfo* getThreadInfo(); + +#endif diff --git a/emulator/opengl/host/libs/Translator/GLES_CM/Android.mk b/emulator/opengl/host/libs/Translator/GLES_CM/Android.mk new file mode 100644 index 0000000..9aa74a7 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLES_CM/Android.mk @@ -0,0 +1,28 @@ +LOCAL_PATH := $(call my-dir) + +host_common_SRC_FILES := \ + GLEScmImp.cpp \ + GLEScmUtils.cpp \ + GLEScmContext.cpp \ + GLEScmValidate.cpp + + +### GLES_CM host implementation (On top of OpenGL) ######################## +$(call emugl-begin-host-shared-library,libGLES_CM_translator) + +$(call emugl-import,libGLcommon) + +LOCAL_SRC_FILES := $(host_common_SRC_FILES) + +$(call emugl-end-module) + + +### GLES_CM host implementation, 64-bit ######################## +$(call emugl-begin-host-shared-library,lib64GLES_CM_translator) + +$(call emugl-import,lib64GLcommon) + +LOCAL_LDLIBS += -m64 +LOCAL_SRC_FILES := $(host_common_SRC_FILES) + +$(call emugl-end-module) diff --git a/emulator/opengl/host/libs/Translator/GLES_CM/GLDispatch.cpp b/emulator/opengl/host/libs/Translator/GLES_CM/GLDispatch.cpp new file mode 100644 index 0000000..af5c0d8 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLES_CM/GLDispatch.cpp @@ -0,0 +1,178 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "GLDispatch.h" +#include <stdio.h> +#include <OpenglOsUtils/osDynLibrary.h> + +#ifdef __linux__ +#include <GL/glx.h> +#elif defined(WIN32) +#include <windows.h> +#endif + +typedef void (*GL_FUNC_PTR)(); + +static GL_FUNC_PTR getGLFuncAddress(const char *funcName) { + GL_FUNC_PTR ret = NULL; +#ifdef __linux__ + static osUtils::dynLibrary* libGL = osUtils::dynLibrary::open("libGL.so"); + ret = (GL_FUNC_PTR)glXGetProcAddress((const GLubyte*)funcName); +#elif defined(WIN32) + static osUtils::dynLibrary* libGL = osUtils::dynLibrary::open("opengl32"); + ret = (GL_FUNC_PTR)wglGetProcAddress(funcName); +#endif + if(!ret && libGL){ + ret = libGL->findSymbol(funcName); + } + return ret; +} + +#define LOAD_GL_FUNC(name) { void * funcAddrs = NULL; \ + funcAddrs = (void *)getGLFuncAddress(#name); \ + if(funcAddrs) \ + *(void**)(&name) = funcAddrs; \ + else \ + fprintf(stderr,"could not load func %s\n",#name); } + +GLDispatch::GLDispatch():m_isLoaded(false){}; + + +void GLDispatch::dispatchFuncs() { + android::Mutex::Autolock mutex(m_lock); + if(m_isLoaded) + return; + LOAD_GL_FUNC(glActiveTexture); + LOAD_GL_FUNC(glAlphaFunc); + LOAD_GL_FUNC(glBegin); + LOAD_GL_FUNC(glBindBuffer); + LOAD_GL_FUNC(glBindTexture); + LOAD_GL_FUNC(glBlendFunc); + LOAD_GL_FUNC(glBufferData); + LOAD_GL_FUNC(glBufferSubData); + LOAD_GL_FUNC(glClear); + LOAD_GL_FUNC(glClearColor); + LOAD_GL_FUNC(glClearDepth); + LOAD_GL_FUNC(glClearStencil); + LOAD_GL_FUNC(glClientActiveTexture); + LOAD_GL_FUNC(glClipPlane); + LOAD_GL_FUNC(glColor4d); + LOAD_GL_FUNC(glColor4f); + LOAD_GL_FUNC(glColor4fv); + LOAD_GL_FUNC(glColor4ub); + LOAD_GL_FUNC(glColor4ubv); + LOAD_GL_FUNC(glColorMask); + LOAD_GL_FUNC(glColorPointer); + LOAD_GL_FUNC(glCompressedTexImage2D); + LOAD_GL_FUNC(glCompressedTexSubImage2D); + LOAD_GL_FUNC(glCopyTexImage2D); + LOAD_GL_FUNC(glCopyTexSubImage2D); + LOAD_GL_FUNC(glCullFace); + LOAD_GL_FUNC(glDeleteBuffers); + LOAD_GL_FUNC(glDeleteTextures); + LOAD_GL_FUNC(glDepthFunc); + LOAD_GL_FUNC(glDepthMask); + LOAD_GL_FUNC(glDepthRange); + LOAD_GL_FUNC(glDisable); + LOAD_GL_FUNC(glDisableClientState); + LOAD_GL_FUNC(glDrawArrays); + LOAD_GL_FUNC(glDrawElements); + LOAD_GL_FUNC(glEnable); + LOAD_GL_FUNC(glEnableClientState); + LOAD_GL_FUNC(glEnd); + LOAD_GL_FUNC(glFinish); + LOAD_GL_FUNC(glFlush); + LOAD_GL_FUNC(glFogf); + LOAD_GL_FUNC(glFogfv); + LOAD_GL_FUNC(glFrontFace); + LOAD_GL_FUNC(glFrustum); + LOAD_GL_FUNC(glGenBuffers); + LOAD_GL_FUNC(glGenTextures); + LOAD_GL_FUNC(glGetBooleanv); + LOAD_GL_FUNC(glGetBufferParameteriv); + LOAD_GL_FUNC(glGetClipPlane); + LOAD_GL_FUNC(glGetDoublev); + LOAD_GL_FUNC(glGetError); + LOAD_GL_FUNC(glGetFloatv); + LOAD_GL_FUNC(glGetIntegerv); + LOAD_GL_FUNC(glGetLightfv); + LOAD_GL_FUNC(glGetMaterialfv); + LOAD_GL_FUNC(glGetPointerv); + LOAD_GL_FUNC(glGetString); + LOAD_GL_FUNC(glGetTexEnvfv); + LOAD_GL_FUNC(glGetTexEnviv); + LOAD_GL_FUNC(glGetTexParameterfv); + LOAD_GL_FUNC(glGetTexParameteriv); + LOAD_GL_FUNC(glHint); + LOAD_GL_FUNC(glIsBuffer); + LOAD_GL_FUNC(glIsEnabled); + LOAD_GL_FUNC(glIsTexture); + LOAD_GL_FUNC(glLightf); + LOAD_GL_FUNC(glLightfv); + LOAD_GL_FUNC(glLightModelf); + LOAD_GL_FUNC(glLightModelfv); + LOAD_GL_FUNC(glLineWidth); + LOAD_GL_FUNC(glLoadIdentity); + LOAD_GL_FUNC(glLoadMatrixf); + LOAD_GL_FUNC(glLogicOp); + LOAD_GL_FUNC(glMaterialf); + LOAD_GL_FUNC(glMaterialfv); + LOAD_GL_FUNC(glMultiTexCoord2fv); + LOAD_GL_FUNC(glMultiTexCoord2sv); + LOAD_GL_FUNC(glMultiTexCoord3fv); + LOAD_GL_FUNC(glMultiTexCoord3sv); + LOAD_GL_FUNC(glMultiTexCoord4fv); + LOAD_GL_FUNC(glMultiTexCoord4sv); + LOAD_GL_FUNC(glMultiTexCoord4f); + LOAD_GL_FUNC(glMultMatrixf); + LOAD_GL_FUNC(glNormal3f); + LOAD_GL_FUNC(glNormal3fv); + LOAD_GL_FUNC(glNormal3sv); + LOAD_GL_FUNC(glOrtho); + LOAD_GL_FUNC(glPointParameterf); + LOAD_GL_FUNC(glPointParameterfv); + LOAD_GL_FUNC(glPointSize); + LOAD_GL_FUNC(glPolygonOffset); + LOAD_GL_FUNC(glRotatef); + LOAD_GL_FUNC(glScalef); + LOAD_GL_FUNC(glTexEnvf); + LOAD_GL_FUNC(glTexEnvfv); + LOAD_GL_FUNC(glTexParameterf); + LOAD_GL_FUNC(glTexParameterfv); + LOAD_GL_FUNC(glMatrixMode); + LOAD_GL_FUNC(glNormalPointer); + LOAD_GL_FUNC(glPixelStorei); + LOAD_GL_FUNC(glPopMatrix); + LOAD_GL_FUNC(glPushMatrix); + LOAD_GL_FUNC(glReadPixels); + LOAD_GL_FUNC(glSampleCoverage); + LOAD_GL_FUNC(glScissor); + LOAD_GL_FUNC(glShadeModel); + LOAD_GL_FUNC(glStencilFunc); + LOAD_GL_FUNC(glStencilMask); + LOAD_GL_FUNC(glStencilOp); + LOAD_GL_FUNC(glTexCoordPointer); + LOAD_GL_FUNC(glTexEnvi); + LOAD_GL_FUNC(glTexEnviv); + LOAD_GL_FUNC(glTexImage2D); + LOAD_GL_FUNC(glTexParameteri); + LOAD_GL_FUNC(glTexParameteriv); + LOAD_GL_FUNC(glTexSubImage2D); + LOAD_GL_FUNC(glTranslatef); + LOAD_GL_FUNC(glVertexPointer); + LOAD_GL_FUNC(glViewport); + + m_isLoaded = true; +} diff --git a/emulator/opengl/host/libs/Translator/GLES_CM/GLDispatch.h b/emulator/opengl/host/libs/Translator/GLES_CM/GLDispatch.h new file mode 100644 index 0000000..9dc320f --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLES_CM/GLDispatch.h @@ -0,0 +1,158 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef GLDISPATCHH +#define GLDISPATCHH + +#include <GLES/gl.h> +#include <utils/threads.h> + +#define GLAPIENTRY GL_APIENTRY + +typedef double GLclampd; /* double precision float in [0,1] */ +typedef double GLdouble; /* double precision float */ + +class GLDispatch +{ +public: + + GLDispatch(); + void dispatchFuncs(); + + void (GLAPIENTRY *glActiveTexture) ( GLenum texture ); + void (GLAPIENTRY *glAlphaFunc) (GLenum func, GLclampf ref); + void (GLAPIENTRY *glBegin)( GLenum mode ); + void (GLAPIENTRY *glBindBuffer) (GLenum target, GLuint buffer); + void (GLAPIENTRY *glBindTexture) (GLenum target, GLuint texture); + void (GLAPIENTRY *glBlendFunc) (GLenum sfactor, GLenum dfactor); + void (GLAPIENTRY *glBufferData) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); + void (GLAPIENTRY *glBufferSubData) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); + void (GLAPIENTRY *glClear) (GLbitfield mask); + void (GLAPIENTRY *glClearColor) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); + void (GLAPIENTRY *glClearDepth) (GLclampd depth); + void (GLAPIENTRY *glClearStencil) (GLint s); + void (GLAPIENTRY *glClientActiveTexture) ( GLenum texture ); + void (GLAPIENTRY *glClipPlane) (GLenum plane, const GLdouble *equation); + void (GLAPIENTRY *glColor4d) (GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha); + void (GLAPIENTRY *glColor4f) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); + void (GLAPIENTRY *glColor4fv) ( const GLfloat *v ); + void (GLAPIENTRY *glColor4ub) (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); + void (GLAPIENTRY *glColor4ubv) ( const GLubyte *v ); + void (GLAPIENTRY *glColorMask) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); + void (GLAPIENTRY *glColorPointer) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); + void (GLAPIENTRY *glCompressedTexImage2D) ( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data ); + void (GLAPIENTRY *glCompressedTexSubImage2D) ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data ); + void (GLAPIENTRY *glCopyTexImage2D) (GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); + void (GLAPIENTRY *glCopyTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); + void (GLAPIENTRY *glCullFace) (GLenum mode); + void (GLAPIENTRY *glDeleteBuffers) (GLsizei n, const GLuint *buffers); + void (GLAPIENTRY *glDeleteTextures) (GLsizei n, const GLuint *textures); + void (GLAPIENTRY *glDepthFunc) (GLenum func); + void (GLAPIENTRY *glDepthMask) (GLboolean flag); + void (GLAPIENTRY *glDepthRange) (GLclampd zNear, GLclampd zFar); + void (GLAPIENTRY *glDisable) (GLenum cap); + void (GLAPIENTRY *glDisableClientState) (GLenum array); + void (GLAPIENTRY *glDrawArrays) (GLenum mode, GLint first, GLsizei count); + void (GLAPIENTRY *glDrawElements) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); + void (GLAPIENTRY *glEnable) (GLenum cap); + void (GLAPIENTRY *glEnableClientState) (GLenum array); + void (GLAPIENTRY *glEnd) ( void ); + void (GLAPIENTRY *glFinish) (void); + void (GLAPIENTRY *glFlush) (void); + void (GLAPIENTRY *glFogf) (GLenum pname, GLfloat param); + void (GLAPIENTRY *glFogfv) (GLenum pname, const GLfloat *params); + void (GLAPIENTRY *glFrontFace) (GLenum mode); + void (GLAPIENTRY *glFrustum) (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); + void (GLAPIENTRY *glGenBuffers) (GLsizei n, GLuint *buffers); + void (GLAPIENTRY *glGenTextures) (GLsizei n, GLuint *textures); + void (GLAPIENTRY *glGetBooleanv) (GLenum pname, GLboolean *params); + void (GLAPIENTRY *glGetBufferParameteriv) (GLenum, GLenum, GLint *); + void (GLAPIENTRY *glGetClipPlane) (GLenum plane, GLdouble *equation); + void (GLAPIENTRY *glGetDoublev) ( GLenum pname, GLdouble *params ); + GLenum (GLAPIENTRY *glGetError) (void); + void (GLAPIENTRY *glGetFloatv) (GLenum pname, GLfloat *params); + void (GLAPIENTRY *glGetIntegerv) (GLenum pname, GLint *params); + void (GLAPIENTRY *glGetLightfv) (GLenum light, GLenum pname, GLfloat *params); + void (GLAPIENTRY *glGetMaterialfv) (GLenum face, GLenum pname, GLfloat *params); + void (GLAPIENTRY *glGetPointerv) (GLenum pname, GLvoid* *params); + const GLubyte * (GLAPIENTRY *glGetString) (GLenum name); + void (GLAPIENTRY *glGetTexEnvfv) (GLenum target, GLenum pname, GLfloat *params); + void (GLAPIENTRY *glGetTexEnviv) (GLenum target, GLenum pname, GLint *params); + void (GLAPIENTRY *glGetTexParameterfv) (GLenum target, GLenum pname, GLfloat *params); + void (GLAPIENTRY *glGetTexParameteriv) (GLenum target, GLenum pname, GLint *params); + void (GLAPIENTRY *glHint) (GLenum target, GLenum mode); + GLboolean (GLAPIENTRY *glIsBuffer) (GLuint); + GLboolean (GLAPIENTRY *glIsEnabled) (GLenum cap); + GLboolean (GLAPIENTRY *glIsTexture) (GLuint texture); + void (GLAPIENTRY *glLightf) (GLenum light, GLenum pname, GLfloat param); + void (GLAPIENTRY *glLightfv) (GLenum light, GLenum pname, const GLfloat *params); + void (GLAPIENTRY *glLightModelf) (GLenum pname, GLfloat param); + void (GLAPIENTRY *glLightModelfv) (GLenum pname, const GLfloat *params); + void (GLAPIENTRY *glLineWidth) (GLfloat width); + void (GLAPIENTRY *glLoadIdentity) (void); + void (GLAPIENTRY *glLoadMatrixf) (const GLfloat *m); + void (GLAPIENTRY *glLogicOp) (GLenum opcode); + void (GLAPIENTRY *glMaterialf) (GLenum face, GLenum pname, GLfloat param); + void (GLAPIENTRY *glMaterialfv) (GLenum face, GLenum pname, const GLfloat *params); + void (GLAPIENTRY *glMultiTexCoord2fv) ( GLenum target, const GLfloat *v ); + void (GLAPIENTRY *glMultiTexCoord2sv) ( GLenum target, const GLshort *v ); + void (GLAPIENTRY *glMultiTexCoord3fv) ( GLenum target, const GLfloat *v ); + void (GLAPIENTRY *glMultiTexCoord3sv) ( GLenum target, const GLshort *v ); + void (GLAPIENTRY *glMultiTexCoord4f) ( GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q ); + void (GLAPIENTRY *glMultiTexCoord4fv) ( GLenum target, const GLfloat *v ); + void (GLAPIENTRY *glMultiTexCoord4sv) ( GLenum target, const GLshort *v ); + void (GLAPIENTRY *glMultMatrixf) (const GLfloat *m); + void (GLAPIENTRY *glNormal3f) (GLfloat nx, GLfloat ny, GLfloat nz); + void (GLAPIENTRY *glNormal3fv) ( const GLfloat *v ); + void (GLAPIENTRY *glNormal3sv) ( const GLshort *v ); + void (GLAPIENTRY *glOrtho) (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); + void (GLAPIENTRY *glPointParameterf) (GLenum, GLfloat); + void (GLAPIENTRY *glPointParameterfv) (GLenum, const GLfloat *); + void (GLAPIENTRY *glPointSize) (GLfloat size); + void (GLAPIENTRY *glPolygonOffset) (GLfloat factor, GLfloat units); + void (GLAPIENTRY *glRotatef) (GLfloat angle, GLfloat x, GLfloat y, GLfloat z); + void (GLAPIENTRY *glScalef) (GLfloat x, GLfloat y, GLfloat z); + void (GLAPIENTRY *glTexEnvf) (GLenum target, GLenum pname, GLfloat param); + void (GLAPIENTRY *glTexEnvfv) (GLenum target, GLenum pname, const GLfloat *params); + void (GLAPIENTRY *glTexParameterf) (GLenum target, GLenum pname, GLfloat param); + void (GLAPIENTRY *glTexParameterfv) (GLenum target, GLenum pname, const GLfloat *params); + void (GLAPIENTRY *glMatrixMode) (GLenum mode); + void (GLAPIENTRY *glNormalPointer) (GLenum type, GLsizei stride, const GLvoid *pointer); + void (GLAPIENTRY *glPixelStorei) (GLenum pname, GLint param); + void (GLAPIENTRY *glPopMatrix) (void); + void (GLAPIENTRY *glPushMatrix) (void); + void (GLAPIENTRY *glReadPixels) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); + void (GLAPIENTRY *glSampleCoverage) ( GLclampf value, GLboolean invert ); + void (GLAPIENTRY *glScissor) (GLint x, GLint y, GLsizei width, GLsizei height); + void (GLAPIENTRY *glShadeModel) (GLenum mode); + void (GLAPIENTRY *glStencilFunc) (GLenum func, GLint ref, GLuint mask); + void (GLAPIENTRY *glStencilMask) (GLuint mask); + void (GLAPIENTRY *glStencilOp) (GLenum fail, GLenum zfail, GLenum zpass); + void (GLAPIENTRY *glTexCoordPointer) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); + void (GLAPIENTRY *glTexEnvi) (GLenum target, GLenum pname, GLint param); + void (GLAPIENTRY *glTexEnviv) (GLenum target, GLenum pname, const GLint *params); + void (GLAPIENTRY *glTexImage2D) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); + void (GLAPIENTRY *glTexParameteri) (GLenum target, GLenum pname, GLint param); + void (GLAPIENTRY *glTexParameteriv) (GLenum target, GLenum pname, const GLint *params); + void (GLAPIENTRY *glTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); + void (GLAPIENTRY *glTranslatef) (GLfloat x, GLfloat y, GLfloat z); + void (GLAPIENTRY *glVertexPointer) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); + void (GLAPIENTRY *glViewport) (GLint x, GLint y, GLsizei width, GLsizei height); +private: + bool m_isLoaded; + android::Mutex m_lock; +}; + +#endif diff --git a/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.cpp b/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.cpp new file mode 100644 index 0000000..abf461c --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.cpp @@ -0,0 +1,420 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "GLEScmContext.h" +#include "GLEScmUtils.h" +#include <GLcommon/GLutils.h> +#include <GLcommon/GLconversion_macros.h> +#include <string.h> +#include <GLES/gl.h> +#include <GLES/glext.h> + +void GLEScmContext::init() { + android::Mutex::Autolock mutex(s_lock); + if(!m_initialized) { + s_glDispatch.dispatchFuncs(GLES_1_1); + GLEScontext::init(); + + m_texCoords = new GLESpointer[s_glSupport.maxTexUnits]; + m_map[GL_TEXTURE_COORD_ARRAY] = &m_texCoords[m_clientActiveTexture]; + + const char* baseRenderer = (const char*)dispatcher().glGetString(GL_RENDERER); + size_t baseRendererLen = strlen(baseRenderer); + s_glRenderer.clear(); + s_glRenderer.reserve(19 + baseRendererLen); + s_glRenderer.append("OpenGL ES-CM 1.1 (", 18); + s_glRenderer.append(baseRenderer, baseRendererLen); + s_glRenderer.append(")", 1); + } + m_initialized = true; +} + +GLEScmContext::GLEScmContext():GLEScontext(),m_texCoords(NULL),m_pointsIndex(-1), m_clientActiveTexture(0) { + + m_map[GL_COLOR_ARRAY] = new GLESpointer(); + m_map[GL_NORMAL_ARRAY] = new GLESpointer(); + m_map[GL_VERTEX_ARRAY] = new GLESpointer(); + m_map[GL_POINT_SIZE_ARRAY_OES] = new GLESpointer(); +} + + +void GLEScmContext::setActiveTexture(GLenum tex) { + m_activeTexture = tex - GL_TEXTURE0; +} + +void GLEScmContext::setClientActiveTexture(GLenum tex) { + m_clientActiveTexture = tex - GL_TEXTURE0; + m_map[GL_TEXTURE_COORD_ARRAY] = &m_texCoords[m_clientActiveTexture]; +} + +GLEScmContext::~GLEScmContext(){ + if(m_texCoords){ + delete[] m_texCoords; + m_texCoords = NULL; + } + m_map[GL_TEXTURE_COORD_ARRAY] = NULL; +} + + +//setting client side arr +void GLEScmContext::setupArr(const GLvoid* arr,GLenum arrayType,GLenum dataType,GLint size,GLsizei stride,GLboolean normalized, int index){ + if( arr == NULL) return; + switch(arrayType) { + case GL_VERTEX_ARRAY: + s_glDispatch.glVertexPointer(size,dataType,stride,arr); + break; + case GL_NORMAL_ARRAY: + s_glDispatch.glNormalPointer(dataType,stride,arr); + break; + case GL_TEXTURE_COORD_ARRAY: + s_glDispatch.glTexCoordPointer(size,dataType,stride,arr); + break; + case GL_COLOR_ARRAY: + s_glDispatch.glColorPointer(size,dataType,stride,arr); + break; + case GL_POINT_SIZE_ARRAY_OES: + m_pointsIndex = index; + break; + } +} + + +void GLEScmContext::setupArrayPointerHelper(GLESConversionArrays& cArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLenum array_id,GLESpointer* p){ + unsigned int size = p->getSize(); + GLenum dataType = p->getType(); + + if(needConvert(cArrs,first,count,type,indices,direct,p,array_id)){ + //conversion has occured + ArrayData currentArr = cArrs.getCurrentArray(); + setupArr(currentArr.data,array_id,currentArr.type,size,currentArr.stride,GL_FALSE, cArrs.getCurrentIndex()); + ++cArrs; + } else { + setupArr(p->getData(),array_id,dataType,size,p->getStride(), GL_FALSE); + } +} + +void GLEScmContext::setupArraysPointers(GLESConversionArrays& cArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct) { + ArraysMap::iterator it; + m_pointsIndex = -1; + + //going over all clients arrays Pointers + for ( it=m_map.begin() ; it != m_map.end(); it++ ) { + + GLenum array_id = (*it).first; + GLESpointer* p = (*it).second; + if(!isArrEnabled(array_id)) continue; + if(array_id == GL_TEXTURE_COORD_ARRAY) continue; //handling textures later + setupArrayPointerHelper(cArrs,first,count,type,indices,direct,array_id,p); + } + + unsigned int activeTexture = m_clientActiveTexture + GL_TEXTURE0; + + s_lock.lock(); + int maxTexUnits = s_glSupport.maxTexUnits; + s_lock.unlock(); + + //converting all texture coords arrays + for(int i=0; i< maxTexUnits;i++) { + + unsigned int tex = GL_TEXTURE0+i; + setClientActiveTexture(tex); + s_glDispatch.glClientActiveTexture(tex); + + GLenum array_id = GL_TEXTURE_COORD_ARRAY; + GLESpointer* p = m_map[array_id]; + if(!isArrEnabled(array_id)) continue; + setupArrayPointerHelper(cArrs,first,count,type,indices,direct,array_id,p); + } + + setClientActiveTexture(activeTexture); + s_glDispatch.glClientActiveTexture(activeTexture); +} + +void GLEScmContext::drawPointsData(GLESConversionArrays& cArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices_in,bool isElemsDraw) { + const char *pointsArr = NULL; + int stride = 0; + GLESpointer* p = m_map[GL_POINT_SIZE_ARRAY_OES]; + + //choosing the right points sizes array source + if(m_pointsIndex >= 0) { //point size array was converted + pointsArr = (const char*)(cArrs[m_pointsIndex].data); + stride = cArrs[m_pointsIndex].stride; + } else { + pointsArr = static_cast<const char*>(p->getData()); + stride = p->getStride(); + } + + if(stride == 0){ + stride = sizeof(GLfloat); + } + + + if(isElemsDraw) { + int tSize = type == GL_UNSIGNED_SHORT ? 2 : 1; + + int i = 0; + while(i<count) + { + int sStart = i; + int sCount = 1; + +#define INDEX \ + (type == GL_UNSIGNED_SHORT ? \ + static_cast<const GLushort*>(indices_in)[i]: \ + static_cast<const GLubyte*>(indices_in)[i]) + + GLfloat pSize = *((GLfloat*)(pointsArr+(INDEX*stride))); + i++; + + while(i < count && pSize == *((GLfloat*)(pointsArr+(INDEX*stride)))) + { + sCount++; + i++; + } + + s_glDispatch.glPointSize(pSize); + s_glDispatch.glDrawElements(GL_POINTS, sCount, type, (char*)indices_in+sStart*tSize); + } + } else { + int i = 0; + while(i<count) + { + int sStart = i; + int sCount = 1; + GLfloat pSize = *((GLfloat*)(pointsArr+((first+i)*stride))); + i++; + + while(i < count && pSize == *((GLfloat*)(pointsArr+((first+i)*stride)))) + { + sCount++; + i++; + } + + s_glDispatch.glPointSize(pSize); + s_glDispatch.glDrawArrays(GL_POINTS, first+sStart, sCount); + } + } +} + +void GLEScmContext::drawPointsArrs(GLESConversionArrays& arrs,GLint first,GLsizei count) { + drawPointsData(arrs,first,count,0,NULL,false); +} + +void GLEScmContext::drawPointsElems(GLESConversionArrays& arrs,GLsizei count,GLenum type,const GLvoid* indices_in) { + drawPointsData(arrs,0,count,type,indices_in,true); +} + +bool GLEScmContext::needConvert(GLESConversionArrays& cArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id) { + + bool usingVBO = p->isVBO(); + GLenum arrType = p->getType(); + /* + conversion is not necessary in the following cases: + (*) array type is byte but it is not vertex or texture array + (*) array type is not fixed + */ + if((arrType != GL_FIXED) && (arrType != GL_BYTE)) return false; + if((arrType == GL_BYTE && (array_id != GL_VERTEX_ARRAY)) && + (arrType == GL_BYTE && (array_id != GL_TEXTURE_COORD_ARRAY)) ) return false; + + + bool byteVBO = (arrType == GL_BYTE) && usingVBO; + if(byteVBO){ + p->redirectPointerData(); + } + + if(!usingVBO || byteVBO) { + if (direct) { + convertDirect(cArrs,first,count,array_id,p); + } else { + convertIndirect(cArrs,count,type,indices,array_id,p); + } + } else { + if (direct) { + convertDirectVBO(cArrs,first,count,array_id,p) ; + } else { + convertIndirectVBO(cArrs,count,type,indices,array_id,p); + } + } + return true; +} + +const GLESpointer* GLEScmContext::getPointer(GLenum arrType) { + GLenum type = + arrType == GL_VERTEX_ARRAY_POINTER ? GL_VERTEX_ARRAY : + arrType == GL_NORMAL_ARRAY_POINTER ? GL_NORMAL_ARRAY : + arrType == GL_TEXTURE_COORD_ARRAY_POINTER ? GL_TEXTURE_COORD_ARRAY : + arrType == GL_COLOR_ARRAY_POINTER ? GL_COLOR_ARRAY : + arrType == GL_POINT_SIZE_ARRAY_POINTER_OES ? GL_POINT_SIZE_ARRAY_OES : + 0; + if(type != 0) + { + return GLEScontext::getPointer(type); + } + return NULL; +} + +void GLEScmContext::initExtensionString() { + *s_glExtensions = "GL_OES_blend_func_separate GL_OES_blend_equation_separate GL_OES_blend_subtract " + "GL_OES_byte_coordinates GL_OES_compressed_paletted_texture GL_OES_point_size_array " + "GL_OES_point_sprite GL_OES_single_precision GL_OES_stencil_wrap GL_OES_texture_env_crossbar " + "GL_OES_texture_mirored_repeat GL_OES_EGL_image GL_OES_element_index_uint GL_OES_draw_texture " + "GL_OES_texture_cube_map GL_OES_draw_texture "; + if (s_glSupport.GL_OES_READ_FORMAT) + *s_glExtensions+="GL_OES_read_format "; + if (s_glSupport.GL_EXT_FRAMEBUFFER_OBJECT) { + *s_glExtensions+="GL_OES_framebuffer_object GL_OES_depth24 GL_OES_depth32 GL_OES_fbo_render_mipmap " + "GL_OES_rgb8_rgba8 GL_OES_stencil1 GL_OES_stencil4 GL_OES_stencil8 "; + } + if (s_glSupport.GL_EXT_PACKED_DEPTH_STENCIL) + *s_glExtensions+="GL_OES_packed_depth_stencil "; + if (s_glSupport.GL_EXT_TEXTURE_FORMAT_BGRA8888) + *s_glExtensions+="GL_EXT_texture_format_BGRA8888 GL_APPLE_texture_format_BGRA8888 "; + if (s_glSupport.GL_ARB_MATRIX_PALETTE && s_glSupport.GL_ARB_VERTEX_BLEND) { + *s_glExtensions+="GL_OES_matrix_palette "; + GLint max_palette_matrices=0; + GLint max_vertex_units=0; + dispatcher().glGetIntegerv(GL_MAX_PALETTE_MATRICES_OES,&max_palette_matrices); + dispatcher().glGetIntegerv(GL_MAX_VERTEX_UNITS_OES,&max_vertex_units); + if (max_palette_matrices>=32 && max_vertex_units>=4) + *s_glExtensions+="GL_OES_extended_matrix_palette "; + } + *s_glExtensions+="GL_OES_compressed_ETC1_RGB8_texture "; +} + +int GLEScmContext::getMaxTexUnits() { + return getCaps()->maxTexUnits; +} + +bool GLEScmContext::glGetBooleanv(GLenum pname, GLboolean *params) +{ + GLint iParam; + + if(glGetIntegerv(pname, &iParam)) + { + *params = (iParam != 0); + return true; + } + + return false; +} + +bool GLEScmContext::glGetFixedv(GLenum pname, GLfixed *params) +{ + GLint iParam; + + if(glGetIntegerv(pname, &iParam)) + { + *params = I2X(iParam); + return true; + } + + return false; +} + +bool GLEScmContext::glGetFloatv(GLenum pname, GLfloat *params) +{ + GLint iParam; + + if(glGetIntegerv(pname, &iParam)) + { + *params = (GLfloat)iParam; + return true; + } + + return false; +} + +bool GLEScmContext::glGetIntegerv(GLenum pname, GLint *params) +{ + if(GLEScontext::glGetIntegerv(pname, params)) + return true; + + const GLESpointer* ptr = NULL; + + switch(pname){ + case GL_VERTEX_ARRAY_BUFFER_BINDING: + case GL_VERTEX_ARRAY_SIZE: + case GL_VERTEX_ARRAY_STRIDE: + case GL_VERTEX_ARRAY_TYPE: + ptr = getPointer(GL_VERTEX_ARRAY_POINTER); + break; + + case GL_NORMAL_ARRAY_BUFFER_BINDING: + case GL_NORMAL_ARRAY_STRIDE: + case GL_NORMAL_ARRAY_TYPE: + ptr = getPointer(GL_NORMAL_ARRAY_POINTER); + break; + + case GL_COLOR_ARRAY_BUFFER_BINDING: + case GL_COLOR_ARRAY_SIZE: + case GL_COLOR_ARRAY_STRIDE: + case GL_COLOR_ARRAY_TYPE: + ptr = getPointer(GL_COLOR_ARRAY_POINTER); + break; + + case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING: + case GL_TEXTURE_COORD_ARRAY_SIZE: + case GL_TEXTURE_COORD_ARRAY_STRIDE: + case GL_TEXTURE_COORD_ARRAY_TYPE: + ptr = getPointer(GL_TEXTURE_COORD_ARRAY_POINTER); + break; + + case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES: + case GL_POINT_SIZE_ARRAY_STRIDE_OES: + case GL_POINT_SIZE_ARRAY_TYPE_OES: + ptr = getPointer(GL_POINT_SIZE_ARRAY_POINTER_OES); + break; + + default: + return false; + } + + switch(pname) + { + case GL_VERTEX_ARRAY_BUFFER_BINDING: + case GL_NORMAL_ARRAY_BUFFER_BINDING: + case GL_COLOR_ARRAY_BUFFER_BINDING: + case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING: + case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES: + *params = ptr ? ptr->getBufferName() : 0; + break; + + case GL_VERTEX_ARRAY_STRIDE: + case GL_NORMAL_ARRAY_STRIDE: + case GL_COLOR_ARRAY_STRIDE: + case GL_TEXTURE_COORD_ARRAY_STRIDE: + case GL_POINT_SIZE_ARRAY_STRIDE_OES: + *params = ptr ? ptr->getStride() : 0; + break; + + case GL_VERTEX_ARRAY_SIZE: + case GL_COLOR_ARRAY_SIZE: + case GL_TEXTURE_COORD_ARRAY_SIZE: + *params = ptr ? ptr->getSize() : 0; + break; + + case GL_VERTEX_ARRAY_TYPE: + case GL_NORMAL_ARRAY_TYPE: + case GL_COLOR_ARRAY_TYPE: + case GL_TEXTURE_COORD_ARRAY_TYPE: + case GL_POINT_SIZE_ARRAY_TYPE_OES: + *params = ptr ? ptr->getType() : 0; + break; + } + + return true; +} diff --git a/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.h b/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.h new file mode 100644 index 0000000..1785877 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmContext.h @@ -0,0 +1,69 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef GLES_CM_CONTEX_H +#define GLES_CM_CONTEX_H + +#include <GLcommon/GLDispatch.h> +#include <GLcommon/GLESpointer.h> +#include <GLcommon/GLESbuffer.h> +#include <GLcommon/GLEScontext.h> +#include <map> +#include <vector> +#include <string> +#include <utils/threads.h> + + +typedef std::map<GLfloat,std::vector<int> > PointSizeIndices; + +class GLEScmContext: public GLEScontext +{ +public: + void init(); + GLEScmContext(); + + void setActiveTexture(GLenum tex); + void setClientActiveTexture(GLenum tex); + GLenum getActiveTexture() { return GL_TEXTURE0 + m_activeTexture;}; + GLenum getClientActiveTexture() { return GL_TEXTURE0 + m_clientActiveTexture;}; + void setupArraysPointers(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct); + void drawPointsArrs(GLESConversionArrays& arrs,GLint first,GLsizei count); + void drawPointsElems(GLESConversionArrays& arrs,GLsizei count,GLenum type,const GLvoid* indices); + virtual const GLESpointer* getPointer(GLenum arrType); + int getMaxTexUnits(); + + virtual bool glGetIntegerv(GLenum pname, GLint *params); + virtual bool glGetBooleanv(GLenum pname, GLboolean *params); + virtual bool glGetFloatv(GLenum pname, GLfloat *params); + virtual bool glGetFixedv(GLenum pname, GLfixed *params); + + ~GLEScmContext(); +protected: + + bool needConvert(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id); +private: + void setupArrayPointerHelper(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLenum array_id,GLESpointer* p); + void setupArr(const GLvoid* arr,GLenum arrayType,GLenum dataType,GLint size,GLsizei stride,GLboolean normalized, int pointsIndex = -1); + void drawPoints(PointSizeIndices* points); + void drawPointsData(GLESConversionArrays& arrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices_in,bool isElemsDraw); + void initExtensionString(); + + GLESpointer* m_texCoords; + int m_pointsIndex; + unsigned int m_clientActiveTexture; +}; + +#endif + diff --git a/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmImp.cpp b/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmImp.cpp new file mode 100644 index 0000000..b78a022 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmImp.cpp @@ -0,0 +1,2360 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifdef _WIN32 +#undef GL_API +#define GL_API __declspec(dllexport) +#define GL_APICALL __declspec(dllexport) +#endif +#define GL_GLEXT_PROTOTYPES +#include "GLEScmContext.h" +#include "GLEScmValidate.h" +#include "GLEScmUtils.h" +#include <GLcommon/TextureUtils.h> + +#include <stdio.h> +#include <GLcommon/gldefs.h> +#include <GLcommon/GLDispatch.h> +#include <GLcommon/GLconversion_macros.h> +#include <GLcommon/TranslatorIfaces.h> +#include <GLcommon/FramebufferData.h> +#include <GLES/gl.h> +#include <GLES/glext.h> +#include <cmath> +#include <map> + +extern "C" { + +//decleration +static void initContext(GLEScontext* ctx,ShareGroupPtr grp); +static void deleteGLESContext(GLEScontext* ctx); +static void setShareGroup(GLEScontext* ctx,ShareGroupPtr grp); +static GLEScontext* createGLESContext(); +static __translatorMustCastToProperFunctionPointerType getProcAddress(const char* procName); + +} + +/************************************** GLES EXTENSIONS *********************************************************/ +//extentions descriptor +typedef std::map<std::string, __translatorMustCastToProperFunctionPointerType> ProcTableMap; +ProcTableMap *s_glesExtensions = NULL; +/****************************************************************************************************************/ + +static EGLiface* s_eglIface = NULL; +static GLESiface s_glesIface = { + createGLESContext:createGLESContext, + initContext :initContext, + deleteGLESContext:deleteGLESContext, + flush :(FUNCPTR)glFlush, + finish :(FUNCPTR)glFinish, + setShareGroup :setShareGroup, + getProcAddress :getProcAddress +}; + +#include <GLcommon/GLESmacros.h> + +extern "C" { + +static void initContext(GLEScontext* ctx,ShareGroupPtr grp) { + if (!ctx->isInitialized()) { + ctx->setShareGroup(grp); + ctx->init(); + glBindTexture(GL_TEXTURE_2D,0); + glBindTexture(GL_TEXTURE_CUBE_MAP_OES,0); + } +} + +static GLEScontext* createGLESContext() { + return new GLEScmContext(); +} + +static void deleteGLESContext(GLEScontext* ctx) { + if(ctx) delete ctx; +} + +static void setShareGroup(GLEScontext* ctx,ShareGroupPtr grp) { + if(ctx) { + ctx->setShareGroup(grp); + } +} +static __translatorMustCastToProperFunctionPointerType getProcAddress(const char* procName) { + GET_CTX_RET(NULL) + ctx->getGlobalLock(); + static bool proc_table_initialized = false; + if (!proc_table_initialized) { + proc_table_initialized = true; + if (!s_glesExtensions) + s_glesExtensions = new ProcTableMap(); + else + s_glesExtensions->clear(); + (*s_glesExtensions)["glEGLImageTargetTexture2DOES"] = (__translatorMustCastToProperFunctionPointerType)glEGLImageTargetTexture2DOES; + (*s_glesExtensions)["glEGLImageTargetRenderbufferStorageOES"]=(__translatorMustCastToProperFunctionPointerType)glEGLImageTargetRenderbufferStorageOES; + (*s_glesExtensions)["glBlendEquationSeparateOES"] = (__translatorMustCastToProperFunctionPointerType)glBlendEquationSeparateOES; + (*s_glesExtensions)["glBlendFuncSeparateOES"] = (__translatorMustCastToProperFunctionPointerType)glBlendFuncSeparateOES; + (*s_glesExtensions)["glBlendEquationOES"] = (__translatorMustCastToProperFunctionPointerType)glBlendEquationOES; + + if (ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND) { + (*s_glesExtensions)["glCurrentPaletteMatrixOES"] = (__translatorMustCastToProperFunctionPointerType)glCurrentPaletteMatrixOES; + (*s_glesExtensions)["glLoadPaletteFromModelViewMatrixOES"]=(__translatorMustCastToProperFunctionPointerType)glLoadPaletteFromModelViewMatrixOES; + (*s_glesExtensions)["glMatrixIndexPointerOES"] = (__translatorMustCastToProperFunctionPointerType)glMatrixIndexPointerOES; + (*s_glesExtensions)["glWeightPointerOES"] = (__translatorMustCastToProperFunctionPointerType)glWeightPointerOES; + } + (*s_glesExtensions)["glDepthRangefOES"] = (__translatorMustCastToProperFunctionPointerType)glDepthRangef; + (*s_glesExtensions)["glFrustumfOES"] = (__translatorMustCastToProperFunctionPointerType)glFrustumf; + (*s_glesExtensions)["glOrthofOES"] = (__translatorMustCastToProperFunctionPointerType)glOrthof; + (*s_glesExtensions)["glClipPlanefOES"] = (__translatorMustCastToProperFunctionPointerType)glClipPlanef; + (*s_glesExtensions)["glGetClipPlanefOES"] = (__translatorMustCastToProperFunctionPointerType)glGetClipPlanef; + (*s_glesExtensions)["glClearDepthfOES"] = (__translatorMustCastToProperFunctionPointerType)glClearDepthf; + (*s_glesExtensions)["glPointSizePointerOES"] = (__translatorMustCastToProperFunctionPointerType)glPointSizePointerOES; + (*s_glesExtensions)["glTexGenfOES"] = (__translatorMustCastToProperFunctionPointerType)glTexGenfOES; + (*s_glesExtensions)["glTexGenfvOES"] = (__translatorMustCastToProperFunctionPointerType)glTexGenfvOES; + (*s_glesExtensions)["glTexGeniOES"] = (__translatorMustCastToProperFunctionPointerType)glTexGeniOES; + (*s_glesExtensions)["glTexGenivOES"] = (__translatorMustCastToProperFunctionPointerType)glTexGenivOES; + (*s_glesExtensions)["glTexGenxOES"] = (__translatorMustCastToProperFunctionPointerType)glTexGenxOES; + (*s_glesExtensions)["glTexGenxvOES"] = (__translatorMustCastToProperFunctionPointerType)glTexGenxvOES; + (*s_glesExtensions)["glGetTexGenfvOES"] = (__translatorMustCastToProperFunctionPointerType)glGetTexGenfvOES; + (*s_glesExtensions)["glGetTexGenivOES"] = (__translatorMustCastToProperFunctionPointerType)glGetTexGenivOES; + (*s_glesExtensions)["glGetTexGenxvOES"] = (__translatorMustCastToProperFunctionPointerType)glGetTexGenxvOES; + if (ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT) { + (*s_glesExtensions)["glIsRenderbufferOES"] = (__translatorMustCastToProperFunctionPointerType)glIsRenderbufferOES; + (*s_glesExtensions)["glBindRenderbufferOES"] = (__translatorMustCastToProperFunctionPointerType)glBindRenderbufferOES; + (*s_glesExtensions)["glDeleteRenderbuffersOES"] = (__translatorMustCastToProperFunctionPointerType)glDeleteRenderbuffersOES; + (*s_glesExtensions)["glGenRenderbuffersOES"] = (__translatorMustCastToProperFunctionPointerType)glGenRenderbuffersOES; + (*s_glesExtensions)["glRenderbufferStorageOES"] = (__translatorMustCastToProperFunctionPointerType)glRenderbufferStorageOES; + (*s_glesExtensions)["glGetRenderbufferParameterivOES"] = (__translatorMustCastToProperFunctionPointerType)glGetRenderbufferParameterivOES; + (*s_glesExtensions)["glIsFramebufferOES"] = (__translatorMustCastToProperFunctionPointerType)glIsFramebufferOES; + (*s_glesExtensions)["glBindFramebufferOES"] = (__translatorMustCastToProperFunctionPointerType)glBindFramebufferOES; + (*s_glesExtensions)["glDeleteFramebuffersOES"] = (__translatorMustCastToProperFunctionPointerType)glDeleteFramebuffersOES; + (*s_glesExtensions)["glGenFramebuffersOES"] = (__translatorMustCastToProperFunctionPointerType)glGenFramebuffersOES; + (*s_glesExtensions)["glCheckFramebufferStatusOES"] = (__translatorMustCastToProperFunctionPointerType)glCheckFramebufferStatusOES; + (*s_glesExtensions)["glFramebufferTexture2DOES"] = (__translatorMustCastToProperFunctionPointerType)glFramebufferTexture2DOES; + (*s_glesExtensions)["glFramebufferRenderbufferOES"] = (__translatorMustCastToProperFunctionPointerType)glFramebufferRenderbufferOES; + (*s_glesExtensions)["glGetFramebufferAttachmentParameterivOES"] = (__translatorMustCastToProperFunctionPointerType)glGetFramebufferAttachmentParameterivOES; + (*s_glesExtensions)["glGenerateMipmapOES"] = (__translatorMustCastToProperFunctionPointerType)glGenerateMipmapOES; + } + (*s_glesExtensions)["glDrawTexsOES"] = (__translatorMustCastToProperFunctionPointerType)glDrawTexsOES; + (*s_glesExtensions)["glDrawTexiOES"] = (__translatorMustCastToProperFunctionPointerType)glDrawTexiOES; + (*s_glesExtensions)["glDrawTexfOES"] = (__translatorMustCastToProperFunctionPointerType)glDrawTexfOES; + (*s_glesExtensions)["glDrawTexxOES"] = (__translatorMustCastToProperFunctionPointerType)glDrawTexxOES; + (*s_glesExtensions)["glDrawTexsvOES"] = (__translatorMustCastToProperFunctionPointerType)glDrawTexsvOES; + (*s_glesExtensions)["glDrawTexivOES"] = (__translatorMustCastToProperFunctionPointerType)glDrawTexivOES; + (*s_glesExtensions)["glDrawTexfvOES"] = (__translatorMustCastToProperFunctionPointerType)glDrawTexfvOES; + (*s_glesExtensions)["glDrawTexxvOES"] = (__translatorMustCastToProperFunctionPointerType)glDrawTexxvOES; + } + __translatorMustCastToProperFunctionPointerType ret=NULL; + ProcTableMap::iterator val = s_glesExtensions->find(procName); + if (val!=s_glesExtensions->end()) + ret = val->second; + ctx->releaseGlobalLock(); + + return ret; +} + +GL_API GLESiface* __translator_getIfaces(EGLiface* eglIface){ + s_eglIface = eglIface; + return & s_glesIface; +} + +} + +static ObjectLocalName TextureLocalName(GLenum target, unsigned int tex) { + GET_CTX_RET(0); + return (tex!=0? tex : ctx->getDefaultTextureName(target)); +} + +static TextureData* getTextureData(ObjectLocalName tex){ + GET_CTX_RET(NULL); + + if(!ctx->shareGroup()->isObject(TEXTURE,tex)) + { + return NULL; + } + + TextureData *texData = NULL; + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(TEXTURE,tex); + if(!objData.Ptr()){ + texData = new TextureData(); + ctx->shareGroup()->setObjectData(TEXTURE, tex, ObjectDataPtr(texData)); + } else { + texData = (TextureData*)objData.Ptr(); + } + return texData; +} + +static TextureData* getTextureTargetData(GLenum target){ + GET_CTX_RET(NULL); + unsigned int tex = ctx->getBindedTexture(target); + return getTextureData(TextureLocalName(target,tex)); +} + +GL_API GLboolean GL_APIENTRY glIsBuffer(GLuint buffer) { + GET_CTX_RET(GL_FALSE) + + if(buffer && ctx->shareGroup().Ptr()) { + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(VERTEXBUFFER,buffer); + return objData.Ptr() ? ((GLESbuffer*)objData.Ptr())->wasBinded():GL_FALSE; + } + return GL_FALSE; +} + +GL_API GLboolean GL_APIENTRY glIsEnabled( GLenum cap) { + GET_CTX_CM_RET(GL_FALSE) + RET_AND_SET_ERROR_IF(!GLEScmValidate::capability(cap,ctx->getMaxLights(),ctx->getMaxClipPlanes()),GL_INVALID_ENUM,GL_FALSE); + + if (cap == GL_POINT_SIZE_ARRAY_OES) + return ctx->isArrEnabled(cap); + else if (cap==GL_TEXTURE_GEN_STR_OES) + return (ctx->dispatcher().glIsEnabled(GL_TEXTURE_GEN_S) && + ctx->dispatcher().glIsEnabled(GL_TEXTURE_GEN_T) && + ctx->dispatcher().glIsEnabled(GL_TEXTURE_GEN_R)); + else + return ctx->dispatcher().glIsEnabled(cap); +} + +GL_API GLboolean GL_APIENTRY glIsTexture( GLuint texture) { + GET_CTX_RET(GL_FALSE) + + if(texture == 0) // Special case + return GL_FALSE; + + TextureData* tex = getTextureData(texture); + return tex ? tex->wasBound : GL_FALSE; +} + +GL_API GLenum GL_APIENTRY glGetError(void) { + GET_CTX_RET(GL_NO_ERROR) + GLenum err = ctx->getGLerror(); + if(err != GL_NO_ERROR) { + ctx->setGLerror(GL_NO_ERROR); + return err; + } + + return ctx->dispatcher().glGetError(); +} + +GL_API const GLubyte * GL_APIENTRY glGetString( GLenum name) { + + GET_CTX_RET(NULL) + static const GLubyte VENDOR[] = "Google"; + static const GLubyte VERSION[] = "OpenGL ES-CM 1.1"; + + switch(name) { + case GL_VENDOR: + return VENDOR; + case GL_RENDERER: + return (const GLubyte*)ctx->getRendererString(); + case GL_VERSION: + return VERSION; + case GL_EXTENSIONS: + return (const GLubyte*)ctx->getExtensionString(); + default: + RET_AND_SET_ERROR_IF(true,GL_INVALID_ENUM,NULL); + } +} + +GL_API void GL_APIENTRY glActiveTexture( GLenum texture) { + GET_CTX_CM() + SET_ERROR_IF(!GLEScmValidate::textureEnum(texture,ctx->getMaxTexUnits()),GL_INVALID_ENUM); + ctx->setActiveTexture(texture); + ctx->dispatcher().glActiveTexture(texture); +} + +GL_API void GL_APIENTRY glAlphaFunc( GLenum func, GLclampf ref) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::alphaFunc(func),GL_INVALID_ENUM); + ctx->dispatcher().glAlphaFunc(func,ref); +} + + +GL_API void GL_APIENTRY glAlphaFuncx( GLenum func, GLclampx ref) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::alphaFunc(func),GL_INVALID_ENUM); + ctx->dispatcher().glAlphaFunc(func,X2F(ref)); +} + + +GL_API void GL_APIENTRY glBindBuffer( GLenum target, GLuint buffer) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::bufferTarget(target),GL_INVALID_ENUM); + + //if buffer wasn't generated before,generate one + if(buffer && ctx->shareGroup().Ptr() && !ctx->shareGroup()->isObject(VERTEXBUFFER,buffer)){ + ctx->shareGroup()->genName(VERTEXBUFFER,buffer); + ctx->shareGroup()->setObjectData(VERTEXBUFFER,buffer,ObjectDataPtr(new GLESbuffer())); + } + ctx->bindBuffer(target,buffer); + if (buffer) { + GLESbuffer* vbo = (GLESbuffer*)ctx->shareGroup()->getObjectData(VERTEXBUFFER,buffer).Ptr(); + vbo->setBinded(); + } +} + + +GL_API void GL_APIENTRY glBindTexture( GLenum target, GLuint texture) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::textureTarget(target),GL_INVALID_ENUM) + + //for handling default texture (0) + ObjectLocalName localTexName = TextureLocalName(target,texture); + + GLuint globalTextureName = localTexName; + if(ctx->shareGroup().Ptr()){ + globalTextureName = ctx->shareGroup()->getGlobalName(TEXTURE,localTexName); + //if texture wasn't generated before,generate one + if(!globalTextureName){ + ctx->shareGroup()->genName(TEXTURE,localTexName); + globalTextureName = ctx->shareGroup()->getGlobalName(TEXTURE,localTexName); + } + + TextureData* texData = getTextureData(localTexName); + if (texData->target==0) + texData->target = target; + //if texture was already bound to another target + SET_ERROR_IF(ctx->GLTextureTargetToLocal(texData->target) != ctx->GLTextureTargetToLocal(target), GL_INVALID_OPERATION); + texData->wasBound = true; + } + + ctx->setBindedTexture(target,texture); + ctx->dispatcher().glBindTexture(target,globalTextureName); +} + +GL_API void GL_APIENTRY glBlendFunc( GLenum sfactor, GLenum dfactor) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::blendSrc(sfactor) || !GLEScmValidate::blendDst(dfactor),GL_INVALID_ENUM) + ctx->dispatcher().glBlendFunc(sfactor,dfactor); +} + +GL_API void GL_APIENTRY glBufferData( GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::bufferTarget(target),GL_INVALID_ENUM); + SET_ERROR_IF(!ctx->isBindedBuffer(target),GL_INVALID_OPERATION); + ctx->setBufferData(target,size,data,usage); +} + +GL_API void GL_APIENTRY glBufferSubData( GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data) { + GET_CTX() + SET_ERROR_IF(!ctx->isBindedBuffer(target),GL_INVALID_OPERATION); + SET_ERROR_IF(!GLEScmValidate::bufferTarget(target),GL_INVALID_ENUM); + SET_ERROR_IF(!ctx->setBufferSubData(target,offset,size,data),GL_INVALID_VALUE); +} + +GL_API void GL_APIENTRY glClear( GLbitfield mask) { + GET_CTX() + ctx->drawValidate(); + + ctx->dispatcher().glClear(mask); +} + +GL_API void GL_APIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) { + GET_CTX() + ctx->dispatcher().glClearColor(red,green,blue,alpha); +} + +GL_API void GL_APIENTRY glClearColorx( GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha) { + GET_CTX() + ctx->dispatcher().glClearColor(X2F(red),X2F(green),X2F(blue),X2F(alpha)); +} + + +GL_API void GL_APIENTRY glClearDepthf( GLclampf depth) { + GET_CTX() + ctx->dispatcher().glClearDepth(depth); +} + +GL_API void GL_APIENTRY glClearDepthx( GLclampx depth) { + GET_CTX() + ctx->dispatcher().glClearDepth(X2F(depth)); +} + +GL_API void GL_APIENTRY glClearStencil( GLint s) { + GET_CTX() + ctx->dispatcher().glClearStencil(s); +} + +GL_API void GL_APIENTRY glClientActiveTexture( GLenum texture) { + GET_CTX_CM() + SET_ERROR_IF(!GLEScmValidate::textureEnum(texture,ctx->getMaxTexUnits()),GL_INVALID_ENUM); + ctx->setClientActiveTexture(texture); + ctx->dispatcher().glClientActiveTexture(texture); + +} + +GL_API void GL_APIENTRY glClipPlanef( GLenum plane, const GLfloat *equation) { + GET_CTX() + GLdouble tmpEquation[4]; + + for(int i = 0; i < 4; i++) { + tmpEquation[i] = static_cast<GLdouble>(equation[i]); + } + ctx->dispatcher().glClipPlane(plane,tmpEquation); +} + +GL_API void GL_APIENTRY glClipPlanex( GLenum plane, const GLfixed *equation) { + GET_CTX() + GLdouble tmpEquation[4]; + for(int i = 0; i < 4; i++) { + tmpEquation[i] = X2D(equation[i]); + } + ctx->dispatcher().glClipPlane(plane,tmpEquation); +} + +GL_API void GL_APIENTRY glColor4f( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { + GET_CTX() + ctx->dispatcher().glColor4f(red,green,blue,alpha); +} + +GL_API void GL_APIENTRY glColor4ub( GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) { + GET_CTX() + ctx->dispatcher().glColor4ub(red,green,blue,alpha); +} + +GL_API void GL_APIENTRY glColor4x( GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha) { + GET_CTX() + ctx->dispatcher().glColor4f(X2F(red),X2F(green),X2F(blue),X2F(alpha)); +} + +GL_API void GL_APIENTRY glColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) { + GET_CTX() + ctx->dispatcher().glColorMask(red,green,blue,alpha); +} + +GL_API void GL_APIENTRY glColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::colorPointerParams(size,stride),GL_INVALID_VALUE); + SET_ERROR_IF(!GLEScmValidate::colorPointerType(type),GL_INVALID_ENUM); + ctx->setPointer(GL_COLOR_ARRAY,size,type,stride,pointer); +} + +GL_API void GL_APIENTRY glCompressedTexImage2D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) { + GET_CTX_CM() + SET_ERROR_IF(!GLEScmValidate::textureTargetEx(target),GL_INVALID_ENUM); + + doCompressedTexImage2D(ctx, target, level, internalformat, + width, height, border, + imageSize, data, (void*)glTexImage2D); +} + +GL_API void GL_APIENTRY glCompressedTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data) { + GET_CTX_CM() + SET_ERROR_IF(!(GLEScmValidate::texCompImgFrmt(format) && GLEScmValidate::textureTargetEx(target)),GL_INVALID_ENUM); + SET_ERROR_IF(level < 0 || level > log2(ctx->getMaxTexSize()),GL_INVALID_VALUE) + + GLenum uncompressedFrmt; + unsigned char* uncompressed = uncompressTexture(format,uncompressedFrmt,width,height,imageSize,data,level); + ctx->dispatcher().glTexSubImage2D(target,level,xoffset,yoffset,width,height,uncompressedFrmt,GL_UNSIGNED_BYTE,uncompressed); + delete uncompressed; +} + +GL_API void GL_APIENTRY glCopyTexImage2D( GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) { + GET_CTX() + SET_ERROR_IF(!(GLEScmValidate::pixelFrmt(ctx,internalformat) && GLEScmValidate::textureTargetEx(target)),GL_INVALID_ENUM); + SET_ERROR_IF(border != 0,GL_INVALID_VALUE); + ctx->dispatcher().glCopyTexImage2D(target,level,internalformat,x,y,width,height,border); +} + +GL_API void GL_APIENTRY glCopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::textureTargetEx(target),GL_INVALID_ENUM); + ctx->dispatcher().glCopyTexSubImage2D(target,level,xoffset,yoffset,x,y,width,height); +} + +GL_API void GL_APIENTRY glCullFace( GLenum mode) { + GET_CTX() + ctx->dispatcher().glCullFace(mode); +} + +GL_API void GL_APIENTRY glDeleteBuffers( GLsizei n, const GLuint *buffers) { + GET_CTX() + SET_ERROR_IF(n<0,GL_INVALID_VALUE); + if(ctx->shareGroup().Ptr()) { + for(int i=0; i < n; i++){ + ctx->shareGroup()->deleteName(VERTEXBUFFER,buffers[i]); + ctx->unbindBuffer(buffers[i]); + } + } +} + +GL_API void GL_APIENTRY glDeleteTextures( GLsizei n, const GLuint *textures) { + GET_CTX() + SET_ERROR_IF(n<0,GL_INVALID_VALUE); + if(ctx->shareGroup().Ptr()) { + for(int i=0; i < n; i++){ + if(textures[i] != 0) + { + TextureData* tData = getTextureData(textures[i]); + // delete the underlying OpenGL texture but only if this + // texture is not a target of EGLImage. + if (!tData || tData->sourceEGLImage == 0) { + const GLuint globalTextureName = ctx->shareGroup()->getGlobalName(TEXTURE,textures[i]); + ctx->dispatcher().glDeleteTextures(1,&globalTextureName); + } + ctx->shareGroup()->deleteName(TEXTURE,textures[i]); + + if(ctx->getBindedTexture(GL_TEXTURE_2D) == textures[i]) + ctx->setBindedTexture(GL_TEXTURE_2D,0); + if (ctx->getBindedTexture(GL_TEXTURE_CUBE_MAP) == textures[i]) + ctx->setBindedTexture(GL_TEXTURE_CUBE_MAP,0); + } + } + } +} + +GL_API void GL_APIENTRY glDepthFunc( GLenum func) { + GET_CTX() + ctx->dispatcher().glDepthFunc(func); +} + +GL_API void GL_APIENTRY glDepthMask( GLboolean flag) { + GET_CTX() + ctx->dispatcher().glDepthMask(flag); +} + +GL_API void GL_APIENTRY glDepthRangef( GLclampf zNear, GLclampf zFar) { + GET_CTX() + ctx->dispatcher().glDepthRange(zNear,zFar); +} + +GL_API void GL_APIENTRY glDepthRangex( GLclampx zNear, GLclampx zFar) { + GET_CTX() + ctx->dispatcher().glDepthRange(X2F(zNear),X2F(zFar)); +} + +GL_API void GL_APIENTRY glDisable( GLenum cap) { + GET_CTX() + if (cap==GL_TEXTURE_GEN_STR_OES) { + ctx->dispatcher().glDisable(GL_TEXTURE_GEN_S); + ctx->dispatcher().glDisable(GL_TEXTURE_GEN_T); + ctx->dispatcher().glDisable(GL_TEXTURE_GEN_R); + } + else ctx->dispatcher().glDisable(cap); + if (cap==GL_TEXTURE_2D || cap==GL_TEXTURE_CUBE_MAP_OES) + ctx->setTextureEnabled(cap,false); +} + +GL_API void GL_APIENTRY glDisableClientState( GLenum array) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::supportedArrays(array),GL_INVALID_ENUM) + + ctx->enableArr(array,false); + if(array != GL_POINT_SIZE_ARRAY_OES) ctx->dispatcher().glDisableClientState(array); +} + + +GL_API void GL_APIENTRY glDrawArrays( GLenum mode, GLint first, GLsizei count) { + GET_CTX_CM() + SET_ERROR_IF(count < 0,GL_INVALID_VALUE) + SET_ERROR_IF(!GLEScmValidate::drawMode(mode),GL_INVALID_ENUM) + + ctx->drawValidate(); + + if(!ctx->isArrEnabled(GL_VERTEX_ARRAY)) return; + + GLESConversionArrays tmpArrs; + ctx->setupArraysPointers(tmpArrs,first,count,0,NULL,true); + if(mode == GL_POINTS && ctx->isArrEnabled(GL_POINT_SIZE_ARRAY_OES)){ + ctx->drawPointsArrs(tmpArrs,first,count); + } + else + { + ctx->dispatcher().glDrawArrays(mode,first,count); + } +} + +GL_API void GL_APIENTRY glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *elementsIndices) { + GET_CTX_CM() + SET_ERROR_IF(count < 0,GL_INVALID_VALUE) + SET_ERROR_IF((!GLEScmValidate::drawMode(mode) || !GLEScmValidate::drawType(type)),GL_INVALID_ENUM) + if(!ctx->isArrEnabled(GL_VERTEX_ARRAY)) return; + + ctx->drawValidate(); + + const GLvoid* indices = elementsIndices; + GLESConversionArrays tmpArrs; + if(ctx->isBindedBuffer(GL_ELEMENT_ARRAY_BUFFER)) { // if vbo is binded take the indices from the vbo + const unsigned char* buf = static_cast<unsigned char *>(ctx->getBindedBuffer(GL_ELEMENT_ARRAY_BUFFER)); + indices = buf+reinterpret_cast<uintptr_t>(elementsIndices); + } + + ctx->setupArraysPointers(tmpArrs,0,count,type,indices,false); + if(mode == GL_POINTS && ctx->isArrEnabled(GL_POINT_SIZE_ARRAY_OES)){ + ctx->drawPointsElems(tmpArrs,count,type,indices); + } + else{ + ctx->dispatcher().glDrawElements(mode,count,type,indices); + } +} + +GL_API void GL_APIENTRY glEnable( GLenum cap) { + GET_CTX() + if (cap==GL_TEXTURE_GEN_STR_OES) { + ctx->dispatcher().glEnable(GL_TEXTURE_GEN_S); + ctx->dispatcher().glEnable(GL_TEXTURE_GEN_T); + ctx->dispatcher().glEnable(GL_TEXTURE_GEN_R); + } + else + ctx->dispatcher().glEnable(cap); + if (cap==GL_TEXTURE_2D || cap==GL_TEXTURE_CUBE_MAP_OES) + ctx->setTextureEnabled(cap,true); +} + +GL_API void GL_APIENTRY glEnableClientState( GLenum array) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::supportedArrays(array),GL_INVALID_ENUM) + + ctx->enableArr(array,true); + if(array != GL_POINT_SIZE_ARRAY_OES) ctx->dispatcher().glEnableClientState(array); +} + +GL_API void GL_APIENTRY glFinish( void) { + GET_CTX() + ctx->dispatcher().glFinish(); +} + +GL_API void GL_APIENTRY glFlush( void) { + GET_CTX() + ctx->dispatcher().glFlush(); +} + +GL_API void GL_APIENTRY glFogf( GLenum pname, GLfloat param) { + GET_CTX() + ctx->dispatcher().glFogf(pname,param); +} + +GL_API void GL_APIENTRY glFogfv( GLenum pname, const GLfloat *params) { + GET_CTX() + ctx->dispatcher().glFogfv(pname,params); +} + +GL_API void GL_APIENTRY glFogx( GLenum pname, GLfixed param) { + GET_CTX() + ctx->dispatcher().glFogf(pname,(pname == GL_FOG_MODE)? static_cast<GLfloat>(param):X2F(param)); +} + +GL_API void GL_APIENTRY glFogxv( GLenum pname, const GLfixed *params) { + GET_CTX() + if(pname == GL_FOG_MODE) { + GLfloat tmpParam = static_cast<GLfloat>(params[0]); + ctx->dispatcher().glFogfv(pname,&tmpParam); + } else { + GLfloat tmpParams[4]; + for(int i=0; i< 4; i++) { + tmpParams[i] = X2F(params[i]); + } + ctx->dispatcher().glFogfv(pname,tmpParams); + } + +} + +GL_API void GL_APIENTRY glFrontFace( GLenum mode) { + GET_CTX() + ctx->dispatcher().glFrontFace(mode); +} + +GL_API void GL_APIENTRY glFrustumf( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) { + GET_CTX() + ctx->dispatcher().glFrustum(left,right,bottom,top,zNear,zFar); +} + +GL_API void GL_APIENTRY glFrustumx( GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) { + GET_CTX() + ctx->dispatcher().glFrustum(X2F(left),X2F(right),X2F(bottom),X2F(top),X2F(zNear),X2F(zFar)); +} + +GL_API void GL_APIENTRY glGenBuffers( GLsizei n, GLuint *buffers) { + GET_CTX() + SET_ERROR_IF(n<0,GL_INVALID_VALUE); + if(ctx->shareGroup().Ptr()) { + for(int i=0; i<n ;i++) { + buffers[i] = ctx->shareGroup()->genName(VERTEXBUFFER, 0, true); + //generating vbo object related to this buffer name + ctx->shareGroup()->setObjectData(VERTEXBUFFER,buffers[i],ObjectDataPtr(new GLESbuffer())); + } + } +} + +GL_API void GL_APIENTRY glGenTextures( GLsizei n, GLuint *textures) { + GET_CTX(); + if(ctx->shareGroup().Ptr()) { + for(int i=0; i<n ;i++) { + textures[i] = ctx->shareGroup()->genName(TEXTURE, 0, true); + } + } +} + +GL_API void GL_APIENTRY glGetBooleanv( GLenum pname, GLboolean *params) { + GET_CTX() + + if(ctx->glGetBooleanv(pname, params)) + { + return; + } + + GLint i; + + switch(pname) + { + case GL_FRAMEBUFFER_BINDING_OES: + case GL_RENDERBUFFER_BINDING_OES: + { + GLint name; + glGetIntegerv(pname,&name); + *params = name!=0 ? GL_TRUE: GL_FALSE; + } + break; + case GL_TEXTURE_GEN_STR_OES: + { + GLboolean state_s = GL_FALSE; + GLboolean state_t = GL_FALSE; + GLboolean state_r = GL_FALSE; + ctx->dispatcher().glGetBooleanv(GL_TEXTURE_GEN_S,&state_s); + ctx->dispatcher().glGetBooleanv(GL_TEXTURE_GEN_T,&state_t); + ctx->dispatcher().glGetBooleanv(GL_TEXTURE_GEN_R,&state_r); + *params = state_s && state_t && state_r ? GL_TRUE: GL_FALSE; + } + break; + case GL_NUM_COMPRESSED_TEXTURE_FORMATS: + *params = (GLboolean)getCompressedFormats(NULL); + break; + case GL_COMPRESSED_TEXTURE_FORMATS: + { + int nparams = getCompressedFormats(NULL); + if (nparams>0) { + int * iparams = new int[nparams]; + getCompressedFormats(iparams); + for (int i=0; i<nparams; i++) params[i] = (GLboolean)iparams[i]; + delete [] iparams; + } + } + break; + default: + ctx->dispatcher().glGetBooleanv(pname,params); + } +} + +GL_API void GL_APIENTRY glGetBufferParameteriv( GLenum target, GLenum pname, GLint *params) { + GET_CTX() + SET_ERROR_IF(!(GLEScmValidate::bufferTarget(target) && GLEScmValidate::bufferParam(pname)),GL_INVALID_ENUM); + SET_ERROR_IF(!ctx->isBindedBuffer(target),GL_INVALID_OPERATION); + bool ret = true; + switch(pname) { + case GL_BUFFER_SIZE: + ctx->getBufferSize(target,params); + break; + case GL_BUFFER_USAGE: + ctx->getBufferUsage(target,params); + break; + } + +} + +GL_API void GL_APIENTRY glGetClipPlanef( GLenum pname, GLfloat eqn[4]) { + GET_CTX() + GLdouble tmpEqn[4]; + + ctx->dispatcher().glGetClipPlane(pname,tmpEqn); + for(int i =0 ;i < 4; i++){ + eqn[i] = static_cast<GLfloat>(tmpEqn[i]); + } +} + +GL_API void GL_APIENTRY glGetClipPlanex( GLenum pname, GLfixed eqn[4]) { + GET_CTX() + GLdouble tmpEqn[4]; + + ctx->dispatcher().glGetClipPlane(pname,tmpEqn); + for(int i =0 ;i < 4; i++){ + eqn[i] = F2X(tmpEqn[i]); + } +} + +GL_API void GL_APIENTRY glGetFixedv( GLenum pname, GLfixed *params) { + GET_CTX() + + if(ctx->glGetFixedv(pname, params)) + { + return; + } + + size_t nParams = glParamSize(pname); + GLfloat fParams[16]; + GLint i; + + switch(pname) + { + case GL_FRAMEBUFFER_BINDING_OES: + case GL_RENDERBUFFER_BINDING_OES: + case GL_TEXTURE_GEN_STR_OES: + glGetFloatv(pname,&fParams[0]); + break; + case GL_NUM_COMPRESSED_TEXTURE_FORMATS: + *params = I2X(getCompressedFormats(NULL)); + return; + break; + case GL_COMPRESSED_TEXTURE_FORMATS: + { + int nparams = getCompressedFormats(NULL); + if (nparams>0) { + int * iparams = new int[nparams]; + getCompressedFormats(iparams); + for (int i=0; i<nparams; i++) params[i] = I2X(iparams[i]); + delete [] iparams; + } + return; + } + break; + default: + ctx->dispatcher().glGetFloatv(pname,fParams); + } + + if (nParams) + { + for(size_t i =0 ; i < nParams;i++) { + params[i] = F2X(fParams[i]); + } + } +} + +GL_API void GL_APIENTRY glGetFloatv( GLenum pname, GLfloat *params) { + GET_CTX() + + if(ctx->glGetFloatv(pname, params)) + { + return; + } + + GLint i; + + switch (pname) { + case GL_FRAMEBUFFER_BINDING_OES: + case GL_RENDERBUFFER_BINDING_OES: + case GL_TEXTURE_GEN_STR_OES: + glGetIntegerv(pname,&i); + *params = (GLfloat)i; + break; + case GL_NUM_COMPRESSED_TEXTURE_FORMATS: + *params = (GLfloat)getCompressedFormats(NULL); + break; + case GL_COMPRESSED_TEXTURE_FORMATS: + { + int nparams = getCompressedFormats(NULL); + if (nparams>0) { + int * iparams = new int[nparams]; + getCompressedFormats(iparams); + for (int i=0; i<nparams; i++) params[i] = (GLfloat)iparams[i]; + delete [] iparams; + } + } + break; + default: + ctx->dispatcher().glGetFloatv(pname,params); + } +} + +GL_API void GL_APIENTRY glGetIntegerv( GLenum pname, GLint *params) { + GET_CTX() + + if(ctx->glGetIntegerv(pname, params)) + { + return; + } + + GLint i; + GLfloat f; + + switch(pname) + { + case GL_TEXTURE_GEN_STR_OES: + ctx->dispatcher().glGetIntegerv(GL_TEXTURE_GEN_S,¶ms[0]); + break; + case GL_FRAMEBUFFER_BINDING_OES: + if (ctx->shareGroup().Ptr()) { + ctx->dispatcher().glGetIntegerv(pname,&i); + *params = ctx->shareGroup()->getLocalName(FRAMEBUFFER,i); + } + break; + case GL_RENDERBUFFER_BINDING_OES: + if (ctx->shareGroup().Ptr()) { + ctx->dispatcher().glGetIntegerv(pname,&i); + *params = ctx->shareGroup()->getLocalName(RENDERBUFFER,i); + } + break; + case GL_NUM_COMPRESSED_TEXTURE_FORMATS: + *params = getCompressedFormats(NULL); + break; + case GL_COMPRESSED_TEXTURE_FORMATS: + getCompressedFormats(params); + break; + case GL_MAX_CLIP_PLANES: + ctx->dispatcher().glGetIntegerv(pname,params); + if(*params > 6) + { + // GLES spec requires only 6, and the ATI driver erronously + // returns 8 (although it supports only 6). This WAR is simple, + // compliant and good enough for developers. + *params = 6; + } + break; + case GL_ALPHA_TEST_REF: + // Both the ATI and nVidia OpenGL drivers return the wrong answer + // here. So return the right one. + ctx->dispatcher().glGetFloatv(pname,&f); + *params = (int)(f * (float)0x7fffffff); + break; + case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: + ctx->dispatcher().glGetIntegerv(pname,params); + if(*params > 16) + { + // GLES spec requires only 2, and the ATI driver erronously + // returns 32 (although it supports only 16). This WAR is simple, + // compliant and good enough for developers. + *params = 16; + } + break; + + default: + ctx->dispatcher().glGetIntegerv(pname,params); + } +} + +GL_API void GL_APIENTRY glGetLightfv( GLenum light, GLenum pname, GLfloat *params) { + GET_CTX() + ctx->dispatcher().glGetLightfv(light,pname,params); +} + +GL_API void GL_APIENTRY glGetLightxv( GLenum light, GLenum pname, GLfixed *params) { + GET_CTX() + GLfloat tmpParams[4]; + + ctx->dispatcher().glGetLightfv(light,pname,tmpParams); + switch (pname){ + case GL_AMBIENT: + case GL_DIFFUSE: + case GL_SPECULAR: + case GL_POSITION: + params[3] = F2X(tmpParams[3]); + case GL_SPOT_DIRECTION: + params[2] = F2X(tmpParams[2]); + case GL_SPOT_EXPONENT: + case GL_SPOT_CUTOFF: + case GL_CONSTANT_ATTENUATION: + case GL_LINEAR_ATTENUATION: + case GL_QUADRATIC_ATTENUATION: + params[1] = F2X(tmpParams[1]); + break; + default:{ + ctx->setGLerror(GL_INVALID_ENUM); + return; + } + + } + params[0] = F2X(tmpParams[0]); +} + +GL_API void GL_APIENTRY glGetMaterialfv( GLenum face, GLenum pname, GLfloat *params) { + GET_CTX() + ctx->dispatcher().glGetMaterialfv(face,pname,params); +} + +GL_API void GL_APIENTRY glGetMaterialxv( GLenum face, GLenum pname, GLfixed *params) { + GET_CTX() + GLfloat tmpParams[4]; + ctx->dispatcher().glGetMaterialfv(face,pname,tmpParams); + switch(pname){ + case GL_AMBIENT: + case GL_DIFFUSE: + case GL_SPECULAR: + case GL_EMISSION: + case GL_AMBIENT_AND_DIFFUSE: + params[3] = tmpParams[3]; + params[2] = tmpParams[2]; + params[1] = tmpParams[1]; + case GL_SHININESS: + params[0] = tmpParams[0]; + break; + default:{ + ctx->setGLerror(GL_INVALID_ENUM); + return; + } + } +} + +GL_API void GL_APIENTRY glGetPointerv( GLenum pname, void **params) { + GET_CTX() + const GLESpointer* p = ctx->getPointer(pname); + if(p) { + if(p->isVBO()) + { + *params = (void*)(p->getBufferOffset()); + }else{ + *params = const_cast<void *>( p->getArrayData()); + } + } else { + ctx->setGLerror(GL_INVALID_ENUM); + } + +} + +GL_API void GL_APIENTRY glGetTexEnvfv( GLenum env, GLenum pname, GLfloat *params) { + GET_CTX() + ctx->dispatcher().glGetTexEnvfv(env,pname,params); +} + +GL_API void GL_APIENTRY glGetTexEnviv( GLenum env, GLenum pname, GLint *params) { + GET_CTX() + ctx->dispatcher().glGetTexEnviv(env,pname,params); +} + +GL_API void GL_APIENTRY glGetTexEnvxv( GLenum env, GLenum pname, GLfixed *params) { + GET_CTX() + GLfloat tmpParams[4]; + + ctx->dispatcher().glGetTexEnvfv(env,pname,tmpParams); + if(pname == GL_TEXTURE_ENV_MODE) { + params[0] = static_cast<GLfixed>(tmpParams[0]); + } else { + for(int i=0 ; i < 4 ; i++) + params[i] = F2X(tmpParams[i]); + } +} + +GL_API void GL_APIENTRY glGetTexParameterfv( GLenum target, GLenum pname, GLfloat *params) { + GET_CTX() + if (pname==GL_TEXTURE_CROP_RECT_OES) { + TextureData *texData = getTextureTargetData(target); + SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION); + for (int i=0;i<4;++i) + params[i] = texData->crop_rect[i]; + } + else { + ctx->dispatcher().glGetTexParameterfv(target,pname,params); + } +} + +GL_API void GL_APIENTRY glGetTexParameteriv( GLenum target, GLenum pname, GLint *params) { + GET_CTX() + if (pname==GL_TEXTURE_CROP_RECT_OES) { + TextureData *texData = getTextureTargetData(target); + SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION); + for (int i=0;i<4;++i) + params[i] = texData->crop_rect[i]; + } + else { + ctx->dispatcher().glGetTexParameteriv(target,pname,params); + } +} + +GL_API void GL_APIENTRY glGetTexParameterxv( GLenum target, GLenum pname, GLfixed *params) { + GET_CTX() + if (pname==GL_TEXTURE_CROP_RECT_OES) { + TextureData *texData = getTextureTargetData(target); + SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION); + for (int i=0;i<4;++i) + params[i] = F2X(texData->crop_rect[i]); + } + else { + GLfloat tmpParam; + ctx->dispatcher().glGetTexParameterfv(target,pname,&tmpParam); + params[0] = static_cast<GLfixed>(tmpParam); + } +} + +GL_API void GL_APIENTRY glHint( GLenum target, GLenum mode) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::hintTargetMode(target,mode),GL_INVALID_ENUM); + ctx->dispatcher().glHint(target,mode); +} + +GL_API void GL_APIENTRY glLightModelf( GLenum pname, GLfloat param) { + GET_CTX() + ctx->dispatcher().glLightModelf(pname,param); +} + +GL_API void GL_APIENTRY glLightModelfv( GLenum pname, const GLfloat *params) { + GET_CTX() + ctx->dispatcher().glLightModelfv(pname,params); +} + +GL_API void GL_APIENTRY glLightModelx( GLenum pname, GLfixed param) { + GET_CTX() + GLfloat tmpParam = static_cast<GLfloat>(param); + ctx->dispatcher().glLightModelf(pname,tmpParam); +} + +GL_API void GL_APIENTRY glLightModelxv( GLenum pname, const GLfixed *params) { + GET_CTX() + GLfloat tmpParams[4]; + if(pname == GL_LIGHT_MODEL_TWO_SIDE) { + tmpParams[0] = X2F(params[0]); + } else if (pname == GL_LIGHT_MODEL_AMBIENT) { + for(int i=0;i<4;i++) { + tmpParams[i] = X2F(params[i]); + } + } + + ctx->dispatcher().glLightModelfv(pname,tmpParams); +} + +GL_API void GL_APIENTRY glLightf( GLenum light, GLenum pname, GLfloat param) { + GET_CTX() + ctx->dispatcher().glLightf(light,pname,param); +} + +GL_API void GL_APIENTRY glLightfv( GLenum light, GLenum pname, const GLfloat *params) { + GET_CTX() + ctx->dispatcher().glLightfv(light,pname,params); +} + +GL_API void GL_APIENTRY glLightx( GLenum light, GLenum pname, GLfixed param) { + GET_CTX() + ctx->dispatcher().glLightf(light,pname,X2F(param)); +} + +GL_API void GL_APIENTRY glLightxv( GLenum light, GLenum pname, const GLfixed *params) { + GET_CTX() + GLfloat tmpParams[4]; + + switch (pname) { + case GL_AMBIENT: + case GL_DIFFUSE: + case GL_SPECULAR: + case GL_EMISSION: + case GL_POSITION: + tmpParams[3] = X2F(params[3]); + case GL_SPOT_DIRECTION: + tmpParams[2] = X2F(params[2]); + tmpParams[1] = X2F(params[1]); + case GL_SPOT_EXPONENT: + case GL_SPOT_CUTOFF: + case GL_CONSTANT_ATTENUATION: + case GL_LINEAR_ATTENUATION: + case GL_QUADRATIC_ATTENUATION: + tmpParams[0] = X2F(params[0]); + break; + default: { + ctx->setGLerror(GL_INVALID_ENUM); + return; + } + } + ctx->dispatcher().glLightfv(light,pname,tmpParams); +} + +GL_API void GL_APIENTRY glLineWidth( GLfloat width) { + GET_CTX() + ctx->dispatcher().glLineWidth(width); +} + +GL_API void GL_APIENTRY glLineWidthx( GLfixed width) { + GET_CTX() + ctx->dispatcher().glLineWidth(X2F(width)); +} + +GL_API void GL_APIENTRY glLoadIdentity( void) { + GET_CTX() + ctx->dispatcher().glLoadIdentity(); +} + +GL_API void GL_APIENTRY glLoadMatrixf( const GLfloat *m) { + GET_CTX() + ctx->dispatcher().glLoadMatrixf(m); +} + +GL_API void GL_APIENTRY glLoadMatrixx( const GLfixed *m) { + GET_CTX() + GLfloat mat[16]; + for(int i=0; i< 16 ; i++) { + mat[i] = X2F(m[i]); + } + ctx->dispatcher().glLoadMatrixf(mat); +} + +GL_API void GL_APIENTRY glLogicOp( GLenum opcode) { + GET_CTX() + ctx->dispatcher().glLogicOp(opcode); +} + +GL_API void GL_APIENTRY glMaterialf( GLenum face, GLenum pname, GLfloat param) { + GET_CTX() + ctx->dispatcher().glMaterialf(face,pname,param); +} + +GL_API void GL_APIENTRY glMaterialfv( GLenum face, GLenum pname, const GLfloat *params) { + GET_CTX() + ctx->dispatcher().glMaterialfv(face,pname,params); +} + +GL_API void GL_APIENTRY glMaterialx( GLenum face, GLenum pname, GLfixed param) { + GET_CTX() + ctx->dispatcher().glMaterialf(face,pname,X2F(param)); +} + +GL_API void GL_APIENTRY glMaterialxv( GLenum face, GLenum pname, const GLfixed *params) { + GET_CTX() + GLfloat tmpParams[4]; + + for(int i=0; i< 4; i++) { + tmpParams[i] = X2F(params[i]); + } + ctx->dispatcher().glMaterialfv(face,pname,tmpParams); +} + +GL_API void GL_APIENTRY glMatrixMode( GLenum mode) { + GET_CTX() + ctx->dispatcher().glMatrixMode(mode); +} + +GL_API void GL_APIENTRY glMultMatrixf( const GLfloat *m) { + GET_CTX() + ctx->dispatcher().glMultMatrixf(m); +} + +GL_API void GL_APIENTRY glMultMatrixx( const GLfixed *m) { + GET_CTX() + GLfloat mat[16]; + for(int i=0; i< 16 ; i++) { + mat[i] = X2F(m[i]); + } + ctx->dispatcher().glMultMatrixf(mat); +} + +GL_API void GL_APIENTRY glMultiTexCoord4f( GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) { + GET_CTX_CM() + SET_ERROR_IF(!GLEScmValidate::textureEnum(target,ctx->getMaxTexUnits()),GL_INVALID_ENUM); + ctx->dispatcher().glMultiTexCoord4f(target,s,t,r,q); +} + +GL_API void GL_APIENTRY glMultiTexCoord4x( GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q) { + GET_CTX_CM() + SET_ERROR_IF(!GLEScmValidate::textureEnum(target,ctx->getMaxTexUnits()),GL_INVALID_ENUM); + ctx->dispatcher().glMultiTexCoord4f(target,X2F(s),X2F(t),X2F(r),X2F(q)); +} + +GL_API void GL_APIENTRY glNormal3f( GLfloat nx, GLfloat ny, GLfloat nz) { + GET_CTX() + ctx->dispatcher().glNormal3f(nx,ny,nz); +} + +GL_API void GL_APIENTRY glNormal3x( GLfixed nx, GLfixed ny, GLfixed nz) { + GET_CTX() + ctx->dispatcher().glNormal3f(X2F(nx),X2F(ny),X2F(nz)); +} + +GL_API void GL_APIENTRY glNormalPointer( GLenum type, GLsizei stride, const GLvoid *pointer) { + GET_CTX() + SET_ERROR_IF(stride < 0,GL_INVALID_VALUE); + SET_ERROR_IF(!GLEScmValidate::normalPointerType(type),GL_INVALID_ENUM); + ctx->setPointer(GL_NORMAL_ARRAY,3,type,stride,pointer);//3 normal verctor +} + +GL_API void GL_APIENTRY glOrthof( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) { + GET_CTX() + ctx->dispatcher().glOrtho(left,right,bottom,top,zNear,zFar); +} + +GL_API void GL_APIENTRY glOrthox( GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) { + GET_CTX() + ctx->dispatcher().glOrtho(X2F(left),X2F(right),X2F(bottom),X2F(top),X2F(zNear),X2F(zFar)); +} + +GL_API void GL_APIENTRY glPixelStorei( GLenum pname, GLint param) { + GET_CTX() + SET_ERROR_IF(!(pname == GL_PACK_ALIGNMENT || pname == GL_UNPACK_ALIGNMENT),GL_INVALID_ENUM); + SET_ERROR_IF(!((param==1)||(param==2)||(param==4)||(param==8)), GL_INVALID_VALUE); + ctx->setUnpackAlignment(param); + ctx->dispatcher().glPixelStorei(pname,param); +} + +GL_API void GL_APIENTRY glPointParameterf( GLenum pname, GLfloat param) { + GET_CTX() + ctx->dispatcher().glPointParameterf(pname,param); +} + +GL_API void GL_APIENTRY glPointParameterfv( GLenum pname, const GLfloat *params) { + GET_CTX() + ctx->dispatcher().glPointParameterfv(pname,params); +} + +GL_API void GL_APIENTRY glPointParameterx( GLenum pname, GLfixed param) +{ + GET_CTX() + ctx->dispatcher().glPointParameterf(pname,X2F(param)); +} + +GL_API void GL_APIENTRY glPointParameterxv( GLenum pname, const GLfixed *params) { + GET_CTX() + + GLfloat tmpParam = X2F(*params) ; + ctx->dispatcher().glPointParameterfv(pname,&tmpParam); +} + +GL_API void GL_APIENTRY glPointSize( GLfloat size) { + GET_CTX() + ctx->dispatcher().glPointSize(size); +} + +GL_API void GL_APIENTRY glPointSizePointerOES( GLenum type, GLsizei stride, const GLvoid *pointer) { + GET_CTX() + SET_ERROR_IF(stride < 0,GL_INVALID_VALUE); + SET_ERROR_IF(!GLEScmValidate::pointPointerType(type),GL_INVALID_ENUM); + ctx->setPointer(GL_POINT_SIZE_ARRAY_OES,1,type,stride,pointer); +} + +GL_API void GL_APIENTRY glPointSizex( GLfixed size) { + GET_CTX() + ctx->dispatcher().glPointSize(X2F(size)); +} + +GL_API void GL_APIENTRY glPolygonOffset( GLfloat factor, GLfloat units) { + GET_CTX() + ctx->dispatcher().glPolygonOffset(factor,units); +} + +GL_API void GL_APIENTRY glPolygonOffsetx( GLfixed factor, GLfixed units) { + GET_CTX() + ctx->dispatcher().glPolygonOffset(X2F(factor),X2F(units)); +} + +GL_API void GL_APIENTRY glPopMatrix(void) { + GET_CTX() + ctx->dispatcher().glPopMatrix(); +} + +GL_API void GL_APIENTRY glPushMatrix(void) { + GET_CTX() + ctx->dispatcher().glPushMatrix(); +} + +GL_API void GL_APIENTRY glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) { + GET_CTX() + SET_ERROR_IF(!(GLEScmValidate::pixelFrmt(ctx,format) && GLEScmValidate::pixelType(ctx,type)),GL_INVALID_ENUM); + SET_ERROR_IF(!(GLEScmValidate::pixelOp(format,type)),GL_INVALID_OPERATION); + + ctx->dispatcher().glReadPixels(x,y,width,height,format,type,pixels); +} + +GL_API void GL_APIENTRY glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z) { + GET_CTX() + ctx->dispatcher().glRotatef(angle,x,y,z); +} + +GL_API void GL_APIENTRY glRotatex( GLfixed angle, GLfixed x, GLfixed y, GLfixed z) { + GET_CTX() + ctx->dispatcher().glRotatef(angle,X2F(x),X2F(y),X2F(z)); +} + +GL_API void GL_APIENTRY glSampleCoverage( GLclampf value, GLboolean invert) { + GET_CTX() + ctx->dispatcher().glSampleCoverage(value,invert); +} + +GL_API void GL_APIENTRY glSampleCoveragex( GLclampx value, GLboolean invert) { + GET_CTX() + ctx->dispatcher().glSampleCoverage(X2F(value),invert); +} + +GL_API void GL_APIENTRY glScalef( GLfloat x, GLfloat y, GLfloat z) { + GET_CTX() + ctx->dispatcher().glScalef(x,y,z); +} + +GL_API void GL_APIENTRY glScalex( GLfixed x, GLfixed y, GLfixed z) { + GET_CTX() + ctx->dispatcher().glScalef(X2F(x),X2F(y),X2F(z)); +} + +GL_API void GL_APIENTRY glScissor( GLint x, GLint y, GLsizei width, GLsizei height) { + GET_CTX() + ctx->dispatcher().glScissor(x,y,width,height); +} + +GL_API void GL_APIENTRY glShadeModel( GLenum mode) { + GET_CTX() + ctx->dispatcher().glShadeModel(mode); +} + +GL_API void GL_APIENTRY glStencilFunc( GLenum func, GLint ref, GLuint mask) { + GET_CTX() + ctx->dispatcher().glStencilFunc(func,ref,mask); +} + +GL_API void GL_APIENTRY glStencilMask( GLuint mask) { + GET_CTX() + ctx->dispatcher().glStencilMask(mask); +} + +GL_API void GL_APIENTRY glStencilOp( GLenum fail, GLenum zfail, GLenum zpass) { + GET_CTX() + SET_ERROR_IF(!(GLEScmValidate::stencilOp(fail) && GLEScmValidate::stencilOp(zfail) && GLEScmValidate::stencilOp(zpass)),GL_INVALID_ENUM); + ctx->dispatcher().glStencilOp(fail,zfail,zpass); +} + +GL_API void GL_APIENTRY glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::texCoordPointerParams(size,stride),GL_INVALID_VALUE); + SET_ERROR_IF(!GLEScmValidate::texCoordPointerType(type),GL_INVALID_ENUM); + ctx->setPointer(GL_TEXTURE_COORD_ARRAY,size,type,stride,pointer); +} + +GL_API void GL_APIENTRY glTexEnvf( GLenum target, GLenum pname, GLfloat param) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM); + ctx->dispatcher().glTexEnvf(target,pname,param); +} + +GL_API void GL_APIENTRY glTexEnvfv( GLenum target, GLenum pname, const GLfloat *params) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM); + ctx->dispatcher().glTexEnvfv(target,pname,params); +} + +GL_API void GL_APIENTRY glTexEnvi( GLenum target, GLenum pname, GLint param) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM); + ctx->dispatcher().glTexEnvi(target,pname,param); +} + +GL_API void GL_APIENTRY glTexEnviv( GLenum target, GLenum pname, const GLint *params) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM); + ctx->dispatcher().glTexEnviv(target,pname,params); +} + +GL_API void GL_APIENTRY glTexEnvx( GLenum target, GLenum pname, GLfixed param) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM); + GLfloat tmpParam = static_cast<GLfloat>(param); + ctx->dispatcher().glTexEnvf(target,pname,tmpParam); +} + +GL_API void GL_APIENTRY glTexEnvxv( GLenum target, GLenum pname, const GLfixed *params) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM); + + GLfloat tmpParams[4]; + if(pname == GL_TEXTURE_ENV_COLOR) { + for(int i =0;i<4;i++) { + tmpParams[i] = X2F(params[i]); + } + } else { + tmpParams[0] = static_cast<GLfloat>(params[0]); + } + ctx->dispatcher().glTexEnvfv(target,pname,tmpParams); +} + +GL_API void GL_APIENTRY glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels) { + GET_CTX() + + SET_ERROR_IF(!(GLEScmValidate::textureTargetEx(target) && + GLEScmValidate::pixelFrmt(ctx,internalformat) && + GLEScmValidate::pixelFrmt(ctx,format) && + GLEScmValidate::pixelType(ctx,type)),GL_INVALID_ENUM); + + SET_ERROR_IF(!(GLEScmValidate::pixelOp(format,type) && internalformat == ((GLint)format)),GL_INVALID_OPERATION); + + bool needAutoMipmap = false; + + if (ctx->shareGroup().Ptr()){ + TextureData *texData = getTextureTargetData(target); + SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION); + if(texData) { + texData->width = width; + texData->height = height; + texData->border = border; + texData->internalFormat = internalformat; + texData->target = target; + + if (texData->sourceEGLImage != 0) { + // + // This texture was a target of EGLImage, + // but now it is re-defined so we need to detach + // from the EGLImage and re-generate global texture name + // for it. + // + if (texData->eglImageDetach) { + (*texData->eglImageDetach)(texData->sourceEGLImage); + } + unsigned int tex = ctx->getBindedTexture(target); + ctx->shareGroup()->replaceGlobalName(TEXTURE, + tex, + texData->oldGlobal); + ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, texData->oldGlobal); + texData->sourceEGLImage = 0; + texData->oldGlobal = 0; + } + + needAutoMipmap = texData->requiresAutoMipmap; + } + } + + ctx->dispatcher().glTexImage2D(target,level, + internalformat,width,height, + border,format,type,pixels); + + if(needAutoMipmap) + { + ctx->dispatcher().glGenerateMipmapEXT(target); + } +} + +static bool handleMipmapGeneration(GLenum target, GLenum pname, bool param) +{ + GET_CTX_RET(false) + + if(pname == GL_GENERATE_MIPMAP && !ctx->isAutoMipmapSupported()) + { + TextureData *texData = getTextureTargetData(target); + if(texData) + { + texData->requiresAutoMipmap = param; + } + return true; + } + + return false; +} + +GL_API void GL_APIENTRY glTexParameterf( GLenum target, GLenum pname, GLfloat param) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM); + + if(handleMipmapGeneration(target, pname, (bool)param)) + return; + + ctx->dispatcher().glTexParameterf(target,pname,param); +} + +GL_API void GL_APIENTRY glTexParameterfv( GLenum target, GLenum pname, const GLfloat *params) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM); + + if(handleMipmapGeneration(target, pname, (bool)(*params))) + return; + + if (pname==GL_TEXTURE_CROP_RECT_OES) { + TextureData *texData = getTextureTargetData(target); + SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION); + for (int i=0;i<4;++i) + texData->crop_rect[i] = params[i]; + } + else { + ctx->dispatcher().glTexParameterfv(target,pname,params); + } +} + +GL_API void GL_APIENTRY glTexParameteri( GLenum target, GLenum pname, GLint param) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM); + + if(handleMipmapGeneration(target, pname, (bool)param)) + return; + + ctx->dispatcher().glTexParameteri(target,pname,param); +} + +GL_API void GL_APIENTRY glTexParameteriv( GLenum target, GLenum pname, const GLint *params) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM); + + if(handleMipmapGeneration(target, pname, (bool)(*params))) + return; + + if (pname==GL_TEXTURE_CROP_RECT_OES) { + TextureData *texData = getTextureTargetData(target); + SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION); + for (int i=0;i<4;++i) + texData->crop_rect[i] = params[i]; + } + else { + ctx->dispatcher().glTexParameteriv(target,pname,params); + } +} + +GL_API void GL_APIENTRY glTexParameterx( GLenum target, GLenum pname, GLfixed param) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM); + + if(handleMipmapGeneration(target, pname, (bool)param)) + return; + + ctx->dispatcher().glTexParameterf(target,pname,static_cast<GLfloat>(param)); +} + +GL_API void GL_APIENTRY glTexParameterxv( GLenum target, GLenum pname, const GLfixed *params) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM); + + if(handleMipmapGeneration(target, pname, (bool)(*params))) + return; + + if (pname==GL_TEXTURE_CROP_RECT_OES) { + TextureData *texData = getTextureTargetData(target); + SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION); + for (int i=0;i<4;++i) + texData->crop_rect[i] = X2F(params[i]); + } + else { + GLfloat param = static_cast<GLfloat>(params[0]); + ctx->dispatcher().glTexParameterfv(target,pname,¶m); + } +} + +GL_API void GL_APIENTRY glTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels) { + GET_CTX() + SET_ERROR_IF(!(GLEScmValidate::textureTargetEx(target) && + GLEScmValidate::pixelFrmt(ctx,format)&& + GLEScmValidate::pixelType(ctx,type)),GL_INVALID_ENUM); + SET_ERROR_IF(!GLEScmValidate::pixelOp(format,type),GL_INVALID_OPERATION); + + ctx->dispatcher().glTexSubImage2D(target,level,xoffset,yoffset,width,height,format,type,pixels); + + if (ctx->shareGroup().Ptr()){ + TextureData *texData = getTextureTargetData(target); + SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION); + if(texData && texData->requiresAutoMipmap) + { + ctx->dispatcher().glGenerateMipmapEXT(target); + } + } +} + +GL_API void GL_APIENTRY glTranslatef( GLfloat x, GLfloat y, GLfloat z) { + GET_CTX() + ctx->dispatcher().glTranslatef(x,y,z); +} + +GL_API void GL_APIENTRY glTranslatex( GLfixed x, GLfixed y, GLfixed z) { + GET_CTX() + ctx->dispatcher().glTranslatef(X2F(x),X2F(y),X2F(z)); +} + +GL_API void GL_APIENTRY glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::vertexPointerParams(size,stride),GL_INVALID_VALUE); + SET_ERROR_IF(!GLEScmValidate::vertexPointerType(type),GL_INVALID_ENUM); + ctx->setPointer(GL_VERTEX_ARRAY,size,type,stride,pointer); +} + +GL_API void GL_APIENTRY glViewport( GLint x, GLint y, GLsizei width, GLsizei height) { + GET_CTX() + ctx->dispatcher().glViewport(x,y,width,height); +} + +GL_API void GL_APIENTRY glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) +{ + GET_CTX(); + SET_ERROR_IF(!GLEScmValidate::textureTargetLimited(target),GL_INVALID_ENUM); + unsigned int imagehndl = ToTargetCompatibleHandle((uintptr_t)image); + EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl); + if (img) { + // Create the texture object in the underlying EGL implementation, + // flag to the OpenGL layer to skip the image creation and map the + // current binded texture object to the existing global object. + if (ctx->shareGroup().Ptr()) { + ObjectLocalName tex = TextureLocalName(target,ctx->getBindedTexture(target)); + unsigned int oldGlobal = ctx->shareGroup()->getGlobalName(TEXTURE, tex); + // Delete old texture object but only if it is not a target of a EGLImage + if (oldGlobal) { + TextureData* oldTexData = getTextureData(tex); + if (!oldTexData || oldTexData->sourceEGLImage == 0) { + ctx->dispatcher().glDeleteTextures(1, &oldGlobal); + } + } + // replace mapping and bind the new global object + ctx->shareGroup()->replaceGlobalName(TEXTURE, tex,img->globalTexName); + ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, img->globalTexName); + TextureData *texData = getTextureTargetData(target); + SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION); + texData->width = img->width; + texData->height = img->height; + texData->border = img->border; + texData->internalFormat = img->internalFormat; + texData->sourceEGLImage = imagehndl; + texData->eglImageDetach = s_eglIface->eglDetachEGLImage; + texData->oldGlobal = oldGlobal; + } + } +} + +GL_API void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image) +{ + GET_CTX(); + SET_ERROR_IF(target != GL_RENDERBUFFER_OES,GL_INVALID_ENUM); + unsigned int imagehndl = ToTargetCompatibleHandle((uintptr_t)image); + EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl); + SET_ERROR_IF(!img,GL_INVALID_VALUE); + SET_ERROR_IF(!ctx->shareGroup().Ptr(),GL_INVALID_OPERATION); + + // Get current bounded renderbuffer + // raise INVALID_OPERATIOn if no renderbuffer is bounded + GLuint rb = ctx->getRenderbufferBinding(); + SET_ERROR_IF(rb == 0,GL_INVALID_OPERATION); + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(RENDERBUFFER,rb); + RenderbufferData *rbData = (RenderbufferData *)objData.Ptr(); + SET_ERROR_IF(!rbData,GL_INVALID_OPERATION); + + // + // flag in the renderbufferData that it is an eglImage target + // + rbData->sourceEGLImage = imagehndl; + rbData->eglImageDetach = s_eglIface->eglDetachEGLImage; + rbData->eglImageGlobalTexName = img->globalTexName; + + // + // if the renderbuffer is attached to a framebuffer + // change the framebuffer attachment in the undelying OpenGL + // to point to the eglImage texture object. + // + if (rbData->attachedFB) { + // update the framebuffer attachment point to the + // underlying texture of the img + GLuint prevFB = ctx->getFramebufferBinding(); + if (prevFB != rbData->attachedFB) { + ctx->dispatcher().glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, + rbData->attachedFB); + } + ctx->dispatcher().glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, + rbData->attachedPoint, + GL_TEXTURE_2D, + img->globalTexName,0); + if (prevFB != rbData->attachedFB) { + ctx->dispatcher().glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, + prevFB); + } + } +} + +/* GL_OES_blend_subtract*/ +GL_API void GL_APIENTRY glBlendEquationOES(GLenum mode) { + GET_CTX() + SET_ERROR_IF(!(GLEScmValidate::blendEquationMode(mode)), GL_INVALID_ENUM); + ctx->dispatcher().glBlendEquation(mode); +} + +/* GL_OES_blend_equation_separate */ +GL_API void GL_APIENTRY glBlendEquationSeparateOES (GLenum modeRGB, GLenum modeAlpha) { + GET_CTX() + SET_ERROR_IF(!(GLEScmValidate::blendEquationMode(modeRGB) && GLEScmValidate::blendEquationMode(modeAlpha)), GL_INVALID_ENUM); + ctx->dispatcher().glBlendEquationSeparate(modeRGB,modeAlpha); +} + +/* GL_OES_blend_func_separate */ +GL_API void GL_APIENTRY glBlendFuncSeparateOES(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::blendSrc(srcRGB) || !GLEScmValidate::blendDst(dstRGB) || + !GLEScmValidate::blendSrc(srcAlpha) || ! GLEScmValidate::blendDst(dstAlpha) ,GL_INVALID_ENUM); + ctx->dispatcher().glBlendFuncSeparate(srcRGB,dstRGB,srcAlpha,dstAlpha); +} + +/* GL_OES_framebuffer_object */ +GL_API GLboolean GL_APIENTRY glIsRenderbufferOES(GLuint renderbuffer) { + GET_CTX_RET(GL_FALSE) + RET_AND_SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION,GL_FALSE); + if(renderbuffer && ctx->shareGroup().Ptr()){ + return ctx->shareGroup()->isObject(RENDERBUFFER,renderbuffer) ? GL_TRUE :GL_FALSE; + } + return ctx->dispatcher().glIsRenderbufferEXT(renderbuffer); +} + +GL_API void GLAPIENTRY glBindRenderbufferOES(GLenum target, GLuint renderbuffer) { + GET_CTX() + SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); + SET_ERROR_IF(!GLEScmValidate::renderbufferTarget(target),GL_INVALID_ENUM); + + //if buffer wasn't generated before,generate one + if(renderbuffer && ctx->shareGroup().Ptr() && !ctx->shareGroup()->isObject(RENDERBUFFER,renderbuffer)){ + ctx->shareGroup()->genName(RENDERBUFFER,renderbuffer); + ctx->shareGroup()->setObjectData(RENDERBUFFER, + renderbuffer, + ObjectDataPtr(new RenderbufferData())); + } + + int globalBufferName = (renderbuffer != 0) ? ctx->shareGroup()->getGlobalName(RENDERBUFFER,renderbuffer) : 0; + ctx->dispatcher().glBindRenderbufferEXT(target,globalBufferName); + + // update renderbuffer binding state + ctx->setRenderbufferBinding(renderbuffer); +} + +GL_API void GLAPIENTRY glDeleteRenderbuffersOES(GLsizei n, const GLuint *renderbuffers) { + GET_CTX() + SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); + for (int i=0;i<n;++i) { + GLuint globalBufferName = ctx->shareGroup()->getGlobalName(RENDERBUFFER,renderbuffers[i]); + ctx->dispatcher().glDeleteRenderbuffersEXT(1,&globalBufferName); + } +} + +GL_API void GLAPIENTRY glGenRenderbuffersOES(GLsizei n, GLuint *renderbuffers) { + GET_CTX() + SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); + SET_ERROR_IF(n<0,GL_INVALID_VALUE); + if(ctx->shareGroup().Ptr()) { + for(int i=0; i<n ;i++) { + renderbuffers[i] = ctx->shareGroup()->genName(RENDERBUFFER, 0, true); + ctx->shareGroup()->setObjectData(RENDERBUFFER, + renderbuffers[i], + ObjectDataPtr(new RenderbufferData())); + } + } +} + +GL_API void GLAPIENTRY glRenderbufferStorageOES(GLenum target, GLenum internalformat, GLsizei width, GLsizei height){ + GET_CTX() + SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); + SET_ERROR_IF(!GLEScmValidate::renderbufferTarget(target) || !GLEScmValidate::renderbufferInternalFrmt(ctx,internalformat) ,GL_INVALID_ENUM); + if (internalformat==GL_RGB565_OES) //RGB565 not supported by GL + internalformat = GL_RGB8_OES; + + // Get current bounded renderbuffer + // raise INVALID_OPERATIOn if no renderbuffer is bounded + GLuint rb = ctx->getRenderbufferBinding(); + SET_ERROR_IF(rb == 0,GL_INVALID_OPERATION); + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(RENDERBUFFER,rb); + RenderbufferData *rbData = (RenderbufferData *)objData.Ptr(); + SET_ERROR_IF(!rbData,GL_INVALID_OPERATION); + + // + // if the renderbuffer was an eglImage target, detach from + // the eglImage. + // + if (rbData->sourceEGLImage != 0) { + if (rbData->eglImageDetach) { + (*rbData->eglImageDetach)(rbData->sourceEGLImage); + } + rbData->sourceEGLImage = 0; + rbData->eglImageGlobalTexName = 0; + } + + ctx->dispatcher().glRenderbufferStorageEXT(target,internalformat,width,height); +} + +GL_API void GLAPIENTRY glGetRenderbufferParameterivOES(GLenum target, GLenum pname, GLint* params) { + GET_CTX() + SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); + SET_ERROR_IF(!GLEScmValidate::renderbufferTarget(target) || !GLEScmValidate::renderbufferParams(pname) ,GL_INVALID_ENUM); + + // + // If this is a renderbuffer which is eglimage's target, we + // should query the underlying eglimage's texture object instead. + // + GLuint rb = ctx->getRenderbufferBinding(); + if (rb) { + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(RENDERBUFFER,rb); + RenderbufferData *rbData = (RenderbufferData *)objData.Ptr(); + if (rbData && rbData->sourceEGLImage != 0) { + GLenum texPname; + switch(pname) { + case GL_RENDERBUFFER_WIDTH_OES: + texPname = GL_TEXTURE_WIDTH; + break; + case GL_RENDERBUFFER_HEIGHT_OES: + texPname = GL_TEXTURE_HEIGHT; + break; + case GL_RENDERBUFFER_INTERNAL_FORMAT_OES: + texPname = GL_TEXTURE_INTERNAL_FORMAT; + break; + case GL_RENDERBUFFER_RED_SIZE_OES: + texPname = GL_TEXTURE_RED_SIZE; + break; + case GL_RENDERBUFFER_GREEN_SIZE_OES: + texPname = GL_TEXTURE_GREEN_SIZE; + break; + case GL_RENDERBUFFER_BLUE_SIZE_OES: + texPname = GL_TEXTURE_BLUE_SIZE; + break; + case GL_RENDERBUFFER_ALPHA_SIZE_OES: + texPname = GL_TEXTURE_ALPHA_SIZE; + break; + case GL_RENDERBUFFER_DEPTH_SIZE_OES: + texPname = GL_TEXTURE_DEPTH_SIZE; + break; + case GL_RENDERBUFFER_STENCIL_SIZE_OES: + default: + *params = 0; //XXX + return; + break; + } + + GLint prevTex; + ctx->dispatcher().glGetIntegerv(GL_TEXTURE_BINDING_2D, &prevTex); + ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, + rbData->eglImageGlobalTexName); + ctx->dispatcher().glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, + texPname, + params); + ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, prevTex); + return; + } + } + + ctx->dispatcher().glGetRenderbufferParameterivEXT(target,pname,params); +} + +GL_API GLboolean GLAPIENTRY glIsFramebufferOES(GLuint framebuffer) { + GET_CTX_RET(GL_FALSE) + RET_AND_SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION,GL_FALSE); + if (framebuffer && ctx->shareGroup().Ptr()) { + return ctx->shareGroup()->isObject(FRAMEBUFFER,framebuffer) ? GL_TRUE : GL_FALSE; + } + return ctx->dispatcher().glIsFramebufferEXT(framebuffer); +} + +GL_API void GLAPIENTRY glBindFramebufferOES(GLenum target, GLuint framebuffer) { + GET_CTX() + SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); + SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) ,GL_INVALID_ENUM); + if (framebuffer && ctx->shareGroup().Ptr() && !ctx->shareGroup()->isObject(FRAMEBUFFER,framebuffer)) { + ctx->shareGroup()->genName(FRAMEBUFFER,framebuffer); + ctx->shareGroup()->setObjectData(FRAMEBUFFER, framebuffer, + ObjectDataPtr(new FramebufferData(framebuffer))); + } + int globalBufferName = (framebuffer!=0) ? ctx->shareGroup()->getGlobalName(FRAMEBUFFER,framebuffer) : 0; + ctx->dispatcher().glBindFramebufferEXT(target,globalBufferName); + + // update framebuffer binding state + ctx->setFramebufferBinding(framebuffer); +} + +GL_API void GLAPIENTRY glDeleteFramebuffersOES(GLsizei n, const GLuint *framebuffers) { + GET_CTX() + SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); + for (int i=0;i<n;++i) { + GLuint globalBufferName = ctx->shareGroup()->getGlobalName(FRAMEBUFFER,framebuffers[i]); + ctx->dispatcher().glDeleteFramebuffersEXT(1,&globalBufferName); + } +} + +GL_API void GLAPIENTRY glGenFramebuffersOES(GLsizei n, GLuint *framebuffers) { + GET_CTX() + SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); + SET_ERROR_IF(n<0,GL_INVALID_VALUE); + if (ctx->shareGroup().Ptr()) { + for (int i=0;i<n;i++) { + framebuffers[i] = ctx->shareGroup()->genName(FRAMEBUFFER, 0, true); + ctx->shareGroup()->setObjectData(FRAMEBUFFER, framebuffers[i], + ObjectDataPtr(new FramebufferData(framebuffers[i]))); + } + } +} + +GL_API GLenum GLAPIENTRY glCheckFramebufferStatusOES(GLenum target) { + GET_CTX_RET(0) + RET_AND_SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION,0); + RET_AND_SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) ,GL_INVALID_ENUM,0); + return ctx->dispatcher().glCheckFramebufferStatusEXT(target); +} + +GL_API void GLAPIENTRY glFramebufferTexture2DOES(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) { + GET_CTX() + SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); + SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) || !GLEScmValidate::framebufferAttachment(attachment) || + !GLEScmValidate::textureTargetEx(textarget),GL_INVALID_ENUM); + SET_ERROR_IF(!ctx->shareGroup().Ptr(), GL_INVALID_OPERATION); + + GLuint globalTexName = 0; + if(texture) { + if (!ctx->shareGroup()->isObject(TEXTURE,texture)) { + ctx->shareGroup()->genName(TEXTURE,texture); + } + ObjectLocalName texname = TextureLocalName(textarget,texture); + globalTexName = ctx->shareGroup()->getGlobalName(TEXTURE,texname); + } + + ctx->dispatcher().glFramebufferTexture2DEXT(target,attachment,textarget,globalTexName,level); + + // Update the the current framebuffer object attachment state + GLuint fbName = ctx->getFramebufferBinding(); + ObjectDataPtr fbObj = ctx->shareGroup()->getObjectData(FRAMEBUFFER,fbName); + if (fbObj.Ptr() != NULL) { + FramebufferData *fbData = (FramebufferData *)fbObj.Ptr(); + fbData->setAttachment(attachment, textarget, + texture, ObjectDataPtr(NULL)); + } +} + +GL_API void GLAPIENTRY glFramebufferRenderbufferOES(GLenum target, GLenum attachment,GLenum renderbuffertarget, GLuint renderbuffer) { + GET_CTX() + SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); + SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) || + !GLEScmValidate::framebufferAttachment(attachment) || + !GLEScmValidate::renderbufferTarget(renderbuffertarget), GL_INVALID_ENUM); + + SET_ERROR_IF(!ctx->shareGroup().Ptr(), GL_INVALID_OPERATION); + + GLuint globalBufferName = 0; + ObjectDataPtr obj; + + // generate the renderbuffer object if not yet exist + if (renderbuffer) { + if (!ctx->shareGroup()->isObject(RENDERBUFFER,renderbuffer)) { + ctx->shareGroup()->genName(RENDERBUFFER,renderbuffer); + obj = ObjectDataPtr(new RenderbufferData()); + ctx->shareGroup()->setObjectData(RENDERBUFFER, + renderbuffer, + ObjectDataPtr(new RenderbufferData())); + } + else { + obj = ctx->shareGroup()->getObjectData(RENDERBUFFER,renderbuffer); + } + globalBufferName = ctx->shareGroup()->getGlobalName(RENDERBUFFER,renderbuffer); + } + + // Update the the current framebuffer object attachment state + GLuint fbName = ctx->getFramebufferBinding(); + ObjectDataPtr fbObj = ctx->shareGroup()->getObjectData(FRAMEBUFFER,fbName); + if (fbObj.Ptr() != NULL) { + FramebufferData *fbData = (FramebufferData *)fbObj.Ptr(); + fbData->setAttachment(attachment, renderbuffertarget, renderbuffer, obj); + } + + if (renderbuffer && obj.Ptr() != NULL) { + RenderbufferData *rbData = (RenderbufferData *)obj.Ptr(); + if (rbData->sourceEGLImage != 0) { + // + // This renderbuffer object is an eglImage target + // attach the eglimage's texture instead the renderbuffer. + // + ctx->dispatcher().glFramebufferTexture2DEXT(target, + attachment, + GL_TEXTURE_2D, + rbData->eglImageGlobalTexName,0); + return; + } + } + + ctx->dispatcher().glFramebufferRenderbufferEXT(target,attachment,renderbuffertarget,globalBufferName); +} + +GL_API void GLAPIENTRY glGetFramebufferAttachmentParameterivOES(GLenum target, GLenum attachment, GLenum pname, GLint *params) { + GET_CTX() + SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); + SET_ERROR_IF(!GLEScmValidate::framebufferTarget(target) || !GLEScmValidate::framebufferAttachment(attachment) || + !GLEScmValidate::framebufferAttachmentParams(pname), GL_INVALID_ENUM); + + // + // Take the attachment attribute from our state - if available + // + GLuint fbName = ctx->getFramebufferBinding(); + if (fbName) { + ObjectDataPtr fbObj = ctx->shareGroup()->getObjectData(FRAMEBUFFER,fbName); + if (fbObj.Ptr() != NULL) { + FramebufferData *fbData = (FramebufferData *)fbObj.Ptr(); + GLenum target; + GLuint name = fbData->getAttachment(attachment, &target, NULL); + if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_OES) { + *params = target; + return; + } + else if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_OES) { + *params = name; + return; + } + } + } + + ctx->dispatcher().glGetFramebufferAttachmentParameterivEXT(target,attachment,pname,params); +} + +GL_API void GL_APIENTRY glGenerateMipmapOES(GLenum target) { + GET_CTX() + SET_ERROR_IF(!ctx->getCaps()->GL_EXT_FRAMEBUFFER_OBJECT,GL_INVALID_OPERATION); + SET_ERROR_IF(!GLEScmValidate::textureTargetLimited(target),GL_INVALID_ENUM); + ctx->dispatcher().glGenerateMipmapEXT(target); +} + +GL_API void GL_APIENTRY glCurrentPaletteMatrixOES(GLuint index) { + GET_CTX() + SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION); + ctx->dispatcher().glCurrentPaletteMatrixARB(index); +} + +GL_API void GL_APIENTRY glLoadPaletteFromModelViewMatrixOES() { + GET_CTX() + SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION); + GLint matrix[16]; + ctx->dispatcher().glGetIntegerv(GL_MODELVIEW_MATRIX,matrix); + ctx->dispatcher().glMatrixIndexuivARB(1,(GLuint*)matrix); + +} + +GL_API void GL_APIENTRY glMatrixIndexPointerOES(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { + GET_CTX() + SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION); + ctx->dispatcher().glMatrixIndexPointerARB(size,type,stride,pointer); +} + +GL_API void GL_APIENTRY glWeightPointerOES(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { + GET_CTX() + SET_ERROR_IF(!(ctx->getCaps()->GL_ARB_MATRIX_PALETTE && ctx->getCaps()->GL_ARB_VERTEX_BLEND),GL_INVALID_OPERATION); + ctx->dispatcher().glWeightPointerARB(size,type,stride,pointer); + +} + +GL_API void GL_APIENTRY glTexGenfOES (GLenum coord, GLenum pname, GLfloat param) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM); + if (coord == GL_TEXTURE_GEN_STR_OES) { + ctx->dispatcher().glTexGenf(GL_S,pname,param); + ctx->dispatcher().glTexGenf(GL_T,pname,param); + ctx->dispatcher().glTexGenf(GL_R,pname,param); + } + else + ctx->dispatcher().glTexGenf(coord,pname,param); +} + +GL_API void GL_APIENTRY glTexGenfvOES (GLenum coord, GLenum pname, const GLfloat *params) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM); + if (coord == GL_TEXTURE_GEN_STR_OES) { + ctx->dispatcher().glTexGenfv(GL_S,pname,params); + ctx->dispatcher().glTexGenfv(GL_T,pname,params); + ctx->dispatcher().glTexGenfv(GL_R,pname,params); + } + else + ctx->dispatcher().glTexGenfv(coord,pname,params); +} +GL_API void GL_APIENTRY glTexGeniOES (GLenum coord, GLenum pname, GLint param) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM); + if (coord == GL_TEXTURE_GEN_STR_OES) { + ctx->dispatcher().glTexGeni(GL_S,pname,param); + ctx->dispatcher().glTexGeni(GL_T,pname,param); + ctx->dispatcher().glTexGeni(GL_R,pname,param); + } + else + ctx->dispatcher().glTexGeni(coord,pname,param); +} +GL_API void GL_APIENTRY glTexGenivOES (GLenum coord, GLenum pname, const GLint *params) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM); + if (coord == GL_TEXTURE_GEN_STR_OES) { + ctx->dispatcher().glTexGeniv(GL_S,pname,params); + ctx->dispatcher().glTexGeniv(GL_T,pname,params); + ctx->dispatcher().glTexGeniv(GL_R,pname,params); + } + else + ctx->dispatcher().glTexGeniv(coord,pname,params); +} +GL_API void GL_APIENTRY glTexGenxOES (GLenum coord, GLenum pname, GLfixed param) { + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM); + if (coord == GL_TEXTURE_GEN_STR_OES) { + ctx->dispatcher().glTexGenf(GL_S,pname,X2F(param)); + ctx->dispatcher().glTexGenf(GL_T,pname,X2F(param)); + ctx->dispatcher().glTexGenf(GL_R,pname,X2F(param)); + } + else + ctx->dispatcher().glTexGenf(coord,pname,X2F(param)); +} +GL_API void GL_APIENTRY glTexGenxvOES (GLenum coord, GLenum pname, const GLfixed *params) { + GLfloat tmpParams[1]; + GET_CTX() + SET_ERROR_IF(!GLEScmValidate::texGen(coord,pname),GL_INVALID_ENUM); + tmpParams[0] = X2F(params[0]); + if (coord == GL_TEXTURE_GEN_STR_OES) { + ctx->dispatcher().glTexGenfv(GL_S,pname,tmpParams); + ctx->dispatcher().glTexGenfv(GL_T,pname,tmpParams); + ctx->dispatcher().glTexGenfv(GL_R,pname,tmpParams); + } + else + ctx->dispatcher().glTexGenfv(coord,pname,tmpParams); +} + +GL_API void GL_APIENTRY glGetTexGenfvOES (GLenum coord, GLenum pname, GLfloat *params) { + GET_CTX() + if (coord == GL_TEXTURE_GEN_STR_OES) + { + GLfloat state_s = GL_FALSE; + GLfloat state_t = GL_FALSE; + GLfloat state_r = GL_FALSE; + ctx->dispatcher().glGetTexGenfv(GL_S,pname,&state_s); + ctx->dispatcher().glGetTexGenfv(GL_T,pname,&state_t); + ctx->dispatcher().glGetTexGenfv(GL_R,pname,&state_r); + *params = state_s && state_t && state_r ? GL_TRUE: GL_FALSE; + } + else + ctx->dispatcher().glGetTexGenfv(coord,pname,params); + +} +GL_API void GL_APIENTRY glGetTexGenivOES (GLenum coord, GLenum pname, GLint *params) { + GET_CTX() + if (coord == GL_TEXTURE_GEN_STR_OES) + { + GLint state_s = GL_FALSE; + GLint state_t = GL_FALSE; + GLint state_r = GL_FALSE; + ctx->dispatcher().glGetTexGeniv(GL_S,pname,&state_s); + ctx->dispatcher().glGetTexGeniv(GL_T,pname,&state_t); + ctx->dispatcher().glGetTexGeniv(GL_R,pname,&state_r); + *params = state_s && state_t && state_r ? GL_TRUE: GL_FALSE; + } + else + ctx->dispatcher().glGetTexGeniv(coord,pname,params); +} + +GL_API void GL_APIENTRY glGetTexGenxvOES (GLenum coord, GLenum pname, GLfixed *params) { + GET_CTX() + GLfloat tmpParams[1]; + + if (coord == GL_TEXTURE_GEN_STR_OES) + { + GLfloat state_s = GL_FALSE; + GLfloat state_t = GL_FALSE; + GLfloat state_r = GL_FALSE; + ctx->dispatcher().glGetTexGenfv(GL_TEXTURE_GEN_S,pname,&state_s); + ctx->dispatcher().glGetTexGenfv(GL_TEXTURE_GEN_T,pname,&state_t); + ctx->dispatcher().glGetTexGenfv(GL_TEXTURE_GEN_R,pname,&state_r); + tmpParams[0] = state_s && state_t && state_r ? GL_TRUE: GL_FALSE; + } + else + ctx->dispatcher().glGetTexGenfv(coord,pname,tmpParams); + + params[0] = F2X(tmpParams[1]); +} + +template <class T, GLenum TypeName> +void glDrawTexOES (T x, T y, T z, T width, T height) { + GET_CTX() + + SET_ERROR_IF((width<=0 || height<=0),GL_INVALID_VALUE); + + ctx->drawValidate(); + + int numClipPlanes; + + GLint viewport[4]; + z = (z>1 ? 1 : (z<0 ? 0 : z)); + + T vertices[4*3] = {x , y, z, + x , y+height, z, + x+width, y+height, z, + x+width, y, z}; + GLfloat texels[ctx->getMaxTexUnits()][4*2]; + memset((void*)texels, 0, ctx->getMaxTexUnits()*4*2*sizeof(GLfloat)); + + ctx->dispatcher().glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); + ctx->dispatcher().glPushAttrib(GL_TRANSFORM_BIT); + + //setup projection matrix to draw in viewport aligned coordinates + ctx->dispatcher().glMatrixMode(GL_PROJECTION); + ctx->dispatcher().glPushMatrix(); + ctx->dispatcher().glLoadIdentity(); + ctx->dispatcher().glGetIntegerv(GL_VIEWPORT,viewport); + ctx->dispatcher().glOrtho(viewport[0],viewport[0] + viewport[2],viewport[1],viewport[1]+viewport[3],0,-1); + //setup texture matrix + ctx->dispatcher().glMatrixMode(GL_TEXTURE); + ctx->dispatcher().glPushMatrix(); + ctx->dispatcher().glLoadIdentity(); + //setup modelview matrix + ctx->dispatcher().glMatrixMode(GL_MODELVIEW); + ctx->dispatcher().glPushMatrix(); + ctx->dispatcher().glLoadIdentity(); + //backup vbo's + int array_buffer,element_array_buffer; + glGetIntegerv(GL_ARRAY_BUFFER_BINDING,&array_buffer); + glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING,&element_array_buffer); + ctx->dispatcher().glBindBuffer(GL_ARRAY_BUFFER,0); + ctx->dispatcher().glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0); + + //disable clip planes + ctx->dispatcher().glGetIntegerv(GL_MAX_CLIP_PLANES,&numClipPlanes); + for (int i=0;i<numClipPlanes;++i) + ctx->dispatcher().glDisable(GL_CLIP_PLANE0+i); + + int nTexPtrs = 0; + for (int i=0;i<ctx->getMaxTexUnits();++i) { + if (ctx->isTextureUnitEnabled(GL_TEXTURE0+i)) { + TextureData * texData = NULL; + unsigned int texname = ctx->getBindedTexture(GL_TEXTURE0+i,GL_TEXTURE_2D); + ObjectLocalName tex = TextureLocalName(GL_TEXTURE_2D,texname); + ctx->dispatcher().glClientActiveTexture(GL_TEXTURE0+i); + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(TEXTURE,tex); + if (objData.Ptr()) { + texData = (TextureData*)objData.Ptr(); + //calculate texels + texels[i][0] = (float)(texData->crop_rect[0])/(float)(texData->width); + texels[i][1] = (float)(texData->crop_rect[1])/(float)(texData->height); + + texels[i][2] = (float)(texData->crop_rect[0])/(float)(texData->width); + texels[i][3] = (float)(texData->crop_rect[3]+texData->crop_rect[1])/(float)(texData->height); + + texels[i][4] = (float)(texData->crop_rect[2]+texData->crop_rect[0])/(float)(texData->width); + texels[i][5] = (float)(texData->crop_rect[3]+texData->crop_rect[1])/(float)(texData->height); + + texels[i][6] = (float)(texData->crop_rect[2]+texData->crop_rect[0])/(float)(texData->width); + texels[i][7] = (float)(texData->crop_rect[1])/(float)(texData->height); + + ctx->dispatcher().glTexCoordPointer(2,GL_FLOAT,0,texels[i]); + nTexPtrs++; + } + } + } + + if (nTexPtrs>0) { + //draw rectangle - only if we have some textures enabled & ready + ctx->dispatcher().glEnableClientState(GL_VERTEX_ARRAY); + ctx->dispatcher().glVertexPointer(3,TypeName,0,vertices); + ctx->dispatcher().glEnableClientState(GL_TEXTURE_COORD_ARRAY); + ctx->dispatcher().glDrawArrays(GL_TRIANGLE_FAN,0,4); + } + + //restore vbo's + ctx->dispatcher().glBindBuffer(GL_ARRAY_BUFFER,array_buffer); + ctx->dispatcher().glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,element_array_buffer); + + //restore matrix state + + ctx->dispatcher().glMatrixMode(GL_MODELVIEW); + ctx->dispatcher().glPopMatrix(); + ctx->dispatcher().glMatrixMode(GL_TEXTURE); + ctx->dispatcher().glPopMatrix(); + ctx->dispatcher().glMatrixMode(GL_PROJECTION); + ctx->dispatcher().glPopMatrix(); + + ctx->dispatcher().glPopAttrib(); + ctx->dispatcher().glPopClientAttrib(); +} + +GL_API void GL_APIENTRY glDrawTexsOES (GLshort x, GLshort y, GLshort z, GLshort width, GLshort height) { + glDrawTexOES<GLshort,GL_SHORT>(x,y,z,width,height); +} + +GL_API void GL_APIENTRY glDrawTexiOES (GLint x, GLint y, GLint z, GLint width, GLint height) { + glDrawTexOES<GLint,GL_INT>(x,y,z,width,height); +} + +GL_API void GL_APIENTRY glDrawTexfOES (GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height) { + glDrawTexOES<GLfloat,GL_FLOAT>(x,y,z,width,height); +} + +GL_API void GL_APIENTRY glDrawTexxOES (GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height) { + glDrawTexOES<GLfloat,GL_FLOAT>(X2F(x),X2F(y),X2F(z),X2F(width),X2F(height)); +} + +GL_API void GL_APIENTRY glDrawTexsvOES (const GLshort * coords) { + glDrawTexOES<GLshort,GL_SHORT>(coords[0],coords[1],coords[2],coords[3],coords[4]); +} + +GL_API void GL_APIENTRY glDrawTexivOES (const GLint * coords) { + glDrawTexOES<GLint,GL_INT>(coords[0],coords[1],coords[2],coords[3],coords[4]); +} + +GL_API void GL_APIENTRY glDrawTexfvOES (const GLfloat * coords) { + glDrawTexOES<GLfloat,GL_FLOAT>(coords[0],coords[1],coords[2],coords[3],coords[4]); +} + +GL_API void GL_APIENTRY glDrawTexxvOES (const GLfixed * coords) { + glDrawTexOES<GLfloat,GL_FLOAT>(X2F(coords[0]),X2F(coords[1]),X2F(coords[2]),X2F(coords[3]),X2F(coords[4])); +} diff --git a/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmUtils.cpp b/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmUtils.cpp new file mode 100644 index 0000000..891b4e3 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmUtils.cpp @@ -0,0 +1,101 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "GLEScmUtils.h" + + +size_t glParamSize(GLenum param) +{ + size_t s = 0; + + switch(param) + { + case GL_MAX_TEXTURE_SIZE: + //case GL_TEXTURE_GEN_MODE_OES: + case GL_TEXTURE_ENV_MODE: + case GL_FOG_MODE: + case GL_FOG_DENSITY: + case GL_FOG_START: + case GL_FOG_END: + case GL_SPOT_EXPONENT: + case GL_CONSTANT_ATTENUATION: + case GL_LINEAR_ATTENUATION: + case GL_QUADRATIC_ATTENUATION: + case GL_SHININESS: + case GL_LIGHT_MODEL_TWO_SIDE: + case GL_POINT_SIZE: + case GL_POINT_SIZE_MIN: + case GL_POINT_SIZE_MAX: + case GL_POINT_FADE_THRESHOLD_SIZE: + case GL_CULL_FACE_MODE: + case GL_FRONT_FACE: + case GL_SHADE_MODEL: + case GL_DEPTH_WRITEMASK: + case GL_DEPTH_CLEAR_VALUE: + case GL_STENCIL_FAIL: + case GL_STENCIL_PASS_DEPTH_FAIL: + case GL_STENCIL_PASS_DEPTH_PASS: + case GL_STENCIL_REF: + case GL_STENCIL_WRITEMASK: + case GL_MATRIX_MODE: + case GL_MODELVIEW_STACK_DEPTH: + case GL_PROJECTION_STACK_DEPTH: + case GL_TEXTURE_STACK_DEPTH: + case GL_ALPHA_TEST_FUNC: + case GL_ALPHA_TEST_REF: + case GL_BLEND_DST: + case GL_BLEND_SRC: + case GL_LOGIC_OP_MODE: + case GL_SCISSOR_TEST: + case GL_MAX_TEXTURE_UNITS: + s = 1; + break; + case GL_ALIASED_LINE_WIDTH_RANGE: + case GL_ALIASED_POINT_SIZE_RANGE: + case GL_DEPTH_RANGE: + case GL_MAX_VIEWPORT_DIMS: + case GL_SMOOTH_POINT_SIZE_RANGE: + case GL_SMOOTH_LINE_WIDTH_RANGE: + s= 2; + break; + case GL_SPOT_DIRECTION: + case GL_POINT_DISTANCE_ATTENUATION: + case GL_CURRENT_NORMAL: + s = 3; + break; + case GL_CURRENT_TEXTURE_COORDS: + case GL_CURRENT_COLOR: + case GL_FOG_COLOR: + case GL_AMBIENT: + case GL_DIFFUSE: + case GL_SPECULAR: + case GL_EMISSION: + case GL_POSITION: + case GL_LIGHT_MODEL_AMBIENT: + case GL_TEXTURE_ENV_COLOR: + case GL_SCISSOR_BOX: + case GL_VIEWPORT: + //case GL_TEXTURE_CROP_RECT_OES: + s = 4; + break; + case GL_MODELVIEW_MATRIX: + case GL_PROJECTION_MATRIX: + case GL_TEXTURE_MATRIX: + s = 16; + default: + s = 1; // assume 1 + } + return s; +} diff --git a/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmUtils.h b/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmUtils.h new file mode 100644 index 0000000..38ad6bc --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmUtils.h @@ -0,0 +1,22 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef GLES_UTILS_H +#define GLES_UTILS_H +#include <GLES/gl.h> +#include <stdlib.h> + +size_t glParamSize(GLenum param); +#endif diff --git a/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmValidate.cpp b/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmValidate.cpp new file mode 100644 index 0000000..1970232 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmValidate.cpp @@ -0,0 +1,305 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "GLEScmValidate.h" +#include <GLcommon/GLutils.h> +#include <GLES/gl.h> +#include <GLES/glext.h> +#include <GLcommon/GLEScontext.h> +#include "GLEScmValidate.h" + + +bool GLEScmValidate::lightEnum(GLenum e,unsigned int maxLights) { + return e >=GL_LIGHT0 && e <= (GL_LIGHT0+maxLights); +} + +bool GLEScmValidate::clipPlaneEnum(GLenum e,unsigned int maxClipPlanes) { + return e >=GL_CLIP_PLANE0 && e <= (GL_CLIP_PLANE0+maxClipPlanes); +} + +bool GLEScmValidate::alphaFunc(GLenum f) { + switch(f) { + case GL_NEVER: + case GL_LESS: + case GL_EQUAL: + case GL_LEQUAL: + case GL_GREATER: + case GL_NOTEQUAL: + case GL_GEQUAL: + case GL_ALWAYS: + return true; + } + return false; +} + +bool GLEScmValidate::blendSrc(GLenum s) { + switch(s) { + case GL_ZERO: + case GL_ONE: + 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: + return true; + } + return false; +} + +bool GLEScmValidate::vertexPointerParams(GLint size,GLsizei stride) { + return ((size >=2) && (size <= 4)) && (stride >=0) ; +} + +bool GLEScmValidate::colorPointerParams(GLint size,GLsizei stride) { + return ((size >=3) && (size <= 4)) && (stride >=0) ; +} + +bool GLEScmValidate::texCoordPointerParams(GLint size,GLsizei stride) { + return ((size >=2) && (size <= 4)) && (stride >=0) ; +} + +bool GLEScmValidate::supportedArrays(GLenum arr) { + switch(arr) { + case GL_COLOR_ARRAY: + case GL_NORMAL_ARRAY: + case GL_POINT_SIZE_ARRAY_OES: + case GL_TEXTURE_COORD_ARRAY: + case GL_VERTEX_ARRAY: + return true; + } + return false; +} + +bool GLEScmValidate::hintTargetMode(GLenum target,GLenum mode) { + switch(target) { + case GL_FOG_HINT: + case GL_GENERATE_MIPMAP_HINT: + case GL_LINE_SMOOTH_HINT: + case GL_PERSPECTIVE_CORRECTION_HINT: + case GL_POINT_SMOOTH_HINT: + break; + default: return false; + } + switch(mode) { + case GL_FASTEST: + case GL_NICEST: + case GL_DONT_CARE: + break; + default: return false; + } + return true; +} + +bool GLEScmValidate::texParams(GLenum target,GLenum pname) { + switch(pname) { + case GL_TEXTURE_MIN_FILTER: + case GL_TEXTURE_MAG_FILTER: + case GL_TEXTURE_WRAP_S: + case GL_TEXTURE_WRAP_T: + case GL_TEXTURE_CROP_RECT_OES: + case GL_GENERATE_MIPMAP: + break; + default: + return false; + } + return (target == GL_TEXTURE_2D)||(target == GL_TEXTURE_CUBE_MAP_OES); +} + +bool GLEScmValidate::texEnv(GLenum target,GLenum pname) { + switch(pname) { + case GL_TEXTURE_ENV_MODE: + case GL_TEXTURE_ENV_COLOR: + case GL_COMBINE_RGB: + case GL_COMBINE_ALPHA: + case GL_SRC0_RGB: + case GL_SRC1_RGB: + case GL_SRC2_RGB: + case GL_SRC0_ALPHA: + case GL_SRC1_ALPHA: + case GL_SRC2_ALPHA: + case GL_OPERAND0_RGB: + case GL_OPERAND1_RGB: + case GL_OPERAND2_RGB: + case GL_OPERAND0_ALPHA: + case GL_OPERAND1_ALPHA: + case GL_OPERAND2_ALPHA: + case GL_RGB_SCALE: + case GL_ALPHA_SCALE: + case GL_COORD_REPLACE_OES: + break; + default: + return false; + } + return (target == GL_TEXTURE_ENV || target == GL_POINT_SPRITE_OES); +} + +bool GLEScmValidate::capability(GLenum cap,int maxLights,int maxClipPlanes) { + switch(cap) { + case GL_ALPHA_TEST: + case GL_BLEND: + case GL_COLOR_ARRAY: + case GL_COLOR_LOGIC_OP: + case GL_COLOR_MATERIAL: + case GL_CULL_FACE: + case GL_DEPTH_TEST: + case GL_DITHER: + case GL_FOG: + case GL_LIGHTING: + case GL_LINE_SMOOTH: + case GL_MULTISAMPLE: + case GL_NORMAL_ARRAY: + case GL_NORMALIZE: + case GL_POINT_SIZE_ARRAY_OES: + case GL_POINT_SMOOTH: + case GL_POINT_SPRITE_OES: + case GL_POLYGON_OFFSET_FILL: + case GL_RESCALE_NORMAL: + case GL_SAMPLE_ALPHA_TO_COVERAGE: + case GL_SAMPLE_ALPHA_TO_ONE: + case GL_SAMPLE_COVERAGE: + case GL_SCISSOR_TEST: + case GL_STENCIL_TEST: + case GL_TEXTURE_2D: + case GL_TEXTURE_COORD_ARRAY: + case GL_VERTEX_ARRAY: + return true; + } + return GLEScmValidate::lightEnum(cap,maxLights) || GLEScmValidate::clipPlaneEnum(cap,maxClipPlanes); +} + + +bool GLEScmValidate::texCompImgFrmt(GLenum format) { + switch(format) { + case GL_PALETTE4_RGB8_OES: + case GL_PALETTE4_RGBA8_OES: + case GL_PALETTE4_R5_G6_B5_OES: + case GL_PALETTE4_RGBA4_OES: + case GL_PALETTE4_RGB5_A1_OES: + case GL_PALETTE8_RGB8_OES: + case GL_PALETTE8_RGBA8_OES: + case GL_PALETTE8_R5_G6_B5_OES: + case GL_PALETTE8_RGBA4_OES: + case GL_PALETTE8_RGB5_A1_OES: + return true; + } + return false; +} + +bool GLEScmValidate::blendDst(GLenum d) { + switch(d) { + case GL_ZERO: + case GL_ONE: + case GL_SRC_COLOR: + case GL_ONE_MINUS_SRC_COLOR: + case GL_SRC_ALPHA: + case GL_ONE_MINUS_SRC_ALPHA: + case GL_DST_ALPHA: + case GL_ONE_MINUS_DST_ALPHA: + return true; + } + return false; +} + +bool GLEScmValidate::renderbufferInternalFrmt(GLEScontext* ctx, GLenum internalformat) +{ + switch (internalformat) { + case GL_DEPTH_COMPONENT16_OES: + case GL_RGBA4_OES: + case GL_RGB5_A1_OES: + case GL_RGB565_OES: + case GL_STENCIL_INDEX1_OES: + case GL_STENCIL_INDEX4_OES: + case GL_STENCIL_INDEX8_OES: + case GL_RGB8_OES: + case GL_RGBA8_OES: + case GL_DEPTH_COMPONENT24_OES: + case GL_DEPTH_COMPONENT32_OES: + return true; + } + if (ctx->getCaps()->GL_EXT_PACKED_DEPTH_STENCIL && internalformat==GL_DEPTH24_STENCIL8_OES) + return true; + + return false; +} + +bool GLEScmValidate::stencilOp(GLenum param) { + switch (param) { + case GL_KEEP: + case GL_ZERO: + case GL_REPLACE: + case GL_INCR: + case GL_DECR: + case GL_INVERT: + case GL_INCR_WRAP_OES: + case GL_DECR_WRAP_OES: + return true; + } + return false; +} + +bool GLEScmValidate::texGen(GLenum coord, GLenum pname) { + return (coord == GL_TEXTURE_GEN_STR_OES && pname == GL_TEXTURE_GEN_MODE_OES); +} + +bool GLEScmValidate::colorPointerType(GLenum type){ + switch(type){ + case GL_UNSIGNED_BYTE: + case GL_FIXED: + case GL_FLOAT: + return true; + } + return false; +} + +bool GLEScmValidate::normalPointerType(GLenum type){ + + switch(type){ + case GL_BYTE: + case GL_SHORT: + case GL_FLOAT: + case GL_FIXED: + return true; + } + return false; +} + +bool GLEScmValidate::pointPointerType(GLenum type){ + return type == GL_FIXED || type == GL_FLOAT; +} + +bool GLEScmValidate::texCoordPointerType(GLenum type){ + switch(type){ + case GL_BYTE: + case GL_SHORT: + case GL_FLOAT: + case GL_FIXED: + return true; + } + return false; +} + +bool GLEScmValidate::vertexPointerType(GLenum type){ + switch(type){ + case GL_BYTE: + case GL_SHORT: + case GL_FLOAT: + case GL_FIXED: + return true; + } + return false; +} + diff --git a/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmValidate.h b/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmValidate.h new file mode 100644 index 0000000..9bc3393 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmValidate.h @@ -0,0 +1,50 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef GLES_CM_VALIDATE_H +#define GLES_CM_VALIDATE_H + +#include <GLES/gl.h> +#include <GLcommon/GLESvalidate.h> +struct GLEScmValidate : public GLESvalidate +{ +static bool blendSrc(GLenum s); +static bool blendDst(GLenum d); +static bool lightEnum(GLenum e,unsigned int maxLIghts); +static bool clipPlaneEnum(GLenum e,unsigned int maxClipPlanes); +static bool alphaFunc(GLenum f); +static bool vertexPointerParams(GLint size,GLsizei stride); +static bool colorPointerParams(GLint size,GLsizei stride); +static bool supportedArrays(GLenum arr); +static bool hintTargetMode(GLenum target,GLenum mode); +static bool capability(GLenum cap,int maxLights,int maxClipPlanes); +static bool texParams(GLenum target,GLenum pname); +static bool texCoordPointerParams(GLint size,GLsizei stride); + +static bool texEnv(GLenum target,GLenum pname); +static bool texCompImgFrmt(GLenum format); + +static bool renderbufferInternalFrmt(GLEScontext * ctx, GLenum internalformat); +static bool stencilOp(GLenum param); +static bool texGen(GLenum coord,GLenum pname); + +static bool colorPointerType(GLenum type); +static bool normalPointerType(GLenum type); +static bool pointPointerType(GLenum type); +static bool texCoordPointerType(GLenum type); +static bool vertexPointerType(GLenum type); +}; + +#endif diff --git a/emulator/opengl/host/libs/Translator/GLES_V2/Android.mk b/emulator/opengl/host/libs/Translator/GLES_V2/Android.mk new file mode 100644 index 0000000..f4845f7 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLES_V2/Android.mk @@ -0,0 +1,27 @@ +LOCAL_PATH := $(call my-dir) + +host_common_SRC_FILES := \ + GLESv2Imp.cpp \ + GLESv2Context.cpp \ + GLESv2Validate.cpp \ + ShaderParser.cpp \ + ProgramData.cpp + + +### GLES_V2 host implementation (On top of OpenGL) ######################## +$(call emugl-begin-host-shared-library,libGLES_V2_translator) +$(call emugl-import, libGLcommon) + +LOCAL_SRC_FILES := $(host_common_SRC_FILES) + +$(call emugl-end-module) + + +### GLES_V2 host implementation, 64-bit ############################## +$(call emugl-begin-host-shared-library,lib64GLES_V2_translator) +$(call emugl-import, lib64GLcommon) + +LOCAL_LDLIBS += -m64 +LOCAL_SRC_FILES := $(host_common_SRC_FILES) + +$(call emugl-end-module) diff --git a/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.cpp b/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.cpp new file mode 100644 index 0000000..73acb61 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.cpp @@ -0,0 +1,164 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "GLESv2Context.h" + + + +void GLESv2Context::init() { + android::Mutex::Autolock mutex(s_lock); + if(!m_initialized) { + s_glDispatch.dispatchFuncs(GLES_2_0); + GLEScontext::init(); + for(int i=0; i < s_glSupport.maxVertexAttribs;i++){ + m_map[i] = new GLESpointer(); + } + setAttribute0value(0.0, 0.0, 0.0, 1.0); + + const char* baseRenderer = (const char*)dispatcher().glGetString(GL_RENDERER); + size_t baseRendererLen = strlen(baseRenderer); + s_glRenderer.clear(); + s_glRenderer.reserve(16 + baseRendererLen); + s_glRenderer.append("OpenGL ES 2.0 (", 15); + s_glRenderer.append(baseRenderer, baseRendererLen); + s_glRenderer.append(")", 1); + } + m_initialized = true; +} + +GLESv2Context::GLESv2Context():GLEScontext(), m_att0Array(NULL), m_att0ArrayLength(0), m_att0NeedsDisable(false){}; + +GLESv2Context::~GLESv2Context() +{ + delete[] m_att0Array; +} + +void GLESv2Context::setAttribute0value(float x, float y, float z, float w) +{ + m_attribute0value[0] = x; + m_attribute0value[1] = y; + m_attribute0value[2] = z; + m_attribute0value[3] = w; +} + +void GLESv2Context::validateAtt0PreDraw(unsigned int count) +{ + m_att0NeedsDisable = false; + + if(count == 0) + return; + + int enabled = 0; + s_glDispatch.glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &enabled); + if(enabled) + return; + + if(count > m_att0ArrayLength) + { + delete [] m_att0Array; + m_att0Array = new GLfloat[4*count]; + m_att0ArrayLength = count; + } + + for(unsigned int i=0; i<count; i++) + memcpy(m_att0Array+i*4, m_attribute0value, 4*sizeof(GLfloat)); + + s_glDispatch.glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, m_att0Array); + s_glDispatch.glEnableVertexAttribArray(0); + + m_att0NeedsDisable = true; +} + +void GLESv2Context::validateAtt0PostDraw(void) +{ + if(m_att0NeedsDisable) + s_glDispatch.glDisableVertexAttribArray(0); + + m_att0NeedsDisable = false; +} + +void GLESv2Context::setupArraysPointers(GLESConversionArrays& cArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct) { + ArraysMap::iterator it; + + //going over all clients arrays Pointers + for ( it=m_map.begin() ; it != m_map.end(); it++ ) { + GLenum array_id = (*it).first; + GLESpointer* p = (*it).second; + if(!isArrEnabled(array_id)) continue; + + unsigned int size = p->getSize(); + + if(needConvert(cArrs,first,count,type,indices,direct,p,array_id)){ + //conversion has occured + ArrayData currentArr = cArrs.getCurrentArray(); + setupArr(currentArr.data,array_id,currentArr.type,size,currentArr.stride, p->getNormalized()); + ++cArrs; + } else { + setupArr(p->getData(),array_id,p->getType(), + size,p->getStride(), p->getNormalized()); + } + } +} + +//setting client side arr +void GLESv2Context::setupArr(const GLvoid* arr,GLenum arrayType,GLenum dataType,GLint size,GLsizei stride,GLboolean normalized, int index){ + if(arr == NULL) return; + s_glDispatch.glVertexAttribPointer(arrayType,size,dataType,normalized,stride,arr); +} + +bool GLESv2Context::needConvert(GLESConversionArrays& cArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id) { + + bool usingVBO = p->isVBO(); + GLenum arrType = p->getType(); + /* + conversion is not necessary in the following cases: + (*) array type is not fixed + */ + if(arrType != GL_FIXED) return false; + + if(!usingVBO) { + if (direct) { + convertDirect(cArrs,first,count,array_id,p); + } else { + convertIndirect(cArrs,count,type,indices,array_id,p); + } + } else { + if (direct) { + convertDirectVBO(cArrs,first,count,array_id,p) ; + } else { + convertIndirectVBO(cArrs,count,type,indices,array_id,p); + } + } + return true; +} + +void GLESv2Context::initExtensionString() { + *s_glExtensions = "GL_OES_EGL_image GL_OES_depth24 GL_OES_depth32 GL_OES_element_index_uint " + "GL_OES_texture_float GL_OES_texture_float_linear " + "GL_OES_compressed_paletted_texture GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth_texture "; + if (s_glSupport.GL_ARB_HALF_FLOAT_PIXEL || s_glSupport.GL_NV_HALF_FLOAT) + *s_glExtensions+="GL_OES_texture_half_float GL_OES_texture_half_float_linear "; + if (s_glSupport.GL_EXT_PACKED_DEPTH_STENCIL) + *s_glExtensions+="GL_OES_packed_depth_stencil "; + if (s_glSupport.GL_ARB_HALF_FLOAT_VERTEX) + *s_glExtensions+="GL_OES_vertex_half_float "; + if (s_glSupport.GL_OES_STANDARD_DERIVATIVES) + *s_glExtensions+="GL_OES_standard_derivatives "; +} + +int GLESv2Context::getMaxTexUnits() { + return getCaps()->maxTexImageUnits; +} diff --git a/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.h b/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.h new file mode 100644 index 0000000..75af864 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Context.h @@ -0,0 +1,56 @@ +/* +* Copyright 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef GLES_V2_CONTEXT_H +#define GLES_V2_CONTEXT_H + +#include <GLcommon/GLDispatch.h> +#include <GLcommon/GLEScontext.h> +#include <GLcommon/objectNameManager.h> +#include <utils/threads.h> + + + +class GLESv2Context : public GLEScontext{ +public: + void init(); + GLESv2Context(); + virtual ~GLESv2Context(); + void setupArraysPointers(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct); + int getMaxTexUnits(); + + // This whole att0 thing is about a incompatibility between GLES and OpenGL. + // GLES allows a vertex shader attribute to be in location 0 and have a + // current value, while OpenGL is not very clear about this, which results + // in each implementation doing something different. + void setAttribute0value(float x, float y, float z, float w); + void validateAtt0PreDraw(unsigned int count); + void validateAtt0PostDraw(void); + const float* getAtt0(void) {return m_attribute0value;} + +protected: + bool needConvert(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id); +private: + void setupArr(const GLvoid* arr,GLenum arrayType,GLenum dataType,GLint size,GLsizei stride,GLboolean normalized, int pointsIndex = -1); + void initExtensionString(); + + float m_attribute0value[4]; + GLfloat* m_att0Array; + unsigned int m_att0ArrayLength; + bool m_att0NeedsDisable; +}; + +#endif diff --git a/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp b/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp new file mode 100644 index 0000000..412584d --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp @@ -0,0 +1,2089 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License") +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifdef _WIN32 +#undef GL_APICALL +#define GL_API __declspec(dllexport) +#define GL_APICALL __declspec(dllexport) +#endif + +#define GL_GLEXT_PROTOTYPES +#include <stdio.h> +#include <GLES2/gl2.h> +#include <GLES2/gl2ext.h> +#include <GLcommon/TranslatorIfaces.h> +#include <GLcommon/gldefs.h> +#include "GLESv2Context.h" +#include "GLESv2Validate.h" +#include "ShaderParser.h" +#include "ProgramData.h" +#include <GLcommon/TextureUtils.h> +#include <GLcommon/FramebufferData.h> + +extern "C" { + +//decleration +static void initContext(GLEScontext* ctx,ShareGroupPtr grp); +static void deleteGLESContext(GLEScontext* ctx); +static void setShareGroup(GLEScontext* ctx,ShareGroupPtr grp); +static GLEScontext* createGLESContext(); +static __translatorMustCastToProperFunctionPointerType getProcAddress(const char* procName); + +} + +/************************************** GLES EXTENSIONS *********************************************************/ +//extentions descriptor +typedef std::map<std::string, __translatorMustCastToProperFunctionPointerType> ProcTableMap; +ProcTableMap *s_glesExtensions = NULL; +/****************************************************************************************************************/ + +static EGLiface* s_eglIface = NULL; +static GLESiface s_glesIface = { + createGLESContext:createGLESContext, + initContext :initContext, + deleteGLESContext:deleteGLESContext, + flush :(FUNCPTR)glFlush, + finish :(FUNCPTR)glFinish, + setShareGroup :setShareGroup, + getProcAddress :getProcAddress +}; + +#include <GLcommon/GLESmacros.h> + +extern "C" { + +static void initContext(GLEScontext* ctx,ShareGroupPtr grp) { + if (!ctx->isInitialized()) { + ctx->setShareGroup(grp); + ctx->init(); + glBindTexture(GL_TEXTURE_2D,0); + glBindTexture(GL_TEXTURE_CUBE_MAP,0); + } +} +static GLEScontext* createGLESContext() { + return new GLESv2Context(); +} + +static void deleteGLESContext(GLEScontext* ctx) { + delete ctx; +} + +static void setShareGroup(GLEScontext* ctx,ShareGroupPtr grp) { + if(ctx) { + ctx->setShareGroup(grp); + } +} + +static __translatorMustCastToProperFunctionPointerType getProcAddress(const char* procName) { + GET_CTX_RET(NULL) + ctx->getGlobalLock(); + static bool proc_table_initialized = false; + if (!proc_table_initialized) { + proc_table_initialized = true; + if (!s_glesExtensions) + s_glesExtensions = new ProcTableMap(); + else + s_glesExtensions->clear(); + (*s_glesExtensions)["glEGLImageTargetTexture2DOES"] = (__translatorMustCastToProperFunctionPointerType)glEGLImageTargetTexture2DOES; + (*s_glesExtensions)["glEGLImageTargetRenderbufferStorageOES"]=(__translatorMustCastToProperFunctionPointerType)glEGLImageTargetRenderbufferStorageOES; + } + __translatorMustCastToProperFunctionPointerType ret=NULL; + ProcTableMap::iterator val = s_glesExtensions->find(procName); + if (val!=s_glesExtensions->end()) + ret = val->second; + ctx->releaseGlobalLock(); + + return ret; +} + +GL_APICALL GLESiface* __translator_getIfaces(EGLiface* eglIface){ + s_eglIface = eglIface; + return & s_glesIface; +} + +} + +static ObjectLocalName TextureLocalName(GLenum target,unsigned int tex) { + GET_CTX_RET(0); + return (tex!=0? tex : ctx->getDefaultTextureName(target)); +} + +static TextureData* getTextureData(ObjectLocalName tex) { + GET_CTX_RET(NULL); + TextureData *texData = NULL; + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(TEXTURE,tex); + if(!objData.Ptr()){ + texData = new TextureData(); + ctx->shareGroup()->setObjectData(TEXTURE, tex, ObjectDataPtr(texData)); + } else { + texData = (TextureData*)objData.Ptr(); + } + return texData; +} + +static TextureData* getTextureTargetData(GLenum target){ + GET_CTX_RET(NULL); + unsigned int tex = ctx->getBindedTexture(target); + return getTextureData(TextureLocalName(target,tex)); +} + +GL_APICALL void GL_APIENTRY glActiveTexture(GLenum texture){ + GET_CTX_V2(); + SET_ERROR_IF (!GLESv2Validate::textureEnum(texture,ctx->getMaxTexUnits()),GL_INVALID_ENUM); + ctx->setActiveTexture(texture); + ctx->dispatcher().glActiveTexture(texture); +} + +GL_APICALL void GL_APIENTRY glAttachShader(GLuint program, GLuint shader){ + GET_CTX(); + if(ctx->shareGroup().Ptr()) { + const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program); + SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE); + const GLuint globalShaderName = ctx->shareGroup()->getGlobalName(SHADER,shader); + SET_ERROR_IF(globalShaderName==0, GL_INVALID_VALUE); + + ObjectDataPtr programData = ctx->shareGroup()->getObjectData(SHADER,program); + ObjectDataPtr shaderData = ctx->shareGroup()->getObjectData(SHADER,shader); + SET_ERROR_IF(!shaderData.Ptr() || !programData.Ptr() ,GL_INVALID_OPERATION); + SET_ERROR_IF(!(shaderData.Ptr()->getDataType() ==SHADER_DATA) || + !(programData.Ptr()->getDataType()==PROGRAM_DATA) ,GL_INVALID_OPERATION); + + GLenum shaderType = ((ShaderParser*)shaderData.Ptr())->getType(); + ProgramData* pData = (ProgramData*)programData.Ptr(); + SET_ERROR_IF((pData->getAttachedShader(shaderType)!=0), GL_INVALID_OPERATION); + pData->attachShader(shader,shaderType); + ctx->dispatcher().glAttachShader(globalProgramName,globalShaderName); + } +} + +GL_APICALL void GL_APIENTRY glBindAttribLocation(GLuint program, GLuint index, const GLchar* name){ + GET_CTX(); + SET_ERROR_IF(!GLESv2Validate::attribName(name),GL_INVALID_OPERATION); + SET_ERROR_IF(!GLESv2Validate::attribIndex(index),GL_INVALID_VALUE); + if(ctx->shareGroup().Ptr()) { + const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program); + SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE); + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program); + SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION); + + ctx->dispatcher().glBindAttribLocation(globalProgramName,index,name); + } +} + +GL_APICALL void GL_APIENTRY glBindBuffer(GLenum target, GLuint buffer){ + GET_CTX(); + SET_ERROR_IF(!GLESv2Validate::bufferTarget(target),GL_INVALID_ENUM); + //if buffer wasn't generated before,generate one + if(buffer && ctx->shareGroup().Ptr() && !ctx->shareGroup()->isObject(VERTEXBUFFER,buffer)){ + ctx->shareGroup()->genName(VERTEXBUFFER,buffer); + ctx->shareGroup()->setObjectData(VERTEXBUFFER,buffer,ObjectDataPtr(new GLESbuffer())); + } + ctx->bindBuffer(target,buffer); + if (buffer) { + GLESbuffer* vbo = (GLESbuffer*)ctx->shareGroup()->getObjectData(VERTEXBUFFER,buffer).Ptr(); + vbo->setBinded(); + } +} + +GL_APICALL void GL_APIENTRY glBindFramebuffer(GLenum target, GLuint framebuffer){ + GET_CTX(); + SET_ERROR_IF(!GLESv2Validate::framebufferTarget(target),GL_INVALID_ENUM); + + GLuint globalFrameBufferName = framebuffer; + if(framebuffer && ctx->shareGroup().Ptr()){ + globalFrameBufferName = ctx->shareGroup()->getGlobalName(FRAMEBUFFER,framebuffer); + //if framebuffer wasn't generated before,generate one + if(!globalFrameBufferName){ + ctx->shareGroup()->genName(FRAMEBUFFER,framebuffer); + ctx->shareGroup()->setObjectData(FRAMEBUFFER, framebuffer, + ObjectDataPtr(new FramebufferData(framebuffer))); + globalFrameBufferName = ctx->shareGroup()->getGlobalName(FRAMEBUFFER,framebuffer); + } + } + ctx->dispatcher().glBindFramebufferEXT(target,globalFrameBufferName); + + // update framebuffer binding state + ctx->setFramebufferBinding(framebuffer); +} + +GL_APICALL void GL_APIENTRY glBindRenderbuffer(GLenum target, GLuint renderbuffer){ + GET_CTX(); + SET_ERROR_IF(!GLESv2Validate::renderbufferTarget(target),GL_INVALID_ENUM); + + GLuint globalRenderBufferName = renderbuffer; + if(renderbuffer && ctx->shareGroup().Ptr()){ + globalRenderBufferName = ctx->shareGroup()->getGlobalName(RENDERBUFFER,renderbuffer); + //if renderbuffer wasn't generated before,generate one + if(!globalRenderBufferName){ + ctx->shareGroup()->genName(RENDERBUFFER,renderbuffer); + ctx->shareGroup()->setObjectData(RENDERBUFFER, + renderbuffer, + ObjectDataPtr(new RenderbufferData())); + globalRenderBufferName = ctx->shareGroup()->getGlobalName(RENDERBUFFER,renderbuffer); + } + } + ctx->dispatcher().glBindRenderbufferEXT(target,globalRenderBufferName); + + // update renderbuffer binding state + ctx->setRenderbufferBinding(renderbuffer); +} + +GL_APICALL void GL_APIENTRY glBindTexture(GLenum target, GLuint texture){ + GET_CTX(); + SET_ERROR_IF(!GLESv2Validate::textureTarget(target),GL_INVALID_ENUM) + + //for handling default texture (0) + ObjectLocalName localTexName = TextureLocalName(target,texture); + + GLuint globalTextureName = localTexName; + if(ctx->shareGroup().Ptr()){ + globalTextureName = ctx->shareGroup()->getGlobalName(TEXTURE,localTexName); + //if texture wasn't generated before,generate one + if(!globalTextureName){ + ctx->shareGroup()->genName(TEXTURE,localTexName); + globalTextureName = ctx->shareGroup()->getGlobalName(TEXTURE,localTexName); + } + + TextureData* texData = getTextureData(localTexName); + if (texData->target==0) + texData->target = target; + //if texture was already bound to another target + SET_ERROR_IF(ctx->GLTextureTargetToLocal(texData->target) != ctx->GLTextureTargetToLocal(target), GL_INVALID_OPERATION); + texData->wasBound = true; + } + + ctx->setBindedTexture(target,texture); + ctx->dispatcher().glBindTexture(target,globalTextureName); +} + +GL_APICALL void GL_APIENTRY glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha){ + GET_CTX(); + ctx->dispatcher().glBlendColor(red,green,blue,alpha); +} + +GL_APICALL void GL_APIENTRY glBlendEquation( GLenum mode ){ + GET_CTX(); + SET_ERROR_IF(!GLESv2Validate::blendEquationMode(mode),GL_INVALID_ENUM) + ctx->dispatcher().glBlendEquation(mode); +} + +GL_APICALL void GL_APIENTRY glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha){ + GET_CTX(); + SET_ERROR_IF(!(GLESv2Validate::blendEquationMode(modeRGB) && GLESv2Validate::blendEquationMode(modeAlpha)),GL_INVALID_ENUM); + ctx->dispatcher().glBlendEquationSeparate(modeRGB,modeAlpha); +} + +GL_APICALL void GL_APIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor){ + GET_CTX(); + SET_ERROR_IF(!GLESv2Validate::blendSrc(sfactor) || !GLESv2Validate::blendDst(dfactor),GL_INVALID_ENUM) + ctx->dispatcher().glBlendFunc(sfactor,dfactor); +} + +GL_APICALL void GL_APIENTRY glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha){ + GET_CTX(); + SET_ERROR_IF( +!(GLESv2Validate::blendSrc(srcRGB) && GLESv2Validate::blendDst(dstRGB) && GLESv2Validate::blendSrc(srcAlpha) && GLESv2Validate::blendDst(dstAlpha)),GL_INVALID_ENUM); + ctx->dispatcher().glBlendFuncSeparate(srcRGB,dstRGB,srcAlpha,dstAlpha); +} + +GL_APICALL void GL_APIENTRY glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage){ + GET_CTX(); + SET_ERROR_IF(!GLESv2Validate::bufferTarget(target),GL_INVALID_ENUM); + SET_ERROR_IF(!ctx->isBindedBuffer(target),GL_INVALID_OPERATION); + ctx->setBufferData(target,size,data,usage); +} + +GL_APICALL void GL_APIENTRY glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data){ + GET_CTX(); + SET_ERROR_IF(!ctx->isBindedBuffer(target),GL_INVALID_OPERATION); + SET_ERROR_IF(!GLESv2Validate::bufferTarget(target),GL_INVALID_ENUM); + SET_ERROR_IF(!ctx->setBufferSubData(target,offset,size,data),GL_INVALID_VALUE); +} + + +GL_APICALL GLenum GL_APIENTRY glCheckFramebufferStatus(GLenum target){ + GET_CTX_RET(GL_FRAMEBUFFER_COMPLETE); + RET_AND_SET_ERROR_IF(!GLESv2Validate::framebufferTarget(target),GL_INVALID_ENUM,GL_FRAMEBUFFER_COMPLETE); + ctx->drawValidate(); + return ctx->dispatcher().glCheckFramebufferStatusEXT(target); +} + +GL_APICALL void GL_APIENTRY glClear(GLbitfield mask){ + GET_CTX(); + ctx->drawValidate(); + + ctx->dispatcher().glClear(mask); +} +GL_APICALL void GL_APIENTRY glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha){ + GET_CTX(); + ctx->dispatcher().glClearColor(red,green,blue,alpha); +} +GL_APICALL void GL_APIENTRY glClearDepthf(GLclampf depth){ + GET_CTX(); + ctx->dispatcher().glClearDepth(depth); +} +GL_APICALL void GL_APIENTRY glClearStencil(GLint s){ + GET_CTX(); + ctx->dispatcher().glClearStencil(s); +} +GL_APICALL void GL_APIENTRY glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha){ + GET_CTX(); + ctx->dispatcher().glColorMask(red,green,blue,alpha); +} + +GL_APICALL void GL_APIENTRY glCompileShader(GLuint shader){ + GET_CTX(); + if(ctx->shareGroup().Ptr()) { + const GLuint globalShaderName = ctx->shareGroup()->getGlobalName(SHADER,shader); + SET_ERROR_IF(globalShaderName==0, GL_INVALID_VALUE); + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,shader); + SET_ERROR_IF(objData.Ptr()->getDataType()!= SHADER_DATA,GL_INVALID_OPERATION); + ShaderParser* sp = (ShaderParser*)objData.Ptr(); + ctx->dispatcher().glCompileShader(globalShaderName); + + GLsizei infoLogLength=0; + GLchar* infoLog; + ctx->dispatcher().glGetShaderiv(globalShaderName,GL_INFO_LOG_LENGTH,&infoLogLength); + infoLog = new GLchar[infoLogLength+1]; + ctx->dispatcher().glGetShaderInfoLog(globalShaderName,infoLogLength,NULL,infoLog); + sp->setInfoLog(infoLog); + } +} + +GL_APICALL void GL_APIENTRY glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid* data) +{ + GET_CTX(); + SET_ERROR_IF(!GLESv2Validate::textureTargetEx(target),GL_INVALID_ENUM); + + doCompressedTexImage2D(ctx, target, level, internalformat, + width, height, border, + imageSize, data, (void*)glTexImage2D); +} + +GL_APICALL void GL_APIENTRY glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid* data){ + GET_CTX(); + SET_ERROR_IF(!GLESv2Validate::textureTargetEx(target),GL_INVALID_ENUM); + ctx->dispatcher().glCompressedTexSubImage2D(target,level,xoffset,yoffset,width,height,format,imageSize,data); +} + +GL_APICALL void GL_APIENTRY glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border){ + GET_CTX(); + SET_ERROR_IF(!(GLESv2Validate::pixelFrmt(ctx,internalformat) && GLESv2Validate::textureTargetEx(target)),GL_INVALID_ENUM); + SET_ERROR_IF(border != 0,GL_INVALID_VALUE); + ctx->dispatcher().glCopyTexImage2D(target,level,internalformat,x,y,width,height,border); +} + +GL_APICALL void GL_APIENTRY glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height){ + GET_CTX(); + SET_ERROR_IF(!GLESv2Validate::textureTargetEx(target),GL_INVALID_ENUM); + ctx->dispatcher().glCopyTexSubImage2D(target,level,xoffset,yoffset,x,y,width,height); +} + +GL_APICALL GLuint GL_APIENTRY glCreateProgram(void){ + GET_CTX_RET(0); + const GLuint globalProgramName = ctx->dispatcher().glCreateProgram(); + if(ctx->shareGroup().Ptr() && globalProgramName) { + ProgramData* programInfo = new ProgramData(); + const GLuint localProgramName = ctx->shareGroup()->genName(SHADER, 0, true); + ctx->shareGroup()->replaceGlobalName(SHADER,localProgramName,globalProgramName); + ctx->shareGroup()->setObjectData(SHADER,localProgramName,ObjectDataPtr(programInfo)); + return localProgramName; + } + if(globalProgramName){ + ctx->dispatcher().glDeleteProgram(globalProgramName); + } + return 0; +} + +GL_APICALL GLuint GL_APIENTRY glCreateShader(GLenum type){ + GET_CTX_V2_RET(0); + RET_AND_SET_ERROR_IF(!GLESv2Validate::shaderType(type),GL_INVALID_ENUM,0); + const GLuint globalShaderName = ctx->dispatcher().glCreateShader(type); + if(ctx->shareGroup().Ptr() && globalShaderName) { + const GLuint localShaderName = ctx->shareGroup()->genName(SHADER, 0, true); + ShaderParser* sp = new ShaderParser(type); + ctx->shareGroup()->replaceGlobalName(SHADER,localShaderName,globalShaderName); + ctx->shareGroup()->setObjectData(SHADER,localShaderName,ObjectDataPtr(sp)); + return localShaderName; + } + if(globalShaderName){ + ctx->dispatcher().glDeleteShader(globalShaderName); + } + return 0; +} + +GL_APICALL void GL_APIENTRY glCullFace(GLenum mode){ + GET_CTX(); + ctx->dispatcher().glCullFace(mode); +} + +GL_APICALL void GL_APIENTRY glDeleteBuffers(GLsizei n, const GLuint* buffers){ + GET_CTX(); + SET_ERROR_IF(n<0,GL_INVALID_VALUE); + if(ctx->shareGroup().Ptr()) { + for(int i=0; i < n; i++){ + ctx->shareGroup()->deleteName(VERTEXBUFFER,buffers[i]); + } + } +} + +GL_APICALL void GL_APIENTRY glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers){ + GET_CTX(); + SET_ERROR_IF(n<0,GL_INVALID_VALUE); + if(ctx->shareGroup().Ptr()) { + for(int i=0; i < n; i++){ + const GLuint globalFrameBufferName = ctx->shareGroup()->getGlobalName(FRAMEBUFFER,framebuffers[i]); + ctx->shareGroup()->deleteName(FRAMEBUFFER,framebuffers[i]); + ctx->dispatcher().glDeleteFramebuffersEXT(1,&globalFrameBufferName); + } + } +} + +GL_APICALL void GL_APIENTRY glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers){ + GET_CTX(); + SET_ERROR_IF(n<0,GL_INVALID_VALUE); + if(ctx->shareGroup().Ptr()) { + for(int i=0; i < n; i++){ + const GLuint globalRenderBufferName = ctx->shareGroup()->getGlobalName(RENDERBUFFER,renderbuffers[i]); + ctx->shareGroup()->deleteName(RENDERBUFFER,renderbuffers[i]); + ctx->dispatcher().glDeleteRenderbuffersEXT(1,&globalRenderBufferName); + } + } +} + +GL_APICALL void GL_APIENTRY glDeleteTextures(GLsizei n, const GLuint* textures){ + GET_CTX(); + SET_ERROR_IF(n<0,GL_INVALID_VALUE); + if(ctx->shareGroup().Ptr()) { + for(int i=0; i < n; i++){ + if (textures[i]!=0) { + TextureData* tData = getTextureData(textures[i]); + // delete the underlying OpenGL texture but only if this + // texture is not a target of EGLImage. + if (!tData || tData->sourceEGLImage == 0) { + const GLuint globalTextureName = ctx->shareGroup()->getGlobalName(TEXTURE,textures[i]); + ctx->dispatcher().glDeleteTextures(1,&globalTextureName); + } + ctx->shareGroup()->deleteName(TEXTURE,textures[i]); + + if (ctx->getBindedTexture(GL_TEXTURE_2D) == textures[i]) + ctx->setBindedTexture(GL_TEXTURE_2D,0); + if (ctx->getBindedTexture(GL_TEXTURE_CUBE_MAP) == textures[i]) + ctx->setBindedTexture(GL_TEXTURE_CUBE_MAP,0); + } + } + } +} + +GL_APICALL void GL_APIENTRY glDeleteProgram(GLuint program){ + GET_CTX(); + if(program && ctx->shareGroup().Ptr()) { + const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program); + SET_ERROR_IF(!globalProgramName, GL_INVALID_VALUE); + ctx->shareGroup()->deleteName(SHADER,program); + ctx->dispatcher().glDeleteProgram(globalProgramName); + } +} + +GL_APICALL void GL_APIENTRY glDeleteShader(GLuint shader){ + GET_CTX(); + if(shader && ctx->shareGroup().Ptr()) { + const GLuint globalShaderName = ctx->shareGroup()->getGlobalName(SHADER,shader); + SET_ERROR_IF(!globalShaderName, GL_INVALID_VALUE); + ctx->shareGroup()->deleteName(SHADER,shader); + ctx->dispatcher().glDeleteShader(globalShaderName); + } + +} + +GL_APICALL void GL_APIENTRY glDepthFunc(GLenum func){ + GET_CTX(); + ctx->dispatcher().glDepthFunc(func); +} +GL_APICALL void GL_APIENTRY glDepthMask(GLboolean flag){ + GET_CTX(); + ctx->dispatcher().glDepthMask(flag); +} +GL_APICALL void GL_APIENTRY glDepthRangef(GLclampf zNear, GLclampf zFar){ + GET_CTX(); + ctx->dispatcher().glDepthRange(zNear,zFar); +} + +GL_APICALL void GL_APIENTRY glDetachShader(GLuint program, GLuint shader){ + GET_CTX(); + if(ctx->shareGroup().Ptr()) { + const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program); + SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE); + const GLuint globalShaderName = ctx->shareGroup()->getGlobalName(SHADER,shader); + SET_ERROR_IF(globalShaderName==0, GL_INVALID_VALUE); + + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program); + SET_ERROR_IF(!objData.Ptr(),GL_INVALID_OPERATION); + SET_ERROR_IF(!(objData.Ptr()->getDataType()==PROGRAM_DATA) ,GL_INVALID_OPERATION); + + ProgramData* programData = (ProgramData*)objData.Ptr(); + SET_ERROR_IF(!programData->isAttached(shader),GL_INVALID_OPERATION); + programData->detachShader(shader); + + ctx->dispatcher().glDetachShader(globalProgramName,globalShaderName); + } +} + +GL_APICALL void GL_APIENTRY glDisable(GLenum cap){ + GET_CTX(); + ctx->dispatcher().glDisable(cap); +} + +GL_APICALL void GL_APIENTRY glDisableVertexAttribArray(GLuint index){ + GET_CTX(); + SET_ERROR_IF((!GLESv2Validate::arrayIndex(ctx,index)),GL_INVALID_VALUE); + ctx->enableArr(index,false); + ctx->dispatcher().glDisableVertexAttribArray(index); +} + +GL_APICALL void GL_APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count){ + GET_CTX_V2(); + SET_ERROR_IF(count < 0,GL_INVALID_VALUE) + SET_ERROR_IF(!GLESv2Validate::drawMode(mode),GL_INVALID_ENUM); + + ctx->drawValidate(); + + GLESConversionArrays tmpArrs; + ctx->setupArraysPointers(tmpArrs,first,count,0,NULL,true); + + ctx->validateAtt0PreDraw(count); + + //Enable texture generation for GL_POINTS and gl_PointSize shader variable + //GLES2 assumes this is enabled by default, we need to set this state for GL + if (mode==GL_POINTS) { + ctx->dispatcher().glEnable(GL_POINT_SPRITE); + ctx->dispatcher().glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); + } + + ctx->dispatcher().glDrawArrays(mode,first,count); + + if (mode==GL_POINTS) { + ctx->dispatcher().glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); + ctx->dispatcher().glDisable(GL_POINT_SPRITE); + } + + ctx->validateAtt0PostDraw(); +} + +GL_APICALL void GL_APIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* elementsIndices){ + GET_CTX_V2(); + SET_ERROR_IF(count < 0,GL_INVALID_VALUE) + SET_ERROR_IF(!(GLESv2Validate::drawMode(mode) && GLESv2Validate::drawType(type)),GL_INVALID_ENUM); + + ctx->drawValidate(); + + const GLvoid* indices = elementsIndices; + if(ctx->isBindedBuffer(GL_ELEMENT_ARRAY_BUFFER)) { // if vbo is binded take the indices from the vbo + const unsigned char* buf = static_cast<unsigned char *>(ctx->getBindedBuffer(GL_ELEMENT_ARRAY_BUFFER)); + indices = buf+reinterpret_cast<uintptr_t>(elementsIndices); + } + + GLESConversionArrays tmpArrs; + ctx->setupArraysPointers(tmpArrs,0,count,type,indices,false); + + int maxIndex = ctx->findMaxIndex(count, type, indices); + ctx->validateAtt0PreDraw(maxIndex); + + //See glDrawArrays + if (mode==GL_POINTS) { + ctx->dispatcher().glEnable(GL_POINT_SPRITE); + ctx->dispatcher().glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); + } + + ctx->dispatcher().glDrawElements(mode,count,type,indices); + + if (mode==GL_POINTS) { + ctx->dispatcher().glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); + ctx->dispatcher().glDisable(GL_POINT_SPRITE); + } + + ctx->validateAtt0PostDraw(); +} + +GL_APICALL void GL_APIENTRY glEnable(GLenum cap){ + GET_CTX(); + ctx->dispatcher().glEnable(cap); +} + +GL_APICALL void GL_APIENTRY glEnableVertexAttribArray(GLuint index){ + GET_CTX(); + SET_ERROR_IF(!(GLESv2Validate::arrayIndex(ctx,index)),GL_INVALID_VALUE); + ctx->enableArr(index,true); + ctx->dispatcher().glEnableVertexAttribArray(index); +} + +GL_APICALL void GL_APIENTRY glFinish(void){ + GET_CTX(); + ctx->dispatcher().glFinish(); +} +GL_APICALL void GL_APIENTRY glFlush(void){ + GET_CTX(); + ctx->dispatcher().glFlush(); +} + + +GL_APICALL void GL_APIENTRY glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer){ + GET_CTX(); + SET_ERROR_IF(!(GLESv2Validate::framebufferTarget(target) && + GLESv2Validate::renderbufferTarget(renderbuffertarget) && + GLESv2Validate::framebufferAttachment(attachment)),GL_INVALID_ENUM); + SET_ERROR_IF(!ctx->shareGroup().Ptr(), GL_INVALID_OPERATION); + + GLuint globalRenderbufferName = 0; + ObjectDataPtr obj; + + // generate the renderbuffer object if not yet exist + if(renderbuffer) { + if (!ctx->shareGroup()->isObject(RENDERBUFFER,renderbuffer)) { + ctx->shareGroup()->genName(RENDERBUFFER,renderbuffer); + obj = ObjectDataPtr(new RenderbufferData()); + ctx->shareGroup()->setObjectData(RENDERBUFFER, + renderbuffer, obj); + } + else { + obj = ctx->shareGroup()->getObjectData(RENDERBUFFER, renderbuffer); + } + + globalRenderbufferName = ctx->shareGroup()->getGlobalName(RENDERBUFFER,renderbuffer); + } + + // Update the the current framebuffer object attachment state + GLuint fbName = ctx->getFramebufferBinding(); + ObjectDataPtr fbObj = ctx->shareGroup()->getObjectData(FRAMEBUFFER,fbName); + if (fbObj.Ptr() != NULL) { + FramebufferData *fbData = (FramebufferData *)fbObj.Ptr(); + fbData->setAttachment(attachment, renderbuffertarget, renderbuffer, obj); + } + + if (renderbuffer && obj.Ptr() != NULL) { + RenderbufferData *rbData = (RenderbufferData *)obj.Ptr(); + if (rbData->sourceEGLImage != 0) { + // + // This renderbuffer object is an eglImage target + // attach the eglimage's texture instead the renderbuffer. + // + ctx->dispatcher().glFramebufferTexture2DEXT(target, + attachment, + GL_TEXTURE_2D, + rbData->eglImageGlobalTexName,0); + return; + } + } + + ctx->dispatcher().glFramebufferRenderbufferEXT(target,attachment,renderbuffertarget,globalRenderbufferName); +} + +GL_APICALL void GL_APIENTRY glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level){ + GET_CTX(); + SET_ERROR_IF(!(GLESv2Validate::framebufferTarget(target) && + GLESv2Validate::textureTargetEx(textarget) && + GLESv2Validate::framebufferAttachment(attachment)),GL_INVALID_ENUM); + SET_ERROR_IF(level != 0, GL_INVALID_VALUE); + SET_ERROR_IF(!ctx->shareGroup().Ptr(), GL_INVALID_OPERATION); + + GLuint globalTextureName = 0; + + if(texture) { + if (!ctx->shareGroup()->isObject(TEXTURE,texture)) { + ctx->shareGroup()->genName(TEXTURE,texture); + } + ObjectLocalName texname = TextureLocalName(textarget,texture); + globalTextureName = ctx->shareGroup()->getGlobalName(TEXTURE,texname); + } + + ctx->dispatcher().glFramebufferTexture2DEXT(target,attachment,textarget,globalTextureName,level); + + // Update the the current framebuffer object attachment state + GLuint fbName = ctx->getFramebufferBinding(); + ObjectDataPtr fbObj = ctx->shareGroup()->getObjectData(FRAMEBUFFER,fbName); + if (fbObj.Ptr() != NULL) { + FramebufferData *fbData = (FramebufferData *)fbObj.Ptr(); + fbData->setAttachment(attachment, textarget, + texture, ObjectDataPtr(NULL)); + } +} + + +GL_APICALL void GL_APIENTRY glFrontFace(GLenum mode){ + GET_CTX(); + ctx->dispatcher().glFrontFace(mode); +} + +GL_APICALL void GL_APIENTRY glGenBuffers(GLsizei n, GLuint* buffers){ + GET_CTX(); + SET_ERROR_IF(n<0,GL_INVALID_VALUE); + if(ctx->shareGroup().Ptr()) { + for(int i=0; i<n ;i++) { + buffers[i] = ctx->shareGroup()->genName(VERTEXBUFFER, 0, true); + //generating vbo object related to this buffer name + ctx->shareGroup()->setObjectData(VERTEXBUFFER,buffers[i],ObjectDataPtr(new GLESbuffer())); + } + } +} + +GL_APICALL void GL_APIENTRY glGenerateMipmap(GLenum target){ + GET_CTX(); + SET_ERROR_IF(!GLESv2Validate::textureTargetEx(target),GL_INVALID_ENUM); + ctx->dispatcher().glGenerateMipmapEXT(target); +} + +GL_APICALL void GL_APIENTRY glGenFramebuffers(GLsizei n, GLuint* framebuffers){ + GET_CTX(); + SET_ERROR_IF(n<0,GL_INVALID_VALUE); + if(ctx->shareGroup().Ptr()) { + for(int i=0; i<n ;i++) { + framebuffers[i] = ctx->shareGroup()->genName(FRAMEBUFFER, 0 ,true); + ctx->shareGroup()->setObjectData(FRAMEBUFFER, framebuffers[i], + ObjectDataPtr(new FramebufferData(framebuffers[i]))); + } + } +} + +GL_APICALL void GL_APIENTRY glGenRenderbuffers(GLsizei n, GLuint* renderbuffers){ + GET_CTX(); + SET_ERROR_IF(n<0,GL_INVALID_VALUE); + if(ctx->shareGroup().Ptr()) { + for(int i=0; i<n ;i++) { + renderbuffers[i] = ctx->shareGroup()->genName(RENDERBUFFER, 0, true); + ctx->shareGroup()->setObjectData(RENDERBUFFER, + renderbuffers[i], + ObjectDataPtr(new RenderbufferData())); + } + } +} + +GL_APICALL void GL_APIENTRY glGenTextures(GLsizei n, GLuint* textures){ + GET_CTX(); + SET_ERROR_IF(n<0,GL_INVALID_VALUE); + if(ctx->shareGroup().Ptr()) { + for(int i=0; i<n ;i++) { + textures[i] = ctx->shareGroup()->genName(TEXTURE, 0, true); + } + } +} + +GL_APICALL void GL_APIENTRY glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name){ + GET_CTX(); + if(ctx->shareGroup().Ptr()) { + const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program); + SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE); + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program); + SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION); + ctx->dispatcher().glGetActiveAttrib(globalProgramName,index,bufsize,length,size,type,name); + } +} + +GL_APICALL void GL_APIENTRY glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name){ + GET_CTX(); + if(ctx->shareGroup().Ptr()) { + const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program); + SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE); + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program); + SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION); + ctx->dispatcher().glGetActiveUniform(globalProgramName,index,bufsize,length,size,type,name); + } +} + +GL_APICALL void GL_APIENTRY glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders){ + GET_CTX(); + if(ctx->shareGroup().Ptr()) { + const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program); + SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE); + ctx->dispatcher().glGetAttachedShaders(globalProgramName,maxcount,count,shaders); + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program); + SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION); + GLint numShaders=0; + ctx->dispatcher().glGetProgramiv(globalProgramName,GL_ATTACHED_SHADERS,&numShaders); + for(int i=0 ; i < maxcount && i<numShaders ;i++){ + shaders[i] = ctx->shareGroup()->getLocalName(SHADER,shaders[i]); + } + } +} + +GL_APICALL int GL_APIENTRY glGetAttribLocation(GLuint program, const GLchar* name){ + GET_CTX_RET(-1); + if(ctx->shareGroup().Ptr()) { + const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program); + RET_AND_SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE,-1); + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program); + RET_AND_SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION,-1); + ProgramData* pData = (ProgramData *)objData.Ptr(); + RET_AND_SET_ERROR_IF(pData->getLinkStatus() != GL_TRUE,GL_INVALID_OPERATION,-1); + return ctx->dispatcher().glGetAttribLocation(globalProgramName,name); + } + return -1; +} + +GL_APICALL void GL_APIENTRY glGetBooleanv(GLenum pname, GLboolean* params){ + GET_CTX(); + + if (ctx->glGetBooleanv(pname,params)) + { + return; + } + + switch(pname) + { + case GL_SHADER_COMPILER: + case GL_SHADER_BINARY_FORMATS: + case GL_NUM_SHADER_BINARY_FORMATS: + case GL_MAX_VERTEX_UNIFORM_VECTORS: + case GL_MAX_VARYING_VECTORS: + case GL_MAX_FRAGMENT_UNIFORM_VECTORS: + if(ctx->getCaps()->GL_ARB_ES2_COMPATIBILITY) + ctx->dispatcher().glGetBooleanv(pname,params); + else + { + GLint iparam; + glGetIntegerv(pname,&iparam); + *params = (iparam != 0); + } + break; + + default: + ctx->dispatcher().glGetBooleanv(pname,params); + } +} + +GL_APICALL void GL_APIENTRY glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params){ + GET_CTX(); + SET_ERROR_IF(!(GLESv2Validate::bufferTarget(target) && GLESv2Validate::bufferParam(pname)),GL_INVALID_ENUM); + SET_ERROR_IF(!ctx->isBindedBuffer(target),GL_INVALID_OPERATION); + bool ret = true; + switch(pname) { + case GL_BUFFER_SIZE: + ctx->getBufferSize(target,params); + break; + case GL_BUFFER_USAGE: + ctx->getBufferUsage(target,params); + break; + } +} + + +GL_APICALL GLenum GL_APIENTRY glGetError(void){ + GET_CTX_RET(GL_NO_ERROR) + GLenum err = ctx->getGLerror(); + if(err != GL_NO_ERROR) { + ctx->setGLerror(GL_NO_ERROR); + return err; + } + return ctx->dispatcher().glGetError(); +} + +GL_APICALL void GL_APIENTRY glGetFloatv(GLenum pname, GLfloat* params){ + GET_CTX(); + + if (ctx->glGetFloatv(pname,params)) { + return; + } + + GLint i; + + switch (pname) { + case GL_CURRENT_PROGRAM: + case GL_FRAMEBUFFER_BINDING: + case GL_RENDERBUFFER_BINDING: + glGetIntegerv(pname,&i); + *params = (GLfloat)i; + break; + case GL_NUM_COMPRESSED_TEXTURE_FORMATS: + *params = (GLfloat)getCompressedFormats(NULL); + break; + case GL_COMPRESSED_TEXTURE_FORMATS: + { + int nparams = getCompressedFormats(NULL); + if (nparams>0) { + int * iparams = new int[nparams]; + getCompressedFormats(iparams); + for (int i=0; i<nparams; i++) params[i] = (GLfloat)iparams[i]; + delete [] iparams; + } + } + break; + + case GL_SHADER_COMPILER: + case GL_SHADER_BINARY_FORMATS: + case GL_NUM_SHADER_BINARY_FORMATS: + case GL_MAX_VERTEX_UNIFORM_VECTORS: + case GL_MAX_VARYING_VECTORS: + case GL_MAX_FRAGMENT_UNIFORM_VECTORS: + if(ctx->getCaps()->GL_ARB_ES2_COMPATIBILITY) + ctx->dispatcher().glGetFloatv(pname,params); + else + { + glGetIntegerv(pname,&i); + *params = (GLfloat)i; + } + break; + + default: + ctx->dispatcher().glGetFloatv(pname,params); + } +} + +GL_APICALL void GL_APIENTRY glGetIntegerv(GLenum pname, GLint* params){ + GET_CTX(); + + if (ctx->glGetIntegerv(pname,params)) + { + return; + } + + bool es2 = ctx->getCaps()->GL_ARB_ES2_COMPATIBILITY; + GLint i; + + switch (pname) { + case GL_CURRENT_PROGRAM: + if (ctx->shareGroup().Ptr()) { + ctx->dispatcher().glGetIntegerv(pname,&i); + *params = ctx->shareGroup()->getLocalName(SHADER,i); + } + break; + case GL_FRAMEBUFFER_BINDING: + if (ctx->shareGroup().Ptr()) { + ctx->dispatcher().glGetIntegerv(pname,&i); + *params = ctx->shareGroup()->getLocalName(FRAMEBUFFER,i); + } + break; + case GL_RENDERBUFFER_BINDING: + if (ctx->shareGroup().Ptr()) { + ctx->dispatcher().glGetIntegerv(pname,&i); + *params = ctx->shareGroup()->getLocalName(RENDERBUFFER,i); + } + break; + + case GL_NUM_COMPRESSED_TEXTURE_FORMATS: + *params = getCompressedFormats(NULL); + break; + case GL_COMPRESSED_TEXTURE_FORMATS: + getCompressedFormats(params); + break; + + case GL_SHADER_COMPILER: + if(es2) + ctx->dispatcher().glGetIntegerv(pname,params); + else + *params = 1; + break; + + case GL_SHADER_BINARY_FORMATS: + if(es2) + ctx->dispatcher().glGetIntegerv(pname,params); + break; + + case GL_NUM_SHADER_BINARY_FORMATS: + if(es2) + ctx->dispatcher().glGetIntegerv(pname,params); + else + *params = 0; + break; + + case GL_MAX_VERTEX_UNIFORM_VECTORS: + if(es2) + ctx->dispatcher().glGetIntegerv(pname,params); + else + *params = 128; + break; + + case GL_MAX_VARYING_VECTORS: + if(es2) + ctx->dispatcher().glGetIntegerv(pname,params); + else + *params = 8; + break; + + case GL_MAX_FRAGMENT_UNIFORM_VECTORS: + if(es2) + ctx->dispatcher().glGetIntegerv(pname,params); + else + *params = 16; + break; + + case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: + ctx->dispatcher().glGetIntegerv(pname,params); + if(*params > 16) + { + // GLES spec requires only 2, and the ATI driver erronously + // returns 32 (although it supports only 16). This WAR is simple, + // compliant and good enough for developers. + *params = 16; + } + break; + default: + ctx->dispatcher().glGetIntegerv(pname,params); + } +} + +GL_APICALL void GL_APIENTRY glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params){ + GET_CTX(); + SET_ERROR_IF(!(GLESv2Validate::framebufferTarget(target) && + GLESv2Validate::framebufferAttachment(attachment) && + GLESv2Validate::framebufferAttachmentParams(pname)),GL_INVALID_ENUM); + + // + // Take the attachment attribute from our state - if available + // + GLuint fbName = ctx->getFramebufferBinding(); + if (fbName) { + ObjectDataPtr fbObj = ctx->shareGroup()->getObjectData(FRAMEBUFFER,fbName); + if (fbObj.Ptr() != NULL) { + FramebufferData *fbData = (FramebufferData *)fbObj.Ptr(); + GLenum target; + GLuint name = fbData->getAttachment(attachment, &target, NULL); + if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE) { + if (target == GL_TEXTURE_2D) { + *params = GL_TEXTURE; + return; + } + else if (target == GL_RENDERBUFFER) { + *params = GL_RENDERBUFFER; + return; + } + } + else if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) { + *params = name; + return; + } + } + } + + ctx->dispatcher().glGetFramebufferAttachmentParameterivEXT(target,attachment,pname,params); +} + +GL_APICALL void GL_APIENTRY glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params){ + GET_CTX(); + SET_ERROR_IF(!(GLESv2Validate::renderbufferTarget(target) && GLESv2Validate::renderbufferParams(pname)),GL_INVALID_ENUM); + + // + // If this is a renderbuffer which is eglimage's target, we + // should query the underlying eglimage's texture object instead. + // + GLuint rb = ctx->getRenderbufferBinding(); + if (rb) { + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(RENDERBUFFER,rb); + RenderbufferData *rbData = (RenderbufferData *)objData.Ptr(); + if (rbData && rbData->sourceEGLImage != 0) { + GLenum texPname; + switch(pname) { + case GL_RENDERBUFFER_WIDTH: + texPname = GL_TEXTURE_WIDTH; + break; + case GL_RENDERBUFFER_HEIGHT: + texPname = GL_TEXTURE_HEIGHT; + break; + case GL_RENDERBUFFER_INTERNAL_FORMAT: + texPname = GL_TEXTURE_INTERNAL_FORMAT; + break; + case GL_RENDERBUFFER_RED_SIZE: + texPname = GL_TEXTURE_RED_SIZE; + break; + case GL_RENDERBUFFER_GREEN_SIZE: + texPname = GL_TEXTURE_GREEN_SIZE; + break; + case GL_RENDERBUFFER_BLUE_SIZE: + texPname = GL_TEXTURE_BLUE_SIZE; + break; + case GL_RENDERBUFFER_ALPHA_SIZE: + texPname = GL_TEXTURE_ALPHA_SIZE; + break; + case GL_RENDERBUFFER_DEPTH_SIZE: + texPname = GL_TEXTURE_DEPTH_SIZE; + break; + case GL_RENDERBUFFER_STENCIL_SIZE: + default: + *params = 0; //XXX + return; + break; + } + + GLint prevTex; + ctx->dispatcher().glGetIntegerv(GL_TEXTURE_BINDING_2D, &prevTex); + ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, + rbData->eglImageGlobalTexName); + ctx->dispatcher().glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, + texPname, + params); + ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, prevTex); + return; + } + } + + ctx->dispatcher().glGetRenderbufferParameterivEXT(target,pname,params); +} + + +GL_APICALL void GL_APIENTRY glGetProgramiv(GLuint program, GLenum pname, GLint* params){ + GET_CTX(); + SET_ERROR_IF(!GLESv2Validate::programParam(pname),GL_INVALID_ENUM); + if(ctx->shareGroup().Ptr()) { + const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program); + SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE); + switch(pname) { + case GL_LINK_STATUS: + { + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program); + SET_ERROR_IF(!objData.Ptr() ,GL_INVALID_OPERATION); + SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION); + ProgramData* programData = (ProgramData*)objData.Ptr(); + params[0] = programData->getLinkStatus(); + } + break; + //validate status should not return GL_TRUE if link failed + case GL_VALIDATE_STATUS: + { + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program); + SET_ERROR_IF(!objData.Ptr() ,GL_INVALID_OPERATION); + SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION); + ProgramData* programData = (ProgramData*)objData.Ptr(); + if (programData->getLinkStatus()==GL_TRUE) + ctx->dispatcher().glGetProgramiv(globalProgramName,pname,params); + else + params[0] = GL_FALSE; + } + break; + case GL_INFO_LOG_LENGTH: + { + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program); + SET_ERROR_IF(!objData.Ptr() ,GL_INVALID_OPERATION); + SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION); + ProgramData* programData = (ProgramData*)objData.Ptr(); + GLint logLength = strlen(programData->getInfoLog()); + params[0] = (logLength>0) ? logLength+1 : 0; + } + break; + default: + ctx->dispatcher().glGetProgramiv(globalProgramName,pname,params); + } + } +} + +GL_APICALL void GL_APIENTRY glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog){ + GET_CTX(); + if(ctx->shareGroup().Ptr()) { + const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program); + SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE); + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program); + SET_ERROR_IF(!objData.Ptr() ,GL_INVALID_OPERATION); + SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION); + ProgramData* programData = (ProgramData*)objData.Ptr(); + + if (bufsize==0) { + if (length) { + *length = 0; + } + return; + } + + GLsizei logLength; + logLength = strlen(programData->getInfoLog()); + + GLsizei returnLength=0; + if (infolog) { + returnLength = bufsize-1 < logLength ? bufsize-1 : logLength; + strncpy(infolog,programData->getInfoLog(),returnLength+1); + infolog[returnLength] = '\0'; + } + if (length) { + *length = returnLength; + } + } +} + +GL_APICALL void GL_APIENTRY glGetShaderiv(GLuint shader, GLenum pname, GLint* params){ + GET_CTX(); + if(ctx->shareGroup().Ptr()) { + const GLuint globalShaderName = ctx->shareGroup()->getGlobalName(SHADER,shader); + SET_ERROR_IF(globalShaderName==0, GL_INVALID_VALUE); + switch(pname) { + case GL_INFO_LOG_LENGTH: + { + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,shader); + SET_ERROR_IF(!objData.Ptr() ,GL_INVALID_OPERATION); + SET_ERROR_IF(objData.Ptr()->getDataType()!=SHADER_DATA,GL_INVALID_OPERATION); + ShaderParser* sp = (ShaderParser*)objData.Ptr(); + GLint logLength = strlen(sp->getInfoLog()); + params[0] = (logLength>0) ? logLength+1 : 0; + } + break; + default: + ctx->dispatcher().glGetShaderiv(globalShaderName,pname,params); + } + } +} + + +GL_APICALL void GL_APIENTRY glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog){ + GET_CTX(); + if(ctx->shareGroup().Ptr()) { + const GLuint globalShaderName = ctx->shareGroup()->getGlobalName(SHADER,shader); + SET_ERROR_IF(globalShaderName==0, GL_INVALID_VALUE); + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,shader); + SET_ERROR_IF(!objData.Ptr() ,GL_INVALID_OPERATION); + SET_ERROR_IF(objData.Ptr()->getDataType()!=SHADER_DATA,GL_INVALID_OPERATION); + ShaderParser* sp = (ShaderParser*)objData.Ptr(); + + if (bufsize==0) { + if (length) { + *length = 0; + } + return; + } + + GLsizei logLength; + logLength = strlen(sp->getInfoLog()); + + GLsizei returnLength=0; + if (infolog) { + returnLength = bufsize-1 <logLength ? bufsize-1 : logLength; + strncpy(infolog,sp->getInfoLog(),returnLength+1); + infolog[returnLength] = '\0'; + } + if (length) { + *length = returnLength; + } + } +} + +GL_APICALL void GL_APIENTRY glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision){ + GET_CTX_V2(); + SET_ERROR_IF(!(GLESv2Validate::shaderType(shadertype) && GLESv2Validate::precisionType(precisiontype)),GL_INVALID_ENUM); + + switch (precisiontype) { + case GL_LOW_INT: + case GL_MEDIUM_INT: + case GL_HIGH_INT: + range[0] = range[1] = 16; + *precision = 0; + break; + + case GL_LOW_FLOAT: + case GL_MEDIUM_FLOAT: + case GL_HIGH_FLOAT: + if(ctx->dispatcher().glGetShaderPrecisionFormat != NULL) { + ctx->dispatcher().glGetShaderPrecisionFormat(shadertype,precisiontype,range,precision); + } else { + range[0] = range[1] = 127; + *precision = 24; + } + break; + } +} + +GL_APICALL void GL_APIENTRY glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source){ + GET_CTX(); + if(ctx->shareGroup().Ptr()) { + const GLuint globalShaderName = ctx->shareGroup()->getGlobalName(SHADER,shader); + SET_ERROR_IF(globalShaderName == 0,GL_INVALID_VALUE); + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,shader); + SET_ERROR_IF(!objData.Ptr(),GL_INVALID_OPERATION); + SET_ERROR_IF(objData.Ptr()->getDataType()!=SHADER_DATA,GL_INVALID_OPERATION); + const char* src = ((ShaderParser*)objData.Ptr())->getOriginalSrc(); + int srcLength = 0; + if (src) { + srcLength = strlen(src); + } + + int returnLength = bufsize<srcLength ? bufsize-1 : srcLength; + if (returnLength) { + strncpy(source,src, returnLength); + source[returnLength] = '\0'; + } + + if (length) + *length = returnLength; + } +} + + +GL_APICALL const GLubyte* GL_APIENTRY glGetString(GLenum name){ + GET_CTX_RET(NULL) + static const GLubyte VENDOR[] = "Google"; + static const GLubyte VERSION[] = "OpenGL ES 2.0"; + static const GLubyte SHADING[] = "OpenGL ES GLSL ES 1.0.17"; + switch(name) { + case GL_VENDOR: + return VENDOR; + case GL_RENDERER: + return (const GLubyte*)ctx->getRendererString(); + case GL_VERSION: + return VERSION; + case GL_SHADING_LANGUAGE_VERSION: + return SHADING; + case GL_EXTENSIONS: + return (const GLubyte*)ctx->getExtensionString(); + default: + RET_AND_SET_ERROR_IF(true,GL_INVALID_ENUM,NULL); + } +} + +GL_APICALL void GL_APIENTRY glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params){ + GET_CTX(); + SET_ERROR_IF(!(GLESv2Validate::textureTarget(target) && GLESv2Validate::textureParams(pname)),GL_INVALID_ENUM); + ctx->dispatcher().glGetTexParameterfv(target,pname,params); + +} +GL_APICALL void GL_APIENTRY glGetTexParameteriv(GLenum target, GLenum pname, GLint* params){ + GET_CTX(); + SET_ERROR_IF(!(GLESv2Validate::textureTarget(target) && GLESv2Validate::textureParams(pname)),GL_INVALID_ENUM); + ctx->dispatcher().glGetTexParameteriv(target,pname,params); +} + +GL_APICALL void GL_APIENTRY glGetUniformfv(GLuint program, GLint location, GLfloat* params){ + GET_CTX(); + SET_ERROR_IF(location < 0,GL_INVALID_OPERATION); + if(ctx->shareGroup().Ptr()) { + const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program); + SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE); + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program); + SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION); + ProgramData* pData = (ProgramData *)objData.Ptr(); + SET_ERROR_IF(pData->getLinkStatus() != GL_TRUE,GL_INVALID_OPERATION); + ctx->dispatcher().glGetUniformfv(globalProgramName,location,params); + } +} + +GL_APICALL void GL_APIENTRY glGetUniformiv(GLuint program, GLint location, GLint* params){ + GET_CTX(); + SET_ERROR_IF(location < 0,GL_INVALID_OPERATION); + if(ctx->shareGroup().Ptr()) { + const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program); + SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE); + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program); + SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION); + ProgramData* pData = (ProgramData *)objData.Ptr(); + SET_ERROR_IF(pData->getLinkStatus() != GL_TRUE,GL_INVALID_OPERATION); + ctx->dispatcher().glGetUniformiv(globalProgramName,location,params); + } +} + +GL_APICALL int GL_APIENTRY glGetUniformLocation(GLuint program, const GLchar* name){ + GET_CTX_RET(-1); + if(ctx->shareGroup().Ptr()) { + const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program); + RET_AND_SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE,-1); + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program); + RET_AND_SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION,-1); + ProgramData* pData = (ProgramData *)objData.Ptr(); + RET_AND_SET_ERROR_IF(pData->getLinkStatus() != GL_TRUE,GL_INVALID_OPERATION,-1); + return ctx->dispatcher().glGetUniformLocation(globalProgramName,name); + } + return -1; +} + + + +GL_APICALL void GL_APIENTRY glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params){ + GET_CTX_V2(); + const GLESpointer* p = ctx->getPointer(index); + if(p) { + switch(pname){ + case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: + *params = 0; + break; + case GL_VERTEX_ATTRIB_ARRAY_ENABLED: + *params = p->isEnable(); + break; + case GL_VERTEX_ATTRIB_ARRAY_SIZE: + *params = p->getSize(); + break; + case GL_VERTEX_ATTRIB_ARRAY_STRIDE: + *params = p->getStride(); + break; + case GL_VERTEX_ATTRIB_ARRAY_TYPE: + *params = p->getType(); + break; + case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: + *params = p->isNormalize(); + break; + case GL_CURRENT_VERTEX_ATTRIB: + if(index == 0) + { + const float* att0 = ctx->getAtt0(); + for(int i=0; i<4; i++) + params[i] = att0[i]; + } + else + ctx->dispatcher().glGetVertexAttribfv(index,pname,params); + break; + default: + ctx->setGLerror(GL_INVALID_ENUM); + } + } else { + ctx->setGLerror(GL_INVALID_VALUE); + } +} + +GL_APICALL void GL_APIENTRY glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params){ + GET_CTX_V2(); + const GLESpointer* p = ctx->getPointer(index); + if(p) { + switch(pname){ + case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: + *params = 0; + break; + case GL_VERTEX_ATTRIB_ARRAY_ENABLED: + *params = p->isEnable(); + break; + case GL_VERTEX_ATTRIB_ARRAY_SIZE: + *params = p->getSize(); + break; + case GL_VERTEX_ATTRIB_ARRAY_STRIDE: + *params = p->getStride(); + break; + case GL_VERTEX_ATTRIB_ARRAY_TYPE: + *params = p->getType(); + break; + case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: + *params = p->isNormalize(); + break; + case GL_CURRENT_VERTEX_ATTRIB: + if(index == 0) + { + const float* att0 = ctx->getAtt0(); + for(int i=0; i<4; i++) + params[i] = (GLint)att0[i]; + } + else + ctx->dispatcher().glGetVertexAttribiv(index,pname,params); + break; + default: + ctx->setGLerror(GL_INVALID_ENUM); + } + } else { + ctx->setGLerror(GL_INVALID_VALUE); + } +} + +GL_APICALL void GL_APIENTRY glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer){ + GET_CTX(); + SET_ERROR_IF(pname != GL_VERTEX_ATTRIB_ARRAY_POINTER,GL_INVALID_ENUM); + SET_ERROR_IF((!GLESv2Validate::arrayIndex(ctx,index)),GL_INVALID_VALUE); + + const GLESpointer* p = ctx->getPointer(index); + if(p) { + *pointer = const_cast<void *>( p->getBufferData()); + } else { + ctx->setGLerror(GL_INVALID_VALUE); + } +} + +GL_APICALL void GL_APIENTRY glHint(GLenum target, GLenum mode){ + GET_CTX(); + SET_ERROR_IF(!GLESv2Validate::hintTargetMode(target,mode),GL_INVALID_ENUM); + ctx->dispatcher().glHint(target,mode); +} + +GL_APICALL GLboolean GL_APIENTRY glIsEnabled(GLenum cap){ + GET_CTX_RET(GL_FALSE); + RET_AND_SET_ERROR_IF(!GLESv2Validate::capability(cap),GL_INVALID_ENUM,GL_FALSE); + return ctx->dispatcher().glIsEnabled(cap); +} + +GL_APICALL GLboolean GL_APIENTRY glIsBuffer(GLuint buffer){ + GET_CTX_RET(GL_FALSE) + if(buffer && ctx->shareGroup().Ptr()) { + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(VERTEXBUFFER,buffer); + return objData.Ptr() ? ((GLESbuffer*)objData.Ptr())->wasBinded():GL_FALSE; + } + return GL_FALSE; +} + +GL_APICALL GLboolean GL_APIENTRY glIsFramebuffer(GLuint framebuffer){ + GET_CTX_RET(GL_FALSE) + if(framebuffer && ctx->shareGroup().Ptr()){ + return ctx->shareGroup()->isObject(FRAMEBUFFER,framebuffer) ? GL_TRUE :GL_FALSE; + } + return GL_FALSE; +} + +GL_APICALL GLboolean GL_APIENTRY glIsRenderbuffer(GLuint renderbuffer){ + GET_CTX_RET(GL_FALSE) + if(renderbuffer && ctx->shareGroup().Ptr()){ + return ctx->shareGroup()->isObject(RENDERBUFFER,renderbuffer) ? GL_TRUE :GL_FALSE; + } + return GL_FALSE; +} + +GL_APICALL GLboolean GL_APIENTRY glIsTexture(GLuint texture){ + GET_CTX_RET(GL_FALSE) + if (texture==0) + return GL_FALSE; + TextureData* tex = getTextureData(texture); + return tex ? tex->wasBound : GL_FALSE; +} + +GL_APICALL GLboolean GL_APIENTRY glIsProgram(GLuint program){ + GET_CTX_RET(GL_FALSE) + if(program && ctx->shareGroup().Ptr() && + ctx->shareGroup()->isObject(SHADER,program)) { + const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program); + return ctx->dispatcher().glIsProgram(globalProgramName); + } + return GL_FALSE; +} + +GL_APICALL GLboolean GL_APIENTRY glIsShader(GLuint shader){ + GET_CTX_RET(GL_FALSE) + if(shader && ctx->shareGroup().Ptr() && + ctx->shareGroup()->isObject(SHADER,shader)) { + const GLuint globalShaderName = ctx->shareGroup()->getGlobalName(SHADER,shader); + return ctx->dispatcher().glIsShader(globalShaderName); + } + return GL_FALSE; +} + +GL_APICALL void GL_APIENTRY glLineWidth(GLfloat width){ + GET_CTX(); + ctx->dispatcher().glLineWidth(width); +} + +GL_APICALL void GL_APIENTRY glLinkProgram(GLuint program){ + GET_CTX(); + GLint linkStatus = GL_FALSE; + if(ctx->shareGroup().Ptr()) { + const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program); + SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE); + + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program); + SET_ERROR_IF(!objData.Ptr(), GL_INVALID_OPERATION); + SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA, GL_INVALID_OPERATION); + ProgramData* programData = (ProgramData*)objData.Ptr(); + GLint fragmentShader = programData->getAttachedFragmentShader(); + GLint vertexShader = programData->getAttachedVertexShader(); + if (vertexShader != 0 && fragmentShader!=0) { + /* validating that the fragment & vertex shaders were compiled successfuly*/ + GLint fCompileStatus = GL_FALSE; + GLint vCompileStatus = GL_FALSE; + GLuint fragmentShaderGlobal = ctx->shareGroup()->getGlobalName(SHADER,fragmentShader); + GLuint vertexShaderGlobal = ctx->shareGroup()->getGlobalName(SHADER,vertexShader); + ctx->dispatcher().glGetShaderiv(fragmentShaderGlobal,GL_COMPILE_STATUS,&fCompileStatus); + ctx->dispatcher().glGetShaderiv(vertexShaderGlobal,GL_COMPILE_STATUS,&vCompileStatus); + + if(fCompileStatus != 0 && vCompileStatus != 0){ + ctx->dispatcher().glLinkProgram(globalProgramName); + ctx->dispatcher().glGetProgramiv(globalProgramName,GL_LINK_STATUS,&linkStatus); + } + } + programData->setLinkStatus(linkStatus); + + GLsizei infoLogLength=0; + GLchar* infoLog; + ctx->dispatcher().glGetProgramiv(globalProgramName,GL_INFO_LOG_LENGTH,&infoLogLength); + infoLog = new GLchar[infoLogLength+1]; + ctx->dispatcher().glGetProgramInfoLog(globalProgramName,infoLogLength,NULL,infoLog); + programData->setInfoLog(infoLog); + } +} + +GL_APICALL void GL_APIENTRY glPixelStorei(GLenum pname, GLint param){ + GET_CTX(); + SET_ERROR_IF(!GLESv2Validate::pixelStoreParam(pname),GL_INVALID_ENUM); + SET_ERROR_IF(!((param==1)||(param==2)||(param==4)||(param==8)), GL_INVALID_VALUE); + ctx->setUnpackAlignment(param); + ctx->dispatcher().glPixelStorei(pname,param); +} + +GL_APICALL void GL_APIENTRY glPolygonOffset(GLfloat factor, GLfloat units){ + GET_CTX(); + ctx->dispatcher().glPolygonOffset(factor,units); +} + +GL_APICALL void GL_APIENTRY glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels){ + GET_CTX(); + SET_ERROR_IF(!(GLESv2Validate::readPixelFrmt(format) && GLESv2Validate::pixelType(ctx,type)),GL_INVALID_ENUM); + SET_ERROR_IF(!(GLESv2Validate::pixelOp(format,type)),GL_INVALID_OPERATION); + ctx->dispatcher().glReadPixels(x,y,width,height,format,type,pixels); +} + + +GL_APICALL void GL_APIENTRY glReleaseShaderCompiler(void){ + GET_CTX(); + + if(ctx->dispatcher().glReleaseShaderCompiler != NULL) + { + ctx->dispatcher().glReleaseShaderCompiler(); + } +} + +GL_APICALL void GL_APIENTRY glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height){ + GET_CTX(); + GLenum internal = internalformat; + switch (internalformat) { + case GL_RGB565: + internal = GL_RGB; + break; + case GL_RGB5_A1: + internal = GL_RGBA; + break; + default: + internal = internalformat; + break; + } + + // Get current bounded renderbuffer + // raise INVALID_OPERATIOn if no renderbuffer is bounded + GLuint rb = ctx->getRenderbufferBinding(); + SET_ERROR_IF(rb == 0,GL_INVALID_OPERATION); + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(RENDERBUFFER,rb); + RenderbufferData *rbData = (RenderbufferData *)objData.Ptr(); + SET_ERROR_IF(!rbData,GL_INVALID_OPERATION); + + // + // if the renderbuffer was an eglImage target, detach from + // the eglImage. + // + if (rbData->sourceEGLImage != 0) { + if (rbData->eglImageDetach) { + (*rbData->eglImageDetach)(rbData->sourceEGLImage); + } + rbData->sourceEGLImage = 0; + rbData->eglImageGlobalTexName = 0; + } + + ctx->dispatcher().glRenderbufferStorageEXT(target,internal,width,height); +} + +GL_APICALL void GL_APIENTRY glSampleCoverage(GLclampf value, GLboolean invert){ + GET_CTX(); + ctx->dispatcher().glSampleCoverage(value,invert); +} + +GL_APICALL void GL_APIENTRY glScissor(GLint x, GLint y, GLsizei width, GLsizei height){ + GET_CTX(); + ctx->dispatcher().glScissor(x,y,width,height); +} + +GL_APICALL void GL_APIENTRY glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length){ + GET_CTX(); + + SET_ERROR_IF( (ctx->dispatcher().glShaderBinary == NULL), GL_INVALID_OPERATION); + + if(ctx->shareGroup().Ptr()){ + for(int i=0; i < n ; i++){ + const GLuint globalShaderName = ctx->shareGroup()->getGlobalName(SHADER,shaders[i]); + SET_ERROR_IF(globalShaderName == 0,GL_INVALID_VALUE); + ctx->dispatcher().glShaderBinary(1,&globalShaderName,binaryformat,binary,length); + } + } +} + +GL_APICALL void GL_APIENTRY glShaderSource(GLuint shader, GLsizei count, const GLchar** string, const GLint* length){ + GET_CTX_V2(); + SET_ERROR_IF(count < 0,GL_INVALID_VALUE); + if(ctx->shareGroup().Ptr()){ + const GLuint globalShaderName = ctx->shareGroup()->getGlobalName(SHADER,shader); + SET_ERROR_IF(globalShaderName == 0,GL_INVALID_VALUE); + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,shader); + SET_ERROR_IF(!objData.Ptr(),GL_INVALID_OPERATION); + SET_ERROR_IF(objData.Ptr()->getDataType()!=SHADER_DATA,GL_INVALID_OPERATION); + ShaderParser* sp = (ShaderParser*)objData.Ptr(); + sp->setSrc(ctx->glslVersion(),count,string,length); + ctx->dispatcher().glShaderSource(globalShaderName,1,sp->parsedLines(),NULL); + } +} + +GL_APICALL void GL_APIENTRY glStencilFunc(GLenum func, GLint ref, GLuint mask){ + GET_CTX(); + ctx->dispatcher().glStencilFunc(func,ref,mask); +} +GL_APICALL void GL_APIENTRY glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask){ + GET_CTX(); + ctx->dispatcher().glStencilFuncSeparate(face,func,ref,mask); +} +GL_APICALL void GL_APIENTRY glStencilMask(GLuint mask){ + GET_CTX(); + ctx->dispatcher().glStencilMask(mask); +} + +GL_APICALL void GL_APIENTRY glStencilMaskSeparate(GLenum face, GLuint mask){ + GET_CTX(); + ctx->dispatcher().glStencilMaskSeparate(face,mask); +} + +GL_APICALL void GL_APIENTRY glStencilOp(GLenum fail, GLenum zfail, GLenum zpass){ + GET_CTX(); + ctx->dispatcher().glStencilOp(fail,zfail,zpass); +} + +GL_APICALL void GL_APIENTRY glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass){ + GET_CTX(); + ctx->dispatcher().glStencilOp(fail,zfail,zpass); +} + +GL_APICALL void GL_APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels){ + GET_CTX(); + SET_ERROR_IF(!(GLESv2Validate::textureTargetEx(target) && + GLESv2Validate::pixelFrmt(ctx,internalformat) && + GLESv2Validate::pixelFrmt(ctx,format)&& + GLESv2Validate::pixelType(ctx,type)),GL_INVALID_ENUM); + + SET_ERROR_IF((format == GL_DEPTH_COMPONENT || internalformat == GL_DEPTH_COMPONENT) && + (type != GL_UNSIGNED_SHORT && type != GL_UNSIGNED_INT), GL_INVALID_OPERATION); + + SET_ERROR_IF((type == GL_UNSIGNED_SHORT || type == GL_UNSIGNED_INT) && + (format != GL_DEPTH_COMPONENT || internalformat != GL_DEPTH_COMPONENT), GL_INVALID_OPERATION); + + SET_ERROR_IF(!(GLESv2Validate::pixelOp(format,type) && internalformat == ((GLint)format)),GL_INVALID_OPERATION); + SET_ERROR_IF(border != 0,GL_INVALID_VALUE); + + if (ctx->shareGroup().Ptr()){ + TextureData *texData = getTextureTargetData(target); + if(texData) { + texData->width = width; + texData->height = height; + texData->border = border; + texData->internalFormat = internalformat; + texData->target = target; + + if (texData->sourceEGLImage != 0) { + // + // This texture was a target of EGLImage, + // but now it is re-defined so we need to detach + // from the EGLImage and re-generate global texture name + // for it. + // + if (texData->eglImageDetach) { + (*texData->eglImageDetach)(texData->sourceEGLImage); + } + unsigned int tex = ctx->getBindedTexture(target); + ctx->shareGroup()->replaceGlobalName(TEXTURE, + tex, + texData->oldGlobal); + ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, texData->oldGlobal); + texData->sourceEGLImage = 0; + texData->oldGlobal = 0; + } + } + } + + if (type==GL_HALF_FLOAT_OES) + type = GL_HALF_FLOAT_NV; + if (pixels==NULL && type==GL_UNSIGNED_SHORT_5_5_5_1) + type = GL_UNSIGNED_SHORT; + ctx->dispatcher().glTexImage2D(target,level,internalformat,width,height,border,format,type,pixels); +} + + +GL_APICALL void GL_APIENTRY glTexParameterf(GLenum target, GLenum pname, GLfloat param){ + GET_CTX(); + SET_ERROR_IF(!(GLESv2Validate::textureTarget(target) && GLESv2Validate::textureParams(pname)),GL_INVALID_ENUM); + ctx->dispatcher().glTexParameterf(target,pname,param); +} +GL_APICALL void GL_APIENTRY glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params){ + GET_CTX(); + SET_ERROR_IF(!(GLESv2Validate::textureTarget(target) && GLESv2Validate::textureParams(pname)),GL_INVALID_ENUM); + ctx->dispatcher().glTexParameterfv(target,pname,params); +} +GL_APICALL void GL_APIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param){ + GET_CTX(); + SET_ERROR_IF(!(GLESv2Validate::textureTarget(target) && GLESv2Validate::textureParams(pname)),GL_INVALID_ENUM); + ctx->dispatcher().glTexParameteri(target,pname,param); +} +GL_APICALL void GL_APIENTRY glTexParameteriv(GLenum target, GLenum pname, const GLint* params){ + GET_CTX(); + SET_ERROR_IF(!(GLESv2Validate::textureTarget(target) && GLESv2Validate::textureParams(pname)),GL_INVALID_ENUM); + ctx->dispatcher().glTexParameteriv(target,pname,params); +} + +GL_APICALL void GL_APIENTRY glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels){ + GET_CTX(); + SET_ERROR_IF(!(GLESv2Validate::textureTargetEx(target) && + GLESv2Validate::pixelFrmt(ctx,format)&& + GLESv2Validate::pixelType(ctx,type)),GL_INVALID_ENUM); + SET_ERROR_IF(!GLESv2Validate::pixelOp(format,type),GL_INVALID_OPERATION); + if (type==GL_HALF_FLOAT_OES) + type = GL_HALF_FLOAT_NV; + + ctx->dispatcher().glTexSubImage2D(target,level,xoffset,yoffset,width,height,format,type,pixels); + +} + +GL_APICALL void GL_APIENTRY glUniform1f(GLint location, GLfloat x){ + GET_CTX(); + ctx->dispatcher().glUniform1f(location,x); +} +GL_APICALL void GL_APIENTRY glUniform1fv(GLint location, GLsizei count, const GLfloat* v){ + GET_CTX(); + ctx->dispatcher().glUniform1fv(location,count,v); +} + +GL_APICALL void GL_APIENTRY glUniform1i(GLint location, GLint x){ + GET_CTX(); + ctx->dispatcher().glUniform1i(location,x); +} +GL_APICALL void GL_APIENTRY glUniform1iv(GLint location, GLsizei count, const GLint* v){ + GET_CTX(); + ctx->dispatcher().glUniform1iv(location,count,v); +} +GL_APICALL void GL_APIENTRY glUniform2f(GLint location, GLfloat x, GLfloat y){ + GET_CTX(); + ctx->dispatcher().glUniform2f(location,x,y); +} +GL_APICALL void GL_APIENTRY glUniform2fv(GLint location, GLsizei count, const GLfloat* v){ + GET_CTX(); + ctx->dispatcher().glUniform2fv(location,count,v); +} +GL_APICALL void GL_APIENTRY glUniform2i(GLint location, GLint x, GLint y){ + GET_CTX(); + ctx->dispatcher().glUniform2i(location,x,y); +} +GL_APICALL void GL_APIENTRY glUniform2iv(GLint location, GLsizei count, const GLint* v){ + GET_CTX(); + ctx->dispatcher().glUniform2iv(location,count,v); +} +GL_APICALL void GL_APIENTRY glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z){ + GET_CTX(); + ctx->dispatcher().glUniform3f(location,x,y,z); +} +GL_APICALL void GL_APIENTRY glUniform3fv(GLint location, GLsizei count, const GLfloat* v){ + GET_CTX(); + ctx->dispatcher().glUniform3fv(location,count,v); +} +GL_APICALL void GL_APIENTRY glUniform3i(GLint location, GLint x, GLint y, GLint z){ + GET_CTX(); + ctx->dispatcher().glUniform3i(location,x,y,z); +} + +GL_APICALL void GL_APIENTRY glUniform3iv(GLint location, GLsizei count, const GLint* v){ + GET_CTX(); + ctx->dispatcher().glUniform3iv(location,count,v); +} + +GL_APICALL void GL_APIENTRY glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w){ + GET_CTX(); + ctx->dispatcher().glUniform4f(location,x,y,z,w); +} + +GL_APICALL void GL_APIENTRY glUniform4fv(GLint location, GLsizei count, const GLfloat* v){ + GET_CTX(); + ctx->dispatcher().glUniform4fv(location,count,v); +} + +GL_APICALL void GL_APIENTRY glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w){ + GET_CTX(); + ctx->dispatcher().glUniform4i(location,x,y,z,w); +} + +GL_APICALL void GL_APIENTRY glUniform4iv(GLint location, GLsizei count, const GLint* v){ + GET_CTX(); + ctx->dispatcher().glUniform4iv(location,count,v); +} + +GL_APICALL void GL_APIENTRY glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value){ + GET_CTX(); + SET_ERROR_IF(transpose != GL_FALSE,GL_INVALID_VALUE); + ctx->dispatcher().glUniformMatrix2fv(location,count,transpose,value); +} + +GL_APICALL void GL_APIENTRY glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value){ + GET_CTX(); + SET_ERROR_IF(transpose != GL_FALSE,GL_INVALID_VALUE); + ctx->dispatcher().glUniformMatrix3fv(location,count,transpose,value); +} + +GL_APICALL void GL_APIENTRY glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value){ + GET_CTX(); + SET_ERROR_IF(transpose != GL_FALSE,GL_INVALID_VALUE); + ctx->dispatcher().glUniformMatrix4fv(location,count,transpose,value); +} + +GL_APICALL void GL_APIENTRY glUseProgram(GLuint program){ + GET_CTX(); + if(ctx->shareGroup().Ptr()) { + const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program); + SET_ERROR_IF(program!=0 && globalProgramName==0,GL_INVALID_VALUE); + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program); + SET_ERROR_IF(objData.Ptr() && (objData.Ptr()->getDataType()!=PROGRAM_DATA),GL_INVALID_OPERATION); + ctx->dispatcher().glUseProgram(globalProgramName); + } +} + +GL_APICALL void GL_APIENTRY glValidateProgram(GLuint program){ + GET_CTX(); + if(ctx->shareGroup().Ptr()) { + const GLuint globalProgramName = ctx->shareGroup()->getGlobalName(SHADER,program); + SET_ERROR_IF(globalProgramName==0, GL_INVALID_VALUE); + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(SHADER,program); + SET_ERROR_IF(objData.Ptr()->getDataType()!=PROGRAM_DATA,GL_INVALID_OPERATION); + ProgramData* programData = (ProgramData*)objData.Ptr(); + ctx->dispatcher().glValidateProgram(globalProgramName); + + GLsizei infoLogLength=0; + GLchar* infoLog; + ctx->dispatcher().glGetProgramiv(globalProgramName,GL_INFO_LOG_LENGTH,&infoLogLength); + infoLog = new GLchar[infoLogLength+1]; + ctx->dispatcher().glGetProgramInfoLog(globalProgramName,infoLogLength,NULL,infoLog); + programData->setInfoLog(infoLog); + } +} + +GL_APICALL void GL_APIENTRY glVertexAttrib1f(GLuint indx, GLfloat x){ + GET_CTX_V2(); + ctx->dispatcher().glVertexAttrib1f(indx,x); + if(indx == 0) + ctx->setAttribute0value(x, 0.0, 0.0, 1.0); +} + +GL_APICALL void GL_APIENTRY glVertexAttrib1fv(GLuint indx, const GLfloat* values){ + GET_CTX_V2(); + ctx->dispatcher().glVertexAttrib1fv(indx,values); + if(indx == 0) + ctx->setAttribute0value(values[0], 0.0, 0.0, 1.0); +} + +GL_APICALL void GL_APIENTRY glVertexAttrib2f(GLuint indx, GLfloat x, GLfloat y){ + GET_CTX_V2(); + ctx->dispatcher().glVertexAttrib2f(indx,x,y); + if(indx == 0) + ctx->setAttribute0value(x, y, 0.0, 1.0); +} + +GL_APICALL void GL_APIENTRY glVertexAttrib2fv(GLuint indx, const GLfloat* values){ + GET_CTX_V2(); + ctx->dispatcher().glVertexAttrib2fv(indx,values); + if(indx == 0) + ctx->setAttribute0value(values[0], values[1], 0.0, 1.0); +} + +GL_APICALL void GL_APIENTRY glVertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z){ + GET_CTX_V2(); + ctx->dispatcher().glVertexAttrib3f(indx,x,y,z); + if(indx == 0) + ctx->setAttribute0value(x, y, z, 1.0); +} + +GL_APICALL void GL_APIENTRY glVertexAttrib3fv(GLuint indx, const GLfloat* values){ + GET_CTX_V2(); + ctx->dispatcher().glVertexAttrib3fv(indx,values); + if(indx == 0) + ctx->setAttribute0value(values[0], values[1], values[2], 1.0); +} + +GL_APICALL void GL_APIENTRY glVertexAttrib4f(GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w){ + GET_CTX_V2(); + ctx->dispatcher().glVertexAttrib4f(indx,x,y,z,w); + if(indx == 0) + ctx->setAttribute0value(x, y, z, w); +} + +GL_APICALL void GL_APIENTRY glVertexAttrib4fv(GLuint indx, const GLfloat* values){ + GET_CTX_V2(); + ctx->dispatcher().glVertexAttrib4fv(indx,values); + if(indx == 0) + ctx->setAttribute0value(values[0], values[1], values[2], values[3]); +} + +GL_APICALL void GL_APIENTRY glVertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr){ + GET_CTX(); + SET_ERROR_IF((!GLESv2Validate::arrayIndex(ctx,indx)),GL_INVALID_VALUE); + if (type == GL_HALF_FLOAT_OES) type = GL_HALF_FLOAT; + ctx->setPointer(indx,size,type,stride,ptr,normalized); +} + +GL_APICALL void GL_APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height){ + GET_CTX(); + ctx->dispatcher().glViewport(x,y,width,height); +} + +GL_APICALL void GL_APIENTRY glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) +{ + GET_CTX(); + SET_ERROR_IF(!GLESv2Validate::textureTargetLimited(target),GL_INVALID_ENUM); + unsigned int imagehndl = ToTargetCompatibleHandle((uintptr_t)image); + EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl); + if (img) { + // Create the texture object in the underlying EGL implementation, + // flag to the OpenGL layer to skip the image creation and map the + // current binded texture object to the existing global object. + if (ctx->shareGroup().Ptr()) { + ObjectLocalName tex = TextureLocalName(target,ctx->getBindedTexture(target)); + unsigned int oldGlobal = ctx->shareGroup()->getGlobalName(TEXTURE, tex); + // Delete old texture object but only if it is not a target of a EGLImage + if (oldGlobal) { + TextureData* oldTexData = getTextureData(tex); + if (!oldTexData || oldTexData->sourceEGLImage == 0) { + ctx->dispatcher().glDeleteTextures(1, &oldGlobal); + } + } + // replace mapping and bind the new global object + ctx->shareGroup()->replaceGlobalName(TEXTURE, tex,img->globalTexName); + ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, img->globalTexName); + TextureData *texData = getTextureTargetData(target); + SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION); + texData->width = img->width; + texData->height = img->height; + texData->border = img->border; + texData->internalFormat = img->internalFormat; + texData->sourceEGLImage = imagehndl; + texData->eglImageDetach = s_eglIface->eglDetachEGLImage; + texData->oldGlobal = oldGlobal; + } + } +} + +GL_APICALL void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image) +{ + GET_CTX(); + SET_ERROR_IF(target != GL_RENDERBUFFER_OES,GL_INVALID_ENUM); + unsigned int imagehndl = ToTargetCompatibleHandle((uintptr_t)image); + EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl); + SET_ERROR_IF(!img,GL_INVALID_VALUE); + SET_ERROR_IF(!ctx->shareGroup().Ptr(),GL_INVALID_OPERATION); + + // Get current bounded renderbuffer + // raise INVALID_OPERATIOn if no renderbuffer is bounded + GLuint rb = ctx->getRenderbufferBinding(); + SET_ERROR_IF(rb == 0,GL_INVALID_OPERATION); + ObjectDataPtr objData = ctx->shareGroup()->getObjectData(RENDERBUFFER,rb); + RenderbufferData *rbData = (RenderbufferData *)objData.Ptr(); + SET_ERROR_IF(!rbData,GL_INVALID_OPERATION); + + // + // flag in the renderbufferData that it is an eglImage target + // + rbData->sourceEGLImage = imagehndl; + rbData->eglImageDetach = s_eglIface->eglDetachEGLImage; + rbData->eglImageGlobalTexName = img->globalTexName; + + // + // if the renderbuffer is attached to a framebuffer + // change the framebuffer attachment in the undelying OpenGL + // to point to the eglImage texture object. + // + if (rbData->attachedFB) { + // update the framebuffer attachment point to the + // underlying texture of the img + GLuint prevFB = ctx->getFramebufferBinding(); + if (prevFB != rbData->attachedFB) { + ctx->dispatcher().glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, + rbData->attachedFB); + } + ctx->dispatcher().glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, + rbData->attachedPoint, + GL_TEXTURE_2D, + img->globalTexName,0); + if (prevFB != rbData->attachedFB) { + ctx->dispatcher().glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, + prevFB); + } + } +} diff --git a/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Validate.cpp b/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Validate.cpp new file mode 100644 index 0000000..53d1314 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Validate.cpp @@ -0,0 +1,182 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "GLESv2Validate.h" + +bool GLESv2Validate::blendEquationMode(GLenum mode){ + return mode == GL_FUNC_ADD || + mode == GL_FUNC_SUBTRACT || + mode == GL_FUNC_REVERSE_SUBTRACT; +} + +bool GLESv2Validate::blendSrc(GLenum s) { + switch(s) { + 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_CONSTANT_COLOR: + case GL_ONE_MINUS_CONSTANT_COLOR: + case GL_CONSTANT_ALPHA: + case GL_ONE_MINUS_CONSTANT_ALPHA: + case GL_SRC_ALPHA_SATURATE: + return true; + } + return false; +} + + +bool GLESv2Validate::blendDst(GLenum d) { + switch(d) { + 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_CONSTANT_COLOR: + case GL_ONE_MINUS_CONSTANT_COLOR: + case GL_CONSTANT_ALPHA: + case GL_ONE_MINUS_CONSTANT_ALPHA: + return true; + } + return false; +} + +bool GLESv2Validate::textureParams(GLenum param){ + switch(param) { + case GL_TEXTURE_MIN_FILTER: + case GL_TEXTURE_MAG_FILTER: + case GL_TEXTURE_WRAP_S: + case GL_TEXTURE_WRAP_T: + return true; + default: + return false; + } +} + +bool GLESv2Validate::hintTargetMode(GLenum target,GLenum mode){ + + switch(mode) { + case GL_FASTEST: + case GL_NICEST: + case GL_DONT_CARE: + break; + default: return false; + } + return target == GL_GENERATE_MIPMAP_HINT || target == GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES; +} + +bool GLESv2Validate::capability(GLenum cap){ + switch(cap){ + case GL_BLEND: + case GL_CULL_FACE: + case GL_DEPTH_TEST: + case GL_DITHER: + case GL_POLYGON_OFFSET_FILL: + case GL_SAMPLE_ALPHA_TO_COVERAGE: + case GL_SAMPLE_COVERAGE: + case GL_SCISSOR_TEST: + case GL_STENCIL_TEST: + return true; + } + return false; +} + +bool GLESv2Validate::pixelStoreParam(GLenum param){ + return param == GL_PACK_ALIGNMENT || param == GL_UNPACK_ALIGNMENT; +} + +bool GLESv2Validate::readPixelFrmt(GLenum format){ + switch(format) { + case GL_ALPHA: + case GL_RGB: + case GL_RGBA: + return true; + } + return false; +} + + +bool GLESv2Validate::shaderType(GLenum type){ + return type == GL_VERTEX_SHADER || type == GL_FRAGMENT_SHADER; +} + +bool GLESv2Validate::precisionType(GLenum type){ + switch(type){ + case GL_LOW_FLOAT: + case GL_MEDIUM_FLOAT: + case GL_HIGH_FLOAT: + case GL_LOW_INT: + case GL_MEDIUM_INT: + case GL_HIGH_INT: + return true; + } + return false; +} + +bool GLESv2Validate::arrayIndex(GLEScontext * ctx,GLuint index) { + return index < (GLuint)ctx->getCaps()->maxVertexAttribs; +} + +bool GLESv2Validate::pixelType(GLEScontext * ctx,GLenum type) { + if(type == GL_UNSIGNED_SHORT || type == GL_UNSIGNED_INT) + return true; + + return GLESvalidate::pixelType(ctx, type); +} + +bool GLESv2Validate::pixelFrmt(GLEScontext* ctx,GLenum format) { + if(format == GL_DEPTH_COMPONENT) + return true; + + return GLESvalidate::pixelFrmt(ctx, format); +} + +bool GLESv2Validate::attribName(const GLchar* name){ + const GLchar* found = strstr(name,"gl_"); + return (!found) || + (found != name) ; // attrib name does not start with gl_ +} + +bool GLESv2Validate::attribIndex(int index){ + return index >=0 && index < GL_MAX_VERTEX_ATTRIBS; +} + +bool GLESv2Validate::programParam(GLenum pname){ + switch(pname){ + case GL_DELETE_STATUS: + case GL_LINK_STATUS: + case GL_VALIDATE_STATUS: + case GL_INFO_LOG_LENGTH: + case GL_ATTACHED_SHADERS: + case GL_ACTIVE_ATTRIBUTES: + case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: + case GL_ACTIVE_UNIFORMS: + case GL_ACTIVE_UNIFORM_MAX_LENGTH: + return true; + } + return false; +} diff --git a/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Validate.h b/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Validate.h new file mode 100644 index 0000000..b7cd07d --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Validate.h @@ -0,0 +1,43 @@ +/* +* Copyright 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef GLES_V2_VALIDATE_H +#define GLES_V2_VALIDATE_H + +#include <GLES2/gl2.h> +#include <GLES2/gl2ext.h> +#include <GLcommon/GLESvalidate.h> + +struct GLESv2Validate:public GLESvalidate{ +static bool blendEquationMode(GLenum mode); +static bool blendSrc(GLenum s); +static bool blendDst(GLenum d); +static bool textureParams(GLenum param); +static bool hintTargetMode(GLenum target,GLenum mode); +static bool capability(GLenum cap); +static bool pixelStoreParam(GLenum param); +static bool readPixelFrmt(GLenum format); +static bool shaderType(GLenum type); +static bool precisionType(GLenum type); +static bool arrayIndex(GLEScontext * ctx,GLuint index); +static bool pixelType(GLEScontext * ctx,GLenum type); +static bool pixelFrmt(GLEScontext* ctx,GLenum format); +static bool attribName(const GLchar* name); +static bool attribIndex(int index); +static bool programParam(GLenum pname); +}; + +#endif diff --git a/emulator/opengl/host/libs/Translator/GLES_V2/ProgramData.cpp b/emulator/opengl/host/libs/Translator/GLES_V2/ProgramData.cpp new file mode 100644 index 0000000..656c782 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLES_V2/ProgramData.cpp @@ -0,0 +1,96 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include <GLES2/gl2.h> +#include <GLcommon/objectNameManager.h> +#include "ProgramData.h" + +ProgramData::ProgramData() : ObjectData(PROGRAM_DATA), + AttachedVertexShader(0), + AttachedFragmentShader(0), + LinkStatus(GL_FALSE) { + infoLog = new GLchar[1]; + infoLog[0] = '\0'; +} + +ProgramData::~ProgramData () { + delete[] infoLog; +}; + +void ProgramData::setInfoLog(GLchar* log) { + delete[] infoLog; + infoLog = log; +} + +GLchar* ProgramData::getInfoLog() { + return infoLog; +} + +GLuint ProgramData::getAttachedVertexShader() { + return AttachedVertexShader; +} + +GLuint ProgramData::getAttachedFragmentShader() { + return AttachedFragmentShader; +} + +GLuint ProgramData::getAttachedShader(GLenum type) { + GLuint shader = 0; + switch (type) { + case GL_VERTEX_SHADER: + shader = AttachedVertexShader; + break; + case GL_FRAGMENT_SHADER: + shader = AttachedFragmentShader; + break; + } + return shader; +} + +bool ProgramData::attachShader(GLuint shader,GLenum type) { + if (type==GL_VERTEX_SHADER && AttachedVertexShader==0) { + AttachedVertexShader=shader; + return true; + } + else if (type==GL_FRAGMENT_SHADER && AttachedFragmentShader==0) { + AttachedFragmentShader=shader; + return true; + } + return false; +} + +bool ProgramData::isAttached(GLuint shader) { + return (AttachedFragmentShader==shader || AttachedVertexShader==shader); +} + +bool ProgramData::detachShader(GLuint shader) { + if (AttachedVertexShader==shader) { + AttachedVertexShader = 0; + return true; + } + else if (AttachedFragmentShader==shader) { + AttachedFragmentShader = 0; + return true; + } + return false; +} + +void ProgramData::setLinkStatus(GLint status) { + LinkStatus = status; +} + +GLint ProgramData::getLinkStatus() { + return LinkStatus; +} diff --git a/emulator/opengl/host/libs/Translator/GLES_V2/ProgramData.h b/emulator/opengl/host/libs/Translator/GLES_V2/ProgramData.h new file mode 100644 index 0000000..a79574a --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLES_V2/ProgramData.h @@ -0,0 +1,44 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef PROGRAM_DATA_H +#define PROGRAM_DATA_H + +class ProgramData:public ObjectData{ +public: + ProgramData(); + virtual ~ProgramData(); + + GLuint getAttachedVertexShader(); + GLuint getAttachedFragmentShader(); + GLuint getAttachedShader(GLenum type); + + bool attachShader(GLuint shader,GLenum type); + bool isAttached(GLuint shader); + bool detachShader(GLuint shader); + + void setLinkStatus(GLint status); + GLint getLinkStatus(); + + void setInfoLog(GLchar *log); + GLchar* getInfoLog(); + +private: + GLuint AttachedVertexShader; + GLuint AttachedFragmentShader; + GLint LinkStatus; + GLchar* infoLog; +}; +#endif diff --git a/emulator/opengl/host/libs/Translator/GLES_V2/ShaderParser.cpp b/emulator/opengl/host/libs/Translator/GLES_V2/ShaderParser.cpp new file mode 100644 index 0000000..a80326d --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLES_V2/ShaderParser.cpp @@ -0,0 +1,343 @@ +/* +* Copyright 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "ShaderParser.h" +#include <string.h> + +ShaderParser::ShaderParser():ObjectData(SHADER_DATA), + m_type(0), + m_originalSrc(NULL), + m_parsedLines(NULL) { + m_infoLog = new GLchar[1]; + m_infoLog[0] = '\0'; +}; + +ShaderParser::ShaderParser(GLenum type):ObjectData(SHADER_DATA), + m_type(type), + m_originalSrc(NULL), + m_parsedLines(NULL) { + + m_infoLog = new GLchar[1]; + m_infoLog[0] = '\0'; +}; + +void ShaderParser::setSrc(const Version& ver,GLsizei count,const GLchar** strings,const GLint* length){ + for(int i = 0;i<count;i++){ + m_src.append(strings[i]); + } + //store original source + if (m_originalSrc) + free(m_originalSrc); + m_originalSrc = strdup(m_src.c_str()); + + clearParsedSrc(); + + // parseGLSLversion must be called first since #version should be the + // first token in the shader source. + parseGLSLversion(); + parseBuiltinConstants(); + /* + version 1.30.10 is the first version of GLSL Language containing precision qualifiers + if the glsl version is less than 1.30.10 than we will use a shader parser which omits + all precision qualifiers from the shader source , otherwise we will use a shader parser + which set the default precisions to be the same as the default precisions of GLSL ES + */ +#if 0 + if(ver < Version(1,30,10)){ + parseOmitPrecision(); + } else { + parseExtendDefaultPrecision(); + } +#else + //XXX: Until proved otherwise, glsl doesn't know/use those precision macros, so we omit then + parseOmitPrecision(); +#endif + parseLineNumbers(); + parseOriginalSrc(); +} +const GLchar** ShaderParser::parsedLines() { + m_parsedLines = (GLchar*)m_parsedSrc.c_str(); + return const_cast<const GLchar**> (&m_parsedLines); +}; + +const char* ShaderParser::getOriginalSrc(){ + return m_originalSrc; +} + +void ShaderParser::parseLineNumbers() +{ + m_parsedSrc += "#line 1\n"; +} + +void ShaderParser::parseOriginalSrc() { + m_parsedSrc+=m_src; +} + +void ShaderParser::parseGLSLversion() { + + // + // find in shader the #version token if exist. + // That token should be the first non-comment or blank token + // + const char *src = m_src.c_str(); + const int minGLSLVersion = 120; + int glslVersion = minGLSLVersion; + enum { + PARSE_NONE, + PARSE_IN_C_COMMENT, + PARSE_IN_LINE_COMMENT + } parseState = PARSE_NONE; + const char *c = src; + + while( c && *c != '\0') { + if (parseState == PARSE_IN_C_COMMENT) { + if (*c == '*' && *(c+1) == '/') { + parseState = PARSE_NONE; + c += 2; + } + else c++; + } + else if (parseState == PARSE_IN_LINE_COMMENT) { + if (*c == '\n') { + parseState = PARSE_NONE; + } + c++; + } + else if (*c == '/' && *(c+1) == '/') { + parseState = PARSE_IN_LINE_COMMENT; + c += 2; + } + else if (*c == '/' && *(c+1) == '*') { + parseState = PARSE_IN_C_COMMENT; + c += 2; + } + else if (*c == ' ' || *c == '\t' || *c == '\r' || *c == '\n') { + c++; + } + else { + // + // We have reached the first non-blank character outside + // a comment, this must be a #version token or else #version + // token does not exist in this shader source. + // + if (!strncmp(c,"#version",8)) { + int ver; + if (sscanf(c+8,"%d",&ver) == 1) { + // + // parsed version string correctly, blank out the + // version token from the source, we will add it later at + // the begining of the shader. + // + char *cc = (char *)c; + for (int i=0; i<8; i++,cc++) *cc = ' '; + while (*cc < '0' || *cc > '9') { *cc = ' '; cc++; } + while (*cc >= '0' && *cc <= '9') { *cc = ' '; cc++; } + + // Use the version from the source but only if + // it is larger than our minGLSLVersion + if (ver > minGLSLVersion) glslVersion = ver; + } + } + + // + // break the loop, no need to go further on the source. + break; + } + } + + // + // allow to force GLSL version through environment variable + // + const char *forceVersion = getenv("GOOGLE_GLES_FORCE_GLSL_VERSION"); + if (forceVersion) { + int ver; + if (sscanf(forceVersion,"%d",&ver) == 1) { + glslVersion = ver; + } + } + + // + // if glslVersion is defined, add it to the parsed source + // + if (glslVersion > 0) { + char vstr[16]; + sprintf(vstr,"%d",glslVersion); + m_parsedSrc += std::string("#version ") + + std::string(vstr) + + std::string("\n"); + } +} + +void ShaderParser::parseBuiltinConstants() +{ + m_parsedSrc += + "const int _translator_gl_MaxVertexUniformVectors = 256;\n" + "const int _translator_gl_MaxFragmentUniformVectors = 256;\n" + "const int _translator_gl_MaxVaryingVectors = 15;\n" + "#define gl_MaxVertexUniformVectors _translator_gl_MaxVertexUniformVectors\n" + "#define gl_MaxFragmentUniformVectors _translator_gl_MaxFragmentUniformVectors\n" + "#define gl_MaxVaryingVectors _translator_gl_MaxVaryingVectors\n"; + +} + +void ShaderParser::parseOmitPrecision(){ + + //defines we need to add in order to Omit precisions qualifiers + static const GLchar defines[] = { + "#define GLES 1\n" + "#define lowp \n" + "#define mediump \n" + "#define highp \n" + }; + m_parsedSrc+=defines; + + // + // parse the source and blank out precision statements + // which has the following syntax: + // precision {qualifier} {type}; + // where {qualifier} is one of lowp,mediump or hightp + // type is any valid GLES defined type (we do not check that here!) + // NOTE: This is needed in order to workaround driver bug in + // Intel/Linux where the compiler does not get statement like + // "float;", otherwise we could just define a macro named + // precision to be empty. + // + const char *src = m_src.c_str(); + + enum { + PRECISION, + QUALIFIER, + SEMICOLON + } statementState = PRECISION; + const char *precision = NULL; + const char *delimiter = NULL; + + enum { + PARSE_NONE, + PARSE_IN_C_COMMENT, + PARSE_IN_LINE_COMMENT + } parseState = PARSE_NONE; + const char *c = src; + const char *t = NULL; + + #define IS_DELIMITER(c) ( (c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n' ) + #define IS_TOKEN_START(c) ( ((c) >= 'a' && (c) <='z') || ((c) >= 'A' && (c) <= 'Z') ) + #define IS_TOKEN_DELIMITER(c) ( IS_DELIMITER(c) || (c) == ';' ) + + while( c && *c != '\0') { + if (parseState == PARSE_IN_C_COMMENT) { + if (*c == '*' && *(c+1) == '/') { + parseState = PARSE_NONE; + c += 2; + } + else c++; + } + else if (parseState == PARSE_IN_LINE_COMMENT) { + if (*c == '\n') { + parseState = PARSE_NONE; + } + c++; + } + else if (*c == '/' && *(c+1) == '/') { + parseState = PARSE_IN_LINE_COMMENT; + c += 2; + } + else if (*c == '/' && *(c+1) == '*') { + parseState = PARSE_IN_C_COMMENT; + c += 2; + } + else if (t && IS_TOKEN_DELIMITER(*c)) { + int tokenLen = c - t; + switch (statementState) { + case PRECISION: + if (tokenLen == 9 && !strncmp(t,"precision",9)) { + statementState = QUALIFIER; + precision = t; + } + break; + case QUALIFIER: + if ((tokenLen == 4 && !strncmp(t,"lowp",4)) || + (tokenLen == 7 && !strncmp(t,"mediump",7)) || + (tokenLen == 5 && !strncmp(t,"highp",5))) { + statementState = SEMICOLON; + } + else { + statementState = PRECISION; + } + break; + case SEMICOLON: + if (*c == ';') { + for (char *r = (char *)precision; r<=c ; ++r) { + *r = ' '; //blank the character + } + } + statementState = PRECISION; //search for the next precision line + break; + default: + break; + } + c++; + t = NULL; + } + else if (IS_DELIMITER(*c)) { + c++; + } + else { + if (!t && IS_TOKEN_START(*c)) { + t = c; + } + c++; + } + } +} + +void ShaderParser::parseExtendDefaultPrecision(){ + + //the precision lines which we need to add to the shader + static const GLchar extend[] = { + "#define GLES 1\n" + "precision lowp sampler2D;\n" + "precision lowp samplerCube;\n" + }; + + m_parsedSrc+=extend; +} + +void ShaderParser::clearParsedSrc(){ + m_parsedSrc.clear(); +} + +GLenum ShaderParser::getType() { + return m_type; +} + +void ShaderParser::setInfoLog(GLchar* infoLog) +{ + delete[] m_infoLog; + m_infoLog = infoLog; +} + +GLchar* ShaderParser::getInfoLog() +{ + return m_infoLog; +} + +ShaderParser::~ShaderParser(){ + clearParsedSrc(); + if (m_originalSrc) + free(m_originalSrc); + delete[] m_infoLog; +} diff --git a/emulator/opengl/host/libs/Translator/GLES_V2/ShaderParser.h b/emulator/opengl/host/libs/Translator/GLES_V2/ShaderParser.h new file mode 100644 index 0000000..7b538c3 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLES_V2/ShaderParser.h @@ -0,0 +1,54 @@ +/* +* Copyright 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef SHADER_PARSER_H +#define SHADER_PARSER_H + +#include "GLESv2Context.h" +#include <string> +#include <GLES2/gl2.h> +#include <GLcommon/objectNameManager.h> + +class ShaderParser:public ObjectData{ +public: + ShaderParser(); + ShaderParser(GLenum type); + void setSrc(const Version& ver,GLsizei count,const GLchar** strings,const GLint* length); + const char* getOriginalSrc(); + const GLchar** parsedLines(); + GLenum getType(); + ~ShaderParser(); + + void setInfoLog(GLchar * infoLog); + GLchar* getInfoLog(); + +private: + void parseOriginalSrc(); + void parseGLSLversion(); + void parseBuiltinConstants(); + void parseOmitPrecision(); + void parseExtendDefaultPrecision(); + void parseLineNumbers(); + void clearParsedSrc(); + + GLenum m_type; + char* m_originalSrc; + std::string m_src; + std::string m_parsedSrc; + GLchar* m_parsedLines; + GLchar* m_infoLog; +}; +#endif diff --git a/emulator/opengl/host/libs/Translator/GLcommon/Android.mk b/emulator/opengl/host/libs/Translator/GLcommon/Android.mk new file mode 100644 index 0000000..1236566 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLcommon/Android.mk @@ -0,0 +1,61 @@ +LOCAL_PATH := $(call my-dir) + +host_common_SRC_FILES := \ + GLDispatch.cpp \ + GLutils.cpp \ + GLEScontext.cpp \ + GLESvalidate.cpp \ + GLESpointer.cpp \ + GLESbuffer.cpp \ + DummyGLfuncs.cpp \ + RangeManip.cpp \ + TextureUtils.cpp \ + PaletteTexture.cpp \ + etc1.cpp \ + objectNameManager.cpp \ + FramebufferData.cpp + +host_GL_COMMON_LINKER_FLAGS := +host_common_LDLIBS := +host_common_LDFLAGS := + +ifeq ($(HOST_OS),linux) +# host_common_LDFLAGS += -Wl,--whole-archive + host_common_LDLIBS += -lGL -ldl + host_common_LDFLAGS += -Wl,-Bsymbolic +endif + +ifeq ($(HOST_OS),windows) + host_common_LDLIBS += -lopengl32 -lgdi32 + host_common_LDFLAGS += -Wl,--add-stdcall-alias +endif + + +### EGL host implementation ######################## + +$(call emugl-begin-host-static-library,libGLcommon) + +$(call emugl-import,libOpenglOsUtils) +translator_path := $(LOCAL_PATH)/.. +LOCAL_SRC_FILES := $(host_common_SRC_FILES) +$(call emugl-export,LDLIBS,$(host_common_LDLIBS)) +$(call emugl-export,LDFLAGS,$(host_common_LDFLAGS)) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)/../include $(EMUGL_PATH)/shared) +$(call emugl-export,STATIC_LIBRARIES, libcutils libutils liblog) + +$(call emugl-end-module) + + +### EGL host implementation, 64-bit ################ + +$(call emugl-begin-host-static-library,lib64GLcommon) + +$(call emugl-import,lib64OpenglOsUtils) +translator_path := $(LOCAL_PATH)/.. +LOCAL_SRC_FILES := $(host_common_SRC_FILES) +$(call emugl-export,LDLIBS,$(host_common_LDLIBS)) +$(call emugl-export,LDFLAGS,$(host_common_LDFLAGS)) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)/../include $(EMUGL_PATH)/shared) +$(call emugl-export,STATIC_LIBRARIES, lib64cutils lib64utils lib64log) + +$(call emugl-end-module) diff --git a/emulator/opengl/host/libs/Translator/GLcommon/DummyGLfuncs.cpp b/emulator/opengl/host/libs/Translator/GLcommon/DummyGLfuncs.cpp new file mode 100644 index 0000000..e4b632d --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLcommon/DummyGLfuncs.cpp @@ -0,0 +1,256 @@ +/* +* Copyright 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "DummyGLfuncs.h" + + void GLAPIENTRY dummy_glActiveTexture ( GLenum texture ){} + void GLAPIENTRY dummy_glBindBuffer (GLenum target, GLuint buffer){} + void GLAPIENTRY dummy_glBindTexture (GLenum target, GLuint texture){} + void GLAPIENTRY dummy_glBlendFunc (GLenum sfactor, GLenum dfactor){} + void GLAPIENTRY dummy_glBlendEquation( GLenum mode ){} + void GLAPIENTRY dummy_glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha){} + void GLAPIENTRY dummy_glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha){} + void GLAPIENTRY dummy_glBufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage){} + void GLAPIENTRY dummy_glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data){} + void GLAPIENTRY dummy_glClear(GLbitfield mask){} + void GLAPIENTRY dummy_glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha){} + void GLAPIENTRY dummy_glClearStencil(GLint s){} + void GLAPIENTRY dummy_glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha){} + void GLAPIENTRY dummy_glCompressedTexImage2D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data ){} + void GLAPIENTRY dummy_glCompressedTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data ){} + void GLAPIENTRY dummy_glCopyTexImage2D(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border){} + void GLAPIENTRY dummy_glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height){} + void GLAPIENTRY dummy_glCullFace(GLenum mode){} + void GLAPIENTRY dummy_glDeleteBuffers(GLsizei n, const GLuint *buffers){} + void GLAPIENTRY dummy_glDeleteTextures(GLsizei n, const GLuint *textures){} + void GLAPIENTRY dummy_glDepthFunc(GLenum func){} + void GLAPIENTRY dummy_glDepthMask(GLboolean flag){} + void GLAPIENTRY dummy_glDepthRange(GLclampd zNear, GLclampd zFar){} + void GLAPIENTRY dummy_glDisable(GLenum cap){} + void GLAPIENTRY dummy_glDrawArrays(GLenum mode, GLint first, GLsizei count){} + void GLAPIENTRY dummy_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices){} + void GLAPIENTRY dummy_glEnable(GLenum cap){} + void GLAPIENTRY dummy_glFinish(void){} + void GLAPIENTRY dummy_glFlush(void){} + void GLAPIENTRY dummy_glFrontFace(GLenum mode){} + void GLAPIENTRY dummy_glGenBuffers(GLsizei n, GLuint *buffers){} + void GLAPIENTRY dummy_glGenTextures(GLsizei n, GLuint *textures){} + void GLAPIENTRY dummy_glGetBooleanv(GLenum pname, GLboolean *params){} + void GLAPIENTRY dummy_glGetBufferParameteriv(GLenum, GLenum, GLint *){} + GLenum GLAPIENTRY dummy_glGetError(void){ return 0;} + void GLAPIENTRY dummy_glGetFloatv(GLenum pname, GLfloat *params){} + void GLAPIENTRY dummy_glGetIntegerv(GLenum pname, GLint *params){} + const GLubyte * GLAPIENTRY dummy_glGetString(GLenum name){ return 0;} + void GLAPIENTRY dummy_glGetTexParameterfv(GLenum target, GLenum pname, GLfloat *params){} + void GLAPIENTRY dummy_glGetTexParameteriv(GLenum target, GLenum pname, GLint *params){} + void GLAPIENTRY dummy_glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params){} + void GLAPIENTRY dummy_glHint(GLenum target, GLenum mode){} + GLboolean GLAPIENTRY dummy_glIsBuffer(GLuint){ return false;} + GLboolean GLAPIENTRY dummy_glIsEnabled(GLenum cap){ return false;} + GLboolean GLAPIENTRY dummy_glIsTexture(GLuint texture){return false;} + void GLAPIENTRY dummy_glLineWidth(GLfloat width){} + void GLAPIENTRY dummy_glPolygonOffset(GLfloat factor, GLfloat units){} + void GLAPIENTRY dummy_glPixelStorei(GLenum pname, GLint param){} + void GLAPIENTRY dummy_glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels){} + void GLAPIENTRY dummy_glSampleCoverage(GLclampf value, GLboolean invert ){} + void GLAPIENTRY dummy_glScissor(GLint x, GLint y, GLsizei width, GLsizei height){} + void GLAPIENTRY dummy_glStencilFunc(GLenum func, GLint ref, GLuint mask){} + void GLAPIENTRY dummy_glStencilMask(GLuint mask){} + void GLAPIENTRY dummy_glStencilOp(GLenum fail, GLenum zfail, GLenum zpass){} + void GLAPIENTRY dummy_glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels){} + void GLAPIENTRY dummy_glTexParameteri(GLenum target, GLenum pname, GLint param){} + void GLAPIENTRY dummy_glTexParameteriv(GLenum target, GLenum pname, const GLint *params){} + void GLAPIENTRY dummy_glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels){} + void GLAPIENTRY dummy_glViewport(GLint x, GLint y, GLsizei width, GLsizei height){} + void GLAPIENTRY dummy_glPushAttrib( GLbitfield mask ){} + void GLAPIENTRY dummy_glPopAttrib( void ){} + void GLAPIENTRY dummy_glPushClientAttrib( GLbitfield mask ){} + void GLAPIENTRY dummy_glPopClientAttrib( void ){} + + /* OpenGL functions which are needed ONLY for implementing GLES 1.1*/ + void GLAPIENTRY dummy_glAlphaFunc(GLenum func, GLclampf ref){} + void GLAPIENTRY dummy_glBegin( GLenum mode ){} + void GLAPIENTRY dummy_glClearDepth(GLclampd depth){} + void GLAPIENTRY dummy_glClientActiveTexture( GLenum texture ){} + void GLAPIENTRY dummy_glClipPlane(GLenum plane, const GLdouble *equation){} + void GLAPIENTRY dummy_glColor4d(GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha){} + void GLAPIENTRY dummy_glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha){} + void GLAPIENTRY dummy_glColor4fv( const GLfloat *v ){} + void GLAPIENTRY dummy_glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha){} + void GLAPIENTRY dummy_glColor4ubv( const GLubyte *v ){} + void GLAPIENTRY dummy_glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer){} + void GLAPIENTRY dummy_glDisableClientState(GLenum array){} + void GLAPIENTRY dummy_glEnableClientState(GLenum array){} + void GLAPIENTRY dummy_glEnd(void){} + void GLAPIENTRY dummy_glFogf(GLenum pname, GLfloat param){} + void GLAPIENTRY dummy_glFogfv(GLenum pname, const GLfloat *params){} + void GLAPIENTRY dummy_glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar){} + void GLAPIENTRY dummy_glGetClipPlane(GLenum plane, GLdouble *equation){} + void GLAPIENTRY dummy_glGetDoublev( GLenum pname, GLdouble *params ){} + void GLAPIENTRY dummy_glGetLightfv(GLenum light, GLenum pname, GLfloat *params){} + void GLAPIENTRY dummy_glGetMaterialfv(GLenum face, GLenum pname, GLfloat *params){} + void GLAPIENTRY dummy_glGetPointerv(GLenum pname, GLvoid* *params){} + void GLAPIENTRY dummy_glGetTexEnvfv(GLenum target, GLenum pname, GLfloat *params){} + void GLAPIENTRY dummy_glGetTexEnviv(GLenum target, GLenum pname, GLint *params){} + void GLAPIENTRY dummy_glLightf(GLenum light, GLenum pname, GLfloat param){} + void GLAPIENTRY dummy_glLightfv(GLenum light, GLenum pname, const GLfloat *params){} + void GLAPIENTRY dummy_glLightModelf(GLenum pname, GLfloat param){} + void GLAPIENTRY dummy_glLightModelfv(GLenum pname, const GLfloat *params){} + void GLAPIENTRY dummy_glLoadIdentity(void){} + void GLAPIENTRY dummy_glLoadMatrixf(const GLfloat *m){} + void GLAPIENTRY dummy_glLogicOp(GLenum opcode){} + void GLAPIENTRY dummy_glMaterialf(GLenum face, GLenum pname, GLfloat param){} + void GLAPIENTRY dummy_glMaterialfv(GLenum face, GLenum pname, const GLfloat *params){} + void GLAPIENTRY dummy_glMultiTexCoord2fv( GLenum target, const GLfloat *v ){} + void GLAPIENTRY dummy_glMultiTexCoord2sv( GLenum target, const GLshort *v ){} + void GLAPIENTRY dummy_glMultiTexCoord3fv( GLenum target, const GLfloat *v ){} + void GLAPIENTRY dummy_glMultiTexCoord3sv( GLenum target, const GLshort *v ){} + void GLAPIENTRY dummy_glMultiTexCoord4f( GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q ){} + void GLAPIENTRY dummy_glMultiTexCoord4fv( GLenum target, const GLfloat *v ){} + void GLAPIENTRY dummy_glMultiTexCoord4sv( GLenum target, const GLshort *v ){} + void GLAPIENTRY dummy_glMultMatrixf(const GLfloat *m){} + void GLAPIENTRY dummy_glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz){} + void GLAPIENTRY dummy_glNormal3fv( const GLfloat *v ){} + void GLAPIENTRY dummy_glNormal3sv(const GLshort *v ){} + void GLAPIENTRY dummy_glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar){} + void GLAPIENTRY dummy_glPointParameterf(GLenum, GLfloat){} + void GLAPIENTRY dummy_glPointParameterfv(GLenum, const GLfloat *){} + void GLAPIENTRY dummy_glPointSize(GLfloat size){} + void GLAPIENTRY dummy_glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z){} + void GLAPIENTRY dummy_glScalef(GLfloat x, GLfloat y, GLfloat z){} + void GLAPIENTRY dummy_glTexEnvf(GLenum target, GLenum pname, GLfloat param){} + void GLAPIENTRY dummy_glTexEnvfv(GLenum target, GLenum pname, const GLfloat *params){} + void GLAPIENTRY dummy_glTexParameterf(GLenum target, GLenum pname, GLfloat param){} + void GLAPIENTRY dummy_glTexParameterfv(GLenum target, GLenum pname, const GLfloat *params){} + void GLAPIENTRY dummy_glMatrixMode(GLenum mode){} + void GLAPIENTRY dummy_glNormalPointer(GLenum type, GLsizei stride, const GLvoid *pointer){} + void GLAPIENTRY dummy_glPopMatrix(void){} + void GLAPIENTRY dummy_glPushMatrix(void){} + void GLAPIENTRY dummy_glShadeModel(GLenum mode){} + void GLAPIENTRY dummy_glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer){} + void GLAPIENTRY dummy_glTexEnvi(GLenum target, GLenum pname, GLint param){} + void GLAPIENTRY dummy_glTexEnviv(GLenum target, GLenum pname, const GLint *params){} + void GLAPIENTRY dummy_glTranslatef(GLfloat x, GLfloat y, GLfloat z){} + void GLAPIENTRY dummy_glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer){} + + /* OpenGL functions which are needed ONLY for implementing GLES 1.1 EXTENSIONS*/ + GLboolean GLAPIENTRY dummy_glIsRenderbufferEXT(GLuint renderbuffer){ return false;} + void GLAPIENTRY dummy_glBindRenderbufferEXT(GLenum target, GLuint renderbuffer){} + void GLAPIENTRY dummy_glDeleteRenderbuffersEXT(GLsizei n, const GLuint *renderbuffers){} + void GLAPIENTRY dummy_glGenRenderbuffersEXT(GLsizei n, GLuint *renderbuffers){} + void GLAPIENTRY dummy_glRenderbufferStorageEXT(GLenum target, GLenum internalformat, GLsizei width, GLsizei height){} + void GLAPIENTRY dummy_glGetRenderbufferParameterivEXT(GLenum target, GLenum pname, GLint *params){} + GLboolean GLAPIENTRY dummy_glIsFramebufferEXT(GLuint framebuffer){ return false;} + void GLAPIENTRY dummy_glBindFramebufferEXT(GLenum target, GLuint framebuffer){} + void GLAPIENTRY dummy_glDeleteFramebuffersEXT(GLsizei n, const GLuint *framebuffers){} + void GLAPIENTRY dummy_glGenFramebuffersEXT(GLsizei n, GLuint *framebuffers){} + GLenum GLAPIENTRY dummy_glCheckFramebufferStatusEXT(GLenum target){ return 0;} + void GLAPIENTRY dummy_glFramebufferTexture1DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level){} + void GLAPIENTRY dummy_glFramebufferTexture2DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level){} + void GLAPIENTRY dummy_glFramebufferTexture3DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset){} + void GLAPIENTRY dummy_glFramebufferRenderbufferEXT(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer){} + void GLAPIENTRY dummy_glGetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment, GLenum pname, GLint *params){} + void GLAPIENTRY dummy_glGenerateMipmapEXT(GLenum target){} + void GLAPIENTRY dummy_glCurrentPaletteMatrixARB(GLint index){} + void GLAPIENTRY dummy_glMatrixIndexuivARB(GLint size, GLuint * indices){} + void GLAPIENTRY dummy_glMatrixIndexPointerARB(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer){} + void GLAPIENTRY dummy_glWeightPointerARB(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer){} + void GLAPIENTRY dummy_glTexGenf(GLenum coord, GLenum pname, GLfloat param ){} + void GLAPIENTRY dummy_glTexGeni(GLenum coord, GLenum pname, GLint param ){} + void GLAPIENTRY dummy_glTexGenf(GLenum coord, GLenum pname, const GLfloat *params ){} + void GLAPIENTRY dummy_glTexGeniv(GLenum coord, GLenum pname, const GLint *params ){} + void GLAPIENTRY dummy_glGetTexGenfv(GLenum coord, GLenum pname, GLfloat *params ){} + void GLAPIENTRY dummy_glGetTexGeniv(GLenum coord, GLenum pname, GLint *params ){} + + /* Loading OpenGL functions which are needed ONLY for implementing GLES 2.0*/ + void GL_APIENTRY dummy_glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha){} + void GL_APIENTRY dummy_glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask){} + void GL_APIENTRY dummy_glStencilMaskSeparate(GLenum face, GLuint mask){} + void GL_APIENTRY dummy_glGenerateMipmap(GLenum target){} + void GL_APIENTRY dummy_glBindFramebuffer(GLenum target, GLuint framebuffer){} + void GL_APIENTRY dummy_glBindRenderbuffer(GLenum target, GLuint renderbuffer){} + void GL_APIENTRY dummy_glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers){} + void GL_APIENTRY dummy_glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers){} + GLboolean GL_APIENTRY dummy_glIsProgram(GLuint program){ return false;} + GLboolean GL_APIENTRY dummy_glIsShader(GLuint shader){ return false;} + void GL_APIENTRY dummy_glVertexAttrib1f(GLuint indx, GLfloat x){} + void GL_APIENTRY dummy_glVertexAttrib1fv(GLuint indx, const GLfloat* values){} + void GL_APIENTRY dummy_glVertexAttrib2f(GLuint indx, GLfloat x, GLfloat y){} + void GL_APIENTRY dummy_glVertexAttrib2fv(GLuint indx, const GLfloat* values){} + void GL_APIENTRY dummy_glVertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z){} + void GL_APIENTRY dummy_glVertexAttrib3fv(GLuint indx, const GLfloat* values){} + void GL_APIENTRY dummy_glVertexAttrib4f(GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w){} + void GL_APIENTRY dummy_glVertexAttrib4fv(GLuint indx, const GLfloat* values){} + void GL_APIENTRY dummy_glVertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr){} + void GL_APIENTRY dummy_glDisableVertexAttribArray(GLuint index){} + void GL_APIENTRY dummy_glEnableVertexAttribArray(GLuint index){} + void GL_APIENTRY dummy_glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params){} + void GL_APIENTRY dummy_glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params){} + void GL_APIENTRY dummy_glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer){} + void GL_APIENTRY dummy_glUniform1f(GLint location, GLfloat x){} + void GL_APIENTRY dummy_glUniform1fv(GLint location, GLsizei count, const GLfloat* v){} + void GL_APIENTRY dummy_glUniform1i(GLint location, GLint x){} + void GL_APIENTRY dummy_glUniform1iv(GLint location, GLsizei count, const GLint* v){} + void GL_APIENTRY dummy_glUniform2f(GLint location, GLfloat x, GLfloat y){} + void GL_APIENTRY dummy_glUniform2fv(GLint location, GLsizei count, const GLfloat* v){} + void GL_APIENTRY dummy_glUniform2i(GLint location, GLint x, GLint y){} + void GL_APIENTRY dummy_glUniform2iv(GLint location, GLsizei count, const GLint* v){} + void GL_APIENTRY dummy_glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z){} + void GL_APIENTRY dummy_glUniform3fv(GLint location, GLsizei count, const GLfloat* v){} + void GL_APIENTRY dummy_glUniform3i(GLint location, GLint x, GLint y, GLint z){} + void GL_APIENTRY dummy_glUniform3iv(GLint location, GLsizei count, const GLint* v){} + void GL_APIENTRY dummy_glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w){} + void GL_APIENTRY dummy_glUniform4fv(GLint location, GLsizei count, const GLfloat* v){} + void GL_APIENTRY dummy_glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w){} + void GL_APIENTRY dummy_glUniform4iv(GLint location, GLsizei count, const GLint* v){} + void GL_APIENTRY dummy_glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value){} + void GL_APIENTRY dummy_glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value){} + void GL_APIENTRY dummy_glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value){} + void GL_APIENTRY dummy_glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params){} + void GL_APIENTRY dummy_glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params){} + GLboolean GL_APIENTRY dummy_glIsFramebuffer(GLuint framebuffer){ return false;} + GLboolean GL_APIENTRY dummy_glIsRenderbuffer(GLuint renderbuffer){ return false;} + GLenum GL_APIENTRY dummy_glCheckFramebufferStatus(GLenum target){ return 0;} + void GL_APIENTRY dummy_glAttachShader(GLuint program, GLuint shader){} + void GL_APIENTRY dummy_glBindAttribLocation(GLuint program, GLuint index, const GLchar* name){} + void GL_APIENTRY dummy_glCompileShader(GLuint shader){} + GLuint GL_APIENTRY dummy_glCreateProgram(void){ return 0;} + GLuint GL_APIENTRY dummy_glCreateShader(GLenum type){ return 0;} + void GL_APIENTRY dummy_glDeleteProgram(GLuint program){} + void GL_APIENTRY dummy_glDeleteShader(GLuint shader){} + void GL_APIENTRY dummy_glDetachShader(GLuint program, GLuint shader){} + void GL_APIENTRY dummy_glLinkProgram(GLuint program){} + void GL_APIENTRY dummy_glUseProgram(GLuint program){} + void GL_APIENTRY dummy_glValidateProgram(GLuint program){} + void GL_APIENTRY dummy_glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name){} + void GL_APIENTRY dummy_glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name){} + void GL_APIENTRY dummy_glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders){} + int GL_APIENTRY dummy_glGetAttribLocation(GLuint program, const GLchar* name){ return 0;} + void GL_APIENTRY dummy_glGetProgramiv(GLuint program, GLenum pname, GLint* params){} + void GL_APIENTRY dummy_glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog){} + void GL_APIENTRY dummy_glGetShaderiv(GLuint shader, GLenum pname, GLint* params){} + void GL_APIENTRY dummy_glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog){} + void GL_APIENTRY dummy_glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision){} + void GL_APIENTRY dummy_glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source){} + void GL_APIENTRY dummy_glGetUniformfv(GLuint program, GLint location, GLfloat* params){} + void GL_APIENTRY dummy_glGetUniformiv(GLuint program, GLint location, GLint* params){} + int GL_APIENTRY dummy_glGetUniformLocation(GLuint program, const GLchar* name){ return 0;} + void GL_APIENTRY dummy_glReleaseShaderCompiler(void){} + void GL_APIENTRY dummy_glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height){} + void GL_APIENTRY dummy_glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length){} + void GL_APIENTRY dummy_glShaderSource(GLuint shader, GLsizei count, const GLchar** string, const GLint* length){} + void GL_APIENTRY dummy_glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer){} + void GL_APIENTRY dummy_glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level){} diff --git a/emulator/opengl/host/libs/Translator/GLcommon/DummyGLfuncs.h b/emulator/opengl/host/libs/Translator/GLcommon/DummyGLfuncs.h new file mode 100644 index 0000000..f72107c --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLcommon/DummyGLfuncs.h @@ -0,0 +1,265 @@ +/* +* Copyright 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef DUMMY_GL_FUNCS_H +#define DUMMY_GL_FUNCS_H + +#include <GLES/gl.h> +#include <GLES2/gl2.h> + +#include <GLcommon/gldefs.h> +#define GLAPIENTRY GL_APIENTRY + + void GLAPIENTRY dummy_glActiveTexture ( GLenum texture ); + void GLAPIENTRY dummy_glBindBuffer (GLenum target, GLuint buffer); + void GLAPIENTRY dummy_glBindTexture (GLenum target, GLuint texture); + void GLAPIENTRY dummy_glBlendFunc (GLenum sfactor, GLenum dfactor); + void GLAPIENTRY dummy_glBlendEquation( GLenum mode ); + void GLAPIENTRY dummy_glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha); + void GLAPIENTRY dummy_glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); + void GLAPIENTRY dummy_glBufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); + void GLAPIENTRY dummy_glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); + void GLAPIENTRY dummy_glClear(GLbitfield mask); + void GLAPIENTRY dummy_glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); + void GLAPIENTRY dummy_glClearStencil(GLint s); + void GLAPIENTRY dummy_glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); + void GLAPIENTRY dummy_glCompressedTexImage2D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data ); + void GLAPIENTRY dummy_glCompressedTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data ); + void GLAPIENTRY dummy_glCopyTexImage2D(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); + void GLAPIENTRY dummy_glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); + void GLAPIENTRY dummy_glCullFace(GLenum mode); + void GLAPIENTRY dummy_glDeleteBuffers(GLsizei n, const GLuint *buffers); + void GLAPIENTRY dummy_glDeleteTextures(GLsizei n, const GLuint *textures); + void GLAPIENTRY dummy_glDepthFunc(GLenum func); + void GLAPIENTRY dummy_glDepthMask(GLboolean flag); + void GLAPIENTRY dummy_glDepthRange(GLclampd zNear, GLclampd zFar); + void GLAPIENTRY dummy_glDisable(GLenum cap); + void GLAPIENTRY dummy_glDrawArrays(GLenum mode, GLint first, GLsizei count); + void GLAPIENTRY dummy_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); + void GLAPIENTRY dummy_glEnable(GLenum cap); + void GLAPIENTRY dummy_glFinish(void); + void GLAPIENTRY dummy_glFlush(void); + void GLAPIENTRY dummy_glFrontFace(GLenum mode); + void GLAPIENTRY dummy_glGenBuffers(GLsizei n, GLuint *buffers); + void GLAPIENTRY dummy_glGenTextures(GLsizei n, GLuint *textures); + void GLAPIENTRY dummy_glGetBooleanv(GLenum pname, GLboolean *params); + void GLAPIENTRY dummy_glGetBufferParameteriv(GLenum, GLenum, GLint *); + GLenum GLAPIENTRY dummy_glGetError(void); + void GLAPIENTRY dummy_glGetFloatv(GLenum pname, GLfloat *params); + void GLAPIENTRY dummy_glGetIntegerv(GLenum pname, GLint *params); + const GLubyte * GLAPIENTRY dummy_glGetString(GLenum name); + void GLAPIENTRY dummy_glGetTexParameterfv(GLenum target, GLenum pname, GLfloat *params); + void GLAPIENTRY dummy_glGetTexParameteriv(GLenum target, GLenum pname, GLint *params); + void GLAPIENTRY dummy_glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params); + void GLAPIENTRY dummy_glHint(GLenum target, GLenum mode); + GLboolean GLAPIENTRY dummy_glIsBuffer(GLuint); + GLboolean GLAPIENTRY dummy_glIsEnabled(GLenum cap); + GLboolean GLAPIENTRY dummy_glIsTexture(GLuint texture); + void GLAPIENTRY dummy_glLineWidth(GLfloat width); + void GLAPIENTRY dummy_glPolygonOffset(GLfloat factor, GLfloat units); + void GLAPIENTRY dummy_glPixelStorei(GLenum pname, GLint param); + void GLAPIENTRY dummy_glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); + void GLAPIENTRY dummy_glSampleCoverage(GLclampf value, GLboolean invert ); + void GLAPIENTRY dummy_glScissor(GLint x, GLint y, GLsizei width, GLsizei height); + void GLAPIENTRY dummy_glStencilFunc(GLenum func, GLint ref, GLuint mask); + void GLAPIENTRY dummy_glStencilMask(GLuint mask); + void GLAPIENTRY dummy_glStencilOp(GLenum fail, GLenum zfail, GLenum zpass); + void GLAPIENTRY dummy_glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); + void GLAPIENTRY dummy_glTexParameteri(GLenum target, GLenum pname, GLint param); + void GLAPIENTRY dummy_glTexParameteriv(GLenum target, GLenum pname, const GLint *params); + void GLAPIENTRY dummy_glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); + void GLAPIENTRY dummy_glViewport(GLint x, GLint y, GLsizei width, GLsizei height); + void GLAPIENTRY dummy_glPushAttrib( GLbitfield mask ); + void GLAPIENTRY dummy_glPopAttrib( void ); + void GLAPIENTRY dummy_glPushClientAttrib( GLbitfield mask ); + void GLAPIENTRY dummy_glPopClientAttrib( void ); + + /* OpenGL functions which are needed ONLY for implementing GLES 1.1*/ + void GLAPIENTRY dummy_glAlphaFunc(GLenum func, GLclampf ref); + void GLAPIENTRY dummy_glBegin( GLenum mode ); + void GLAPIENTRY dummy_glClearDepth(GLclampd depth); + void GLAPIENTRY dummy_glClientActiveTexture( GLenum texture ); + void GLAPIENTRY dummy_glClipPlane(GLenum plane, const GLdouble *equation); + void GLAPIENTRY dummy_glColor4d(GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha); + void GLAPIENTRY dummy_glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); + void GLAPIENTRY dummy_glColor4fv( const GLfloat *v ); + void GLAPIENTRY dummy_glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); + void GLAPIENTRY dummy_glColor4ubv( const GLubyte *v ); + void GLAPIENTRY dummy_glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); + void GLAPIENTRY dummy_glDisableClientState(GLenum array); + void GLAPIENTRY dummy_glEnableClientState(GLenum array); + void GLAPIENTRY dummy_glEnd(void); + void GLAPIENTRY dummy_glFogf(GLenum pname, GLfloat param); + void GLAPIENTRY dummy_glFogfv(GLenum pname, const GLfloat *params); + void GLAPIENTRY dummy_glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); + void GLAPIENTRY dummy_glGetClipPlane(GLenum plane, GLdouble *equation); + void GLAPIENTRY dummy_glGetDoublev( GLenum pname, GLdouble *params ); + void GLAPIENTRY dummy_glGetLightfv(GLenum light, GLenum pname, GLfloat *params); + void GLAPIENTRY dummy_glGetMaterialfv(GLenum face, GLenum pname, GLfloat *params); + void GLAPIENTRY dummy_glGetPointerv(GLenum pname, GLvoid* *params); + void GLAPIENTRY dummy_glGetTexEnvfv(GLenum target, GLenum pname, GLfloat *params); + void GLAPIENTRY dummy_glGetTexEnviv(GLenum target, GLenum pname, GLint *params); + void GLAPIENTRY dummy_glLightf(GLenum light, GLenum pname, GLfloat param); + void GLAPIENTRY dummy_glLightfv(GLenum light, GLenum pname, const GLfloat *params); + void GLAPIENTRY dummy_glLightModelf(GLenum pname, GLfloat param); + void GLAPIENTRY dummy_glLightModelfv(GLenum pname, const GLfloat *params); + void GLAPIENTRY dummy_glLoadIdentity(void); + void GLAPIENTRY dummy_glLoadMatrixf(const GLfloat *m); + void GLAPIENTRY dummy_glLogicOp(GLenum opcode); + void GLAPIENTRY dummy_glMaterialf(GLenum face, GLenum pname, GLfloat param); + void GLAPIENTRY dummy_glMaterialfv(GLenum face, GLenum pname, const GLfloat *params); + void GLAPIENTRY dummy_glMultiTexCoord2fv( GLenum target, const GLfloat *v ); + void GLAPIENTRY dummy_glMultiTexCoord2sv( GLenum target, const GLshort *v ); + void GLAPIENTRY dummy_glMultiTexCoord3fv( GLenum target, const GLfloat *v ); + void GLAPIENTRY dummy_glMultiTexCoord3sv( GLenum target, const GLshort *v ); + void GLAPIENTRY dummy_glMultiTexCoord4f( GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q ); + void GLAPIENTRY dummy_glMultiTexCoord4fv( GLenum target, const GLfloat *v ); + void GLAPIENTRY dummy_glMultiTexCoord4sv( GLenum target, const GLshort *v ); + void GLAPIENTRY dummy_glMultMatrixf(const GLfloat *m); + void GLAPIENTRY dummy_glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz); + void GLAPIENTRY dummy_glNormal3fv( const GLfloat *v ); + void GLAPIENTRY dummy_glNormal3sv(const GLshort *v ); + void GLAPIENTRY dummy_glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); + void GLAPIENTRY dummy_glPointParameterf(GLenum, GLfloat); + void GLAPIENTRY dummy_glPointParameterfv(GLenum, const GLfloat *); + void GLAPIENTRY dummy_glPointSize(GLfloat size); + void GLAPIENTRY dummy_glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z); + void GLAPIENTRY dummy_glScalef(GLfloat x, GLfloat y, GLfloat z); + void GLAPIENTRY dummy_glTexEnvf(GLenum target, GLenum pname, GLfloat param); + void GLAPIENTRY dummy_glTexEnvfv(GLenum target, GLenum pname, const GLfloat *params); + void GLAPIENTRY dummy_glTexParameterf(GLenum target, GLenum pname, GLfloat param); + void GLAPIENTRY dummy_glTexParameterfv(GLenum target, GLenum pname, const GLfloat *params); + void GLAPIENTRY dummy_glMatrixMode(GLenum mode); + void GLAPIENTRY dummy_glNormalPointer(GLenum type, GLsizei stride, const GLvoid *pointer); + void GLAPIENTRY dummy_glPopMatrix(void); + void GLAPIENTRY dummy_glPushMatrix(void); + void GLAPIENTRY dummy_glShadeModel(GLenum mode); + void GLAPIENTRY dummy_glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); + void GLAPIENTRY dummy_glTexEnvi(GLenum target, GLenum pname, GLint param); + void GLAPIENTRY dummy_glTexEnviv(GLenum target, GLenum pname, const GLint *params); + void GLAPIENTRY dummy_glTranslatef(GLfloat x, GLfloat y, GLfloat z); + void GLAPIENTRY dummy_glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); + + /* OpenGL functions which are needed ONLY for implementing GLES 1.1 EXTENSIONS*/ + GLboolean GLAPIENTRY dummy_glIsRenderbufferEXT(GLuint renderbuffer); + void GLAPIENTRY dummy_glBindRenderbufferEXT(GLenum target, GLuint renderbuffer); + void GLAPIENTRY dummy_glDeleteRenderbuffersEXT(GLsizei n, const GLuint *renderbuffers); + void GLAPIENTRY dummy_glGenRenderbuffersEXT(GLsizei n, GLuint *renderbuffers); + void GLAPIENTRY dummy_glRenderbufferStorageEXT(GLenum target, GLenum internalformat, GLsizei width, GLsizei height); + void GLAPIENTRY dummy_glGetRenderbufferParameterivEXT(GLenum target, GLenum pname, GLint *params); + GLboolean GLAPIENTRY dummy_glIsFramebufferEXT(GLuint framebuffer); + void GLAPIENTRY dummy_glBindFramebufferEXT(GLenum target, GLuint framebuffer); + void GLAPIENTRY dummy_glDeleteFramebuffersEXT(GLsizei n, const GLuint *framebuffers); + void GLAPIENTRY dummy_glGenFramebuffersEXT(GLsizei n, GLuint *framebuffers); + GLenum GLAPIENTRY dummy_glCheckFramebufferStatusEXT(GLenum target); + void GLAPIENTRY dummy_glFramebufferTexture1DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); + void GLAPIENTRY dummy_glFramebufferTexture2DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); + void GLAPIENTRY dummy_glFramebufferTexture3DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); + void GLAPIENTRY dummy_glFramebufferRenderbufferEXT(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); + void GLAPIENTRY dummy_glGetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment, GLenum pname, GLint *params); + void GLAPIENTRY dummy_glGenerateMipmapEXT(GLenum target); + void GLAPIENTRY dummy_glCurrentPaletteMatrixARB(GLint index); + void GLAPIENTRY dummy_glMatrixIndexuivARB(GLint size, GLuint * indices); + void GLAPIENTRY dummy_glMatrixIndexPointerARB(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer); + void GLAPIENTRY dummy_glWeightPointerARB(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer); + void GLAPIENTRY dummy_glTexGenf(GLenum coord, GLenum pname, GLfloat param ); + void GLAPIENTRY dummy_glTexGeni(GLenum coord, GLenum pname, GLint param ); + void GLAPIENTRY dummy_glTexGenf(GLenum coord, GLenum pname, const GLfloat *params ); + void GLAPIENTRY dummy_glTexGeniv(GLenum coord, GLenum pname, const GLint *params ); + void GLAPIENTRY dummy_glGetTexGenfv(GLenum coord, GLenum pname, GLfloat *params ); + void GLAPIENTRY dummy_glGetTexGeniv(GLenum coord, GLenum pname, GLint *params ); + + /* Loading OpenGL functions which are needed ONLY for implementing GLES 2.0*/ + void GL_APIENTRY dummy_glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); + void GL_APIENTRY dummy_glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask); + void GL_APIENTRY dummy_glStencilMaskSeparate(GLenum face, GLuint mask); + void GL_APIENTRY dummy_glGenerateMipmap(GLenum target); + void GL_APIENTRY dummy_glBindFramebuffer(GLenum target, GLuint framebuffer); + void GL_APIENTRY dummy_glBindRenderbuffer(GLenum target, GLuint renderbuffer); + void GL_APIENTRY dummy_glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers); + void GL_APIENTRY dummy_glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers); + GLboolean GL_APIENTRY dummy_glIsProgram(GLuint program); + GLboolean GL_APIENTRY dummy_glIsShader(GLuint shader); + void GL_APIENTRY dummy_glVertexAttrib1f(GLuint indx, GLfloat x); + void GL_APIENTRY dummy_glVertexAttrib1fv(GLuint indx, const GLfloat* values); + void GL_APIENTRY dummy_glVertexAttrib2f(GLuint indx, GLfloat x, GLfloat y); + void GL_APIENTRY dummy_glVertexAttrib2fv(GLuint indx, const GLfloat* values); + void GL_APIENTRY dummy_glVertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z); + void GL_APIENTRY dummy_glVertexAttrib3fv(GLuint indx, const GLfloat* values); + void GL_APIENTRY dummy_glVertexAttrib4f(GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w); + void GL_APIENTRY dummy_glVertexAttrib4fv(GLuint indx, const GLfloat* values); + void GL_APIENTRY dummy_glVertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr); + void GL_APIENTRY dummy_glDisableVertexAttribArray(GLuint index); + void GL_APIENTRY dummy_glEnableVertexAttribArray(GLuint index); + void GL_APIENTRY dummy_glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params); + void GL_APIENTRY dummy_glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params); + void GL_APIENTRY dummy_glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer); + void GL_APIENTRY dummy_glUniform1f(GLint location, GLfloat x); + void GL_APIENTRY dummy_glUniform1fv(GLint location, GLsizei count, const GLfloat* v); + void GL_APIENTRY dummy_glUniform1i(GLint location, GLint x); + void GL_APIENTRY dummy_glUniform1iv(GLint location, GLsizei count, const GLint* v); + void GL_APIENTRY dummy_glUniform2f(GLint location, GLfloat x, GLfloat y); + void GL_APIENTRY dummy_glUniform2fv(GLint location, GLsizei count, const GLfloat* v); + void GL_APIENTRY dummy_glUniform2i(GLint location, GLint x, GLint y); + void GL_APIENTRY dummy_glUniform2iv(GLint location, GLsizei count, const GLint* v); + void GL_APIENTRY dummy_glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z); + void GL_APIENTRY dummy_glUniform3fv(GLint location, GLsizei count, const GLfloat* v); + void GL_APIENTRY dummy_glUniform3i(GLint location, GLint x, GLint y, GLint z); + void GL_APIENTRY dummy_glUniform3iv(GLint location, GLsizei count, const GLint* v); + void GL_APIENTRY dummy_glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w); + void GL_APIENTRY dummy_glUniform4fv(GLint location, GLsizei count, const GLfloat* v); + void GL_APIENTRY dummy_glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w); + void GL_APIENTRY dummy_glUniform4iv(GLint location, GLsizei count, const GLint* v); + void GL_APIENTRY dummy_glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); + void GL_APIENTRY dummy_glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); + void GL_APIENTRY dummy_glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); + void GL_APIENTRY dummy_glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params); + void GL_APIENTRY dummy_glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params); + GLboolean GL_APIENTRY dummy_glIsFramebuffer(GLuint framebuffer); + GLboolean GL_APIENTRY dummy_glIsRenderbuffer(GLuint renderbuffer); + GLenum GL_APIENTRY dummy_glCheckFramebufferStatus(GLenum target); + void GL_APIENTRY dummy_glAttachShader(GLuint program, GLuint shader); + void GL_APIENTRY dummy_glBindAttribLocation(GLuint program, GLuint index, const GLchar* name); + void GL_APIENTRY dummy_glCompileShader(GLuint shader); + GLuint GL_APIENTRY dummy_glCreateProgram(void); + GLuint GL_APIENTRY dummy_glCreateShader(GLenum type); + void GL_APIENTRY dummy_glDeleteProgram(GLuint program); + void GL_APIENTRY dummy_glDeleteShader(GLuint shader); + void GL_APIENTRY dummy_glDetachShader(GLuint program, GLuint shader); + void GL_APIENTRY dummy_glLinkProgram(GLuint program); + void GL_APIENTRY dummy_glUseProgram(GLuint program); + void GL_APIENTRY dummy_glValidateProgram(GLuint program); + void GL_APIENTRY dummy_glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name); + void GL_APIENTRY dummy_glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name); + void GL_APIENTRY dummy_glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders); + int GL_APIENTRY dummy_glGetAttribLocation(GLuint program, const GLchar* name); + void GL_APIENTRY dummy_glGetProgramiv(GLuint program, GLenum pname, GLint* params); + void GL_APIENTRY dummy_glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog); + void GL_APIENTRY dummy_glGetShaderiv(GLuint shader, GLenum pname, GLint* params); + void GL_APIENTRY dummy_glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog); + void GL_APIENTRY dummy_glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision); + void GL_APIENTRY dummy_glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source); + void GL_APIENTRY dummy_glGetUniformfv(GLuint program, GLint location, GLfloat* params); + void GL_APIENTRY dummy_glGetUniformiv(GLuint program, GLint location, GLint* params); + int GL_APIENTRY dummy_glGetUniformLocation(GLuint program, const GLchar* name); + void GL_APIENTRY dummy_glReleaseShaderCompiler(void); + void GL_APIENTRY dummy_glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height); + void GL_APIENTRY dummy_glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length); + void GL_APIENTRY dummy_glShaderSource(GLuint shader, GLsizei count, const GLchar** string, const GLint* length); + void GL_APIENTRY dummy_glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); + void GL_APIENTRY dummy_glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); + +#endif diff --git a/emulator/opengl/host/libs/Translator/GLcommon/FramebufferData.cpp b/emulator/opengl/host/libs/Translator/GLcommon/FramebufferData.cpp new file mode 100644 index 0000000..c923bfc --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLcommon/FramebufferData.cpp @@ -0,0 +1,212 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include <GLES/gl.h> +#include <GLES/glext.h> +#include <GLcommon/FramebufferData.h> +#include <GLcommon/GLEScontext.h> + +RenderbufferData::RenderbufferData() : sourceEGLImage(0), + eglImageDetach(NULL), + attachedFB(0), + attachedPoint(0), + eglImageGlobalTexName(0) { +} + +RenderbufferData::~RenderbufferData() { + if (sourceEGLImage && eglImageDetach) (*eglImageDetach)(sourceEGLImage); +} + + +FramebufferData::FramebufferData(GLuint name):m_dirty(false) { + m_fbName = name; + for (int i=0; i<MAX_ATTACH_POINTS; i++) { + m_attachPoints[i].target = 0; + m_attachPoints[i].name = 0; + m_attachPoints[i].obj = ObjectDataPtr(NULL); + m_attachPoints[i].owned = false; + } +} + +FramebufferData::~FramebufferData() { +for (int i=0; i<MAX_ATTACH_POINTS; i++) { + detachObject(i); +} +} + +void FramebufferData::setAttachment(GLenum attachment, + GLenum target, + GLuint name, + ObjectDataPtr obj, + bool takeOwnership) { +int idx = attachmentPointIndex(attachment); + + if (m_attachPoints[idx].target != target || + m_attachPoints[idx].name != name || + m_attachPoints[idx].obj.Ptr() != obj.Ptr() || + m_attachPoints[idx].owned != takeOwnership) { + + detachObject(idx); + + m_attachPoints[idx].target = target; + m_attachPoints[idx].name = name; + m_attachPoints[idx].obj = obj; + m_attachPoints[idx].owned = takeOwnership; + + if (target == GL_RENDERBUFFER_OES && obj.Ptr() != NULL) { + RenderbufferData *rbData = (RenderbufferData *)obj.Ptr(); + rbData->attachedFB = m_fbName; + rbData->attachedPoint = attachment; + } + + m_dirty = true; + } +} + +GLuint FramebufferData::getAttachment(GLenum attachment, + GLenum *outTarget, + ObjectDataPtr *outObj) { + int idx = attachmentPointIndex(attachment); + if (outTarget) *outTarget = m_attachPoints[idx].target; + if (outObj) *outObj = m_attachPoints[idx].obj; + return m_attachPoints[idx].name; +} + +int FramebufferData::attachmentPointIndex(GLenum attachment) +{ + switch(attachment) { + case GL_COLOR_ATTACHMENT0_OES: + return 0; + case GL_DEPTH_ATTACHMENT_OES: + return 1; + case GL_STENCIL_ATTACHMENT_OES: + return 2; + default: + return MAX_ATTACH_POINTS; + } +} + +void FramebufferData::detachObject(int idx) { + if (m_attachPoints[idx].target == GL_RENDERBUFFER_OES && m_attachPoints[idx].obj.Ptr() != NULL) { + RenderbufferData *rbData = (RenderbufferData *)m_attachPoints[idx].obj.Ptr(); + rbData->attachedFB = 0; + rbData->attachedPoint = 0; + } + + if(m_attachPoints[idx].owned) + { + switch(m_attachPoints[idx].target) + { + case GL_RENDERBUFFER_OES: + GLEScontext::dispatcher().glDeleteRenderbuffersEXT(1, &(m_attachPoints[idx].name)); + break; + case GL_TEXTURE_2D: + GLEScontext::dispatcher().glDeleteTextures(1, &(m_attachPoints[idx].name)); + break; + } + } + + m_attachPoints[idx].target = 0; + m_attachPoints[idx].name = 0; + m_attachPoints[idx].obj = ObjectDataPtr(NULL); + m_attachPoints[idx].owned = false; +} + +void FramebufferData::validate(GLEScontext* ctx) +{ + if(!getAttachment(GL_COLOR_ATTACHMENT0_OES, NULL, NULL)) + { + // GLES does not require the framebuffer to have a color attachment. + // OpenGL does. Therefore, if no color is attached, create a dummy + // color texture and attach it. + // This dummy color texture will is owned by the FramebufferObject, + // and will be released by it when its object is detached. + + GLint type = GL_NONE; + GLint name = 0; + + ctx->dispatcher().glGetFramebufferAttachmentParameterivEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT_OES, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &type); + if(type != GL_NONE) + { + ctx->dispatcher().glGetFramebufferAttachmentParameterivEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT_OES, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &name); + } + else + { + ctx->dispatcher().glGetFramebufferAttachmentParameterivEXT(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT_OES, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &type); + if(type != GL_NONE) + { + ctx->dispatcher().glGetFramebufferAttachmentParameterivEXT(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT_OES, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &name); + } + else + { + // No color, depth or stencil attachments - do nothing + return; + } + } + + // Find the existing attachment(s) dimensions + GLint width = 0; + GLint height = 0; + + if(type == GL_RENDERBUFFER) + { + GLint prev; + ctx->dispatcher().glGetIntegerv(GL_RENDERBUFFER_BINDING, &prev); + ctx->dispatcher().glBindRenderbufferEXT(GL_RENDERBUFFER, name); + ctx->dispatcher().glGetRenderbufferParameterivEXT(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &width); + ctx->dispatcher().glGetRenderbufferParameterivEXT(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &height); + ctx->dispatcher().glBindRenderbufferEXT(GL_RENDERBUFFER, prev); + } + else if(type == GL_TEXTURE) + { + GLint prev; + ctx->dispatcher().glGetIntegerv(GL_TEXTURE_BINDING_2D, &prev); + ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, name); + ctx->dispatcher().glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); + ctx->dispatcher().glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); + ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, prev); + } + + // Create the color attachment and attch it + unsigned int tex = ctx->shareGroup()->genGlobalName(TEXTURE); + GLint prev; + ctx->dispatcher().glGetIntegerv(GL_TEXTURE_BINDING_2D, &prev); + ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, tex); + + ctx->dispatcher().glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); + ctx->dispatcher().glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); + ctx->dispatcher().glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); + ctx->dispatcher().glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); + ctx->dispatcher().glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + + ctx->dispatcher().glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, tex, 0); + setAttachment(GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, tex, ObjectDataPtr(NULL), true); + + ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, prev); + } + + if(m_dirty) + { + // This is a workaround for a bug found in several OpenGL + // drivers (e.g. ATI's) - after the framebuffer attachments + // have changed, and before the next draw, unbind and rebind + // the framebuffer to sort things out. + ctx->dispatcher().glBindFramebufferEXT(GL_FRAMEBUFFER,0); + ctx->dispatcher().glBindFramebufferEXT(GL_FRAMEBUFFER,ctx->shareGroup()->getGlobalName(FRAMEBUFFER,m_fbName)); + + m_dirty = false; + } +} + diff --git a/emulator/opengl/host/libs/Translator/GLcommon/GLDispatch.cpp b/emulator/opengl/host/libs/Translator/GLcommon/GLDispatch.cpp new file mode 100644 index 0000000..abed760 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLcommon/GLDispatch.cpp @@ -0,0 +1,537 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include <GLcommon/GLDispatch.h> +#include <stdio.h> +#include <OpenglOsUtils/osDynLibrary.h> + +#ifdef __linux__ +#include <GL/glx.h> +#elif defined(WIN32) +#include <windows.h> +#endif + +#include "DummyGLfuncs.h" + +typedef void (*GL_FUNC_PTR)(); + +static GL_FUNC_PTR getGLFuncAddress(const char *funcName) { + GL_FUNC_PTR ret = NULL; +#ifdef __linux__ + static osUtils::dynLibrary* libGL = osUtils::dynLibrary::open("libGL.so"); + ret = (GL_FUNC_PTR)glXGetProcAddress((const GLubyte*)funcName); +#elif defined(WIN32) + static osUtils::dynLibrary* libGL = osUtils::dynLibrary::open("opengl32"); + ret = (GL_FUNC_PTR)wglGetProcAddress(funcName); +#elif defined(__APPLE__) + static osUtils::dynLibrary* libGL = osUtils::dynLibrary::open("/System/Library/Frameworks/OpenGL.framework/OpenGL"); +#endif + if(!ret && libGL){ + ret = libGL->findSymbol(funcName); + } + return ret; +} + +#define LOAD_GL_FUNC(name) { void * funcAddrs = NULL; \ + if(name == NULL){ \ + funcAddrs = (void *)getGLFuncAddress(#name); \ + if(funcAddrs){ \ + *(void**)(&name) = funcAddrs; \ + } else { \ + fprintf(stderr,"could not load func %s\n",#name); \ + *(void**)(&name) = (void *)dummy_##name; \ + } \ + } \ + } + +#define LOAD_GLEXT_FUNC(name) { void * funcAddrs = NULL; \ + if(name == NULL){ \ + funcAddrs = (void *)getGLFuncAddress(#name); \ + if(funcAddrs) \ + *(void**)(&name) = funcAddrs; \ + } \ + } + +/* initializing static GLDispatch members*/ + +android::Mutex GLDispatch::s_lock; +void (GLAPIENTRY *GLDispatch::glActiveTexture)(GLenum) = NULL; +void (GLAPIENTRY *GLDispatch::glBindBuffer)(GLenum,GLuint) = NULL; +void (GLAPIENTRY *GLDispatch::glBindTexture)(GLenum, GLuint) = NULL; +void (GLAPIENTRY *GLDispatch::glBlendFunc)(GLenum,GLenum) = NULL; +void (GLAPIENTRY *GLDispatch::glBlendEquation)(GLenum) = NULL; +void (GLAPIENTRY *GLDispatch::glBlendEquationSeparate)(GLenum,GLenum) = NULL; +void (GLAPIENTRY *GLDispatch::glBlendFuncSeparate)(GLenum,GLenum,GLenum,GLenum) = NULL; +void (GLAPIENTRY *GLDispatch::glBufferData)(GLenum,GLsizeiptr,const GLvoid *,GLenum) = NULL; +void (GLAPIENTRY *GLDispatch::glBufferSubData)(GLenum,GLintptr,GLsizeiptr,const GLvoid *) = NULL; +void (GLAPIENTRY *GLDispatch::glClear)(GLbitfield) = NULL; +void (GLAPIENTRY *GLDispatch::glClearColor)(GLclampf,GLclampf,GLclampf,GLclampf) = NULL; +void (GLAPIENTRY *GLDispatch::glClearStencil)(GLint) = NULL; +void (GLAPIENTRY *GLDispatch::glColorMask)(GLboolean,GLboolean,GLboolean,GLboolean) = NULL; +void (GLAPIENTRY *GLDispatch::glCompressedTexImage2D)(GLenum,GLint,GLenum,GLsizei,GLsizei,GLint,GLsizei, const GLvoid *) = NULL; +void (GLAPIENTRY *GLDispatch::glCompressedTexSubImage2D)(GLenum,GLint,GLint,GLint,GLsizei,GLsizei,GLenum,GLsizei,const GLvoid *) = NULL; +void (GLAPIENTRY *GLDispatch::glCopyTexImage2D)(GLenum,GLint,GLenum,GLint,GLint,GLsizei,GLsizei,GLint) = NULL; +void (GLAPIENTRY *GLDispatch::glCopyTexSubImage2D)(GLenum,GLint,GLint,GLint,GLint,GLint,GLsizei,GLsizei) = NULL; +void (GLAPIENTRY *GLDispatch::glCullFace)(GLenum) = NULL; +void (GLAPIENTRY *GLDispatch::glDeleteBuffers)(GLsizei,const GLuint *) = NULL; +void (GLAPIENTRY *GLDispatch::glDeleteTextures)(GLsizei,const GLuint *) = NULL; +void (GLAPIENTRY *GLDispatch::glDepthFunc)(GLenum) = NULL; +void (GLAPIENTRY *GLDispatch::glDepthMask)(GLboolean) = NULL; +void (GLAPIENTRY *GLDispatch::glDepthRange)(GLclampd,GLclampd) = NULL; +void (GLAPIENTRY *GLDispatch::glDisable)(GLenum) = NULL; +void (GLAPIENTRY *GLDispatch::glDrawArrays)(GLenum,GLint,GLsizei) = NULL; +void (GLAPIENTRY *GLDispatch::glDrawElements)(GLenum,GLsizei,GLenum,const GLvoid *) = NULL; +void (GLAPIENTRY *GLDispatch::glEnable)(GLenum) = NULL; +void (GLAPIENTRY *GLDispatch::glFinish)() = NULL; +void (GLAPIENTRY *GLDispatch::glFlush)() = NULL; +void (GLAPIENTRY *GLDispatch::glFrontFace)(GLenum) = NULL; +void (GLAPIENTRY *GLDispatch::glGenBuffers)(GLsizei,GLuint *) = NULL; +void (GLAPIENTRY *GLDispatch::glGenTextures)(GLsizei,GLuint *) = NULL; +void (GLAPIENTRY *GLDispatch::glGetBooleanv)(GLenum,GLboolean *) = NULL; +void (GLAPIENTRY *GLDispatch::glGetBufferParameteriv)(GLenum, GLenum, GLint *) = NULL; +GLenum (GLAPIENTRY *GLDispatch::glGetError)() = NULL; +void (GLAPIENTRY *GLDispatch::glGetFloatv)(GLenum,GLfloat *) = NULL; +void (GLAPIENTRY *GLDispatch::glGetIntegerv)(GLenum,GLint *) = NULL; +const GLubyte * (GLAPIENTRY *GLDispatch::glGetString) (GLenum) = NULL; +void (GLAPIENTRY *GLDispatch::glGetTexParameterfv)(GLenum,GLenum,GLfloat *) = NULL; +void (GLAPIENTRY *GLDispatch::glGetTexParameteriv)(GLenum,GLenum,GLint *) = NULL; +void (GLAPIENTRY *GLDispatch::glGetTexLevelParameteriv) (GLenum target, GLint level, GLenum pname, GLint *params) = NULL; +void (GLAPIENTRY *GLDispatch::glHint)(GLenum,GLenum) = NULL; +GLboolean (GLAPIENTRY *GLDispatch::glIsBuffer)(GLuint) = NULL; +GLboolean (GLAPIENTRY *GLDispatch::glIsEnabled)(GLenum) = NULL; +GLboolean (GLAPIENTRY *GLDispatch::glIsTexture)(GLuint) = NULL; +void (GLAPIENTRY *GLDispatch::glLineWidth)(GLfloat) = NULL; +void (GLAPIENTRY *GLDispatch::glPolygonOffset)(GLfloat, GLfloat) = NULL; +void (GLAPIENTRY *GLDispatch::glPixelStorei)(GLenum,GLint) = NULL; +void (GLAPIENTRY *GLDispatch::glReadPixels)(GLint,GLint,GLsizei,GLsizei,GLenum,GLenum,GLvoid *) = NULL; +void (GLAPIENTRY *GLDispatch::glSampleCoverage)(GLclampf,GLboolean) = NULL; +void (GLAPIENTRY *GLDispatch::glScissor)(GLint,GLint,GLsizei,GLsizei) = NULL; +void (GLAPIENTRY *GLDispatch::glStencilFunc)(GLenum,GLint,GLuint) = NULL; +void (GLAPIENTRY *GLDispatch::glStencilMask)(GLuint) = NULL; +void (GLAPIENTRY *GLDispatch::glStencilOp)(GLenum, GLenum,GLenum); +void (GLAPIENTRY *GLDispatch::glTexImage2D)(GLenum,GLint,GLint,GLsizei,GLsizei,GLint,GLenum,GLenum,const GLvoid *) = NULL; +void (GLAPIENTRY *GLDispatch::glTexParameterf)(GLenum,GLenum, GLfloat) = NULL; +void (GLAPIENTRY *GLDispatch::glTexParameterfv)(GLenum,GLenum,const GLfloat *) = NULL; +void (GLAPIENTRY *GLDispatch::glTexParameteri)(GLenum,GLenum,GLint) = NULL; +void (GLAPIENTRY *GLDispatch::glTexParameteriv)(GLenum,GLenum,const GLint *) = NULL; +void (GLAPIENTRY *GLDispatch::glTexSubImage2D)(GLenum,GLint,GLint,GLint,GLsizei,GLsizei,GLenum,GLenum,const GLvoid *) = NULL; +void (GLAPIENTRY *GLDispatch::glViewport)(GLint,GLint,GLsizei,GLsizei) = NULL; +void (GLAPIENTRY *GLDispatch::glPushAttrib) ( GLbitfield mask ) = NULL; +void (GLAPIENTRY *GLDispatch::glPopAttrib) ( void ) = NULL; +void (GLAPIENTRY *GLDispatch::glPushClientAttrib) ( GLbitfield mask ) = NULL; +void (GLAPIENTRY *GLDispatch::glPopClientAttrib) ( void ) = NULL; + +/*GLES 1.1*/ +void (GLAPIENTRY *GLDispatch::glAlphaFunc)(GLenum,GLclampf) = NULL; +void (GLAPIENTRY *GLDispatch::glBegin)(GLenum) = NULL; +void (GLAPIENTRY *GLDispatch::glClearDepth)(GLclampd) = NULL; +void (GLAPIENTRY *GLDispatch::glClientActiveTexture)(GLenum) = NULL; +void (GLAPIENTRY *GLDispatch::glClipPlane)(GLenum,const GLdouble *) = NULL; +void (GLAPIENTRY *GLDispatch::glColor4d)(GLdouble,GLdouble,GLdouble,GLdouble) = NULL; +void (GLAPIENTRY *GLDispatch::glColor4f)(GLfloat,GLfloat,GLfloat,GLfloat) = NULL; +void (GLAPIENTRY *GLDispatch::glColor4fv)(const GLfloat *) = NULL; +void (GLAPIENTRY *GLDispatch::glColor4ub)(GLubyte,GLubyte,GLubyte,GLubyte) = NULL; +void (GLAPIENTRY *GLDispatch::glColor4ubv)(const GLubyte *) = NULL; +void (GLAPIENTRY *GLDispatch::glColorPointer)(GLint,GLenum,GLsizei,const GLvoid *) = NULL; +void (GLAPIENTRY *GLDispatch::glDisableClientState)(GLenum) = NULL; +void (GLAPIENTRY *GLDispatch::glEnableClientState)(GLenum) = NULL; +void (GLAPIENTRY *GLDispatch::glEnd)() = NULL; +void (GLAPIENTRY *GLDispatch::glFogf)(GLenum, GLfloat) = NULL; +void (GLAPIENTRY *GLDispatch::glFogfv)(GLenum,const GLfloat *); +void (GLAPIENTRY *GLDispatch::glFrustum)(GLdouble,GLdouble,GLdouble,GLdouble,GLdouble,GLdouble) = NULL; +void (GLAPIENTRY *GLDispatch::glGetClipPlane)(GLenum,GLdouble *) = NULL; +void (GLAPIENTRY *GLDispatch::glGetDoublev)(GLenum,GLdouble *) = NULL; +void (GLAPIENTRY *GLDispatch::glGetLightfv)(GLenum,GLenum,GLfloat *) = NULL; +void (GLAPIENTRY *GLDispatch::glGetMaterialfv)(GLenum,GLenum,GLfloat *) = NULL; +void (GLAPIENTRY *GLDispatch::glGetPointerv)(GLenum,GLvoid**) = NULL; +void (GLAPIENTRY *GLDispatch::glGetTexEnvfv)(GLenum,GLenum,GLfloat *) = NULL; +void (GLAPIENTRY *GLDispatch::glGetTexEnviv)(GLenum,GLenum,GLint *)= NULL; +void (GLAPIENTRY *GLDispatch::glLightf)(GLenum,GLenum,GLfloat) = NULL; +void (GLAPIENTRY *GLDispatch::glLightfv)(GLenum,GLenum,const GLfloat *) = NULL; +void (GLAPIENTRY *GLDispatch::glLightModelf)(GLenum,GLfloat) = NULL; +void (GLAPIENTRY *GLDispatch::glLightModelfv)(GLenum,const GLfloat *) = NULL; +void (GLAPIENTRY *GLDispatch::glLoadIdentity)() = NULL; +void (GLAPIENTRY *GLDispatch::glLoadMatrixf)(const GLfloat *) = NULL; +void (GLAPIENTRY *GLDispatch::glLogicOp)(GLenum) = NULL; +void (GLAPIENTRY *GLDispatch::glMaterialf)(GLenum,GLenum,GLfloat) = NULL; +void (GLAPIENTRY *GLDispatch::glMaterialfv)(GLenum,GLenum,const GLfloat *); +void (GLAPIENTRY *GLDispatch::glMultiTexCoord2fv)(GLenum, const GLfloat *) = NULL; +void (GLAPIENTRY *GLDispatch::glMultiTexCoord2sv)(GLenum, const GLshort *) = NULL; +void (GLAPIENTRY *GLDispatch::glMultiTexCoord3fv)(GLenum, const GLfloat *) = NULL; +void (GLAPIENTRY *GLDispatch::glMultiTexCoord3sv)(GLenum,const GLshort *) = NULL; +void (GLAPIENTRY *GLDispatch::glMultiTexCoord4f)(GLenum,GLfloat,GLfloat,GLfloat,GLfloat) = NULL; +void (GLAPIENTRY *GLDispatch::glMultiTexCoord4fv)(GLenum,const GLfloat *) = NULL; +void (GLAPIENTRY *GLDispatch::glMultiTexCoord4sv)(GLenum,const GLshort *) = NULL; +void (GLAPIENTRY *GLDispatch::glMultMatrixf)(const GLfloat *) = NULL; +void (GLAPIENTRY *GLDispatch::glNormal3f)(GLfloat,GLfloat,GLfloat) = NULL; +void (GLAPIENTRY *GLDispatch::glNormal3fv)(const GLfloat *) = NULL; +void (GLAPIENTRY *GLDispatch::glNormal3sv)(const GLshort *) = NULL; +void (GLAPIENTRY *GLDispatch::glOrtho)(GLdouble,GLdouble,GLdouble,GLdouble,GLdouble,GLdouble) = NULL; +void (GLAPIENTRY *GLDispatch::glPointParameterf)(GLenum, GLfloat) = NULL; +void (GLAPIENTRY *GLDispatch::glPointParameterfv)(GLenum, const GLfloat *) = NULL; +void (GLAPIENTRY *GLDispatch::glPointSize)(GLfloat) = NULL; +void (GLAPIENTRY *GLDispatch::glRotatef)(GLfloat,GLfloat,GLfloat,GLfloat) = NULL; +void (GLAPIENTRY *GLDispatch::glScalef)(GLfloat,GLfloat,GLfloat) = NULL; +void (GLAPIENTRY *GLDispatch::glTexEnvf)(GLenum,GLenum,GLfloat) = NULL; +void (GLAPIENTRY *GLDispatch::glTexEnvfv)(GLenum,GLenum,const GLfloat *) = NULL; +void (GLAPIENTRY *GLDispatch::glMatrixMode)(GLenum) = NULL; +void (GLAPIENTRY *GLDispatch::glNormalPointer)(GLenum,GLsizei,const GLvoid *) = NULL; +void (GLAPIENTRY *GLDispatch::glPopMatrix)() = NULL; +void (GLAPIENTRY *GLDispatch::glPushMatrix)() = NULL; +void (GLAPIENTRY *GLDispatch::glShadeModel)(GLenum) = NULL; +void (GLAPIENTRY *GLDispatch::glTexCoordPointer)(GLint,GLenum, GLsizei, const GLvoid*) = NULL; +void (GLAPIENTRY *GLDispatch::glTexEnvi)(GLenum ,GLenum,GLint) = NULL; +void (GLAPIENTRY *GLDispatch::glTexEnviv)(GLenum, GLenum, const GLint *) = NULL; +void (GLAPIENTRY *GLDispatch::glTranslatef)(GLfloat,GLfloat, GLfloat) = NULL; +void (GLAPIENTRY *GLDispatch::glVertexPointer)(GLint,GLenum,GLsizei, const GLvoid *) = NULL; + +/* GLES 1.1 EXTENSIONS*/ +GLboolean (GLAPIENTRY *GLDispatch::glIsRenderbufferEXT) (GLuint renderbuffer) = NULL; +void (GLAPIENTRY *GLDispatch::glBindRenderbufferEXT) (GLenum target, GLuint renderbuffer) = NULL; +void (GLAPIENTRY *GLDispatch::glDeleteRenderbuffersEXT) (GLsizei n, const GLuint *renderbuffers) = NULL; +void (GLAPIENTRY *GLDispatch::glGenRenderbuffersEXT) (GLsizei n, GLuint *renderbuffers) = NULL; +void (GLAPIENTRY *GLDispatch::glRenderbufferStorageEXT) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height) = NULL; +void (GLAPIENTRY *GLDispatch::glGetRenderbufferParameterivEXT) (GLenum target, GLenum pname, GLint *params) = NULL; +GLboolean (GLAPIENTRY *GLDispatch::glIsFramebufferEXT) (GLuint framebuffer) = NULL; +void (GLAPIENTRY *GLDispatch::glBindFramebufferEXT) (GLenum target, GLuint framebuffer) = NULL; +void (GLAPIENTRY *GLDispatch::glDeleteFramebuffersEXT) (GLsizei n, const GLuint *framebuffers) = NULL; +void (GLAPIENTRY *GLDispatch::glGenFramebuffersEXT) (GLsizei n, GLuint *framebuffers) = NULL; +GLenum (GLAPIENTRY *GLDispatch::glCheckFramebufferStatusEXT) (GLenum target) = NULL; +void (GLAPIENTRY *GLDispatch::glFramebufferTexture1DEXT) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) = NULL; +void (GLAPIENTRY *GLDispatch::glFramebufferTexture2DEXT) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) = NULL; +void (GLAPIENTRY *GLDispatch::glFramebufferTexture3DEXT) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset) = NULL; +void (GLAPIENTRY *GLDispatch::glFramebufferRenderbufferEXT) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) = NULL; +void (GLAPIENTRY *GLDispatch::glGetFramebufferAttachmentParameterivEXT) (GLenum target, GLenum attachment, GLenum pname, GLint *params) = NULL; +void (GLAPIENTRY *GLDispatch::glGenerateMipmapEXT) (GLenum target) = NULL; +void (GLAPIENTRY *GLDispatch::glCurrentPaletteMatrixARB) (GLint index) = NULL; +void (GLAPIENTRY *GLDispatch::glMatrixIndexuivARB) (GLint size, GLuint * indices) = NULL; +void (GLAPIENTRY *GLDispatch::glMatrixIndexPointerARB) (GLint size, GLenum type, GLsizei stride, const GLvoid* pointer) = NULL; +void (GLAPIENTRY *GLDispatch::glWeightPointerARB) (GLint size, GLenum type, GLsizei stride, const GLvoid* pointer) = NULL; +void (GLAPIENTRY *GLDispatch::glTexGenf) (GLenum coord, GLenum pname, GLfloat param ) = NULL; +void (GLAPIENTRY *GLDispatch::glTexGeni) (GLenum coord, GLenum pname, GLint param ) = NULL; +void (GLAPIENTRY *GLDispatch::glTexGenfv) (GLenum coord, GLenum pname, const GLfloat *params ) = NULL; +void (GLAPIENTRY *GLDispatch::glTexGeniv) (GLenum coord, GLenum pname, const GLint *params ) = NULL; +void (GLAPIENTRY *GLDispatch::glGetTexGenfv) (GLenum coord, GLenum pname, GLfloat *params ) = NULL; +void (GLAPIENTRY *GLDispatch::glGetTexGeniv) (GLenum coord, GLenum pname, GLint *params ) = NULL; + +/* GLES 2.0*/ +void (GL_APIENTRY *GLDispatch::glBlendColor)(GLclampf,GLclampf,GLclampf,GLclampf) = NULL; +void (GL_APIENTRY *GLDispatch::glStencilFuncSeparate)(GLenum,GLenum,GLint,GLuint) = NULL; +void (GL_APIENTRY *GLDispatch::glStencilMaskSeparate)(GLenum,GLuint) = NULL; +GLboolean (GL_APIENTRY *GLDispatch::glIsProgram)(GLuint program) = NULL; +GLboolean (GL_APIENTRY *GLDispatch::glIsShader)(GLuint shader) = NULL; +void (GL_APIENTRY *GLDispatch::glVertexAttrib1f)(GLuint,GLfloat) = NULL; +void (GL_APIENTRY *GLDispatch::glVertexAttrib1fv)(GLuint,const GLfloat*) = NULL; +void (GL_APIENTRY *GLDispatch::glVertexAttrib2f)(GLuint,GLfloat, GLfloat) = NULL; +void (GL_APIENTRY *GLDispatch::glVertexAttrib2fv)(GLuint,const GLfloat*) = NULL; +void (GL_APIENTRY *GLDispatch::glVertexAttrib3f)(GLuint,GLfloat, GLfloat,GLfloat) = NULL; +void (GL_APIENTRY *GLDispatch::glVertexAttrib3fv)(GLuint,const GLfloat*) = NULL; +void (GL_APIENTRY *GLDispatch::glVertexAttrib4f)(GLuint,GLfloat,GLfloat,GLfloat,GLfloat ) = NULL; +void (GL_APIENTRY *GLDispatch::glVertexAttrib4fv)(GLuint,const GLfloat*) = NULL; +void (GL_APIENTRY *GLDispatch::glVertexAttribPointer)(GLuint,GLint,GLenum,GLboolean,GLsizei,const GLvoid*) = NULL; +void (GL_APIENTRY *GLDispatch::glDisableVertexAttribArray)(GLuint) = NULL; +void (GL_APIENTRY *GLDispatch::glEnableVertexAttribArray)(GLuint) = NULL; +void (GL_APIENTRY *GLDispatch::glGetVertexAttribfv)(GLuint,GLenum,GLfloat*) = NULL; +void (GL_APIENTRY *GLDispatch::glGetVertexAttribiv)(GLuint,GLenum,GLint*) = NULL; +void (GL_APIENTRY *GLDispatch::glGetVertexAttribPointerv)(GLuint,GLenum,GLvoid**) = NULL; +void (GL_APIENTRY *GLDispatch::glUniform1f)(GLint,GLfloat) = NULL; +void (GL_APIENTRY *GLDispatch::glUniform1fv)(GLint,GLsizei,const GLfloat*) = NULL; +void (GL_APIENTRY *GLDispatch::glUniform1i)(GLint,GLint) = NULL; +void (GL_APIENTRY *GLDispatch::glUniform1iv)(GLint,GLsizei,const GLint*) = NULL; +void (GL_APIENTRY *GLDispatch::glUniform2f)(GLint,GLfloat,GLfloat) = NULL; +void (GL_APIENTRY *GLDispatch::glUniform2fv)(GLint,GLsizei,const GLfloat*) = NULL; +void (GL_APIENTRY *GLDispatch::glUniform2i)(GLint,GLint,GLint) = NULL; +void (GL_APIENTRY *GLDispatch::glUniform2iv)(GLint ,GLsizei,const GLint*) = NULL; +void (GL_APIENTRY *GLDispatch::glUniform3f)(GLint,GLfloat,GLfloat,GLfloat) = NULL; +void (GL_APIENTRY *GLDispatch::glUniform3fv)(GLint,GLsizei,const GLfloat*) = NULL; +void (GL_APIENTRY *GLDispatch::glUniform3i)(GLint,GLint,GLint,GLint) = NULL; +void (GL_APIENTRY *GLDispatch::glUniform3iv)(GLint,GLsizei,const GLint*) = NULL; +void (GL_APIENTRY *GLDispatch::glUniform4f)(GLint,GLfloat,GLfloat,GLfloat,GLfloat) = NULL; +void (GL_APIENTRY *GLDispatch::glUniform4fv)(GLint,GLsizei,const GLfloat*) = NULL; +void (GL_APIENTRY *GLDispatch::glUniform4i)(GLint,GLint,GLint,GLint,GLint) = NULL; +void (GL_APIENTRY *GLDispatch::glUniform4iv)(GLint,GLsizei,const GLint*) = NULL; +void (GL_APIENTRY *GLDispatch::glUniformMatrix2fv)(GLint,GLsizei,GLboolean,const GLfloat*) = NULL; +void (GL_APIENTRY *GLDispatch::glUniformMatrix3fv)(GLint,GLsizei,GLboolean,const GLfloat*) = NULL; +void (GL_APIENTRY *GLDispatch::glUniformMatrix4fv)(GLint,GLsizei,GLboolean,const GLfloat*) = NULL; +void (GL_APIENTRY *GLDispatch::glAttachShader)(GLuint,GLuint) = NULL; +void (GL_APIENTRY *GLDispatch::glBindAttribLocation)(GLuint,GLuint,const GLchar*) = NULL; +void (GL_APIENTRY *GLDispatch::glCompileShader)(GLuint) = NULL; +GLuint (GL_APIENTRY *GLDispatch::glCreateProgram)() = NULL; +GLuint (GL_APIENTRY *GLDispatch::glCreateShader)(GLenum) = NULL; +void (GL_APIENTRY *GLDispatch::glDeleteProgram)(GLuint) = NULL; +void (GL_APIENTRY *GLDispatch::glDeleteShader)(GLuint) = NULL; +void (GL_APIENTRY *GLDispatch::glDetachShader)(GLuint,GLuint) = NULL; +void (GL_APIENTRY *GLDispatch::glLinkProgram)(GLuint) = NULL; +void (GL_APIENTRY *GLDispatch::glUseProgram)(GLuint) = NULL; +void (GL_APIENTRY *GLDispatch::glValidateProgram)(GLuint) = NULL; +void (GL_APIENTRY *GLDispatch::glGetActiveAttrib)(GLuint,GLuint,GLsizei,GLsizei*,GLint*,GLenum*,GLchar*) = NULL; +void (GL_APIENTRY *GLDispatch::glGetActiveUniform)(GLuint,GLuint,GLsizei,GLsizei*,GLint*,GLenum*,GLchar*) = NULL; +void (GL_APIENTRY *GLDispatch::glGetAttachedShaders)(GLuint,GLsizei,GLsizei*,GLuint*) = NULL; +int (GL_APIENTRY *GLDispatch::glGetAttribLocation)(GLuint,const GLchar*) = NULL; +void (GL_APIENTRY *GLDispatch::glGetProgramiv)(GLuint,GLenum,GLint*) = NULL; +void (GL_APIENTRY *GLDispatch::glGetProgramInfoLog)(GLuint,GLsizei,GLsizei*,GLchar*) = NULL; +void (GL_APIENTRY *GLDispatch::glGetShaderiv)(GLuint,GLenum,GLint*) = NULL; +void (GL_APIENTRY *GLDispatch::glGetShaderInfoLog)(GLuint,GLsizei,GLsizei*,GLchar*) = NULL; +void (GL_APIENTRY *GLDispatch::glGetShaderPrecisionFormat)(GLenum,GLenum,GLint*,GLint*) = NULL; +void (GL_APIENTRY *GLDispatch::glGetShaderSource)(GLuint,GLsizei,GLsizei*,GLchar*) = NULL; +void (GL_APIENTRY *GLDispatch::glGetUniformfv)(GLuint,GLint,GLfloat*) = NULL; +void (GL_APIENTRY *GLDispatch::glGetUniformiv)(GLuint,GLint,GLint*) = NULL; +int (GL_APIENTRY *GLDispatch::glGetUniformLocation)(GLuint,const GLchar*) = NULL; +void (GL_APIENTRY *GLDispatch::glReleaseShaderCompiler)() = NULL; +void (GL_APIENTRY *GLDispatch::glShaderBinary)(GLsizei,const GLuint*,GLenum,const GLvoid*,GLsizei) = NULL; +void (GL_APIENTRY *GLDispatch::glShaderSource)(GLuint,GLsizei,const GLchar**,const GLint*) = NULL; + +GLDispatch::GLDispatch():m_isLoaded(false){}; + + +void GLDispatch::dispatchFuncs(GLESVersion version){ + android::Mutex::Autolock mutex(s_lock); + if(m_isLoaded) + return; + + /* Loading OpenGL functions which are needed for implementing BOTH GLES 1.1 & GLES 2.0*/ + LOAD_GL_FUNC(glActiveTexture); + LOAD_GL_FUNC(glBindBuffer); + LOAD_GL_FUNC(glBindTexture); + LOAD_GL_FUNC(glBlendFunc); + LOAD_GL_FUNC(glBlendEquation); + LOAD_GL_FUNC(glBlendEquationSeparate); + LOAD_GL_FUNC(glBlendFuncSeparate); + LOAD_GL_FUNC(glBufferData); + LOAD_GL_FUNC(glBufferSubData); + LOAD_GL_FUNC(glClear); + LOAD_GL_FUNC(glClearColor); + LOAD_GL_FUNC(glClearDepth); + LOAD_GL_FUNC(glClearStencil); + LOAD_GL_FUNC(glColorMask); + LOAD_GL_FUNC(glCompressedTexImage2D); + LOAD_GL_FUNC(glCompressedTexSubImage2D); + LOAD_GL_FUNC(glCopyTexImage2D); + LOAD_GL_FUNC(glCopyTexSubImage2D); + LOAD_GL_FUNC(glCullFace); + LOAD_GL_FUNC(glDeleteBuffers); + LOAD_GL_FUNC(glDeleteTextures); + LOAD_GL_FUNC(glDepthFunc); + LOAD_GL_FUNC(glDepthMask); + LOAD_GL_FUNC(glDepthRange); + LOAD_GL_FUNC(glDisable); + LOAD_GL_FUNC(glDrawArrays); + LOAD_GL_FUNC(glDrawElements); + LOAD_GL_FUNC(glEnable); + LOAD_GL_FUNC(glFinish); + LOAD_GL_FUNC(glFlush); + LOAD_GL_FUNC(glFrontFace); + LOAD_GL_FUNC(glGenBuffers); + LOAD_GL_FUNC(glGenTextures); + LOAD_GL_FUNC(glGetBooleanv); + LOAD_GL_FUNC(glGetBufferParameteriv); + LOAD_GL_FUNC(glGetError); + LOAD_GL_FUNC(glGetFloatv); + LOAD_GL_FUNC(glGetIntegerv); + LOAD_GL_FUNC(glGetString); + LOAD_GL_FUNC(glTexParameterf); + LOAD_GL_FUNC(glTexParameterfv); + LOAD_GL_FUNC(glGetTexParameterfv); + LOAD_GL_FUNC(glGetTexParameteriv); + LOAD_GL_FUNC(glGetTexLevelParameteriv); + LOAD_GL_FUNC(glHint); + LOAD_GL_FUNC(glIsBuffer); + LOAD_GL_FUNC(glIsEnabled); + LOAD_GL_FUNC(glIsTexture); + LOAD_GL_FUNC(glLineWidth); + LOAD_GL_FUNC(glPolygonOffset); + LOAD_GL_FUNC(glPixelStorei); + LOAD_GL_FUNC(glReadPixels); + LOAD_GL_FUNC(glSampleCoverage); + LOAD_GL_FUNC(glScissor); + LOAD_GL_FUNC(glStencilFunc); + LOAD_GL_FUNC(glStencilMask); + LOAD_GL_FUNC(glStencilOp); + LOAD_GL_FUNC(glTexImage2D); + LOAD_GL_FUNC(glTexParameteri); + LOAD_GL_FUNC(glTexParameteriv); + LOAD_GL_FUNC(glTexSubImage2D); + LOAD_GL_FUNC(glViewport); + LOAD_GL_FUNC(glPushAttrib); + LOAD_GL_FUNC(glPushClientAttrib); + LOAD_GL_FUNC(glPopAttrib); + LOAD_GL_FUNC(glPopClientAttrib); + LOAD_GLEXT_FUNC(glIsRenderbufferEXT); + LOAD_GLEXT_FUNC(glBindRenderbufferEXT); + LOAD_GLEXT_FUNC(glDeleteRenderbuffersEXT); + LOAD_GLEXT_FUNC(glGenRenderbuffersEXT); + LOAD_GLEXT_FUNC(glRenderbufferStorageEXT); + LOAD_GLEXT_FUNC(glGetRenderbufferParameterivEXT); + LOAD_GLEXT_FUNC(glIsFramebufferEXT); + LOAD_GLEXT_FUNC(glBindFramebufferEXT); + LOAD_GLEXT_FUNC(glDeleteFramebuffersEXT); + LOAD_GLEXT_FUNC(glGenFramebuffersEXT); + LOAD_GLEXT_FUNC(glCheckFramebufferStatusEXT); + LOAD_GLEXT_FUNC(glFramebufferTexture1DEXT); + LOAD_GLEXT_FUNC(glFramebufferTexture2DEXT); + LOAD_GLEXT_FUNC(glFramebufferTexture3DEXT); + LOAD_GLEXT_FUNC(glFramebufferRenderbufferEXT); + LOAD_GLEXT_FUNC(glGetFramebufferAttachmentParameterivEXT); + LOAD_GLEXT_FUNC(glGenerateMipmapEXT); + + /* Loading OpenGL functions which are needed ONLY for implementing GLES 1.1*/ + if(version == GLES_1_1){ + LOAD_GL_FUNC(glAlphaFunc); + LOAD_GL_FUNC(glBegin); + LOAD_GL_FUNC(glClientActiveTexture); + LOAD_GL_FUNC(glClipPlane); + LOAD_GL_FUNC(glColor4d); + LOAD_GL_FUNC(glColor4f); + LOAD_GL_FUNC(glColor4fv); + LOAD_GL_FUNC(glColor4ub); + LOAD_GL_FUNC(glColor4ubv); + LOAD_GL_FUNC(glColorPointer); + LOAD_GL_FUNC(glDisableClientState); + LOAD_GL_FUNC(glEnableClientState); + LOAD_GL_FUNC(glEnd); + LOAD_GL_FUNC(glFogf); + LOAD_GL_FUNC(glFogfv); + LOAD_GL_FUNC(glFrustum); + LOAD_GL_FUNC(glGetClipPlane); + LOAD_GL_FUNC(glGetDoublev); + LOAD_GL_FUNC(glGetLightfv); + LOAD_GL_FUNC(glGetMaterialfv); + LOAD_GL_FUNC(glGetPointerv); + LOAD_GL_FUNC(glGetTexEnvfv); + LOAD_GL_FUNC(glGetTexEnviv); + LOAD_GL_FUNC(glLightf); + LOAD_GL_FUNC(glLightfv); + LOAD_GL_FUNC(glLightModelf); + LOAD_GL_FUNC(glLightModelfv); + LOAD_GL_FUNC(glLoadIdentity); + LOAD_GL_FUNC(glLoadMatrixf); + LOAD_GL_FUNC(glLogicOp); + LOAD_GL_FUNC(glMaterialf); + LOAD_GL_FUNC(glMaterialfv); + LOAD_GL_FUNC(glMultiTexCoord2fv); + LOAD_GL_FUNC(glMultiTexCoord2sv); + LOAD_GL_FUNC(glMultiTexCoord3fv); + LOAD_GL_FUNC(glMultiTexCoord3sv); + LOAD_GL_FUNC(glMultiTexCoord4fv); + LOAD_GL_FUNC(glMultiTexCoord4sv); + LOAD_GL_FUNC(glMultiTexCoord4f); + LOAD_GL_FUNC(glMultMatrixf); + LOAD_GL_FUNC(glNormal3f); + LOAD_GL_FUNC(glNormal3fv); + LOAD_GL_FUNC(glNormal3sv); + LOAD_GL_FUNC(glOrtho); + LOAD_GL_FUNC(glPointParameterf); + LOAD_GL_FUNC(glPointParameterfv); + LOAD_GL_FUNC(glPointSize); + LOAD_GL_FUNC(glRotatef); + LOAD_GL_FUNC(glScalef); + LOAD_GL_FUNC(glTexEnvf); + LOAD_GL_FUNC(glTexEnvfv); + LOAD_GL_FUNC(glMatrixMode); + LOAD_GL_FUNC(glNormalPointer); + LOAD_GL_FUNC(glPopMatrix); + LOAD_GL_FUNC(glPushMatrix); + LOAD_GL_FUNC(glShadeModel); + LOAD_GL_FUNC(glTexCoordPointer); + LOAD_GL_FUNC(glTexEnvi); + LOAD_GL_FUNC(glTexEnviv); + LOAD_GL_FUNC(glTranslatef); + LOAD_GL_FUNC(glVertexPointer); + + LOAD_GLEXT_FUNC(glCurrentPaletteMatrixARB); + LOAD_GLEXT_FUNC(glMatrixIndexuivARB); + LOAD_GLEXT_FUNC(glMatrixIndexPointerARB); + LOAD_GLEXT_FUNC(glWeightPointerARB); + LOAD_GLEXT_FUNC(glTexGenf); + LOAD_GLEXT_FUNC(glTexGeni); + LOAD_GLEXT_FUNC(glTexGenfv); + LOAD_GLEXT_FUNC(glTexGeniv); + LOAD_GLEXT_FUNC(glGetTexGenfv); + LOAD_GLEXT_FUNC(glGetTexGeniv); + + } else if (version == GLES_2_0){ + + /* Loading OpenGL functions which are needed ONLY for implementing GLES 2.0*/ + + LOAD_GL_FUNC(glBlendColor); + LOAD_GL_FUNC(glBlendFuncSeparate); + LOAD_GL_FUNC(glStencilFuncSeparate); + LOAD_GL_FUNC(glIsProgram); + LOAD_GL_FUNC(glIsShader); + LOAD_GL_FUNC(glVertexAttrib1f); + LOAD_GL_FUNC(glVertexAttrib1fv); + LOAD_GL_FUNC(glVertexAttrib2f); + LOAD_GL_FUNC(glVertexAttrib2fv); + LOAD_GL_FUNC(glVertexAttrib3f); + LOAD_GL_FUNC(glVertexAttrib3fv); + LOAD_GL_FUNC(glVertexAttrib4f); + LOAD_GL_FUNC(glVertexAttrib4fv); + LOAD_GL_FUNC(glVertexAttribPointer); + LOAD_GL_FUNC(glDisableVertexAttribArray); + LOAD_GL_FUNC(glEnableVertexAttribArray); + LOAD_GL_FUNC(glGetVertexAttribfv); + LOAD_GL_FUNC(glGetVertexAttribiv); + LOAD_GL_FUNC(glGetVertexAttribPointerv); + LOAD_GL_FUNC(glUniform1f); + LOAD_GL_FUNC(glUniform1fv); + LOAD_GL_FUNC(glUniform1i); + LOAD_GL_FUNC(glUniform1iv); + LOAD_GL_FUNC(glUniform2f); + LOAD_GL_FUNC(glUniform2fv); + LOAD_GL_FUNC(glUniform2i); + LOAD_GL_FUNC(glUniform2iv); + LOAD_GL_FUNC(glUniform3f); + LOAD_GL_FUNC(glUniform3fv); + LOAD_GL_FUNC(glUniform3i); + LOAD_GL_FUNC(glUniform3iv); + LOAD_GL_FUNC(glUniform4f); + LOAD_GL_FUNC(glUniform4fv); + LOAD_GL_FUNC(glUniform4i); + LOAD_GL_FUNC(glUniform4iv); + LOAD_GL_FUNC(glUniformMatrix2fv); + LOAD_GL_FUNC(glUniformMatrix3fv); + LOAD_GL_FUNC(glUniformMatrix4fv); + LOAD_GL_FUNC(glAttachShader); + LOAD_GL_FUNC(glBindAttribLocation); + LOAD_GL_FUNC(glCompileShader); + LOAD_GL_FUNC(glCreateProgram); + LOAD_GL_FUNC(glCreateShader); + LOAD_GL_FUNC(glDeleteProgram); + LOAD_GL_FUNC(glDeleteShader); + LOAD_GL_FUNC(glDetachShader); + LOAD_GL_FUNC(glLinkProgram); + LOAD_GL_FUNC(glUseProgram); + LOAD_GL_FUNC(glValidateProgram); + LOAD_GL_FUNC(glGetActiveAttrib); + LOAD_GL_FUNC(glGetActiveUniform); + LOAD_GL_FUNC(glGetAttachedShaders); + LOAD_GL_FUNC(glGetAttribLocation); + LOAD_GL_FUNC(glGetProgramiv); + LOAD_GL_FUNC(glGetProgramInfoLog); + LOAD_GL_FUNC(glGetShaderiv); + LOAD_GL_FUNC(glGetShaderInfoLog); + LOAD_GLEXT_FUNC(glGetShaderPrecisionFormat); + LOAD_GL_FUNC(glGetShaderSource); + LOAD_GL_FUNC(glGetUniformfv); + LOAD_GL_FUNC(glGetUniformiv); + LOAD_GL_FUNC(glGetUniformLocation); + LOAD_GLEXT_FUNC(glReleaseShaderCompiler); + LOAD_GLEXT_FUNC(glShaderBinary); + LOAD_GL_FUNC(glShaderSource); + LOAD_GL_FUNC(glStencilMaskSeparate); + } + m_isLoaded = true; +} diff --git a/emulator/opengl/host/libs/Translator/GLcommon/GLESbuffer.cpp b/emulator/opengl/host/libs/Translator/GLcommon/GLESbuffer.cpp new file mode 100644 index 0000000..5dcdd65 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLcommon/GLESbuffer.cpp @@ -0,0 +1,55 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include <GLcommon/GLESbuffer.h> +#include <string.h> + +bool GLESbuffer::setBuffer(GLuint size,GLuint usage,const GLvoid* data) { + m_size = size; + m_usage = usage; + if(m_data) { + delete [] m_data; + m_data = NULL; + } + m_data = new unsigned char[size]; + if(m_data) { + if(data) { + memcpy(m_data,data,size); + } + m_conversionManager.clear(); + m_conversionManager.addRange(Range(0,m_size)); + return true; + } + return false; +} + +bool GLESbuffer::setSubBuffer(GLint offset,GLuint size,const GLvoid* data) { + if(offset + size > m_size) return false; + memcpy(m_data+offset,data,size); + m_conversionManager.addRange(Range(offset,size)); + m_conversionManager.merge(); + return true; +} + +void GLESbuffer::getConversions(const RangeList& rIn,RangeList& rOut) { + m_conversionManager.delRanges(rIn,rOut); + rOut.merge(); +} + +GLESbuffer::~GLESbuffer() { + if(m_data) { + delete [] m_data; + } +} diff --git a/emulator/opengl/host/libs/Translator/GLcommon/GLEScontext.cpp b/emulator/opengl/host/libs/Translator/GLcommon/GLEScontext.cpp new file mode 100644 index 0000000..cff639e --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLcommon/GLEScontext.cpp @@ -0,0 +1,716 @@ +/* +* Copyright 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include <GLcommon/GLEScontext.h> +#include <GLcommon/GLconversion_macros.h> +#include <GLcommon/GLESmacros.h> +#include <GLES/gl.h> +#include <GLES/glext.h> +#include <GLcommon/GLESvalidate.h> +#include <GLcommon/TextureUtils.h> +#include <GLcommon/FramebufferData.h> +#include <strings.h> + +//decleration +static void convertFixedDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize); +static void convertFixedIndirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,GLsizei count,GLenum indices_type,const GLvoid* indices,unsigned int strideOut,int attribSize); +static void convertByteDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize); +static void convertByteIndirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,GLsizei count,GLenum indices_type,const GLvoid* indices,unsigned int strideOut,int attribSize); + +GLESConversionArrays::~GLESConversionArrays() { + for(std::map<GLenum,ArrayData>::iterator it = m_arrays.begin(); it != m_arrays.end();it++) { + if((*it).second.allocated){ + if((*it).second.type == GL_FLOAT){ + GLfloat* p = (GLfloat *)((*it).second.data); + if(p) delete[] p; + } else if((*it).second.type == GL_SHORT){ + GLshort* p = (GLshort *)((*it).second.data); + if(p) delete[] p; + } + } + } +} + +void GLESConversionArrays::allocArr(unsigned int size,GLenum type){ + if(type == GL_FIXED){ + m_arrays[m_current].data = new GLfloat[size]; + m_arrays[m_current].type = GL_FLOAT; + } else if(type == GL_BYTE){ + m_arrays[m_current].data = new GLshort[size]; + m_arrays[m_current].type = GL_SHORT; + } + m_arrays[m_current].stride = 0; + m_arrays[m_current].allocated = true; +} + +void GLESConversionArrays::setArr(void* data,unsigned int stride,GLenum type){ + m_arrays[m_current].type = type; + m_arrays[m_current].data = data; + m_arrays[m_current].stride = stride; + m_arrays[m_current].allocated = false; +} + +void* GLESConversionArrays::getCurrentData(){ + return m_arrays[m_current].data; +} + +ArrayData& GLESConversionArrays::getCurrentArray(){ + return m_arrays[m_current]; +} + +unsigned int GLESConversionArrays::getCurrentIndex(){ + return m_current; +} + +ArrayData& GLESConversionArrays::operator[](int i){ + return m_arrays[i]; +} + +void GLESConversionArrays::operator++(){ + m_current++; +} + +GLDispatch GLEScontext::s_glDispatch; +android::Mutex GLEScontext::s_lock; +std::string* GLEScontext::s_glExtensions= NULL; +std::string GLEScontext::s_glRenderer; +GLSupport GLEScontext::s_glSupport; + +Version::Version():m_major(0), + m_minor(0), + m_release(0){}; + +Version::Version(int major,int minor,int release):m_major(major), + m_minor(minor), + m_release(release){}; + +Version::Version(const Version& ver):m_major(ver.m_major), + m_minor(ver.m_minor), + m_release(ver.m_release){} + +Version::Version(const char* versionString){ + m_release = 0; + if((!versionString) || + ((!(sscanf(versionString,"%d.%d" ,&m_major,&m_minor) == 2)) && + (!(sscanf(versionString,"%d.%d.%d",&m_major,&m_minor,&m_release) == 3)))){ + m_major = m_minor = 0; // the version is not in the right format + } +} + +Version& Version::operator=(const Version& ver){ + m_major = ver.m_major; + m_minor = ver.m_minor; + m_release = ver.m_release; + return *this; +} + +bool Version::operator<(const Version& ver) const{ + if(m_major < ver.m_major) return true; + if(m_major == ver.m_major){ + if(m_minor < ver.m_minor) return true; + if(m_minor == ver.m_minor){ + return m_release < ver.m_release; + } + } + return false; +} + +void GLEScontext::init() { + + if (!s_glExtensions) { + initCapsLocked(s_glDispatch.glGetString(GL_EXTENSIONS)); + s_glExtensions = new std::string(""); + } + + if (!m_initialized) { + initExtensionString(); + + int maxTexUnits = getMaxTexUnits(); + m_texState = new textureUnitState[maxTexUnits]; + for (int i=0;i<maxTexUnits;++i) { + for (int j=0;j<NUM_TEXTURE_TARGETS;++j) + { + m_texState[i][j].texture = 0; + m_texState[i][j].enabled = GL_FALSE; + } + } + } +} + +GLEScontext::GLEScontext(): + m_initialized(false) , + m_activeTexture(0) , + m_unpackAlignment(4) , + m_glError(GL_NO_ERROR) , + m_texState(0) , + m_arrayBuffer(0) , + m_elementBuffer(0), + m_renderbuffer(0), + m_framebuffer(0) +{ +}; + +GLenum GLEScontext::getGLerror() { + return m_glError; +} + +void GLEScontext::setGLerror(GLenum err) { + m_glError = err; +} + +void GLEScontext::setActiveTexture(GLenum tex) { + m_activeTexture = tex - GL_TEXTURE0; +} + +GLEScontext::~GLEScontext() { + for(ArraysMap::iterator it = m_map.begin(); it != m_map.end();it++) { + GLESpointer* p = (*it).second; + if(p) { + delete p; + } + } + delete[] m_texState; + m_texState = NULL; +} + +const GLvoid* GLEScontext::setPointer(GLenum arrType,GLint size,GLenum type,GLsizei stride,const GLvoid* data,bool normalize) { + GLuint bufferName = m_arrayBuffer; + if(bufferName) { + unsigned int offset = ToTargetCompatibleHandle((uintptr_t)data); + GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr()); + m_map[arrType]->setBuffer(size,type,stride,vbo,bufferName,offset,normalize); + return static_cast<const unsigned char*>(vbo->getData()) + offset; + } + m_map[arrType]->setArray(size,type,stride,data,normalize); + return data; +} + +void GLEScontext::enableArr(GLenum arr,bool enable) { + m_map[arr]->enable(enable); +} + +bool GLEScontext::isArrEnabled(GLenum arr) { + return m_map[arr]->isEnable(); +} + +const GLESpointer* GLEScontext::getPointer(GLenum arrType) { + if (m_map.find(arrType) != m_map.end()) return m_map[arrType]; + return NULL; +} + +static void convertFixedDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize) { + + for(unsigned int i = 0; i < nBytes;i+=strideOut) { + const GLfixed* fixed_data = (const GLfixed *)dataIn; + //filling attrib + for(int j=0;j<attribSize;j++) { + reinterpret_cast<GLfloat*>(&static_cast<unsigned char*>(dataOut)[i])[j] = X2F(fixed_data[j]); + } + dataIn += strideIn; + } +} + +static void convertFixedIndirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,GLsizei count,GLenum indices_type,const GLvoid* indices,unsigned int strideOut,int attribSize) { + for(int i = 0 ;i < count ;i++) { + unsigned short index = indices_type == GL_UNSIGNED_BYTE? ((GLubyte *)indices)[i]: + ((GLushort *)indices)[i]; + const GLfixed* fixed_data = (GLfixed *)(dataIn + index*strideIn); + GLfloat* float_data = reinterpret_cast<GLfloat*>(static_cast<unsigned char*>(dataOut) + index*strideOut); + + for(int j=0;j<attribSize;j++) { + float_data[j] = X2F(fixed_data[j]); + } + } +} + +static void convertByteDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize) { + + for(unsigned int i = 0; i < nBytes;i+=strideOut) { + const GLbyte* byte_data = (const GLbyte *)dataIn; + //filling attrib + for(int j=0;j<attribSize;j++) { + reinterpret_cast<GLshort*>(&static_cast<unsigned char*>(dataOut)[i])[j] = B2S(byte_data[j]); + } + dataIn += strideIn; + } +} + +static void convertByteIndirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,GLsizei count,GLenum indices_type,const GLvoid* indices,unsigned int strideOut,int attribSize) { + for(int i = 0 ;i < count ;i++) { + unsigned short index = indices_type == GL_UNSIGNED_BYTE? ((GLubyte *)indices)[i]: + ((GLushort *)indices)[i]; + const GLbyte* bytes_data = (GLbyte *)(dataIn + index*strideIn); + GLshort* short_data = reinterpret_cast<GLshort*>(static_cast<unsigned char*>(dataOut) + index*strideOut); + + for(int j=0;j<attribSize;j++) { + short_data[j] = B2S(bytes_data[j]); + } + } +} +static void directToBytesRanges(GLint first,GLsizei count,GLESpointer* p,RangeList& list) { + + int attribSize = p->getSize()*4; //4 is the sizeof GLfixed or GLfloat in bytes + int stride = p->getStride()?p->getStride():attribSize; + int start = p->getBufferOffset()+first*attribSize; + if(!p->getStride()) { + list.addRange(Range(start,count*attribSize)); + } else { + for(int i = 0 ;i < count; i++,start+=stride) { + list.addRange(Range(start,attribSize)); + } + } +} + +static void indirectToBytesRanges(const GLvoid* indices,GLenum indices_type,GLsizei count,GLESpointer* p,RangeList& list) { + + int attribSize = p->getSize() * 4; //4 is the sizeof GLfixed or GLfloat in bytes + int stride = p->getStride()?p->getStride():attribSize; + int start = p->getBufferOffset(); + for(int i=0 ; i < count; i++) { + GLushort index = (indices_type == GL_UNSIGNED_SHORT? + static_cast<const GLushort*>(indices)[i]: + static_cast<const GLubyte*>(indices)[i]); + list.addRange(Range(start+index*stride,attribSize)); + + } +} + +int bytesRangesToIndices(RangeList& ranges,GLESpointer* p,GLushort* indices) { + + int attribSize = p->getSize() * 4; //4 is the sizeof GLfixed or GLfloat in bytes + int stride = p->getStride()?p->getStride():attribSize; + int offset = p->getBufferOffset(); + + int n = 0; + for(int i=0;i<ranges.size();i++) { + int startIndex = (ranges[i].getStart() - offset) / stride; + int nElements = ranges[i].getSize()/attribSize; + for(int j=0;j<nElements;j++) { + indices[n++] = startIndex+j; + } + } + return n; +} + +void GLEScontext::convertDirect(GLESConversionArrays& cArrs,GLint first,GLsizei count,GLenum array_id,GLESpointer* p) { + + GLenum type = p->getType(); + int attribSize = p->getSize(); + unsigned int size = attribSize*count + first; + unsigned int bytes = type == GL_FIXED ? sizeof(GLfixed):sizeof(GLbyte); + cArrs.allocArr(size,type); + int stride = p->getStride()?p->getStride():bytes*attribSize; + const char* data = (const char*)p->getArrayData() + (first*stride); + + if(type == GL_FIXED) { + convertFixedDirectLoop(data,stride,cArrs.getCurrentData(),size*sizeof(GLfloat),attribSize*sizeof(GLfloat),attribSize); + } else if(type == GL_BYTE) { + convertByteDirectLoop(data,stride,cArrs.getCurrentData(),size*sizeof(GLshort),attribSize*sizeof(GLshort),attribSize); + } +} + +void GLEScontext::convertDirectVBO(GLESConversionArrays& cArrs,GLint first,GLsizei count,GLenum array_id,GLESpointer* p) { + + RangeList ranges; + RangeList conversions; + GLushort* indices = NULL; + GLenum type = p->getType(); + int attribSize = p->getSize(); + int stride = p->getStride()?p->getStride():sizeof(GLfixed)*attribSize; + unsigned int size = p->getStride()?p->getStride()*count:attribSize*count*sizeof(GLfixed); + char* data = (char*)p->getBufferData() + (first*stride); + + if(p->bufferNeedConversion()) { + directToBytesRanges(first,count,p,ranges); //converting indices range to buffer bytes ranges by offset + p->getBufferConversions(ranges,conversions); // getting from the buffer the relevant ranges that still needs to be converted + + if(conversions.size()) { // there are some elements to convert + indices = new GLushort[count]; + int nIndices = bytesRangesToIndices(conversions,p,indices); //converting bytes ranges by offset to indices in this array + convertFixedIndirectLoop(data,stride,data,nIndices,GL_UNSIGNED_SHORT,indices,stride,attribSize); + } + } + if(indices) delete[] indices; + cArrs.setArr(data,p->getStride(),GL_FLOAT); +} + +int GLEScontext::findMaxIndex(GLsizei count,GLenum type,const GLvoid* indices) { + //finding max index + int max = 0; + if(type == GL_UNSIGNED_BYTE) { + GLubyte* b_indices =(GLubyte *)indices; + for(int i=0;i<count;i++) { + if(b_indices[i] > max) max = b_indices[i]; + } + } else { + GLushort* us_indices =(GLushort *)indices; + for(int i=0;i<count;i++) { + if(us_indices[i] > max) max = us_indices[i]; + } + } + return max; +} + +void GLEScontext::convertIndirect(GLESConversionArrays& cArrs,GLsizei count,GLenum indices_type,const GLvoid* indices,GLenum array_id,GLESpointer* p) { + GLenum type = p->getType(); + int maxElements = findMaxIndex(count,type,indices) + 1; + + int attribSize = p->getSize(); + int size = attribSize * maxElements; + unsigned int bytes = type == GL_FIXED ? sizeof(GLfixed):sizeof(GLbyte); + cArrs.allocArr(size,type); + int stride = p->getStride()?p->getStride():bytes*attribSize; + + const char* data = (const char*)p->getArrayData(); + if(type == GL_FIXED) { + convertFixedIndirectLoop(data,stride,cArrs.getCurrentData(),count,indices_type,indices,attribSize*sizeof(GLfloat),attribSize); + } else if(type == GL_BYTE){ + convertByteIndirectLoop(data,stride,cArrs.getCurrentData(),count,indices_type,indices,attribSize*sizeof(GLshort),attribSize); + } +} + +void GLEScontext::convertIndirectVBO(GLESConversionArrays& cArrs,GLsizei count,GLenum indices_type,const GLvoid* indices,GLenum array_id,GLESpointer* p) { + RangeList ranges; + RangeList conversions; + GLushort* conversionIndices = NULL; + GLenum type = p->getType(); + int attribSize = p->getSize(); + int stride = p->getStride()?p->getStride():sizeof(GLfixed)*attribSize; + char* data = static_cast<char*>(p->getBufferData()); + if(p->bufferNeedConversion()) { + indirectToBytesRanges(indices,indices_type,count,p,ranges); //converting indices range to buffer bytes ranges by offset + p->getBufferConversions(ranges,conversions); // getting from the buffer the relevant ranges that still needs to be converted + if(conversions.size()) { // there are some elements to convert + conversionIndices = new GLushort[count]; + int nIndices = bytesRangesToIndices(conversions,p,conversionIndices); //converting bytes ranges by offset to indices in this array + convertFixedIndirectLoop(data,stride,data,nIndices,GL_UNSIGNED_SHORT,conversionIndices,stride,attribSize); + } + } + if(conversionIndices) delete[] conversionIndices; + cArrs.setArr(data,p->getStride(),GL_FLOAT); +} + + + +void GLEScontext::bindBuffer(GLenum target,GLuint buffer) { + if(target == GL_ARRAY_BUFFER) { + m_arrayBuffer = buffer; + } else { + m_elementBuffer = buffer; + } +} + +void GLEScontext::unbindBuffer(GLuint buffer) { + if(m_arrayBuffer == buffer) + { + m_arrayBuffer = 0; + } + if(m_elementBuffer == buffer) + { + m_elementBuffer = 0; + } +} + +//checks if any buffer is binded to target +bool GLEScontext::isBindedBuffer(GLenum target) { + if(target == GL_ARRAY_BUFFER) { + return m_arrayBuffer != 0; + } else { + return m_elementBuffer != 0; + } +} + +GLuint GLEScontext::getBuffer(GLenum target) { + return target == GL_ARRAY_BUFFER ? m_arrayBuffer:m_elementBuffer; +} + +GLvoid* GLEScontext::getBindedBuffer(GLenum target) { + GLuint bufferName = getBuffer(target); + if(!bufferName) return NULL; + + GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr()); + return vbo->getData(); +} + +void GLEScontext::getBufferSize(GLenum target,GLint* param) { + GLuint bufferName = getBuffer(target); + GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr()); + *param = vbo->getSize(); +} + +void GLEScontext::getBufferUsage(GLenum target,GLint* param) { + GLuint bufferName = getBuffer(target); + GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr()); + *param = vbo->getUsage(); +} + +bool GLEScontext::setBufferData(GLenum target,GLsizeiptr size,const GLvoid* data,GLenum usage) { + GLuint bufferName = getBuffer(target); + if(!bufferName) return false; + GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr()); + return vbo->setBuffer(size,usage,data); +} + +bool GLEScontext::setBufferSubData(GLenum target,GLintptr offset,GLsizeiptr size,const GLvoid* data) { + + GLuint bufferName = getBuffer(target); + if(!bufferName) return false; + GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr()); + return vbo->setSubBuffer(offset,size,data); +} + +const char * GLEScontext::getExtensionString() { + const char * ret; + s_lock.lock(); + if (s_glExtensions) + ret = s_glExtensions->c_str(); + else + ret=""; + s_lock.unlock(); + return ret; +} + +const char * GLEScontext::getRendererString() const { + return s_glRenderer.c_str(); +} + +void GLEScontext::getGlobalLock() { + s_lock.lock(); +} + +void GLEScontext::releaseGlobalLock() { + s_lock.unlock(); +} + + +void GLEScontext::initCapsLocked(const GLubyte * extensionString) +{ + const char* cstring = (const char*)extensionString; + + s_glDispatch.glGetIntegerv(GL_MAX_VERTEX_ATTRIBS,&s_glSupport.maxVertexAttribs); + s_glDispatch.glGetIntegerv(GL_MAX_CLIP_PLANES,&s_glSupport.maxClipPlane); + s_glDispatch.glGetIntegerv(GL_MAX_LIGHTS,&s_glSupport.maxLights); + s_glDispatch.glGetIntegerv(GL_MAX_TEXTURE_SIZE,&s_glSupport.maxTexSize); + s_glDispatch.glGetIntegerv(GL_MAX_TEXTURE_UNITS,&s_glSupport.maxTexUnits); + s_glDispatch.glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS,&s_glSupport.maxTexImageUnits); + const GLubyte* glslVersion = s_glDispatch.glGetString(GL_SHADING_LANGUAGE_VERSION); + s_glSupport.glslVersion = Version((const char*)(glslVersion)); + + if (strstr(cstring,"GL_EXT_bgra ")!=NULL) + s_glSupport.GL_EXT_TEXTURE_FORMAT_BGRA8888 = true; + + if (strstr(cstring,"GL_EXT_framebuffer_object ")!=NULL) + s_glSupport.GL_EXT_FRAMEBUFFER_OBJECT = true; + + if (strstr(cstring,"GL_ARB_vertex_blend ")!=NULL) + s_glSupport.GL_ARB_VERTEX_BLEND = true; + + if (strstr(cstring,"GL_ARB_matrix_palette ")!=NULL) + s_glSupport.GL_ARB_MATRIX_PALETTE = true; + + if (strstr(cstring,"GL_EXT_packed_depth_stencil ")!=NULL ) + s_glSupport.GL_EXT_PACKED_DEPTH_STENCIL = true; + + if (strstr(cstring,"GL_OES_read_format ")!=NULL) + s_glSupport.GL_OES_READ_FORMAT = true; + + if (strstr(cstring,"GL_ARB_half_float_pixel ")!=NULL) + s_glSupport.GL_ARB_HALF_FLOAT_PIXEL = true; + + if (strstr(cstring,"GL_NV_half_float ")!=NULL) + s_glSupport.GL_NV_HALF_FLOAT = true; + + if (strstr(cstring,"GL_ARB_half_float_vertex ")!=NULL) + s_glSupport.GL_ARB_HALF_FLOAT_VERTEX = true; + + if (strstr(cstring,"GL_SGIS_generate_mipmap ")!=NULL) + s_glSupport.GL_SGIS_GENERATE_MIPMAP = true; + + if (strstr(cstring,"GL_ARB_ES2_compatibility ")!=NULL) + s_glSupport.GL_ARB_ES2_COMPATIBILITY = true; + + if (strstr(cstring,"GL_OES_standard_derivatives ")!=NULL) + s_glSupport.GL_OES_STANDARD_DERIVATIVES = true; + +} + +bool GLEScontext::isTextureUnitEnabled(GLenum unit) { + for (int i=0;i<NUM_TEXTURE_TARGETS;++i) { + if (m_texState[unit-GL_TEXTURE0][i].enabled) + return true; + } + return false; +} + +bool GLEScontext::glGetBooleanv(GLenum pname, GLboolean *params) +{ + GLint iParam; + + if(glGetIntegerv(pname, &iParam)) + { + *params = (iParam != 0); + return true; + } + + return false; +} + +bool GLEScontext::glGetFixedv(GLenum pname, GLfixed *params) +{ + bool result = false; + GLint numParams = 1; + + GLint* iParams = new GLint[numParams]; + if (numParams>0 && glGetIntegerv(pname,iParams)) { + while(numParams >= 0) + { + params[numParams] = I2X(iParams[numParams]); + numParams--; + } + result = true; + } + delete [] iParams; + + return result; +} + +bool GLEScontext::glGetFloatv(GLenum pname, GLfloat *params) +{ + bool result = false; + GLint numParams = 1; + + GLint* iParams = new GLint[numParams]; + if (numParams>0 && glGetIntegerv(pname,iParams)) { + while(numParams >= 0) + { + params[numParams] = (GLfloat)iParams[numParams]; + numParams--; + } + result = true; + } + delete [] iParams; + + return result; +} + +bool GLEScontext::glGetIntegerv(GLenum pname, GLint *params) +{ + switch(pname) + { + case GL_ARRAY_BUFFER_BINDING: + *params = m_arrayBuffer; + break; + + case GL_ELEMENT_ARRAY_BUFFER_BINDING: + *params = m_elementBuffer; + break; + + case GL_TEXTURE_BINDING_CUBE_MAP: + *params = m_texState[m_activeTexture][TEXTURE_CUBE_MAP].texture; + break; + + case GL_TEXTURE_BINDING_2D: + *params = m_texState[m_activeTexture][TEXTURE_2D].texture; + break; + + case GL_ACTIVE_TEXTURE: + *params = m_activeTexture+GL_TEXTURE0; + break; + + case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES: + *params = GL_UNSIGNED_BYTE; + break; + + case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES: + *params = GL_RGBA; + break; + default: + return false; + } + + return true; +} + +TextureTarget GLEScontext::GLTextureTargetToLocal(GLenum target) { + TextureTarget value=TEXTURE_2D; + switch (target) { + case GL_TEXTURE_CUBE_MAP: + case GL_TEXTURE_CUBE_MAP_POSITIVE_X: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: + value = TEXTURE_CUBE_MAP; + break; + case GL_TEXTURE_2D: + value = TEXTURE_2D; + break; + } + return value; +} + +unsigned int GLEScontext::getBindedTexture(GLenum target) { + TextureTarget pos = GLTextureTargetToLocal(target); + return m_texState[m_activeTexture][pos].texture; +} + +unsigned int GLEScontext::getBindedTexture(GLenum unit, GLenum target) { + TextureTarget pos = GLTextureTargetToLocal(target); + return m_texState[unit-GL_TEXTURE0][pos].texture; +} + +void GLEScontext::setBindedTexture(GLenum target, unsigned int tex) { + TextureTarget pos = GLTextureTargetToLocal(target); + m_texState[m_activeTexture][pos].texture = tex; +} + +void GLEScontext::setTextureEnabled(GLenum target, GLenum enable) { + TextureTarget pos = GLTextureTargetToLocal(target); + m_texState[m_activeTexture][pos].enabled = enable; +} + +#define INTERNAL_NAME(x) (x +0x100000000ll); + +ObjectLocalName GLEScontext::getDefaultTextureName(GLenum target) { + ObjectLocalName name = 0; + switch (GLTextureTargetToLocal(target)) { + case TEXTURE_2D: + name = INTERNAL_NAME(0); + break; + case TEXTURE_CUBE_MAP: + name = INTERNAL_NAME(1); + break; + default: + name = 0; + break; + } + return name; +} + +void GLEScontext::drawValidate(void) +{ + if(m_framebuffer == 0) + return; + + ObjectDataPtr fbObj = m_shareGroup->getObjectData(FRAMEBUFFER,m_framebuffer); + if (fbObj.Ptr() == NULL) + return; + + FramebufferData *fbData = (FramebufferData *)fbObj.Ptr(); + + fbData->validate(this); +} diff --git a/emulator/opengl/host/libs/Translator/GLcommon/GLESpointer.cpp b/emulator/opengl/host/libs/Translator/GLcommon/GLESpointer.cpp new file mode 100644 index 0000000..372257e --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLcommon/GLESpointer.cpp @@ -0,0 +1,109 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include <GLcommon/GLESpointer.h> +#include <stdlib.h> + +GLESpointer::GLESpointer():m_size(4), + m_type(GL_FLOAT), + m_stride(0), + m_enabled(false), + m_normalize(false), + m_data(NULL), + m_buffer(NULL), + m_bufferName(0), + m_buffOffset(0), + m_isVBO(false){}; + + +GLenum GLESpointer:: getType() const { + return m_type; +} + +GLint GLESpointer::getSize() const { + return m_size; +} + +GLsizei GLESpointer::getStride() const { + return m_stride; +} + +const GLvoid* GLESpointer::getArrayData() const { + return m_data; +} + +GLvoid* GLESpointer::getBufferData() const { + return m_buffer ? static_cast<unsigned char*>(m_buffer->getData()) + m_buffOffset : NULL; +} + +const GLvoid* GLESpointer::getData() const{ + return m_isVBO ? getBufferData():getArrayData(); +} + +void GLESpointer::redirectPointerData(){ + m_data = getBufferData(); +} + +GLuint GLESpointer::getBufferName() const { + return m_bufferName; +} + +unsigned int GLESpointer::getBufferOffset() const { + + return m_buffOffset; +} + +bool GLESpointer::isEnable() const { + return m_enabled; +} + +bool GLESpointer::isNormalize() const { + return m_normalize; +} + +bool GLESpointer::isVBO() const { + return m_isVBO; +} + +void GLESpointer::enable(bool b) { + m_enabled = b; +} + +void GLESpointer::setArray(GLint size,GLenum type,GLsizei stride,const GLvoid* data,bool normalize) { + m_size = size; + m_type = type; + m_stride = stride; + m_data = data; + m_buffer = NULL; + m_bufferName = 0; + m_normalize = normalize; + m_isVBO = false; +} + +void GLESpointer::setBuffer(GLint size,GLenum type,GLsizei stride,GLESbuffer* buf,GLuint bufferName,int offset,bool normalize) { + m_size = size; + m_type = type; + m_stride = stride; + m_data = NULL; + m_buffer = buf; + m_bufferName = bufferName; + m_buffOffset = offset; + m_normalize = normalize; + m_isVBO = true; +} + +void GLESpointer::getBufferConversions(const RangeList& rl,RangeList& rlOut) { + m_buffer->getConversions(rl,rlOut); +} diff --git a/emulator/opengl/host/libs/Translator/GLcommon/GLESvalidate.cpp b/emulator/opengl/host/libs/Translator/GLcommon/GLESvalidate.cpp new file mode 100644 index 0000000..882d95b --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLcommon/GLESvalidate.cpp @@ -0,0 +1,184 @@ +/* +* Copyright 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include <GLcommon/GLESvalidate.h> +#include <GLES/gl.h> +#include <GLES/glext.h> +#include <GLES2/gl2.h> +#include <GLES2/gl2ext.h> +#include <OpenglCodecCommon/ErrorLog.h> + + +bool GLESvalidate::textureEnum(GLenum e,unsigned int maxTex) { + return e >= GL_TEXTURE0 && e <= (GL_TEXTURE0 + maxTex); +} + +bool GLESvalidate::pixelType(GLEScontext * ctx, GLenum type) { + if ((ctx && ctx->getCaps()->GL_EXT_PACKED_DEPTH_STENCIL) && + (type == GL_UNSIGNED_INT_24_8_OES) ) + return true; + + if (ctx && + (ctx->getCaps()->GL_ARB_HALF_FLOAT_PIXEL || ctx->getCaps()->GL_NV_HALF_FLOAT) && + (type == GL_HALF_FLOAT_OES)) + return true; + + switch(type) { + case GL_UNSIGNED_BYTE: + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_FLOAT: + return true; + } + return false; +} + +bool GLESvalidate::pixelOp(GLenum format,GLenum type) { + switch(type) { + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_5_5_5_1: + return format == GL_RGBA; + case GL_UNSIGNED_SHORT_5_6_5: + return format == GL_RGB; + } + return true; +} + +bool GLESvalidate::pixelFrmt(GLEScontext* ctx ,GLenum format) { + if (ctx && ctx->getCaps()->GL_EXT_TEXTURE_FORMAT_BGRA8888 && format == GL_BGRA_EXT) + return true; + if (ctx && ctx->getCaps()->GL_EXT_PACKED_DEPTH_STENCIL && format == GL_DEPTH_STENCIL_OES) + return true; + switch(format) { + case GL_ALPHA: + case GL_RGB: + case GL_RGBA: + case GL_LUMINANCE: + case GL_LUMINANCE_ALPHA: + return true; + } + return false; +} + +bool GLESvalidate::bufferTarget(GLenum target) { + return target == GL_ARRAY_BUFFER || target == GL_ELEMENT_ARRAY_BUFFER; +} + +bool GLESvalidate::bufferParam(GLenum param) { + return (param == GL_BUFFER_SIZE) || (param == GL_BUFFER_USAGE); +} + +bool GLESvalidate::drawMode(GLenum mode) { + switch(mode) { + case GL_POINTS: + case GL_LINE_STRIP: + case GL_LINE_LOOP: + case GL_LINES: + case GL_TRIANGLE_STRIP: + case GL_TRIANGLE_FAN: + case GL_TRIANGLES: + return true; + } + return false; +} + +bool GLESvalidate::drawType(GLenum mode) { + return mode == GL_UNSIGNED_BYTE || + mode == GL_UNSIGNED_SHORT || + mode == GL_UNSIGNED_INT; +} + +bool GLESvalidate::textureTarget(GLenum target) { + return target==GL_TEXTURE_2D || target==GL_TEXTURE_CUBE_MAP; +} + +bool GLESvalidate::textureTargetLimited(GLenum target) { + return target==GL_TEXTURE_2D; +} + +bool GLESvalidate::textureTargetEx(GLenum target) { + switch(target) { + case GL_TEXTURE_CUBE_MAP_POSITIVE_X_OES: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_OES: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_OES: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_OES: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_OES: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_OES: + case GL_TEXTURE_2D: + return true; + } + return false; +} + +bool GLESvalidate::blendEquationMode(GLenum mode){ + return mode == GL_FUNC_ADD || + mode == GL_FUNC_SUBTRACT || + mode == GL_FUNC_REVERSE_SUBTRACT; +} + +bool GLESvalidate::framebufferTarget(GLenum target){ + return target == GL_FRAMEBUFFER; +} + +bool GLESvalidate::framebufferAttachment(GLenum attachment){ + switch(attachment){ + case GL_COLOR_ATTACHMENT0: + case GL_DEPTH_ATTACHMENT: + case GL_STENCIL_ATTACHMENT: + return true; + } + return false; +} + +bool GLESvalidate::framebufferAttachmentParams(GLenum pname){ + switch(pname){ + case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: + case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: + case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: + case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: + return true; + } + return false; +} + +bool GLESvalidate::renderbufferTarget(GLenum target){ + return target == GL_RENDERBUFFER; +} + +bool GLESvalidate::renderbufferParams(GLenum pname){ + switch(pname){ + case GL_RENDERBUFFER_WIDTH: + case GL_RENDERBUFFER_HEIGHT: + case GL_RENDERBUFFER_INTERNAL_FORMAT: + case GL_RENDERBUFFER_RED_SIZE: + case GL_RENDERBUFFER_GREEN_SIZE: + case GL_RENDERBUFFER_BLUE_SIZE: + case GL_RENDERBUFFER_ALPHA_SIZE: + case GL_RENDERBUFFER_DEPTH_SIZE: + case GL_RENDERBUFFER_STENCIL_SIZE: + return true; + } + return false; +} + +bool GLESvalidate::texImgDim(GLsizei width,GLsizei height,int maxTexSize) { + + if( width < 0 || height < 0 || width > maxTexSize || height > maxTexSize) + return false; + return isPowerOf2(width) && isPowerOf2(height); +} + diff --git a/emulator/opengl/host/libs/Translator/GLcommon/GLutils.cpp b/emulator/opengl/host/libs/Translator/GLcommon/GLutils.cpp new file mode 100644 index 0000000..46e292c --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLcommon/GLutils.cpp @@ -0,0 +1,20 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include <GLcommon/GLutils.h> + +bool isPowerOf2(int num) { + return (num & (num -1)) == 0; +} diff --git a/emulator/opengl/host/libs/Translator/GLcommon/PaletteTexture.cpp b/emulator/opengl/host/libs/Translator/GLcommon/PaletteTexture.cpp new file mode 100644 index 0000000..c99ed07 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLcommon/PaletteTexture.cpp @@ -0,0 +1,170 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "GLcommon/PaletteTexture.h" +#include <stdio.h> + + + +struct Color +{ + Color(unsigned char r, unsigned char g,unsigned char b, unsigned char a):red(r),green(g),blue(b),alpha(a){}; + unsigned char red; + unsigned char green; + unsigned char blue; + unsigned char alpha; +}; + +void getPaletteInfo(GLenum internalFormat,unsigned int& indexSizeBits,unsigned int& colorSizeBytes,GLenum& colorFrmt) { + + colorFrmt = GL_RGB; + switch(internalFormat) + { + case GL_PALETTE4_RGB8_OES: + indexSizeBits = 4; + colorSizeBytes = 3; + break; + + case GL_PALETTE4_RGBA8_OES: + indexSizeBits = 4; + colorSizeBytes = 4; + colorFrmt = GL_RGBA; + break; + + case GL_PALETTE4_RGBA4_OES: + case GL_PALETTE4_RGB5_A1_OES: + colorFrmt = GL_RGBA; + /* fall-through */ + case GL_PALETTE4_R5_G6_B5_OES: + indexSizeBits = 4; + colorSizeBytes = 2; + break; + + case GL_PALETTE8_RGB8_OES: + indexSizeBits = 8; + colorSizeBytes = 3; + break; + + case GL_PALETTE8_RGBA8_OES: + indexSizeBits = 8; + colorSizeBytes = 4; + colorFrmt = GL_RGBA; + break; + + case GL_PALETTE8_RGBA4_OES: + case GL_PALETTE8_RGB5_A1_OES: + colorFrmt = GL_RGBA; + /* fall-through */ + case GL_PALETTE8_R5_G6_B5_OES: + indexSizeBits = 8; + colorSizeBytes = 2; + break; + } +} + + +Color paletteColor(const unsigned char* pallete,unsigned int index,GLenum format) +{ + short s; + switch(format) { + //RGB + case GL_PALETTE4_RGB8_OES: + case GL_PALETTE8_RGB8_OES: + return Color(pallete[index],pallete[index+1],pallete[index+2],0); + case GL_PALETTE8_R5_G6_B5_OES: + case GL_PALETTE4_R5_G6_B5_OES: + s = *((short *)(pallete+index)); + return Color((s >> 11)*255/31,((s >> 5) & 0x3f)*255/63 ,(s & 0x1f)*255/31,0); + + //RGBA + case GL_PALETTE4_RGBA8_OES: + case GL_PALETTE8_RGBA8_OES: + return Color(pallete[index],pallete[index+1],pallete[index+2],pallete[index+3]); + case GL_PALETTE4_RGBA4_OES: + case GL_PALETTE8_RGBA4_OES: + s = *((short *)(pallete+index)); + return Color(((s >> 12) & 0xf)*255/15,((s >> 8) & 0xf)*255/15,((s >> 4) & 0xf)*255/15 ,(s & 0xf)*255/15); + case GL_PALETTE4_RGB5_A1_OES: + case GL_PALETTE8_RGB5_A1_OES: + s = *((short *)(pallete+index)); + return Color(((s >> 11) & 0x1f)*255/31,((s >> 6) & 0x1f)*255/31,((s >> 1) & 0x1f)*255/31 ,(s & 0x1) * 255); + default: + return Color(255,255,255,255); + } +} + +unsigned char* uncompressTexture(GLenum internalformat,GLenum& formatOut,GLsizei width,GLsizei height,GLsizei imageSize, const GLvoid* data,GLint level) { + + unsigned int indexSizeBits; //the size of the color index in the pallete + unsigned int colorSizeBytes; //the size of each color cell in the pallete + + getPaletteInfo(internalformat,indexSizeBits,colorSizeBytes,formatOut); + if(!data) + { + return NULL; + } + + const unsigned char* palette = static_cast<const unsigned char *>(data); + + //the pallete positioned in the begininng of the data + // so we jump over it to get to the colos indices in the palette + + int nColors = 2 << (indexSizeBits -1); //2^indexSizeBits + int paletteSizeBytes = nColors*colorSizeBytes; + const unsigned char* imageIndices = palette + paletteSizeBytes; + + //jumping to the the correct mipmap level + for(int i=0;i<level;i++) { + imageIndices+= (width*height*indexSizeBits)/8; + width = width >> 1; + height = height >> 1; + } + + int colorSizeOut = (formatOut == GL_RGB? 3:4); + int nPixels = width*height; + unsigned char* pixelsOut = new unsigned char[nPixels*colorSizeOut]; + if(!pixelsOut) return NULL; + + int leftBytes = ((palette + imageSize) /* the end of data pointer*/ + - imageIndices); + int leftPixels = (leftBytes * 8 )/indexSizeBits; + + int maxIndices = (leftPixels < nPixels) ? leftPixels:nPixels; + + //filling the pixels array + for(int i =0 ; i < maxIndices ; i++) { + int paletteIndex = 0; + int indexOut = i*colorSizeOut; + if(indexSizeBits == 4) { + paletteIndex = (i%2) == 0 ? + imageIndices[i/2] >> 4: //upper bits + imageIndices[i/2] & 0xf; //lower bits + } else { + paletteIndex = imageIndices[i]; + } + + paletteIndex*=colorSizeBytes; + Color c = paletteColor(palette,paletteIndex,internalformat); + + pixelsOut[indexOut] = c.red; + pixelsOut[indexOut+1] = c.green; + pixelsOut[indexOut+2] = c.blue; + if(formatOut == GL_RGBA) { + pixelsOut[indexOut+3] = c.alpha; + } + } + return pixelsOut; +} + diff --git a/emulator/opengl/host/libs/Translator/GLcommon/RangeManip.cpp b/emulator/opengl/host/libs/Translator/GLcommon/RangeManip.cpp new file mode 100644 index 0000000..5ba609b --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLcommon/RangeManip.cpp @@ -0,0 +1,126 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include <GLcommon/RangeManip.h> + + +bool Range::rangeIntersection(const Range& r,Range& rOut) const { + if(m_start > r.getEnd() || r.getStart() > m_end) return false; + int max_start = (m_start > r.getStart())? m_start:r.getStart(); + int min_end = (m_end < r.getEnd())?m_end:r.getEnd(); + int size = min_end - max_start; + if(size) { + rOut.setRange(max_start,min_end-max_start); + return true; + } + return false; +} + +bool Range::rangeUnion(const Range& r,Range& rOut) const { + if(m_start > r.getEnd() || r.getStart() > m_end) return false; + int min_start = (m_start < r.getStart())?m_start:r.getStart(); + int max_end = (m_end > r.getEnd())?m_end:r.getEnd(); + int size = max_end - min_start; + if(size) { + rOut.setRange(min_start,max_end-min_start); + return false; + } + return false; +} + +void RangeList::addRange(const Range& r) { + list.push_back(r); +} + +void RangeList::addRanges(const RangeList& rl) { + for(int i =0; i< rl.size();i++) { + addRange(rl.list[i]); + } +} + +void RangeList::delRanges(const RangeList& rl,RangeList& deleted) { + for(int i =0; i< rl.size();i++) { + delRange(rl.list[i],deleted); + } +} + +bool RangeList::empty() const{ + return list.empty(); +} + +int RangeList::size() const{ + return list.size(); +} +void RangeList::clear() { + return list.clear(); +} + +void RangeList::erase(unsigned int i) { + if(i > list.size()) return; + list.erase(list.begin() +i); +} + +void RangeList::delRange(const Range& r,RangeList& deleted) { + if(r.getSize() == 0) return; + + Range intersection; + Range temp; + // compare new rect to each and any of the rects on the list + for (int i=0;i<(int)list.size();i++) { // i must be signed for i-- below + // if there is intersection + if (r.rangeIntersection(list[i],intersection)) { + Range old=list[i]; + // remove old as it is about to be split + erase(i); + i--; + if (intersection!=old) { // otherwise split: + //intersection on right side + if(old.getStart() != intersection.getStart()) { + list.insert(list.begin(),Range(old.getStart(),intersection.getStart() - old.getStart())); + } + + //intersection on left side + if(old.getEnd() != intersection.getEnd()) { + list.insert(list.begin(),Range(intersection.getEnd(),old.getEnd() - intersection.getEnd())); + } + } + deleted.addRange(intersection); + } + } +} + +void RangeList::merge() { + if(list.empty()) return; + + Range temp; + bool changed; + + do { // re-run if changed in last run + changed=0; + // run for each combinations of two rects in the list + for (int i=0;i<(((int)list.size())-1) && !changed ;i++) + { + for (int j=i+1;j<(int)list.size() && !changed ;j++) + { + if (list[i].rangeUnion(list[j],temp)) { + // are them exactly one on left of the other + list[i] = temp; + erase(j); + changed=1; + } + } + } + } while (changed); +} diff --git a/emulator/opengl/host/libs/Translator/GLcommon/TextureUtils.cpp b/emulator/opengl/host/libs/Translator/GLcommon/TextureUtils.cpp new file mode 100644 index 0000000..81152f6 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLcommon/TextureUtils.cpp @@ -0,0 +1,109 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include <GLcommon/TextureUtils.h> +#include <GLcommon/GLESmacros.h> +#include <GLcommon/GLDispatch.h> +#include <GLcommon/GLESvalidate.h> +#include <stdio.h> +#include <cmath> + +int getCompressedFormats(int* formats){ + if(formats){ + //Palette + formats[0] = GL_PALETTE4_RGBA8_OES; + formats[1] = GL_PALETTE4_RGBA4_OES; + formats[2] = GL_PALETTE8_RGBA8_OES; + formats[3] = GL_PALETTE8_RGBA4_OES; + formats[4] = GL_PALETTE4_RGB8_OES; + formats[5] = GL_PALETTE8_RGB8_OES; + formats[6] = GL_PALETTE4_RGB5_A1_OES; + formats[7] = GL_PALETTE8_RGB5_A1_OES; + formats[8] = GL_PALETTE4_R5_G6_B5_OES; + formats[9] = GL_PALETTE8_R5_G6_B5_OES; + //ETC + formats[MAX_SUPPORTED_PALETTE] = GL_ETC1_RGB8_OES; + } + return MAX_SUPPORTED_PALETTE + MAX_ETC_SUPPORTED; +} + +void doCompressedTexImage2D(GLEScontext * ctx, GLenum target, GLint level, + GLenum internalformat, GLsizei width, + GLsizei height, GLint border, + GLsizei imageSize, const GLvoid* data, void * funcPtr) +{ + /* XXX: This is just a hack to fix the resolve of glTexImage2D problem + It will be removed when we'll no longer link against ligGL */ + typedef void (GLAPIENTRY *glTexImage2DPtr_t ) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); + glTexImage2DPtr_t glTexImage2DPtr; + glTexImage2DPtr = (glTexImage2DPtr_t)funcPtr; + + switch (internalformat) { + case GL_ETC1_RGB8_OES: + { + GLint format = GL_RGB; + GLint type = GL_UNSIGNED_BYTE; + + GLsizei compressedSize = etc1_get_encoded_data_size(width, height); + SET_ERROR_IF((compressedSize > imageSize), GL_INVALID_VALUE); + + const int32_t align = ctx->getUnpackAlignment()-1; + const int32_t bpr = ((width * 3) + align) & ~align; + const size_t size = bpr * height; + + etc1_byte* pOut = new etc1_byte[size]; + int res = etc1_decode_image((const etc1_byte*)data, pOut, width, height, 3, bpr); + SET_ERROR_IF(res!=0, GL_INVALID_VALUE); + glTexImage2DPtr(target,level,format,width,height,border,format,type,pOut); + delete [] pOut; + } + break; + + case GL_PALETTE4_RGB8_OES: + case GL_PALETTE4_RGBA8_OES: + case GL_PALETTE4_R5_G6_B5_OES: + case GL_PALETTE4_RGBA4_OES: + case GL_PALETTE4_RGB5_A1_OES: + case GL_PALETTE8_RGB8_OES: + case GL_PALETTE8_RGBA8_OES: + case GL_PALETTE8_R5_G6_B5_OES: + case GL_PALETTE8_RGBA4_OES: + case GL_PALETTE8_RGB5_A1_OES: + { + SET_ERROR_IF(level > log2(ctx->getMaxTexSize()) || + border !=0 || level > 0 || + !GLESvalidate::texImgDim(width,height,ctx->getMaxTexSize()+2),GL_INVALID_VALUE) + + int nMipmaps = -level + 1; + GLsizei tmpWidth = width; + GLsizei tmpHeight = height; + + for(int i = 0; i < nMipmaps ; i++) + { + GLenum uncompressedFrmt; + unsigned char* uncompressed = uncompressTexture(internalformat,uncompressedFrmt,width,height,imageSize,data,i); + glTexImage2DPtr(target,i,uncompressedFrmt,tmpWidth,tmpHeight,border,uncompressedFrmt,GL_UNSIGNED_BYTE,uncompressed); + tmpWidth/=2; + tmpHeight/=2; + delete[] uncompressed; + } + } + break; + + default: + SET_ERROR_IF(1, GL_INVALID_ENUM); + break; + } +} diff --git a/emulator/opengl/host/libs/Translator/GLcommon/etc1.cpp b/emulator/opengl/host/libs/Translator/GLcommon/etc1.cpp new file mode 100644 index 0000000..5ed2c3c --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLcommon/etc1.cpp @@ -0,0 +1,670 @@ +// Copyright 2009 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <ETC1/etc1.h> + +#include <string.h> + +/* From http://www.khronos.org/registry/gles/extensions/OES/OES_compressed_ETC1_RGB8_texture.txt + + The number of bits that represent a 4x4 texel block is 64 bits if + <internalformat> is given by ETC1_RGB8_OES. + + The data for a block is a number of bytes, + + {q0, q1, q2, q3, q4, q5, q6, q7} + + where byte q0 is located at the lowest memory address and q7 at + the highest. The 64 bits specifying the block is then represented + by the following 64 bit integer: + + int64bit = 256*(256*(256*(256*(256*(256*(256*q0+q1)+q2)+q3)+q4)+q5)+q6)+q7; + + ETC1_RGB8_OES: + + a) bit layout in bits 63 through 32 if diffbit = 0 + + 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 + ----------------------------------------------- + | base col1 | base col2 | base col1 | base col2 | + | R1 (4bits)| R2 (4bits)| G1 (4bits)| G2 (4bits)| + ----------------------------------------------- + + 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 + --------------------------------------------------- + | base col1 | base col2 | table | table |diff|flip| + | B1 (4bits)| B2 (4bits)| cw 1 | cw 2 |bit |bit | + --------------------------------------------------- + + + b) bit layout in bits 63 through 32 if diffbit = 1 + + 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 + ----------------------------------------------- + | base col1 | dcol 2 | base col1 | dcol 2 | + | R1' (5 bits) | dR2 | G1' (5 bits) | dG2 | + ----------------------------------------------- + + 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 + --------------------------------------------------- + | base col 1 | dcol 2 | table | table |diff|flip| + | B1' (5 bits) | dB2 | cw 1 | cw 2 |bit |bit | + --------------------------------------------------- + + + c) bit layout in bits 31 through 0 (in both cases) + + 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 + ----------------------------------------------- + | most significant pixel index bits | + | p| o| n| m| l| k| j| i| h| g| f| e| d| c| b| a| + ----------------------------------------------- + + 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 + -------------------------------------------------- + | least significant pixel index bits | + | p| o| n| m| l| k| j| i| h| g| f| e| d| c | b | a | + -------------------------------------------------- + + + Add table 3.17.2: Intensity modifier sets for ETC1 compressed textures: + + table codeword modifier table + ------------------ ---------------------- + 0 -8 -2 2 8 + 1 -17 -5 5 17 + 2 -29 -9 9 29 + 3 -42 -13 13 42 + 4 -60 -18 18 60 + 5 -80 -24 24 80 + 6 -106 -33 33 106 + 7 -183 -47 47 183 + + + Add table 3.17.3 Mapping from pixel index values to modifier values for + ETC1 compressed textures: + + pixel index value + --------------- + msb lsb resulting modifier value + ----- ----- ------------------------- + 1 1 -b (large negative value) + 1 0 -a (small negative value) + 0 0 a (small positive value) + 0 1 b (large positive value) + + + */ + +static const int kModifierTable[] = { +/* 0 */2, 8, -2, -8, +/* 1 */5, 17, -5, -17, +/* 2 */9, 29, -9, -29, +/* 3 */13, 42, -13, -42, +/* 4 */18, 60, -18, -60, +/* 5 */24, 80, -24, -80, +/* 6 */33, 106, -33, -106, +/* 7 */47, 183, -47, -183 }; + +static const int kLookup[8] = { 0, 1, 2, 3, -4, -3, -2, -1 }; + +static inline etc1_byte clamp(int x) { + return (etc1_byte) (x >= 0 ? (x < 255 ? x : 255) : 0); +} + +static +inline int convert4To8(int b) { + int c = b & 0xf; + return (c << 4) | c; +} + +static +inline int convert5To8(int b) { + int c = b & 0x1f; + return (c << 3) | (c >> 2); +} + +static +inline int convert6To8(int b) { + int c = b & 0x3f; + return (c << 2) | (c >> 4); +} + +static +inline int divideBy255(int d) { + return (d + 128 + (d >> 8)) >> 8; +} + +static +inline int convert8To4(int b) { + int c = b & 0xff; + return divideBy255(b * 15); +} + +static +inline int convert8To5(int b) { + int c = b & 0xff; + return divideBy255(b * 31); +} + +static +inline int convertDiff(int base, int diff) { + return convert5To8((0x1f & base) + kLookup[0x7 & diff]); +} + +static +void decode_subblock(etc1_byte* pOut, int r, int g, int b, const int* table, + etc1_uint32 low, bool second, bool flipped) { + int baseX = 0; + int baseY = 0; + if (second) { + if (flipped) { + baseY = 2; + } else { + baseX = 2; + } + } + for (int i = 0; i < 8; i++) { + int x, y; + if (flipped) { + x = baseX + (i >> 1); + y = baseY + (i & 1); + } else { + x = baseX + (i >> 2); + y = baseY + (i & 3); + } + int k = y + (x * 4); + int offset = ((low >> k) & 1) | ((low >> (k + 15)) & 2); + int delta = table[offset]; + etc1_byte* q = pOut + 3 * (x + 4 * y); + *q++ = clamp(r + delta); + *q++ = clamp(g + delta); + *q++ = clamp(b + delta); + } +} + +// Input is an ETC1 compressed version of the data. +// Output is a 4 x 4 square of 3-byte pixels in form R, G, B + +void etc1_decode_block(const etc1_byte* pIn, etc1_byte* pOut) { + etc1_uint32 high = (pIn[0] << 24) | (pIn[1] << 16) | (pIn[2] << 8) | pIn[3]; + etc1_uint32 low = (pIn[4] << 24) | (pIn[5] << 16) | (pIn[6] << 8) | pIn[7]; + int r1, r2, g1, g2, b1, b2; + if (high & 2) { + // differential + int rBase = high >> 27; + int gBase = high >> 19; + int bBase = high >> 11; + r1 = convert5To8(rBase); + r2 = convertDiff(rBase, high >> 24); + g1 = convert5To8(gBase); + g2 = convertDiff(gBase, high >> 16); + b1 = convert5To8(bBase); + b2 = convertDiff(bBase, high >> 8); + } else { + // not differential + r1 = convert4To8(high >> 28); + r2 = convert4To8(high >> 24); + g1 = convert4To8(high >> 20); + g2 = convert4To8(high >> 16); + b1 = convert4To8(high >> 12); + b2 = convert4To8(high >> 8); + } + int tableIndexA = 7 & (high >> 5); + int tableIndexB = 7 & (high >> 2); + const int* tableA = kModifierTable + tableIndexA * 4; + const int* tableB = kModifierTable + tableIndexB * 4; + bool flipped = (high & 1) != 0; + decode_subblock(pOut, r1, g1, b1, tableA, low, false, flipped); + decode_subblock(pOut, r2, g2, b2, tableB, low, true, flipped); +} + +typedef struct { + etc1_uint32 high; + etc1_uint32 low; + etc1_uint32 score; // Lower is more accurate +} etc_compressed; + +static +inline void take_best(etc_compressed* a, const etc_compressed* b) { + if (a->score > b->score) { + *a = *b; + } +} + +static +void etc_average_colors_subblock(const etc1_byte* pIn, etc1_uint32 inMask, + etc1_byte* pColors, bool flipped, bool second) { + int r = 0; + int g = 0; + int b = 0; + + if (flipped) { + int by = 0; + if (second) { + by = 2; + } + for (int y = 0; y < 2; y++) { + int yy = by + y; + for (int x = 0; x < 4; x++) { + int i = x + 4 * yy; + if (inMask & (1 << i)) { + const etc1_byte* p = pIn + i * 3; + r += *(p++); + g += *(p++); + b += *(p++); + } + } + } + } else { + int bx = 0; + if (second) { + bx = 2; + } + for (int y = 0; y < 4; y++) { + for (int x = 0; x < 2; x++) { + int xx = bx + x; + int i = xx + 4 * y; + if (inMask & (1 << i)) { + const etc1_byte* p = pIn + i * 3; + r += *(p++); + g += *(p++); + b += *(p++); + } + } + } + } + pColors[0] = (etc1_byte)((r + 4) >> 3); + pColors[1] = (etc1_byte)((g + 4) >> 3); + pColors[2] = (etc1_byte)((b + 4) >> 3); +} + +static +inline int square(int x) { + return x * x; +} + +static etc1_uint32 chooseModifier(const etc1_byte* pBaseColors, + const etc1_byte* pIn, etc1_uint32 *pLow, int bitIndex, + const int* pModifierTable) { + etc1_uint32 bestScore = ~0; + int bestIndex = 0; + int pixelR = pIn[0]; + int pixelG = pIn[1]; + int pixelB = pIn[2]; + int r = pBaseColors[0]; + int g = pBaseColors[1]; + int b = pBaseColors[2]; + for (int i = 0; i < 4; i++) { + int modifier = pModifierTable[i]; + int decodedG = clamp(g + modifier); + etc1_uint32 score = (etc1_uint32) (6 * square(decodedG - pixelG)); + if (score >= bestScore) { + continue; + } + int decodedR = clamp(r + modifier); + score += (etc1_uint32) (3 * square(decodedR - pixelR)); + if (score >= bestScore) { + continue; + } + int decodedB = clamp(b + modifier); + score += (etc1_uint32) square(decodedB - pixelB); + if (score < bestScore) { + bestScore = score; + bestIndex = i; + } + } + etc1_uint32 lowMask = (((bestIndex >> 1) << 16) | (bestIndex & 1)) + << bitIndex; + *pLow |= lowMask; + return bestScore; +} + +static +void etc_encode_subblock_helper(const etc1_byte* pIn, etc1_uint32 inMask, + etc_compressed* pCompressed, bool flipped, bool second, + const etc1_byte* pBaseColors, const int* pModifierTable) { + int score = pCompressed->score; + if (flipped) { + int by = 0; + if (second) { + by = 2; + } + for (int y = 0; y < 2; y++) { + int yy = by + y; + for (int x = 0; x < 4; x++) { + int i = x + 4 * yy; + if (inMask & (1 << i)) { + score += chooseModifier(pBaseColors, pIn + i * 3, + &pCompressed->low, yy + x * 4, pModifierTable); + } + } + } + } else { + int bx = 0; + if (second) { + bx = 2; + } + for (int y = 0; y < 4; y++) { + for (int x = 0; x < 2; x++) { + int xx = bx + x; + int i = xx + 4 * y; + if (inMask & (1 << i)) { + score += chooseModifier(pBaseColors, pIn + i * 3, + &pCompressed->low, y + xx * 4, pModifierTable); + } + } + } + } + pCompressed->score = score; +} + +static bool inRange4bitSigned(int color) { + return color >= -4 && color <= 3; +} + +static void etc_encodeBaseColors(etc1_byte* pBaseColors, + const etc1_byte* pColors, etc_compressed* pCompressed) { + int r1, g1, b1, r2, g2, b2; // 8 bit base colors for sub-blocks + bool differential; + { + int r51 = convert8To5(pColors[0]); + int g51 = convert8To5(pColors[1]); + int b51 = convert8To5(pColors[2]); + int r52 = convert8To5(pColors[3]); + int g52 = convert8To5(pColors[4]); + int b52 = convert8To5(pColors[5]); + + r1 = convert5To8(r51); + g1 = convert5To8(g51); + b1 = convert5To8(b51); + + int dr = r52 - r51; + int dg = g52 - g51; + int db = b52 - b51; + + differential = inRange4bitSigned(dr) && inRange4bitSigned(dg) + && inRange4bitSigned(db); + if (differential) { + r2 = convert5To8(r51 + dr); + g2 = convert5To8(g51 + dg); + b2 = convert5To8(b51 + db); + pCompressed->high |= (r51 << 27) | ((7 & dr) << 24) | (g51 << 19) + | ((7 & dg) << 16) | (b51 << 11) | ((7 & db) << 8) | 2; + } + } + + if (!differential) { + int r41 = convert8To4(pColors[0]); + int g41 = convert8To4(pColors[1]); + int b41 = convert8To4(pColors[2]); + int r42 = convert8To4(pColors[3]); + int g42 = convert8To4(pColors[4]); + int b42 = convert8To4(pColors[5]); + r1 = convert4To8(r41); + g1 = convert4To8(g41); + b1 = convert4To8(b41); + r2 = convert4To8(r42); + g2 = convert4To8(g42); + b2 = convert4To8(b42); + pCompressed->high |= (r41 << 28) | (r42 << 24) | (g41 << 20) | (g42 + << 16) | (b41 << 12) | (b42 << 8); + } + pBaseColors[0] = r1; + pBaseColors[1] = g1; + pBaseColors[2] = b1; + pBaseColors[3] = r2; + pBaseColors[4] = g2; + pBaseColors[5] = b2; +} + +static +void etc_encode_block_helper(const etc1_byte* pIn, etc1_uint32 inMask, + const etc1_byte* pColors, etc_compressed* pCompressed, bool flipped) { + pCompressed->score = ~0; + pCompressed->high = (flipped ? 1 : 0); + pCompressed->low = 0; + + etc1_byte pBaseColors[6]; + + etc_encodeBaseColors(pBaseColors, pColors, pCompressed); + + int originalHigh = pCompressed->high; + + const int* pModifierTable = kModifierTable; + for (int i = 0; i < 8; i++, pModifierTable += 4) { + etc_compressed temp; + temp.score = 0; + temp.high = originalHigh | (i << 5); + temp.low = 0; + etc_encode_subblock_helper(pIn, inMask, &temp, flipped, false, + pBaseColors, pModifierTable); + take_best(pCompressed, &temp); + } + pModifierTable = kModifierTable; + etc_compressed firstHalf = *pCompressed; + for (int i = 0; i < 8; i++, pModifierTable += 4) { + etc_compressed temp; + temp.score = firstHalf.score; + temp.high = firstHalf.high | (i << 2); + temp.low = firstHalf.low; + etc_encode_subblock_helper(pIn, inMask, &temp, flipped, true, + pBaseColors + 3, pModifierTable); + if (i == 0) { + *pCompressed = temp; + } else { + take_best(pCompressed, &temp); + } + } +} + +static void writeBigEndian(etc1_byte* pOut, etc1_uint32 d) { + pOut[0] = (etc1_byte)(d >> 24); + pOut[1] = (etc1_byte)(d >> 16); + pOut[2] = (etc1_byte)(d >> 8); + pOut[3] = (etc1_byte) d; +} + +// Input is a 4 x 4 square of 3-byte pixels in form R, G, B +// inmask is a 16-bit mask where bit (1 << (x + y * 4)) tells whether the corresponding (x,y) +// pixel is valid or not. Invalid pixel color values are ignored when compressing. +// Output is an ETC1 compressed version of the data. + +void etc1_encode_block(const etc1_byte* pIn, etc1_uint32 inMask, + etc1_byte* pOut) { + etc1_byte colors[6]; + etc1_byte flippedColors[6]; + etc_average_colors_subblock(pIn, inMask, colors, false, false); + etc_average_colors_subblock(pIn, inMask, colors + 3, false, true); + etc_average_colors_subblock(pIn, inMask, flippedColors, true, false); + etc_average_colors_subblock(pIn, inMask, flippedColors + 3, true, true); + + etc_compressed a, b; + etc_encode_block_helper(pIn, inMask, colors, &a, false); + etc_encode_block_helper(pIn, inMask, flippedColors, &b, true); + take_best(&a, &b); + writeBigEndian(pOut, a.high); + writeBigEndian(pOut + 4, a.low); +} + +// Return the size of the encoded image data (does not include size of PKM header). + +etc1_uint32 etc1_get_encoded_data_size(etc1_uint32 width, etc1_uint32 height) { + return (((width + 3) & ~3) * ((height + 3) & ~3)) >> 1; +} + +// Encode an entire image. +// pIn - pointer to the image data. Formatted such that the Red component of +// pixel (x,y) is at pIn + pixelSize * x + stride * y + redOffset; +// pOut - pointer to encoded data. Must be large enough to store entire encoded image. + +int etc1_encode_image(const etc1_byte* pIn, etc1_uint32 width, etc1_uint32 height, + etc1_uint32 pixelSize, etc1_uint32 stride, etc1_byte* pOut) { + if (pixelSize < 2 || pixelSize > 3) { + return -1; + } + static const unsigned short kYMask[] = { 0x0, 0xf, 0xff, 0xfff, 0xffff }; + static const unsigned short kXMask[] = { 0x0, 0x1111, 0x3333, 0x7777, + 0xffff }; + etc1_byte block[ETC1_DECODED_BLOCK_SIZE]; + etc1_byte encoded[ETC1_ENCODED_BLOCK_SIZE]; + + etc1_uint32 encodedWidth = (width + 3) & ~3; + etc1_uint32 encodedHeight = (height + 3) & ~3; + + for (etc1_uint32 y = 0; y < encodedHeight; y += 4) { + etc1_uint32 yEnd = height - y; + if (yEnd > 4) { + yEnd = 4; + } + int ymask = kYMask[yEnd]; + for (etc1_uint32 x = 0; x < encodedWidth; x += 4) { + etc1_uint32 xEnd = width - x; + if (xEnd > 4) { + xEnd = 4; + } + int mask = ymask & kXMask[xEnd]; + for (etc1_uint32 cy = 0; cy < yEnd; cy++) { + etc1_byte* q = block + (cy * 4) * 3; + const etc1_byte* p = pIn + pixelSize * x + stride * (y + cy); + if (pixelSize == 3) { + memcpy(q, p, xEnd * 3); + } else { + for (etc1_uint32 cx = 0; cx < xEnd; cx++) { + int pixel = (p[1] << 8) | p[0]; + *q++ = convert5To8(pixel >> 11); + *q++ = convert6To8(pixel >> 5); + *q++ = convert5To8(pixel); + p += pixelSize; + } + } + } + etc1_encode_block(block, mask, encoded); + memcpy(pOut, encoded, sizeof(encoded)); + pOut += sizeof(encoded); + } + } + return 0; +} + +// Decode an entire image. +// pIn - pointer to encoded data. +// pOut - pointer to the image data. Will be written such that the Red component of +// pixel (x,y) is at pIn + pixelSize * x + stride * y + redOffset. Must be +// large enough to store entire image. + + +int etc1_decode_image(const etc1_byte* pIn, etc1_byte* pOut, + etc1_uint32 width, etc1_uint32 height, + etc1_uint32 pixelSize, etc1_uint32 stride) { + if (pixelSize < 2 || pixelSize > 3) { + return -1; + } + etc1_byte block[ETC1_DECODED_BLOCK_SIZE]; + + etc1_uint32 encodedWidth = (width + 3) & ~3; + etc1_uint32 encodedHeight = (height + 3) & ~3; + + for (etc1_uint32 y = 0; y < encodedHeight; y += 4) { + etc1_uint32 yEnd = height - y; + if (yEnd > 4) { + yEnd = 4; + } + for (etc1_uint32 x = 0; x < encodedWidth; x += 4) { + etc1_uint32 xEnd = width - x; + if (xEnd > 4) { + xEnd = 4; + } + etc1_decode_block(pIn, block); + pIn += ETC1_ENCODED_BLOCK_SIZE; + for (etc1_uint32 cy = 0; cy < yEnd; cy++) { + const etc1_byte* q = block + (cy * 4) * 3; + etc1_byte* p = pOut + pixelSize * x + stride * (y + cy); + if (pixelSize == 3) { + memcpy(p, q, xEnd * 3); + } else { + for (etc1_uint32 cx = 0; cx < xEnd; cx++) { + etc1_byte r = *q++; + etc1_byte g = *q++; + etc1_byte b = *q++; + etc1_uint32 pixel = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3); + *p++ = (etc1_byte) pixel; + *p++ = (etc1_byte) (pixel >> 8); + } + } + } + } + } + return 0; +} + +static const char kMagic[] = { 'P', 'K', 'M', ' ', '1', '0' }; + +static const etc1_uint32 ETC1_PKM_FORMAT_OFFSET = 6; +static const etc1_uint32 ETC1_PKM_ENCODED_WIDTH_OFFSET = 8; +static const etc1_uint32 ETC1_PKM_ENCODED_HEIGHT_OFFSET = 10; +static const etc1_uint32 ETC1_PKM_WIDTH_OFFSET = 12; +static const etc1_uint32 ETC1_PKM_HEIGHT_OFFSET = 14; + +static const etc1_uint32 ETC1_RGB_NO_MIPMAPS = 0; + +static void writeBEUint16(etc1_byte* pOut, etc1_uint32 data) { + pOut[0] = (etc1_byte) (data >> 8); + pOut[1] = (etc1_byte) data; +} + +static etc1_uint32 readBEUint16(const etc1_byte* pIn) { + return (pIn[0] << 8) | pIn[1]; +} + +// Format a PKM header + +void etc1_pkm_format_header(etc1_byte* pHeader, etc1_uint32 width, etc1_uint32 height) { + memcpy(pHeader, kMagic, sizeof(kMagic)); + etc1_uint32 encodedWidth = (width + 3) & ~3; + etc1_uint32 encodedHeight = (height + 3) & ~3; + writeBEUint16(pHeader + ETC1_PKM_FORMAT_OFFSET, ETC1_RGB_NO_MIPMAPS); + writeBEUint16(pHeader + ETC1_PKM_ENCODED_WIDTH_OFFSET, encodedWidth); + writeBEUint16(pHeader + ETC1_PKM_ENCODED_HEIGHT_OFFSET, encodedHeight); + writeBEUint16(pHeader + ETC1_PKM_WIDTH_OFFSET, width); + writeBEUint16(pHeader + ETC1_PKM_HEIGHT_OFFSET, height); +} + +// Check if a PKM header is correctly formatted. + +etc1_bool etc1_pkm_is_valid(const etc1_byte* pHeader) { + if (memcmp(pHeader, kMagic, sizeof(kMagic))) { + return false; + } + etc1_uint32 format = readBEUint16(pHeader + ETC1_PKM_FORMAT_OFFSET); + etc1_uint32 encodedWidth = readBEUint16(pHeader + ETC1_PKM_ENCODED_WIDTH_OFFSET); + etc1_uint32 encodedHeight = readBEUint16(pHeader + ETC1_PKM_ENCODED_HEIGHT_OFFSET); + etc1_uint32 width = readBEUint16(pHeader + ETC1_PKM_WIDTH_OFFSET); + etc1_uint32 height = readBEUint16(pHeader + ETC1_PKM_HEIGHT_OFFSET); + return format == ETC1_RGB_NO_MIPMAPS && + encodedWidth >= width && encodedWidth - width < 4 && + encodedHeight >= height && encodedHeight - height < 4; +} + +// Read the image width from a PKM header + +etc1_uint32 etc1_pkm_get_width(const etc1_byte* pHeader) { + return readBEUint16(pHeader + ETC1_PKM_WIDTH_OFFSET); +} + +// Read the image height from a PKM header + +etc1_uint32 etc1_pkm_get_height(const etc1_byte* pHeader){ + return readBEUint16(pHeader + ETC1_PKM_HEIGHT_OFFSET); +} diff --git a/emulator/opengl/host/libs/Translator/GLcommon/objectNameManager.cpp b/emulator/opengl/host/libs/Translator/GLcommon/objectNameManager.cpp new file mode 100644 index 0000000..cfea855 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/GLcommon/objectNameManager.cpp @@ -0,0 +1,411 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include <map> +#include <GLcommon/objectNameManager.h> +#include <GLcommon/GLEScontext.h> + + +NameSpace::NameSpace(NamedObjectType p_type, GlobalNameSpace *globalNameSpace) : + m_nextName(0), + m_type(p_type), + m_globalNameSpace(globalNameSpace) +{ +} + +NameSpace::~NameSpace() +{ + for (NamesMap::iterator n = m_localToGlobalMap.begin(); + n != m_localToGlobalMap.end(); + n++) { + m_globalNameSpace->deleteName(m_type, (*n).second); + } +} + +ObjectLocalName +NameSpace::genName(ObjectLocalName p_localName, bool genGlobal, bool genLocal) +{ + + ObjectLocalName localName = p_localName; + if (genLocal) { + do { + localName = ++m_nextName; + } while( localName == 0 || m_localToGlobalMap.find(localName) != m_localToGlobalMap.end() ); + } + + if (genGlobal) { + unsigned int globalName = m_globalNameSpace->genName(m_type); + m_localToGlobalMap[localName] = globalName; + } + + return localName; +} + + +unsigned int +NameSpace::genGlobalName(void) +{ + return m_globalNameSpace->genName(m_type); +} + +unsigned int +NameSpace::getGlobalName(ObjectLocalName p_localName) +{ + NamesMap::iterator n( m_localToGlobalMap.find(p_localName) ); + if (n != m_localToGlobalMap.end()) { + // object found - return its global name map + return (*n).second; + } + + // object does not exist; + return 0; +} + +ObjectLocalName +NameSpace::getLocalName(unsigned int p_globalName) +{ + for(NamesMap::iterator it = m_localToGlobalMap.begin(); it != m_localToGlobalMap.end();it++){ + if((*it).second == p_globalName){ + // object found - return its local name + return (*it).first; + } + } + + // object does not exist; + return 0; +} + +void +NameSpace::deleteName(ObjectLocalName p_localName) +{ + NamesMap::iterator n( m_localToGlobalMap.find(p_localName) ); + if (n != m_localToGlobalMap.end()) { + m_globalNameSpace->deleteName(m_type, (*n).second); + m_localToGlobalMap.erase(p_localName); + } +} + +bool +NameSpace::isObject(ObjectLocalName p_localName) +{ + return (m_localToGlobalMap.find(p_localName) != m_localToGlobalMap.end() ); +} + +void +NameSpace::replaceGlobalName(ObjectLocalName p_localName, unsigned int p_globalName) +{ + NamesMap::iterator n( m_localToGlobalMap.find(p_localName) ); + if (n != m_localToGlobalMap.end()) { + m_globalNameSpace->deleteName(m_type, (*n).second); + (*n).second = p_globalName; + } +} + + +GlobalNameSpace::GlobalNameSpace() +{ + mutex_init(&m_lock); +} + +GlobalNameSpace::~GlobalNameSpace() +{ + mutex_destroy(&m_lock); +} + +unsigned int +GlobalNameSpace::genName(NamedObjectType p_type) +{ + if ( p_type >= NUM_OBJECT_TYPES ) return 0; + unsigned int name = 0; + + mutex_lock(&m_lock); + switch (p_type) { + case VERTEXBUFFER: + GLEScontext::dispatcher().glGenBuffers(1,&name); + break; + case TEXTURE: + GLEScontext::dispatcher().glGenTextures(1,&name); + break; + case RENDERBUFFER: + GLEScontext::dispatcher().glGenRenderbuffersEXT(1,&name); + break; + case FRAMEBUFFER: + GLEScontext::dispatcher().glGenFramebuffersEXT(1,&name); + break; + case SHADER: //objects in shader namepace are not handled + default: + name = 0; + } + mutex_unlock(&m_lock); + return name; +} + +void +GlobalNameSpace::deleteName(NamedObjectType p_type, unsigned int p_name) +{ +} + +typedef std::pair<NamedObjectType, ObjectLocalName> ObjectIDPair; +typedef std::map<ObjectIDPair, ObjectDataPtr> ObjectDataMap; + +ShareGroup::ShareGroup(GlobalNameSpace *globalNameSpace) +{ + mutex_init(&m_lock); + + for (int i=0; i<NUM_OBJECT_TYPES; i++) { + m_nameSpace[i] = new NameSpace((NamedObjectType)i, globalNameSpace); + } + + m_objectsData = NULL; +} + +ShareGroup::~ShareGroup() +{ + mutex_lock(&m_lock); + for (int t = 0; t < NUM_OBJECT_TYPES; t++) { + delete m_nameSpace[t]; + } + + ObjectDataMap *map = (ObjectDataMap *)m_objectsData; + if (map) delete map; + + mutex_unlock(&m_lock); + mutex_destroy(&m_lock); +} + +ObjectLocalName +ShareGroup::genName(NamedObjectType p_type, ObjectLocalName p_localName, bool genLocal) +{ + if (p_type >= NUM_OBJECT_TYPES) return 0; + + mutex_lock(&m_lock); + ObjectLocalName localName = m_nameSpace[p_type]->genName(p_localName,true,genLocal); + mutex_unlock(&m_lock); + + return localName; +} + +unsigned int +ShareGroup::genGlobalName(NamedObjectType p_type) +{ + if (p_type >= NUM_OBJECT_TYPES) return 0; + + mutex_lock(&m_lock); + unsigned int name = m_nameSpace[p_type]->genGlobalName(); + mutex_unlock(&m_lock); + + return name; +} + +unsigned int +ShareGroup::getGlobalName(NamedObjectType p_type, ObjectLocalName p_localName) +{ + if (p_type >= NUM_OBJECT_TYPES) return 0; + + mutex_lock(&m_lock); + unsigned int globalName = m_nameSpace[p_type]->getGlobalName(p_localName); + mutex_unlock(&m_lock); + + return globalName; +} + +ObjectLocalName +ShareGroup::getLocalName(NamedObjectType p_type, unsigned int p_globalName) +{ + if (p_type >= NUM_OBJECT_TYPES) return 0; + + mutex_lock(&m_lock); + ObjectLocalName localName = m_nameSpace[p_type]->getLocalName(p_globalName); + mutex_unlock(&m_lock); + + return localName; +} + +void +ShareGroup::deleteName(NamedObjectType p_type, ObjectLocalName p_localName) +{ + if (p_type >= NUM_OBJECT_TYPES) return; + + mutex_lock(&m_lock); + m_nameSpace[p_type]->deleteName(p_localName); + ObjectDataMap *map = (ObjectDataMap *)m_objectsData; + if (map) { + map->erase( ObjectIDPair(p_type, p_localName) ); + } + mutex_unlock(&m_lock); +} + +bool +ShareGroup::isObject(NamedObjectType p_type, ObjectLocalName p_localName) +{ + if (p_type >= NUM_OBJECT_TYPES) return 0; + + mutex_lock(&m_lock); + bool exist = m_nameSpace[p_type]->isObject(p_localName); + mutex_unlock(&m_lock); + + return exist; +} + +void +ShareGroup::replaceGlobalName(NamedObjectType p_type, ObjectLocalName p_localName, unsigned int p_globalName) +{ + if (p_type >= NUM_OBJECT_TYPES) return; + + mutex_lock(&m_lock); + m_nameSpace[p_type]->replaceGlobalName(p_localName, p_globalName); + mutex_unlock(&m_lock); +} + +void +ShareGroup::setObjectData(NamedObjectType p_type, ObjectLocalName p_localName, ObjectDataPtr data) +{ + if (p_type >= NUM_OBJECT_TYPES) return; + + mutex_lock(&m_lock); + + ObjectDataMap *map = (ObjectDataMap *)m_objectsData; + if (!map) { + map = new ObjectDataMap(); + m_objectsData = map; + } + + ObjectIDPair id( p_type, p_localName ); + map->insert( std::pair<ObjectIDPair, ObjectDataPtr>(id, data) ); + + mutex_unlock(&m_lock); +} + +ObjectDataPtr +ShareGroup::getObjectData(NamedObjectType p_type, ObjectLocalName p_localName) +{ + ObjectDataPtr ret; + + if (p_type >= NUM_OBJECT_TYPES) return ret; + + mutex_lock(&m_lock); + + ObjectDataMap *map = (ObjectDataMap *)m_objectsData; + if (map) { + ObjectDataMap::iterator i = map->find( ObjectIDPair(p_type, p_localName) ); + if (i != map->end()) ret = (*i).second; + } + + mutex_unlock(&m_lock); + + return ret; +} + +ObjectNameManager::ObjectNameManager(GlobalNameSpace *globalNameSpace) : + m_globalNameSpace(globalNameSpace) +{ + mutex_init(&m_lock); +} + +ObjectNameManager::~ObjectNameManager() +{ + mutex_destroy(&m_lock); +} + +ShareGroupPtr +ObjectNameManager::createShareGroup(void *p_groupName) +{ + mutex_lock(&m_lock); + + ShareGroupPtr shareGroupReturn; + + ShareGroupsMap::iterator s( m_groups.find(p_groupName) ); + if (s != m_groups.end()) { + shareGroupReturn = (*s).second; + } + else { + // + // Group does not exist, create new group + // + shareGroupReturn = ShareGroupPtr( new ShareGroup(m_globalNameSpace) ); + m_groups.insert( std::pair<void *, ShareGroupPtr>(p_groupName, shareGroupReturn) ); + } + + mutex_unlock(&m_lock); + + return shareGroupReturn; +} + +ShareGroupPtr +ObjectNameManager::getShareGroup(void *p_groupName) +{ + mutex_lock(&m_lock); + + ShareGroupPtr shareGroupReturn(NULL); + + ShareGroupsMap::iterator s( m_groups.find(p_groupName) ); + if (s != m_groups.end()) { + shareGroupReturn = (*s).second; + } + mutex_unlock(&m_lock); + + return shareGroupReturn; +} + +ShareGroupPtr +ObjectNameManager::attachShareGroup(void *p_groupName, void *p_existingGroupName) +{ + mutex_lock(&m_lock); + + ShareGroupPtr shareGroupReturn; + + ShareGroupsMap::iterator s( m_groups.find(p_existingGroupName) ); + if (s == m_groups.end()) { + // ShareGroup did not found !!! + mutex_unlock(&m_lock); + return ShareGroupPtr(NULL); + } + + shareGroupReturn = (*s).second; + + if (m_groups.find(p_groupName) == m_groups.end()) + { + m_groups.insert( std::pair<void *, ShareGroupPtr>(p_groupName, shareGroupReturn) ); + } + + mutex_unlock(&m_lock); + + return shareGroupReturn; +} + +void +ObjectNameManager::deleteShareGroup(void *p_groupName) +{ + mutex_lock(&m_lock); + + ShareGroupsMap::iterator s( m_groups.find(p_groupName) ); + if (s != m_groups.end()) { + m_groups.erase(s); + } + + mutex_unlock(&m_lock); +} + +void *ObjectNameManager::getGlobalContext() +{ + void *ret = NULL; + + mutex_lock(&m_lock); + if (m_groups.size() > 0) ret = (*m_groups.begin()).first; + mutex_unlock(&m_lock); + + return ret; +} + diff --git a/emulator/opengl/host/libs/Translator/include/EGL/egl.h b/emulator/opengl/host/libs/Translator/include/EGL/egl.h new file mode 100644 index 0000000..99ea342 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/EGL/egl.h @@ -0,0 +1,329 @@ +/* -*- mode: c; tab-width: 8; -*- */ +/* vi: set sw=4 ts=8: */ +/* Reference version of egl.h for EGL 1.4. + * $Revision: 9356 $ on $Date: 2009-10-21 02:52:25 -0700 (Wed, 21 Oct 2009) $ + */ + +/* +** Copyright (c) 2007-2009 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are 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 Materials. +** +** THE MATERIALS ARE 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 +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +#ifndef __egl_h_ +#define __egl_h_ + +/* All platform-dependent types and macro boilerplate (such as EGLAPI + * and EGLAPIENTRY) should go in eglplatform.h. + */ +#include <EGL/eglplatform.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* EGL Types */ +/* EGLint is defined in eglplatform.h */ +typedef unsigned int EGLBoolean; +typedef unsigned int EGLenum; +typedef void *EGLConfig; +typedef void *EGLContext; +typedef void *EGLDisplay; +typedef void *EGLSurface; +typedef void *EGLClientBuffer; + +/* EGL Versioning */ +#define EGL_VERSION_1_0 1 +#define EGL_VERSION_1_1 1 +#define EGL_VERSION_1_2 1 +#define EGL_VERSION_1_3 1 +#define EGL_VERSION_1_4 1 + +/* EGL Enumerants. Bitmasks and other exceptional cases aside, most + * enums are assigned unique values starting at 0x3000. + */ + +/* EGL aliases */ +#define EGL_FALSE 0 +#define EGL_TRUE 1 + +/* Out-of-band handle values */ +#define EGL_DEFAULT_DISPLAY ((EGLNativeDisplayType)0) +#define EGL_NO_CONTEXT ((EGLContext)0) +#define EGL_NO_DISPLAY ((EGLDisplay)0) +#define EGL_NO_SURFACE ((EGLSurface)0) + +/* Out-of-band attribute value */ +#define EGL_DONT_CARE ((EGLint)-1) + +/* Errors / GetError return values */ +#define EGL_SUCCESS 0x3000 +#define EGL_NOT_INITIALIZED 0x3001 +#define EGL_BAD_ACCESS 0x3002 +#define EGL_BAD_ALLOC 0x3003 +#define EGL_BAD_ATTRIBUTE 0x3004 +#define EGL_BAD_CONFIG 0x3005 +#define EGL_BAD_CONTEXT 0x3006 +#define EGL_BAD_CURRENT_SURFACE 0x3007 +#define EGL_BAD_DISPLAY 0x3008 +#define EGL_BAD_MATCH 0x3009 +#define EGL_BAD_NATIVE_PIXMAP 0x300A +#define EGL_BAD_NATIVE_WINDOW 0x300B +#define EGL_BAD_PARAMETER 0x300C +#define EGL_BAD_SURFACE 0x300D +#define EGL_CONTEXT_LOST 0x300E /* EGL 1.1 - IMG_power_management */ + +/* Reserved 0x300F-0x301F for additional errors */ + +/* Config attributes */ +#define EGL_BUFFER_SIZE 0x3020 +#define EGL_ALPHA_SIZE 0x3021 +#define EGL_BLUE_SIZE 0x3022 +#define EGL_GREEN_SIZE 0x3023 +#define EGL_RED_SIZE 0x3024 +#define EGL_DEPTH_SIZE 0x3025 +#define EGL_STENCIL_SIZE 0x3026 +#define EGL_CONFIG_CAVEAT 0x3027 +#define EGL_CONFIG_ID 0x3028 +#define EGL_LEVEL 0x3029 +#define EGL_MAX_PBUFFER_HEIGHT 0x302A +#define EGL_MAX_PBUFFER_PIXELS 0x302B +#define EGL_MAX_PBUFFER_WIDTH 0x302C +#define EGL_NATIVE_RENDERABLE 0x302D +#define EGL_NATIVE_VISUAL_ID 0x302E +#define EGL_NATIVE_VISUAL_TYPE 0x302F +#define EGL_SAMPLES 0x3031 +#define EGL_SAMPLE_BUFFERS 0x3032 +#define EGL_SURFACE_TYPE 0x3033 +#define EGL_TRANSPARENT_TYPE 0x3034 +#define EGL_TRANSPARENT_BLUE_VALUE 0x3035 +#define EGL_TRANSPARENT_GREEN_VALUE 0x3036 +#define EGL_TRANSPARENT_RED_VALUE 0x3037 +#define EGL_NONE 0x3038 /* Attrib list terminator */ +#define EGL_BIND_TO_TEXTURE_RGB 0x3039 +#define EGL_BIND_TO_TEXTURE_RGBA 0x303A +#define EGL_MIN_SWAP_INTERVAL 0x303B +#define EGL_MAX_SWAP_INTERVAL 0x303C +#define EGL_LUMINANCE_SIZE 0x303D +#define EGL_ALPHA_MASK_SIZE 0x303E +#define EGL_COLOR_BUFFER_TYPE 0x303F +#define EGL_RENDERABLE_TYPE 0x3040 +#define EGL_MATCH_NATIVE_PIXMAP 0x3041 /* Pseudo-attribute (not queryable) */ +#define EGL_CONFORMANT 0x3042 + +/* Reserved 0x3041-0x304F for additional config attributes */ + +/* Config attribute values */ +#define EGL_SLOW_CONFIG 0x3050 /* EGL_CONFIG_CAVEAT value */ +#define EGL_NON_CONFORMANT_CONFIG 0x3051 /* EGL_CONFIG_CAVEAT value */ +#define EGL_TRANSPARENT_RGB 0x3052 /* EGL_TRANSPARENT_TYPE value */ +#define EGL_RGB_BUFFER 0x308E /* EGL_COLOR_BUFFER_TYPE value */ +#define EGL_LUMINANCE_BUFFER 0x308F /* EGL_COLOR_BUFFER_TYPE value */ + +/* More config attribute values, for EGL_TEXTURE_FORMAT */ +#define EGL_NO_TEXTURE 0x305C +#define EGL_TEXTURE_RGB 0x305D +#define EGL_TEXTURE_RGBA 0x305E +#define EGL_TEXTURE_2D 0x305F + +/* Config attribute mask bits */ +#define EGL_PBUFFER_BIT 0x0001 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_PIXMAP_BIT 0x0002 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_WINDOW_BIT 0x0004 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_VG_COLORSPACE_LINEAR_BIT 0x0020 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_VG_ALPHA_FORMAT_PRE_BIT 0x0040 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_MULTISAMPLE_RESOLVE_BOX_BIT 0x0200 /* EGL_SURFACE_TYPE mask bits */ +#define EGL_SWAP_BEHAVIOR_PRESERVED_BIT 0x0400 /* EGL_SURFACE_TYPE mask bits */ + +#define EGL_OPENGL_ES_BIT 0x0001 /* EGL_RENDERABLE_TYPE mask bits */ +#define EGL_OPENVG_BIT 0x0002 /* EGL_RENDERABLE_TYPE mask bits */ +#define EGL_OPENGL_ES2_BIT 0x0004 /* EGL_RENDERABLE_TYPE mask bits */ +#define EGL_OPENGL_BIT 0x0008 /* EGL_RENDERABLE_TYPE mask bits */ + +/* QueryString targets */ +#define EGL_VENDOR 0x3053 +#define EGL_VERSION 0x3054 +#define EGL_EXTENSIONS 0x3055 +#define EGL_CLIENT_APIS 0x308D + +/* QuerySurface / SurfaceAttrib / CreatePbufferSurface targets */ +#define EGL_HEIGHT 0x3056 +#define EGL_WIDTH 0x3057 +#define EGL_LARGEST_PBUFFER 0x3058 +#define EGL_TEXTURE_FORMAT 0x3080 +#define EGL_TEXTURE_TARGET 0x3081 +#define EGL_MIPMAP_TEXTURE 0x3082 +#define EGL_MIPMAP_LEVEL 0x3083 +#define EGL_RENDER_BUFFER 0x3086 +#define EGL_VG_COLORSPACE 0x3087 +#define EGL_VG_ALPHA_FORMAT 0x3088 +#define EGL_HORIZONTAL_RESOLUTION 0x3090 +#define EGL_VERTICAL_RESOLUTION 0x3091 +#define EGL_PIXEL_ASPECT_RATIO 0x3092 +#define EGL_SWAP_BEHAVIOR 0x3093 +#define EGL_MULTISAMPLE_RESOLVE 0x3099 + +/* EGL_RENDER_BUFFER values / BindTexImage / ReleaseTexImage buffer targets */ +#define EGL_BACK_BUFFER 0x3084 +#define EGL_SINGLE_BUFFER 0x3085 + +/* OpenVG color spaces */ +#define EGL_VG_COLORSPACE_sRGB 0x3089 /* EGL_VG_COLORSPACE value */ +#define EGL_VG_COLORSPACE_LINEAR 0x308A /* EGL_VG_COLORSPACE value */ + +/* OpenVG alpha formats */ +#define EGL_VG_ALPHA_FORMAT_NONPRE 0x308B /* EGL_ALPHA_FORMAT value */ +#define EGL_VG_ALPHA_FORMAT_PRE 0x308C /* EGL_ALPHA_FORMAT value */ + +/* Constant scale factor by which fractional display resolutions & + * aspect ratio are scaled when queried as integer values. + */ +#define EGL_DISPLAY_SCALING 10000 + +/* Unknown display resolution/aspect ratio */ +#define EGL_UNKNOWN ((EGLint)-1) + +/* Back buffer swap behaviors */ +#define EGL_BUFFER_PRESERVED 0x3094 /* EGL_SWAP_BEHAVIOR value */ +#define EGL_BUFFER_DESTROYED 0x3095 /* EGL_SWAP_BEHAVIOR value */ + +/* CreatePbufferFromClientBuffer buffer types */ +#define EGL_OPENVG_IMAGE 0x3096 + +/* QueryContext targets */ +#define EGL_CONTEXT_CLIENT_TYPE 0x3097 + +/* CreateContext attributes */ +#define EGL_CONTEXT_CLIENT_VERSION 0x3098 + +/* Multisample resolution behaviors */ +#define EGL_MULTISAMPLE_RESOLVE_DEFAULT 0x309A /* EGL_MULTISAMPLE_RESOLVE value */ +#define EGL_MULTISAMPLE_RESOLVE_BOX 0x309B /* EGL_MULTISAMPLE_RESOLVE value */ + +/* BindAPI/QueryAPI targets */ +#define EGL_OPENGL_ES_API 0x30A0 +#define EGL_OPENVG_API 0x30A1 +#define EGL_OPENGL_API 0x30A2 + +/* GetCurrentSurface targets */ +#define EGL_DRAW 0x3059 +#define EGL_READ 0x305A + +/* WaitNative engines */ +#define EGL_CORE_NATIVE_ENGINE 0x305B + +/* EGL 1.2 tokens renamed for consistency in EGL 1.3 */ +#define EGL_COLORSPACE EGL_VG_COLORSPACE +#define EGL_ALPHA_FORMAT EGL_VG_ALPHA_FORMAT +#define EGL_COLORSPACE_sRGB EGL_VG_COLORSPACE_sRGB +#define EGL_COLORSPACE_LINEAR EGL_VG_COLORSPACE_LINEAR +#define EGL_ALPHA_FORMAT_NONPRE EGL_VG_ALPHA_FORMAT_NONPRE +#define EGL_ALPHA_FORMAT_PRE EGL_VG_ALPHA_FORMAT_PRE + +/* EGL extensions must request enum blocks from the Khronos + * API Registrar, who maintains the enumerant registry. Submit + * a bug in Khronos Bugzilla against task "Registry". + */ + + + +/* EGL Functions */ + +EGLAPI EGLint EGLAPIENTRY eglGetError(void); + +EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id); +EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor); +EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy); + +EGLAPI const char * EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name); + +EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, + EGLint config_size, EGLint *num_config); +EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, + EGLConfig *configs, EGLint config_size, + EGLint *num_config); +EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, + EGLint attribute, EGLint *value); + +EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, + EGLNativeWindowType win, + const EGLint *attrib_list); +EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, + const EGLint *attrib_list); +EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, + EGLNativePixmapType pixmap, + const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay dpy, EGLSurface surface); +EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface(EGLDisplay dpy, EGLSurface surface, + EGLint attribute, EGLint *value); + +EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI(EGLenum api); +EGLAPI EGLenum EGLAPIENTRY eglQueryAPI(void); + +EGLAPI EGLBoolean EGLAPIENTRY eglWaitClient(void); + +EGLAPI EGLBoolean EGLAPIENTRY eglReleaseThread(void); + +EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferFromClientBuffer( + EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, + EGLConfig config, const EGLint *attrib_list); + +EGLAPI EGLBoolean EGLAPIENTRY eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, + EGLint attribute, EGLint value); +EGLAPI EGLBoolean EGLAPIENTRY eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer); +EGLAPI EGLBoolean EGLAPIENTRY eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer); + + +EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval); + + +EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, + EGLContext share_context, + const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext ctx); +EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, + EGLSurface read, EGLContext ctx); + +EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext(void); +EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface(EGLint readdraw); +EGLAPI EGLDisplay EGLAPIENTRY eglGetCurrentDisplay(void); +EGLAPI EGLBoolean EGLAPIENTRY eglQueryContext(EGLDisplay dpy, EGLContext ctx, + EGLint attribute, EGLint *value); + +EGLAPI EGLBoolean EGLAPIENTRY eglWaitGL(void); +EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative(EGLint engine); +EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surface); +EGLAPI EGLBoolean EGLAPIENTRY eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, + EGLNativePixmapType target); + +/* This is a generic function pointer type, whose name indicates it must + * be cast to the proper type *and calling convention* before use. + */ +typedef void (*__eglMustCastToProperFunctionPointerType)(void); + +/* Now, define eglGetProcAddress using the generic function ptr. type */ +EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY + eglGetProcAddress(const char *procname); + +#ifdef __cplusplus +} +#endif + +#endif /* __egl_h_ */ diff --git a/emulator/opengl/host/libs/Translator/include/EGL/eglext.h b/emulator/opengl/host/libs/Translator/include/EGL/eglext.h new file mode 100644 index 0000000..1ffcd56 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/EGL/eglext.h @@ -0,0 +1,244 @@ +#ifndef __eglext_h_ +#define __eglext_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** Copyright (c) 2007-2010 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are 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 Materials. +** +** THE MATERIALS ARE 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 +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +#include <EGL/eglplatform.h> + +/*************************************************************/ + +/* Header file version number */ +/* Current version at http://www.khronos.org/registry/egl/ */ +/* $Revision: 11249 $ on $Date: 2010-05-05 09:54:28 -0700 (Wed, 05 May 2010) $ */ +#define EGL_EGLEXT_VERSION 5 + +#ifndef EGL_KHR_config_attribs +#define EGL_KHR_config_attribs 1 +#define EGL_CONFORMANT_KHR 0x3042 /* EGLConfig attribute */ +#define EGL_VG_COLORSPACE_LINEAR_BIT_KHR 0x0020 /* EGL_SURFACE_TYPE bitfield */ +#define EGL_VG_ALPHA_FORMAT_PRE_BIT_KHR 0x0040 /* EGL_SURFACE_TYPE bitfield */ +#endif + +#ifndef EGL_KHR_lock_surface +#define EGL_KHR_lock_surface 1 +#define EGL_READ_SURFACE_BIT_KHR 0x0001 /* EGL_LOCK_USAGE_HINT_KHR bitfield */ +#define EGL_WRITE_SURFACE_BIT_KHR 0x0002 /* EGL_LOCK_USAGE_HINT_KHR bitfield */ +#define EGL_LOCK_SURFACE_BIT_KHR 0x0080 /* EGL_SURFACE_TYPE bitfield */ +#define EGL_OPTIMAL_FORMAT_BIT_KHR 0x0100 /* EGL_SURFACE_TYPE bitfield */ +#define EGL_MATCH_FORMAT_KHR 0x3043 /* EGLConfig attribute */ +#define EGL_FORMAT_RGB_565_EXACT_KHR 0x30C0 /* EGL_MATCH_FORMAT_KHR value */ +#define EGL_FORMAT_RGB_565_KHR 0x30C1 /* EGL_MATCH_FORMAT_KHR value */ +#define EGL_FORMAT_RGBA_8888_EXACT_KHR 0x30C2 /* EGL_MATCH_FORMAT_KHR value */ +#define EGL_FORMAT_RGBA_8888_KHR 0x30C3 /* EGL_MATCH_FORMAT_KHR value */ +#define EGL_MAP_PRESERVE_PIXELS_KHR 0x30C4 /* eglLockSurfaceKHR attribute */ +#define EGL_LOCK_USAGE_HINT_KHR 0x30C5 /* eglLockSurfaceKHR attribute */ +#define EGL_BITMAP_POINTER_KHR 0x30C6 /* eglQuerySurface attribute */ +#define EGL_BITMAP_PITCH_KHR 0x30C7 /* eglQuerySurface attribute */ +#define EGL_BITMAP_ORIGIN_KHR 0x30C8 /* eglQuerySurface attribute */ +#define EGL_BITMAP_PIXEL_RED_OFFSET_KHR 0x30C9 /* eglQuerySurface attribute */ +#define EGL_BITMAP_PIXEL_GREEN_OFFSET_KHR 0x30CA /* eglQuerySurface attribute */ +#define EGL_BITMAP_PIXEL_BLUE_OFFSET_KHR 0x30CB /* eglQuerySurface attribute */ +#define EGL_BITMAP_PIXEL_ALPHA_OFFSET_KHR 0x30CC /* eglQuerySurface attribute */ +#define EGL_BITMAP_PIXEL_LUMINANCE_OFFSET_KHR 0x30CD /* eglQuerySurface attribute */ +#define EGL_LOWER_LEFT_KHR 0x30CE /* EGL_BITMAP_ORIGIN_KHR value */ +#define EGL_UPPER_LEFT_KHR 0x30CF /* EGL_BITMAP_ORIGIN_KHR value */ +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglLockSurfaceKHR (EGLDisplay display, EGLSurface surface, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglUnlockSurfaceKHR (EGLDisplay display, EGLSurface surface); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLBoolean (EGLAPIENTRYP PFNEGLLOCKSURFACEKHRPROC) (EGLDisplay display, EGLSurface surface, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLUNLOCKSURFACEKHRPROC) (EGLDisplay display, EGLSurface surface); +#endif + +#ifndef EGL_KHR_image +#define EGL_KHR_image 1 +#define EGL_NATIVE_PIXMAP_KHR 0x30B0 /* eglCreateImageKHR target */ +typedef void *EGLImageKHR; +#define EGL_NO_IMAGE_KHR ((EGLImageKHR)0) +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLImageKHR EGLAPIENTRY eglCreateImageKHR (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroyImageKHR (EGLDisplay dpy, EGLImageKHR image); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEIMAGEKHRPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGLImageKHR image); +#endif + +#ifndef EGL_KHR_vg_parent_image +#define EGL_KHR_vg_parent_image 1 +#define EGL_VG_PARENT_IMAGE_KHR 0x30BA /* eglCreateImageKHR target */ +#endif + +#ifndef EGL_KHR_gl_texture_2D_image +#define EGL_KHR_gl_texture_2D_image 1 +#define EGL_GL_TEXTURE_2D_KHR 0x30B1 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_LEVEL_KHR 0x30BC /* eglCreateImageKHR attribute */ +#endif + +#ifndef EGL_KHR_gl_texture_cubemap_image +#define EGL_KHR_gl_texture_cubemap_image 1 +#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR 0x30B3 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR 0x30B4 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR 0x30B5 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR 0x30B6 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR 0x30B7 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR 0x30B8 /* eglCreateImageKHR target */ +#endif + +#ifndef EGL_KHR_gl_texture_3D_image +#define EGL_KHR_gl_texture_3D_image 1 +#define EGL_GL_TEXTURE_3D_KHR 0x30B2 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_ZOFFSET_KHR 0x30BD /* eglCreateImageKHR attribute */ +#endif + +#ifndef EGL_KHR_gl_renderbuffer_image +#define EGL_KHR_gl_renderbuffer_image 1 +#define EGL_GL_RENDERBUFFER_KHR 0x30B9 /* eglCreateImageKHR target */ +#endif + +#ifndef EGL_KHR_reusable_sync +#define EGL_KHR_reusable_sync 1 + +typedef void* EGLSyncKHR; +typedef khronos_utime_nanoseconds_t EGLTimeKHR; + +#define EGL_SYNC_STATUS_KHR 0x30F1 +#define EGL_SIGNALED_KHR 0x30F2 +#define EGL_UNSIGNALED_KHR 0x30F3 +#define EGL_TIMEOUT_EXPIRED_KHR 0x30F5 +#define EGL_CONDITION_SATISFIED_KHR 0x30F6 +#define EGL_SYNC_TYPE_KHR 0x30F7 +#define EGL_SYNC_REUSABLE_KHR 0x30FA +#define EGL_SYNC_FLUSH_COMMANDS_BIT_KHR 0x0001 /* eglClientWaitSyncKHR <flags> bitfield */ +#define EGL_FOREVER_KHR 0xFFFFFFFFFFFFFFFFull +#define EGL_NO_SYNC_KHR ((EGLSyncKHR)0) +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync); +EGLAPI EGLint EGLAPIENTRY eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout); +EGLAPI EGLBoolean EGLAPIENTRY eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode); +EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLSyncKHR (EGLAPIENTRYP PFNEGLCREATESYNCKHRPROC) (EGLDisplay dpy, EGLenum type, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync); +typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value); +#endif + +#ifndef EGL_KHR_image_base +#define EGL_KHR_image_base 1 +/* Most interfaces defined by EGL_KHR_image_pixmap above */ +#define EGL_IMAGE_PRESERVED_KHR 0x30D2 /* eglCreateImageKHR attribute */ +#endif + +#ifndef EGL_KHR_image_pixmap +#define EGL_KHR_image_pixmap 1 +/* Interfaces defined by EGL_KHR_image above */ +#endif + +#ifndef EGL_IMG_context_priority +#define EGL_IMG_context_priority 1 +#define EGL_CONTEXT_PRIORITY_LEVEL_IMG 0x3100 +#define EGL_CONTEXT_PRIORITY_HIGH_IMG 0x3101 +#define EGL_CONTEXT_PRIORITY_MEDIUM_IMG 0x3102 +#define EGL_CONTEXT_PRIORITY_LOW_IMG 0x3103 +#endif + +#ifndef EGL_NV_coverage_sample +#define EGL_NV_coverage_sample 1 +#define EGL_COVERAGE_BUFFERS_NV 0x30E0 +#define EGL_COVERAGE_SAMPLES_NV 0x30E1 +#endif + +#ifndef EGL_NV_depth_nonlinear +#define EGL_NV_depth_nonlinear 1 +#define EGL_DEPTH_ENCODING_NV 0x30E2 +#define EGL_DEPTH_ENCODING_NONE_NV 0 +#define EGL_DEPTH_ENCODING_NONLINEAR_NV 0x30E3 +#endif + +#ifndef EGL_NV_sync +#define EGL_NV_sync 1 +#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_NV 0x30E6 +#define EGL_SYNC_STATUS_NV 0x30E7 +#define EGL_SIGNALED_NV 0x30E8 +#define EGL_UNSIGNALED_NV 0x30E9 +#define EGL_SYNC_FLUSH_COMMANDS_BIT_NV 0x0001 +#define EGL_FOREVER_NV 0xFFFFFFFFFFFFFFFFull +#define EGL_ALREADY_SIGNALED_NV 0x30EA +#define EGL_TIMEOUT_EXPIRED_NV 0x30EB +#define EGL_CONDITION_SATISFIED_NV 0x30EC +#define EGL_SYNC_TYPE_NV 0x30ED +#define EGL_SYNC_CONDITION_NV 0x30EE +#define EGL_SYNC_FENCE_NV 0x30EF +#define EGL_NO_SYNC_NV ((EGLSyncNV)0) +typedef void* EGLSyncNV; +typedef unsigned long long EGLTimeNV; +#ifdef EGL_EGLEXT_PROTOTYPES +EGLSyncNV eglCreateFenceSyncNV (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list); +EGLBoolean eglDestroySyncNV (EGLSyncNV sync); +EGLBoolean eglFenceNV (EGLSyncNV sync); +EGLint eglClientWaitSyncNV (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout); +EGLBoolean eglSignalSyncNV (EGLSyncNV sync, EGLenum mode); +EGLBoolean eglGetSyncAttribNV (EGLSyncNV sync, EGLint attribute, EGLint *value); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLSyncNV (EGLAPIENTRYP PFNEGLCREATEFENCESYNCNVPROC) (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCNVPROC) (EGLSyncNV sync); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLFENCENVPROC) (EGLSyncNV sync); +typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCNVPROC) (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCNVPROC) (EGLSyncNV sync, EGLenum mode); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBNVPROC) (EGLSyncNV sync, EGLint attribute, EGLint *value); +#endif + +#ifndef EGL_KHR_fence_sync +#define EGL_KHR_fence_sync 1 +/* Reuses most tokens and entry points from EGL_KHR_reusable_sync */ +#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR 0x30F0 +#define EGL_SYNC_CONDITION_KHR 0x30F8 +#define EGL_SYNC_FENCE_KHR 0x30F9 +#endif + +#ifndef EGL_ANDROID_image_native_buffer +#define EGL_ANDROID_image_native_buffer 1 +struct android_native_buffer_t; +#define EGL_NATIVE_BUFFER_ANDROID 0x3140 /* eglCreateImageKHR target */ +#endif + +#ifndef EGL_ANDROID_swap_rectangle +#define EGL_ANDROID_swap_rectangle 1 +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglSetSwapRectangleANDROID (EGLDisplay dpy, EGLSurface draw, EGLint left, EGLint top, EGLint width, EGLint height); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSETSWAPRECTANGLEANDROIDPROC) (EGLDisplay dpy, EGLSurface draw, EGLint left, EGLint top, EGLint width, EGLint height); +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/emulator/opengl/host/libs/Translator/include/EGL/eglinternalplatform.h b/emulator/opengl/host/libs/Translator/include/EGL/eglinternalplatform.h new file mode 100644 index 0000000..953284a --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/EGL/eglinternalplatform.h @@ -0,0 +1,69 @@ +/* +* Copyright 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef EGL_INTERNAL_PLATFORM_H +#define EGL_INTERNAL_PLATFORM_H + +class SrfcInfo; //defined in Egl{$platform}Api.cpp +typedef SrfcInfo* SURFACE; +typedef SURFACE EGLNativeSurfaceType; + +#if defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */ +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif + +#include <GL/gl.h> +#define WGL_WGLEXT_PROTOTYPES +#include <GL/wglext.h> + +class WinDisplay; //defined in EglWindows.cpp +typedef WinDisplay* DISPLAY; + +typedef PIXELFORMATDESCRIPTOR EGLNativePixelFormatType; +#define PIXEL_FORMAT_INITIALIZER {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +typedef HGLRC EGLNativeContextType; +typedef HPBUFFERARB EGLNativePbufferType; +typedef DISPLAY EGLNativeInternalDisplayType; + +#elif defined(__APPLE__) + +typedef void* EGLNativePixelFormatType; +#define PIXEL_FORMAT_INITIALIZER NULL +typedef void* EGLNativeContextType; +typedef void* EGLNativePbufferType; +typedef EGLNativeDisplayType EGLNativeInternalDisplayType; + + +#elif defined(__unix__) + +/* X11 (tentative) */ +#include <GL/glx.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> + +typedef GLXFBConfig EGLNativePixelFormatType; +#define PIXEL_FORMAT_INITIALIZER 0; +typedef GLXContext EGLNativeContextType; +typedef GLXPbuffer EGLNativePbufferType; +typedef EGLNativeDisplayType EGLNativeInternalDisplayType; + +#else +#error "Platform not recognized" +#endif + + +#endif diff --git a/emulator/opengl/host/libs/Translator/include/EGL/eglplatform.h b/emulator/opengl/host/libs/Translator/include/EGL/eglplatform.h new file mode 100644 index 0000000..b159cd7 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/EGL/eglplatform.h @@ -0,0 +1,111 @@ +#ifndef __eglplatform_h_ +#define __eglplatform_h_ +/* +** Copyright (c) 2007-2009 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are 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 Materials. +** +** THE MATERIALS ARE 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 +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/* Platform-specific types and definitions for egl.h + * $Revision: 9724 $ on $Date: 2009-12-02 02:05:33 -0800 (Wed, 02 Dec 2009) $ + * + * Adopters may modify khrplatform.h and this file to suit their platform. + * You are encouraged to submit all modifications to the Khronos group so that + * they can be included in future versions of this file. Please submit changes + * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) + * by filing a bug against product "EGL" component "Registry". + */ +#include <KHR/khrplatform.h> + +/* Macros used in EGL function prototype declarations. + * + * EGL functions should be prototyped as: + * + * EGLAPI return-type EGLAPIENTRY eglFunction(arguments); + * typedef return-type (EXPAPIENTRYP PFNEGLFUNCTIONPROC) (arguments); + * + * KHRONOS_APICALL and KHRONOS_APIENTRY are defined in KHR/khrplatform.h + */ + +#ifndef EGLAPI +#define EGLAPI KHRONOS_APICALL +#endif + +#ifndef EGLAPIENTRY +#define EGLAPIENTRY KHRONOS_APIENTRY +#endif +#define EGLAPIENTRYP EGLAPIENTRY* + +/* The types NativeDisplayType, NativeWindowType, and NativePixmapType + * are aliases of window-system-dependent types, such as X Display * or + * Windows Device Context. They must be defined in platform-specific + * code below. The EGL-prefixed versions of Native*Type are the same + * types, renamed in EGL 1.3 so all types in the API start with "EGL". + */ + +#if defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */ +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif +#include <windows.h> + + + +typedef HDC EGLNativeDisplayType; +typedef HBITMAP EGLNativePixmapType; +typedef HWND EGLNativeWindowType; + +#elif defined(__APPLE__) + +typedef unsigned int EGLNativeDisplayType; +typedef void* EGLNativePixmapType; +typedef void* EGLNativeWindowType; + + +#elif defined(__unix__) + +/* X11 (tentative) */ +#include <X11/Xlib.h> +#include <X11/Xutil.h> + +typedef Display * EGLNativeDisplayType; +typedef Pixmap EGLNativePixmapType; +typedef Window EGLNativeWindowType; + +#else +#error "Platform not recognized" +#endif + +/* EGL 1.2 types, renamed for consistency in EGL 1.3 */ +typedef EGLNativeDisplayType NativeDisplayType; +typedef EGLNativePixmapType NativePixmapType; +typedef EGLNativeWindowType NativeWindowType; + + +/* Define EGLint. This must be a signed integral type large enough to contain + * all legal attribute names and values passed into and out of EGL, whether + * their type is boolean, bitmask, enumerant (symbolic constant), integer, + * handle, or other. While in general a 32-bit integer will suffice, if + * handles are 64 bit types, then EGLint should be defined as a signed 64-bit + * integer type. + */ +typedef khronos_int32_t EGLint; + +#endif /* __eglplatform_h */ diff --git a/emulator/opengl/host/libs/Translator/include/GL/wglext.h b/emulator/opengl/host/libs/Translator/include/GL/wglext.h new file mode 100644 index 0000000..8e06d93 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GL/wglext.h @@ -0,0 +1,901 @@ +#ifndef __wglext_h_ +#define __wglext_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** Copyright (c) 2007-2010 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are 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 Materials. +** +** THE MATERIALS ARE 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 +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +/* Function declaration macros - to move into glplatform.h */ + +#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) +#define WIN32_LEAN_AND_MEAN 1 +#include <windows.h> +#endif + +#ifndef APIENTRY +#define APIENTRY +#endif +#ifndef APIENTRYP +#define APIENTRYP APIENTRY * +#endif +#ifndef GLAPI +#define GLAPI extern +#endif + +/*************************************************************/ + +/* Header file version number */ +/* wglext.h last updated 2010/08/06 */ +/* Current version at http://www.opengl.org/registry/ */ +#define WGL_WGLEXT_VERSION 22 + +#ifndef WGL_ARB_buffer_region +#define WGL_FRONT_COLOR_BUFFER_BIT_ARB 0x00000001 +#define WGL_BACK_COLOR_BUFFER_BIT_ARB 0x00000002 +#define WGL_DEPTH_BUFFER_BIT_ARB 0x00000004 +#define WGL_STENCIL_BUFFER_BIT_ARB 0x00000008 +#endif + +#ifndef WGL_ARB_multisample +#define WGL_SAMPLE_BUFFERS_ARB 0x2041 +#define WGL_SAMPLES_ARB 0x2042 +#endif + +#ifndef WGL_ARB_extensions_string +#endif + +#ifndef WGL_ARB_pixel_format +#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 +#define WGL_DRAW_TO_WINDOW_ARB 0x2001 +#define WGL_DRAW_TO_BITMAP_ARB 0x2002 +#define WGL_ACCELERATION_ARB 0x2003 +#define WGL_NEED_PALETTE_ARB 0x2004 +#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005 +#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006 +#define WGL_SWAP_METHOD_ARB 0x2007 +#define WGL_NUMBER_OVERLAYS_ARB 0x2008 +#define WGL_NUMBER_UNDERLAYS_ARB 0x2009 +#define WGL_TRANSPARENT_ARB 0x200A +#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037 +#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038 +#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039 +#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A +#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B +#define WGL_SHARE_DEPTH_ARB 0x200C +#define WGL_SHARE_STENCIL_ARB 0x200D +#define WGL_SHARE_ACCUM_ARB 0x200E +#define WGL_SUPPORT_GDI_ARB 0x200F +#define WGL_SUPPORT_OPENGL_ARB 0x2010 +#define WGL_DOUBLE_BUFFER_ARB 0x2011 +#define WGL_STEREO_ARB 0x2012 +#define WGL_PIXEL_TYPE_ARB 0x2013 +#define WGL_COLOR_BITS_ARB 0x2014 +#define WGL_RED_BITS_ARB 0x2015 +#define WGL_RED_SHIFT_ARB 0x2016 +#define WGL_GREEN_BITS_ARB 0x2017 +#define WGL_GREEN_SHIFT_ARB 0x2018 +#define WGL_BLUE_BITS_ARB 0x2019 +#define WGL_BLUE_SHIFT_ARB 0x201A +#define WGL_ALPHA_BITS_ARB 0x201B +#define WGL_ALPHA_SHIFT_ARB 0x201C +#define WGL_ACCUM_BITS_ARB 0x201D +#define WGL_ACCUM_RED_BITS_ARB 0x201E +#define WGL_ACCUM_GREEN_BITS_ARB 0x201F +#define WGL_ACCUM_BLUE_BITS_ARB 0x2020 +#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021 +#define WGL_DEPTH_BITS_ARB 0x2022 +#define WGL_STENCIL_BITS_ARB 0x2023 +#define WGL_AUX_BUFFERS_ARB 0x2024 +#define WGL_NO_ACCELERATION_ARB 0x2025 +#define WGL_GENERIC_ACCELERATION_ARB 0x2026 +#define WGL_FULL_ACCELERATION_ARB 0x2027 +#define WGL_SWAP_EXCHANGE_ARB 0x2028 +#define WGL_SWAP_COPY_ARB 0x2029 +#define WGL_SWAP_UNDEFINED_ARB 0x202A +#define WGL_TYPE_RGBA_ARB 0x202B +#define WGL_TYPE_COLORINDEX_ARB 0x202C +#endif + +#ifndef WGL_ARB_make_current_read +#define ERROR_INVALID_PIXEL_TYPE_ARB 0x2043 +#define ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB 0x2054 +#endif + +#ifndef WGL_ARB_pbuffer +#define WGL_DRAW_TO_PBUFFER_ARB 0x202D +#define WGL_MAX_PBUFFER_PIXELS_ARB 0x202E +#define WGL_MAX_PBUFFER_WIDTH_ARB 0x202F +#define WGL_MAX_PBUFFER_HEIGHT_ARB 0x2030 +#define WGL_PBUFFER_LARGEST_ARB 0x2033 +#define WGL_PBUFFER_WIDTH_ARB 0x2034 +#define WGL_PBUFFER_HEIGHT_ARB 0x2035 +#define WGL_PBUFFER_LOST_ARB 0x2036 +#endif + +#ifndef WGL_ARB_render_texture +#define WGL_BIND_TO_TEXTURE_RGB_ARB 0x2070 +#define WGL_BIND_TO_TEXTURE_RGBA_ARB 0x2071 +#define WGL_TEXTURE_FORMAT_ARB 0x2072 +#define WGL_TEXTURE_TARGET_ARB 0x2073 +#define WGL_MIPMAP_TEXTURE_ARB 0x2074 +#define WGL_TEXTURE_RGB_ARB 0x2075 +#define WGL_TEXTURE_RGBA_ARB 0x2076 +#define WGL_NO_TEXTURE_ARB 0x2077 +#define WGL_TEXTURE_CUBE_MAP_ARB 0x2078 +#define WGL_TEXTURE_1D_ARB 0x2079 +#define WGL_TEXTURE_2D_ARB 0x207A +#define WGL_MIPMAP_LEVEL_ARB 0x207B +#define WGL_CUBE_MAP_FACE_ARB 0x207C +#define WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x207D +#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x207E +#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x207F +#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x2080 +#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x2081 +#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x2082 +#define WGL_FRONT_LEFT_ARB 0x2083 +#define WGL_FRONT_RIGHT_ARB 0x2084 +#define WGL_BACK_LEFT_ARB 0x2085 +#define WGL_BACK_RIGHT_ARB 0x2086 +#define WGL_AUX0_ARB 0x2087 +#define WGL_AUX1_ARB 0x2088 +#define WGL_AUX2_ARB 0x2089 +#define WGL_AUX3_ARB 0x208A +#define WGL_AUX4_ARB 0x208B +#define WGL_AUX5_ARB 0x208C +#define WGL_AUX6_ARB 0x208D +#define WGL_AUX7_ARB 0x208E +#define WGL_AUX8_ARB 0x208F +#define WGL_AUX9_ARB 0x2090 +#endif + +#ifndef WGL_ARB_pixel_format_float +#define WGL_TYPE_RGBA_FLOAT_ARB 0x21A0 +#endif + +#ifndef WGL_ARB_framebuffer_sRGB +#define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20A9 +#endif + +#ifndef WGL_ARB_create_context +#define WGL_CONTEXT_DEBUG_BIT_ARB 0x00000001 +#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 +#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 +#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 +#define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093 +#define WGL_CONTEXT_FLAGS_ARB 0x2094 +#define ERROR_INVALID_VERSION_ARB 0x2095 +#endif + +#ifndef WGL_ARB_create_context_profile +#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126 +#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 +#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 +#define ERROR_INVALID_PROFILE_ARB 0x2096 +#endif + +#ifndef WGL_ARB_create_context_robustness +#define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004 +#define WGL_LOSE_CONTEXT_ON_RESET_ARB 0x8252 +#define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 +#define WGL_NO_RESET_NOTIFICATION_ARB 0x8261 +#endif + +#ifndef WGL_EXT_make_current_read +#define ERROR_INVALID_PIXEL_TYPE_EXT 0x2043 +#endif + +#ifndef WGL_EXT_pixel_format +#define WGL_NUMBER_PIXEL_FORMATS_EXT 0x2000 +#define WGL_DRAW_TO_WINDOW_EXT 0x2001 +#define WGL_DRAW_TO_BITMAP_EXT 0x2002 +#define WGL_ACCELERATION_EXT 0x2003 +#define WGL_NEED_PALETTE_EXT 0x2004 +#define WGL_NEED_SYSTEM_PALETTE_EXT 0x2005 +#define WGL_SWAP_LAYER_BUFFERS_EXT 0x2006 +#define WGL_SWAP_METHOD_EXT 0x2007 +#define WGL_NUMBER_OVERLAYS_EXT 0x2008 +#define WGL_NUMBER_UNDERLAYS_EXT 0x2009 +#define WGL_TRANSPARENT_EXT 0x200A +#define WGL_TRANSPARENT_VALUE_EXT 0x200B +#define WGL_SHARE_DEPTH_EXT 0x200C +#define WGL_SHARE_STENCIL_EXT 0x200D +#define WGL_SHARE_ACCUM_EXT 0x200E +#define WGL_SUPPORT_GDI_EXT 0x200F +#define WGL_SUPPORT_OPENGL_EXT 0x2010 +#define WGL_DOUBLE_BUFFER_EXT 0x2011 +#define WGL_STEREO_EXT 0x2012 +#define WGL_PIXEL_TYPE_EXT 0x2013 +#define WGL_COLOR_BITS_EXT 0x2014 +#define WGL_RED_BITS_EXT 0x2015 +#define WGL_RED_SHIFT_EXT 0x2016 +#define WGL_GREEN_BITS_EXT 0x2017 +#define WGL_GREEN_SHIFT_EXT 0x2018 +#define WGL_BLUE_BITS_EXT 0x2019 +#define WGL_BLUE_SHIFT_EXT 0x201A +#define WGL_ALPHA_BITS_EXT 0x201B +#define WGL_ALPHA_SHIFT_EXT 0x201C +#define WGL_ACCUM_BITS_EXT 0x201D +#define WGL_ACCUM_RED_BITS_EXT 0x201E +#define WGL_ACCUM_GREEN_BITS_EXT 0x201F +#define WGL_ACCUM_BLUE_BITS_EXT 0x2020 +#define WGL_ACCUM_ALPHA_BITS_EXT 0x2021 +#define WGL_DEPTH_BITS_EXT 0x2022 +#define WGL_STENCIL_BITS_EXT 0x2023 +#define WGL_AUX_BUFFERS_EXT 0x2024 +#define WGL_NO_ACCELERATION_EXT 0x2025 +#define WGL_GENERIC_ACCELERATION_EXT 0x2026 +#define WGL_FULL_ACCELERATION_EXT 0x2027 +#define WGL_SWAP_EXCHANGE_EXT 0x2028 +#define WGL_SWAP_COPY_EXT 0x2029 +#define WGL_SWAP_UNDEFINED_EXT 0x202A +#define WGL_TYPE_RGBA_EXT 0x202B +#define WGL_TYPE_COLORINDEX_EXT 0x202C +#endif + +#ifndef WGL_EXT_pbuffer +#define WGL_DRAW_TO_PBUFFER_EXT 0x202D +#define WGL_MAX_PBUFFER_PIXELS_EXT 0x202E +#define WGL_MAX_PBUFFER_WIDTH_EXT 0x202F +#define WGL_MAX_PBUFFER_HEIGHT_EXT 0x2030 +#define WGL_OPTIMAL_PBUFFER_WIDTH_EXT 0x2031 +#define WGL_OPTIMAL_PBUFFER_HEIGHT_EXT 0x2032 +#define WGL_PBUFFER_LARGEST_EXT 0x2033 +#define WGL_PBUFFER_WIDTH_EXT 0x2034 +#define WGL_PBUFFER_HEIGHT_EXT 0x2035 +#endif + +#ifndef WGL_EXT_depth_float +#define WGL_DEPTH_FLOAT_EXT 0x2040 +#endif + +#ifndef WGL_3DFX_multisample +#define WGL_SAMPLE_BUFFERS_3DFX 0x2060 +#define WGL_SAMPLES_3DFX 0x2061 +#endif + +#ifndef WGL_EXT_multisample +#define WGL_SAMPLE_BUFFERS_EXT 0x2041 +#define WGL_SAMPLES_EXT 0x2042 +#endif + +#ifndef WGL_I3D_digital_video_control +#define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_FRAMEBUFFER_I3D 0x2050 +#define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_VALUE_I3D 0x2051 +#define WGL_DIGITAL_VIDEO_CURSOR_INCLUDED_I3D 0x2052 +#define WGL_DIGITAL_VIDEO_GAMMA_CORRECTED_I3D 0x2053 +#endif + +#ifndef WGL_I3D_gamma +#define WGL_GAMMA_TABLE_SIZE_I3D 0x204E +#define WGL_GAMMA_EXCLUDE_DESKTOP_I3D 0x204F +#endif + +#ifndef WGL_I3D_genlock +#define WGL_GENLOCK_SOURCE_MULTIVIEW_I3D 0x2044 +#define WGL_GENLOCK_SOURCE_EXTENAL_SYNC_I3D 0x2045 +#define WGL_GENLOCK_SOURCE_EXTENAL_FIELD_I3D 0x2046 +#define WGL_GENLOCK_SOURCE_EXTENAL_TTL_I3D 0x2047 +#define WGL_GENLOCK_SOURCE_DIGITAL_SYNC_I3D 0x2048 +#define WGL_GENLOCK_SOURCE_DIGITAL_FIELD_I3D 0x2049 +#define WGL_GENLOCK_SOURCE_EDGE_FALLING_I3D 0x204A +#define WGL_GENLOCK_SOURCE_EDGE_RISING_I3D 0x204B +#define WGL_GENLOCK_SOURCE_EDGE_BOTH_I3D 0x204C +#endif + +#ifndef WGL_I3D_image_buffer +#define WGL_IMAGE_BUFFER_MIN_ACCESS_I3D 0x00000001 +#define WGL_IMAGE_BUFFER_LOCK_I3D 0x00000002 +#endif + +#ifndef WGL_I3D_swap_frame_lock +#endif + +#ifndef WGL_NV_render_depth_texture +#define WGL_BIND_TO_TEXTURE_DEPTH_NV 0x20A3 +#define WGL_BIND_TO_TEXTURE_RECTANGLE_DEPTH_NV 0x20A4 +#define WGL_DEPTH_TEXTURE_FORMAT_NV 0x20A5 +#define WGL_TEXTURE_DEPTH_COMPONENT_NV 0x20A6 +#define WGL_DEPTH_COMPONENT_NV 0x20A7 +#endif + +#ifndef WGL_NV_render_texture_rectangle +#define WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV 0x20A0 +#define WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV 0x20A1 +#define WGL_TEXTURE_RECTANGLE_NV 0x20A2 +#endif + +#ifndef WGL_ATI_pixel_format_float +#define WGL_TYPE_RGBA_FLOAT_ATI 0x21A0 +#endif + +#ifndef WGL_NV_float_buffer +#define WGL_FLOAT_COMPONENTS_NV 0x20B0 +#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV 0x20B1 +#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV 0x20B2 +#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV 0x20B3 +#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV 0x20B4 +#define WGL_TEXTURE_FLOAT_R_NV 0x20B5 +#define WGL_TEXTURE_FLOAT_RG_NV 0x20B6 +#define WGL_TEXTURE_FLOAT_RGB_NV 0x20B7 +#define WGL_TEXTURE_FLOAT_RGBA_NV 0x20B8 +#endif + +#ifndef WGL_3DL_stereo_control +#define WGL_STEREO_EMITTER_ENABLE_3DL 0x2055 +#define WGL_STEREO_EMITTER_DISABLE_3DL 0x2056 +#define WGL_STEREO_POLARITY_NORMAL_3DL 0x2057 +#define WGL_STEREO_POLARITY_INVERT_3DL 0x2058 +#endif + +#ifndef WGL_EXT_pixel_format_packed_float +#define WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT 0x20A8 +#endif + +#ifndef WGL_EXT_framebuffer_sRGB +#define WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20A9 +#endif + +#ifndef WGL_NV_present_video +#define WGL_NUM_VIDEO_SLOTS_NV 0x20F0 +#endif + +#ifndef WGL_NV_video_out +#define WGL_BIND_TO_VIDEO_RGB_NV 0x20C0 +#define WGL_BIND_TO_VIDEO_RGBA_NV 0x20C1 +#define WGL_BIND_TO_VIDEO_RGB_AND_DEPTH_NV 0x20C2 +#define WGL_VIDEO_OUT_COLOR_NV 0x20C3 +#define WGL_VIDEO_OUT_ALPHA_NV 0x20C4 +#define WGL_VIDEO_OUT_DEPTH_NV 0x20C5 +#define WGL_VIDEO_OUT_COLOR_AND_ALPHA_NV 0x20C6 +#define WGL_VIDEO_OUT_COLOR_AND_DEPTH_NV 0x20C7 +#define WGL_VIDEO_OUT_FRAME 0x20C8 +#define WGL_VIDEO_OUT_FIELD_1 0x20C9 +#define WGL_VIDEO_OUT_FIELD_2 0x20CA +#define WGL_VIDEO_OUT_STACKED_FIELDS_1_2 0x20CB +#define WGL_VIDEO_OUT_STACKED_FIELDS_2_1 0x20CC +#endif + +#ifndef WGL_NV_swap_group +#endif + +#ifndef WGL_NV_gpu_affinity +#define WGL_ERROR_INCOMPATIBLE_AFFINITY_MASKS_NV 0x20D0 +#define WGL_ERROR_MISSING_AFFINITY_MASK_NV 0x20D1 +#endif + +#ifndef WGL_AMD_gpu_association +#define WGL_GPU_VENDOR_AMD 0x1F00 +#define WGL_GPU_RENDERER_STRING_AMD 0x1F01 +#define WGL_GPU_OPENGL_VERSION_STRING_AMD 0x1F02 +#define WGL_GPU_FASTEST_TARGET_GPUS_AMD 0x21A2 +#define WGL_GPU_RAM_AMD 0x21A3 +#define WGL_GPU_CLOCK_AMD 0x21A4 +#define WGL_GPU_NUM_PIPES_AMD 0x21A5 +#define WGL_GPU_NUM_SIMD_AMD 0x21A6 +#define WGL_GPU_NUM_RB_AMD 0x21A7 +#define WGL_GPU_NUM_SPI_AMD 0x21A8 +#endif + +#ifndef WGL_NV_video_capture +#define WGL_UNIQUE_ID_NV 0x20CE +#define WGL_NUM_VIDEO_CAPTURE_SLOTS_NV 0x20CF +#endif + +#ifndef WGL_NV_copy_image +#endif + +#ifndef WGL_NV_multisample_coverage +#define WGL_COVERAGE_SAMPLES_NV 0x2042 +#define WGL_COLOR_SAMPLES_NV 0x20B9 +#endif + +#ifndef WGL_EXT_create_context_es2_profile +#define WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 +#endif + + +/*************************************************************/ + +#ifndef WGL_ARB_pbuffer +DECLARE_HANDLE(HPBUFFERARB); +#endif +#ifndef WGL_EXT_pbuffer +DECLARE_HANDLE(HPBUFFEREXT); +#endif +#ifndef WGL_NV_present_video +DECLARE_HANDLE(HVIDEOOUTPUTDEVICENV); +#endif +#ifndef WGL_NV_video_output +DECLARE_HANDLE(HPVIDEODEV); +#endif +#ifndef WGL_NV_gpu_affinity +DECLARE_HANDLE(HPGPUNV); +DECLARE_HANDLE(HGPUNV); + +typedef struct _GPU_DEVICE { + DWORD cb; + CHAR DeviceName[32]; + CHAR DeviceString[128]; + DWORD Flags; + RECT rcVirtualScreen; +} GPU_DEVICE, *PGPU_DEVICE; +#endif +#ifndef WGL_NV_video_capture +DECLARE_HANDLE(HVIDEOINPUTDEVICENV); +#endif + +#ifndef WGL_ARB_buffer_region +#define WGL_ARB_buffer_region 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern HANDLE WINAPI wglCreateBufferRegionARB (HDC hDC, int iLayerPlane, UINT uType); +extern VOID WINAPI wglDeleteBufferRegionARB (HANDLE hRegion); +extern BOOL WINAPI wglSaveBufferRegionARB (HANDLE hRegion, int x, int y, int width, int height); +extern BOOL WINAPI wglRestoreBufferRegionARB (HANDLE hRegion, int x, int y, int width, int height, int xSrc, int ySrc); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef HANDLE (WINAPI * PFNWGLCREATEBUFFERREGIONARBPROC) (HDC hDC, int iLayerPlane, UINT uType); +typedef VOID (WINAPI * PFNWGLDELETEBUFFERREGIONARBPROC) (HANDLE hRegion); +typedef BOOL (WINAPI * PFNWGLSAVEBUFFERREGIONARBPROC) (HANDLE hRegion, int x, int y, int width, int height); +typedef BOOL (WINAPI * PFNWGLRESTOREBUFFERREGIONARBPROC) (HANDLE hRegion, int x, int y, int width, int height, int xSrc, int ySrc); +#endif + +#ifndef WGL_ARB_multisample +#define WGL_ARB_multisample 1 +#endif + +#ifndef WGL_ARB_extensions_string +#define WGL_ARB_extensions_string 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern const char * WINAPI wglGetExtensionsStringARB (HDC hdc); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc); +#endif + +#ifndef WGL_ARB_pixel_format +#define WGL_ARB_pixel_format 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglGetPixelFormatAttribivARB (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues); +extern BOOL WINAPI wglGetPixelFormatAttribfvARB (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues); +extern BOOL WINAPI wglChoosePixelFormatARB (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues); +typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues); +typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); +#endif + +#ifndef WGL_ARB_make_current_read +#define WGL_ARB_make_current_read 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglMakeContextCurrentARB (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); +extern HDC WINAPI wglGetCurrentReadDCARB (void); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLMAKECONTEXTCURRENTARBPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); +typedef HDC (WINAPI * PFNWGLGETCURRENTREADDCARBPROC) (void); +#endif + +#ifndef WGL_ARB_pbuffer +#define WGL_ARB_pbuffer 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern HPBUFFERARB WINAPI wglCreatePbufferARB (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList); +extern HDC WINAPI wglGetPbufferDCARB (HPBUFFERARB hPbuffer); +extern int WINAPI wglReleasePbufferDCARB (HPBUFFERARB hPbuffer, HDC hDC); +extern BOOL WINAPI wglDestroyPbufferARB (HPBUFFERARB hPbuffer); +extern BOOL WINAPI wglQueryPbufferARB (HPBUFFERARB hPbuffer, int iAttribute, int *piValue); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef HPBUFFERARB (WINAPI * PFNWGLCREATEPBUFFERARBPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList); +typedef HDC (WINAPI * PFNWGLGETPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer); +typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer, HDC hDC); +typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFERARBPROC) (HPBUFFERARB hPbuffer); +typedef BOOL (WINAPI * PFNWGLQUERYPBUFFERARBPROC) (HPBUFFERARB hPbuffer, int iAttribute, int *piValue); +#endif + +#ifndef WGL_ARB_render_texture +#define WGL_ARB_render_texture 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglBindTexImageARB (HPBUFFERARB hPbuffer, int iBuffer); +extern BOOL WINAPI wglReleaseTexImageARB (HPBUFFERARB hPbuffer, int iBuffer); +extern BOOL WINAPI wglSetPbufferAttribARB (HPBUFFERARB hPbuffer, const int *piAttribList); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLBINDTEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer); +typedef BOOL (WINAPI * PFNWGLRELEASETEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer); +typedef BOOL (WINAPI * PFNWGLSETPBUFFERATTRIBARBPROC) (HPBUFFERARB hPbuffer, const int *piAttribList); +#endif + +#ifndef WGL_ARB_pixel_format_float +#define WGL_ARB_pixel_format_float 1 +#endif + +#ifndef WGL_ARB_framebuffer_sRGB +#define WGL_ARB_framebuffer_sRGB 1 +#endif + +#ifndef WGL_ARB_create_context +#define WGL_ARB_create_context 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern HGLRC WINAPI wglCreateContextAttribsARB (HDC hDC, HGLRC hShareContext, const int *attribList); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int *attribList); +#endif + +#ifndef WGL_ARB_create_context_profile +#define WGL_ARB_create_context_profile 1 +#endif + +#ifndef WGL_ARB_create_context_robustness +#define WGL_ARB_create_context_robustness 1 +#endif + +#ifndef WGL_EXT_display_color_table +#define WGL_EXT_display_color_table 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern GLboolean WINAPI wglCreateDisplayColorTableEXT (GLushort id); +extern GLboolean WINAPI wglLoadDisplayColorTableEXT (const GLushort *table, GLuint length); +extern GLboolean WINAPI wglBindDisplayColorTableEXT (GLushort id); +extern VOID WINAPI wglDestroyDisplayColorTableEXT (GLushort id); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef GLboolean (WINAPI * PFNWGLCREATEDISPLAYCOLORTABLEEXTPROC) (GLushort id); +typedef GLboolean (WINAPI * PFNWGLLOADDISPLAYCOLORTABLEEXTPROC) (const GLushort *table, GLuint length); +typedef GLboolean (WINAPI * PFNWGLBINDDISPLAYCOLORTABLEEXTPROC) (GLushort id); +typedef VOID (WINAPI * PFNWGLDESTROYDISPLAYCOLORTABLEEXTPROC) (GLushort id); +#endif + +#ifndef WGL_EXT_extensions_string +#define WGL_EXT_extensions_string 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern const char * WINAPI wglGetExtensionsStringEXT (void); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGEXTPROC) (void); +#endif + +#ifndef WGL_EXT_make_current_read +#define WGL_EXT_make_current_read 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglMakeContextCurrentEXT (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); +extern HDC WINAPI wglGetCurrentReadDCEXT (void); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLMAKECONTEXTCURRENTEXTPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); +typedef HDC (WINAPI * PFNWGLGETCURRENTREADDCEXTPROC) (void); +#endif + +#ifndef WGL_EXT_pbuffer +#define WGL_EXT_pbuffer 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern HPBUFFEREXT WINAPI wglCreatePbufferEXT (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList); +extern HDC WINAPI wglGetPbufferDCEXT (HPBUFFEREXT hPbuffer); +extern int WINAPI wglReleasePbufferDCEXT (HPBUFFEREXT hPbuffer, HDC hDC); +extern BOOL WINAPI wglDestroyPbufferEXT (HPBUFFEREXT hPbuffer); +extern BOOL WINAPI wglQueryPbufferEXT (HPBUFFEREXT hPbuffer, int iAttribute, int *piValue); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef HPBUFFEREXT (WINAPI * PFNWGLCREATEPBUFFEREXTPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList); +typedef HDC (WINAPI * PFNWGLGETPBUFFERDCEXTPROC) (HPBUFFEREXT hPbuffer); +typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCEXTPROC) (HPBUFFEREXT hPbuffer, HDC hDC); +typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFEREXTPROC) (HPBUFFEREXT hPbuffer); +typedef BOOL (WINAPI * PFNWGLQUERYPBUFFEREXTPROC) (HPBUFFEREXT hPbuffer, int iAttribute, int *piValue); +#endif + +#ifndef WGL_EXT_pixel_format +#define WGL_EXT_pixel_format 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglGetPixelFormatAttribivEXT (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, int *piValues); +extern BOOL WINAPI wglGetPixelFormatAttribfvEXT (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, FLOAT *pfValues); +extern BOOL WINAPI wglChoosePixelFormatEXT (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVEXTPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, int *piValues); +typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVEXTPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, FLOAT *pfValues); +typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATEXTPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); +#endif + +#ifndef WGL_EXT_swap_control +#define WGL_EXT_swap_control 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglSwapIntervalEXT (int interval); +extern int WINAPI wglGetSwapIntervalEXT (void); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval); +typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void); +#endif + +#ifndef WGL_EXT_depth_float +#define WGL_EXT_depth_float 1 +#endif + +#ifndef WGL_NV_vertex_array_range +#define WGL_NV_vertex_array_range 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern void* WINAPI wglAllocateMemoryNV (GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority); +extern void WINAPI wglFreeMemoryNV (void *pointer); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef void* (WINAPI * PFNWGLALLOCATEMEMORYNVPROC) (GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority); +typedef void (WINAPI * PFNWGLFREEMEMORYNVPROC) (void *pointer); +#endif + +#ifndef WGL_3DFX_multisample +#define WGL_3DFX_multisample 1 +#endif + +#ifndef WGL_EXT_multisample +#define WGL_EXT_multisample 1 +#endif + +#ifndef WGL_OML_sync_control +#define WGL_OML_sync_control 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglGetSyncValuesOML (HDC hdc, INT64 *ust, INT64 *msc, INT64 *sbc); +extern BOOL WINAPI wglGetMscRateOML (HDC hdc, INT32 *numerator, INT32 *denominator); +extern INT64 WINAPI wglSwapBuffersMscOML (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder); +extern INT64 WINAPI wglSwapLayerBuffersMscOML (HDC hdc, int fuPlanes, INT64 target_msc, INT64 divisor, INT64 remainder); +extern BOOL WINAPI wglWaitForMscOML (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder, INT64 *ust, INT64 *msc, INT64 *sbc); +extern BOOL WINAPI wglWaitForSbcOML (HDC hdc, INT64 target_sbc, INT64 *ust, INT64 *msc, INT64 *sbc); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLGETSYNCVALUESOMLPROC) (HDC hdc, INT64 *ust, INT64 *msc, INT64 *sbc); +typedef BOOL (WINAPI * PFNWGLGETMSCRATEOMLPROC) (HDC hdc, INT32 *numerator, INT32 *denominator); +typedef INT64 (WINAPI * PFNWGLSWAPBUFFERSMSCOMLPROC) (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder); +typedef INT64 (WINAPI * PFNWGLSWAPLAYERBUFFERSMSCOMLPROC) (HDC hdc, int fuPlanes, INT64 target_msc, INT64 divisor, INT64 remainder); +typedef BOOL (WINAPI * PFNWGLWAITFORMSCOMLPROC) (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder, INT64 *ust, INT64 *msc, INT64 *sbc); +typedef BOOL (WINAPI * PFNWGLWAITFORSBCOMLPROC) (HDC hdc, INT64 target_sbc, INT64 *ust, INT64 *msc, INT64 *sbc); +#endif + +#ifndef WGL_I3D_digital_video_control +#define WGL_I3D_digital_video_control 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglGetDigitalVideoParametersI3D (HDC hDC, int iAttribute, int *piValue); +extern BOOL WINAPI wglSetDigitalVideoParametersI3D (HDC hDC, int iAttribute, const int *piValue); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLGETDIGITALVIDEOPARAMETERSI3DPROC) (HDC hDC, int iAttribute, int *piValue); +typedef BOOL (WINAPI * PFNWGLSETDIGITALVIDEOPARAMETERSI3DPROC) (HDC hDC, int iAttribute, const int *piValue); +#endif + +#ifndef WGL_I3D_gamma +#define WGL_I3D_gamma 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglGetGammaTableParametersI3D (HDC hDC, int iAttribute, int *piValue); +extern BOOL WINAPI wglSetGammaTableParametersI3D (HDC hDC, int iAttribute, const int *piValue); +extern BOOL WINAPI wglGetGammaTableI3D (HDC hDC, int iEntries, USHORT *puRed, USHORT *puGreen, USHORT *puBlue); +extern BOOL WINAPI wglSetGammaTableI3D (HDC hDC, int iEntries, const USHORT *puRed, const USHORT *puGreen, const USHORT *puBlue); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLGETGAMMATABLEPARAMETERSI3DPROC) (HDC hDC, int iAttribute, int *piValue); +typedef BOOL (WINAPI * PFNWGLSETGAMMATABLEPARAMETERSI3DPROC) (HDC hDC, int iAttribute, const int *piValue); +typedef BOOL (WINAPI * PFNWGLGETGAMMATABLEI3DPROC) (HDC hDC, int iEntries, USHORT *puRed, USHORT *puGreen, USHORT *puBlue); +typedef BOOL (WINAPI * PFNWGLSETGAMMATABLEI3DPROC) (HDC hDC, int iEntries, const USHORT *puRed, const USHORT *puGreen, const USHORT *puBlue); +#endif + +#ifndef WGL_I3D_genlock +#define WGL_I3D_genlock 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglEnableGenlockI3D (HDC hDC); +extern BOOL WINAPI wglDisableGenlockI3D (HDC hDC); +extern BOOL WINAPI wglIsEnabledGenlockI3D (HDC hDC, BOOL *pFlag); +extern BOOL WINAPI wglGenlockSourceI3D (HDC hDC, UINT uSource); +extern BOOL WINAPI wglGetGenlockSourceI3D (HDC hDC, UINT *uSource); +extern BOOL WINAPI wglGenlockSourceEdgeI3D (HDC hDC, UINT uEdge); +extern BOOL WINAPI wglGetGenlockSourceEdgeI3D (HDC hDC, UINT *uEdge); +extern BOOL WINAPI wglGenlockSampleRateI3D (HDC hDC, UINT uRate); +extern BOOL WINAPI wglGetGenlockSampleRateI3D (HDC hDC, UINT *uRate); +extern BOOL WINAPI wglGenlockSourceDelayI3D (HDC hDC, UINT uDelay); +extern BOOL WINAPI wglGetGenlockSourceDelayI3D (HDC hDC, UINT *uDelay); +extern BOOL WINAPI wglQueryGenlockMaxSourceDelayI3D (HDC hDC, UINT *uMaxLineDelay, UINT *uMaxPixelDelay); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLENABLEGENLOCKI3DPROC) (HDC hDC); +typedef BOOL (WINAPI * PFNWGLDISABLEGENLOCKI3DPROC) (HDC hDC); +typedef BOOL (WINAPI * PFNWGLISENABLEDGENLOCKI3DPROC) (HDC hDC, BOOL *pFlag); +typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEI3DPROC) (HDC hDC, UINT uSource); +typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEI3DPROC) (HDC hDC, UINT *uSource); +typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEEDGEI3DPROC) (HDC hDC, UINT uEdge); +typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEEDGEI3DPROC) (HDC hDC, UINT *uEdge); +typedef BOOL (WINAPI * PFNWGLGENLOCKSAMPLERATEI3DPROC) (HDC hDC, UINT uRate); +typedef BOOL (WINAPI * PFNWGLGETGENLOCKSAMPLERATEI3DPROC) (HDC hDC, UINT *uRate); +typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEDELAYI3DPROC) (HDC hDC, UINT uDelay); +typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEDELAYI3DPROC) (HDC hDC, UINT *uDelay); +typedef BOOL (WINAPI * PFNWGLQUERYGENLOCKMAXSOURCEDELAYI3DPROC) (HDC hDC, UINT *uMaxLineDelay, UINT *uMaxPixelDelay); +#endif + +#ifndef WGL_I3D_image_buffer +#define WGL_I3D_image_buffer 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern LPVOID WINAPI wglCreateImageBufferI3D (HDC hDC, DWORD dwSize, UINT uFlags); +extern BOOL WINAPI wglDestroyImageBufferI3D (HDC hDC, LPVOID pAddress); +extern BOOL WINAPI wglAssociateImageBufferEventsI3D (HDC hDC, const HANDLE *pEvent, const LPVOID *pAddress, const DWORD *pSize, UINT count); +extern BOOL WINAPI wglReleaseImageBufferEventsI3D (HDC hDC, const LPVOID *pAddress, UINT count); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef LPVOID (WINAPI * PFNWGLCREATEIMAGEBUFFERI3DPROC) (HDC hDC, DWORD dwSize, UINT uFlags); +typedef BOOL (WINAPI * PFNWGLDESTROYIMAGEBUFFERI3DPROC) (HDC hDC, LPVOID pAddress); +typedef BOOL (WINAPI * PFNWGLASSOCIATEIMAGEBUFFEREVENTSI3DPROC) (HDC hDC, const HANDLE *pEvent, const LPVOID *pAddress, const DWORD *pSize, UINT count); +typedef BOOL (WINAPI * PFNWGLRELEASEIMAGEBUFFEREVENTSI3DPROC) (HDC hDC, const LPVOID *pAddress, UINT count); +#endif + +#ifndef WGL_I3D_swap_frame_lock +#define WGL_I3D_swap_frame_lock 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglEnableFrameLockI3D (void); +extern BOOL WINAPI wglDisableFrameLockI3D (void); +extern BOOL WINAPI wglIsEnabledFrameLockI3D (BOOL *pFlag); +extern BOOL WINAPI wglQueryFrameLockMasterI3D (BOOL *pFlag); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLENABLEFRAMELOCKI3DPROC) (void); +typedef BOOL (WINAPI * PFNWGLDISABLEFRAMELOCKI3DPROC) (void); +typedef BOOL (WINAPI * PFNWGLISENABLEDFRAMELOCKI3DPROC) (BOOL *pFlag); +typedef BOOL (WINAPI * PFNWGLQUERYFRAMELOCKMASTERI3DPROC) (BOOL *pFlag); +#endif + +#ifndef WGL_I3D_swap_frame_usage +#define WGL_I3D_swap_frame_usage 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglGetFrameUsageI3D (float *pUsage); +extern BOOL WINAPI wglBeginFrameTrackingI3D (void); +extern BOOL WINAPI wglEndFrameTrackingI3D (void); +extern BOOL WINAPI wglQueryFrameTrackingI3D (DWORD *pFrameCount, DWORD *pMissedFrames, float *pLastMissedUsage); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLGETFRAMEUSAGEI3DPROC) (float *pUsage); +typedef BOOL (WINAPI * PFNWGLBEGINFRAMETRACKINGI3DPROC) (void); +typedef BOOL (WINAPI * PFNWGLENDFRAMETRACKINGI3DPROC) (void); +typedef BOOL (WINAPI * PFNWGLQUERYFRAMETRACKINGI3DPROC) (DWORD *pFrameCount, DWORD *pMissedFrames, float *pLastMissedUsage); +#endif + +#ifndef WGL_ATI_pixel_format_float +#define WGL_ATI_pixel_format_float 1 +#endif + +#ifndef WGL_NV_float_buffer +#define WGL_NV_float_buffer 1 +#endif + +#ifndef WGL_3DL_stereo_control +#define WGL_3DL_stereo_control 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglSetStereoEmitterState3DL (HDC hDC, UINT uState); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLSETSTEREOEMITTERSTATE3DLPROC) (HDC hDC, UINT uState); +#endif + +#ifndef WGL_EXT_pixel_format_packed_float +#define WGL_EXT_pixel_format_packed_float 1 +#endif + +#ifndef WGL_EXT_framebuffer_sRGB +#define WGL_EXT_framebuffer_sRGB 1 +#endif + +#ifndef WGL_NV_present_video +#define WGL_NV_present_video 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern int WINAPI wglEnumerateVideoDevicesNV (HDC hDC, HVIDEOOUTPUTDEVICENV *phDeviceList); +extern BOOL WINAPI wglBindVideoDeviceNV (HDC hDC, unsigned int uVideoSlot, HVIDEOOUTPUTDEVICENV hVideoDevice, const int *piAttribList); +extern BOOL WINAPI wglQueryCurrentContextNV (int iAttribute, int *piValue); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef int (WINAPI * PFNWGLENUMERATEVIDEODEVICESNVPROC) (HDC hDC, HVIDEOOUTPUTDEVICENV *phDeviceList); +typedef BOOL (WINAPI * PFNWGLBINDVIDEODEVICENVPROC) (HDC hDC, unsigned int uVideoSlot, HVIDEOOUTPUTDEVICENV hVideoDevice, const int *piAttribList); +typedef BOOL (WINAPI * PFNWGLQUERYCURRENTCONTEXTNVPROC) (int iAttribute, int *piValue); +#endif + +#ifndef WGL_NV_video_output +#define WGL_NV_video_output 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglGetVideoDeviceNV (HDC hDC, int numDevices, HPVIDEODEV *hVideoDevice); +extern BOOL WINAPI wglReleaseVideoDeviceNV (HPVIDEODEV hVideoDevice); +extern BOOL WINAPI wglBindVideoImageNV (HPVIDEODEV hVideoDevice, HPBUFFERARB hPbuffer, int iVideoBuffer); +extern BOOL WINAPI wglReleaseVideoImageNV (HPBUFFERARB hPbuffer, int iVideoBuffer); +extern BOOL WINAPI wglSendPbufferToVideoNV (HPBUFFERARB hPbuffer, int iBufferType, unsigned long *pulCounterPbuffer, BOOL bBlock); +extern BOOL WINAPI wglGetVideoInfoNV (HPVIDEODEV hpVideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLGETVIDEODEVICENVPROC) (HDC hDC, int numDevices, HPVIDEODEV *hVideoDevice); +typedef BOOL (WINAPI * PFNWGLRELEASEVIDEODEVICENVPROC) (HPVIDEODEV hVideoDevice); +typedef BOOL (WINAPI * PFNWGLBINDVIDEOIMAGENVPROC) (HPVIDEODEV hVideoDevice, HPBUFFERARB hPbuffer, int iVideoBuffer); +typedef BOOL (WINAPI * PFNWGLRELEASEVIDEOIMAGENVPROC) (HPBUFFERARB hPbuffer, int iVideoBuffer); +typedef BOOL (WINAPI * PFNWGLSENDPBUFFERTOVIDEONVPROC) (HPBUFFERARB hPbuffer, int iBufferType, unsigned long *pulCounterPbuffer, BOOL bBlock); +typedef BOOL (WINAPI * PFNWGLGETVIDEOINFONVPROC) (HPVIDEODEV hpVideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo); +#endif + +#ifndef WGL_NV_swap_group +#define WGL_NV_swap_group 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglJoinSwapGroupNV (HDC hDC, GLuint group); +extern BOOL WINAPI wglBindSwapBarrierNV (GLuint group, GLuint barrier); +extern BOOL WINAPI wglQuerySwapGroupNV (HDC hDC, GLuint *group, GLuint *barrier); +extern BOOL WINAPI wglQueryMaxSwapGroupsNV (HDC hDC, GLuint *maxGroups, GLuint *maxBarriers); +extern BOOL WINAPI wglQueryFrameCountNV (HDC hDC, GLuint *count); +extern BOOL WINAPI wglResetFrameCountNV (HDC hDC); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLJOINSWAPGROUPNVPROC) (HDC hDC, GLuint group); +typedef BOOL (WINAPI * PFNWGLBINDSWAPBARRIERNVPROC) (GLuint group, GLuint barrier); +typedef BOOL (WINAPI * PFNWGLQUERYSWAPGROUPNVPROC) (HDC hDC, GLuint *group, GLuint *barrier); +typedef BOOL (WINAPI * PFNWGLQUERYMAXSWAPGROUPSNVPROC) (HDC hDC, GLuint *maxGroups, GLuint *maxBarriers); +typedef BOOL (WINAPI * PFNWGLQUERYFRAMECOUNTNVPROC) (HDC hDC, GLuint *count); +typedef BOOL (WINAPI * PFNWGLRESETFRAMECOUNTNVPROC) (HDC hDC); +#endif + +#ifndef WGL_NV_gpu_affinity +#define WGL_NV_gpu_affinity 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglEnumGpusNV (UINT iGpuIndex, HGPUNV *phGpu); +extern BOOL WINAPI wglEnumGpuDevicesNV (HGPUNV hGpu, UINT iDeviceIndex, PGPU_DEVICE lpGpuDevice); +extern HDC WINAPI wglCreateAffinityDCNV (const HGPUNV *phGpuList); +extern BOOL WINAPI wglEnumGpusFromAffinityDCNV (HDC hAffinityDC, UINT iGpuIndex, HGPUNV *hGpu); +extern BOOL WINAPI wglDeleteDCNV (HDC hdc); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLENUMGPUSNVPROC) (UINT iGpuIndex, HGPUNV *phGpu); +typedef BOOL (WINAPI * PFNWGLENUMGPUDEVICESNVPROC) (HGPUNV hGpu, UINT iDeviceIndex, PGPU_DEVICE lpGpuDevice); +typedef HDC (WINAPI * PFNWGLCREATEAFFINITYDCNVPROC) (const HGPUNV *phGpuList); +typedef BOOL (WINAPI * PFNWGLENUMGPUSFROMAFFINITYDCNVPROC) (HDC hAffinityDC, UINT iGpuIndex, HGPUNV *hGpu); +typedef BOOL (WINAPI * PFNWGLDELETEDCNVPROC) (HDC hdc); +#endif + +#ifndef WGL_AMD_gpu_association +#define WGL_AMD_gpu_association 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern UINT WINAPI wglGetGPUIDsAMD (UINT maxCount, UINT *ids); +extern INT WINAPI wglGetGPUInfoAMD (UINT id, int property, GLenum dataType, UINT size, void *data); +extern UINT WINAPI wglGetContextGPUIDAMD (HGLRC hglrc); +extern HGLRC WINAPI wglCreateAssociatedContextAMD (UINT id); +extern HGLRC WINAPI wglCreateAssociatedContextAttribsAMD (UINT id, HGLRC hShareContext, const int *attribList); +extern BOOL WINAPI wglDeleteAssociatedContextAMD (HGLRC hglrc); +extern BOOL WINAPI wglMakeAssociatedContextCurrentAMD (HGLRC hglrc); +extern HGLRC WINAPI wglGetCurrentAssociatedContextAMD (void); +extern VOID WINAPI wglBlitContextFramebufferAMD (HGLRC dstCtx, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef UINT (WINAPI * PFNWGLGETGPUIDSAMDPROC) (UINT maxCount, UINT *ids); +typedef INT (WINAPI * PFNWGLGETGPUINFOAMDPROC) (UINT id, int property, GLenum dataType, UINT size, void *data); +typedef UINT (WINAPI * PFNWGLGETCONTEXTGPUIDAMDPROC) (HGLRC hglrc); +typedef HGLRC (WINAPI * PFNWGLCREATEASSOCIATEDCONTEXTAMDPROC) (UINT id); +typedef HGLRC (WINAPI * PFNWGLCREATEASSOCIATEDCONTEXTATTRIBSAMDPROC) (UINT id, HGLRC hShareContext, const int *attribList); +typedef BOOL (WINAPI * PFNWGLDELETEASSOCIATEDCONTEXTAMDPROC) (HGLRC hglrc); +typedef BOOL (WINAPI * PFNWGLMAKEASSOCIATEDCONTEXTCURRENTAMDPROC) (HGLRC hglrc); +typedef HGLRC (WINAPI * PFNWGLGETCURRENTASSOCIATEDCONTEXTAMDPROC) (void); +typedef VOID (WINAPI * PFNWGLBLITCONTEXTFRAMEBUFFERAMDPROC) (HGLRC dstCtx, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +#endif + +#ifndef WGL_NV_video_capture +#define WGL_NV_video_capture 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglBindVideoCaptureDeviceNV (UINT uVideoSlot, HVIDEOINPUTDEVICENV hDevice); +extern UINT WINAPI wglEnumerateVideoCaptureDevicesNV (HDC hDc, HVIDEOINPUTDEVICENV *phDeviceList); +extern BOOL WINAPI wglLockVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice); +extern BOOL WINAPI wglQueryVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice, int iAttribute, int *piValue); +extern BOOL WINAPI wglReleaseVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLBINDVIDEOCAPTUREDEVICENVPROC) (UINT uVideoSlot, HVIDEOINPUTDEVICENV hDevice); +typedef UINT (WINAPI * PFNWGLENUMERATEVIDEOCAPTUREDEVICESNVPROC) (HDC hDc, HVIDEOINPUTDEVICENV *phDeviceList); +typedef BOOL (WINAPI * PFNWGLLOCKVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice); +typedef BOOL (WINAPI * PFNWGLQUERYVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice, int iAttribute, int *piValue); +typedef BOOL (WINAPI * PFNWGLRELEASEVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice); +#endif + +#ifndef WGL_NV_copy_image +#define WGL_NV_copy_image 1 +#ifdef WGL_WGLEXT_PROTOTYPES +extern BOOL WINAPI wglCopyImageSubDataNV (HGLRC hSrcRC, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, HGLRC hDstRC, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); +#endif /* WGL_WGLEXT_PROTOTYPES */ +typedef BOOL (WINAPI * PFNWGLCOPYIMAGESUBDATANVPROC) (HGLRC hSrcRC, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, HGLRC hDstRC, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth); +#endif + +#ifndef WGL_NV_multisample_coverage +#define WGL_NV_multisample_coverage 1 +#endif + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/emulator/opengl/host/libs/Translator/include/GLES/gl.h b/emulator/opengl/host/libs/Translator/include/GLES/gl.h new file mode 100644 index 0000000..5b8d85a --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLES/gl.h @@ -0,0 +1,770 @@ +#ifndef __gl_h_ +#define __gl_h_ + +/* $Revision: 10601 $ on $Date:: 2010-03-04 22:15:27 -0800 #$ */ + +#include <GLES/glplatform.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +typedef void GLvoid; +typedef char GLchar; +typedef unsigned int GLenum; +typedef unsigned char GLboolean; +typedef unsigned int GLbitfield; +typedef khronos_int8_t GLbyte; +typedef short GLshort; +typedef int GLint; +typedef int GLsizei; +typedef khronos_uint8_t GLubyte; +typedef unsigned short GLushort; +typedef unsigned int GLuint; +typedef khronos_float_t GLfloat; +typedef khronos_float_t GLclampf; +typedef khronos_int32_t GLfixed; +typedef khronos_int32_t GLclampx; + +typedef khronos_intptr_t GLintptr; +typedef khronos_ssize_t GLsizeiptr; + + +/*************************************************************/ + +/* OpenGL ES core versions */ +#define GL_VERSION_ES_CM_1_0 1 +#define GL_VERSION_ES_CL_1_0 1 +#define GL_VERSION_ES_CM_1_1 1 +#define GL_VERSION_ES_CL_1_1 1 + +/* ClearBufferMask */ +#define GL_DEPTH_BUFFER_BIT 0x00000100 +#define GL_STENCIL_BUFFER_BIT 0x00000400 +#define GL_COLOR_BUFFER_BIT 0x00004000 + +/* Boolean */ +#define GL_FALSE 0 +#define GL_TRUE 1 + +/* BeginMode */ +#define GL_POINTS 0x0000 +#define GL_LINES 0x0001 +#define GL_LINE_LOOP 0x0002 +#define GL_LINE_STRIP 0x0003 +#define GL_TRIANGLES 0x0004 +#define GL_TRIANGLE_STRIP 0x0005 +#define GL_TRIANGLE_FAN 0x0006 + +/* AlphaFunction */ +#define GL_NEVER 0x0200 +#define GL_LESS 0x0201 +#define GL_EQUAL 0x0202 +#define GL_LEQUAL 0x0203 +#define GL_GREATER 0x0204 +#define GL_NOTEQUAL 0x0205 +#define GL_GEQUAL 0x0206 +#define GL_ALWAYS 0x0207 + +/* BlendingFactorDest */ +#define GL_ZERO 0 +#define GL_ONE 1 +#define GL_SRC_COLOR 0x0300 +#define GL_ONE_MINUS_SRC_COLOR 0x0301 +#define GL_SRC_ALPHA 0x0302 +#define GL_ONE_MINUS_SRC_ALPHA 0x0303 +#define GL_DST_ALPHA 0x0304 +#define GL_ONE_MINUS_DST_ALPHA 0x0305 + +/* BlendingFactorSrc */ +/* GL_ZERO */ +/* GL_ONE */ +#define GL_DST_COLOR 0x0306 +#define GL_ONE_MINUS_DST_COLOR 0x0307 +#define GL_SRC_ALPHA_SATURATE 0x0308 +/* GL_SRC_ALPHA */ +/* GL_ONE_MINUS_SRC_ALPHA */ +/* GL_DST_ALPHA */ +/* GL_ONE_MINUS_DST_ALPHA */ + +/* ClipPlaneName */ +#define GL_CLIP_PLANE0 0x3000 +#define GL_CLIP_PLANE1 0x3001 +#define GL_CLIP_PLANE2 0x3002 +#define GL_CLIP_PLANE3 0x3003 +#define GL_CLIP_PLANE4 0x3004 +#define GL_CLIP_PLANE5 0x3005 + +/* ColorMaterialFace */ +/* GL_FRONT_AND_BACK */ + +/* ColorMaterialParameter */ +/* GL_AMBIENT_AND_DIFFUSE */ + +/* ColorPointerType */ +/* GL_UNSIGNED_BYTE */ +/* GL_FLOAT */ +/* GL_FIXED */ + +/* CullFaceMode */ +#define GL_FRONT 0x0404 +#define GL_BACK 0x0405 +#define GL_FRONT_AND_BACK 0x0408 + +/* DepthFunction */ +/* GL_NEVER */ +/* GL_LESS */ +/* GL_EQUAL */ +/* GL_LEQUAL */ +/* GL_GREATER */ +/* GL_NOTEQUAL */ +/* GL_GEQUAL */ +/* GL_ALWAYS */ + +/* EnableCap */ +#define GL_FOG 0x0B60 +#define GL_LIGHTING 0x0B50 +#define GL_TEXTURE_2D 0x0DE1 +#define GL_CULL_FACE 0x0B44 +#define GL_ALPHA_TEST 0x0BC0 +#define GL_BLEND 0x0BE2 +#define GL_COLOR_LOGIC_OP 0x0BF2 +#define GL_DITHER 0x0BD0 +#define GL_STENCIL_TEST 0x0B90 +#define GL_DEPTH_TEST 0x0B71 +/* GL_LIGHT0 */ +/* GL_LIGHT1 */ +/* GL_LIGHT2 */ +/* GL_LIGHT3 */ +/* GL_LIGHT4 */ +/* GL_LIGHT5 */ +/* GL_LIGHT6 */ +/* GL_LIGHT7 */ +#define GL_POINT_SMOOTH 0x0B10 +#define GL_LINE_SMOOTH 0x0B20 +#define GL_SCISSOR_TEST 0x0C11 +#define GL_COLOR_MATERIAL 0x0B57 +#define GL_NORMALIZE 0x0BA1 +#define GL_RESCALE_NORMAL 0x803A +#define GL_POLYGON_OFFSET_FILL 0x8037 +#define GL_VERTEX_ARRAY 0x8074 +#define GL_NORMAL_ARRAY 0x8075 +#define GL_COLOR_ARRAY 0x8076 +#define GL_TEXTURE_COORD_ARRAY 0x8078 +#define GL_MULTISAMPLE 0x809D +#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE 0x809F +#define GL_SAMPLE_COVERAGE 0x80A0 + +/* ErrorCode */ +#define GL_NO_ERROR 0 +#define GL_INVALID_ENUM 0x0500 +#define GL_INVALID_VALUE 0x0501 +#define GL_INVALID_OPERATION 0x0502 +#define GL_STACK_OVERFLOW 0x0503 +#define GL_STACK_UNDERFLOW 0x0504 +#define GL_OUT_OF_MEMORY 0x0505 + +/* FogMode */ +/* GL_LINEAR */ +#define GL_EXP 0x0800 +#define GL_EXP2 0x0801 + +/* FogParameter */ +#define GL_FOG_DENSITY 0x0B62 +#define GL_FOG_START 0x0B63 +#define GL_FOG_END 0x0B64 +#define GL_FOG_MODE 0x0B65 +#define GL_FOG_COLOR 0x0B66 + +/* FrontFaceDirection */ +#define GL_CW 0x0900 +#define GL_CCW 0x0901 + +/* GetPName */ +#define GL_CURRENT_COLOR 0x0B00 +#define GL_CURRENT_NORMAL 0x0B02 +#define GL_CURRENT_TEXTURE_COORDS 0x0B03 +#define GL_POINT_SIZE 0x0B11 +#define GL_POINT_SIZE_MIN 0x8126 +#define GL_POINT_SIZE_MAX 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE 0x8128 +#define GL_POINT_DISTANCE_ATTENUATION 0x8129 +#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12 +#define GL_LINE_WIDTH 0x0B21 +#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22 +#define GL_ALIASED_POINT_SIZE_RANGE 0x846D +#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E +#define GL_CULL_FACE_MODE 0x0B45 +#define GL_FRONT_FACE 0x0B46 +#define GL_SHADE_MODEL 0x0B54 +#define GL_DEPTH_RANGE 0x0B70 +#define GL_DEPTH_WRITEMASK 0x0B72 +#define GL_DEPTH_CLEAR_VALUE 0x0B73 +#define GL_DEPTH_FUNC 0x0B74 +#define GL_STENCIL_CLEAR_VALUE 0x0B91 +#define GL_STENCIL_FUNC 0x0B92 +#define GL_STENCIL_VALUE_MASK 0x0B93 +#define GL_STENCIL_FAIL 0x0B94 +#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95 +#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96 +#define GL_STENCIL_REF 0x0B97 +#define GL_STENCIL_WRITEMASK 0x0B98 +#define GL_MATRIX_MODE 0x0BA0 +#define GL_VIEWPORT 0x0BA2 +#define GL_MODELVIEW_STACK_DEPTH 0x0BA3 +#define GL_PROJECTION_STACK_DEPTH 0x0BA4 +#define GL_TEXTURE_STACK_DEPTH 0x0BA5 +#define GL_MODELVIEW_MATRIX 0x0BA6 +#define GL_PROJECTION_MATRIX 0x0BA7 +#define GL_TEXTURE_MATRIX 0x0BA8 +#define GL_ALPHA_TEST_FUNC 0x0BC1 +#define GL_ALPHA_TEST_REF 0x0BC2 +#define GL_BLEND_DST 0x0BE0 +#define GL_BLEND_SRC 0x0BE1 +#define GL_LOGIC_OP_MODE 0x0BF0 +#define GL_SCISSOR_BOX 0x0C10 +#define GL_SCISSOR_TEST 0x0C11 +#define GL_COLOR_CLEAR_VALUE 0x0C22 +#define GL_COLOR_WRITEMASK 0x0C23 +#define GL_UNPACK_ALIGNMENT 0x0CF5 +#define GL_PACK_ALIGNMENT 0x0D05 +#define GL_MAX_LIGHTS 0x0D31 +#define GL_MAX_CLIP_PLANES 0x0D32 +#define GL_MAX_TEXTURE_SIZE 0x0D33 +#define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36 +#define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38 +#define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39 +#define GL_MAX_VIEWPORT_DIMS 0x0D3A +#define GL_MAX_TEXTURE_UNITS 0x84E2 +#define GL_SUBPIXEL_BITS 0x0D50 +#define GL_RED_BITS 0x0D52 +#define GL_GREEN_BITS 0x0D53 +#define GL_BLUE_BITS 0x0D54 +#define GL_ALPHA_BITS 0x0D55 +#define GL_DEPTH_BITS 0x0D56 +#define GL_STENCIL_BITS 0x0D57 +#define GL_POLYGON_OFFSET_UNITS 0x2A00 +#define GL_POLYGON_OFFSET_FILL 0x8037 +#define GL_POLYGON_OFFSET_FACTOR 0x8038 +#define GL_TEXTURE_BINDING_2D 0x8069 +#define GL_VERTEX_ARRAY_SIZE 0x807A +#define GL_VERTEX_ARRAY_TYPE 0x807B +#define GL_VERTEX_ARRAY_STRIDE 0x807C +#define GL_NORMAL_ARRAY_TYPE 0x807E +#define GL_NORMAL_ARRAY_STRIDE 0x807F +#define GL_COLOR_ARRAY_SIZE 0x8081 +#define GL_COLOR_ARRAY_TYPE 0x8082 +#define GL_COLOR_ARRAY_STRIDE 0x8083 +#define GL_TEXTURE_COORD_ARRAY_SIZE 0x8088 +#define GL_TEXTURE_COORD_ARRAY_TYPE 0x8089 +#define GL_TEXTURE_COORD_ARRAY_STRIDE 0x808A +#define GL_VERTEX_ARRAY_POINTER 0x808E +#define GL_NORMAL_ARRAY_POINTER 0x808F +#define GL_COLOR_ARRAY_POINTER 0x8090 +#define GL_TEXTURE_COORD_ARRAY_POINTER 0x8092 +#define GL_SAMPLE_BUFFERS 0x80A8 +#define GL_SAMPLES 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT 0x80AB + +/* GetTextureParameter */ +/* GL_TEXTURE_MAG_FILTER */ +/* GL_TEXTURE_MIN_FILTER */ +/* GL_TEXTURE_WRAP_S */ +/* GL_TEXTURE_WRAP_T */ + +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 + +/* HintMode */ +#define GL_DONT_CARE 0x1100 +#define GL_FASTEST 0x1101 +#define GL_NICEST 0x1102 + +/* HintTarget */ +#define GL_PERSPECTIVE_CORRECTION_HINT 0x0C50 +#define GL_POINT_SMOOTH_HINT 0x0C51 +#define GL_LINE_SMOOTH_HINT 0x0C52 +#define GL_FOG_HINT 0x0C54 +#define GL_GENERATE_MIPMAP_HINT 0x8192 + +/* LightModelParameter */ +#define GL_LIGHT_MODEL_AMBIENT 0x0B53 +#define GL_LIGHT_MODEL_TWO_SIDE 0x0B52 + +/* LightParameter */ +#define GL_AMBIENT 0x1200 +#define GL_DIFFUSE 0x1201 +#define GL_SPECULAR 0x1202 +#define GL_POSITION 0x1203 +#define GL_SPOT_DIRECTION 0x1204 +#define GL_SPOT_EXPONENT 0x1205 +#define GL_SPOT_CUTOFF 0x1206 +#define GL_CONSTANT_ATTENUATION 0x1207 +#define GL_LINEAR_ATTENUATION 0x1208 +#define GL_QUADRATIC_ATTENUATION 0x1209 + +/* DataType */ +#define GL_BYTE 0x1400 +#define GL_UNSIGNED_BYTE 0x1401 +#define GL_SHORT 0x1402 +#define GL_UNSIGNED_SHORT 0x1403 +#define GL_FLOAT 0x1406 +#define GL_FIXED 0x140C + +/* LogicOp */ +#define GL_CLEAR 0x1500 +#define GL_AND 0x1501 +#define GL_AND_REVERSE 0x1502 +#define GL_COPY 0x1503 +#define GL_AND_INVERTED 0x1504 +#define GL_NOOP 0x1505 +#define GL_XOR 0x1506 +#define GL_OR 0x1507 +#define GL_NOR 0x1508 +#define GL_EQUIV 0x1509 +#define GL_INVERT 0x150A +#define GL_OR_REVERSE 0x150B +#define GL_COPY_INVERTED 0x150C +#define GL_OR_INVERTED 0x150D +#define GL_NAND 0x150E +#define GL_SET 0x150F + +/* MaterialFace */ +/* GL_FRONT_AND_BACK */ + +/* MaterialParameter */ +#define GL_EMISSION 0x1600 +#define GL_SHININESS 0x1601 +#define GL_AMBIENT_AND_DIFFUSE 0x1602 +/* GL_AMBIENT */ +/* GL_DIFFUSE */ +/* GL_SPECULAR */ + +/* MatrixMode */ +#define GL_MODELVIEW 0x1700 +#define GL_PROJECTION 0x1701 +#define GL_TEXTURE 0x1702 + +/* NormalPointerType */ +/* GL_BYTE */ +/* GL_SHORT */ +/* GL_FLOAT */ +/* GL_FIXED */ + +/* PixelFormat */ +#define GL_ALPHA 0x1906 +#define GL_RGB 0x1907 +#define GL_RGBA 0x1908 +#define GL_LUMINANCE 0x1909 +#define GL_LUMINANCE_ALPHA 0x190A + +/* PixelStoreParameter */ +#define GL_UNPACK_ALIGNMENT 0x0CF5 +#define GL_PACK_ALIGNMENT 0x0D05 + +/* PixelType */ +/* GL_UNSIGNED_BYTE */ +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 + +/* ShadingModel */ +#define GL_FLAT 0x1D00 +#define GL_SMOOTH 0x1D01 + +/* StencilFunction */ +/* GL_NEVER */ +/* GL_LESS */ +/* GL_EQUAL */ +/* GL_LEQUAL */ +/* GL_GREATER */ +/* GL_NOTEQUAL */ +/* GL_GEQUAL */ +/* GL_ALWAYS */ + +/* StencilOp */ +/* GL_ZERO */ +#define GL_KEEP 0x1E00 +#define GL_REPLACE 0x1E01 +#define GL_INCR 0x1E02 +#define GL_DECR 0x1E03 +/* GL_INVERT */ + +/* StringName */ +#define GL_VENDOR 0x1F00 +#define GL_RENDERER 0x1F01 +#define GL_VERSION 0x1F02 +#define GL_EXTENSIONS 0x1F03 + +/* TexCoordPointerType */ +/* GL_SHORT */ +/* GL_FLOAT */ +/* GL_FIXED */ +/* GL_BYTE */ + +/* TextureEnvMode */ +#define GL_MODULATE 0x2100 +#define GL_DECAL 0x2101 +/* GL_BLEND */ +#define GL_ADD 0x0104 +/* GL_REPLACE */ + +/* TextureEnvParameter */ +#define GL_TEXTURE_ENV_MODE 0x2200 +#define GL_TEXTURE_ENV_COLOR 0x2201 + +/* TextureEnvTarget */ +#define GL_TEXTURE_ENV 0x2300 + +/* TextureMagFilter */ +#define GL_NEAREST 0x2600 +#define GL_LINEAR 0x2601 + +/* TextureMinFilter */ +/* GL_NEAREST */ +/* GL_LINEAR */ +#define GL_NEAREST_MIPMAP_NEAREST 0x2700 +#define GL_LINEAR_MIPMAP_NEAREST 0x2701 +#define GL_NEAREST_MIPMAP_LINEAR 0x2702 +#define GL_LINEAR_MIPMAP_LINEAR 0x2703 + +/* TextureParameterName */ +#define GL_TEXTURE_MAG_FILTER 0x2800 +#define GL_TEXTURE_MIN_FILTER 0x2801 +#define GL_TEXTURE_WRAP_S 0x2802 +#define GL_TEXTURE_WRAP_T 0x2803 +#define GL_GENERATE_MIPMAP 0x8191 + +/* TextureTarget */ +/* GL_TEXTURE_2D */ + +/* TextureUnit */ +#define GL_TEXTURE0 0x84C0 +#define GL_TEXTURE1 0x84C1 +#define GL_TEXTURE2 0x84C2 +#define GL_TEXTURE3 0x84C3 +#define GL_TEXTURE4 0x84C4 +#define GL_TEXTURE5 0x84C5 +#define GL_TEXTURE6 0x84C6 +#define GL_TEXTURE7 0x84C7 +#define GL_TEXTURE8 0x84C8 +#define GL_TEXTURE9 0x84C9 +#define GL_TEXTURE10 0x84CA +#define GL_TEXTURE11 0x84CB +#define GL_TEXTURE12 0x84CC +#define GL_TEXTURE13 0x84CD +#define GL_TEXTURE14 0x84CE +#define GL_TEXTURE15 0x84CF +#define GL_TEXTURE16 0x84D0 +#define GL_TEXTURE17 0x84D1 +#define GL_TEXTURE18 0x84D2 +#define GL_TEXTURE19 0x84D3 +#define GL_TEXTURE20 0x84D4 +#define GL_TEXTURE21 0x84D5 +#define GL_TEXTURE22 0x84D6 +#define GL_TEXTURE23 0x84D7 +#define GL_TEXTURE24 0x84D8 +#define GL_TEXTURE25 0x84D9 +#define GL_TEXTURE26 0x84DA +#define GL_TEXTURE27 0x84DB +#define GL_TEXTURE28 0x84DC +#define GL_TEXTURE29 0x84DD +#define GL_TEXTURE30 0x84DE +#define GL_TEXTURE31 0x84DF +#define GL_ACTIVE_TEXTURE 0x84E0 +#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1 + +/* TextureWrapMode */ +#define GL_REPEAT 0x2901 +#define GL_CLAMP_TO_EDGE 0x812F + +/* VertexPointerType */ +/* GL_SHORT */ +/* GL_FLOAT */ +/* GL_FIXED */ +/* GL_BYTE */ + +/* LightName */ +#define GL_LIGHT0 0x4000 +#define GL_LIGHT1 0x4001 +#define GL_LIGHT2 0x4002 +#define GL_LIGHT3 0x4003 +#define GL_LIGHT4 0x4004 +#define GL_LIGHT5 0x4005 +#define GL_LIGHT6 0x4006 +#define GL_LIGHT7 0x4007 + +/* Buffer Objects */ +#define GL_ARRAY_BUFFER 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER 0x8893 + +#define GL_ARRAY_BUFFER_BINDING 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 +#define GL_VERTEX_ARRAY_BUFFER_BINDING 0x8896 +#define GL_NORMAL_ARRAY_BUFFER_BINDING 0x8897 +#define GL_COLOR_ARRAY_BUFFER_BINDING 0x8898 +#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING 0x889A + +#define GL_STATIC_DRAW 0x88E4 +#define GL_DYNAMIC_DRAW 0x88E8 + +#define GL_BUFFER_SIZE 0x8764 +#define GL_BUFFER_USAGE 0x8765 + +/* Texture combine + dot3 */ +#define GL_SUBTRACT 0x84E7 +#define GL_COMBINE 0x8570 +#define GL_COMBINE_RGB 0x8571 +#define GL_COMBINE_ALPHA 0x8572 +#define GL_RGB_SCALE 0x8573 +#define GL_ADD_SIGNED 0x8574 +#define GL_INTERPOLATE 0x8575 +#define GL_CONSTANT 0x8576 +#define GL_PRIMARY_COLOR 0x8577 +#define GL_PREVIOUS 0x8578 +#define GL_OPERAND0_RGB 0x8590 +#define GL_OPERAND1_RGB 0x8591 +#define GL_OPERAND2_RGB 0x8592 +#define GL_OPERAND0_ALPHA 0x8598 +#define GL_OPERAND1_ALPHA 0x8599 +#define GL_OPERAND2_ALPHA 0x859A + +#define GL_ALPHA_SCALE 0x0D1C + +#define GL_SRC0_RGB 0x8580 +#define GL_SRC1_RGB 0x8581 +#define GL_SRC2_RGB 0x8582 +#define GL_SRC0_ALPHA 0x8588 +#define GL_SRC1_ALPHA 0x8589 +#define GL_SRC2_ALPHA 0x858A + +#define GL_DOT3_RGB 0x86AE +#define GL_DOT3_RGBA 0x86AF + +/*------------------------------------------------------------------------* + * required OES extension tokens + *------------------------------------------------------------------------*/ + +/* OES_read_format */ +#ifndef GL_OES_read_format +#define GL_IMPLEMENTATION_COLOR_READ_TYPE_OES 0x8B9A +#define GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES 0x8B9B +#endif + +/* GL_OES_compressed_paletted_texture */ +#ifndef GL_OES_compressed_paletted_texture +#define GL_PALETTE4_RGB8_OES 0x8B90 +#define GL_PALETTE4_RGBA8_OES 0x8B91 +#define GL_PALETTE4_R5_G6_B5_OES 0x8B92 +#define GL_PALETTE4_RGBA4_OES 0x8B93 +#define GL_PALETTE4_RGB5_A1_OES 0x8B94 +#define GL_PALETTE8_RGB8_OES 0x8B95 +#define GL_PALETTE8_RGBA8_OES 0x8B96 +#define GL_PALETTE8_R5_G6_B5_OES 0x8B97 +#define GL_PALETTE8_RGBA4_OES 0x8B98 +#define GL_PALETTE8_RGB5_A1_OES 0x8B99 +#endif + +/* OES_point_size_array */ +#ifndef GL_OES_point_size_array +#define GL_POINT_SIZE_ARRAY_OES 0x8B9C +#define GL_POINT_SIZE_ARRAY_TYPE_OES 0x898A +#define GL_POINT_SIZE_ARRAY_STRIDE_OES 0x898B +#define GL_POINT_SIZE_ARRAY_POINTER_OES 0x898C +#define GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES 0x8B9F +#endif + +/* GL_OES_point_sprite */ +#ifndef GL_OES_point_sprite +#define GL_POINT_SPRITE_OES 0x8861 +#define GL_COORD_REPLACE_OES 0x8862 +#endif + +/*************************************************************/ + +/* Available only in Common profile */ +GL_API void GL_APIENTRY glAlphaFunc (GLenum func, GLclampf ref); +GL_API void GL_APIENTRY glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +GL_API void GL_APIENTRY glClearDepthf (GLclampf depth); +GL_API void GL_APIENTRY glClipPlanef (GLenum plane, const GLfloat *equation); +GL_API void GL_APIENTRY glColor4f (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +GL_API void GL_APIENTRY glDepthRangef (GLclampf zNear, GLclampf zFar); +GL_API void GL_APIENTRY glFogf (GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glFogfv (GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glFrustumf (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); +GL_API void GL_APIENTRY glGetClipPlanef (GLenum pname, GLfloat eqn[4]); +GL_API void GL_APIENTRY glGetFloatv (GLenum pname, GLfloat *params); +GL_API void GL_APIENTRY glGetLightfv (GLenum light, GLenum pname, GLfloat *params); +GL_API void GL_APIENTRY glGetMaterialfv (GLenum face, GLenum pname, GLfloat *params); +GL_API void GL_APIENTRY glGetTexEnvfv (GLenum env, GLenum pname, GLfloat *params); +GL_API void GL_APIENTRY glGetTexParameterfv (GLenum target, GLenum pname, GLfloat *params); +GL_API void GL_APIENTRY glLightModelf (GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glLightModelfv (GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glLightf (GLenum light, GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glLightfv (GLenum light, GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glLineWidth (GLfloat width); +GL_API void GL_APIENTRY glLoadMatrixf (const GLfloat *m); +GL_API void GL_APIENTRY glMaterialf (GLenum face, GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glMaterialfv (GLenum face, GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glMultMatrixf (const GLfloat *m); +GL_API void GL_APIENTRY glMultiTexCoord4f (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +GL_API void GL_APIENTRY glNormal3f (GLfloat nx, GLfloat ny, GLfloat nz); +GL_API void GL_APIENTRY glOrthof (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); +GL_API void GL_APIENTRY glPointParameterf (GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glPointParameterfv (GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glPointSize (GLfloat size); +GL_API void GL_APIENTRY glPolygonOffset (GLfloat factor, GLfloat units); +GL_API void GL_APIENTRY glRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z); +GL_API void GL_APIENTRY glScalef (GLfloat x, GLfloat y, GLfloat z); +GL_API void GL_APIENTRY glTexEnvf (GLenum target, GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glTexEnvfv (GLenum target, GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glTexParameterf (GLenum target, GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glTexParameterfv (GLenum target, GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glTranslatef (GLfloat x, GLfloat y, GLfloat z); + +/* Available in both Common and Common-Lite profiles */ +GL_API void GL_APIENTRY glActiveTexture (GLenum texture); +GL_API void GL_APIENTRY glAlphaFuncx (GLenum func, GLclampx ref); +GL_API void GL_APIENTRY glBindBuffer (GLenum target, GLuint buffer); +GL_API void GL_APIENTRY glBindTexture (GLenum target, GLuint texture); +GL_API void GL_APIENTRY glBlendFunc (GLenum sfactor, GLenum dfactor); +GL_API void GL_APIENTRY glBufferData (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); +GL_API void GL_APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); +GL_API void GL_APIENTRY glClear (GLbitfield mask); +GL_API void GL_APIENTRY glClearColorx (GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha); +GL_API void GL_APIENTRY glClearDepthx (GLclampx depth); +GL_API void GL_APIENTRY glClearStencil (GLint s); +GL_API void GL_APIENTRY glClientActiveTexture (GLenum texture); +GL_API void GL_APIENTRY glClipPlanex (GLenum plane, const GLfixed *equation); +GL_API void GL_APIENTRY glColor4ub (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); +GL_API void GL_APIENTRY glColor4x (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha); +GL_API void GL_APIENTRY glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +GL_API void GL_APIENTRY glColorPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GL_API void GL_APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +GL_API void GL_APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +GL_API void GL_APIENTRY glCopyTexImage2D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +GL_API void GL_APIENTRY glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GL_API void GL_APIENTRY glCullFace (GLenum mode); +GL_API void GL_APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers); +GL_API void GL_APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures); +GL_API void GL_APIENTRY glDepthFunc (GLenum func); +GL_API void GL_APIENTRY glDepthMask (GLboolean flag); +GL_API void GL_APIENTRY glDepthRangex (GLclampx zNear, GLclampx zFar); +GL_API void GL_APIENTRY glDisable (GLenum cap); +GL_API void GL_APIENTRY glDisableClientState (GLenum array); +GL_API void GL_APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count); +GL_API void GL_APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); +GL_API void GL_APIENTRY glEnable (GLenum cap); +GL_API void GL_APIENTRY glEnableClientState (GLenum array); +GL_API void GL_APIENTRY glFinish (void); +GL_API void GL_APIENTRY glFlush (void); +GL_API void GL_APIENTRY glFogx (GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glFogxv (GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glFrontFace (GLenum mode); +GL_API void GL_APIENTRY glFrustumx (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar); +GL_API void GL_APIENTRY glGetBooleanv (GLenum pname, GLboolean *params); +GL_API void GL_APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint *params); +GL_API void GL_APIENTRY glGetClipPlanex (GLenum pname, GLfixed eqn[4]); +GL_API void GL_APIENTRY glGenBuffers (GLsizei n, GLuint *buffers); +GL_API void GL_APIENTRY glGenTextures (GLsizei n, GLuint *textures); +GL_API GLenum GL_APIENTRY glGetError (void); +GL_API void GL_APIENTRY glGetFixedv (GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetIntegerv (GLenum pname, GLint *params); +GL_API void GL_APIENTRY glGetLightxv (GLenum light, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetMaterialxv (GLenum face, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetPointerv (GLenum pname, GLvoid **params); +GL_API const GLubyte * GL_APIENTRY glGetString (GLenum name); +GL_API void GL_APIENTRY glGetTexEnviv (GLenum env, GLenum pname, GLint *params); +GL_API void GL_APIENTRY glGetTexEnvxv (GLenum env, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetTexParameteriv (GLenum target, GLenum pname, GLint *params); +GL_API void GL_APIENTRY glGetTexParameterxv (GLenum target, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glHint (GLenum target, GLenum mode); +GL_API GLboolean GL_APIENTRY glIsBuffer (GLuint buffer); +GL_API GLboolean GL_APIENTRY glIsEnabled (GLenum cap); +GL_API GLboolean GL_APIENTRY glIsTexture (GLuint texture); +GL_API void GL_APIENTRY glLightModelx (GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glLightModelxv (GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glLightx (GLenum light, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glLightxv (GLenum light, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glLineWidthx (GLfixed width); +GL_API void GL_APIENTRY glLoadIdentity (void); +GL_API void GL_APIENTRY glLoadMatrixx (const GLfixed *m); +GL_API void GL_APIENTRY glLogicOp (GLenum opcode); +GL_API void GL_APIENTRY glMaterialx (GLenum face, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glMaterialxv (GLenum face, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glMatrixMode (GLenum mode); +GL_API void GL_APIENTRY glMultMatrixx (const GLfixed *m); +GL_API void GL_APIENTRY glMultiTexCoord4x (GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q); +GL_API void GL_APIENTRY glNormal3x (GLfixed nx, GLfixed ny, GLfixed nz); +GL_API void GL_APIENTRY glNormalPointer (GLenum type, GLsizei stride, const GLvoid *pointer); +GL_API void GL_APIENTRY glOrthox (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar); +GL_API void GL_APIENTRY glPixelStorei (GLenum pname, GLint param); +GL_API void GL_APIENTRY glPointParameterx (GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glPointParameterxv (GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glPointSizex (GLfixed size); +GL_API void GL_APIENTRY glPolygonOffsetx (GLfixed factor, GLfixed units); +GL_API void GL_APIENTRY glPopMatrix (void); +GL_API void GL_APIENTRY glPushMatrix (void); +GL_API void GL_APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); +GL_API void GL_APIENTRY glRotatex (GLfixed angle, GLfixed x, GLfixed y, GLfixed z); +GL_API void GL_APIENTRY glSampleCoverage (GLclampf value, GLboolean invert); +GL_API void GL_APIENTRY glSampleCoveragex (GLclampx value, GLboolean invert); +GL_API void GL_APIENTRY glScalex (GLfixed x, GLfixed y, GLfixed z); +GL_API void GL_APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height); +GL_API void GL_APIENTRY glShadeModel (GLenum mode); +GL_API void GL_APIENTRY glStencilFunc (GLenum func, GLint ref, GLuint mask); +GL_API void GL_APIENTRY glStencilMask (GLuint mask); +GL_API void GL_APIENTRY glStencilOp (GLenum fail, GLenum zfail, GLenum zpass); +GL_API void GL_APIENTRY glTexCoordPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GL_API void GL_APIENTRY glTexEnvi (GLenum target, GLenum pname, GLint param); +GL_API void GL_APIENTRY glTexEnvx (GLenum target, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glTexEnviv (GLenum target, GLenum pname, const GLint *params); +GL_API void GL_APIENTRY glTexEnvxv (GLenum target, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +GL_API void GL_APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param); +GL_API void GL_APIENTRY glTexParameterx (GLenum target, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glTexParameteriv (GLenum target, GLenum pname, const GLint *params); +GL_API void GL_APIENTRY glTexParameterxv (GLenum target, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +GL_API void GL_APIENTRY glTranslatex (GLfixed x, GLfixed y, GLfixed z); +GL_API void GL_APIENTRY glVertexPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GL_API void GL_APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height); + +/*------------------------------------------------------------------------* + * Required OES extension functions + *------------------------------------------------------------------------*/ + +/* GL_OES_read_format */ +#ifndef GL_OES_read_format +#define GL_OES_read_format 1 +#endif + +/* GL_OES_compressed_paletted_texture */ +#ifndef GL_OES_compressed_paletted_texture +#define GL_OES_compressed_paletted_texture 1 +#endif + +/* GL_OES_point_size_array */ +#ifndef GL_OES_point_size_array +#define GL_OES_point_size_array 1 +GL_API void GL_APIENTRY glPointSizePointerOES (GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +/* GL_OES_point_sprite */ +#ifndef GL_OES_point_sprite +#define GL_OES_point_sprite 1 +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __gl_h_ */ + diff --git a/emulator/opengl/host/libs/Translator/include/GLES/glext.h b/emulator/opengl/host/libs/Translator/include/GLES/glext.h new file mode 100644 index 0000000..130e4b0 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLES/glext.h @@ -0,0 +1,1073 @@ +#ifndef __glext_h_ +#define __glext_h_ + +/* $Revision: 13240 $ on $Date:: 2010-12-17 15:16:00 -0800 #$ */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +#ifndef GL_APIENTRYP +# define GL_APIENTRYP GL_APIENTRY* +#endif + +/*------------------------------------------------------------------------* + * OES extension tokens + *------------------------------------------------------------------------*/ + +/* GL_OES_blend_equation_separate */ +#ifndef GL_OES_blend_equation_separate +/* BLEND_EQUATION_RGB_OES same as BLEND_EQUATION_OES */ +#define GL_BLEND_EQUATION_RGB_OES 0x8009 +#define GL_BLEND_EQUATION_ALPHA_OES 0x883D +#endif + +/* GL_OES_blend_func_separate */ +#ifndef GL_OES_blend_func_separate +#define GL_BLEND_DST_RGB_OES 0x80C8 +#define GL_BLEND_SRC_RGB_OES 0x80C9 +#define GL_BLEND_DST_ALPHA_OES 0x80CA +#define GL_BLEND_SRC_ALPHA_OES 0x80CB +#endif + +/* GL_OES_blend_subtract */ +#ifndef GL_OES_blend_subtract +#define GL_BLEND_EQUATION_OES 0x8009 +#define GL_FUNC_ADD_OES 0x8006 +#define GL_FUNC_SUBTRACT_OES 0x800A +#define GL_FUNC_REVERSE_SUBTRACT_OES 0x800B +#endif + +/* GL_OES_compressed_ETC1_RGB8_texture */ +#ifndef GL_OES_compressed_ETC1_RGB8_texture +#define GL_ETC1_RGB8_OES 0x8D64 +#endif + +/* GL_OES_depth24 */ +#ifndef GL_OES_depth24 +#define GL_DEPTH_COMPONENT24_OES 0x81A6 +#endif + +/* GL_OES_depth32 */ +#ifndef GL_OES_depth32 +#define GL_DEPTH_COMPONENT32_OES 0x81A7 +#endif + +/* GL_OES_draw_texture */ +#ifndef GL_OES_draw_texture +#define GL_TEXTURE_CROP_RECT_OES 0x8B9D +#endif + +/* GL_OES_EGL_image */ +#ifndef GL_OES_EGL_image +typedef void* GLeglImageOES; +#endif + +/* GL_OES_EGL_image_external */ +#ifndef GL_OES_EGL_image_external +/* GLeglImageOES defined in GL_OES_EGL_image already. */ +#define GL_TEXTURE_EXTERNAL_OES 0x8D65 +#define GL_TEXTURE_BINDING_EXTERNAL_OES 0x8D67 +#define GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES 0x8D68 +#endif + +/* GL_OES_element_index_uint */ +#ifndef GL_OES_element_index_uint +#define GL_UNSIGNED_INT 0x1405 +#endif + +/* GL_OES_fixed_point */ +#ifndef GL_OES_fixed_point +#define GL_FIXED_OES 0x140C +#endif + +/* GL_OES_framebuffer_object */ +#ifndef GL_OES_framebuffer_object +#define GL_NONE_OES 0 +#define GL_FRAMEBUFFER_OES 0x8D40 +#define GL_RENDERBUFFER_OES 0x8D41 +#define GL_RGBA4_OES 0x8056 +#define GL_RGB5_A1_OES 0x8057 +#define GL_RGB565_OES 0x8D62 +#define GL_DEPTH_COMPONENT16_OES 0x81A5 +#define GL_RENDERBUFFER_WIDTH_OES 0x8D42 +#define GL_RENDERBUFFER_HEIGHT_OES 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT_OES 0x8D44 +#define GL_RENDERBUFFER_RED_SIZE_OES 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE_OES 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE_OES 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE_OES 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE_OES 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE_OES 0x8D55 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_OES 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_OES 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_OES 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_OES 0x8CD3 +#define GL_COLOR_ATTACHMENT0_OES 0x8CE0 +#define GL_DEPTH_ATTACHMENT_OES 0x8D00 +#define GL_STENCIL_ATTACHMENT_OES 0x8D20 +#define GL_FRAMEBUFFER_COMPLETE_OES 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_OES 0x8CD9 +#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES 0x8CDA +#define GL_FRAMEBUFFER_UNSUPPORTED_OES 0x8CDD +#define GL_FRAMEBUFFER_BINDING_OES 0x8CA6 +#define GL_RENDERBUFFER_BINDING_OES 0x8CA7 +#define GL_MAX_RENDERBUFFER_SIZE_OES 0x84E8 +#define GL_INVALID_FRAMEBUFFER_OPERATION_OES 0x0506 +#endif + +/* GL_OES_mapbuffer */ +#ifndef GL_OES_mapbuffer +#define GL_WRITE_ONLY_OES 0x88B9 +#define GL_BUFFER_ACCESS_OES 0x88BB +#define GL_BUFFER_MAPPED_OES 0x88BC +#define GL_BUFFER_MAP_POINTER_OES 0x88BD +#endif + +/* GL_OES_matrix_get */ +#ifndef GL_OES_matrix_get +#define GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES 0x898D +#define GL_PROJECTION_MATRIX_FLOAT_AS_INT_BITS_OES 0x898E +#define GL_TEXTURE_MATRIX_FLOAT_AS_INT_BITS_OES 0x898F +#endif + +/* GL_OES_matrix_palette */ +#ifndef GL_OES_matrix_palette +#define GL_MAX_VERTEX_UNITS_OES 0x86A4 +#define GL_MAX_PALETTE_MATRICES_OES 0x8842 +#define GL_MATRIX_PALETTE_OES 0x8840 +#define GL_MATRIX_INDEX_ARRAY_OES 0x8844 +#define GL_WEIGHT_ARRAY_OES 0x86AD +#define GL_CURRENT_PALETTE_MATRIX_OES 0x8843 +#define GL_MATRIX_INDEX_ARRAY_SIZE_OES 0x8846 +#define GL_MATRIX_INDEX_ARRAY_TYPE_OES 0x8847 +#define GL_MATRIX_INDEX_ARRAY_STRIDE_OES 0x8848 +#define GL_MATRIX_INDEX_ARRAY_POINTER_OES 0x8849 +#define GL_MATRIX_INDEX_ARRAY_BUFFER_BINDING_OES 0x8B9E +#define GL_WEIGHT_ARRAY_SIZE_OES 0x86AB +#define GL_WEIGHT_ARRAY_TYPE_OES 0x86A9 +#define GL_WEIGHT_ARRAY_STRIDE_OES 0x86AA +#define GL_WEIGHT_ARRAY_POINTER_OES 0x86AC +#define GL_WEIGHT_ARRAY_BUFFER_BINDING_OES 0x889E +#endif + +/* GL_OES_packed_depth_stencil */ +#ifndef GL_OES_packed_depth_stencil +#define GL_DEPTH_STENCIL_OES 0x84F9 +#define GL_UNSIGNED_INT_24_8_OES 0x84FA +#define GL_DEPTH24_STENCIL8_OES 0x88F0 +#endif + +/* GL_OES_rgb8_rgba8 */ +#ifndef GL_OES_rgb8_rgba8 +#define GL_RGB8_OES 0x8051 +#define GL_RGBA8_OES 0x8058 +#endif + +/* GL_OES_stencil1 */ +#ifndef GL_OES_stencil1 +#define GL_STENCIL_INDEX1_OES 0x8D46 +#endif + +/* GL_OES_stencil4 */ +#ifndef GL_OES_stencil4 +#define GL_STENCIL_INDEX4_OES 0x8D47 +#endif + +/* GL_OES_stencil8 */ +#ifndef GL_OES_stencil8 +#define GL_STENCIL_INDEX8_OES 0x8D48 +#endif + +/* GL_OES_stencil_wrap */ +#ifndef GL_OES_stencil_wrap +#define GL_INCR_WRAP_OES 0x8507 +#define GL_DECR_WRAP_OES 0x8508 +#endif + +/* GL_OES_texture_cube_map */ +#ifndef GL_OES_texture_cube_map +#define GL_NORMAL_MAP_OES 0x8511 +#define GL_REFLECTION_MAP_OES 0x8512 +#define GL_TEXTURE_CUBE_MAP_OES 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP_OES 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_OES 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_OES 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_OES 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_OES 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_OES 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_OES 0x851A +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_OES 0x851C +#define GL_TEXTURE_GEN_MODE_OES 0x2500 +#define GL_TEXTURE_GEN_STR_OES 0x8D60 +#endif + +/* GL_OES_texture_mirrored_repeat */ +#ifndef GL_OES_texture_mirrored_repeat +#define GL_MIRRORED_REPEAT_OES 0x8370 +#endif + +/* GL_OES_vertex_array_object */ +#ifndef GL_OES_vertex_array_object +#define GL_VERTEX_ARRAY_BINDING_OES 0x85B5 +#endif + +/*------------------------------------------------------------------------* + * AMD extension tokens + *------------------------------------------------------------------------*/ + +/* GL_AMD_compressed_3DC_texture */ +#ifndef GL_AMD_compressed_3DC_texture +#define GL_3DC_X_AMD 0x87F9 +#define GL_3DC_XY_AMD 0x87FA +#endif + +/* GL_AMD_compressed_ATC_texture */ +#ifndef GL_AMD_compressed_ATC_texture +#define GL_ATC_RGB_AMD 0x8C92 +#define GL_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93 +#define GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE +#endif + +/*------------------------------------------------------------------------* + * APPLE extension tokens + *------------------------------------------------------------------------*/ + +/* GL_APPLE_texture_2D_limited_npot */ +/* No new tokens introduced by this extension. */ + +/* GL_APPLE_framebuffer_multisample */ +#ifndef GL_APPLE_framebuffer_multisample +#define GL_RENDERBUFFER_SAMPLES_APPLE 0x8CAB +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_APPLE 0x8D56 +#define GL_MAX_SAMPLES_APPLE 0x8D57 +#define GL_READ_FRAMEBUFFER_APPLE 0x8CA8 +#define GL_DRAW_FRAMEBUFFER_APPLE 0x8CA9 +#define GL_DRAW_FRAMEBUFFER_BINDING_APPLE 0x8CA6 +#define GL_READ_FRAMEBUFFER_BINDING_APPLE 0x8CAA +#endif + +/* GL_APPLE_texture_format_BGRA8888 */ +#ifndef GL_APPLE_texture_format_BGRA8888 +#define GL_BGRA_EXT 0x80E1 +#endif + +/* GL_APPLE_texture_max_level */ +#ifndef GL_APPLE_texture_max_level +#define GL_TEXTURE_MAX_LEVEL_APPLE 0x813D +#endif + +/*------------------------------------------------------------------------* + * ARM extension tokens + *------------------------------------------------------------------------*/ + +/* GL_ARM_rgba8 */ +/* No new tokens introduced by this extension. */ + +/*------------------------------------------------------------------------* + * EXT extension tokens + *------------------------------------------------------------------------*/ + +/* GL_EXT_blend_minmax */ +#ifndef GL_EXT_blend_minmax +#define GL_MIN_EXT 0x8007 +#define GL_MAX_EXT 0x8008 +#endif + +/* GL_EXT_discard_framebuffer */ +#ifndef GL_EXT_discard_framebuffer +#define GL_COLOR_EXT 0x1800 +#define GL_DEPTH_EXT 0x1801 +#define GL_STENCIL_EXT 0x1802 +#endif + +/* GL_EXT_multi_draw_arrays */ +/* No new tokens introduced by this extension. */ + +/* GL_EXT_read_format_bgra */ +#ifndef GL_EXT_read_format_bgra +#define GL_BGRA_EXT 0x80E1 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT 0x8365 +#define GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT 0x8366 +#endif + +/* GL_EXT_texture_filter_anisotropic */ +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE +#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF +#endif + +/* GL_EXT_texture_format_BGRA8888 */ +#ifndef GL_EXT_texture_format_BGRA8888 +#define GL_BGRA_EXT 0x80E1 +#endif + +/* GL_EXT_texture_lod_bias */ +#ifndef GL_EXT_texture_lod_bias +#define GL_MAX_TEXTURE_LOD_BIAS_EXT 0x84FD +#define GL_TEXTURE_FILTER_CONTROL_EXT 0x8500 +#define GL_TEXTURE_LOD_BIAS_EXT 0x8501 +#endif + +/*------------------------------------------------------------------------* + * IMG extension tokens + *------------------------------------------------------------------------*/ + +/* GL_IMG_read_format */ +#ifndef GL_IMG_read_format +#define GL_BGRA_IMG 0x80E1 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV_IMG 0x8365 +#endif + +/* GL_IMG_texture_compression_pvrtc */ +#ifndef GL_IMG_texture_compression_pvrtc +#define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00 +#define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01 +#define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02 +#define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03 +#endif + +/* GL_IMG_texture_env_enhanced_fixed_function */ +#ifndef GL_IMG_texture_env_enhanced_fixed_function +#define GL_MODULATE_COLOR_IMG 0x8C04 +#define GL_RECIP_ADD_SIGNED_ALPHA_IMG 0x8C05 +#define GL_TEXTURE_ALPHA_MODULATE_IMG 0x8C06 +#define GL_FACTOR_ALPHA_MODULATE_IMG 0x8C07 +#define GL_FRAGMENT_ALPHA_MODULATE_IMG 0x8C08 +#define GL_ADD_BLEND_IMG 0x8C09 +#define GL_DOT3_RGBA_IMG 0x86AF +#endif + +/* GL_IMG_user_clip_plane */ +#ifndef GL_IMG_user_clip_plane +#define GL_CLIP_PLANE0_IMG 0x3000 +#define GL_CLIP_PLANE1_IMG 0x3001 +#define GL_CLIP_PLANE2_IMG 0x3002 +#define GL_CLIP_PLANE3_IMG 0x3003 +#define GL_CLIP_PLANE4_IMG 0x3004 +#define GL_CLIP_PLANE5_IMG 0x3005 +#define GL_MAX_CLIP_PLANES_IMG 0x0D32 +#endif + +/* GL_IMG_multisampled_render_to_texture */ +#ifndef GL_IMG_multisampled_render_to_texture +#define GL_RENDERBUFFER_SAMPLES_IMG 0x9133 +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_IMG 0x9134 +#define GL_MAX_SAMPLES_IMG 0x9135 +#define GL_TEXTURE_SAMPLES_IMG 0x9136 +#endif + +/*------------------------------------------------------------------------* + * NV extension tokens + *------------------------------------------------------------------------*/ + +/* GL_NV_fence */ +#ifndef GL_NV_fence +#define GL_ALL_COMPLETED_NV 0x84F2 +#define GL_FENCE_STATUS_NV 0x84F3 +#define GL_FENCE_CONDITION_NV 0x84F4 +#endif + +/*------------------------------------------------------------------------* + * QCOM extension tokens + *------------------------------------------------------------------------*/ + +/* GL_QCOM_driver_control */ +/* No new tokens introduced by this extension. */ + +/* GL_QCOM_extended_get */ +#ifndef GL_QCOM_extended_get +#define GL_TEXTURE_WIDTH_QCOM 0x8BD2 +#define GL_TEXTURE_HEIGHT_QCOM 0x8BD3 +#define GL_TEXTURE_DEPTH_QCOM 0x8BD4 +#define GL_TEXTURE_INTERNAL_FORMAT_QCOM 0x8BD5 +#define GL_TEXTURE_FORMAT_QCOM 0x8BD6 +#define GL_TEXTURE_TYPE_QCOM 0x8BD7 +#define GL_TEXTURE_IMAGE_VALID_QCOM 0x8BD8 +#define GL_TEXTURE_NUM_LEVELS_QCOM 0x8BD9 +#define GL_TEXTURE_TARGET_QCOM 0x8BDA +#define GL_TEXTURE_OBJECT_VALID_QCOM 0x8BDB +#define GL_STATE_RESTORE 0x8BDC +#endif + +/* GL_QCOM_extended_get2 */ +/* No new tokens introduced by this extension. */ + +/* GL_QCOM_perfmon_global_mode */ +#ifndef GL_QCOM_perfmon_global_mode +#define GL_PERFMON_GLOBAL_MODE_QCOM 0x8FA0 +#endif + +/* GL_QCOM_writeonly_rendering */ +#ifndef GL_QCOM_writeonly_rendering +#define GL_WRITEONLY_RENDERING_QCOM 0x8823 +#endif + +/* GL_QCOM_tiled_rendering */ +#ifndef GL_QCOM_tiled_rendering +#define GL_COLOR_BUFFER_BIT0_QCOM 0x00000001 +#define GL_COLOR_BUFFER_BIT1_QCOM 0x00000002 +#define GL_COLOR_BUFFER_BIT2_QCOM 0x00000004 +#define GL_COLOR_BUFFER_BIT3_QCOM 0x00000008 +#define GL_COLOR_BUFFER_BIT4_QCOM 0x00000010 +#define GL_COLOR_BUFFER_BIT5_QCOM 0x00000020 +#define GL_COLOR_BUFFER_BIT6_QCOM 0x00000040 +#define GL_COLOR_BUFFER_BIT7_QCOM 0x00000080 +#define GL_DEPTH_BUFFER_BIT0_QCOM 0x00000100 +#define GL_DEPTH_BUFFER_BIT1_QCOM 0x00000200 +#define GL_DEPTH_BUFFER_BIT2_QCOM 0x00000400 +#define GL_DEPTH_BUFFER_BIT3_QCOM 0x00000800 +#define GL_DEPTH_BUFFER_BIT4_QCOM 0x00001000 +#define GL_DEPTH_BUFFER_BIT5_QCOM 0x00002000 +#define GL_DEPTH_BUFFER_BIT6_QCOM 0x00004000 +#define GL_DEPTH_BUFFER_BIT7_QCOM 0x00008000 +#define GL_STENCIL_BUFFER_BIT0_QCOM 0x00010000 +#define GL_STENCIL_BUFFER_BIT1_QCOM 0x00020000 +#define GL_STENCIL_BUFFER_BIT2_QCOM 0x00040000 +#define GL_STENCIL_BUFFER_BIT3_QCOM 0x00080000 +#define GL_STENCIL_BUFFER_BIT4_QCOM 0x00100000 +#define GL_STENCIL_BUFFER_BIT5_QCOM 0x00200000 +#define GL_STENCIL_BUFFER_BIT6_QCOM 0x00400000 +#define GL_STENCIL_BUFFER_BIT7_QCOM 0x00800000 +#define GL_MULTISAMPLE_BUFFER_BIT0_QCOM 0x01000000 +#define GL_MULTISAMPLE_BUFFER_BIT1_QCOM 0x02000000 +#define GL_MULTISAMPLE_BUFFER_BIT2_QCOM 0x04000000 +#define GL_MULTISAMPLE_BUFFER_BIT3_QCOM 0x08000000 +#define GL_MULTISAMPLE_BUFFER_BIT4_QCOM 0x10000000 +#define GL_MULTISAMPLE_BUFFER_BIT5_QCOM 0x20000000 +#define GL_MULTISAMPLE_BUFFER_BIT6_QCOM 0x40000000 +#define GL_MULTISAMPLE_BUFFER_BIT7_QCOM 0x80000000 +#endif + +/*------------------------------------------------------------------------* + * End of extension tokens, start of corresponding extension functions + *------------------------------------------------------------------------*/ + +/*------------------------------------------------------------------------* + * OES extension functions + *------------------------------------------------------------------------*/ + +/* GL_OES_blend_equation_separate */ +#ifndef GL_OES_blend_equation_separate +#define GL_OES_blend_equation_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glBlendEquationSeparateOES (GLenum modeRGB, GLenum modeAlpha); +#endif +typedef void (GL_APIENTRYP PFNGLBLENDEQUATIONSEPARATEOESPROC) (GLenum modeRGB, GLenum modeAlpha); +#endif + +/* GL_OES_blend_func_separate */ +#ifndef GL_OES_blend_func_separate +#define GL_OES_blend_func_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glBlendFuncSeparateOES (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif +typedef void (GL_APIENTRYP PFNGLBLENDFUNCSEPARATEOESPROC) (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +#endif + +/* GL_OES_blend_subtract */ +#ifndef GL_OES_blend_subtract +#define GL_OES_blend_subtract 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glBlendEquationOES (GLenum mode); +#endif +typedef void (GL_APIENTRYP PFNGLBLENDEQUATIONOESPROC) (GLenum mode); +#endif + +/* GL_OES_byte_coordinates */ +#ifndef GL_OES_byte_coordinates +#define GL_OES_byte_coordinates 1 +#endif + +/* GL_OES_compressed_ETC1_RGB8_texture */ +#ifndef GL_OES_compressed_ETC1_RGB8_texture +#define GL_OES_compressed_ETC1_RGB8_texture 1 +#endif + +/* GL_OES_depth24 */ +#ifndef GL_OES_depth24 +#define GL_OES_depth24 1 +#endif + +/* GL_OES_depth32 */ +#ifndef GL_OES_depth32 +#define GL_OES_depth32 1 +#endif + +/* GL_OES_draw_texture */ +#ifndef GL_OES_draw_texture +#define GL_OES_draw_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glDrawTexsOES (GLshort x, GLshort y, GLshort z, GLshort width, GLshort height); +GL_API void GL_APIENTRY glDrawTexiOES (GLint x, GLint y, GLint z, GLint width, GLint height); +GL_API void GL_APIENTRY glDrawTexxOES (GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height); +GL_API void GL_APIENTRY glDrawTexsvOES (const GLshort *coords); +GL_API void GL_APIENTRY glDrawTexivOES (const GLint *coords); +GL_API void GL_APIENTRY glDrawTexxvOES (const GLfixed *coords); +GL_API void GL_APIENTRY glDrawTexfOES (GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height); +GL_API void GL_APIENTRY glDrawTexfvOES (const GLfloat *coords); +#endif +typedef void (GL_APIENTRYP PFNGLDRAWTEXSOESPROC) (GLshort x, GLshort y, GLshort z, GLshort width, GLshort height); +typedef void (GL_APIENTRYP PFNGLDRAWTEXIOESPROC) (GLint x, GLint y, GLint z, GLint width, GLint height); +typedef void (GL_APIENTRYP PFNGLDRAWTEXXOESPROC) (GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height); +typedef void (GL_APIENTRYP PFNGLDRAWTEXSVOESPROC) (const GLshort *coords); +typedef void (GL_APIENTRYP PFNGLDRAWTEXIVOESPROC) (const GLint *coords); +typedef void (GL_APIENTRYP PFNGLDRAWTEXXVOESPROC) (const GLfixed *coords); +typedef void (GL_APIENTRYP PFNGLDRAWTEXFOESPROC) (GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height); +typedef void (GL_APIENTRYP PFNGLDRAWTEXFVOESPROC) (const GLfloat *coords); +#endif + +/* GL_OES_EGL_image */ +#ifndef GL_OES_EGL_image +#define GL_OES_EGL_image 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image); +GL_API void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES (GLenum target, GLeglImageOES image); +#endif +typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image); +typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLeglImageOES image); +#endif + +/* GL_OES_EGL_image_external */ +#ifndef GL_OES_EGL_image_external +#define GL_OES_EGL_image_external 1 +/* glEGLImageTargetTexture2DOES defined in GL_OES_EGL_image already. */ +#endif + +/* GL_OES_element_index_uint */ +#ifndef GL_OES_element_index_uint +#define GL_OES_element_index_uint 1 +#endif + +/* GL_OES_extended_matrix_palette */ +#ifndef GL_OES_extended_matrix_palette +#define GL_OES_extended_matrix_palette 1 +#endif + +/* GL_OES_fbo_render_mipmap */ +#ifndef GL_OES_fbo_render_mipmap +#define GL_OES_fbo_render_mipmap 1 +#endif + +/* GL_OES_fixed_point */ +#ifndef GL_OES_fixed_point +#define GL_OES_fixed_point 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glAlphaFuncxOES (GLenum func, GLclampx ref); +GL_API void GL_APIENTRY glClearColorxOES (GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha); +GL_API void GL_APIENTRY glClearDepthxOES (GLclampx depth); +GL_API void GL_APIENTRY glClipPlanexOES (GLenum plane, const GLfixed *equation); +GL_API void GL_APIENTRY glColor4xOES (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha); +GL_API void GL_APIENTRY glDepthRangexOES (GLclampx zNear, GLclampx zFar); +GL_API void GL_APIENTRY glFogxOES (GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glFogxvOES (GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glFrustumxOES (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar); +GL_API void GL_APIENTRY glGetClipPlanexOES (GLenum pname, GLfixed eqn[4]); +GL_API void GL_APIENTRY glGetFixedvOES (GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetLightxvOES (GLenum light, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetMaterialxvOES (GLenum face, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetTexEnvxvOES (GLenum env, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glGetTexParameterxvOES (GLenum target, GLenum pname, GLfixed *params); +GL_API void GL_APIENTRY glLightModelxOES (GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glLightModelxvOES (GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glLightxOES (GLenum light, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glLightxvOES (GLenum light, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glLineWidthxOES (GLfixed width); +GL_API void GL_APIENTRY glLoadMatrixxOES (const GLfixed *m); +GL_API void GL_APIENTRY glMaterialxOES (GLenum face, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glMaterialxvOES (GLenum face, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glMultMatrixxOES (const GLfixed *m); +GL_API void GL_APIENTRY glMultiTexCoord4xOES (GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q); +GL_API void GL_APIENTRY glNormal3xOES (GLfixed nx, GLfixed ny, GLfixed nz); +GL_API void GL_APIENTRY glOrthoxOES (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar); +GL_API void GL_APIENTRY glPointParameterxOES (GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glPointParameterxvOES (GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glPointSizexOES (GLfixed size); +GL_API void GL_APIENTRY glPolygonOffsetxOES (GLfixed factor, GLfixed units); +GL_API void GL_APIENTRY glRotatexOES (GLfixed angle, GLfixed x, GLfixed y, GLfixed z); +GL_API void GL_APIENTRY glSampleCoveragexOES (GLclampx value, GLboolean invert); +GL_API void GL_APIENTRY glScalexOES (GLfixed x, GLfixed y, GLfixed z); +GL_API void GL_APIENTRY glTexEnvxOES (GLenum target, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glTexEnvxvOES (GLenum target, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glTexParameterxOES (GLenum target, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glTexParameterxvOES (GLenum target, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glTranslatexOES (GLfixed x, GLfixed y, GLfixed z); +#endif +typedef void (GL_APIENTRYP PFNGLALPHAFUNCXOESPROC) (GLenum func, GLclampx ref); +typedef void (GL_APIENTRYP PFNGLCLEARCOLORXOESPROC) (GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha); +typedef void (GL_APIENTRYP PFNGLCLEARDEPTHXOESPROC) (GLclampx depth); +typedef void (GL_APIENTRYP PFNGLCLIPPLANEXOESPROC) (GLenum plane, const GLfixed *equation); +typedef void (GL_APIENTRYP PFNGLCOLOR4XOESPROC) (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha); +typedef void (GL_APIENTRYP PFNGLDEPTHRANGEXOESPROC) (GLclampx zNear, GLclampx zFar); +typedef void (GL_APIENTRYP PFNGLFOGXOESPROC) (GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLFOGXVOESPROC) (GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLFRUSTUMXOESPROC) (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar); +typedef void (GL_APIENTRYP PFNGLGETCLIPPLANEXOESPROC) (GLenum pname, GLfixed eqn[4]); +typedef void (GL_APIENTRYP PFNGLGETFIXEDVOESPROC) (GLenum pname, GLfixed *params); +typedef void (GL_APIENTRYP PFNGLGETLIGHTXVOESPROC) (GLenum light, GLenum pname, GLfixed *params); +typedef void (GL_APIENTRYP PFNGLGETMATERIALXVOESPROC) (GLenum face, GLenum pname, GLfixed *params); +typedef void (GL_APIENTRYP PFNGLGETTEXENVXVOESPROC) (GLenum env, GLenum pname, GLfixed *params); +typedef void (GL_APIENTRYP PFNGLGETTEXPARAMETERXVOESPROC) (GLenum target, GLenum pname, GLfixed *params); +typedef void (GL_APIENTRYP PFNGLLIGHTMODELXOESPROC) (GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLLIGHTMODELXVOESPROC) (GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLLIGHTXOESPROC) (GLenum light, GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLLIGHTXVOESPROC) (GLenum light, GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLLINEWIDTHXOESPROC) (GLfixed width); +typedef void (GL_APIENTRYP PFNGLLOADMATRIXXOESPROC) (const GLfixed *m); +typedef void (GL_APIENTRYP PFNGLMATERIALXOESPROC) (GLenum face, GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLMATERIALXVOESPROC) (GLenum face, GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLMULTMATRIXXOESPROC) (const GLfixed *m); +typedef void (GL_APIENTRYP PFNGLMULTITEXCOORD4XOESPROC) (GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q); +typedef void (GL_APIENTRYP PFNGLNORMAL3XOESPROC) (GLfixed nx, GLfixed ny, GLfixed nz); +typedef void (GL_APIENTRYP PFNGLORTHOXOESPROC) (GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar); +typedef void (GL_APIENTRYP PFNGLPOINTPARAMETERXOESPROC) (GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLPOINTPARAMETERXVOESPROC) (GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLPOINTSIZEXOESPROC) (GLfixed size); +typedef void (GL_APIENTRYP PFNGLPOLYGONOFFSETXOESPROC) (GLfixed factor, GLfixed units); +typedef void (GL_APIENTRYP PFNGLROTATEXOESPROC) (GLfixed angle, GLfixed x, GLfixed y, GLfixed z); +typedef void (GL_APIENTRYP PFNGLSAMPLECOVERAGEXOESPROC) (GLclampx value, GLboolean invert); +typedef void (GL_APIENTRYP PFNGLSCALEXOESPROC) (GLfixed x, GLfixed y, GLfixed z); +typedef void (GL_APIENTRYP PFNGLTEXENVXOESPROC) (GLenum target, GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLTEXENVXVOESPROC) (GLenum target, GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLTEXPARAMETERXOESPROC) (GLenum target, GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLTEXPARAMETERXVOESPROC) (GLenum target, GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLTRANSLATEXOESPROC) (GLfixed x, GLfixed y, GLfixed z); +#endif + +/* GL_OES_framebuffer_object */ +#ifndef GL_OES_framebuffer_object +#define GL_OES_framebuffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API GLboolean GL_APIENTRY glIsRenderbufferOES (GLuint renderbuffer); +GL_API void GL_APIENTRY glBindRenderbufferOES (GLenum target, GLuint renderbuffer); +GL_API void GL_APIENTRY glDeleteRenderbuffersOES (GLsizei n, const GLuint* renderbuffers); +GL_API void GL_APIENTRY glGenRenderbuffersOES (GLsizei n, GLuint* renderbuffers); +GL_API void GL_APIENTRY glRenderbufferStorageOES (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +GL_API void GL_APIENTRY glGetRenderbufferParameterivOES (GLenum target, GLenum pname, GLint* params); +GL_API GLboolean GL_APIENTRY glIsFramebufferOES (GLuint framebuffer); +GL_API void GL_APIENTRY glBindFramebufferOES (GLenum target, GLuint framebuffer); +GL_API void GL_APIENTRY glDeleteFramebuffersOES (GLsizei n, const GLuint* framebuffers); +GL_API void GL_APIENTRY glGenFramebuffersOES (GLsizei n, GLuint* framebuffers); +GL_API GLenum GL_APIENTRY glCheckFramebufferStatusOES (GLenum target); +GL_API void GL_APIENTRY glFramebufferRenderbufferOES (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GL_API void GL_APIENTRY glFramebufferTexture2DOES (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GL_API void GL_APIENTRY glGetFramebufferAttachmentParameterivOES (GLenum target, GLenum attachment, GLenum pname, GLint* params); +GL_API void GL_APIENTRY glGenerateMipmapOES (GLenum target); +#endif +typedef GLboolean (GL_APIENTRYP PFNGLISRENDERBUFFEROESPROC) (GLuint renderbuffer); +typedef void (GL_APIENTRYP PFNGLBINDRENDERBUFFEROESPROC) (GLenum target, GLuint renderbuffer); +typedef void (GL_APIENTRYP PFNGLDELETERENDERBUFFERSOESPROC) (GLsizei n, const GLuint* renderbuffers); +typedef void (GL_APIENTRYP PFNGLGENRENDERBUFFERSOESPROC) (GLsizei n, GLuint* renderbuffers); +typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVOESPROC) (GLenum target, GLenum pname, GLint* params); +typedef GLboolean (GL_APIENTRYP PFNGLISFRAMEBUFFEROESPROC) (GLuint framebuffer); +typedef void (GL_APIENTRYP PFNGLBINDFRAMEBUFFEROESPROC) (GLenum target, GLuint framebuffer); +typedef void (GL_APIENTRYP PFNGLDELETEFRAMEBUFFERSOESPROC) (GLsizei n, const GLuint* framebuffers); +typedef void (GL_APIENTRYP PFNGLGENFRAMEBUFFERSOESPROC) (GLsizei n, GLuint* framebuffers); +typedef GLenum (GL_APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSOESPROC) (GLenum target); +typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFEROESPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DOESPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (GL_APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVOESPROC) (GLenum target, GLenum attachment, GLenum pname, GLint* params); +typedef void (GL_APIENTRYP PFNGLGENERATEMIPMAPOESPROC) (GLenum target); +#endif + +/* GL_OES_mapbuffer */ +#ifndef GL_OES_mapbuffer +#define GL_OES_mapbuffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void* GL_APIENTRY glMapBufferOES (GLenum target, GLenum access); +GL_API GLboolean GL_APIENTRY glUnmapBufferOES (GLenum target); +GL_API void GL_APIENTRY glGetBufferPointervOES (GLenum target, GLenum pname, GLvoid ** params); +#endif +typedef void* (GL_APIENTRYP PFNGLMAPBUFFEROESPROC) (GLenum target, GLenum access); +typedef GLboolean (GL_APIENTRYP PFNGLUNMAPBUFFEROESPROC) (GLenum target); +typedef void (GL_APIENTRYP PFNGLGETBUFFERPOINTERVOESPROC) (GLenum target, GLenum pname, GLvoid ** params); +#endif + +/* GL_OES_matrix_get */ +#ifndef GL_OES_matrix_get +#define GL_OES_matrix_get 1 +#endif + +/* GL_OES_matrix_palette */ +#ifndef GL_OES_matrix_palette +#define GL_OES_matrix_palette 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glCurrentPaletteMatrixOES (GLuint matrixpaletteindex); +GL_API void GL_APIENTRY glLoadPaletteFromModelViewMatrixOES (void); +GL_API void GL_APIENTRY glMatrixIndexPointerOES (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +GL_API void GL_APIENTRY glWeightPointerOES (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif +typedef void (GL_APIENTRYP PFNGLCURRENTPALETTEMATRIXOESPROC) (GLuint matrixpaletteindex); +typedef void (GL_APIENTRYP PFNGLLOADPALETTEFROMMODELVIEWMATRIXOESPROC) (void); +typedef void (GL_APIENTRYP PFNGLMATRIXINDEXPOINTEROESPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (GL_APIENTRYP PFNGLWEIGHTPOINTEROESPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +/* GL_OES_packed_depth_stencil */ +#ifndef GL_OES_packed_depth_stencil +#define GL_OES_packed_depth_stencil 1 +#endif + +/* GL_OES_query_matrix */ +#ifndef GL_OES_query_matrix +#define GL_OES_query_matrix 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API GLbitfield GL_APIENTRY glQueryMatrixxOES (GLfixed mantissa[16], GLint exponent[16]); +#endif +typedef GLbitfield (GL_APIENTRYP PFNGLQUERYMATRIXXOESPROC) (GLfixed mantissa[16], GLint exponent[16]); +#endif + +/* GL_OES_rgb8_rgba8 */ +#ifndef GL_OES_rgb8_rgba8 +#define GL_OES_rgb8_rgba8 1 +#endif + +/* GL_OES_single_precision */ +#ifndef GL_OES_single_precision +#define GL_OES_single_precision 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glDepthRangefOES (GLclampf zNear, GLclampf zFar); +GL_API void GL_APIENTRY glFrustumfOES (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); +GL_API void GL_APIENTRY glOrthofOES (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); +GL_API void GL_APIENTRY glClipPlanefOES (GLenum plane, const GLfloat *equation); +GL_API void GL_APIENTRY glGetClipPlanefOES (GLenum pname, GLfloat eqn[4]); +GL_API void GL_APIENTRY glClearDepthfOES (GLclampf depth); +#endif +typedef void (GL_APIENTRYP PFNGLDEPTHRANGEFOESPROC) (GLclampf zNear, GLclampf zFar); +typedef void (GL_APIENTRYP PFNGLFRUSTUMFOESPROC) (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); +typedef void (GL_APIENTRYP PFNGLORTHOFOESPROC) (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); +typedef void (GL_APIENTRYP PFNGLCLIPPLANEFOESPROC) (GLenum plane, const GLfloat *equation); +typedef void (GL_APIENTRYP PFNGLGETCLIPPLANEFOESPROC) (GLenum pname, GLfloat eqn[4]); +typedef void (GL_APIENTRYP PFNGLCLEARDEPTHFOESPROC) (GLclampf depth); +#endif + +/* GL_OES_stencil1 */ +#ifndef GL_OES_stencil1 +#define GL_OES_stencil1 1 +#endif + +/* GL_OES_stencil4 */ +#ifndef GL_OES_stencil4 +#define GL_OES_stencil4 1 +#endif + +/* GL_OES_stencil8 */ +#ifndef GL_OES_stencil8 +#define GL_OES_stencil8 1 +#endif + +/* GL_OES_stencil_wrap */ +#ifndef GL_OES_stencil_wrap +#define GL_OES_stencil_wrap 1 +#endif + +/* GL_OES_texture_cube_map */ +#ifndef GL_OES_texture_cube_map +#define GL_OES_texture_cube_map 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glTexGenfOES (GLenum coord, GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glTexGenfvOES (GLenum coord, GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glTexGeniOES (GLenum coord, GLenum pname, GLint param); +GL_API void GL_APIENTRY glTexGenivOES (GLenum coord, GLenum pname, const GLint *params); +GL_API void GL_APIENTRY glTexGenxOES (GLenum coord, GLenum pname, GLfixed param); +GL_API void GL_APIENTRY glTexGenxvOES (GLenum coord, GLenum pname, const GLfixed *params); +GL_API void GL_APIENTRY glGetTexGenfvOES (GLenum coord, GLenum pname, GLfloat *params); +GL_API void GL_APIENTRY glGetTexGenivOES (GLenum coord, GLenum pname, GLint *params); +GL_API void GL_APIENTRY glGetTexGenxvOES (GLenum coord, GLenum pname, GLfixed *params); +#endif +typedef void (GL_APIENTRYP PFNGLTEXGENFOESPROC) (GLenum coord, GLenum pname, GLfloat param); +typedef void (GL_APIENTRYP PFNGLTEXGENFVOESPROC) (GLenum coord, GLenum pname, const GLfloat *params); +typedef void (GL_APIENTRYP PFNGLTEXGENIOESPROC) (GLenum coord, GLenum pname, GLint param); +typedef void (GL_APIENTRYP PFNGLTEXGENIVOESPROC) (GLenum coord, GLenum pname, const GLint *params); +typedef void (GL_APIENTRYP PFNGLTEXGENXOESPROC) (GLenum coord, GLenum pname, GLfixed param); +typedef void (GL_APIENTRYP PFNGLTEXGENXVOESPROC) (GLenum coord, GLenum pname, const GLfixed *params); +typedef void (GL_APIENTRYP PFNGLGETTEXGENFVOESPROC) (GLenum coord, GLenum pname, GLfloat *params); +typedef void (GL_APIENTRYP PFNGLGETTEXGENIVOESPROC) (GLenum coord, GLenum pname, GLint *params); +typedef void (GL_APIENTRYP PFNGLGETTEXGENXVOESPROC) (GLenum coord, GLenum pname, GLfixed *params); +#endif + +/* GL_OES_texture_env_crossbar */ +#ifndef GL_OES_texture_env_crossbar +#define GL_OES_texture_env_crossbar 1 +#endif + +/* GL_OES_texture_mirrored_repeat */ +#ifndef GL_OES_texture_mirrored_repeat +#define GL_OES_texture_mirrored_repeat 1 +#endif + +/* GL_OES_vertex_array_object */ +#ifndef GL_OES_vertex_array_object +#define GL_OES_vertex_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glBindVertexArrayOES (GLuint array); +GL_API void GL_APIENTRY glDeleteVertexArraysOES (GLsizei n, const GLuint *arrays); +GL_API void GL_APIENTRY glGenVertexArraysOES (GLsizei n, GLuint *arrays); +GL_API GLboolean GL_APIENTRY glIsVertexArrayOES (GLuint array); +#endif +typedef void (GL_APIENTRYP PFNGLBINDVERTEXARRAYOESPROC) (GLuint array); +typedef void (GL_APIENTRYP PFNGLDELETEVERTEXARRAYSOESPROC) (GLsizei n, const GLuint *arrays); +typedef void (GL_APIENTRYP PFNGLGENVERTEXARRAYSOESPROC) (GLsizei n, GLuint *arrays); +typedef GLboolean (GL_APIENTRYP PFNGLISVERTEXARRAYOESPROC) (GLuint array); +#endif + +/*------------------------------------------------------------------------* + * AMD extension functions + *------------------------------------------------------------------------*/ + +/* GL_AMD_compressed_3DC_texture */ +#ifndef GL_AMD_compressed_3DC_texture +#define GL_AMD_compressed_3DC_texture 1 +#endif + +/* GL_AMD_compressed_ATC_texture */ +#ifndef GL_AMD_compressed_ATC_texture +#define GL_AMD_compressed_ATC_texture 1 +#endif + +/*------------------------------------------------------------------------* + * APPLE extension functions + *------------------------------------------------------------------------*/ + +/* GL_APPLE_texture_2D_limited_npot */ +#ifndef GL_APPLE_texture_2D_limited_npot +#define GL_APPLE_texture_2D_limited_npot 1 +#endif + +/* GL_APPLE_framebuffer_multisample */ +#ifndef GL_APPLE_framebuffer_multisample +#define GL_APPLE_framebuffer_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glRenderbufferStorageMultisampleAPPLE (GLenum, GLsizei, GLenum, GLsizei, GLsizei); +GL_API void GL_APIENTRY glResolveMultisampleFramebufferAPPLE (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEAPPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLRESOLVEMULTISAMPLEFRAMEBUFFERAPPLEPROC) (void); +#endif + +/* GL_APPLE_texture_format_BGRA8888 */ +#ifndef GL_APPLE_texture_format_BGRA8888 +#define GL_APPLE_texture_format_BGRA8888 1 +#endif + +/* GL_APPLE_texture_max_level */ +#ifndef GL_APPLE_texture_max_level +#define GL_APPLE_texture_max_level 1 +#endif + +/*------------------------------------------------------------------------* + * ARM extension functions + *------------------------------------------------------------------------*/ + +/* GL_ARM_rgba8 */ +#ifndef GL_ARM_rgba8 +#define GL_ARM_rgba8 1 +#endif + +/*------------------------------------------------------------------------* + * EXT extension functions + *------------------------------------------------------------------------*/ + +/* GL_EXT_blend_minmax */ +#ifndef GL_EXT_blend_minmax +#define GL_EXT_blend_minmax 1 +#endif + +/* GL_EXT_discard_framebuffer */ +#ifndef GL_EXT_discard_framebuffer +#define GL_EXT_discard_framebuffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glDiscardFramebufferEXT (GLenum target, GLsizei numAttachments, const GLenum *attachments); +#endif +typedef void (GL_APIENTRYP PFNGLDISCARDFRAMEBUFFEREXTPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments); +#endif + +/* GL_EXT_multi_draw_arrays */ +#ifndef GL_EXT_multi_draw_arrays +#define GL_EXT_multi_draw_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glMultiDrawArraysEXT (GLenum, GLint *, GLsizei *, GLsizei); +GL_API void GL_APIENTRY glMultiDrawElementsEXT (GLenum, const GLsizei *, GLenum, const GLvoid* *, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (GL_APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, GLint *first, GLsizei *count, GLsizei primcount); +typedef void (GL_APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); +#endif + +/* GL_EXT_read_format_bgra */ +#ifndef GL_EXT_read_format_bgra +#define GL_EXT_read_format_bgra 1 +#endif + +/* GL_EXT_texture_filter_anisotropic */ +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_EXT_texture_filter_anisotropic 1 +#endif + +/* GL_EXT_texture_format_BGRA8888 */ +#ifndef GL_EXT_texture_format_BGRA8888 +#define GL_EXT_texture_format_BGRA8888 1 +#endif + +/* GL_EXT_texture_lod_bias */ +#ifndef GL_EXT_texture_lod_bias +#define GL_EXT_texture_lod_bias 1 +#endif + +/*------------------------------------------------------------------------* + * IMG extension functions + *------------------------------------------------------------------------*/ + +/* GL_IMG_read_format */ +#ifndef GL_IMG_read_format +#define GL_IMG_read_format 1 +#endif + +/* GL_IMG_texture_compression_pvrtc */ +#ifndef GL_IMG_texture_compression_pvrtc +#define GL_IMG_texture_compression_pvrtc 1 +#endif + +/* GL_IMG_texture_env_enhanced_fixed_function */ +#ifndef GL_IMG_texture_env_enhanced_fixed_function +#define GL_IMG_texture_env_enhanced_fixed_function 1 +#endif + +/* GL_IMG_user_clip_plane */ +#ifndef GL_IMG_user_clip_plane +#define GL_IMG_user_clip_plane 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glClipPlanefIMG (GLenum, const GLfloat *); +GL_API void GL_APIENTRY glClipPlanexIMG (GLenum, const GLfixed *); +#endif +typedef void (GL_APIENTRYP PFNGLCLIPPLANEFIMGPROC) (GLenum p, const GLfloat *eqn); +typedef void (GL_APIENTRYP PFNGLCLIPPLANEXIMGPROC) (GLenum p, const GLfixed *eqn); +#endif + +/* GL_IMG_multisampled_render_to_texture */ +#ifndef GL_IMG_multisampled_render_to_texture +#define GL_IMG_multisampled_render_to_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glRenderbufferStorageMultisampleIMG (GLenum, GLsizei, GLenum, GLsizei, GLsizei); +GL_API void GL_APIENTRY glFramebufferTexture2DMultisampleIMG (GLenum, GLenum, GLenum, GLuint, GLint, GLsizei); +#endif +typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMG) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEIMG) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples); +#endif + +/*------------------------------------------------------------------------* + * NV extension functions + *------------------------------------------------------------------------*/ + +/* NV_fence */ +#ifndef GL_NV_fence +#define GL_NV_fence 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glDeleteFencesNV (GLsizei, const GLuint *); +GL_API void GL_APIENTRY glGenFencesNV (GLsizei, GLuint *); +GL_API GLboolean GL_APIENTRY glIsFenceNV (GLuint); +GL_API GLboolean GL_APIENTRY glTestFenceNV (GLuint); +GL_API void GL_APIENTRY glGetFenceivNV (GLuint, GLenum, GLint *); +GL_API void GL_APIENTRY glFinishFenceNV (GLuint); +GL_API void GL_APIENTRY glSetFenceNV (GLuint, GLenum); +#endif +typedef void (GL_APIENTRYP PFNGLDELETEFENCESNVPROC) (GLsizei n, const GLuint *fences); +typedef void (GL_APIENTRYP PFNGLGENFENCESNVPROC) (GLsizei n, GLuint *fences); +typedef GLboolean (GL_APIENTRYP PFNGLISFENCENVPROC) (GLuint fence); +typedef GLboolean (GL_APIENTRYP PFNGLTESTFENCENVPROC) (GLuint fence); +typedef void (GL_APIENTRYP PFNGLGETFENCEIVNVPROC) (GLuint fence, GLenum pname, GLint *params); +typedef void (GL_APIENTRYP PFNGLFINISHFENCENVPROC) (GLuint fence); +typedef void (GL_APIENTRYP PFNGLSETFENCENVPROC) (GLuint fence, GLenum condition); +#endif + +/*------------------------------------------------------------------------* + * QCOM extension functions + *------------------------------------------------------------------------*/ + +/* GL_QCOM_driver_control */ +#ifndef GL_QCOM_driver_control +#define GL_QCOM_driver_control 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glGetDriverControlsQCOM (GLint *num, GLsizei size, GLuint *driverControls); +GL_API void GL_APIENTRY glGetDriverControlStringQCOM (GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString); +GL_API void GL_APIENTRY glEnableDriverControlQCOM (GLuint driverControl); +GL_API void GL_APIENTRY glDisableDriverControlQCOM (GLuint driverControl); +#endif +typedef void (GL_APIENTRYP PFNGLGETDRIVERCONTROLSQCOMPROC) (GLint *num, GLsizei size, GLuint *driverControls); +typedef void (GL_APIENTRYP PFNGLGETDRIVERCONTROLSTRINGQCOMPROC) (GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString); +typedef void (GL_APIENTRYP PFNGLENABLEDRIVERCONTROLQCOMPROC) (GLuint driverControl); +typedef void (GL_APIENTRYP PFNGLDISABLEDRIVERCONTROLQCOMPROC) (GLuint driverControl); +#endif + +/* GL_QCOM_extended_get */ +#ifndef GL_QCOM_extended_get +#define GL_QCOM_extended_get 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glExtGetTexturesQCOM (GLuint *textures, GLint maxTextures, GLint *numTextures); +GL_API void GL_APIENTRY glExtGetBuffersQCOM (GLuint *buffers, GLint maxBuffers, GLint *numBuffers); +GL_API void GL_APIENTRY glExtGetRenderbuffersQCOM (GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers); +GL_API void GL_APIENTRY glExtGetFramebuffersQCOM (GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers); +GL_API void GL_APIENTRY glExtGetTexLevelParameterivQCOM (GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params); +GL_API void GL_APIENTRY glExtTexObjectStateOverrideiQCOM (GLenum target, GLenum pname, GLint param); +GL_API void GL_APIENTRY glExtGetTexSubImageQCOM (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels); +GL_API void GL_APIENTRY glExtGetBufferPointervQCOM (GLenum target, GLvoid **params); +#endif +typedef void (GL_APIENTRYP PFNGLEXTGETTEXTURESQCOMPROC) (GLuint *textures, GLint maxTextures, GLint *numTextures); +typedef void (GL_APIENTRYP PFNGLEXTGETBUFFERSQCOMPROC) (GLuint *buffers, GLint maxBuffers, GLint *numBuffers); +typedef void (GL_APIENTRYP PFNGLEXTGETRENDERBUFFERSQCOMPROC) (GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers); +typedef void (GL_APIENTRYP PFNGLEXTGETFRAMEBUFFERSQCOMPROC) (GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers); +typedef void (GL_APIENTRYP PFNGLEXTGETTEXLEVELPARAMETERIVQCOMPROC) (GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params); +typedef void (GL_APIENTRYP PFNGLEXTTEXOBJECTSTATEOVERRIDEIQCOMPROC) (GLenum target, GLenum pname, GLint param); +typedef void (GL_APIENTRYP PFNGLEXTGETTEXSUBIMAGEQCOMPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels); +typedef void (GL_APIENTRYP PFNGLEXTGETBUFFERPOINTERVQCOMPROC) (GLenum target, GLvoid **params); +#endif + +/* GL_QCOM_extended_get2 */ +#ifndef GL_QCOM_extended_get2 +#define GL_QCOM_extended_get2 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glExtGetShadersQCOM (GLuint *shaders, GLint maxShaders, GLint *numShaders); +GL_API void GL_APIENTRY glExtGetProgramsQCOM (GLuint *programs, GLint maxPrograms, GLint *numPrograms); +GL_API GLboolean GL_APIENTRY glExtIsProgramBinaryQCOM (GLuint program); +GL_API void GL_APIENTRY glExtGetProgramBinarySourceQCOM (GLuint program, GLenum shadertype, GLchar *source, GLint *length); +#endif +typedef void (GL_APIENTRYP PFNGLEXTGETSHADERSQCOMPROC) (GLuint *shaders, GLint maxShaders, GLint *numShaders); +typedef void (GL_APIENTRYP PFNGLEXTGETPROGRAMSQCOMPROC) (GLuint *programs, GLint maxPrograms, GLint *numPrograms); +typedef GLboolean (GL_APIENTRYP PFNGLEXTISPROGRAMBINARYQCOMPROC) (GLuint program); +typedef void (GL_APIENTRYP PFNGLEXTGETPROGRAMBINARYSOURCEQCOMPROC) (GLuint program, GLenum shadertype, GLchar *source, GLint *length); +#endif + +/* GL_QCOM_perfmon_global_mode */ +#ifndef GL_QCOM_perfmon_global_mode +#define GL_QCOM_perfmon_global_mode 1 +#endif + +/* GL_QCOM_writeonly_rendering */ +#ifndef GL_QCOM_writeonly_rendering +#define GL_QCOM_writeonly_rendering 1 +#endif + +/* GL_QCOM_tiled_rendering */ +#ifndef GL_QCOM_tiled_rendering +#define GL_QCOM_tiled_rendering 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_API void GL_APIENTRY glStartTilingQCOM (GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask); +GL_API void GL_APIENTRY glEndTilingQCOM (GLbitfield preserveMask); +#endif +typedef void (GL_APIENTRYP PFNGLSTARTTILINGQCOMPROC) (GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask); +typedef void (GL_APIENTRYP PFNGLENDTILINGQCOMPROC) (GLbitfield preserveMask); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __glext_h_ */ + diff --git a/emulator/opengl/host/libs/Translator/include/GLES/glplatform.h b/emulator/opengl/host/libs/Translator/include/GLES/glplatform.h new file mode 100644 index 0000000..2db6ee2 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLES/glplatform.h @@ -0,0 +1,30 @@ +#ifndef __glplatform_h_ +#define __glplatform_h_ + +/* $Revision: 10601 $ on $Date:: 2010-03-04 22:15:27 -0800 #$ */ + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +/* Platform-specific types and definitions for OpenGL ES 1.X gl.h + * + * Adopters may modify khrplatform.h and this file to suit their platform. + * You are encouraged to submit all modifications to the Khronos group so that + * they can be included in future versions of this file. Please submit changes + * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) + * by filing a bug against product "OpenGL-ES" component "Registry". + */ + +#include <KHR/khrplatform.h> + +#ifndef GL_API +#define GL_API KHRONOS_APICALL +#endif + +#ifndef GL_APIENTRY +#define GL_APIENTRY KHRONOS_APIENTRY +#endif + +#endif /* __glplatform_h_ */ diff --git a/emulator/opengl/host/libs/Translator/include/GLES2/gl2.h b/emulator/opengl/host/libs/Translator/include/GLES2/gl2.h new file mode 100644 index 0000000..e1d3b87 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLES2/gl2.h @@ -0,0 +1,621 @@ +#ifndef __gl2_h_ +#define __gl2_h_ + +/* $Revision: 10602 $ on $Date:: 2010-03-04 22:35:34 -0800 #$ */ + +#include <GLES2/gl2platform.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +/*------------------------------------------------------------------------- + * Data type definitions + *-----------------------------------------------------------------------*/ + +typedef void GLvoid; +typedef char GLchar; +typedef unsigned int GLenum; +typedef unsigned char GLboolean; +typedef unsigned int GLbitfield; +typedef khronos_int8_t GLbyte; +typedef short GLshort; +typedef int GLint; +typedef int GLsizei; +typedef khronos_uint8_t GLubyte; +typedef unsigned short GLushort; +typedef unsigned int GLuint; +typedef khronos_float_t GLfloat; +typedef khronos_float_t GLclampf; +typedef khronos_int32_t GLfixed; + +/* GL types for handling large vertex buffer objects */ +typedef khronos_intptr_t GLintptr; +typedef khronos_ssize_t GLsizeiptr; + +/* OpenGL ES core versions */ +#define GL_ES_VERSION_2_0 1 + +/* ClearBufferMask */ +#define GL_DEPTH_BUFFER_BIT 0x00000100 +#define GL_STENCIL_BUFFER_BIT 0x00000400 +#define GL_COLOR_BUFFER_BIT 0x00004000 + +/* Boolean */ +#define GL_FALSE 0 +#define GL_TRUE 1 + +/* BeginMode */ +#define GL_POINTS 0x0000 +#define GL_LINES 0x0001 +#define GL_LINE_LOOP 0x0002 +#define GL_LINE_STRIP 0x0003 +#define GL_TRIANGLES 0x0004 +#define GL_TRIANGLE_STRIP 0x0005 +#define GL_TRIANGLE_FAN 0x0006 + +/* AlphaFunction (not supported in ES20) */ +/* GL_NEVER */ +/* GL_LESS */ +/* GL_EQUAL */ +/* GL_LEQUAL */ +/* GL_GREATER */ +/* GL_NOTEQUAL */ +/* GL_GEQUAL */ +/* GL_ALWAYS */ + +/* BlendingFactorDest */ +#define GL_ZERO 0 +#define GL_ONE 1 +#define GL_SRC_COLOR 0x0300 +#define GL_ONE_MINUS_SRC_COLOR 0x0301 +#define GL_SRC_ALPHA 0x0302 +#define GL_ONE_MINUS_SRC_ALPHA 0x0303 +#define GL_DST_ALPHA 0x0304 +#define GL_ONE_MINUS_DST_ALPHA 0x0305 + +/* BlendingFactorSrc */ +/* GL_ZERO */ +/* GL_ONE */ +#define GL_DST_COLOR 0x0306 +#define GL_ONE_MINUS_DST_COLOR 0x0307 +#define GL_SRC_ALPHA_SATURATE 0x0308 +/* GL_SRC_ALPHA */ +/* GL_ONE_MINUS_SRC_ALPHA */ +/* GL_DST_ALPHA */ +/* GL_ONE_MINUS_DST_ALPHA */ + +/* BlendEquationSeparate */ +#define GL_FUNC_ADD 0x8006 +#define GL_BLEND_EQUATION 0x8009 +#define GL_BLEND_EQUATION_RGB 0x8009 /* same as BLEND_EQUATION */ +#define GL_BLEND_EQUATION_ALPHA 0x883D + +/* BlendSubtract */ +#define GL_FUNC_SUBTRACT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT 0x800B + +/* Separate Blend Functions */ +#define GL_BLEND_DST_RGB 0x80C8 +#define GL_BLEND_SRC_RGB 0x80C9 +#define GL_BLEND_DST_ALPHA 0x80CA +#define GL_BLEND_SRC_ALPHA 0x80CB +#define GL_CONSTANT_COLOR 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 +#define GL_CONSTANT_ALPHA 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 +#define GL_BLEND_COLOR 0x8005 + +/* Buffer Objects */ +#define GL_ARRAY_BUFFER 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER 0x8893 +#define GL_ARRAY_BUFFER_BINDING 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 + +#define GL_STREAM_DRAW 0x88E0 +#define GL_STATIC_DRAW 0x88E4 +#define GL_DYNAMIC_DRAW 0x88E8 + +#define GL_BUFFER_SIZE 0x8764 +#define GL_BUFFER_USAGE 0x8765 + +#define GL_CURRENT_VERTEX_ATTRIB 0x8626 + +/* CullFaceMode */ +#define GL_FRONT 0x0404 +#define GL_BACK 0x0405 +#define GL_FRONT_AND_BACK 0x0408 + +/* DepthFunction */ +/* GL_NEVER */ +/* GL_LESS */ +/* GL_EQUAL */ +/* GL_LEQUAL */ +/* GL_GREATER */ +/* GL_NOTEQUAL */ +/* GL_GEQUAL */ +/* GL_ALWAYS */ + +/* EnableCap */ +#define GL_TEXTURE_2D 0x0DE1 +#define GL_CULL_FACE 0x0B44 +#define GL_BLEND 0x0BE2 +#define GL_DITHER 0x0BD0 +#define GL_STENCIL_TEST 0x0B90 +#define GL_DEPTH_TEST 0x0B71 +#define GL_SCISSOR_TEST 0x0C11 +#define GL_POLYGON_OFFSET_FILL 0x8037 +#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E +#define GL_SAMPLE_COVERAGE 0x80A0 + +/* ErrorCode */ +#define GL_NO_ERROR 0 +#define GL_INVALID_ENUM 0x0500 +#define GL_INVALID_VALUE 0x0501 +#define GL_INVALID_OPERATION 0x0502 +#define GL_OUT_OF_MEMORY 0x0505 + +/* FrontFaceDirection */ +#define GL_CW 0x0900 +#define GL_CCW 0x0901 + +/* GetPName */ +#define GL_LINE_WIDTH 0x0B21 +#define GL_ALIASED_POINT_SIZE_RANGE 0x846D +#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E +#define GL_CULL_FACE_MODE 0x0B45 +#define GL_FRONT_FACE 0x0B46 +#define GL_DEPTH_RANGE 0x0B70 +#define GL_DEPTH_WRITEMASK 0x0B72 +#define GL_DEPTH_CLEAR_VALUE 0x0B73 +#define GL_DEPTH_FUNC 0x0B74 +#define GL_STENCIL_CLEAR_VALUE 0x0B91 +#define GL_STENCIL_FUNC 0x0B92 +#define GL_STENCIL_FAIL 0x0B94 +#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95 +#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96 +#define GL_STENCIL_REF 0x0B97 +#define GL_STENCIL_VALUE_MASK 0x0B93 +#define GL_STENCIL_WRITEMASK 0x0B98 +#define GL_STENCIL_BACK_FUNC 0x8800 +#define GL_STENCIL_BACK_FAIL 0x8801 +#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802 +#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803 +#define GL_STENCIL_BACK_REF 0x8CA3 +#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4 +#define GL_STENCIL_BACK_WRITEMASK 0x8CA5 +#define GL_VIEWPORT 0x0BA2 +#define GL_SCISSOR_BOX 0x0C10 +/* GL_SCISSOR_TEST */ +#define GL_COLOR_CLEAR_VALUE 0x0C22 +#define GL_COLOR_WRITEMASK 0x0C23 +#define GL_UNPACK_ALIGNMENT 0x0CF5 +#define GL_PACK_ALIGNMENT 0x0D05 +#define GL_MAX_TEXTURE_SIZE 0x0D33 +#define GL_MAX_VIEWPORT_DIMS 0x0D3A +#define GL_SUBPIXEL_BITS 0x0D50 +#define GL_RED_BITS 0x0D52 +#define GL_GREEN_BITS 0x0D53 +#define GL_BLUE_BITS 0x0D54 +#define GL_ALPHA_BITS 0x0D55 +#define GL_DEPTH_BITS 0x0D56 +#define GL_STENCIL_BITS 0x0D57 +#define GL_POLYGON_OFFSET_UNITS 0x2A00 +/* GL_POLYGON_OFFSET_FILL */ +#define GL_POLYGON_OFFSET_FACTOR 0x8038 +#define GL_TEXTURE_BINDING_2D 0x8069 +#define GL_SAMPLE_BUFFERS 0x80A8 +#define GL_SAMPLES 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT 0x80AB + +/* GetTextureParameter */ +/* GL_TEXTURE_MAG_FILTER */ +/* GL_TEXTURE_MIN_FILTER */ +/* GL_TEXTURE_WRAP_S */ +/* GL_TEXTURE_WRAP_T */ + +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 + +/* HintMode */ +#define GL_DONT_CARE 0x1100 +#define GL_FASTEST 0x1101 +#define GL_NICEST 0x1102 + +/* HintTarget */ +#define GL_GENERATE_MIPMAP_HINT 0x8192 + +/* DataType */ +#define GL_BYTE 0x1400 +#define GL_UNSIGNED_BYTE 0x1401 +#define GL_SHORT 0x1402 +#define GL_UNSIGNED_SHORT 0x1403 +#define GL_INT 0x1404 +#define GL_UNSIGNED_INT 0x1405 +#define GL_FLOAT 0x1406 +#define GL_FIXED 0x140C + +/* PixelFormat */ +#define GL_DEPTH_COMPONENT 0x1902 +#define GL_ALPHA 0x1906 +#define GL_RGB 0x1907 +#define GL_RGBA 0x1908 +#define GL_LUMINANCE 0x1909 +#define GL_LUMINANCE_ALPHA 0x190A + +/* PixelType */ +/* GL_UNSIGNED_BYTE */ +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 + +/* Shaders */ +#define GL_FRAGMENT_SHADER 0x8B30 +#define GL_VERTEX_SHADER 0x8B31 +#define GL_MAX_VERTEX_ATTRIBS 0x8869 +#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB +#define GL_MAX_VARYING_VECTORS 0x8DFC +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D +#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C +#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872 +#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD +#define GL_SHADER_TYPE 0x8B4F +#define GL_DELETE_STATUS 0x8B80 +#define GL_LINK_STATUS 0x8B82 +#define GL_VALIDATE_STATUS 0x8B83 +#define GL_ATTACHED_SHADERS 0x8B85 +#define GL_ACTIVE_UNIFORMS 0x8B86 +#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87 +#define GL_ACTIVE_ATTRIBUTES 0x8B89 +#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A +#define GL_SHADING_LANGUAGE_VERSION 0x8B8C +#define GL_CURRENT_PROGRAM 0x8B8D + +/* StencilFunction */ +#define GL_NEVER 0x0200 +#define GL_LESS 0x0201 +#define GL_EQUAL 0x0202 +#define GL_LEQUAL 0x0203 +#define GL_GREATER 0x0204 +#define GL_NOTEQUAL 0x0205 +#define GL_GEQUAL 0x0206 +#define GL_ALWAYS 0x0207 + +/* StencilOp */ +/* GL_ZERO */ +#define GL_KEEP 0x1E00 +#define GL_REPLACE 0x1E01 +#define GL_INCR 0x1E02 +#define GL_DECR 0x1E03 +#define GL_INVERT 0x150A +#define GL_INCR_WRAP 0x8507 +#define GL_DECR_WRAP 0x8508 + +/* StringName */ +#define GL_VENDOR 0x1F00 +#define GL_RENDERER 0x1F01 +#define GL_VERSION 0x1F02 +#define GL_EXTENSIONS 0x1F03 + +/* TextureMagFilter */ +#define GL_NEAREST 0x2600 +#define GL_LINEAR 0x2601 + +/* TextureMinFilter */ +/* GL_NEAREST */ +/* GL_LINEAR */ +#define GL_NEAREST_MIPMAP_NEAREST 0x2700 +#define GL_LINEAR_MIPMAP_NEAREST 0x2701 +#define GL_NEAREST_MIPMAP_LINEAR 0x2702 +#define GL_LINEAR_MIPMAP_LINEAR 0x2703 + +/* TextureParameterName */ +#define GL_TEXTURE_MAG_FILTER 0x2800 +#define GL_TEXTURE_MIN_FILTER 0x2801 +#define GL_TEXTURE_WRAP_S 0x2802 +#define GL_TEXTURE_WRAP_T 0x2803 + +/* TextureTarget */ +/* GL_TEXTURE_2D */ +#define GL_TEXTURE 0x1702 + +#define GL_TEXTURE_CUBE_MAP 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C + +/* TextureUnit */ +#define GL_TEXTURE0 0x84C0 +#define GL_TEXTURE1 0x84C1 +#define GL_TEXTURE2 0x84C2 +#define GL_TEXTURE3 0x84C3 +#define GL_TEXTURE4 0x84C4 +#define GL_TEXTURE5 0x84C5 +#define GL_TEXTURE6 0x84C6 +#define GL_TEXTURE7 0x84C7 +#define GL_TEXTURE8 0x84C8 +#define GL_TEXTURE9 0x84C9 +#define GL_TEXTURE10 0x84CA +#define GL_TEXTURE11 0x84CB +#define GL_TEXTURE12 0x84CC +#define GL_TEXTURE13 0x84CD +#define GL_TEXTURE14 0x84CE +#define GL_TEXTURE15 0x84CF +#define GL_TEXTURE16 0x84D0 +#define GL_TEXTURE17 0x84D1 +#define GL_TEXTURE18 0x84D2 +#define GL_TEXTURE19 0x84D3 +#define GL_TEXTURE20 0x84D4 +#define GL_TEXTURE21 0x84D5 +#define GL_TEXTURE22 0x84D6 +#define GL_TEXTURE23 0x84D7 +#define GL_TEXTURE24 0x84D8 +#define GL_TEXTURE25 0x84D9 +#define GL_TEXTURE26 0x84DA +#define GL_TEXTURE27 0x84DB +#define GL_TEXTURE28 0x84DC +#define GL_TEXTURE29 0x84DD +#define GL_TEXTURE30 0x84DE +#define GL_TEXTURE31 0x84DF +#define GL_ACTIVE_TEXTURE 0x84E0 + +/* TextureWrapMode */ +#define GL_REPEAT 0x2901 +#define GL_CLAMP_TO_EDGE 0x812F +#define GL_MIRRORED_REPEAT 0x8370 + +/* Uniform Types */ +#define GL_FLOAT_VEC2 0x8B50 +#define GL_FLOAT_VEC3 0x8B51 +#define GL_FLOAT_VEC4 0x8B52 +#define GL_INT_VEC2 0x8B53 +#define GL_INT_VEC3 0x8B54 +#define GL_INT_VEC4 0x8B55 +#define GL_BOOL 0x8B56 +#define GL_BOOL_VEC2 0x8B57 +#define GL_BOOL_VEC3 0x8B58 +#define GL_BOOL_VEC4 0x8B59 +#define GL_FLOAT_MAT2 0x8B5A +#define GL_FLOAT_MAT3 0x8B5B +#define GL_FLOAT_MAT4 0x8B5C +#define GL_SAMPLER_2D 0x8B5E +#define GL_SAMPLER_CUBE 0x8B60 + +/* Vertex Arrays */ +#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 +#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 +#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 +#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 +#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A +#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F + +/* Read Format */ +#define GL_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A +#define GL_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B + +/* Shader Source */ +#define GL_COMPILE_STATUS 0x8B81 +#define GL_INFO_LOG_LENGTH 0x8B84 +#define GL_SHADER_SOURCE_LENGTH 0x8B88 +#define GL_SHADER_COMPILER 0x8DFA + +/* Shader Binary */ +#define GL_SHADER_BINARY_FORMATS 0x8DF8 +#define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9 + +/* Shader Precision-Specified Types */ +#define GL_LOW_FLOAT 0x8DF0 +#define GL_MEDIUM_FLOAT 0x8DF1 +#define GL_HIGH_FLOAT 0x8DF2 +#define GL_LOW_INT 0x8DF3 +#define GL_MEDIUM_INT 0x8DF4 +#define GL_HIGH_INT 0x8DF5 + +/* Framebuffer Object. */ +#define GL_FRAMEBUFFER 0x8D40 +#define GL_RENDERBUFFER 0x8D41 + +#define GL_RGBA4 0x8056 +#define GL_RGB5_A1 0x8057 +#define GL_RGB565 0x8D62 +#define GL_DEPTH_COMPONENT16 0x81A5 +#define GL_STENCIL_INDEX 0x1901 +#define GL_STENCIL_INDEX8 0x8D48 + +#define GL_RENDERBUFFER_WIDTH 0x8D42 +#define GL_RENDERBUFFER_HEIGHT 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44 +#define GL_RENDERBUFFER_RED_SIZE 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 + +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3 + +#define GL_COLOR_ATTACHMENT0 0x8CE0 +#define GL_DEPTH_ATTACHMENT 0x8D00 +#define GL_STENCIL_ATTACHMENT 0x8D20 + +#define GL_NONE 0 + +#define GL_FRAMEBUFFER_COMPLETE 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 0x8CD9 +#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD + +#define GL_FRAMEBUFFER_BINDING 0x8CA6 +#define GL_RENDERBUFFER_BINDING 0x8CA7 +#define GL_MAX_RENDERBUFFER_SIZE 0x84E8 + +#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 + +/*------------------------------------------------------------------------- + * GL core functions. + *-----------------------------------------------------------------------*/ + +GL_APICALL void GL_APIENTRY glActiveTexture (GLenum texture); +GL_APICALL void GL_APIENTRY glAttachShader (GLuint program, GLuint shader); +GL_APICALL void GL_APIENTRY glBindAttribLocation (GLuint program, GLuint index, const GLchar* name); +GL_APICALL void GL_APIENTRY glBindBuffer (GLenum target, GLuint buffer); +GL_APICALL void GL_APIENTRY glBindFramebuffer (GLenum target, GLuint framebuffer); +GL_APICALL void GL_APIENTRY glBindRenderbuffer (GLenum target, GLuint renderbuffer); +GL_APICALL void GL_APIENTRY glBindTexture (GLenum target, GLuint texture); +GL_APICALL void GL_APIENTRY glBlendColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +GL_APICALL void GL_APIENTRY glBlendEquation ( GLenum mode ); +GL_APICALL void GL_APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha); +GL_APICALL void GL_APIENTRY glBlendFunc (GLenum sfactor, GLenum dfactor); +GL_APICALL void GL_APIENTRY glBlendFuncSeparate (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +GL_APICALL void GL_APIENTRY glBufferData (GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage); +GL_APICALL void GL_APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data); +GL_APICALL GLenum GL_APIENTRY glCheckFramebufferStatus (GLenum target); +GL_APICALL void GL_APIENTRY glClear (GLbitfield mask); +GL_APICALL void GL_APIENTRY glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +GL_APICALL void GL_APIENTRY glClearDepthf (GLclampf depth); +GL_APICALL void GL_APIENTRY glClearStencil (GLint s); +GL_APICALL void GL_APIENTRY glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +GL_APICALL void GL_APIENTRY glCompileShader (GLuint shader); +GL_APICALL void GL_APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid* data); +GL_APICALL void GL_APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid* data); +GL_APICALL void GL_APIENTRY glCopyTexImage2D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +GL_APICALL void GL_APIENTRY glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GL_APICALL GLuint GL_APIENTRY glCreateProgram (void); +GL_APICALL GLuint GL_APIENTRY glCreateShader (GLenum type); +GL_APICALL void GL_APIENTRY glCullFace (GLenum mode); +GL_APICALL void GL_APIENTRY glDeleteBuffers (GLsizei n, const GLuint* buffers); +GL_APICALL void GL_APIENTRY glDeleteFramebuffers (GLsizei n, const GLuint* framebuffers); +GL_APICALL void GL_APIENTRY glDeleteProgram (GLuint program); +GL_APICALL void GL_APIENTRY glDeleteRenderbuffers (GLsizei n, const GLuint* renderbuffers); +GL_APICALL void GL_APIENTRY glDeleteShader (GLuint shader); +GL_APICALL void GL_APIENTRY glDeleteTextures (GLsizei n, const GLuint* textures); +GL_APICALL void GL_APIENTRY glDepthFunc (GLenum func); +GL_APICALL void GL_APIENTRY glDepthMask (GLboolean flag); +GL_APICALL void GL_APIENTRY glDepthRangef (GLclampf zNear, GLclampf zFar); +GL_APICALL void GL_APIENTRY glDetachShader (GLuint program, GLuint shader); +GL_APICALL void GL_APIENTRY glDisable (GLenum cap); +GL_APICALL void GL_APIENTRY glDisableVertexAttribArray (GLuint index); +GL_APICALL void GL_APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count); +GL_APICALL void GL_APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid* indices); +GL_APICALL void GL_APIENTRY glEnable (GLenum cap); +GL_APICALL void GL_APIENTRY glEnableVertexAttribArray (GLuint index); +GL_APICALL void GL_APIENTRY glFinish (void); +GL_APICALL void GL_APIENTRY glFlush (void); +GL_APICALL void GL_APIENTRY glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +GL_APICALL void GL_APIENTRY glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +GL_APICALL void GL_APIENTRY glFrontFace (GLenum mode); +GL_APICALL void GL_APIENTRY glGenBuffers (GLsizei n, GLuint* buffers); +GL_APICALL void GL_APIENTRY glGenerateMipmap (GLenum target); +GL_APICALL void GL_APIENTRY glGenFramebuffers (GLsizei n, GLuint* framebuffers); +GL_APICALL void GL_APIENTRY glGenRenderbuffers (GLsizei n, GLuint* renderbuffers); +GL_APICALL void GL_APIENTRY glGenTextures (GLsizei n, GLuint* textures); +GL_APICALL void GL_APIENTRY glGetActiveAttrib (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name); +GL_APICALL void GL_APIENTRY glGetActiveUniform (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name); +GL_APICALL void GL_APIENTRY glGetAttachedShaders (GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders); +GL_APICALL int GL_APIENTRY glGetAttribLocation (GLuint program, const GLchar* name); +GL_APICALL void GL_APIENTRY glGetBooleanv (GLenum pname, GLboolean* params); +GL_APICALL void GL_APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint* params); +GL_APICALL GLenum GL_APIENTRY glGetError (void); +GL_APICALL void GL_APIENTRY glGetFloatv (GLenum pname, GLfloat* params); +GL_APICALL void GL_APIENTRY glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetIntegerv (GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog); +GL_APICALL void GL_APIENTRY glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog); +GL_APICALL void GL_APIENTRY glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision); +GL_APICALL void GL_APIENTRY glGetShaderSource (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source); +GL_APICALL const GLubyte* GL_APIENTRY glGetString (GLenum name); +GL_APICALL void GL_APIENTRY glGetTexParameterfv (GLenum target, GLenum pname, GLfloat* params); +GL_APICALL void GL_APIENTRY glGetTexParameteriv (GLenum target, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetUniformfv (GLuint program, GLint location, GLfloat* params); +GL_APICALL void GL_APIENTRY glGetUniformiv (GLuint program, GLint location, GLint* params); +GL_APICALL int GL_APIENTRY glGetUniformLocation (GLuint program, const GLchar* name); +GL_APICALL void GL_APIENTRY glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat* params); +GL_APICALL void GL_APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint* params); +GL_APICALL void GL_APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, GLvoid** pointer); +GL_APICALL void GL_APIENTRY glHint (GLenum target, GLenum mode); +GL_APICALL GLboolean GL_APIENTRY glIsBuffer (GLuint buffer); +GL_APICALL GLboolean GL_APIENTRY glIsEnabled (GLenum cap); +GL_APICALL GLboolean GL_APIENTRY glIsFramebuffer (GLuint framebuffer); +GL_APICALL GLboolean GL_APIENTRY glIsProgram (GLuint program); +GL_APICALL GLboolean GL_APIENTRY glIsRenderbuffer (GLuint renderbuffer); +GL_APICALL GLboolean GL_APIENTRY glIsShader (GLuint shader); +GL_APICALL GLboolean GL_APIENTRY glIsTexture (GLuint texture); +GL_APICALL void GL_APIENTRY glLineWidth (GLfloat width); +GL_APICALL void GL_APIENTRY glLinkProgram (GLuint program); +GL_APICALL void GL_APIENTRY glPixelStorei (GLenum pname, GLint param); +GL_APICALL void GL_APIENTRY glPolygonOffset (GLfloat factor, GLfloat units); +GL_APICALL void GL_APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels); +GL_APICALL void GL_APIENTRY glReleaseShaderCompiler (void); +GL_APICALL void GL_APIENTRY glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glSampleCoverage (GLclampf value, GLboolean invert); +GL_APICALL void GL_APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glShaderBinary (GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length); +GL_APICALL void GL_APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar** string, const GLint* length); +GL_APICALL void GL_APIENTRY glStencilFunc (GLenum func, GLint ref, GLuint mask); +GL_APICALL void GL_APIENTRY glStencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask); +GL_APICALL void GL_APIENTRY glStencilMask (GLuint mask); +GL_APICALL void GL_APIENTRY glStencilMaskSeparate (GLenum face, GLuint mask); +GL_APICALL void GL_APIENTRY glStencilOp (GLenum fail, GLenum zfail, GLenum zpass); +GL_APICALL void GL_APIENTRY glStencilOpSeparate (GLenum face, GLenum fail, GLenum zfail, GLenum zpass); +GL_APICALL void GL_APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels); +GL_APICALL void GL_APIENTRY glTexParameterf (GLenum target, GLenum pname, GLfloat param); +GL_APICALL void GL_APIENTRY glTexParameterfv (GLenum target, GLenum pname, const GLfloat* params); +GL_APICALL void GL_APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param); +GL_APICALL void GL_APIENTRY glTexParameteriv (GLenum target, GLenum pname, const GLint* params); +GL_APICALL void GL_APIENTRY glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels); +GL_APICALL void GL_APIENTRY glUniform1f (GLint location, GLfloat x); +GL_APICALL void GL_APIENTRY glUniform1fv (GLint location, GLsizei count, const GLfloat* v); +GL_APICALL void GL_APIENTRY glUniform1i (GLint location, GLint x); +GL_APICALL void GL_APIENTRY glUniform1iv (GLint location, GLsizei count, const GLint* v); +GL_APICALL void GL_APIENTRY glUniform2f (GLint location, GLfloat x, GLfloat y); +GL_APICALL void GL_APIENTRY glUniform2fv (GLint location, GLsizei count, const GLfloat* v); +GL_APICALL void GL_APIENTRY glUniform2i (GLint location, GLint x, GLint y); +GL_APICALL void GL_APIENTRY glUniform2iv (GLint location, GLsizei count, const GLint* v); +GL_APICALL void GL_APIENTRY glUniform3f (GLint location, GLfloat x, GLfloat y, GLfloat z); +GL_APICALL void GL_APIENTRY glUniform3fv (GLint location, GLsizei count, const GLfloat* v); +GL_APICALL void GL_APIENTRY glUniform3i (GLint location, GLint x, GLint y, GLint z); +GL_APICALL void GL_APIENTRY glUniform3iv (GLint location, GLsizei count, const GLint* v); +GL_APICALL void GL_APIENTRY glUniform4f (GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GL_APICALL void GL_APIENTRY glUniform4fv (GLint location, GLsizei count, const GLfloat* v); +GL_APICALL void GL_APIENTRY glUniform4i (GLint location, GLint x, GLint y, GLint z, GLint w); +GL_APICALL void GL_APIENTRY glUniform4iv (GLint location, GLsizei count, const GLint* v); +GL_APICALL void GL_APIENTRY glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); +GL_APICALL void GL_APIENTRY glUseProgram (GLuint program); +GL_APICALL void GL_APIENTRY glValidateProgram (GLuint program); +GL_APICALL void GL_APIENTRY glVertexAttrib1f (GLuint indx, GLfloat x); +GL_APICALL void GL_APIENTRY glVertexAttrib1fv (GLuint indx, const GLfloat* values); +GL_APICALL void GL_APIENTRY glVertexAttrib2f (GLuint indx, GLfloat x, GLfloat y); +GL_APICALL void GL_APIENTRY glVertexAttrib2fv (GLuint indx, const GLfloat* values); +GL_APICALL void GL_APIENTRY glVertexAttrib3f (GLuint indx, GLfloat x, GLfloat y, GLfloat z); +GL_APICALL void GL_APIENTRY glVertexAttrib3fv (GLuint indx, const GLfloat* values); +GL_APICALL void GL_APIENTRY glVertexAttrib4f (GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +GL_APICALL void GL_APIENTRY glVertexAttrib4fv (GLuint indx, const GLfloat* values); +GL_APICALL void GL_APIENTRY glVertexAttribPointer (GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr); +GL_APICALL void GL_APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height); + +#ifdef __cplusplus +} +#endif + +#endif /* __gl2_h_ */ diff --git a/emulator/opengl/host/libs/Translator/include/GLES2/gl2ext.h b/emulator/opengl/host/libs/Translator/include/GLES2/gl2ext.h new file mode 100644 index 0000000..46f6093 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLES2/gl2ext.h @@ -0,0 +1,973 @@ +#ifndef __gl2ext_h_ +#define __gl2ext_h_ + +/* $Revision: 13239 $ on $Date:: 2010-12-17 15:13:56 -0800 #$ */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +#ifndef GL_APIENTRYP +# define GL_APIENTRYP GL_APIENTRY* +#endif + +/*------------------------------------------------------------------------* + * OES extension tokens + *------------------------------------------------------------------------*/ + +/* GL_OES_compressed_ETC1_RGB8_texture */ +#ifndef GL_OES_compressed_ETC1_RGB8_texture +#define GL_ETC1_RGB8_OES 0x8D64 +#endif + +/* GL_OES_compressed_paletted_texture */ +#ifndef GL_OES_compressed_paletted_texture +#define GL_PALETTE4_RGB8_OES 0x8B90 +#define GL_PALETTE4_RGBA8_OES 0x8B91 +#define GL_PALETTE4_R5_G6_B5_OES 0x8B92 +#define GL_PALETTE4_RGBA4_OES 0x8B93 +#define GL_PALETTE4_RGB5_A1_OES 0x8B94 +#define GL_PALETTE8_RGB8_OES 0x8B95 +#define GL_PALETTE8_RGBA8_OES 0x8B96 +#define GL_PALETTE8_R5_G6_B5_OES 0x8B97 +#define GL_PALETTE8_RGBA4_OES 0x8B98 +#define GL_PALETTE8_RGB5_A1_OES 0x8B99 +#endif + +/* GL_OES_depth24 */ +#ifndef GL_OES_depth24 +#define GL_DEPTH_COMPONENT24_OES 0x81A6 +#endif + +/* GL_OES_depth32 */ +#ifndef GL_OES_depth32 +#define GL_DEPTH_COMPONENT32_OES 0x81A7 +#endif + +/* GL_OES_depth_texture */ +/* No new tokens introduced by this extension. */ + +/* GL_OES_EGL_image */ +#ifndef GL_OES_EGL_image +typedef void* GLeglImageOES; +#endif + +/* GL_OES_EGL_image_external */ +#ifndef GL_OES_EGL_image_external +/* GLeglImageOES defined in GL_OES_EGL_image already. */ +#define GL_TEXTURE_EXTERNAL_OES 0x8D65 +#define GL_SAMPLER_EXTERNAL_OES 0x8D66 +#define GL_TEXTURE_BINDING_EXTERNAL_OES 0x8D67 +#define GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES 0x8D68 +#endif + +/* GL_OES_element_index_uint */ +#ifndef GL_OES_element_index_uint +#define GL_UNSIGNED_INT 0x1405 +#endif + +/* GL_OES_get_program_binary */ +#ifndef GL_OES_get_program_binary +#define GL_PROGRAM_BINARY_LENGTH_OES 0x8741 +#define GL_NUM_PROGRAM_BINARY_FORMATS_OES 0x87FE +#define GL_PROGRAM_BINARY_FORMATS_OES 0x87FF +#endif + +/* GL_OES_mapbuffer */ +#ifndef GL_OES_mapbuffer +#define GL_WRITE_ONLY_OES 0x88B9 +#define GL_BUFFER_ACCESS_OES 0x88BB +#define GL_BUFFER_MAPPED_OES 0x88BC +#define GL_BUFFER_MAP_POINTER_OES 0x88BD +#endif + +/* GL_OES_packed_depth_stencil */ +#ifndef GL_OES_packed_depth_stencil +#define GL_DEPTH_STENCIL_OES 0x84F9 +#define GL_UNSIGNED_INT_24_8_OES 0x84FA +#define GL_DEPTH24_STENCIL8_OES 0x88F0 +#endif + +/* GL_OES_rgb8_rgba8 */ +#ifndef GL_OES_rgb8_rgba8 +#define GL_RGB8_OES 0x8051 +#define GL_RGBA8_OES 0x8058 +#endif + +/* GL_OES_standard_derivatives */ +#ifndef GL_OES_standard_derivatives +#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES 0x8B8B +#endif + +/* GL_OES_stencil1 */ +#ifndef GL_OES_stencil1 +#define GL_STENCIL_INDEX1_OES 0x8D46 +#endif + +/* GL_OES_stencil4 */ +#ifndef GL_OES_stencil4 +#define GL_STENCIL_INDEX4_OES 0x8D47 +#endif + +/* GL_OES_texture_3D */ +#ifndef GL_OES_texture_3D +#define GL_TEXTURE_WRAP_R_OES 0x8072 +#define GL_TEXTURE_3D_OES 0x806F +#define GL_TEXTURE_BINDING_3D_OES 0x806A +#define GL_MAX_3D_TEXTURE_SIZE_OES 0x8073 +#define GL_SAMPLER_3D_OES 0x8B5F +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_OES 0x8CD4 +#endif + +/* GL_OES_texture_float */ +/* No new tokens introduced by this extension. */ + +/* GL_OES_texture_float_linear */ +/* No new tokens introduced by this extension. */ + +/* GL_OES_texture_half_float */ +#ifndef GL_OES_texture_half_float +#define GL_HALF_FLOAT_OES 0x8D61 +#endif + +/* GL_OES_texture_half_float_linear */ +/* No new tokens introduced by this extension. */ + +/* GL_OES_texture_npot */ +/* No new tokens introduced by this extension. */ + +/* GL_OES_vertex_array_object */ +#ifndef GL_OES_vertex_array_object +#define GL_VERTEX_ARRAY_BINDING_OES 0x85B5 +#endif + +/* GL_OES_vertex_half_float */ +/* GL_HALF_FLOAT_OES defined in GL_OES_texture_half_float already. */ + +/* GL_OES_vertex_type_10_10_10_2 */ +#ifndef GL_OES_vertex_type_10_10_10_2 +#define GL_UNSIGNED_INT_10_10_10_2_OES 0x8DF6 +#define GL_INT_10_10_10_2_OES 0x8DF7 +#endif + +/*------------------------------------------------------------------------* + * AMD extension tokens + *------------------------------------------------------------------------*/ + +/* GL_AMD_compressed_3DC_texture */ +#ifndef GL_AMD_compressed_3DC_texture +#define GL_3DC_X_AMD 0x87F9 +#define GL_3DC_XY_AMD 0x87FA +#endif + +/* GL_AMD_compressed_ATC_texture */ +#ifndef GL_AMD_compressed_ATC_texture +#define GL_ATC_RGB_AMD 0x8C92 +#define GL_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93 +#define GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE +#endif + +/* GL_AMD_performance_monitor */ +#ifndef GL_AMD_performance_monitor +#define GL_COUNTER_TYPE_AMD 0x8BC0 +#define GL_COUNTER_RANGE_AMD 0x8BC1 +#define GL_UNSIGNED_INT64_AMD 0x8BC2 +#define GL_PERCENTAGE_AMD 0x8BC3 +#define GL_PERFMON_RESULT_AVAILABLE_AMD 0x8BC4 +#define GL_PERFMON_RESULT_SIZE_AMD 0x8BC5 +#define GL_PERFMON_RESULT_AMD 0x8BC6 +#endif + +/* GL_AMD_program_binary_Z400 */ +#ifndef GL_AMD_program_binary_Z400 +#define GL_Z400_BINARY_AMD 0x8740 +#endif + +/*------------------------------------------------------------------------* + * ANGLE extension tokens + *------------------------------------------------------------------------*/ + +/* GL_ANGLE_framebuffer_blit */ +#ifndef GL_ANGLE_framebuffer_blit +#define GL_READ_FRAMEBUFFER_ANGLE 0x8CA8 +#define GL_DRAW_FRAMEBUFFER_ANGLE 0x8CA9 +#define GL_DRAW_FRAMEBUFFER_BINDING_ANGLE 0x8CA6 +#define GL_READ_FRAMEBUFFER_BINDING_ANGLE 0x8CAA +#endif + +/* GL_ANGLE_framebuffer_multisample */ +#ifndef GL_ANGLE_framebuffer_multisample +#define GL_RENDERBUFFER_SAMPLES_ANGLE 0x8CAB +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE 0x8D56 +#define GL_MAX_SAMPLES_ANGLE 0x8D57 +#endif + +/*------------------------------------------------------------------------* + * APPLE extension tokens + *------------------------------------------------------------------------*/ + +/* GL_APPLE_rgb_422 */ +#ifndef GL_APPLE_rgb_422 +#define GL_RGB_422_APPLE 0x8A1F +#define GL_UNSIGNED_SHORT_8_8_APPLE 0x85BA +#define GL_UNSIGNED_SHORT_8_8_REV_APPLE 0x85BB +#endif + +/* GL_APPLE_framebuffer_multisample */ +#ifndef GL_APPLE_framebuffer_multisample +#define GL_RENDERBUFFER_SAMPLES_APPLE 0x8CAB +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_APPLE 0x8D56 +#define GL_MAX_SAMPLES_APPLE 0x8D57 +#define GL_READ_FRAMEBUFFER_APPLE 0x8CA8 +#define GL_DRAW_FRAMEBUFFER_APPLE 0x8CA9 +#define GL_DRAW_FRAMEBUFFER_BINDING_APPLE 0x8CA6 +#define GL_READ_FRAMEBUFFER_BINDING_APPLE 0x8CAA +#endif + +/* GL_APPLE_texture_format_BGRA8888 */ +#ifndef GL_APPLE_texture_format_BGRA8888 +#define GL_BGRA_EXT 0x80E1 +#endif + +/* GL_APPLE_texture_max_level */ +#ifndef GL_APPLE_texture_max_level +#define GL_TEXTURE_MAX_LEVEL_APPLE 0x813D +#endif + +/*------------------------------------------------------------------------* + * ARM extension tokens + *------------------------------------------------------------------------*/ + +/* GL_ARM_mali_shader_binary */ +#ifndef GL_ARM_mali_shader_binary +#define GL_MALI_SHADER_BINARY_ARM 0x8F60 +#endif + +/* GL_ARM_rgba8 */ +/* No new tokens introduced by this extension. */ + +/*------------------------------------------------------------------------* + * EXT extension tokens + *------------------------------------------------------------------------*/ + +/* GL_EXT_blend_minmax */ +#ifndef GL_EXT_blend_minmax +#define GL_MIN_EXT 0x8007 +#define GL_MAX_EXT 0x8008 +#endif + +/* GL_EXT_discard_framebuffer */ +#ifndef GL_EXT_discard_framebuffer +#define GL_COLOR_EXT 0x1800 +#define GL_DEPTH_EXT 0x1801 +#define GL_STENCIL_EXT 0x1802 +#endif + +/* GL_EXT_multi_draw_arrays */ +/* No new tokens introduced by this extension. */ + +/* GL_EXT_read_format_bgra */ +#ifndef GL_EXT_read_format_bgra +#define GL_BGRA_EXT 0x80E1 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT 0x8365 +#define GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT 0x8366 +#endif + +/* GL_EXT_texture_filter_anisotropic */ +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE +#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF +#endif + +/* GL_EXT_texture_format_BGRA8888 */ +#ifndef GL_EXT_texture_format_BGRA8888 +#define GL_BGRA_EXT 0x80E1 +#endif + +/* GL_EXT_texture_type_2_10_10_10_REV */ +#ifndef GL_EXT_texture_type_2_10_10_10_REV +#define GL_UNSIGNED_INT_2_10_10_10_REV_EXT 0x8368 +#endif + +/* GL_EXT_texture_compression_dxt1 */ +#ifndef GL_EXT_texture_compression_dxt1 +#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 +#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 +#endif + +/* GL_EXT_shader_texture_lod */ +/* No new tokens introduced by this extension. */ + +/*------------------------------------------------------------------------* + * IMG extension tokens + *------------------------------------------------------------------------*/ + +/* GL_IMG_program_binary */ +#ifndef GL_IMG_program_binary +#define GL_SGX_PROGRAM_BINARY_IMG 0x9130 +#endif + +/* GL_IMG_read_format */ +#ifndef GL_IMG_read_format +#define GL_BGRA_IMG 0x80E1 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV_IMG 0x8365 +#endif + +/* GL_IMG_shader_binary */ +#ifndef GL_IMG_shader_binary +#define GL_SGX_BINARY_IMG 0x8C0A +#endif + +/* GL_IMG_texture_compression_pvrtc */ +#ifndef GL_IMG_texture_compression_pvrtc +#define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00 +#define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01 +#define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02 +#define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03 +#endif + +/* GL_IMG_multisampled_render_to_texture */ +#ifndef GL_IMG_multisampled_render_to_texture +#define GL_RENDERBUFFER_SAMPLES_IMG 0x9133 +#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_IMG 0x9134 +#define GL_MAX_SAMPLES_IMG 0x9135 +#define GL_TEXTURE_SAMPLES_IMG 0x9136 +#endif + +/*------------------------------------------------------------------------* + * NV extension tokens + *------------------------------------------------------------------------*/ + +/* GL_NV_fence */ +#ifndef GL_NV_fence +#define GL_ALL_COMPLETED_NV 0x84F2 +#define GL_FENCE_STATUS_NV 0x84F3 +#define GL_FENCE_CONDITION_NV 0x84F4 +#endif + +/* GL_NV_coverage_sample */ +#ifndef GL_NV_coverage_sample +#define GL_COVERAGE_COMPONENT_NV 0x8ED0 +#define GL_COVERAGE_COMPONENT4_NV 0x8ED1 +#define GL_COVERAGE_ATTACHMENT_NV 0x8ED2 +#define GL_COVERAGE_BUFFERS_NV 0x8ED3 +#define GL_COVERAGE_SAMPLES_NV 0x8ED4 +#define GL_COVERAGE_ALL_FRAGMENTS_NV 0x8ED5 +#define GL_COVERAGE_EDGE_FRAGMENTS_NV 0x8ED6 +#define GL_COVERAGE_AUTOMATIC_NV 0x8ED7 +#define GL_COVERAGE_BUFFER_BIT_NV 0x8000 +#endif + +/* GL_NV_depth_nonlinear */ +#ifndef GL_NV_depth_nonlinear +#define GL_DEPTH_COMPONENT16_NONLINEAR_NV 0x8E2C +#endif + +/*------------------------------------------------------------------------* + * QCOM extension tokens + *------------------------------------------------------------------------*/ + +/* GL_QCOM_driver_control */ +/* No new tokens introduced by this extension. */ + +/* GL_QCOM_extended_get */ +#ifndef GL_QCOM_extended_get +#define GL_TEXTURE_WIDTH_QCOM 0x8BD2 +#define GL_TEXTURE_HEIGHT_QCOM 0x8BD3 +#define GL_TEXTURE_DEPTH_QCOM 0x8BD4 +#define GL_TEXTURE_INTERNAL_FORMAT_QCOM 0x8BD5 +#define GL_TEXTURE_FORMAT_QCOM 0x8BD6 +#define GL_TEXTURE_TYPE_QCOM 0x8BD7 +#define GL_TEXTURE_IMAGE_VALID_QCOM 0x8BD8 +#define GL_TEXTURE_NUM_LEVELS_QCOM 0x8BD9 +#define GL_TEXTURE_TARGET_QCOM 0x8BDA +#define GL_TEXTURE_OBJECT_VALID_QCOM 0x8BDB +#define GL_STATE_RESTORE 0x8BDC +#endif + +/* GL_QCOM_extended_get2 */ +/* No new tokens introduced by this extension. */ + +/* GL_QCOM_perfmon_global_mode */ +#ifndef GL_QCOM_perfmon_global_mode +#define GL_PERFMON_GLOBAL_MODE_QCOM 0x8FA0 +#endif + +/* GL_QCOM_writeonly_rendering */ +#ifndef GL_QCOM_writeonly_rendering +#define GL_WRITEONLY_RENDERING_QCOM 0x8823 +#endif + +/* GL_QCOM_tiled_rendering */ +#ifndef GL_QCOM_tiled_rendering +#define GL_COLOR_BUFFER_BIT0_QCOM 0x00000001 +#define GL_COLOR_BUFFER_BIT1_QCOM 0x00000002 +#define GL_COLOR_BUFFER_BIT2_QCOM 0x00000004 +#define GL_COLOR_BUFFER_BIT3_QCOM 0x00000008 +#define GL_COLOR_BUFFER_BIT4_QCOM 0x00000010 +#define GL_COLOR_BUFFER_BIT5_QCOM 0x00000020 +#define GL_COLOR_BUFFER_BIT6_QCOM 0x00000040 +#define GL_COLOR_BUFFER_BIT7_QCOM 0x00000080 +#define GL_DEPTH_BUFFER_BIT0_QCOM 0x00000100 +#define GL_DEPTH_BUFFER_BIT1_QCOM 0x00000200 +#define GL_DEPTH_BUFFER_BIT2_QCOM 0x00000400 +#define GL_DEPTH_BUFFER_BIT3_QCOM 0x00000800 +#define GL_DEPTH_BUFFER_BIT4_QCOM 0x00001000 +#define GL_DEPTH_BUFFER_BIT5_QCOM 0x00002000 +#define GL_DEPTH_BUFFER_BIT6_QCOM 0x00004000 +#define GL_DEPTH_BUFFER_BIT7_QCOM 0x00008000 +#define GL_STENCIL_BUFFER_BIT0_QCOM 0x00010000 +#define GL_STENCIL_BUFFER_BIT1_QCOM 0x00020000 +#define GL_STENCIL_BUFFER_BIT2_QCOM 0x00040000 +#define GL_STENCIL_BUFFER_BIT3_QCOM 0x00080000 +#define GL_STENCIL_BUFFER_BIT4_QCOM 0x00100000 +#define GL_STENCIL_BUFFER_BIT5_QCOM 0x00200000 +#define GL_STENCIL_BUFFER_BIT6_QCOM 0x00400000 +#define GL_STENCIL_BUFFER_BIT7_QCOM 0x00800000 +#define GL_MULTISAMPLE_BUFFER_BIT0_QCOM 0x01000000 +#define GL_MULTISAMPLE_BUFFER_BIT1_QCOM 0x02000000 +#define GL_MULTISAMPLE_BUFFER_BIT2_QCOM 0x04000000 +#define GL_MULTISAMPLE_BUFFER_BIT3_QCOM 0x08000000 +#define GL_MULTISAMPLE_BUFFER_BIT4_QCOM 0x10000000 +#define GL_MULTISAMPLE_BUFFER_BIT5_QCOM 0x20000000 +#define GL_MULTISAMPLE_BUFFER_BIT6_QCOM 0x40000000 +#define GL_MULTISAMPLE_BUFFER_BIT7_QCOM 0x80000000 +#endif + +/*------------------------------------------------------------------------* + * VIV extension tokens + *------------------------------------------------------------------------*/ + +/* GL_VIV_shader_binary */ +#ifndef GL_VIV_shader_binary +#define GL_SHADER_BINARY_VIV 0x8FC4 +#endif + +/*------------------------------------------------------------------------* + * End of extension tokens, start of corresponding extension functions + *------------------------------------------------------------------------*/ + +/*------------------------------------------------------------------------* + * OES extension functions + *------------------------------------------------------------------------*/ + +/* GL_OES_compressed_ETC1_RGB8_texture */ +#ifndef GL_OES_compressed_ETC1_RGB8_texture +#define GL_OES_compressed_ETC1_RGB8_texture 1 +#endif + +/* GL_OES_compressed_paletted_texture */ +#ifndef GL_OES_compressed_paletted_texture +#define GL_OES_compressed_paletted_texture 1 +#endif + +/* GL_OES_depth24 */ +#ifndef GL_OES_depth24 +#define GL_OES_depth24 1 +#endif + +/* GL_OES_depth32 */ +#ifndef GL_OES_depth32 +#define GL_OES_depth32 1 +#endif + +/* GL_OES_depth_texture */ +#ifndef GL_OES_depth_texture +#define GL_OES_depth_texture 1 +#endif + +/* GL_OES_EGL_image */ +#ifndef GL_OES_EGL_image +#define GL_OES_EGL_image 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image); +GL_APICALL void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES (GLenum target, GLeglImageOES image); +#endif +typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image); +typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLeglImageOES image); +#endif + +/* GL_OES_EGL_image_external */ +#ifndef GL_OES_EGL_image_external +#define GL_OES_EGL_image_external 1 +/* glEGLImageTargetTexture2DOES defined in GL_OES_EGL_image already. */ +#endif + +/* GL_OES_element_index_uint */ +#ifndef GL_OES_element_index_uint +#define GL_OES_element_index_uint 1 +#endif + +/* GL_OES_fbo_render_mipmap */ +#ifndef GL_OES_fbo_render_mipmap +#define GL_OES_fbo_render_mipmap 1 +#endif + +/* GL_OES_fragment_precision_high */ +#ifndef GL_OES_fragment_precision_high +#define GL_OES_fragment_precision_high 1 +#endif + +/* GL_OES_get_program_binary */ +#ifndef GL_OES_get_program_binary +#define GL_OES_get_program_binary 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glGetProgramBinaryOES (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); +GL_APICALL void GL_APIENTRY glProgramBinaryOES (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length); +#endif +typedef void (GL_APIENTRYP PFNGLGETPROGRAMBINARYOESPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary); +typedef void (GL_APIENTRYP PFNGLPROGRAMBINARYOESPROC) (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length); +#endif + +/* GL_OES_mapbuffer */ +#ifndef GL_OES_mapbuffer +#define GL_OES_mapbuffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void* GL_APIENTRY glMapBufferOES (GLenum target, GLenum access); +GL_APICALL GLboolean GL_APIENTRY glUnmapBufferOES (GLenum target); +GL_APICALL void GL_APIENTRY glGetBufferPointervOES (GLenum target, GLenum pname, GLvoid** params); +#endif +typedef void* (GL_APIENTRYP PFNGLMAPBUFFEROESPROC) (GLenum target, GLenum access); +typedef GLboolean (GL_APIENTRYP PFNGLUNMAPBUFFEROESPROC) (GLenum target); +typedef void (GL_APIENTRYP PFNGLGETBUFFERPOINTERVOESPROC) (GLenum target, GLenum pname, GLvoid** params); +#endif + +/* GL_OES_packed_depth_stencil */ +#ifndef GL_OES_packed_depth_stencil +#define GL_OES_packed_depth_stencil 1 +#endif + +/* GL_OES_rgb8_rgba8 */ +#ifndef GL_OES_rgb8_rgba8 +#define GL_OES_rgb8_rgba8 1 +#endif + +/* GL_OES_standard_derivatives */ +#ifndef GL_OES_standard_derivatives +#define GL_OES_standard_derivatives 1 +#endif + +/* GL_OES_stencil1 */ +#ifndef GL_OES_stencil1 +#define GL_OES_stencil1 1 +#endif + +/* GL_OES_stencil4 */ +#ifndef GL_OES_stencil4 +#define GL_OES_stencil4 1 +#endif + +/* GL_OES_texture_3D */ +#ifndef GL_OES_texture_3D +#define GL_OES_texture_3D 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glTexImage3DOES (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels); +GL_APICALL void GL_APIENTRY glTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels); +GL_APICALL void GL_APIENTRY glCopyTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +GL_APICALL void GL_APIENTRY glCompressedTexImage3DOES (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data); +GL_APICALL void GL_APIENTRY glCompressedTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data); +GL_APICALL void GL_APIENTRY glFramebufferTexture3DOES (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +#endif +typedef void (GL_APIENTRYP PFNGLTEXIMAGE3DOESPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels); +typedef void (GL_APIENTRYP PFNGLTEXSUBIMAGE3DOESPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels); +typedef void (GL_APIENTRYP PFNGLCOPYTEXSUBIMAGE3DOESPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DOESPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data); +typedef void (GL_APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DOESPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data); +typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DOES) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +#endif + +/* GL_OES_texture_float */ +#ifndef GL_OES_texture_float +#define GL_OES_texture_float 1 +#endif + +/* GL_OES_texture_float_linear */ +#ifndef GL_OES_texture_float_linear +#define GL_OES_texture_float_linear 1 +#endif + +/* GL_OES_texture_half_float */ +#ifndef GL_OES_texture_half_float +#define GL_OES_texture_half_float 1 +#endif + +/* GL_OES_texture_half_float_linear */ +#ifndef GL_OES_texture_half_float_linear +#define GL_OES_texture_half_float_linear 1 +#endif + +/* GL_OES_texture_npot */ +#ifndef GL_OES_texture_npot +#define GL_OES_texture_npot 1 +#endif + +/* GL_OES_vertex_array_object */ +#ifndef GL_OES_vertex_array_object +#define GL_OES_vertex_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glBindVertexArrayOES (GLuint array); +GL_APICALL void GL_APIENTRY glDeleteVertexArraysOES (GLsizei n, const GLuint *arrays); +GL_APICALL void GL_APIENTRY glGenVertexArraysOES (GLsizei n, GLuint *arrays); +GL_APICALL GLboolean GL_APIENTRY glIsVertexArrayOES (GLuint array); +#endif +typedef void (GL_APIENTRYP PFNGLBINDVERTEXARRAYOESPROC) (GLuint array); +typedef void (GL_APIENTRYP PFNGLDELETEVERTEXARRAYSOESPROC) (GLsizei n, const GLuint *arrays); +typedef void (GL_APIENTRYP PFNGLGENVERTEXARRAYSOESPROC) (GLsizei n, GLuint *arrays); +typedef GLboolean (GL_APIENTRYP PFNGLISVERTEXARRAYOESPROC) (GLuint array); +#endif + +/* GL_OES_vertex_half_float */ +#ifndef GL_OES_vertex_half_float +#define GL_OES_vertex_half_float 1 +#endif + +/* GL_OES_vertex_type_10_10_10_2 */ +#ifndef GL_OES_vertex_type_10_10_10_2 +#define GL_OES_vertex_type_10_10_10_2 1 +#endif + +/*------------------------------------------------------------------------* + * AMD extension functions + *------------------------------------------------------------------------*/ + +/* GL_AMD_compressed_3DC_texture */ +#ifndef GL_AMD_compressed_3DC_texture +#define GL_AMD_compressed_3DC_texture 1 +#endif + +/* GL_AMD_compressed_ATC_texture */ +#ifndef GL_AMD_compressed_ATC_texture +#define GL_AMD_compressed_ATC_texture 1 +#endif + +/* AMD_performance_monitor */ +#ifndef GL_AMD_performance_monitor +#define GL_AMD_performance_monitor 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glGetPerfMonitorGroupsAMD (GLint *numGroups, GLsizei groupsSize, GLuint *groups); +GL_APICALL void GL_APIENTRY glGetPerfMonitorCountersAMD (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters); +GL_APICALL void GL_APIENTRY glGetPerfMonitorGroupStringAMD (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString); +GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterStringAMD (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString); +GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterInfoAMD (GLuint group, GLuint counter, GLenum pname, GLvoid *data); +GL_APICALL void GL_APIENTRY glGenPerfMonitorsAMD (GLsizei n, GLuint *monitors); +GL_APICALL void GL_APIENTRY glDeletePerfMonitorsAMD (GLsizei n, GLuint *monitors); +GL_APICALL void GL_APIENTRY glSelectPerfMonitorCountersAMD (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *countersList); +GL_APICALL void GL_APIENTRY glBeginPerfMonitorAMD (GLuint monitor); +GL_APICALL void GL_APIENTRY glEndPerfMonitorAMD (GLuint monitor); +GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterDataAMD (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten); +#endif +typedef void (GL_APIENTRYP PFNGLGETPERFMONITORGROUPSAMDPROC) (GLint *numGroups, GLsizei groupsSize, GLuint *groups); +typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERSAMDPROC) (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters); +typedef void (GL_APIENTRYP PFNGLGETPERFMONITORGROUPSTRINGAMDPROC) (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString); +typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERSTRINGAMDPROC) (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString); +typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERINFOAMDPROC) (GLuint group, GLuint counter, GLenum pname, GLvoid *data); +typedef void (GL_APIENTRYP PFNGLGENPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors); +typedef void (GL_APIENTRYP PFNGLDELETEPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors); +typedef void (GL_APIENTRYP PFNGLSELECTPERFMONITORCOUNTERSAMDPROC) (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *countersList); +typedef void (GL_APIENTRYP PFNGLBEGINPERFMONITORAMDPROC) (GLuint monitor); +typedef void (GL_APIENTRYP PFNGLENDPERFMONITORAMDPROC) (GLuint monitor); +typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERDATAAMDPROC) (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten); +#endif + +/* GL_AMD_program_binary_Z400 */ +#ifndef GL_AMD_program_binary_Z400 +#define GL_AMD_program_binary_Z400 1 +#endif + +/*------------------------------------------------------------------------* + * ANGLE extension functions + *------------------------------------------------------------------------*/ + +/* GL_ANGLE_framebuffer_blit */ +#ifndef GL_ANGLE_framebuffer_blit +#define GL_ANGLE_framebuffer_blit 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glBlitFramebufferANGLE (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +#endif +typedef void (GL_APIENTRYP PFNGLBLITFRAMEBUFFERANGLEPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); +#endif + +/* GL_ANGLE_framebuffer_multisample */ +#ifndef GL_ANGLE_framebuffer_multisample +#define GL_ANGLE_framebuffer_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleANGLE (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +#endif +typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEANGLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +#endif + +/*------------------------------------------------------------------------* + * APPLE extension functions + *------------------------------------------------------------------------*/ + +/* GL_APPLE_rgb_422 */ +#ifndef GL_APPLE_rgb_422 +#define GL_APPLE_rgb_422 1 +#endif + +/* GL_APPLE_framebuffer_multisample */ +#ifndef GL_APPLE_framebuffer_multisample +#define GL_APPLE_framebuffer_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleAPPLE (GLenum, GLsizei, GLenum, GLsizei, GLsizei); +GL_APICALL void GL_APIENTRY glResolveMultisampleFramebufferAPPLE (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEAPPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLRESOLVEMULTISAMPLEFRAMEBUFFERAPPLEPROC) (void); +#endif + +/* GL_APPLE_texture_format_BGRA8888 */ +#ifndef GL_APPLE_texture_format_BGRA8888 +#define GL_APPLE_texture_format_BGRA8888 1 +#endif + +/* GL_APPLE_texture_max_level */ +#ifndef GL_APPLE_texture_max_level +#define GL_APPLE_texture_max_level 1 +#endif + +/*------------------------------------------------------------------------* + * ARM extension functions + *------------------------------------------------------------------------*/ + +/* GL_ARM_mali_shader_binary */ +#ifndef GL_ARM_mali_shader_binary +#define GL_ARM_mali_shader_binary 1 +#endif + +/* GL_ARM_rgba8 */ +#ifndef GL_ARM_rgba8 +#define GL_ARM_rgba8 1 +#endif + +/*------------------------------------------------------------------------* + * EXT extension functions + *------------------------------------------------------------------------*/ + +/* GL_EXT_blend_minmax */ +#ifndef GL_EXT_blend_minmax +#define GL_EXT_blend_minmax 1 +#endif + +/* GL_EXT_discard_framebuffer */ +#ifndef GL_EXT_discard_framebuffer +#define GL_EXT_discard_framebuffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glDiscardFramebufferEXT (GLenum target, GLsizei numAttachments, const GLenum *attachments); +#endif +typedef void (GL_APIENTRYP PFNGLDISCARDFRAMEBUFFEREXTPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments); +#endif + +#ifndef GL_EXT_multi_draw_arrays +#define GL_EXT_multi_draw_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glMultiDrawArraysEXT (GLenum, GLint *, GLsizei *, GLsizei); +GL_APICALL void GL_APIENTRY glMultiDrawElementsEXT (GLenum, const GLsizei *, GLenum, const GLvoid* *, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (GL_APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, GLint *first, GLsizei *count, GLsizei primcount); +typedef void (GL_APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); +#endif + +/* GL_EXT_read_format_bgra */ +#ifndef GL_EXT_read_format_bgra +#define GL_EXT_read_format_bgra 1 +#endif + +/* GL_EXT_texture_filter_anisotropic */ +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_EXT_texture_filter_anisotropic 1 +#endif + +/* GL_EXT_texture_format_BGRA8888 */ +#ifndef GL_EXT_texture_format_BGRA8888 +#define GL_EXT_texture_format_BGRA8888 1 +#endif + +/* GL_EXT_texture_type_2_10_10_10_REV */ +#ifndef GL_EXT_texture_type_2_10_10_10_REV +#define GL_EXT_texture_type_2_10_10_10_REV 1 +#endif + +/* GL_EXT_texture_compression_dxt1 */ +#ifndef GL_EXT_texture_compression_dxt1 +#define GL_EXT_texture_compression_dxt1 1 +#endif + +/* GL_EXT_shader_texture_lod */ +#ifndef GL_EXT_shader_texture_lod +#define GL_EXT_shader_texture_lod 1 +#endif + +/*------------------------------------------------------------------------* + * IMG extension functions + *------------------------------------------------------------------------*/ + +/* GL_IMG_program_binary */ +#ifndef GL_IMG_program_binary +#define GL_IMG_program_binary 1 +#endif + +/* GL_IMG_read_format */ +#ifndef GL_IMG_read_format +#define GL_IMG_read_format 1 +#endif + +/* GL_IMG_shader_binary */ +#ifndef GL_IMG_shader_binary +#define GL_IMG_shader_binary 1 +#endif + +/* GL_IMG_texture_compression_pvrtc */ +#ifndef GL_IMG_texture_compression_pvrtc +#define GL_IMG_texture_compression_pvrtc 1 +#endif + +/* GL_IMG_multisampled_render_to_texture */ +#ifndef GL_IMG_multisampled_render_to_texture +#define GL_IMG_multisampled_render_to_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleIMG (GLenum, GLsizei, GLenum, GLsizei, GLsizei); +GL_APICALL void GL_APIENTRY glFramebufferTexture2DMultisampleIMG (GLenum, GLenum, GLenum, GLuint, GLint, GLsizei); +#endif +typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMG) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEIMG) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples); +#endif + +/*------------------------------------------------------------------------* + * NV extension functions + *------------------------------------------------------------------------*/ + +/* GL_NV_fence */ +#ifndef GL_NV_fence +#define GL_NV_fence 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glDeleteFencesNV (GLsizei, const GLuint *); +GL_APICALL void GL_APIENTRY glGenFencesNV (GLsizei, GLuint *); +GL_APICALL GLboolean GL_APIENTRY glIsFenceNV (GLuint); +GL_APICALL GLboolean GL_APIENTRY glTestFenceNV (GLuint); +GL_APICALL void GL_APIENTRY glGetFenceivNV (GLuint, GLenum, GLint *); +GL_APICALL void GL_APIENTRY glFinishFenceNV (GLuint); +GL_APICALL void GL_APIENTRY glSetFenceNV (GLuint, GLenum); +#endif +typedef void (GL_APIENTRYP PFNGLDELETEFENCESNVPROC) (GLsizei n, const GLuint *fences); +typedef void (GL_APIENTRYP PFNGLGENFENCESNVPROC) (GLsizei n, GLuint *fences); +typedef GLboolean (GL_APIENTRYP PFNGLISFENCENVPROC) (GLuint fence); +typedef GLboolean (GL_APIENTRYP PFNGLTESTFENCENVPROC) (GLuint fence); +typedef void (GL_APIENTRYP PFNGLGETFENCEIVNVPROC) (GLuint fence, GLenum pname, GLint *params); +typedef void (GL_APIENTRYP PFNGLFINISHFENCENVPROC) (GLuint fence); +typedef void (GL_APIENTRYP PFNGLSETFENCENVPROC) (GLuint fence, GLenum condition); +#endif + +/* GL_NV_coverage_sample */ +#ifndef GL_NV_coverage_sample +#define GL_NV_coverage_sample 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glCoverageMaskNV (GLboolean mask); +GL_APICALL void GL_APIENTRY glCoverageOperationNV (GLenum operation); +#endif +typedef void (GL_APIENTRYP PFNGLCOVERAGEMASKNVPROC) (GLboolean mask); +typedef void (GL_APIENTRYP PFNGLCOVERAGEOPERATIONNVPROC) (GLenum operation); +#endif + +/* GL_NV_depth_nonlinear */ +#ifndef GL_NV_depth_nonlinear +#define GL_NV_depth_nonlinear 1 +#endif + +/*------------------------------------------------------------------------* + * QCOM extension functions + *------------------------------------------------------------------------*/ + +/* GL_QCOM_driver_control */ +#ifndef GL_QCOM_driver_control +#define GL_QCOM_driver_control 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glGetDriverControlsQCOM (GLint *num, GLsizei size, GLuint *driverControls); +GL_APICALL void GL_APIENTRY glGetDriverControlStringQCOM (GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString); +GL_APICALL void GL_APIENTRY glEnableDriverControlQCOM (GLuint driverControl); +GL_APICALL void GL_APIENTRY glDisableDriverControlQCOM (GLuint driverControl); +#endif +typedef void (GL_APIENTRYP PFNGLGETDRIVERCONTROLSQCOMPROC) (GLint *num, GLsizei size, GLuint *driverControls); +typedef void (GL_APIENTRYP PFNGLGETDRIVERCONTROLSTRINGQCOMPROC) (GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString); +typedef void (GL_APIENTRYP PFNGLENABLEDRIVERCONTROLQCOMPROC) (GLuint driverControl); +typedef void (GL_APIENTRYP PFNGLDISABLEDRIVERCONTROLQCOMPROC) (GLuint driverControl); +#endif + +/* GL_QCOM_extended_get */ +#ifndef GL_QCOM_extended_get +#define GL_QCOM_extended_get 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glExtGetTexturesQCOM (GLuint *textures, GLint maxTextures, GLint *numTextures); +GL_APICALL void GL_APIENTRY glExtGetBuffersQCOM (GLuint *buffers, GLint maxBuffers, GLint *numBuffers); +GL_APICALL void GL_APIENTRY glExtGetRenderbuffersQCOM (GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers); +GL_APICALL void GL_APIENTRY glExtGetFramebuffersQCOM (GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers); +GL_APICALL void GL_APIENTRY glExtGetTexLevelParameterivQCOM (GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params); +GL_APICALL void GL_APIENTRY glExtTexObjectStateOverrideiQCOM (GLenum target, GLenum pname, GLint param); +GL_APICALL void GL_APIENTRY glExtGetTexSubImageQCOM (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels); +GL_APICALL void GL_APIENTRY glExtGetBufferPointervQCOM (GLenum target, GLvoid **params); +#endif +typedef void (GL_APIENTRYP PFNGLEXTGETTEXTURESQCOMPROC) (GLuint *textures, GLint maxTextures, GLint *numTextures); +typedef void (GL_APIENTRYP PFNGLEXTGETBUFFERSQCOMPROC) (GLuint *buffers, GLint maxBuffers, GLint *numBuffers); +typedef void (GL_APIENTRYP PFNGLEXTGETRENDERBUFFERSQCOMPROC) (GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers); +typedef void (GL_APIENTRYP PFNGLEXTGETFRAMEBUFFERSQCOMPROC) (GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers); +typedef void (GL_APIENTRYP PFNGLEXTGETTEXLEVELPARAMETERIVQCOMPROC) (GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params); +typedef void (GL_APIENTRYP PFNGLEXTTEXOBJECTSTATEOVERRIDEIQCOMPROC) (GLenum target, GLenum pname, GLint param); +typedef void (GL_APIENTRYP PFNGLEXTGETTEXSUBIMAGEQCOMPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels); +typedef void (GL_APIENTRYP PFNGLEXTGETBUFFERPOINTERVQCOMPROC) (GLenum target, GLvoid **params); +#endif + +/* GL_QCOM_extended_get2 */ +#ifndef GL_QCOM_extended_get2 +#define GL_QCOM_extended_get2 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glExtGetShadersQCOM (GLuint *shaders, GLint maxShaders, GLint *numShaders); +GL_APICALL void GL_APIENTRY glExtGetProgramsQCOM (GLuint *programs, GLint maxPrograms, GLint *numPrograms); +GL_APICALL GLboolean GL_APIENTRY glExtIsProgramBinaryQCOM (GLuint program); +GL_APICALL void GL_APIENTRY glExtGetProgramBinarySourceQCOM (GLuint program, GLenum shadertype, GLchar *source, GLint *length); +#endif +typedef void (GL_APIENTRYP PFNGLEXTGETSHADERSQCOMPROC) (GLuint *shaders, GLint maxShaders, GLint *numShaders); +typedef void (GL_APIENTRYP PFNGLEXTGETPROGRAMSQCOMPROC) (GLuint *programs, GLint maxPrograms, GLint *numPrograms); +typedef GLboolean (GL_APIENTRYP PFNGLEXTISPROGRAMBINARYQCOMPROC) (GLuint program); +typedef void (GL_APIENTRYP PFNGLEXTGETPROGRAMBINARYSOURCEQCOMPROC) (GLuint program, GLenum shadertype, GLchar *source, GLint *length); +#endif + +/* GL_QCOM_perfmon_global_mode */ +#ifndef GL_QCOM_perfmon_global_mode +#define GL_QCOM_perfmon_global_mode 1 +#endif + +/* GL_QCOM_writeonly_rendering */ +#ifndef GL_QCOM_writeonly_rendering +#define GL_QCOM_writeonly_rendering 1 +#endif + +/* GL_QCOM_tiled_rendering */ +#ifndef GL_QCOM_tiled_rendering +#define GL_QCOM_tiled_rendering 1 +#ifdef GL_GLEXT_PROTOTYPES +GL_APICALL void GL_APIENTRY glStartTilingQCOM (GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask); +GL_APICALL void GL_APIENTRY glEndTilingQCOM (GLbitfield preserveMask); +#endif +typedef void (GL_APIENTRYP PFNGLSTARTTILINGQCOMPROC) (GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask); +typedef void (GL_APIENTRYP PFNGLENDTILINGQCOMPROC) (GLbitfield preserveMask); +#endif + +/*------------------------------------------------------------------------* + * VIV extension tokens + *------------------------------------------------------------------------*/ + +/* GL_VIV_shader_binary */ +#ifndef GL_VIV_shader_binary +#define GL_VIV_shader_binary 1 +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __gl2ext_h_ */ diff --git a/emulator/opengl/host/libs/Translator/include/GLES2/gl2platform.h b/emulator/opengl/host/libs/Translator/include/GLES2/gl2platform.h new file mode 100644 index 0000000..c9fa3c4 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLES2/gl2platform.h @@ -0,0 +1,30 @@ +#ifndef __gl2platform_h_ +#define __gl2platform_h_ + +/* $Revision: 10602 $ on $Date:: 2010-03-04 22:35:34 -0800 #$ */ + +/* + * This document is licensed under the SGI Free Software B License Version + * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . + */ + +/* Platform-specific types and definitions for OpenGL ES 2.X gl2.h + * + * Adopters may modify khrplatform.h and this file to suit their platform. + * You are encouraged to submit all modifications to the Khronos group so that + * they can be included in future versions of this file. Please submit changes + * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) + * by filing a bug against product "OpenGL-ES" component "Registry". + */ + +#include <KHR/khrplatform.h> + +#ifndef GL_APICALL +#define GL_APICALL KHRONOS_APICALL +#endif + +#ifndef GL_APIENTRY +#define GL_APIENTRY KHRONOS_APIENTRY +#endif + +#endif /* __gl2platform_h_ */ diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/FramebufferData.h b/emulator/opengl/host/libs/Translator/include/GLcommon/FramebufferData.h new file mode 100644 index 0000000..46cb651 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/FramebufferData.h @@ -0,0 +1,72 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _FRAMEBUFFER_DATA_H +#define _FRAMEBUFFER_DATA_H + +#include "objectNameManager.h" +#include <GLES/gl.h> +#include <GLES/glext.h> + +class RenderbufferData : public ObjectData +{ +public: + RenderbufferData(); + ~RenderbufferData(); + + unsigned int sourceEGLImage; + void (*eglImageDetach)(unsigned int imageId); + GLuint attachedFB; + GLenum attachedPoint; + GLuint eglImageGlobalTexName; + +}; + +const int MAX_ATTACH_POINTS = 3; + +class FramebufferData : public ObjectData +{ +public: + explicit FramebufferData(GLuint name); + ~FramebufferData(); + + void setAttachment(GLenum attachment, + GLenum target, + GLuint name, + ObjectDataPtr obj, + bool takeOwnership = false); + + GLuint getAttachment(GLenum attachment, + GLenum *outTarget, + ObjectDataPtr *outObj); + + void validate(class GLEScontext* ctx); + +private: + inline int attachmentPointIndex(GLenum attachment); + void detachObject(int idx); + +private: + GLuint m_fbName; + struct attachPoint { + GLenum target; // OGL if owned, GLES otherwise + GLuint name; // OGL if owned, GLES otherwise + ObjectDataPtr obj; + bool owned; + } m_attachPoints[MAX_ATTACH_POINTS+1]; + bool m_dirty; +}; + +#endif diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/GLDispatch.h b/emulator/opengl/host/libs/Translator/include/GLcommon/GLDispatch.h new file mode 100644 index 0000000..de7d563 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/GLDispatch.h @@ -0,0 +1,267 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef GLDISPATCHH +#define GLDISPATCHH + +#include <GLES/gl.h> +#include <GLES2/gl2.h> +#include <utils/threads.h> +#include "gldefs.h" +#include "GLutils.h" + +#define GLAPIENTRY GL_APIENTRY +typedef void(*FUNCPTR)(); + +class GLDispatch +{ +public: + + GLDispatch(); + void dispatchFuncs(GLESVersion version); + + /* OpenGL functions which are needed for implementing BOTH GLES 1.1 & GLES 2.0*/ + static void (GLAPIENTRY *glActiveTexture) ( GLenum texture ); + static void (GLAPIENTRY *glBindBuffer) (GLenum target, GLuint buffer); + static void (GLAPIENTRY *glBindTexture) (GLenum target, GLuint texture); + static void (GLAPIENTRY *glBlendFunc) (GLenum sfactor, GLenum dfactor); + static void (GLAPIENTRY *glBlendEquation)( GLenum mode ); + static void (GLAPIENTRY *glBlendEquationSeparate)(GLenum modeRGB, GLenum modeAlpha); + static void (GLAPIENTRY *glBlendFuncSeparate)(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); + static void (GLAPIENTRY *glBufferData) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); + static void (GLAPIENTRY *glBufferSubData) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); + static void (GLAPIENTRY *glClear) (GLbitfield mask); + static void (GLAPIENTRY *glClearColor) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); + static void (GLAPIENTRY *glClearStencil) (GLint s); + static void (GLAPIENTRY *glColorMask) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); + static void (GLAPIENTRY *glCompressedTexImage2D) ( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data ); + static void (GLAPIENTRY *glCompressedTexSubImage2D) ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data ); + static void (GLAPIENTRY *glCopyTexImage2D) (GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); + static void (GLAPIENTRY *glCopyTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); + static void (GLAPIENTRY *glCullFace) (GLenum mode); + static void (GLAPIENTRY *glDeleteBuffers) (GLsizei n, const GLuint *buffers); + static void (GLAPIENTRY *glDeleteTextures) (GLsizei n, const GLuint *textures); + static void (GLAPIENTRY *glDepthFunc) (GLenum func); + static void (GLAPIENTRY *glDepthMask) (GLboolean flag); + static void (GLAPIENTRY *glDepthRange) (GLclampd zNear, GLclampd zFar); + static void (GLAPIENTRY *glDisable) (GLenum cap); + static void (GLAPIENTRY *glDrawArrays) (GLenum mode, GLint first, GLsizei count); + static void (GLAPIENTRY *glDrawElements) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); + static void (GLAPIENTRY *glEnable) (GLenum cap); + static void (GLAPIENTRY *glFinish) (void); + static void (GLAPIENTRY *glFlush) (void); + static void (GLAPIENTRY *glFrontFace) (GLenum mode); + static void (GLAPIENTRY *glGenBuffers) (GLsizei n, GLuint *buffers); + static void (GLAPIENTRY *glGenTextures) (GLsizei n, GLuint *textures); + static void (GLAPIENTRY *glGetBooleanv) (GLenum pname, GLboolean *params); + static void (GLAPIENTRY *glGetBufferParameteriv) (GLenum, GLenum, GLint *); + static GLenum (GLAPIENTRY *glGetError) (void); + static void (GLAPIENTRY *glGetFloatv) (GLenum pname, GLfloat *params); + static void (GLAPIENTRY *glGetIntegerv) (GLenum pname, GLint *params); + static const GLubyte * (GLAPIENTRY *glGetString) (GLenum name); + static void (GLAPIENTRY *glGetTexParameterfv) (GLenum target, GLenum pname, GLfloat *params); + static void (GLAPIENTRY *glGetTexParameteriv) (GLenum target, GLenum pname, GLint *params); + static void (GLAPIENTRY *glGetTexLevelParameteriv) (GLenum target, GLint level, GLenum pname, GLint *params); + static void (GLAPIENTRY *glHint) (GLenum target, GLenum mode); + static GLboolean (GLAPIENTRY *glIsBuffer) (GLuint); + static GLboolean (GLAPIENTRY *glIsEnabled) (GLenum cap); + static GLboolean (GLAPIENTRY *glIsTexture) (GLuint texture); + static void (GLAPIENTRY *glLineWidth) (GLfloat width); + static void (GLAPIENTRY *glPolygonOffset) (GLfloat factor, GLfloat units); + static void (GLAPIENTRY *glPixelStorei) (GLenum pname, GLint param); + static void (GLAPIENTRY *glReadPixels) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); + static void (GLAPIENTRY *glSampleCoverage) ( GLclampf value, GLboolean invert ); + static void (GLAPIENTRY *glScissor) (GLint x, GLint y, GLsizei width, GLsizei height); + static void (GLAPIENTRY *glStencilFunc) (GLenum func, GLint ref, GLuint mask); + static void (GLAPIENTRY *glStencilMask) (GLuint mask); + static void (GLAPIENTRY *glStencilOp) (GLenum fail, GLenum zfail, GLenum zpass); + static void (GLAPIENTRY *glTexImage2D) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); + static void (GLAPIENTRY *glTexParameteri) (GLenum target, GLenum pname, GLint param); + static void (GLAPIENTRY *glTexParameteriv) (GLenum target, GLenum pname, const GLint *params); + static void (GLAPIENTRY *glTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); + static void (GLAPIENTRY *glViewport) (GLint x, GLint y, GLsizei width, GLsizei height); + static void (GLAPIENTRY *glPushAttrib) ( GLbitfield mask ); + static void (GLAPIENTRY *glPopAttrib) ( void ); + static void (GLAPIENTRY *glPushClientAttrib) ( GLbitfield mask ); + static void (GLAPIENTRY *glPopClientAttrib) ( void ); + static GLboolean (GLAPIENTRY *glIsRenderbufferEXT) (GLuint renderbuffer); + static void (GLAPIENTRY *glBindRenderbufferEXT) (GLenum target, GLuint renderbuffer); + static void (GLAPIENTRY *glDeleteRenderbuffersEXT) (GLsizei n, const GLuint *renderbuffers); + static void (GLAPIENTRY *glGenRenderbuffersEXT) (GLsizei n, GLuint *renderbuffers); + static void (GLAPIENTRY *glRenderbufferStorageEXT) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); + static void (GLAPIENTRY *glGetRenderbufferParameterivEXT) (GLenum target, GLenum pname, GLint *params); + static GLboolean (GLAPIENTRY *glIsFramebufferEXT) (GLuint framebuffer); + static void (GLAPIENTRY *glBindFramebufferEXT) (GLenum target, GLuint framebuffer); + static void (GLAPIENTRY *glDeleteFramebuffersEXT) (GLsizei n, const GLuint *framebuffers); + static void (GLAPIENTRY *glGenFramebuffersEXT) (GLsizei n, GLuint *framebuffers); + static GLenum (GLAPIENTRY *glCheckFramebufferStatusEXT) (GLenum target); + static void (GLAPIENTRY *glFramebufferTexture1DEXT) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); + static void (GLAPIENTRY *glFramebufferTexture2DEXT) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); + static void (GLAPIENTRY *glFramebufferTexture3DEXT) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); + static void (GLAPIENTRY *glFramebufferRenderbufferEXT) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); + static void (GLAPIENTRY *glGetFramebufferAttachmentParameterivEXT) (GLenum target, GLenum attachment, GLenum pname, GLint *params); + static void (GLAPIENTRY *glGenerateMipmapEXT) (GLenum target); + + /* OpenGL functions which are needed ONLY for implementing GLES 1.1*/ + static void (GLAPIENTRY *glAlphaFunc) (GLenum func, GLclampf ref); + static void (GLAPIENTRY *glBegin)( GLenum mode ); + static void (GLAPIENTRY *glClearDepth) (GLclampd depth); + static void (GLAPIENTRY *glClientActiveTexture) ( GLenum texture ); + static void (GLAPIENTRY *glClipPlane) (GLenum plane, const GLdouble *equation); + static void (GLAPIENTRY *glColor4d) (GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha); + static void (GLAPIENTRY *glColor4f) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); + static void (GLAPIENTRY *glColor4fv) ( const GLfloat *v ); + static void (GLAPIENTRY *glColor4ub) (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); + static void (GLAPIENTRY *glColor4ubv) ( const GLubyte *v ); + static void (GLAPIENTRY *glColorPointer) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); + static void (GLAPIENTRY *glDisableClientState) (GLenum array); + static void (GLAPIENTRY *glEnableClientState) (GLenum array); + static void (GLAPIENTRY *glEnd) (void); + static void (GLAPIENTRY *glFogf) (GLenum pname, GLfloat param); + static void (GLAPIENTRY *glFogfv) (GLenum pname, const GLfloat *params); + static void (GLAPIENTRY *glFrustum) (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); + static void (GLAPIENTRY *glGetClipPlane) (GLenum plane, GLdouble *equation); + static void (GLAPIENTRY *glGetDoublev) ( GLenum pname, GLdouble *params ); + static void (GLAPIENTRY *glGetLightfv) (GLenum light, GLenum pname, GLfloat *params); + static void (GLAPIENTRY *glGetMaterialfv) (GLenum face, GLenum pname, GLfloat *params); + static void (GLAPIENTRY *glGetPointerv) (GLenum pname, GLvoid* *params); + static void (GLAPIENTRY *glGetTexEnvfv) (GLenum target, GLenum pname, GLfloat *params); + static void (GLAPIENTRY *glGetTexEnviv) (GLenum target, GLenum pname, GLint *params); + static void (GLAPIENTRY *glLightf) (GLenum light, GLenum pname, GLfloat param); + static void (GLAPIENTRY *glLightfv) (GLenum light, GLenum pname, const GLfloat *params); + static void (GLAPIENTRY *glLightModelf) (GLenum pname, GLfloat param); + static void (GLAPIENTRY *glLightModelfv) (GLenum pname, const GLfloat *params); + static void (GLAPIENTRY *glLoadIdentity) (void); + static void (GLAPIENTRY *glLoadMatrixf) (const GLfloat *m); + static void (GLAPIENTRY *glLogicOp) (GLenum opcode); + static void (GLAPIENTRY *glMaterialf) (GLenum face, GLenum pname, GLfloat param); + static void (GLAPIENTRY *glMaterialfv) (GLenum face, GLenum pname, const GLfloat *params); + static void (GLAPIENTRY *glMultiTexCoord2fv) ( GLenum target, const GLfloat *v ); + static void (GLAPIENTRY *glMultiTexCoord2sv) ( GLenum target, const GLshort *v ); + static void (GLAPIENTRY *glMultiTexCoord3fv) ( GLenum target, const GLfloat *v ); + static void (GLAPIENTRY *glMultiTexCoord3sv) ( GLenum target, const GLshort *v ); + static void (GLAPIENTRY *glMultiTexCoord4f) ( GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q ); + static void (GLAPIENTRY *glMultiTexCoord4fv) ( GLenum target, const GLfloat *v ); + static void (GLAPIENTRY *glMultiTexCoord4sv) ( GLenum target, const GLshort *v ); + static void (GLAPIENTRY *glMultMatrixf) (const GLfloat *m); + static void (GLAPIENTRY *glNormal3f) (GLfloat nx, GLfloat ny, GLfloat nz); + static void (GLAPIENTRY *glNormal3fv) ( const GLfloat *v ); + static void (GLAPIENTRY *glNormal3sv) ( const GLshort *v ); + static void (GLAPIENTRY *glOrtho) (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); + static void (GLAPIENTRY *glPointParameterf) (GLenum, GLfloat); + static void (GLAPIENTRY *glPointParameterfv) (GLenum, const GLfloat *); + static void (GLAPIENTRY *glPointSize) (GLfloat size); + static void (GLAPIENTRY *glRotatef) (GLfloat angle, GLfloat x, GLfloat y, GLfloat z); + static void (GLAPIENTRY *glScalef) (GLfloat x, GLfloat y, GLfloat z); + static void (GLAPIENTRY *glTexEnvf) (GLenum target, GLenum pname, GLfloat param); + static void (GLAPIENTRY *glTexEnvfv) (GLenum target, GLenum pname, const GLfloat *params); + static void (GLAPIENTRY *glTexParameterf) (GLenum target, GLenum pname, GLfloat param); + static void (GLAPIENTRY *glTexParameterfv) (GLenum target, GLenum pname, const GLfloat *params); + static void (GLAPIENTRY *glMatrixMode) (GLenum mode); + static void (GLAPIENTRY *glNormalPointer) (GLenum type, GLsizei stride, const GLvoid *pointer); + static void (GLAPIENTRY *glPopMatrix) (void); + static void (GLAPIENTRY *glPushMatrix) (void); + static void (GLAPIENTRY *glShadeModel) (GLenum mode); + static void (GLAPIENTRY *glTexCoordPointer) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); + static void (GLAPIENTRY *glTexEnvi) (GLenum target, GLenum pname, GLint param); + static void (GLAPIENTRY *glTexEnviv) (GLenum target, GLenum pname, const GLint *params); + static void (GLAPIENTRY *glTranslatef) (GLfloat x, GLfloat y, GLfloat z); + static void (GLAPIENTRY *glVertexPointer) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); + + /* OpenGL functions which are needed ONLY for implementing GLES 1.1 EXTENSIONS*/ + static void (GLAPIENTRY *glCurrentPaletteMatrixARB) (GLint index); + static void (GLAPIENTRY *glMatrixIndexuivARB) (GLint size, GLuint * indices); + static void (GLAPIENTRY *glMatrixIndexPointerARB) (GLint size, GLenum type, GLsizei stride, const GLvoid* pointer); + static void (GLAPIENTRY *glWeightPointerARB) (GLint size, GLenum type, GLsizei stride, const GLvoid* pointer); + static void (GLAPIENTRY *glTexGenf) (GLenum coord, GLenum pname, GLfloat param ); + static void (GLAPIENTRY *glTexGeni) (GLenum coord, GLenum pname, GLint param ); + static void (GLAPIENTRY *glTexGenfv) (GLenum coord, GLenum pname, const GLfloat *params ); + static void (GLAPIENTRY *glTexGeniv) (GLenum coord, GLenum pname, const GLint *params ); + static void (GLAPIENTRY *glGetTexGenfv) (GLenum coord, GLenum pname, GLfloat *params ); + static void (GLAPIENTRY *glGetTexGeniv) (GLenum coord, GLenum pname, GLint *params ); + + /* Loading OpenGL functions which are needed ONLY for implementing GLES 2.0*/ + static void (GL_APIENTRY *glBlendColor) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); + static void (GL_APIENTRY *glStencilFuncSeparate)(GLenum face, GLenum func, GLint ref, GLuint mask); + static void (GL_APIENTRY *glStencilMaskSeparate)(GLenum face, GLuint mask); + static GLboolean (GL_APIENTRY *glIsProgram)(GLuint program); + static GLboolean (GL_APIENTRY *glIsShader)(GLuint shader); + static void (GL_APIENTRY *glVertexAttrib1f)(GLuint indx, GLfloat x); + static void (GL_APIENTRY *glVertexAttrib1fv)(GLuint indx, const GLfloat* values); + static void (GL_APIENTRY *glVertexAttrib2f)(GLuint indx, GLfloat x, GLfloat y); + static void (GL_APIENTRY *glVertexAttrib2fv)(GLuint indx, const GLfloat* values); + static void (GL_APIENTRY *glVertexAttrib3f)(GLuint indx, GLfloat x, GLfloat y, GLfloat z); + static void (GL_APIENTRY *glVertexAttrib3fv)(GLuint indx, const GLfloat* values); + static void (GL_APIENTRY *glVertexAttrib4f)(GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w); + static void (GL_APIENTRY *glVertexAttrib4fv)(GLuint indx, const GLfloat* values); + static void (GL_APIENTRY *glVertexAttribPointer)(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr); + static void (GL_APIENTRY *glDisableVertexAttribArray)(GLuint index); + static void (GL_APIENTRY *glEnableVertexAttribArray)(GLuint index); + static void (GL_APIENTRY *glGetVertexAttribfv)(GLuint index, GLenum pname, GLfloat* params); + static void (GL_APIENTRY *glGetVertexAttribiv)(GLuint index, GLenum pname, GLint* params); + static void (GL_APIENTRY *glGetVertexAttribPointerv)(GLuint index, GLenum pname, GLvoid** pointer); + static void (GL_APIENTRY *glUniform1f)(GLint location, GLfloat x); + static void (GL_APIENTRY *glUniform1fv)(GLint location, GLsizei count, const GLfloat* v); + static void (GL_APIENTRY *glUniform1i)(GLint location, GLint x); + static void (GL_APIENTRY *glUniform1iv)(GLint location, GLsizei count, const GLint* v); + static void (GL_APIENTRY *glUniform2f)(GLint location, GLfloat x, GLfloat y); + static void (GL_APIENTRY *glUniform2fv)(GLint location, GLsizei count, const GLfloat* v); + static void (GL_APIENTRY *glUniform2i)(GLint location, GLint x, GLint y); + static void (GL_APIENTRY *glUniform2iv)(GLint location, GLsizei count, const GLint* v); + static void (GL_APIENTRY *glUniform3f)(GLint location, GLfloat x, GLfloat y, GLfloat z); + static void (GL_APIENTRY *glUniform3fv)(GLint location, GLsizei count, const GLfloat* v); + static void (GL_APIENTRY *glUniform3i)(GLint location, GLint x, GLint y, GLint z); + static void (GL_APIENTRY *glUniform3iv)(GLint location, GLsizei count, const GLint* v); + static void (GL_APIENTRY *glUniform4f)(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w); + static void (GL_APIENTRY *glUniform4fv)(GLint location, GLsizei count, const GLfloat* v); + static void (GL_APIENTRY *glUniform4i)(GLint location, GLint x, GLint y, GLint z, GLint w); + static void (GL_APIENTRY *glUniform4iv)(GLint location, GLsizei count, const GLint* v); + static void (GL_APIENTRY *glUniformMatrix2fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); + static void (GL_APIENTRY *glUniformMatrix3fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); + static void (GL_APIENTRY *glUniformMatrix4fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); + static void (GL_APIENTRY *glAttachShader)(GLuint program, GLuint shader); + static void (GL_APIENTRY *glBindAttribLocation)(GLuint program, GLuint index, const GLchar* name); + static void (GL_APIENTRY *glCompileShader)(GLuint shader); + static GLuint (GL_APIENTRY *glCreateProgram)(void); + static GLuint (GL_APIENTRY *glCreateShader)(GLenum type); + static void (GL_APIENTRY *glDeleteProgram)(GLuint program); + static void (GL_APIENTRY *glDeleteShader)(GLuint shader); + static void (GL_APIENTRY *glDetachShader)(GLuint program, GLuint shader); + static void (GL_APIENTRY *glLinkProgram)(GLuint program); + static void (GL_APIENTRY *glUseProgram)(GLuint program); + static void (GL_APIENTRY *glValidateProgram)(GLuint program); + static void (GL_APIENTRY *glGetActiveAttrib)(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name); + static void (GL_APIENTRY *glGetActiveUniform)(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name); + static void (GL_APIENTRY *glGetAttachedShaders)(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders); + static int (GL_APIENTRY *glGetAttribLocation)(GLuint program, const GLchar* name); + static void (GL_APIENTRY *glGetProgramiv)(GLuint program, GLenum pname, GLint* params); + static void (GL_APIENTRY *glGetProgramInfoLog)(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog); + static void (GL_APIENTRY *glGetShaderiv)(GLuint shader, GLenum pname, GLint* params); + static void (GL_APIENTRY *glGetShaderInfoLog)(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog); + static void (GL_APIENTRY *glGetShaderPrecisionFormat)(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision); + static void (GL_APIENTRY *glGetShaderSource)(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source); + static void (GL_APIENTRY *glGetUniformfv)(GLuint program, GLint location, GLfloat* params); + static void (GL_APIENTRY *glGetUniformiv)(GLuint program, GLint location, GLint* params); + static int (GL_APIENTRY *glGetUniformLocation)(GLuint program, const GLchar* name); + static void (GL_APIENTRY *glReleaseShaderCompiler)(void); + static void (GL_APIENTRY *glShaderBinary)(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length); + static void (GL_APIENTRY *glShaderSource)(GLuint shader, GLsizei count, const GLchar** string, const GLint* length); + +private: + bool m_isLoaded; + static android::Mutex s_lock; +}; + +#endif diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/GLESbuffer.h b/emulator/opengl/host/libs/Translator/include/GLcommon/GLESbuffer.h new file mode 100644 index 0000000..3353ec1 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/GLESbuffer.h @@ -0,0 +1,47 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef GLES_BUFFER_H +#define GLES_BUFFER_H + +#include <stdio.h> +#include <GLES/gl.h> +#include <GLcommon/objectNameManager.h> +#include <GLcommon/RangeManip.h> + +class GLESbuffer: public ObjectData { +public: + GLESbuffer():ObjectData(BUFFER_DATA),m_size(0),m_usage(GL_STATIC_DRAW),m_data(NULL),m_wasBound(false){} + GLuint getSize(){return m_size;}; + GLuint getUsage(){return m_usage;}; + GLvoid* getData(){ return m_data;} + bool setBuffer(GLuint size,GLuint usage,const GLvoid* data); + bool setSubBuffer(GLint offset,GLuint size,const GLvoid* data); + void getConversions(const RangeList& rIn,RangeList& rOut); + bool fullyConverted(){return m_conversionManager.size() == 0;}; + void setBinded(){m_wasBound = true;}; + bool wasBinded(){return m_wasBound;}; + ~GLESbuffer(); + +private: + GLuint m_size; + GLuint m_usage; + unsigned char* m_data; + RangeList m_conversionManager; + bool m_wasBound; +}; + +typedef SmartPtr<GLESbuffer> GLESbufferPtr; +#endif diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/GLEScontext.h b/emulator/opengl/host/libs/Translator/include/GLcommon/GLEScontext.h new file mode 100644 index 0000000..fbc118f --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/GLEScontext.h @@ -0,0 +1,211 @@ +/* +* Copyright 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef GLES_CONTEXT_H +#define GLES_CONTEXT_H + +#include "GLDispatch.h" +#include "GLESpointer.h" +#include "objectNameManager.h" +#include <utils/threads.h> +#include <string> + +typedef std::map<GLenum,GLESpointer*> ArraysMap; + +enum TextureTarget { +TEXTURE_2D, +TEXTURE_CUBE_MAP, +NUM_TEXTURE_TARGETS +}; + +typedef struct _textureTargetState { + GLuint texture; + GLboolean enabled; +} textureTargetState; + +typedef textureTargetState textureUnitState[NUM_TEXTURE_TARGETS]; + +class Version{ +public: + Version(); + Version(int major,int minor,int release); + Version(const char* versionString); + Version(const Version& ver); + bool operator<(const Version& ver) const; + Version& operator=(const Version& ver); +private: + int m_major; + int m_minor; + int m_release; +}; + +struct GLSupport { + GLSupport():maxLights(0),maxVertexAttribs(0),maxClipPlane(0),maxTexUnits(0), \ + maxTexImageUnits(0),maxTexSize(0) , \ + GL_EXT_TEXTURE_FORMAT_BGRA8888(false), GL_EXT_FRAMEBUFFER_OBJECT(false), \ + GL_ARB_VERTEX_BLEND(false), GL_ARB_MATRIX_PALETTE(false), \ + GL_EXT_PACKED_DEPTH_STENCIL(false) , GL_OES_READ_FORMAT(false), \ + GL_ARB_HALF_FLOAT_PIXEL(false), GL_NV_HALF_FLOAT(false), \ + GL_ARB_HALF_FLOAT_VERTEX(false),GL_SGIS_GENERATE_MIPMAP(false), + GL_ARB_ES2_COMPATIBILITY(false),GL_OES_STANDARD_DERIVATIVES(false) {} ; + int maxLights; + int maxVertexAttribs; + int maxClipPlane; + int maxTexUnits; + int maxTexImageUnits; + int maxTexSize; + Version glslVersion; + bool GL_EXT_TEXTURE_FORMAT_BGRA8888; + bool GL_EXT_FRAMEBUFFER_OBJECT; + bool GL_ARB_VERTEX_BLEND; + bool GL_ARB_MATRIX_PALETTE; + bool GL_EXT_PACKED_DEPTH_STENCIL; + bool GL_OES_READ_FORMAT; + bool GL_ARB_HALF_FLOAT_PIXEL; + bool GL_NV_HALF_FLOAT; + bool GL_ARB_HALF_FLOAT_VERTEX; + bool GL_SGIS_GENERATE_MIPMAP; + bool GL_ARB_ES2_COMPATIBILITY; + bool GL_OES_STANDARD_DERIVATIVES; + +}; + +struct ArrayData{ + ArrayData():data(NULL), + type(0), + stride(0), + allocated(false){}; + + void* data; + GLenum type; + unsigned int stride; + bool allocated; +}; + +class GLESConversionArrays +{ +public: + GLESConversionArrays():m_current(0){}; + void setArr(void* data,unsigned int stride,GLenum type); + void allocArr(unsigned int size,GLenum type); + ArrayData& operator[](int i); + void* getCurrentData(); + ArrayData& getCurrentArray(); + unsigned int getCurrentIndex(); + void operator++(); + + ~GLESConversionArrays(); +private: + std::map<GLenum,ArrayData> m_arrays; + unsigned int m_current; +}; + +class GLEScontext{ +public: + virtual void init(); + GLEScontext(); + GLenum getGLerror(); + void setGLerror(GLenum err); + void setShareGroup(ShareGroupPtr grp){m_shareGroup = grp;}; + ShareGroupPtr shareGroup() const { return m_shareGroup; } + virtual void setActiveTexture(GLenum tex); + unsigned int getBindedTexture(GLenum target); + unsigned int getBindedTexture(GLenum unit,GLenum target); + void setBindedTexture(GLenum target,unsigned int tex); + bool isTextureUnitEnabled(GLenum unit); + void setTextureEnabled(GLenum target, GLenum enable); + ObjectLocalName getDefaultTextureName(GLenum target); + bool isInitialized() { return m_initialized; }; + void setUnpackAlignment(GLint param){ m_unpackAlignment = param; }; + GLint getUnpackAlignment(){ return m_unpackAlignment; }; + + bool isArrEnabled(GLenum); + void enableArr(GLenum arr,bool enable); + const GLvoid* setPointer(GLenum arrType,GLint size,GLenum type,GLsizei stride,const GLvoid* data,bool normalize = false); + virtual const GLESpointer* getPointer(GLenum arrType); + virtual void setupArraysPointers(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct) = 0; + void bindBuffer(GLenum target,GLuint buffer); + void unbindBuffer(GLuint buffer); + bool isBuffer(GLuint buffer); + bool isBindedBuffer(GLenum target); + GLvoid* getBindedBuffer(GLenum target); + void getBufferSize(GLenum target,GLint* param); + void getBufferUsage(GLenum target,GLint* param); + bool setBufferData(GLenum target,GLsizeiptr size,const GLvoid* data,GLenum usage); + bool setBufferSubData(GLenum target,GLintptr offset,GLsizeiptr size,const GLvoid* data); + const char * getExtensionString(); + const char * getRendererString() const; + void getGlobalLock(); + void releaseGlobalLock(); + virtual GLSupport* getCaps(){return &s_glSupport;}; + virtual ~GLEScontext(); + virtual int getMaxTexUnits() = 0; + virtual void drawValidate(void); + + void setRenderbufferBinding(GLuint rb) { m_renderbuffer = rb; } + GLuint getRenderbufferBinding() const { return m_renderbuffer; } + void setFramebufferBinding(GLuint fb) { m_framebuffer = fb; } + GLuint getFramebufferBinding() const { return m_framebuffer; } + + static GLDispatch& dispatcher(){return s_glDispatch;}; + + static int getMaxLights(){return s_glSupport.maxLights;} + static int getMaxClipPlanes(){return s_glSupport.maxClipPlane;} + static int getMaxTexSize(){return s_glSupport.maxTexSize;} + static Version glslVersion(){return s_glSupport.glslVersion;} + static bool isAutoMipmapSupported(){return s_glSupport.GL_SGIS_GENERATE_MIPMAP;} + static TextureTarget GLTextureTargetToLocal(GLenum target); + static int findMaxIndex(GLsizei count,GLenum type,const GLvoid* indices); + + virtual bool glGetIntegerv(GLenum pname, GLint *params); + virtual bool glGetBooleanv(GLenum pname, GLboolean *params); + virtual bool glGetFloatv(GLenum pname, GLfloat *params); + virtual bool glGetFixedv(GLenum pname, GLfixed *params); + +protected: + virtual bool needConvert(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id) = 0; + void convertDirect(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum array_id,GLESpointer* p); + void convertDirectVBO(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum array_id,GLESpointer* p); + void convertIndirect(GLESConversionArrays& fArrs,GLsizei count,GLenum type,const GLvoid* indices,GLenum array_id,GLESpointer* p); + void convertIndirectVBO(GLESConversionArrays& fArrs,GLsizei count,GLenum indices_type,const GLvoid* indices,GLenum array_id,GLESpointer* p); + void initCapsLocked(const GLubyte * extensionString); + virtual void initExtensionString() =0; + static android::Mutex s_lock; + static GLDispatch s_glDispatch; + bool m_initialized; + unsigned int m_activeTexture; + GLint m_unpackAlignment; + ArraysMap m_map; + static std::string* s_glExtensions; + static std::string s_glRenderer; + static GLSupport s_glSupport; + +private: + + virtual void setupArr(const GLvoid* arr,GLenum arrayType,GLenum dataType,GLint size,GLsizei stride, GLboolean normalized, int pointsIndex = -1) = 0 ; + GLuint getBuffer(GLenum target); + + ShareGroupPtr m_shareGroup; + GLenum m_glError; + textureUnitState* m_texState; + unsigned int m_arrayBuffer; + unsigned int m_elementBuffer; + GLuint m_renderbuffer; + GLuint m_framebuffer; +}; + +#endif + diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/GLESmacros.h b/emulator/opengl/host/libs/Translator/include/GLcommon/GLESmacros.h new file mode 100644 index 0000000..95ffadb --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/GLESmacros.h @@ -0,0 +1,47 @@ +#ifndef GLES_MACROS_H +#define GLES_MACROS_H + +#define GET_CTX() \ + if(!s_eglIface) return; \ + GLEScontext *ctx = s_eglIface->getGLESContext(); \ + +#define GET_CTX_CM() \ + if(!s_eglIface) return; \ + GLEScmContext *ctx = static_cast<GLEScmContext *>(s_eglIface->getGLESContext()); \ + if(!ctx) return; + +#define GET_CTX_V2() \ + if(!s_eglIface) return; \ + GLESv2Context *ctx = static_cast<GLESv2Context *>(s_eglIface->getGLESContext()); \ + if(!ctx) return; + +#define GET_CTX_RET(failure_ret) \ + if(!s_eglIface) return failure_ret; \ + GLEScontext *ctx = s_eglIface->getGLESContext(); \ + if(!ctx) return failure_ret; + +#define GET_CTX_CM_RET(failure_ret) \ + if(!s_eglIface) return failure_ret; \ + GLEScmContext *ctx = static_cast<GLEScmContext *>(s_eglIface->getGLESContext()); \ + if(!ctx) return failure_ret; + +#define GET_CTX_V2_RET(failure_ret) \ + if(!s_eglIface) return failure_ret; \ + GLESv2Context *ctx = static_cast<GLESv2Context *>(s_eglIface->getGLESContext()); \ + if(!ctx) return failure_ret; + + +#define SET_ERROR_IF(condition,err) if((condition)) { \ + fprintf(stderr, "%s:%s:%d error 0x%x\n", __FILE__, __FUNCTION__, __LINE__, err); \ + ctx->setGLerror(err); \ + return; \ + } + + +#define RET_AND_SET_ERROR_IF(condition,err,ret) if((condition)) { \ + fprintf(stderr, "%s:%s:%d error 0x%x\n", __FILE__, __FUNCTION__, __LINE__, err); \ + ctx->setGLerror(err); \ + return ret; \ + } + +#endif diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/GLESpointer.h b/emulator/opengl/host/libs/Translator/include/GLcommon/GLESpointer.h new file mode 100644 index 0000000..851fe45 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/GLESpointer.h @@ -0,0 +1,58 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef GLES_POINTER_H +#define GLES_POINTER_H + +#include <GLES/gl.h> +#include "GLESbuffer.h" + +class GLESpointer +{ + +public: + GLESpointer(); + GLenum getType() const; + GLint getSize() const; + GLsizei getStride() const; + const GLvoid* getArrayData() const; + GLvoid* getBufferData() const; + GLuint getBufferName() const; + GLboolean getNormalized() const { return m_normalize ? GL_TRUE : GL_FALSE; } + const GLvoid* getData() const; + unsigned int getBufferOffset() const; + void redirectPointerData(); + void getBufferConversions(const RangeList& rl,RangeList& rlOut); + bool bufferNeedConversion(){ return !m_buffer->fullyConverted();} + void setArray (GLint size,GLenum type,GLsizei stride,const GLvoid* data,bool normalize = false); + void setBuffer(GLint size,GLenum type,GLsizei stride,GLESbuffer* buf,GLuint bufferName,int offset,bool normalize = false); + bool isEnable() const; + bool isNormalize() const; + bool isVBO() const; + void enable(bool b); + +private: + GLint m_size; + GLenum m_type; + GLsizei m_stride; + bool m_enabled; + bool m_normalize; + const GLvoid* m_data; + GLESbuffer* m_buffer; + GLuint m_bufferName; + unsigned int m_buffOffset; + bool m_isVBO; +}; +#endif diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/GLESvalidate.h b/emulator/opengl/host/libs/Translator/include/GLcommon/GLESvalidate.h new file mode 100644 index 0000000..3daaa7c --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/GLESvalidate.h @@ -0,0 +1,43 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef GLES_VALIDATE_H +#define GLES_VALIDATE_H + +#include <GLES/gl.h> +#include "GLEScontext.h" +struct GLESvalidate +{ +static bool textureEnum(GLenum e,unsigned int maxTex); +static bool pixelType(GLEScontext * ctx,GLenum type); +static bool pixelOp(GLenum format,GLenum type); +static bool pixelFrmt(GLEScontext* ctx , GLenum format); +static bool bufferTarget(GLenum target); +static bool bufferParam(GLenum param); +static bool drawMode(GLenum mode); +static bool drawType(GLenum mode); +static bool textureTarget(GLenum target); +static bool textureTargetLimited(GLenum target); +static bool textureTargetEx(GLenum target); +static bool texImgDim(GLsizei width,GLsizei height,int maxTexSize); +static bool blendEquationMode(GLenum mode); +static bool framebufferTarget(GLenum target); +static bool framebufferAttachment(GLenum attachment); +static bool framebufferAttachmentParams(GLenum pname); +static bool renderbufferTarget(GLenum target); +static bool renderbufferParams(GLenum pname); +}; + +#endif diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/GLconversion_macros.h b/emulator/opengl/host/libs/Translator/include/GLcommon/GLconversion_macros.h new file mode 100644 index 0000000..83e99b4 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/GLconversion_macros.h @@ -0,0 +1,31 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _GL_FIXED_OPS_H +#define _GL_FIXED_OPS_H + +#define X2F(x) (((float)(x))/65536.0f) +#define X2D(x) (((double)(x))/65536.0) +#define X2I(x) ((x) /65536) +#define B2S(x) ((short)x) + + +#define F2X(d) ((d) > 32767.65535 ? 32767 * 65536 + 65535 : \ + (d) < -32768.65535 ? -32768 * 65536 + 65535 : \ + ((GLfixed) ((d) * 65536))) + +#define I2X(d) ((d)*65536) + +#endif diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/GLutils.h b/emulator/opengl/host/libs/Translator/include/GLcommon/GLutils.h new file mode 100644 index 0000000..2aed646 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/GLutils.h @@ -0,0 +1,51 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef GL_UTILS_H +#define GL_UTILS_H + +#include <inttypes.h> +#include <assert.h> + +typedef enum{ + GLES_1_1 = 1, + GLES_2_0 = 2, + MAX_GLES_VERSION //Must be last + }GLESVersion; + +template <class T> +void swap(T& x,T& y) { + T temp; + temp=x; + x=y; + y=temp; +} + +bool isPowerOf2(int num); + +inline +unsigned int ToTargetCompatibleHandle(uintptr_t hostHandle) +{ + // The host and target handles can have different sizes (e.g. 32-bit + // target handle for ARM, and 64-bit host handle on x86_64). + // This function checks that the input host handle value can be + // converted into a target handle one without losing any bits. + // + unsigned int targetHandle = (unsigned int)hostHandle; + assert(sizeof(targetHandle) == sizeof(hostHandle) || targetHandle == hostHandle); + return targetHandle; +} + +#endif diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/PaletteTexture.h b/emulator/opengl/host/libs/Translator/include/GLcommon/PaletteTexture.h new file mode 100644 index 0000000..90b206d --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/PaletteTexture.h @@ -0,0 +1,25 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef __PALETTE_TEXTURE_H__ +#define __PALETTE_TEXTURE_H__ + +#include <GLES/gl.h> + +#define MAX_SUPPORTED_PALETTE 10 + +unsigned char* uncompressTexture(GLenum internalformat,GLenum& formatOut,GLsizei width,GLsizei height,GLsizei imageSize, const GLvoid* data,GLint level); + +#endif diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/RangeManip.h b/emulator/opengl/host/libs/Translator/include/GLcommon/RangeManip.h new file mode 100644 index 0000000..e3162b8 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/RangeManip.h @@ -0,0 +1,69 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef RANGE_H +#define RANGE_H + +#include <vector> + +class Range { + +public: + Range():m_start(0),m_end(0),m_size(0){}; + Range(int start,int size):m_start(start),m_end(start+size),m_size(size){}; + Range(const Range& r):m_start(r.m_start),m_end(r.m_end),m_size(r.m_size){}; + void setRange(int start,int size){m_start = start; m_end = start+size; m_size = size;}; + inline int getStart() const{return m_start;}; + inline int getEnd() const{return m_end;}; + inline int getSize() const{return m_size;}; + Range& operator=(const Range& r) { + m_start = r.m_start; + m_end = r.m_end; + m_size = r.m_size; + return *this; + } + bool operator ==(const Range& r) const { + return m_start == r.m_start && m_size == r.m_size && m_end == r.m_end; + } + bool operator !=(const Range& r) const {return !((*this) == r);}; + bool rangeIntersection(const Range& r,Range& rOut) const ; + bool rangeUnion(const Range& r,Range& rOut) const ; + +private: + int m_start; + int m_end; + int m_size; +}; + +class RangeList { +public: + void addRange(const Range& r); + void addRanges(const RangeList& rl); + void delRange(const Range& r,RangeList& deleted); + void delRanges(const RangeList& rl,RangeList& deleted); + bool empty() const; + void merge(); + int size() const; + void clear(); + Range& operator[](unsigned int i){return list[i];}; +private: + void erase(unsigned int i); + std::vector<Range> list; +}; + + + + +#endif diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/SmartPtr.h b/emulator/opengl/host/libs/Translator/include/GLcommon/SmartPtr.h new file mode 100644 index 0000000..8ac93fb --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/SmartPtr.h @@ -0,0 +1,163 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef __SMART_PTR_H +#define __SMART_PTR_H + +#include <cutils/threads.h> +#include <cutils/atomic.h> + +template <class T, bool threadSafe = false> +class SmartPtr +{ +public: + explicit SmartPtr(T* ptr = (T*)NULL) { + if (threadSafe) { + m_lock = new mutex_t; + mutex_init(m_lock); + } + else m_lock = NULL; + + m_ptr = ptr; + if (ptr) + m_pRefCount = new int32_t(1); + else + m_pRefCount = NULL; + } + + SmartPtr<T,threadSafe>(const SmartPtr<T,false>& rhs) { + if (threadSafe) { + m_lock = new mutex_t; + mutex_init(m_lock); + } + else m_lock = NULL; + + m_pRefCount = rhs.m_pRefCount; + m_ptr = rhs.m_ptr; + use(); + } + + SmartPtr<T,threadSafe>(SmartPtr<T,true>& rhs) { + if (threadSafe) { + m_lock = new mutex_t; + mutex_init(m_lock); + } + else m_lock = NULL; + + if (rhs.m_lock) mutex_lock(rhs.m_lock); + m_pRefCount = rhs.m_pRefCount; + m_ptr = rhs.m_ptr; + use(); + if (rhs.m_lock) mutex_unlock(rhs.m_lock); + } + + ~SmartPtr() { + if (m_lock) mutex_lock(m_lock); + release(); + if (m_lock) + { + mutex_unlock(m_lock); + mutex_destroy(m_lock); + delete m_lock; + } + } + + T* Ptr() const { + return m_ptr; + } + + const T* constPtr() const + { + return m_ptr; + } + + T* operator->() const { + return m_ptr; + } + + T& operator*() const { + return *m_ptr; + } + + // This gives STL lists something to compare. + bool operator <(const SmartPtr<T>& t1) const { + return m_ptr < t1.m_ptr; + } + + SmartPtr<T,threadSafe>& operator=(const SmartPtr<T,false>& rhs) + { + if (m_ptr == rhs.m_ptr) + return *this; + + if (m_lock) mutex_lock(m_lock); + release(); + m_pRefCount = rhs.m_pRefCount; + m_ptr = rhs.m_ptr; + use(); + if (m_lock) mutex_unlock(m_lock); + + return *this; + } + + SmartPtr<T,threadSafe>& operator=(SmartPtr<T,true>& rhs) + { + if (m_ptr == rhs.m_ptr) + return *this; + + if (m_lock) mutex_lock(m_lock); + release(); + if (rhs.m_lock) mutex_lock(rhs.m_lock); + m_pRefCount = rhs.m_pRefCount; + m_ptr = rhs.m_ptr; + use(); + if (rhs.m_lock) mutex_unlock(rhs.m_lock); + if (m_lock) mutex_unlock(m_lock); + + return *this; + } + +private: + int32_t *m_pRefCount; + mutex_t *m_lock; + T* m_ptr; + + // Increment the reference count on this pointer by 1. + int use() { + if (!m_pRefCount) return 0; + return android_atomic_inc(m_pRefCount) + 1; + } + + // Decrement the reference count on the pointer by 1. + // If the reference count goes to (or below) 0, the pointer is deleted. + int release() { + if (!m_pRefCount) return 0; + + int iVal = android_atomic_dec(m_pRefCount); + if (iVal > 1) + return iVal - 1; + + delete m_pRefCount; + m_pRefCount = NULL; + + if (m_ptr) { + delete m_ptr; + m_ptr = NULL; + } + return 0; + } + +}; + +#endif // of __SMART_PTR_H diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/TextureUtils.h b/emulator/opengl/host/libs/Translator/include/GLcommon/TextureUtils.h new file mode 100644 index 0000000..9b0c4ea --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/TextureUtils.h @@ -0,0 +1,31 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _TEXTURE_UTILS_H +#define _TEXTURE_UTILS_H + +#include <GLES/gl.h> +#include <GLES/glext.h> +#include "GLEScontext.h" +#include "PaletteTexture.h" +#include "etc1.h" + +int getCompressedFormats(int* formats); +void doCompressedTexImage2D(GLEScontext * ctx, GLenum target, GLint level, + GLenum internalformat, GLsizei width, + GLsizei height, GLint border, + GLsizei imageSize, const GLvoid* data, void * funcPtr); + +#endif diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/TranslatorIfaces.h b/emulator/opengl/host/libs/Translator/include/GLcommon/TranslatorIfaces.h new file mode 100644 index 0000000..3c5e15a --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/TranslatorIfaces.h @@ -0,0 +1,102 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef TRANSLATOR_IFACES_H +#define TRANSLATOR_IFACES_H +#include <GLES/gl.h> +#include <string.h> +#include "objectNameManager.h" + +extern "C" { + +/* This is a generic function pointer type, whose name indicates it must + * be cast to the proper type *and calling convention* before use. + */ +typedef void (*__translatorMustCastToProperFunctionPointerType)(void); + +typedef struct { + const char* name; + __translatorMustCastToProperFunctionPointerType address; +}ExtentionDescriptor; + +class TextureData : public ObjectData +{ +public: + ~TextureData() { + if (sourceEGLImage && eglImageDetach) (*eglImageDetach)(sourceEGLImage); + } + TextureData(): ObjectData(TEXTURE_DATA), + width(0), + height(0), + border(0), + internalFormat(GL_RGBA), + sourceEGLImage(0), + wasBound(false), + requiresAutoMipmap(false), + target(0), + oldGlobal(0) { + memset(crop_rect,0,4*sizeof(int)); + }; + + unsigned int width; + unsigned int height; + unsigned int border; + unsigned int internalFormat; + unsigned int sourceEGLImage; + bool wasBound; + bool requiresAutoMipmap; + int crop_rect[4]; + void (*eglImageDetach)(unsigned int imageId); + GLenum target; + GLuint oldGlobal; +}; + +struct EglImage +{ + ~EglImage(){}; + unsigned int imageId; + unsigned int globalTexName; + unsigned int width; + unsigned int height; + unsigned int internalFormat; + unsigned int border; +}; + +typedef SmartPtr<EglImage> ImagePtr; +typedef std::map< unsigned int, ImagePtr> ImagesHndlMap; + +class GLEScontext; + +typedef struct { + GLEScontext* (*createGLESContext)(); + void (*initContext)(GLEScontext*,ShareGroupPtr); + void (*deleteGLESContext)(GLEScontext*); + void (*flush)(); + void (*finish)(); + void (*setShareGroup)(GLEScontext*,ShareGroupPtr); + __translatorMustCastToProperFunctionPointerType (*getProcAddress)(const char*); +}GLESiface; + + +typedef struct { + GLEScontext* (*getGLESContext)(); + EglImage* (*eglAttachEGLImage)(unsigned int imageId); + void (*eglDetachEGLImage)(unsigned int imageId); +}EGLiface; + +typedef GLESiface* (*__translator_getGLESIfaceFunc)(EGLiface*); + +} +#endif diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/etc1.h b/emulator/opengl/host/libs/Translator/include/GLcommon/etc1.h new file mode 100644 index 0000000..15ee9ac --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/etc1.h @@ -0,0 +1,108 @@ +// Copyright 2009 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef __etc1_h__ +#define __etc1_h__ + +#define MAX_ETC_SUPPORTED 1 + +#define ETC1_ENCODED_BLOCK_SIZE 8 +#define ETC1_DECODED_BLOCK_SIZE 48 + +#ifndef ETC1_RGB8_OES +#define ETC1_RGB8_OES 0x8D64 +#endif + +typedef unsigned char etc1_byte; +typedef int etc1_bool; +typedef unsigned int etc1_uint32; + +#ifdef __cplusplus +extern "C" { +#endif + +// Encode a block of pixels. +// +// pIn is a pointer to a ETC_DECODED_BLOCK_SIZE array of bytes that represent a +// 4 x 4 square of 3-byte pixels in form R, G, B. Byte (3 * (x + 4 * y) is the R +// value of pixel (x, y). +// +// validPixelMask is a 16-bit mask where bit (1 << (x + y * 4)) indicates whether +// the corresponding (x,y) pixel is valid. Invalid pixel color values are ignored when compressing. +// +// pOut is an ETC1 compressed version of the data. + +void etc1_encode_block(const etc1_byte* pIn, etc1_uint32 validPixelMask, etc1_byte* pOut); + +// Decode a block of pixels. +// +// pIn is an ETC1 compressed version of the data. +// +// pOut is a pointer to a ETC_DECODED_BLOCK_SIZE array of bytes that represent a +// 4 x 4 square of 3-byte pixels in form R, G, B. Byte (3 * (x + 4 * y) is the R +// value of pixel (x, y). + +void etc1_decode_block(const etc1_byte* pIn, etc1_byte* pOut); + +// Return the size of the encoded image data (does not include size of PKM header). + +etc1_uint32 etc1_get_encoded_data_size(etc1_uint32 width, etc1_uint32 height); + +// Encode an entire image. +// pIn - pointer to the image data. Formatted such that +// pixel (x,y) is at pIn + pixelSize * x + stride * y; +// pOut - pointer to encoded data. Must be large enough to store entire encoded image. +// pixelSize can be 2 or 3. 2 is an GL_UNSIGNED_SHORT_5_6_5 image, 3 is a GL_BYTE RGB image. +// returns non-zero if there is an error. + +int etc1_encode_image(const etc1_byte* pIn, etc1_uint32 width, etc1_uint32 height, + etc1_uint32 pixelSize, etc1_uint32 stride, etc1_byte* pOut); + +// Decode an entire image. +// pIn - pointer to encoded data. +// pOut - pointer to the image data. Will be written such that +// pixel (x,y) is at pIn + pixelSize * x + stride * y. Must be +// large enough to store entire image. +// pixelSize can be 2 or 3. 2 is an GL_UNSIGNED_SHORT_5_6_5 image, 3 is a GL_BYTE RGB image. +// returns non-zero if there is an error. + +int etc1_decode_image(const etc1_byte* pIn, etc1_byte* pOut, + etc1_uint32 width, etc1_uint32 height, + etc1_uint32 pixelSize, etc1_uint32 stride); + +// Size of a PKM header, in bytes. + +#define ETC_PKM_HEADER_SIZE 16 + +// Format a PKM header + +void etc1_pkm_format_header(etc1_byte* pHeader, etc1_uint32 width, etc1_uint32 height); + +// Check if a PKM header is correctly formatted. + +etc1_bool etc1_pkm_is_valid(const etc1_byte* pHeader); + +// Read the image width from a PKM header + +etc1_uint32 etc1_pkm_get_width(const etc1_byte* pHeader); + +// Read the image height from a PKM header + +etc1_uint32 etc1_pkm_get_height(const etc1_byte* pHeader); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/gldefs.h b/emulator/opengl/host/libs/Translator/include/GLcommon/gldefs.h new file mode 100644 index 0000000..1f0c7ef --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/gldefs.h @@ -0,0 +1,42 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +typedef double GLclampd; /* double precision float in [0,1] */ +typedef double GLdouble; /* double precision float */ + +#define GL_S 0x2000 +#define GL_T 0x2001 +#define GL_R 0x2002 +#define GL_Q 0x2003 +#define GL_TEXTURE_GEN_S 0x0C60 +#define GL_TEXTURE_GEN_T 0x0C61 +#define GL_TEXTURE_GEN_R 0x0C62 +#define GL_CLIENT_VERTEX_ARRAY_BIT 0x00000002 +#define GL_TRANSFORM_BIT 0x00001000 +#define GL_INT 0x1404 +#define GL_HALF_FLOAT_NV 0x140B +#define GL_HALF_FLOAT 0x140B +#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642 +#define GL_POINT_SPRITE 0x8861 +#define GL_FRAMEBUFFER_EXT 0x8D40 +#define GL_TEXTURE_WIDTH 0x1000 +#define GL_TEXTURE_HEIGHT 0x1001 +#define GL_TEXTURE_RED_SIZE 0x805C +#define GL_TEXTURE_GREEN_SIZE 0x805D +#define GL_TEXTURE_BLUE_SIZE 0x805E +#define GL_TEXTURE_ALPHA_SIZE 0x805F +#define GL_TEXTURE_DEPTH_SIZE 0x884A +#define GL_TEXTURE_INTERNAL_FORMAT 0x1003 diff --git a/emulator/opengl/host/libs/Translator/include/GLcommon/objectNameManager.h b/emulator/opengl/host/libs/Translator/include/GLcommon/objectNameManager.h new file mode 100644 index 0000000..605fd29 --- /dev/null +++ b/emulator/opengl/host/libs/Translator/include/GLcommon/objectNameManager.h @@ -0,0 +1,269 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _OBJECT_NAME_MANAGER_H +#define _OBJECT_NAME_MANAGER_H + +#include <cutils/threads.h> +#include <map> +#include "SmartPtr.h" + +enum NamedObjectType { + VERTEXBUFFER = 0, + TEXTURE = 1, + RENDERBUFFER = 2, + FRAMEBUFFER = 3, + SHADER = 4, + NUM_OBJECT_TYPES = 5 // Must be last +}; + +enum ObjectDataType { + SHADER_DATA, + PROGRAM_DATA, + TEXTURE_DATA, + BUFFER_DATA, + UNDEFINED_DATA +}; + +class ObjectData +{ +public: + ObjectData() : m_dataType(UNDEFINED_DATA) {}; + ObjectData(ObjectDataType type): m_dataType(type) {}; + ObjectDataType getDataType() { return m_dataType; }; + virtual ~ObjectData() {}; +private: + ObjectDataType m_dataType; +}; +typedef SmartPtr<ObjectData> ObjectDataPtr; +typedef unsigned long long ObjectLocalName; +typedef std::map<ObjectLocalName, unsigned int> NamesMap; + +// +// Class NameSpace - this class manages allocations and deletions of objects +// from a single "local" namespace (private to context group). +// For each allocated object name, a "global" name is +// generated as well to be used in the space where all +// contexts are shared. +// +// NOTE: this class does not used by the EGL/GLES layer directly, +// the EGL/GLES layer creates objects using the ShareGroup class +// interface (see below). +class GlobalNameSpace; +class NameSpace +{ + friend class ShareGroup; + friend class GlobalNameSpace; + +private: + NameSpace(NamedObjectType p_type, GlobalNameSpace *globalNameSpace); + ~NameSpace(); + + // + // genName - creates new object in the namespace and returns its name. + // if genLocal is false then the specified p_localName will be used. + // This function also generate a global name for the object, + // the value of the global name can be retrieved using the + // getGlobalName function. + // + ObjectLocalName genName(ObjectLocalName p_localName, bool genGlobal, bool genLocal); + + // genGlobalName() - This function creates a global name + // with no associated local name, for the + // translator internal use. + unsigned int genGlobalName(void); + + // + // getGlobalName - returns the global name of an object or 0 if the object + // does not exist. + // + unsigned int getGlobalName(ObjectLocalName p_localName); + + // + // getLocaalName - returns the local name of an object or 0 if the object + // does not exist. + // + ObjectLocalName getLocalName(unsigned int p_globalName); + + // + // deleteName - deletes and object from the namespace as well as its + // global name from the global name space. + // + void deleteName(ObjectLocalName p_localName); + + // + // isObject - returns true if the named object exist. + // + bool isObject(ObjectLocalName p_localName); + + // + // replaces an object to map to an existing global object + // + void replaceGlobalName(ObjectLocalName p_localName, unsigned int p_globalName); + +private: + ObjectLocalName m_nextName; + NamesMap m_localToGlobalMap; + const NamedObjectType m_type; + GlobalNameSpace *m_globalNameSpace; +}; + +class GlobalNameSpace +{ +public: + GlobalNameSpace(); + ~GlobalNameSpace(); + unsigned int genName(NamedObjectType p_type); + void deleteName(NamedObjectType p_type, unsigned int p_name); + +private: + mutex_t m_lock; +}; + +// +// class ShareGroup - +// That class manages objects of one "local" context share group, typically +// there will be one inctance of ShareGroup for each user OpenGL context +// unless the user context share with another user context. In that case they +// both will share the same ShareGroup instance. +// calls into that class gets serialized through a lock so it is thread safe. +// +class ShareGroup +{ + friend class ObjectNameManager; + friend class SmartPtr<ShareGroup>; // to allow destructing when ShareGroupPtr refcount reaches zero + +public: + + // + // genName - generates new object name and returns its name value. + // if genLocal is false, p_localName will be used as the name. + // This function also generates a "global" name for the object + // which can be queried using the getGlobalName function. + // + ObjectLocalName genName(NamedObjectType p_type, ObjectLocalName p_localName = 0, bool genLocal= false); + + // genGlobalName() - This function creates a global name + // with no associated local name, for the + // translator internal use. + unsigned int genGlobalName(NamedObjectType p_type); + + // + // getGlobalName - retrieves the "global" name of an object or 0 if the + // object does not exist. + // + unsigned int getGlobalName(NamedObjectType p_type, ObjectLocalName p_localName); + + // + // getLocalName - retrieves the "local" name of an object or 0 if the + // object does not exist. + // + ObjectLocalName getLocalName(NamedObjectType p_type, unsigned int p_globalName); + + // + // deleteName - deletes and object from the namespace as well as its + // global name from the global name space. + // + void deleteName(NamedObjectType p_type, ObjectLocalName p_localName); + + // + // replaceGlobalName - replaces an object to map to an existing global + // named object. (used when creating EGLImage siblings) + // + void replaceGlobalName(NamedObjectType p_type, ObjectLocalName p_localName, unsigned int p_globalName); + + // + // isObject - returns true if the named object exist. + // + bool isObject(NamedObjectType p_type, ObjectLocalName p_localName); + + // + // Assign object global data to a names object + // + void setObjectData(NamedObjectType p_type, ObjectLocalName p_localName, ObjectDataPtr data); + + // + // Retrieve object global data + // + ObjectDataPtr getObjectData(NamedObjectType p_type, ObjectLocalName p_localName); + +private: + explicit ShareGroup(GlobalNameSpace *globalNameSpace); + ~ShareGroup(); + +private: + mutex_t m_lock; + NameSpace *m_nameSpace[NUM_OBJECT_TYPES]; + void *m_objectsData; +}; + +typedef SmartPtr<ShareGroup> ShareGroupPtr; +typedef std::multimap<void *, ShareGroupPtr> ShareGroupsMap; + +// +// ObjectNameManager - +// This class manages the set of all ShareGroups instances, +// each ShareGroup instance can be accessed through one or more 'groupName' +// values. the type of 'groupName' is void *, the intent is that the EGL +// layer will use the user context handle as the name for its ShareGroup +// object. Multiple names can be attached to a ShareGroup object to support +// user context sharing. +// +class ObjectNameManager +{ +public: + explicit ObjectNameManager(GlobalNameSpace *globalNameSpace); + ~ObjectNameManager(); + + // + // createShareGroup - create a new ShareGroup object and attach it with + // the "name" specified by p_groupName. + // + ShareGroupPtr createShareGroup(void *p_groupName); + + // + // attachShareGroup - find the ShareGroup object attached to the name + // specified in p_existingGroupName and attach p_groupName to the same + // ShareGroup instance. + // + ShareGroupPtr attachShareGroup(void *p_groupName, void *p_existingGroupName); + + // + // getShareGroup - retreive a ShareGroup object based on its "name" + // + ShareGroupPtr getShareGroup(void *p_groupName); + + // + // deleteShareGroup - deletes the attachment of the p_groupName to its + // attached ShareGroup. When the last name of ShareGroup is + // deleted the ShareGroup object is destroyed. + // + void deleteShareGroup(void *p_groupName); + + // + // getGlobalContext() - this function returns a name of an existing + // ShareGroup. The intent is that the EGL layer will + // use that function to get the GL context which each + // new context needs to share with. + // + void *getGlobalContext(); + +private: + ShareGroupsMap m_groups; + mutex_t m_lock; + GlobalNameSpace *m_globalNameSpace; +}; + +#endif diff --git a/emulator/opengl/host/libs/libOpenglRender/Android.mk b/emulator/opengl/host/libs/libOpenglRender/Android.mk new file mode 100644 index 0000000..1d923b4 --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/Android.mk @@ -0,0 +1,83 @@ +LOCAL_PATH := $(call my-dir) + +host_OS_SRCS := +host_common_LDLIBS := + +ifeq ($(HOST_OS),linux) + host_OS_SRCS = NativeLinuxSubWindow.cpp + host_common_LDLIBS += -lX11 +endif + +ifeq ($(HOST_OS),darwin) + host_OS_SRCS = NativeMacSubWindow.m + host_common_LDLIBS += -Wl,-framework,AppKit +endif + +ifeq ($(HOST_OS),windows) + host_OS_SRCS = NativeWindowsSubWindow.cpp +endif + +host_common_SRC_FILES := \ + $(host_OS_SRCS) \ + render_api.cpp \ + ColorBuffer.cpp \ + EGLDispatch.cpp \ + FBConfig.cpp \ + FrameBuffer.cpp \ + GLDispatch.cpp \ + GL2Dispatch.cpp \ + RenderContext.cpp \ + WindowSurface.cpp \ + RenderControl.cpp \ + ThreadInfo.cpp \ + RenderThread.cpp \ + ReadBuffer.cpp \ + RenderServer.cpp + +host_common_CFLAGS := + +#For gl debbuging +#host_common_CFLAGS += -DCHECK_GL_ERROR + + +### host libOpenglRender ################################################# +$(call emugl-begin-host-shared-library,libOpenglRender) + +$(call emugl-import,libGLESv1_dec libGLESv2_dec lib_renderControl_dec libOpenglCodecCommon libOpenglOsUtils) + +LOCAL_LDLIBS += $(host_common_LDLIBS) + +LOCAL_SRC_FILES := $(host_common_SRC_FILES) +$(call emugl-export,C_INCLUDES,$(EMUGL_PATH)/host/include) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) + +# use Translator's egl/gles headers +LOCAL_C_INCLUDES += $(EMUGL_PATH)/host/libs/Translator/include + +LOCAL_STATIC_LIBRARIES += libutils liblog + +$(call emugl-export,CFLAGS,$(host_common_CFLAGS)) + +$(call emugl-end-module) + + +### host libOpenglRender, 64-bit ######################################### +$(call emugl-begin-host-shared-library,lib64OpenglRender) + +$(call emugl-import,lib64GLESv1_dec lib64GLESv2_dec lib64_renderControl_dec lib64OpenglCodecCommon lib64OpenglOsUtils) + +#LOCAL_LDFLAGS += -m64 # adding -m64 here doesn't work, because it somehow appear BEFORE -m32 in command-line. +LOCAL_LDLIBS += $(host_common_LDLIBS) -m64 # Put -m64 it in LOCAL_LDLIBS instead. + +LOCAL_SRC_FILES := $(host_common_SRC_FILES) +$(call emugl-export,C_INCLUDES,$(EMUGL_PATH)/host/include) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) + +# use Translator's egl/gles headers +LOCAL_C_INCLUDES += $(EMUGL_PATH)/host/libs/Translator/include + +LOCAL_STATIC_LIBRARIES += lib64utils lib64log + +$(call emugl-export,CFLAGS,$(host_common_CFLAGS) -m64) + +$(call emugl-end-module) diff --git a/emulator/opengl/host/libs/libOpenglRender/ColorBuffer.cpp b/emulator/opengl/host/libs/libOpenglRender/ColorBuffer.cpp new file mode 100644 index 0000000..218f32b --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/ColorBuffer.cpp @@ -0,0 +1,346 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "ColorBuffer.h" +#include "FrameBuffer.h" +#include "EGLDispatch.h" +#include "GLDispatch.h" +#include "ThreadInfo.h" +#ifdef WITH_GLES2 +#include "GL2Dispatch.h" +#endif +#include <stdio.h> + +ColorBuffer *ColorBuffer::create(int p_width, int p_height, + GLenum p_internalFormat) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + + GLenum texInternalFormat = 0; + + switch(p_internalFormat) { + case GL_RGB: + case GL_RGB565_OES: + texInternalFormat = GL_RGB; + break; + + case GL_RGBA: + case GL_RGB5_A1_OES: + case GL_RGBA4_OES: + texInternalFormat = GL_RGBA; + break; + + default: + return NULL; + break; + } + + if (!fb->bind_locked()) { + return NULL; + } + + ColorBuffer *cb = new ColorBuffer(); + + + s_gl.glGenTextures(1, &cb->m_tex); + s_gl.glBindTexture(GL_TEXTURE_2D, cb->m_tex); + int nComp = (texInternalFormat == GL_RGB ? 3 : 4); + char *zBuff = new char[nComp*p_width*p_height]; + if (zBuff) { + memset(zBuff, 0, nComp*p_width*p_height); + } + s_gl.glTexImage2D(GL_TEXTURE_2D, 0, texInternalFormat, + p_width, p_height, 0, + texInternalFormat, + GL_UNSIGNED_BYTE, zBuff); + delete [] zBuff; + s_gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + s_gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + s_gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + s_gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + s_gl.glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + + // + // create another texture for that colorbuffer for blit + // + s_gl.glGenTextures(1, &cb->m_blitTex); + s_gl.glBindTexture(GL_TEXTURE_2D, cb->m_blitTex); + s_gl.glTexImage2D(GL_TEXTURE_2D, 0, texInternalFormat, + p_width, p_height, 0, + texInternalFormat, + GL_UNSIGNED_BYTE, NULL); + s_gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + s_gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + s_gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + s_gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + s_gl.glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + + cb->m_width = p_width; + cb->m_height = p_height; + cb->m_internalFormat = texInternalFormat; + + if (fb->getCaps().has_eglimage_texture_2d) { + cb->m_eglImage = s_egl.eglCreateImageKHR(fb->getDisplay(), + s_egl.eglGetCurrentContext(), + EGL_GL_TEXTURE_2D_KHR, + (EGLClientBuffer)cb->m_tex, + NULL); + + cb->m_blitEGLImage = s_egl.eglCreateImageKHR(fb->getDisplay(), + s_egl.eglGetCurrentContext(), + EGL_GL_TEXTURE_2D_KHR, + (EGLClientBuffer)cb->m_blitTex, + NULL); + } + + fb->unbind_locked(); + return cb; +} + +ColorBuffer::ColorBuffer() : + m_tex(0), + m_eglImage(NULL), + m_fbo(0), + m_internalFormat(0), + m_warYInvertBug(false) +{ +#if __APPLE__ + // On Macs running OS X 10.6 and 10.7 with Intel HD Graphics 3000, some + // screens or parts of the screen are displayed upside down. The exact + // conditions/sequence that triggers this aren't known yet; I haven't + // been able to reproduce it in a standalone test. This way of enabling the + // workaround will break if it is a driver bug (rather than a bug in this + // code which works by accident elsewhere) and Apple/Intel release a fix for + // it. Running a standalone test to detect the problem at runtime would be + // more robust. + if (strstr((const char*)s_gl.glGetString(GL_RENDERER), "Intel HD Graphics 3000")) + m_warYInvertBug = true; +#endif +} + +ColorBuffer::~ColorBuffer() +{ + FrameBuffer *fb = FrameBuffer::getFB(); + fb->bind_locked(); + s_gl.glDeleteTextures(1, &m_tex); + if (m_eglImage) { + s_egl.eglDestroyImageKHR(fb->getDisplay(), m_eglImage); + } + if (m_fbo) { + s_gl.glDeleteFramebuffersOES(1, &m_fbo); + } + fb->unbind_locked(); +} + +void ColorBuffer::subUpdate(int x, int y, int width, int height, GLenum p_format, GLenum p_type, void *pixels) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + if (!fb->bind_locked()) return; + s_gl.glBindTexture(GL_TEXTURE_2D, m_tex); + s_gl.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + s_gl.glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, + width, height, p_format, p_type, pixels); + fb->unbind_locked(); +} + +bool ColorBuffer::blitFromCurrentReadBuffer() +{ + RenderThreadInfo *tInfo = getRenderThreadInfo(); + if (!tInfo->currContext.Ptr()) { + // no Current context + return false; + } + + // + // Create a temporary texture inside the current context + // from the blit_texture EGLImage and copy the pixels + // from the current read buffer to that texture + // + GLuint tmpTex; + GLint currTexBind; + if (tInfo->currContext->isGL2()) { + s_gl2.glGetIntegerv(GL_TEXTURE_BINDING_2D, &currTexBind); + s_gl2.glGenTextures(1,&tmpTex); + s_gl2.glBindTexture(GL_TEXTURE_2D, tmpTex); + s_gl2.glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_blitEGLImage); + s_gl2.glCopyTexImage2D(GL_TEXTURE_2D, 0, m_internalFormat, + 0, 0, m_width, m_height, 0); + } + else { + s_gl.glGetIntegerv(GL_TEXTURE_BINDING_2D, &currTexBind); + s_gl.glGenTextures(1,&tmpTex); + s_gl.glBindTexture(GL_TEXTURE_2D, tmpTex); + s_gl.glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_blitEGLImage); + s_gl.glCopyTexImage2D(GL_TEXTURE_2D, 0, m_internalFormat, + 0, 0, m_width, m_height, 0); + } + + + // + // Now bind the frame buffer context and blit from + // m_blitTex into m_tex + // + FrameBuffer *fb = FrameBuffer::getFB(); + if (fb->bind_locked()) { + + // + // bind FBO object which has this colorbuffer as render target + // + if (bind_fbo()) { + + // + // save current viewport and match it to the current + // colorbuffer size + // + GLint vport[4]; + s_gl.glGetIntegerv(GL_VIEWPORT, vport); + s_gl.glViewport(0, 0, m_width, m_height); + + // render m_blitTex + s_gl.glBindTexture(GL_TEXTURE_2D, m_blitTex); + s_gl.glEnable(GL_TEXTURE_2D); + s_gl.glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + drawTexQuad(!m_warYInvertBug); + + // unbind the fbo + s_gl.glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); + + // restrore previous viewport + s_gl.glViewport(vport[0], vport[1], vport[2], vport[3]); + } + + // unbind from the FrameBuffer context + fb->unbind_locked(); + } + + // + // delete the temporary texture and restore the texture binding + // inside the current context + // + if (tInfo->currContext->isGL2()) { + s_gl2.glDeleteTextures(1, &tmpTex); + s_gl2.glBindTexture(GL_TEXTURE_2D, currTexBind); + } + else { + s_gl.glDeleteTextures(1, &tmpTex); + s_gl.glBindTexture(GL_TEXTURE_2D, currTexBind); + } + + return true; +} + +bool ColorBuffer::bindToTexture() +{ + if (m_eglImage) { + RenderThreadInfo *tInfo = getRenderThreadInfo(); + if (tInfo->currContext.Ptr()) { +#ifdef WITH_GLES2 + if (tInfo->currContext->isGL2()) { + s_gl2.glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_eglImage); + } + else { + s_gl.glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_eglImage); + } +#else + s_gl.glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_eglImage); +#endif + return true; + } + } + return false; +} + +bool ColorBuffer::bindToRenderbuffer() +{ + if (m_eglImage) { + RenderThreadInfo *tInfo = getRenderThreadInfo(); + if (tInfo->currContext.Ptr()) { +#ifdef WITH_GLES2 + if (tInfo->currContext->isGL2()) { + s_gl2.glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER_OES, m_eglImage); + } + else { + s_gl.glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER_OES, m_eglImage); + } +#else + s_gl.glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER_OES, m_eglImage); +#endif + return true; + } + } + return false; +} + +bool ColorBuffer::bind_fbo() +{ + if (m_fbo) { + // fbo already exist - just bind + s_gl.glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_fbo); + return true; + } + + s_gl.glGenFramebuffersOES(1, &m_fbo); + s_gl.glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_fbo); + s_gl.glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, + GL_COLOR_ATTACHMENT0_OES, + GL_TEXTURE_2D, m_tex, 0); + GLenum status = s_gl.glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES); + if (status != GL_FRAMEBUFFER_COMPLETE_OES) { + s_gl.glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); + s_gl.glDeleteFramebuffersOES(1, &m_fbo); + m_fbo = 0; + return false; + } + + return true; +} + +bool ColorBuffer::post() +{ + s_gl.glBindTexture(GL_TEXTURE_2D, m_tex); + s_gl.glEnable(GL_TEXTURE_2D); + s_gl.glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + drawTexQuad(true); + + return true; +} + +void ColorBuffer::drawTexQuad(bool flipy) +{ + GLfloat verts[] = { -1.0f, -1.0f, 0.0f, + -1.0f, +1.0f, 0.0f, + +1.0f, -1.0f, 0.0f, + +1.0f, +1.0f, 0.0f }; + + GLfloat tcoords[] = { 0.0f, 1.0f, + 0.0f, 0.0f, + 1.0f, 1.0f, + 1.0f, 0.0f }; + + if (!flipy) { + for (int i = 0; i < 4; i++) { + // swap 0.0/1.0 in second element of each tcoord vector + tcoords[2*i + 1] = tcoords[2*i + 1] == 0.0f ? 1.0f : 0.0f; + } + } + + s_gl.glClientActiveTexture(GL_TEXTURE0); + s_gl.glEnableClientState(GL_TEXTURE_COORD_ARRAY); + s_gl.glTexCoordPointer(2, GL_FLOAT, 0, tcoords); + + s_gl.glEnableClientState(GL_VERTEX_ARRAY); + s_gl.glVertexPointer(3, GL_FLOAT, 0, verts); + s_gl.glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); +} diff --git a/emulator/opengl/host/libs/libOpenglRender/ColorBuffer.h b/emulator/opengl/host/libs/libOpenglRender/ColorBuffer.h new file mode 100644 index 0000000..4a2c6b4 --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/ColorBuffer.h @@ -0,0 +1,60 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _LIBRENDER_COLORBUFFER_H +#define _LIBRENDER_COLORBUFFER_H + +#include <EGL/egl.h> +#include <EGL/eglext.h> +#include <GLES/gl.h> +#include <SmartPtr.h> + +class ColorBuffer +{ +public: + static ColorBuffer *create(int p_width, int p_height, + GLenum p_internalFormat); + ~ColorBuffer(); + + GLuint getGLTextureName() const { return m_tex; } + GLuint getWidth() const { return m_width; } + GLuint getHeight() const { return m_height; } + + void subUpdate(int x, int y, int width, int height, GLenum p_format, GLenum p_type, void *pixels); + bool post(); + bool bindToTexture(); + bool bindToRenderbuffer(); + bool blitFromCurrentReadBuffer(); + +private: + ColorBuffer(); + void drawTexQuad(bool flipy); + bool bind_fbo(); // binds a fbo which have this texture as render target + +private: + GLuint m_tex; + GLuint m_blitTex; + EGLImageKHR m_eglImage; + EGLImageKHR m_blitEGLImage; + GLuint m_width; + GLuint m_height; + GLuint m_fbo; + GLenum m_internalFormat; + bool m_warYInvertBug; +}; + +typedef SmartPtr<ColorBuffer> ColorBufferPtr; + +#endif diff --git a/emulator/opengl/host/libs/libOpenglRender/EGLDispatch.cpp b/emulator/opengl/host/libs/libOpenglRender/EGLDispatch.cpp new file mode 100644 index 0000000..3cf5dbc --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/EGLDispatch.cpp @@ -0,0 +1,87 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "EGLDispatch.h" +#include <stdio.h> +#include <stdlib.h> +#include "osDynLibrary.h" + +EGLDispatch s_egl; + +#define DEFAULT_EGL_LIB EMUGL_LIBNAME("EGL_translator") + +bool init_egl_dispatch() +{ + + const char *libName = getenv("ANDROID_EGL_LIB"); + if (!libName) libName = DEFAULT_EGL_LIB; + + osUtils::dynLibrary *lib = osUtils::dynLibrary::open(libName); + if (!lib) { + printf("Failed to open %s\n", libName); + return NULL; + } + s_egl.eglGetError = (eglGetError_t) lib->findSymbol("eglGetError"); + s_egl.eglGetDisplay = (eglGetDisplay_t) lib->findSymbol("eglGetDisplay"); + s_egl.eglInitialize = (eglInitialize_t) lib->findSymbol("eglInitialize"); + s_egl.eglTerminate = (eglTerminate_t) lib->findSymbol("eglTerminate"); + s_egl.eglQueryString = (eglQueryString_t) lib->findSymbol("eglQueryString"); + s_egl.eglGetConfigs = (eglGetConfigs_t) lib->findSymbol("eglGetConfigs"); + s_egl.eglChooseConfig = (eglChooseConfig_t) lib->findSymbol("eglChooseConfig"); + s_egl.eglGetConfigAttrib = (eglGetConfigAttrib_t) lib->findSymbol("eglGetConfigAttrib"); + s_egl.eglCreateWindowSurface = (eglCreateWindowSurface_t) lib->findSymbol("eglCreateWindowSurface"); + s_egl.eglCreatePbufferSurface = (eglCreatePbufferSurface_t) lib->findSymbol("eglCreatePbufferSurface"); + s_egl.eglCreatePixmapSurface = (eglCreatePixmapSurface_t) lib->findSymbol("eglCreatePixmapSurface"); + s_egl.eglDestroySurface = (eglDestroySurface_t) lib->findSymbol("eglDestroySurface"); + s_egl.eglQuerySurface = (eglQuerySurface_t) lib->findSymbol("eglQuerySurface"); + s_egl.eglBindAPI = (eglBindAPI_t) lib->findSymbol("eglBindAPI"); + s_egl.eglQueryAPI = (eglQueryAPI_t) lib->findSymbol("eglQueryAPI"); + s_egl.eglWaitClient = (eglWaitClient_t) lib->findSymbol("eglWaitClient"); + s_egl.eglReleaseThread = (eglReleaseThread_t) lib->findSymbol("eglReleaseThread"); + s_egl.eglCreatePbufferFromClientBuffer = (eglCreatePbufferFromClientBuffer_t) lib->findSymbol("eglCreatePbufferFromClientBuffer"); + s_egl.eglSurfaceAttrib = (eglSurfaceAttrib_t) lib->findSymbol("eglSurfaceAttrib"); + s_egl.eglBindTexImage = (eglBindTexImage_t) lib->findSymbol("eglBindTexImage"); + s_egl.eglReleaseTexImage = (eglReleaseTexImage_t) lib->findSymbol("eglReleaseTexImage"); + s_egl.eglSwapInterval = (eglSwapInterval_t) lib->findSymbol("eglSwapInterval"); + s_egl.eglCreateContext = (eglCreateContext_t) lib->findSymbol("eglCreateContext"); + s_egl.eglDestroyContext = (eglDestroyContext_t) lib->findSymbol("eglDestroyContext"); + s_egl.eglMakeCurrent = (eglMakeCurrent_t) lib->findSymbol("eglMakeCurrent"); + s_egl.eglGetCurrentContext = (eglGetCurrentContext_t) lib->findSymbol("eglGetCurrentContext"); + s_egl.eglGetCurrentSurface = (eglGetCurrentSurface_t) lib->findSymbol("eglGetCurrentSurface"); + s_egl.eglGetCurrentDisplay = (eglGetCurrentDisplay_t) lib->findSymbol("eglGetCurrentDisplay"); + s_egl.eglQueryContext = (eglQueryContext_t) lib->findSymbol("eglQueryContext"); + s_egl.eglWaitGL = (eglWaitGL_t) lib->findSymbol("eglWaitGL"); + s_egl.eglWaitNative = (eglWaitNative_t) lib->findSymbol("eglWaitNative"); + s_egl.eglSwapBuffers = (eglSwapBuffers_t) lib->findSymbol("eglSwapBuffers"); + s_egl.eglCopyBuffers = (eglCopyBuffers_t) lib->findSymbol("eglCopyBuffers"); + s_egl.eglGetProcAddress = (eglGetProcAddress_t) lib->findSymbol("eglGetProcAddress"); + +#define INIT_EGL_EXT_FUNC(name) \ + if (s_egl.eglGetProcAddress) s_egl.name = (name ## _t) s_egl.eglGetProcAddress(#name); \ + if (!s_egl.name || !s_egl.eglGetProcAddress) s_egl.name = (name ## _t) lib->findSymbol(#name) + + INIT_EGL_EXT_FUNC(eglLockSurfaceKHR); + INIT_EGL_EXT_FUNC(eglUnlockSurfaceKHR); + INIT_EGL_EXT_FUNC(eglCreateImageKHR); + INIT_EGL_EXT_FUNC(eglDestroyImageKHR); + INIT_EGL_EXT_FUNC(eglCreateSyncKHR); + INIT_EGL_EXT_FUNC(eglDestroySyncKHR); + INIT_EGL_EXT_FUNC(eglClientWaitSyncKHR); + INIT_EGL_EXT_FUNC(eglSignalSyncKHR); + INIT_EGL_EXT_FUNC(eglGetSyncAttribKHR); + INIT_EGL_EXT_FUNC(eglSetSwapRectangleANDROID); + + return true; +} diff --git a/emulator/opengl/host/libs/libOpenglRender/EGLDispatch.h b/emulator/opengl/host/libs/libOpenglRender/EGLDispatch.h new file mode 100644 index 0000000..f74acba --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/EGLDispatch.h @@ -0,0 +1,72 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _EGL_DISPATCH_H +#define _EGL_DISPATCH_H + +#include "egl_proc.h" + +struct EGLDispatch { + eglGetError_t eglGetError; + eglGetDisplay_t eglGetDisplay; + eglInitialize_t eglInitialize; + eglTerminate_t eglTerminate; + eglQueryString_t eglQueryString; + eglGetConfigs_t eglGetConfigs; + eglChooseConfig_t eglChooseConfig; + eglGetConfigAttrib_t eglGetConfigAttrib; + eglCreateWindowSurface_t eglCreateWindowSurface; + eglCreatePbufferSurface_t eglCreatePbufferSurface; + eglCreatePixmapSurface_t eglCreatePixmapSurface; + eglDestroySurface_t eglDestroySurface; + eglQuerySurface_t eglQuerySurface; + eglBindAPI_t eglBindAPI; + eglQueryAPI_t eglQueryAPI; + eglWaitClient_t eglWaitClient; + eglReleaseThread_t eglReleaseThread; + eglCreatePbufferFromClientBuffer_t eglCreatePbufferFromClientBuffer; + eglSurfaceAttrib_t eglSurfaceAttrib; + eglBindTexImage_t eglBindTexImage; + eglReleaseTexImage_t eglReleaseTexImage; + eglSwapInterval_t eglSwapInterval; + eglCreateContext_t eglCreateContext; + eglDestroyContext_t eglDestroyContext; + eglMakeCurrent_t eglMakeCurrent; + eglGetCurrentContext_t eglGetCurrentContext; + eglGetCurrentSurface_t eglGetCurrentSurface; + eglGetCurrentDisplay_t eglGetCurrentDisplay; + eglQueryContext_t eglQueryContext; + eglWaitGL_t eglWaitGL; + eglWaitNative_t eglWaitNative; + eglSwapBuffers_t eglSwapBuffers; + eglCopyBuffers_t eglCopyBuffers; + eglGetProcAddress_t eglGetProcAddress; + eglLockSurfaceKHR_t eglLockSurfaceKHR; + eglUnlockSurfaceKHR_t eglUnlockSurfaceKHR; + eglCreateImageKHR_t eglCreateImageKHR; + eglDestroyImageKHR_t eglDestroyImageKHR; + eglCreateSyncKHR_t eglCreateSyncKHR; + eglDestroySyncKHR_t eglDestroySyncKHR; + eglClientWaitSyncKHR_t eglClientWaitSyncKHR; + eglSignalSyncKHR_t eglSignalSyncKHR; + eglGetSyncAttribKHR_t eglGetSyncAttribKHR; + eglSetSwapRectangleANDROID_t eglSetSwapRectangleANDROID; +}; + +bool init_egl_dispatch(); + +extern EGLDispatch s_egl; + +#endif diff --git a/emulator/opengl/host/libs/libOpenglRender/FBConfig.cpp b/emulator/opengl/host/libs/libOpenglRender/FBConfig.cpp new file mode 100644 index 0000000..089f1da --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/FBConfig.cpp @@ -0,0 +1,258 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "FBConfig.h" +#include "FrameBuffer.h" +#include "EGLDispatch.h" +#include <stdio.h> + +FBConfig **FBConfig::s_fbConfigs = NULL; +int FBConfig::s_numConfigs = 0; + +const GLuint FBConfig::s_configAttribs[] = { + EGL_DEPTH_SIZE, // must be first - see getDepthSize() + EGL_STENCIL_SIZE, // must be second - see getStencilSize() + EGL_RENDERABLE_TYPE,// must be third - see getRenderableType() + EGL_SURFACE_TYPE, // must be fourth - see getSurfaceType() + EGL_CONFIG_ID, // must be fifth - see chooseConfig() + EGL_BUFFER_SIZE, + EGL_ALPHA_SIZE, + EGL_BLUE_SIZE, + EGL_GREEN_SIZE, + EGL_RED_SIZE, + EGL_CONFIG_CAVEAT, + EGL_LEVEL, + EGL_MAX_PBUFFER_HEIGHT, + EGL_MAX_PBUFFER_PIXELS, + EGL_MAX_PBUFFER_WIDTH, + EGL_NATIVE_RENDERABLE, + EGL_NATIVE_VISUAL_ID, + EGL_NATIVE_VISUAL_TYPE, + EGL_SAMPLES, + EGL_SAMPLE_BUFFERS, + EGL_TRANSPARENT_TYPE, + EGL_TRANSPARENT_BLUE_VALUE, + EGL_TRANSPARENT_GREEN_VALUE, + EGL_TRANSPARENT_RED_VALUE, + EGL_BIND_TO_TEXTURE_RGB, + EGL_BIND_TO_TEXTURE_RGBA, + EGL_MIN_SWAP_INTERVAL, + EGL_MAX_SWAP_INTERVAL, + EGL_LUMINANCE_SIZE, + EGL_ALPHA_MASK_SIZE, + EGL_COLOR_BUFFER_TYPE, + //EGL_MATCH_NATIVE_PIXMAP, + EGL_CONFORMANT +}; + +const int FBConfig::s_numConfigAttribs = sizeof(FBConfig::s_configAttribs) / sizeof(GLuint); + +InitConfigStatus FBConfig::initConfigList(FrameBuffer *fb) +{ + InitConfigStatus ret = INIT_CONFIG_FAILED; + + if (!fb) { + return ret; + } + + const FrameBufferCaps &caps = fb->getCaps(); + EGLDisplay dpy = fb->getDisplay(); + + if (dpy == EGL_NO_DISPLAY) { + fprintf(stderr,"Could not get EGL Display\n"); + return ret; + } + + // + // Query the set of configs in the EGL backend + // + EGLint nConfigs; + if (!s_egl.eglGetConfigs(dpy, NULL, 0, &nConfigs)) { + fprintf(stderr, "Could not get number of available configs\n"); + return ret; + } + EGLConfig *configs = new EGLConfig[nConfigs]; + s_egl.eglGetConfigs(dpy, configs, nConfigs, &nConfigs); + + // + // copy the config attributes, filter out + // configs we do not want to support. + // + int j = 0; + s_fbConfigs = new FBConfig*[nConfigs]; + for (int i=0; i<nConfigs; i++) { + + // + // filter out configs which does not support pbuffers. + // we only support pbuffer configs since we use a pbuffer + // handle to bind a guest created window object. + // + EGLint surfaceType; + s_egl.eglGetConfigAttrib(dpy, configs[i], + EGL_SURFACE_TYPE, &surfaceType); + if (!(surfaceType & EGL_PBUFFER_BIT)) continue; + + // + // Filter out not RGB configs + // + EGLint redSize, greenSize, blueSize; + s_egl.eglGetConfigAttrib(dpy, configs[i], EGL_RED_SIZE, &redSize); + s_egl.eglGetConfigAttrib(dpy, configs[i], EGL_BLUE_SIZE, &blueSize); + s_egl.eglGetConfigAttrib(dpy, configs[i], EGL_GREEN_SIZE, &greenSize); + if (redSize==0 || greenSize==0 || blueSize==0) continue; + + s_fbConfigs[j++] = new FBConfig(dpy, configs[i]); + } + s_numConfigs = j; + + delete[] configs; + + return s_numConfigs > 0 ? INIT_CONFIG_PASSED : INIT_CONFIG_FAILED; +} + +const FBConfig *FBConfig::get(int p_config) +{ + if (p_config >= 0 && p_config < s_numConfigs) { + return s_fbConfigs[p_config]; + } + return NULL; +} + +int FBConfig::getNumConfigs() +{ + return s_numConfigs; +} + +void FBConfig::packConfigsInfo(GLuint *buffer) +{ + memcpy(buffer, s_configAttribs, s_numConfigAttribs * sizeof(GLuint)); + for (int i=0; i<s_numConfigs; i++) { + memcpy(buffer+(i+1)*s_numConfigAttribs, + s_fbConfigs[i]->m_attribValues, + s_numConfigAttribs * sizeof(GLuint)); + } +} + +int FBConfig::chooseConfig(FrameBuffer *fb, EGLint * attribs, uint32_t * configs, uint32_t configs_size) +{ + EGLDisplay dpy = fb->getDisplay(); + int ret = 0; + + if (dpy == EGL_NO_DISPLAY) { + fprintf(stderr,"Could not get EGL Display\n"); + return ret; + } + // + // Query the num of configs in the EGL backend + // + EGLint nConfigs; + if (!s_egl.eglGetConfigs(dpy, NULL, 0, &nConfigs)) { + fprintf(stderr, "Could not get number of available configs\n"); + return ret; + } + // + // Query the max matching configs in the backend + // + EGLConfig *matchedConfigs = new EGLConfig[nConfigs]; + + // + //Until we have EGLImage implementation, we force pbuf configs + // + bool needToAddPbufAttr = true; + int attribCnt = 0; + EGLint * attrib_p = attribs; + if (attribs) { + while (attrib_p[0] != EGL_NONE) { + if (attrib_p[0] == EGL_SURFACE_TYPE) { + attrib_p[1] = EGL_PBUFFER_BIT; //replace whatever was there before + needToAddPbufAttr = false; + } + attrib_p += 2; + attribCnt += 2; + } + } + EGLint * newAttribs = new EGLint[attribCnt + 1 + ((needToAddPbufAttr) ? 2 : 0)]; + attrib_p = newAttribs; + if (needToAddPbufAttr) { + *(attrib_p++) = EGL_SURFACE_TYPE; + *(attrib_p++) = EGL_PBUFFER_BIT; + } + memcpy(attrib_p, attribs, attribCnt*sizeof(EGLint)); + attrib_p += attribCnt; + *attrib_p = EGL_NONE; + +#if 0 + if (newAttribs) { + EGLint * attrib_p = newAttribs; + while (attrib_p[0] != EGL_NONE) { + DBG("attr: 0x%x %d, ", attrib_p[0], attrib_p[1]); + attrib_p += 2; + } + } +#endif + + s_egl.eglChooseConfig(dpy, newAttribs, matchedConfigs, nConfigs, &nConfigs); + + delete[] newAttribs; + + // + // From all matchedConfigs we need only config_size FBConfigs, so we intersect both lists compating the CONFIG_ID attribute + // + uint32_t nVerifiedCfgs = 0; + for (int matchedIdx=0; matchedIdx<nConfigs; matchedIdx++) { + if ((configs != NULL) && (configs_size > 0) && (nVerifiedCfgs >= configs_size)) break; //We have enouhgt configs + int sCfgId; + s_egl.eglGetConfigAttrib(dpy, matchedConfigs[matchedIdx], EGL_CONFIG_ID, &sCfgId); + for (int fbIdx=0; fbIdx<s_numConfigs; fbIdx++) { + int dCfgId = s_fbConfigs[fbIdx]->m_attribValues[4]; //CONFIG_ID + if (sCfgId == dCfgId) { + //This config matches the requested attributes and filtered into fbConfigs, so we're happy with it + if (configs && nVerifiedCfgs < configs_size) { + configs[nVerifiedCfgs] = fbIdx; + } + nVerifiedCfgs++; + break; + } + } + } + + delete[] matchedConfigs; + + return nVerifiedCfgs; +} + +FBConfig::FBConfig(EGLDisplay p_eglDpy, EGLConfig p_eglCfg) +{ + m_eglConfig = p_eglCfg; + m_attribValues = new GLint[s_numConfigAttribs]; + for (int i=0; i<s_numConfigAttribs; i++) { + m_attribValues[i] = 0; + s_egl.eglGetConfigAttrib(p_eglDpy, p_eglCfg, s_configAttribs[i], &m_attribValues[i]); + + // + // All exported configs supports android native window rendering + // + if (s_configAttribs[i] == EGL_SURFACE_TYPE) { + m_attribValues[i] |= EGL_WINDOW_BIT; + } + } +} + +FBConfig::~FBConfig() +{ + if (m_attribValues) { + delete[] m_attribValues; + } +} diff --git a/emulator/opengl/host/libs/libOpenglRender/FBConfig.h b/emulator/opengl/host/libs/libOpenglRender/FBConfig.h new file mode 100644 index 0000000..6388549 --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/FBConfig.h @@ -0,0 +1,60 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _LIBRENDER_FBCONFIG_H +#define _LIBRENDER_FBCONFIG_H + +#include <EGL/egl.h> +#include <GLES/gl.h> + +class FrameBuffer; + +enum InitConfigStatus { + INIT_CONFIG_FAILED = 0, + INIT_CONFIG_PASSED = 1 +}; + +class FBConfig +{ +public: + static InitConfigStatus initConfigList(FrameBuffer *fb); + static const FBConfig *get(int p_config); + static int getNumConfigs(); + static int getNumAttribs() { return s_numConfigAttribs; } + static void packConfigsInfo(GLuint *buffer); + static int chooseConfig(FrameBuffer *fb, EGLint * attribs, uint32_t * configs, uint32_t configs_size); + ~FBConfig(); + + EGLConfig getEGLConfig() const { return m_eglConfig; } + GLuint getDepthSize() const { return (m_attribValues ? m_attribValues[0] : 0); } + GLuint getStencilSize() const { return (m_attribValues ? m_attribValues[1] : 0); } + GLuint getRenderableType() const { return (m_attribValues ? m_attribValues[2] : 0); } + GLuint getSurfaceType() const { return (m_attribValues ? m_attribValues[3] : 0); } + +private: + FBConfig(EGLDisplay p_eglDpy, EGLConfig p_eglCfg); + +private: + static FBConfig **s_fbConfigs; + static int s_numConfigs; + static const int s_numConfigAttribs; + static const GLuint s_configAttribs[]; + +private: + EGLConfig m_eglConfig; + GLint *m_attribValues; +}; + +#endif diff --git a/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.cpp b/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.cpp new file mode 100644 index 0000000..b7599ce --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.cpp @@ -0,0 +1,868 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "FrameBuffer.h" +#include "NativeSubWindow.h" +#include "FBConfig.h" +#include "EGLDispatch.h" +#include "GLDispatch.h" +#include "GL2Dispatch.h" +#include "ThreadInfo.h" +#include <stdio.h> +#include "TimeUtils.h" + +FrameBuffer *FrameBuffer::s_theFrameBuffer = NULL; +HandleType FrameBuffer::s_nextHandle = 0; + +#ifdef WITH_GLES2 +static const char *getGLES2ExtensionString(EGLDisplay p_dpy) +{ + EGLConfig config; + EGLSurface surface; + + GLint configAttribs[] = { + EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_NONE + }; + + int n; + if (!s_egl.eglChooseConfig(p_dpy, configAttribs, + &config, 1, &n)) { + return NULL; + } + + EGLint pbufAttribs[] = { + EGL_WIDTH, 1, + EGL_HEIGHT, 1, + EGL_NONE + }; + + surface = s_egl.eglCreatePbufferSurface(p_dpy, config, pbufAttribs); + if (surface == EGL_NO_SURFACE) { + return NULL; + } + + GLint gl2ContextAttribs[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; + + EGLContext ctx = s_egl.eglCreateContext(p_dpy, config, + EGL_NO_CONTEXT, + gl2ContextAttribs); + if (ctx == EGL_NO_CONTEXT) { + s_egl.eglDestroySurface(p_dpy, surface); + return NULL; + } + + if (!s_egl.eglMakeCurrent(p_dpy, surface, surface, ctx)) { + s_egl.eglDestroySurface(p_dpy, surface); + s_egl.eglDestroyContext(p_dpy, ctx); + return NULL; + } + + const char *extString = (const char *)s_gl2.glGetString(GL_EXTENSIONS); + if (!extString) { + extString = ""; + } + + s_egl.eglMakeCurrent(p_dpy, NULL, NULL, NULL); + s_egl.eglDestroyContext(p_dpy, ctx); + s_egl.eglDestroySurface(p_dpy, surface); + + return extString; +} +#endif + +void FrameBuffer::finalize(){ + if(s_theFrameBuffer){ + s_theFrameBuffer->removeSubWindow(); + s_theFrameBuffer->m_colorbuffers.clear(); + s_theFrameBuffer->m_windows.clear(); + s_theFrameBuffer->m_contexts.clear(); + s_egl.eglMakeCurrent(s_theFrameBuffer->m_eglDisplay, NULL, NULL, NULL); + s_egl.eglDestroyContext(s_theFrameBuffer->m_eglDisplay,s_theFrameBuffer->m_eglContext); + s_egl.eglDestroyContext(s_theFrameBuffer->m_eglDisplay,s_theFrameBuffer->m_pbufContext); + s_egl.eglDestroySurface(s_theFrameBuffer->m_eglDisplay,s_theFrameBuffer->m_pbufSurface); + s_theFrameBuffer = NULL; + } +} + +bool FrameBuffer::initialize(int width, int height, OnPostFn onPost, void* onPostContext) +{ + if (s_theFrameBuffer != NULL) { + return true; + } + + // + // allocate space for the FrameBuffer object + // + FrameBuffer *fb = new FrameBuffer(width, height, onPost, onPostContext); + if (!fb) { + ERR("Failed to create fb\n"); + return false; + } + +#ifdef WITH_GLES2 + // + // Try to load GLES2 Plugin, not mandatory + // + if (getenv("ANDROID_NO_GLES2")) { + fb->m_caps.hasGL2 = false; + } + else { + fb->m_caps.hasGL2 = s_gl2_enabled; + } +#else + fb->m_caps.hasGL2 = false; +#endif + + // + // Initialize backend EGL display + // + fb->m_eglDisplay = s_egl.eglGetDisplay(EGL_DEFAULT_DISPLAY); + if (fb->m_eglDisplay == EGL_NO_DISPLAY) { + ERR("Failed to Initialize backend EGL display\n"); + delete fb; + return false; + } + + if (!s_egl.eglInitialize(fb->m_eglDisplay, &fb->m_caps.eglMajor, &fb->m_caps.eglMinor)) { + ERR("Failed to eglInitialize\n"); + delete fb; + return false; + } + + DBG("egl: %d %d\n", fb->m_caps.eglMajor, fb->m_caps.eglMinor); + s_egl.eglBindAPI(EGL_OPENGL_ES_API); + + // + // if GLES2 plugin has loaded - try to make GLES2 context and + // get GLES2 extension string + // + const char *gl2Extensions = NULL; +#ifdef WITH_GLES2 + if (fb->m_caps.hasGL2) { + gl2Extensions = getGLES2ExtensionString(fb->m_eglDisplay); + if (!gl2Extensions) { + // Could not create GLES2 context - drop GL2 capability + fb->m_caps.hasGL2 = false; + } + } +#endif + + // + // Create EGL context for framebuffer post rendering. + // +#if 0 + GLint configAttribs[] = { + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT, + EGL_NONE + }; +#else + GLint configAttribs[] = { + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, + EGL_NONE + }; +#endif + + int n; + if (!s_egl.eglChooseConfig(fb->m_eglDisplay, configAttribs, + &fb->m_eglConfig, 1, &n)) { + ERR("Failed on eglChooseConfig\n"); + delete fb; + return false; + } + + GLint glContextAttribs[] = { + EGL_CONTEXT_CLIENT_VERSION, 1, + EGL_NONE + }; + + fb->m_eglContext = s_egl.eglCreateContext(fb->m_eglDisplay, fb->m_eglConfig, + EGL_NO_CONTEXT, + glContextAttribs); + if (fb->m_eglContext == EGL_NO_CONTEXT) { + printf("Failed to create Context 0x%x\n", s_egl.eglGetError()); + delete fb; + return false; + } + + // + // Create another context which shares with the eglContext to be used + // when we bind the pbuffer. That prevent switching drawable binding + // back and forth on framebuffer context. + // The main purpose of it is to solve a "blanking" behaviour we see on + // on Mac platform when switching binded drawable for a context however + // it is more efficient on other platforms as well. + // + fb->m_pbufContext = s_egl.eglCreateContext(fb->m_eglDisplay, fb->m_eglConfig, + fb->m_eglContext, + glContextAttribs); + if (fb->m_pbufContext == EGL_NO_CONTEXT) { + printf("Failed to create Pbuffer Context 0x%x\n", s_egl.eglGetError()); + delete fb; + return false; + } + + // + // create a 1x1 pbuffer surface which will be used for binding + // the FB context. + // The FB output will go to a subwindow, if one exist. + // + EGLint pbufAttribs[] = { + EGL_WIDTH, 1, + EGL_HEIGHT, 1, + EGL_NONE + }; + + fb->m_pbufSurface = s_egl.eglCreatePbufferSurface(fb->m_eglDisplay, + fb->m_eglConfig, + pbufAttribs); + if (fb->m_pbufSurface == EGL_NO_SURFACE) { + printf("Failed to create pbuf surface for FB 0x%x\n", s_egl.eglGetError()); + delete fb; + return false; + } + + // Make the context current + if (!fb->bind_locked()) { + ERR("Failed to make current\n"); + delete fb; + return false; + } + + // + // Initilize framebuffer capabilities + // + const char *glExtensions = (const char *)s_gl.glGetString(GL_EXTENSIONS); + bool has_gl_oes_image = false; + if (glExtensions) { + has_gl_oes_image = strstr(glExtensions, "GL_OES_EGL_image") != NULL; + } + + if (fb->m_caps.hasGL2 && has_gl_oes_image) { + has_gl_oes_image &= (strstr(gl2Extensions, "GL_OES_EGL_image") != NULL); + } + + const char *eglExtensions = s_egl.eglQueryString(fb->m_eglDisplay, + EGL_EXTENSIONS); + + if (eglExtensions && has_gl_oes_image) { + fb->m_caps.has_eglimage_texture_2d = + strstr(eglExtensions, "EGL_KHR_gl_texture_2D_image") != NULL; + fb->m_caps.has_eglimage_renderbuffer = + strstr(eglExtensions, "EGL_KHR_gl_renderbuffer_image") != NULL; + } + else { + fb->m_caps.has_eglimage_texture_2d = false; + fb->m_caps.has_eglimage_renderbuffer = false; + } + + // + // Fail initialization if not all of the following extensions + // exist: + // EGL_KHR_gl_texture_2d_image + // GL_OES_EGL_IMAGE (by both GLES implementations [1 and 2]) + // + if (!fb->m_caps.has_eglimage_texture_2d) { + ERR("Failed: Missing egl_image related extension(s)\n"); + delete fb; + return false; + } + + // + // Initialize set of configs + // + InitConfigStatus configStatus = FBConfig::initConfigList(fb); + if (configStatus == INIT_CONFIG_FAILED) { + ERR("Failed: Initialize set of configs\n"); + delete fb; + return false; + } + + // + // Check that we have config for each GLES and GLES2 + // + int nConfigs = FBConfig::getNumConfigs(); + int nGLConfigs = 0; + int nGL2Configs = 0; + for (int i=0; i<nConfigs; i++) { + GLint rtype = FBConfig::get(i)->getRenderableType(); + if (0 != (rtype & EGL_OPENGL_ES_BIT)) { + nGLConfigs++; + } + if (0 != (rtype & EGL_OPENGL_ES2_BIT)) { + nGL2Configs++; + } + } + + // + // Fail initialization if no GLES configs exist + // + if (nGLConfigs == 0) { + delete fb; + return false; + } + + // + // If no GLES2 configs exist - not GLES2 capability + // + if (nGL2Configs == 0) { + fb->m_caps.hasGL2 = false; + } + + // + // Initialize some GL state in the pbuffer context + // + fb->initGLState(); + + // + // Allocate space for the onPost framebuffer image + // + if (onPost) { + fb->m_fbImage = (unsigned char*)malloc(4 * width * height); + if (!fb->m_fbImage) { + delete fb; + return false; + } + } + + // release the FB context + fb->unbind_locked(); + + // + // Keep the singleton framebuffer pointer + // + s_theFrameBuffer = fb; + return true; +} + +FrameBuffer::FrameBuffer(int p_width, int p_height, + OnPostFn onPost, void* onPostContext) : + m_width(p_width), + m_height(p_height), + m_eglDisplay(EGL_NO_DISPLAY), + m_eglSurface(EGL_NO_SURFACE), + m_eglContext(EGL_NO_CONTEXT), + m_pbufContext(EGL_NO_CONTEXT), + m_prevContext(EGL_NO_CONTEXT), + m_prevReadSurf(EGL_NO_SURFACE), + m_prevDrawSurf(EGL_NO_SURFACE), + m_subWin(NULL), + m_subWinDisplay(NULL), + m_lastPostedColorBuffer(0), + m_zRot(0.0f), + m_eglContextInitialized(false), + m_statsNumFrames(0), + m_statsStartTime(0LL), + m_onPost(onPost), + m_onPostContext(onPostContext), + m_fbImage(NULL) +{ + m_fpsStats = getenv("SHOW_FPS_STATS") != NULL; +} + +FrameBuffer::~FrameBuffer() +{ + free(m_fbImage); +} + +bool FrameBuffer::setupSubWindow(FBNativeWindowType p_window, + int p_x, int p_y, + int p_width, int p_height, float zRot) +{ + bool success = false; + + if (s_theFrameBuffer) { + s_theFrameBuffer->m_lock.lock(); + FrameBuffer *fb = s_theFrameBuffer; + if (!fb->m_subWin) { + + // create native subwindow for FB display output + fb->m_subWin = createSubWindow(p_window, + &fb->m_subWinDisplay, + p_x,p_y,p_width,p_height); + if (fb->m_subWin) { + fb->m_nativeWindow = p_window; + + // create EGLSurface from the generated subwindow + fb->m_eglSurface = s_egl.eglCreateWindowSurface(fb->m_eglDisplay, + fb->m_eglConfig, + fb->m_subWin, + NULL); + + if (fb->m_eglSurface == EGL_NO_SURFACE) { + ERR("Failed to create surface\n"); + destroySubWindow(fb->m_subWinDisplay, fb->m_subWin); + fb->m_subWin = NULL; + } + else if (fb->bindSubwin_locked()) { + // Subwin creation was successfull, + // update viewport and z rotation and draw + // the last posted color buffer. + s_gl.glViewport(0, 0, p_width, p_height); + fb->m_zRot = zRot; + fb->post( fb->m_lastPostedColorBuffer, false ); + fb->unbind_locked(); + success = true; + } + } + } + s_theFrameBuffer->m_lock.unlock(); + } + + return success; +} + +bool FrameBuffer::removeSubWindow() +{ + bool removed = false; + if (s_theFrameBuffer) { + s_theFrameBuffer->m_lock.lock(); + if (s_theFrameBuffer->m_subWin) { + s_egl.eglMakeCurrent(s_theFrameBuffer->m_eglDisplay, NULL, NULL, NULL); + s_egl.eglDestroySurface(s_theFrameBuffer->m_eglDisplay, + s_theFrameBuffer->m_eglSurface); + destroySubWindow(s_theFrameBuffer->m_subWinDisplay, + s_theFrameBuffer->m_subWin); + + s_theFrameBuffer->m_eglSurface = EGL_NO_SURFACE; + s_theFrameBuffer->m_subWin = NULL; + removed = true; + } + s_theFrameBuffer->m_lock.unlock(); + } + return removed; +} + +HandleType FrameBuffer::genHandle() +{ + HandleType id; + do { + id = ++s_nextHandle; + } while( id == 0 || + m_contexts.find(id) != m_contexts.end() || + m_windows.find(id) != m_windows.end() ); + + return id; +} + +HandleType FrameBuffer::createColorBuffer(int p_width, int p_height, + GLenum p_internalFormat) +{ + android::Mutex::Autolock mutex(m_lock); + HandleType ret = 0; + + ColorBufferPtr cb( ColorBuffer::create(p_width, p_height, p_internalFormat) ); + if (cb.Ptr() != NULL) { + ret = genHandle(); + m_colorbuffers[ret].cb = cb; + m_colorbuffers[ret].refcount = 1; + } + return ret; +} + +HandleType FrameBuffer::createRenderContext(int p_config, HandleType p_share, + bool p_isGL2) +{ + android::Mutex::Autolock mutex(m_lock); + HandleType ret = 0; + + RenderContextPtr share(NULL); + if (p_share != 0) { + RenderContextMap::iterator s( m_contexts.find(p_share) ); + if (s == m_contexts.end()) { + return 0; + } + share = (*s).second; + } + + RenderContextPtr rctx( RenderContext::create(p_config, share, p_isGL2) ); + if (rctx.Ptr() != NULL) { + ret = genHandle(); + m_contexts[ret] = rctx; + } + return ret; +} + +HandleType FrameBuffer::createWindowSurface(int p_config, int p_width, int p_height) +{ + android::Mutex::Autolock mutex(m_lock); + + HandleType ret = 0; + WindowSurfacePtr win( WindowSurface::create(p_config, p_width, p_height) ); + if (win.Ptr() != NULL) { + ret = genHandle(); + m_windows[ret] = win; + } + + return ret; +} + +void FrameBuffer::DestroyRenderContext(HandleType p_context) +{ + android::Mutex::Autolock mutex(m_lock); + m_contexts.erase(p_context); +} + +void FrameBuffer::DestroyWindowSurface(HandleType p_surface) +{ + android::Mutex::Autolock mutex(m_lock); + m_windows.erase(p_surface); +} + +void FrameBuffer::openColorBuffer(HandleType p_colorbuffer) +{ + android::Mutex::Autolock mutex(m_lock); + ColorBufferMap::iterator c(m_colorbuffers.find(p_colorbuffer)); + if (c == m_colorbuffers.end()) { + // bad colorbuffer handle + return; + } + (*c).second.refcount++; +} + +void FrameBuffer::closeColorBuffer(HandleType p_colorbuffer) +{ + android::Mutex::Autolock mutex(m_lock); + ColorBufferMap::iterator c(m_colorbuffers.find(p_colorbuffer)); + if (c == m_colorbuffers.end()) { + // bad colorbuffer handle + return; + } + if (--(*c).second.refcount == 0) { + m_colorbuffers.erase(c); + } +} + +bool FrameBuffer::flushWindowSurfaceColorBuffer(HandleType p_surface) +{ + android::Mutex::Autolock mutex(m_lock); + + WindowSurfaceMap::iterator w( m_windows.find(p_surface) ); + if (w == m_windows.end()) { + // bad surface handle + return false; + } + + (*w).second->flushColorBuffer(); + + return true; +} + +bool FrameBuffer::setWindowSurfaceColorBuffer(HandleType p_surface, + HandleType p_colorbuffer) +{ + android::Mutex::Autolock mutex(m_lock); + + WindowSurfaceMap::iterator w( m_windows.find(p_surface) ); + if (w == m_windows.end()) { + // bad surface handle + return false; + } + + ColorBufferMap::iterator c( m_colorbuffers.find(p_colorbuffer) ); + if (c == m_colorbuffers.end()) { + // bad colorbuffer handle + return false; + } + + (*w).second->setColorBuffer( (*c).second.cb ); + + return true; +} + +bool FrameBuffer::updateColorBuffer(HandleType p_colorbuffer, + int x, int y, int width, int height, + GLenum format, GLenum type, void *pixels) +{ + android::Mutex::Autolock mutex(m_lock); + + ColorBufferMap::iterator c( m_colorbuffers.find(p_colorbuffer) ); + if (c == m_colorbuffers.end()) { + // bad colorbuffer handle + return false; + } + + (*c).second.cb->subUpdate(x, y, width, height, format, type, pixels); + + return true; +} + +bool FrameBuffer::bindColorBufferToTexture(HandleType p_colorbuffer) +{ + android::Mutex::Autolock mutex(m_lock); + + ColorBufferMap::iterator c( m_colorbuffers.find(p_colorbuffer) ); + if (c == m_colorbuffers.end()) { + // bad colorbuffer handle + return false; + } + + return (*c).second.cb->bindToTexture(); +} + +bool FrameBuffer::bindColorBufferToRenderbuffer(HandleType p_colorbuffer) +{ + android::Mutex::Autolock mutex(m_lock); + + ColorBufferMap::iterator c( m_colorbuffers.find(p_colorbuffer) ); + if (c == m_colorbuffers.end()) { + // bad colorbuffer handle + return false; + } + + return (*c).second.cb->bindToRenderbuffer(); +} + +bool FrameBuffer::bindContext(HandleType p_context, + HandleType p_drawSurface, + HandleType p_readSurface) +{ + android::Mutex::Autolock mutex(m_lock); + + WindowSurfacePtr draw(NULL), read(NULL); + RenderContextPtr ctx(NULL); + + // + // if this is not an unbind operation - make sure all handles are good + // + if (p_context || p_drawSurface || p_readSurface) { + RenderContextMap::iterator r( m_contexts.find(p_context) ); + if (r == m_contexts.end()) { + // bad context handle + return false; + } + + ctx = (*r).second; + WindowSurfaceMap::iterator w( m_windows.find(p_drawSurface) ); + if (w == m_windows.end()) { + // bad surface handle + return false; + } + draw = (*w).second; + + if (p_readSurface != p_drawSurface) { + WindowSurfaceMap::iterator w( m_windows.find(p_readSurface) ); + if (w == m_windows.end()) { + // bad surface handle + return false; + } + read = (*w).second; + } + else { + read = draw; + } + } + + if (!s_egl.eglMakeCurrent(m_eglDisplay, + draw ? draw->getEGLSurface() : EGL_NO_SURFACE, + read ? read->getEGLSurface() : EGL_NO_SURFACE, + ctx ? ctx->getEGLContext() : EGL_NO_CONTEXT)) { + // MakeCurrent failed + return false; + } + + // + // Bind the surface(s) to the context + // + RenderThreadInfo *tinfo = getRenderThreadInfo(); + if (draw.Ptr() == NULL && read.Ptr() == NULL) { + // if this is an unbind operation - make sure the current bound + // surfaces get unbound from the context. + draw = tinfo->currDrawSurf; + read = tinfo->currReadSurf; + } + + if (draw.Ptr() != NULL && read.Ptr() != NULL) { + if (p_readSurface != p_drawSurface) { + draw->bind( ctx, SURFACE_BIND_DRAW ); + read->bind( ctx, SURFACE_BIND_READ ); + } + else { + draw->bind( ctx, SURFACE_BIND_READDRAW ); + } + } + + // + // update thread info with current bound context + // + tinfo->currContext = ctx; + tinfo->currDrawSurf = draw; + tinfo->currReadSurf = read; + if (ctx) { + if (ctx->isGL2()) tinfo->m_gl2Dec.setContextData(&ctx->decoderContextData()); + else tinfo->m_glDec.setContextData(&ctx->decoderContextData()); + } + else { + tinfo->m_glDec.setContextData(NULL); + tinfo->m_gl2Dec.setContextData(NULL); + } + return true; +} + +// +// The framebuffer lock should be held when calling this function ! +// +bool FrameBuffer::bind_locked() +{ + EGLContext prevContext = s_egl.eglGetCurrentContext(); + EGLSurface prevReadSurf = s_egl.eglGetCurrentSurface(EGL_READ); + EGLSurface prevDrawSurf = s_egl.eglGetCurrentSurface(EGL_DRAW); + + if (!s_egl.eglMakeCurrent(m_eglDisplay, m_pbufSurface, + m_pbufSurface, m_pbufContext)) { + ERR("eglMakeCurrent failed\n"); + return false; + } + + m_prevContext = prevContext; + m_prevReadSurf = prevReadSurf; + m_prevDrawSurf = prevDrawSurf; + return true; +} + +bool FrameBuffer::bindSubwin_locked() +{ + EGLContext prevContext = s_egl.eglGetCurrentContext(); + EGLSurface prevReadSurf = s_egl.eglGetCurrentSurface(EGL_READ); + EGLSurface prevDrawSurf = s_egl.eglGetCurrentSurface(EGL_DRAW); + + if (!s_egl.eglMakeCurrent(m_eglDisplay, m_eglSurface, + m_eglSurface, m_eglContext)) { + ERR("eglMakeCurrent failed\n"); + return false; + } + + // + // initialize GL state in eglContext if not yet initilaized + // + if (!m_eglContextInitialized) { + initGLState(); + m_eglContextInitialized = true; + } + + m_prevContext = prevContext; + m_prevReadSurf = prevReadSurf; + m_prevDrawSurf = prevDrawSurf; + return true; +} + +bool FrameBuffer::unbind_locked() +{ + if (!s_egl.eglMakeCurrent(m_eglDisplay, m_prevDrawSurf, + m_prevReadSurf, m_prevContext)) { + return false; + } + + m_prevContext = EGL_NO_CONTEXT; + m_prevReadSurf = EGL_NO_SURFACE; + m_prevDrawSurf = EGL_NO_SURFACE; + return true; +} + +bool FrameBuffer::post(HandleType p_colorbuffer, bool needLock) +{ + if (needLock) m_lock.lock(); + bool ret = false; + + ColorBufferMap::iterator c( m_colorbuffers.find(p_colorbuffer) ); + if (c != m_colorbuffers.end()) { + + m_lastPostedColorBuffer = p_colorbuffer; + if (!m_subWin) { + // no subwindow created for the FB output + // cannot post the colorbuffer + if (needLock) m_lock.unlock(); + return ret; + } + + + // bind the subwindow eglSurface + if (!bindSubwin_locked()) { + ERR("FrameBuffer::post eglMakeCurrent failed\n"); + if (needLock) m_lock.unlock(); + return false; + } + + // + // render the color buffer to the window + // + s_gl.glPushMatrix(); + s_gl.glRotatef(m_zRot, 0.0f, 0.0f, 1.0f); + if (m_zRot != 0.0f) { + s_gl.glClear(GL_COLOR_BUFFER_BIT); + } + ret = (*c).second.cb->post(); + s_gl.glPopMatrix(); + + if (ret) { + // + // Send framebuffer (without FPS overlay) to callback + // + if (m_onPost) { + s_gl.glReadPixels(0, 0, m_width, m_height, + GL_RGBA, GL_UNSIGNED_BYTE, m_fbImage); + m_onPost(m_onPostContext, m_width, m_height, -1, + GL_RGBA, GL_UNSIGNED_BYTE, m_fbImage); + } + + // + // output FPS statistics + // + if (m_fpsStats) { + long long currTime = GetCurrentTimeMS(); + m_statsNumFrames++; + if (currTime - m_statsStartTime >= 1000) { + float dt = (float)(currTime - m_statsStartTime) / 1000.0f; + printf("FPS: %5.3f\n", (float)m_statsNumFrames / dt); + m_statsStartTime = currTime; + m_statsNumFrames = 0; + } + } + + s_egl.eglSwapBuffers(m_eglDisplay, m_eglSurface); + } + + // restore previous binding + unbind_locked(); + } + + if (needLock) m_lock.unlock(); + return ret; +} + +bool FrameBuffer::repost() +{ + if (m_lastPostedColorBuffer) { + return post( m_lastPostedColorBuffer ); + } + return false; +} + +void FrameBuffer::initGLState() +{ + s_gl.glMatrixMode(GL_PROJECTION); + s_gl.glLoadIdentity(); + s_gl.glOrthof(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); + s_gl.glMatrixMode(GL_MODELVIEW); + s_gl.glLoadIdentity(); +} diff --git a/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.h b/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.h new file mode 100644 index 0000000..343f384 --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.h @@ -0,0 +1,137 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _LIBRENDER_FRAMEBUFFER_H +#define _LIBRENDER_FRAMEBUFFER_H + +#include "libOpenglRender/render_api.h" +#include "ColorBuffer.h" +#include "RenderContext.h" +#include "WindowSurface.h" +#include <utils/threads.h> +#include <map> +#include <EGL/egl.h> +#include <stdint.h> + +typedef uint32_t HandleType; +struct ColorBufferRef { + ColorBufferPtr cb; + uint32_t refcount; // number of client-side references +}; +typedef std::map<HandleType, RenderContextPtr> RenderContextMap; +typedef std::map<HandleType, WindowSurfacePtr> WindowSurfaceMap; +typedef std::map<HandleType, ColorBufferRef> ColorBufferMap; + +struct FrameBufferCaps +{ + bool hasGL2; + bool has_eglimage_texture_2d; + bool has_eglimage_renderbuffer; + EGLint eglMajor; + EGLint eglMinor; +}; + +class FrameBuffer +{ +public: + static bool initialize(int width, int height, OnPostFn onPost, void* onPostContext); + static bool setupSubWindow(FBNativeWindowType p_window, + int x, int y, + int width, int height, float zRot); + static bool removeSubWindow(); + static void finalize(); + static FrameBuffer *getFB() { return s_theFrameBuffer; } + + const FrameBufferCaps &getCaps() const { return m_caps; } + + int getWidth() const { return m_width; } + int getHeight() const { return m_height; } + + HandleType createRenderContext(int p_config, HandleType p_share, bool p_isGL2 = false); + HandleType createWindowSurface(int p_config, int p_width, int p_height); + HandleType createColorBuffer(int p_width, int p_height, GLenum p_internalFormat); + void DestroyRenderContext(HandleType p_context); + void DestroyWindowSurface(HandleType p_surface); + void openColorBuffer(HandleType p_colorbuffer); + void closeColorBuffer(HandleType p_colorbuffer); + + bool bindContext(HandleType p_context, HandleType p_drawSurface, HandleType p_readSurface); + bool setWindowSurfaceColorBuffer(HandleType p_surface, HandleType p_colorbuffer); + bool flushWindowSurfaceColorBuffer(HandleType p_surface); + bool bindColorBufferToTexture(HandleType p_colorbuffer); + bool bindColorBufferToRenderbuffer(HandleType p_colorbuffer); + bool updateColorBuffer(HandleType p_colorbuffer, + int x, int y, int width, int height, + GLenum format, GLenum type, void *pixels); + + bool post(HandleType p_colorbuffer, bool needLock = true); + bool repost(); + + EGLDisplay getDisplay() const { return m_eglDisplay; } + EGLNativeWindowType getSubWindow() const { return m_subWin; } + bool bind_locked(); + bool unbind_locked(); + + void setDisplayRotation(float zRot) { + m_zRot = zRot; + repost(); + } + +private: + FrameBuffer(int p_width, int p_height, OnPostFn onPost, void* onPostContext); + ~FrameBuffer(); + HandleType genHandle(); + bool bindSubwin_locked(); + void initGLState(); + +private: + static FrameBuffer *s_theFrameBuffer; + static HandleType s_nextHandle; + int m_x; + int m_y; + int m_width; + int m_height; + android::Mutex m_lock; + FBNativeWindowType m_nativeWindow; + FrameBufferCaps m_caps; + EGLDisplay m_eglDisplay; + RenderContextMap m_contexts; + WindowSurfaceMap m_windows; + ColorBufferMap m_colorbuffers; + + EGLSurface m_eglSurface; + EGLContext m_eglContext; + EGLSurface m_pbufSurface; + EGLContext m_pbufContext; + + EGLContext m_prevContext; + EGLSurface m_prevReadSurf; + EGLSurface m_prevDrawSurf; + EGLNativeWindowType m_subWin; + EGLNativeDisplayType m_subWinDisplay; + EGLConfig m_eglConfig; + HandleType m_lastPostedColorBuffer; + float m_zRot; + bool m_eglContextInitialized; + + int m_statsNumFrames; + long long m_statsStartTime; + bool m_fpsStats; + + OnPostFn m_onPost; + void* m_onPostContext; + unsigned char* m_fbImage; +}; +#endif diff --git a/emulator/opengl/host/libs/libOpenglRender/GL2Dispatch.cpp b/emulator/opengl/host/libs/libOpenglRender/GL2Dispatch.cpp new file mode 100644 index 0000000..cda205f --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/GL2Dispatch.cpp @@ -0,0 +1,64 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifdef WITH_GLES2 +#include "GL2Dispatch.h" +#include <stdio.h> +#include <stdlib.h> +#include "osDynLibrary.h" + +gl2_decoder_context_t s_gl2; +int s_gl2_enabled; + +static osUtils::dynLibrary *s_gles2_lib = NULL; + +#define DEFAULT_GLES_V2_LIB EMUGL_LIBNAME("GLES_V2_translator") + +// +// This function is called only once during initialiation before +// any thread has been created - hence it should NOT be thread safe. +// +bool init_gl2_dispatch() +{ + const char *libName = getenv("ANDROID_GLESv2_LIB"); + if (!libName) libName = DEFAULT_GLES_V2_LIB; + + // + // Load the GLES library + // + s_gles2_lib = osUtils::dynLibrary::open(libName); + if (!s_gles2_lib) return false; + + // + // init the GLES dispatch table + // + s_gl2.initDispatchByName( gl2_dispatch_get_proc_func, NULL ); + s_gl2_enabled = true; + return true; +} + +// +// This function is called only during initialiation before +// any thread has been created - hence it should NOT be thread safe. +// +void *gl2_dispatch_get_proc_func(const char *name, void *userData) +{ + if (!s_gles2_lib) { + return NULL; + } + return (void *)s_gles2_lib->findSymbol(name); +} + +#endif diff --git a/emulator/opengl/host/libs/libOpenglRender/GL2Dispatch.h b/emulator/opengl/host/libs/libOpenglRender/GL2Dispatch.h new file mode 100644 index 0000000..89f3651 --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/GL2Dispatch.h @@ -0,0 +1,30 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _GLES2_DISPATCH_H +#define _GLES2_DISPATCH_H + +#ifdef WITH_GLES2 + +#include "gl2_dec.h" + +bool init_gl2_dispatch(); +void *gl2_dispatch_get_proc_func(const char *name, void *userData); + +extern gl2_decoder_context_t s_gl2; +extern int s_gl2_enabled; + +#endif +#endif diff --git a/emulator/opengl/host/libs/libOpenglRender/GLDispatch.cpp b/emulator/opengl/host/libs/libOpenglRender/GLDispatch.cpp new file mode 100644 index 0000000..089512a --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/GLDispatch.cpp @@ -0,0 +1,325 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "GLDispatch.h" +#include <stdio.h> +#include <stdlib.h> +#include "osDynLibrary.h" + +GLDispatch s_gl; + +static osUtils::dynLibrary *s_gles_lib = NULL; + +// +// This function is called only once during initialiation before +// any thread has been created - hence it should NOT be thread safe. +// + +#define DEFAULT_GLES_CM_LIB EMUGL_LIBNAME("GLES_CM_translator") + +bool init_gl_dispatch() +{ + const char *libName = getenv("ANDROID_GLESv1_LIB"); + if (!libName) libName = DEFAULT_GLES_CM_LIB; + + s_gles_lib = osUtils::dynLibrary::open(libName); + if (!s_gles_lib) return false; + + s_gl.glAlphaFunc = (glAlphaFunc_t) s_gles_lib->findSymbol("glAlphaFunc"); + s_gl.glClearColor = (glClearColor_t) s_gles_lib->findSymbol("glClearColor"); + s_gl.glClearDepthf = (glClearDepthf_t) s_gles_lib->findSymbol("glClearDepthf"); + s_gl.glClipPlanef = (glClipPlanef_t) s_gles_lib->findSymbol("glClipPlanef"); + s_gl.glColor4f = (glColor4f_t) s_gles_lib->findSymbol("glColor4f"); + s_gl.glDepthRangef = (glDepthRangef_t) s_gles_lib->findSymbol("glDepthRangef"); + s_gl.glFogf = (glFogf_t) s_gles_lib->findSymbol("glFogf"); + s_gl.glFogfv = (glFogfv_t) s_gles_lib->findSymbol("glFogfv"); + s_gl.glFrustumf = (glFrustumf_t) s_gles_lib->findSymbol("glFrustumf"); + s_gl.glGetClipPlanef = (glGetClipPlanef_t) s_gles_lib->findSymbol("glGetClipPlanef"); + s_gl.glGetFloatv = (glGetFloatv_t) s_gles_lib->findSymbol("glGetFloatv"); + s_gl.glGetLightfv = (glGetLightfv_t) s_gles_lib->findSymbol("glGetLightfv"); + s_gl.glGetMaterialfv = (glGetMaterialfv_t) s_gles_lib->findSymbol("glGetMaterialfv"); + s_gl.glGetTexEnvfv = (glGetTexEnvfv_t) s_gles_lib->findSymbol("glGetTexEnvfv"); + s_gl.glGetTexParameterfv = (glGetTexParameterfv_t) s_gles_lib->findSymbol("glGetTexParameterfv"); + s_gl.glLightModelf = (glLightModelf_t) s_gles_lib->findSymbol("glLightModelf"); + s_gl.glLightModelfv = (glLightModelfv_t) s_gles_lib->findSymbol("glLightModelfv"); + s_gl.glLightf = (glLightf_t) s_gles_lib->findSymbol("glLightf"); + s_gl.glLightfv = (glLightfv_t) s_gles_lib->findSymbol("glLightfv"); + s_gl.glLineWidth = (glLineWidth_t) s_gles_lib->findSymbol("glLineWidth"); + s_gl.glLoadMatrixf = (glLoadMatrixf_t) s_gles_lib->findSymbol("glLoadMatrixf"); + s_gl.glMaterialf = (glMaterialf_t) s_gles_lib->findSymbol("glMaterialf"); + s_gl.glMaterialfv = (glMaterialfv_t) s_gles_lib->findSymbol("glMaterialfv"); + s_gl.glMultMatrixf = (glMultMatrixf_t) s_gles_lib->findSymbol("glMultMatrixf"); + s_gl.glMultiTexCoord4f = (glMultiTexCoord4f_t) s_gles_lib->findSymbol("glMultiTexCoord4f"); + s_gl.glNormal3f = (glNormal3f_t) s_gles_lib->findSymbol("glNormal3f"); + s_gl.glOrthof = (glOrthof_t) s_gles_lib->findSymbol("glOrthof"); + s_gl.glPointParameterf = (glPointParameterf_t) s_gles_lib->findSymbol("glPointParameterf"); + s_gl.glPointParameterfv = (glPointParameterfv_t) s_gles_lib->findSymbol("glPointParameterfv"); + s_gl.glPointSize = (glPointSize_t) s_gles_lib->findSymbol("glPointSize"); + s_gl.glPolygonOffset = (glPolygonOffset_t) s_gles_lib->findSymbol("glPolygonOffset"); + s_gl.glRotatef = (glRotatef_t) s_gles_lib->findSymbol("glRotatef"); + s_gl.glScalef = (glScalef_t) s_gles_lib->findSymbol("glScalef"); + s_gl.glTexEnvf = (glTexEnvf_t) s_gles_lib->findSymbol("glTexEnvf"); + s_gl.glTexEnvfv = (glTexEnvfv_t) s_gles_lib->findSymbol("glTexEnvfv"); + s_gl.glTexParameterf = (glTexParameterf_t) s_gles_lib->findSymbol("glTexParameterf"); + s_gl.glTexParameterfv = (glTexParameterfv_t) s_gles_lib->findSymbol("glTexParameterfv"); + s_gl.glTranslatef = (glTranslatef_t) s_gles_lib->findSymbol("glTranslatef"); + s_gl.glActiveTexture = (glActiveTexture_t) s_gles_lib->findSymbol("glActiveTexture"); + s_gl.glAlphaFuncx = (glAlphaFuncx_t) s_gles_lib->findSymbol("glAlphaFuncx"); + s_gl.glBindBuffer = (glBindBuffer_t) s_gles_lib->findSymbol("glBindBuffer"); + s_gl.glBindTexture = (glBindTexture_t) s_gles_lib->findSymbol("glBindTexture"); + s_gl.glBlendFunc = (glBlendFunc_t) s_gles_lib->findSymbol("glBlendFunc"); + s_gl.glBufferData = (glBufferData_t) s_gles_lib->findSymbol("glBufferData"); + s_gl.glBufferSubData = (glBufferSubData_t) s_gles_lib->findSymbol("glBufferSubData"); + s_gl.glClear = (glClear_t) s_gles_lib->findSymbol("glClear"); + s_gl.glClearColorx = (glClearColorx_t) s_gles_lib->findSymbol("glClearColorx"); + s_gl.glClearDepthx = (glClearDepthx_t) s_gles_lib->findSymbol("glClearDepthx"); + s_gl.glClearStencil = (glClearStencil_t) s_gles_lib->findSymbol("glClearStencil"); + s_gl.glClientActiveTexture = (glClientActiveTexture_t) s_gles_lib->findSymbol("glClientActiveTexture"); + s_gl.glClipPlanex = (glClipPlanex_t) s_gles_lib->findSymbol("glClipPlanex"); + s_gl.glColor4ub = (glColor4ub_t) s_gles_lib->findSymbol("glColor4ub"); + s_gl.glColor4x = (glColor4x_t) s_gles_lib->findSymbol("glColor4x"); + s_gl.glColorMask = (glColorMask_t) s_gles_lib->findSymbol("glColorMask"); + s_gl.glColorPointer = (glColorPointer_t) s_gles_lib->findSymbol("glColorPointer"); + s_gl.glCompressedTexImage2D = (glCompressedTexImage2D_t) s_gles_lib->findSymbol("glCompressedTexImage2D"); + s_gl.glCompressedTexSubImage2D = (glCompressedTexSubImage2D_t) s_gles_lib->findSymbol("glCompressedTexSubImage2D"); + s_gl.glCopyTexImage2D = (glCopyTexImage2D_t) s_gles_lib->findSymbol("glCopyTexImage2D"); + s_gl.glCopyTexSubImage2D = (glCopyTexSubImage2D_t) s_gles_lib->findSymbol("glCopyTexSubImage2D"); + s_gl.glCullFace = (glCullFace_t) s_gles_lib->findSymbol("glCullFace"); + s_gl.glDeleteBuffers = (glDeleteBuffers_t) s_gles_lib->findSymbol("glDeleteBuffers"); + s_gl.glDeleteTextures = (glDeleteTextures_t) s_gles_lib->findSymbol("glDeleteTextures"); + s_gl.glDepthFunc = (glDepthFunc_t) s_gles_lib->findSymbol("glDepthFunc"); + s_gl.glDepthMask = (glDepthMask_t) s_gles_lib->findSymbol("glDepthMask"); + s_gl.glDepthRangex = (glDepthRangex_t) s_gles_lib->findSymbol("glDepthRangex"); + s_gl.glDisable = (glDisable_t) s_gles_lib->findSymbol("glDisable"); + s_gl.glDisableClientState = (glDisableClientState_t) s_gles_lib->findSymbol("glDisableClientState"); + s_gl.glDrawArrays = (glDrawArrays_t) s_gles_lib->findSymbol("glDrawArrays"); + s_gl.glDrawElements = (glDrawElements_t) s_gles_lib->findSymbol("glDrawElements"); + s_gl.glEnable = (glEnable_t) s_gles_lib->findSymbol("glEnable"); + s_gl.glEnableClientState = (glEnableClientState_t) s_gles_lib->findSymbol("glEnableClientState"); + s_gl.glFinish = (glFinish_t) s_gles_lib->findSymbol("glFinish"); + s_gl.glFlush = (glFlush_t) s_gles_lib->findSymbol("glFlush"); + s_gl.glFogx = (glFogx_t) s_gles_lib->findSymbol("glFogx"); + s_gl.glFogxv = (glFogxv_t) s_gles_lib->findSymbol("glFogxv"); + s_gl.glFrontFace = (glFrontFace_t) s_gles_lib->findSymbol("glFrontFace"); + s_gl.glFrustumx = (glFrustumx_t) s_gles_lib->findSymbol("glFrustumx"); + s_gl.glGetBooleanv = (glGetBooleanv_t) s_gles_lib->findSymbol("glGetBooleanv"); + s_gl.glGetBufferParameteriv = (glGetBufferParameteriv_t) s_gles_lib->findSymbol("glGetBufferParameteriv"); + s_gl.glGetClipPlanex = (glGetClipPlanex_t) s_gles_lib->findSymbol("glGetClipPlanex"); + s_gl.glGenBuffers = (glGenBuffers_t) s_gles_lib->findSymbol("glGenBuffers"); + s_gl.glGenTextures = (glGenTextures_t) s_gles_lib->findSymbol("glGenTextures"); + s_gl.glGetError = (glGetError_t) s_gles_lib->findSymbol("glGetError"); + s_gl.glGetFixedv = (glGetFixedv_t) s_gles_lib->findSymbol("glGetFixedv"); + s_gl.glGetIntegerv = (glGetIntegerv_t) s_gles_lib->findSymbol("glGetIntegerv"); + s_gl.glGetLightxv = (glGetLightxv_t) s_gles_lib->findSymbol("glGetLightxv"); + s_gl.glGetMaterialxv = (glGetMaterialxv_t) s_gles_lib->findSymbol("glGetMaterialxv"); + s_gl.glGetPointerv = (glGetPointerv_t) s_gles_lib->findSymbol("glGetPointerv"); + s_gl.glGetString = (glGetString_t) s_gles_lib->findSymbol("glGetString"); + s_gl.glGetTexEnviv = (glGetTexEnviv_t) s_gles_lib->findSymbol("glGetTexEnviv"); + s_gl.glGetTexEnvxv = (glGetTexEnvxv_t) s_gles_lib->findSymbol("glGetTexEnvxv"); + s_gl.glGetTexParameteriv = (glGetTexParameteriv_t) s_gles_lib->findSymbol("glGetTexParameteriv"); + s_gl.glGetTexParameterxv = (glGetTexParameterxv_t) s_gles_lib->findSymbol("glGetTexParameterxv"); + s_gl.glHint = (glHint_t) s_gles_lib->findSymbol("glHint"); + s_gl.glIsBuffer = (glIsBuffer_t) s_gles_lib->findSymbol("glIsBuffer"); + s_gl.glIsEnabled = (glIsEnabled_t) s_gles_lib->findSymbol("glIsEnabled"); + s_gl.glIsTexture = (glIsTexture_t) s_gles_lib->findSymbol("glIsTexture"); + s_gl.glLightModelx = (glLightModelx_t) s_gles_lib->findSymbol("glLightModelx"); + s_gl.glLightModelxv = (glLightModelxv_t) s_gles_lib->findSymbol("glLightModelxv"); + s_gl.glLightx = (glLightx_t) s_gles_lib->findSymbol("glLightx"); + s_gl.glLightxv = (glLightxv_t) s_gles_lib->findSymbol("glLightxv"); + s_gl.glLineWidthx = (glLineWidthx_t) s_gles_lib->findSymbol("glLineWidthx"); + s_gl.glLoadIdentity = (glLoadIdentity_t) s_gles_lib->findSymbol("glLoadIdentity"); + s_gl.glLoadMatrixx = (glLoadMatrixx_t) s_gles_lib->findSymbol("glLoadMatrixx"); + s_gl.glLogicOp = (glLogicOp_t) s_gles_lib->findSymbol("glLogicOp"); + s_gl.glMaterialx = (glMaterialx_t) s_gles_lib->findSymbol("glMaterialx"); + s_gl.glMaterialxv = (glMaterialxv_t) s_gles_lib->findSymbol("glMaterialxv"); + s_gl.glMatrixMode = (glMatrixMode_t) s_gles_lib->findSymbol("glMatrixMode"); + s_gl.glMultMatrixx = (glMultMatrixx_t) s_gles_lib->findSymbol("glMultMatrixx"); + s_gl.glMultiTexCoord4x = (glMultiTexCoord4x_t) s_gles_lib->findSymbol("glMultiTexCoord4x"); + s_gl.glNormal3x = (glNormal3x_t) s_gles_lib->findSymbol("glNormal3x"); + s_gl.glNormalPointer = (glNormalPointer_t) s_gles_lib->findSymbol("glNormalPointer"); + s_gl.glOrthox = (glOrthox_t) s_gles_lib->findSymbol("glOrthox"); + s_gl.glPixelStorei = (glPixelStorei_t) s_gles_lib->findSymbol("glPixelStorei"); + s_gl.glPointParameterx = (glPointParameterx_t) s_gles_lib->findSymbol("glPointParameterx"); + s_gl.glPointParameterxv = (glPointParameterxv_t) s_gles_lib->findSymbol("glPointParameterxv"); + s_gl.glPointSizex = (glPointSizex_t) s_gles_lib->findSymbol("glPointSizex"); + s_gl.glPolygonOffsetx = (glPolygonOffsetx_t) s_gles_lib->findSymbol("glPolygonOffsetx"); + s_gl.glPopMatrix = (glPopMatrix_t) s_gles_lib->findSymbol("glPopMatrix"); + s_gl.glPushMatrix = (glPushMatrix_t) s_gles_lib->findSymbol("glPushMatrix"); + s_gl.glReadPixels = (glReadPixels_t) s_gles_lib->findSymbol("glReadPixels"); + s_gl.glRotatex = (glRotatex_t) s_gles_lib->findSymbol("glRotatex"); + s_gl.glSampleCoverage = (glSampleCoverage_t) s_gles_lib->findSymbol("glSampleCoverage"); + s_gl.glSampleCoveragex = (glSampleCoveragex_t) s_gles_lib->findSymbol("glSampleCoveragex"); + s_gl.glScalex = (glScalex_t) s_gles_lib->findSymbol("glScalex"); + s_gl.glScissor = (glScissor_t) s_gles_lib->findSymbol("glScissor"); + s_gl.glShadeModel = (glShadeModel_t) s_gles_lib->findSymbol("glShadeModel"); + s_gl.glStencilFunc = (glStencilFunc_t) s_gles_lib->findSymbol("glStencilFunc"); + s_gl.glStencilMask = (glStencilMask_t) s_gles_lib->findSymbol("glStencilMask"); + s_gl.glStencilOp = (glStencilOp_t) s_gles_lib->findSymbol("glStencilOp"); + s_gl.glTexCoordPointer = (glTexCoordPointer_t) s_gles_lib->findSymbol("glTexCoordPointer"); + s_gl.glTexEnvi = (glTexEnvi_t) s_gles_lib->findSymbol("glTexEnvi"); + s_gl.glTexEnvx = (glTexEnvx_t) s_gles_lib->findSymbol("glTexEnvx"); + s_gl.glTexEnviv = (glTexEnviv_t) s_gles_lib->findSymbol("glTexEnviv"); + s_gl.glTexEnvxv = (glTexEnvxv_t) s_gles_lib->findSymbol("glTexEnvxv"); + s_gl.glTexImage2D = (glTexImage2D_t) s_gles_lib->findSymbol("glTexImage2D"); + s_gl.glTexParameteri = (glTexParameteri_t) s_gles_lib->findSymbol("glTexParameteri"); + s_gl.glTexParameterx = (glTexParameterx_t) s_gles_lib->findSymbol("glTexParameterx"); + s_gl.glTexParameteriv = (glTexParameteriv_t) s_gles_lib->findSymbol("glTexParameteriv"); + s_gl.glTexParameterxv = (glTexParameterxv_t) s_gles_lib->findSymbol("glTexParameterxv"); + s_gl.glTexSubImage2D = (glTexSubImage2D_t) s_gles_lib->findSymbol("glTexSubImage2D"); + s_gl.glTranslatex = (glTranslatex_t) s_gles_lib->findSymbol("glTranslatex"); + s_gl.glVertexPointer = (glVertexPointer_t) s_gles_lib->findSymbol("glVertexPointer"); + s_gl.glViewport = (glViewport_t) s_gles_lib->findSymbol("glViewport"); + s_gl.glPointSizePointerOES = (glPointSizePointerOES_t) s_gles_lib->findSymbol("glPointSizePointerOES"); + s_gl.glBlendEquationSeparateOES = (glBlendEquationSeparateOES_t) s_gles_lib->findSymbol("glBlendEquationSeparateOES"); + s_gl.glBlendFuncSeparateOES = (glBlendFuncSeparateOES_t) s_gles_lib->findSymbol("glBlendFuncSeparateOES"); + s_gl.glBlendEquationOES = (glBlendEquationOES_t) s_gles_lib->findSymbol("glBlendEquationOES"); + s_gl.glDrawTexsOES = (glDrawTexsOES_t) s_gles_lib->findSymbol("glDrawTexsOES"); + s_gl.glDrawTexiOES = (glDrawTexiOES_t) s_gles_lib->findSymbol("glDrawTexiOES"); + s_gl.glDrawTexxOES = (glDrawTexxOES_t) s_gles_lib->findSymbol("glDrawTexxOES"); + s_gl.glDrawTexsvOES = (glDrawTexsvOES_t) s_gles_lib->findSymbol("glDrawTexsvOES"); + s_gl.glDrawTexivOES = (glDrawTexivOES_t) s_gles_lib->findSymbol("glDrawTexivOES"); + s_gl.glDrawTexxvOES = (glDrawTexxvOES_t) s_gles_lib->findSymbol("glDrawTexxvOES"); + s_gl.glDrawTexfOES = (glDrawTexfOES_t) s_gles_lib->findSymbol("glDrawTexfOES"); + s_gl.glDrawTexfvOES = (glDrawTexfvOES_t) s_gles_lib->findSymbol("glDrawTexfvOES"); + s_gl.glEGLImageTargetTexture2DOES = (glEGLImageTargetTexture2DOES_t) s_gles_lib->findSymbol("glEGLImageTargetTexture2DOES"); + s_gl.glEGLImageTargetRenderbufferStorageOES = (glEGLImageTargetRenderbufferStorageOES_t) s_gles_lib->findSymbol("glEGLImageTargetRenderbufferStorageOES"); + s_gl.glAlphaFuncxOES = (glAlphaFuncxOES_t) s_gles_lib->findSymbol("glAlphaFuncxOES"); + s_gl.glClearColorxOES = (glClearColorxOES_t) s_gles_lib->findSymbol("glClearColorxOES"); + s_gl.glClearDepthxOES = (glClearDepthxOES_t) s_gles_lib->findSymbol("glClearDepthxOES"); + s_gl.glClipPlanexOES = (glClipPlanexOES_t) s_gles_lib->findSymbol("glClipPlanexOES"); + s_gl.glColor4xOES = (glColor4xOES_t) s_gles_lib->findSymbol("glColor4xOES"); + s_gl.glDepthRangexOES = (glDepthRangexOES_t) s_gles_lib->findSymbol("glDepthRangexOES"); + s_gl.glFogxOES = (glFogxOES_t) s_gles_lib->findSymbol("glFogxOES"); + s_gl.glFogxvOES = (glFogxvOES_t) s_gles_lib->findSymbol("glFogxvOES"); + s_gl.glFrustumxOES = (glFrustumxOES_t) s_gles_lib->findSymbol("glFrustumxOES"); + s_gl.glGetClipPlanexOES = (glGetClipPlanexOES_t) s_gles_lib->findSymbol("glGetClipPlanexOES"); + s_gl.glGetFixedvOES = (glGetFixedvOES_t) s_gles_lib->findSymbol("glGetFixedvOES"); + s_gl.glGetLightxvOES = (glGetLightxvOES_t) s_gles_lib->findSymbol("glGetLightxvOES"); + s_gl.glGetMaterialxvOES = (glGetMaterialxvOES_t) s_gles_lib->findSymbol("glGetMaterialxvOES"); + s_gl.glGetTexEnvxvOES = (glGetTexEnvxvOES_t) s_gles_lib->findSymbol("glGetTexEnvxvOES"); + s_gl.glGetTexParameterxvOES = (glGetTexParameterxvOES_t) s_gles_lib->findSymbol("glGetTexParameterxvOES"); + s_gl.glLightModelxOES = (glLightModelxOES_t) s_gles_lib->findSymbol("glLightModelxOES"); + s_gl.glLightModelxvOES = (glLightModelxvOES_t) s_gles_lib->findSymbol("glLightModelxvOES"); + s_gl.glLightxOES = (glLightxOES_t) s_gles_lib->findSymbol("glLightxOES"); + s_gl.glLightxvOES = (glLightxvOES_t) s_gles_lib->findSymbol("glLightxvOES"); + s_gl.glLineWidthxOES = (glLineWidthxOES_t) s_gles_lib->findSymbol("glLineWidthxOES"); + s_gl.glLoadMatrixxOES = (glLoadMatrixxOES_t) s_gles_lib->findSymbol("glLoadMatrixxOES"); + s_gl.glMaterialxOES = (glMaterialxOES_t) s_gles_lib->findSymbol("glMaterialxOES"); + s_gl.glMaterialxvOES = (glMaterialxvOES_t) s_gles_lib->findSymbol("glMaterialxvOES"); + s_gl.glMultMatrixxOES = (glMultMatrixxOES_t) s_gles_lib->findSymbol("glMultMatrixxOES"); + s_gl.glMultiTexCoord4xOES = (glMultiTexCoord4xOES_t) s_gles_lib->findSymbol("glMultiTexCoord4xOES"); + s_gl.glNormal3xOES = (glNormal3xOES_t) s_gles_lib->findSymbol("glNormal3xOES"); + s_gl.glOrthoxOES = (glOrthoxOES_t) s_gles_lib->findSymbol("glOrthoxOES"); + s_gl.glPointParameterxOES = (glPointParameterxOES_t) s_gles_lib->findSymbol("glPointParameterxOES"); + s_gl.glPointParameterxvOES = (glPointParameterxvOES_t) s_gles_lib->findSymbol("glPointParameterxvOES"); + s_gl.glPointSizexOES = (glPointSizexOES_t) s_gles_lib->findSymbol("glPointSizexOES"); + s_gl.glPolygonOffsetxOES = (glPolygonOffsetxOES_t) s_gles_lib->findSymbol("glPolygonOffsetxOES"); + s_gl.glRotatexOES = (glRotatexOES_t) s_gles_lib->findSymbol("glRotatexOES"); + s_gl.glSampleCoveragexOES = (glSampleCoveragexOES_t) s_gles_lib->findSymbol("glSampleCoveragexOES"); + s_gl.glScalexOES = (glScalexOES_t) s_gles_lib->findSymbol("glScalexOES"); + s_gl.glTexEnvxOES = (glTexEnvxOES_t) s_gles_lib->findSymbol("glTexEnvxOES"); + s_gl.glTexEnvxvOES = (glTexEnvxvOES_t) s_gles_lib->findSymbol("glTexEnvxvOES"); + s_gl.glTexParameterxOES = (glTexParameterxOES_t) s_gles_lib->findSymbol("glTexParameterxOES"); + s_gl.glTexParameterxvOES = (glTexParameterxvOES_t) s_gles_lib->findSymbol("glTexParameterxvOES"); + s_gl.glTranslatexOES = (glTranslatexOES_t) s_gles_lib->findSymbol("glTranslatexOES"); + s_gl.glIsRenderbufferOES = (glIsRenderbufferOES_t) s_gles_lib->findSymbol("glIsRenderbufferOES"); + s_gl.glBindRenderbufferOES = (glBindRenderbufferOES_t) s_gles_lib->findSymbol("glBindRenderbufferOES"); + s_gl.glDeleteRenderbuffersOES = (glDeleteRenderbuffersOES_t) s_gles_lib->findSymbol("glDeleteRenderbuffersOES"); + s_gl.glGenRenderbuffersOES = (glGenRenderbuffersOES_t) s_gles_lib->findSymbol("glGenRenderbuffersOES"); + s_gl.glRenderbufferStorageOES = (glRenderbufferStorageOES_t) s_gles_lib->findSymbol("glRenderbufferStorageOES"); + s_gl.glGetRenderbufferParameterivOES = (glGetRenderbufferParameterivOES_t) s_gles_lib->findSymbol("glGetRenderbufferParameterivOES"); + s_gl.glIsFramebufferOES = (glIsFramebufferOES_t) s_gles_lib->findSymbol("glIsFramebufferOES"); + s_gl.glBindFramebufferOES = (glBindFramebufferOES_t) s_gles_lib->findSymbol("glBindFramebufferOES"); + s_gl.glDeleteFramebuffersOES = (glDeleteFramebuffersOES_t) s_gles_lib->findSymbol("glDeleteFramebuffersOES"); + s_gl.glGenFramebuffersOES = (glGenFramebuffersOES_t) s_gles_lib->findSymbol("glGenFramebuffersOES"); + s_gl.glCheckFramebufferStatusOES = (glCheckFramebufferStatusOES_t) s_gles_lib->findSymbol("glCheckFramebufferStatusOES"); + s_gl.glFramebufferRenderbufferOES = (glFramebufferRenderbufferOES_t) s_gles_lib->findSymbol("glFramebufferRenderbufferOES"); + s_gl.glFramebufferTexture2DOES = (glFramebufferTexture2DOES_t) s_gles_lib->findSymbol("glFramebufferTexture2DOES"); + s_gl.glGetFramebufferAttachmentParameterivOES = (glGetFramebufferAttachmentParameterivOES_t) s_gles_lib->findSymbol("glGetFramebufferAttachmentParameterivOES"); + s_gl.glGenerateMipmapOES = (glGenerateMipmapOES_t) s_gles_lib->findSymbol("glGenerateMipmapOES"); + s_gl.glMapBufferOES = (glMapBufferOES_t) s_gles_lib->findSymbol("glMapBufferOES"); + s_gl.glUnmapBufferOES = (glUnmapBufferOES_t) s_gles_lib->findSymbol("glUnmapBufferOES"); + s_gl.glGetBufferPointervOES = (glGetBufferPointervOES_t) s_gles_lib->findSymbol("glGetBufferPointervOES"); + s_gl.glCurrentPaletteMatrixOES = (glCurrentPaletteMatrixOES_t) s_gles_lib->findSymbol("glCurrentPaletteMatrixOES"); + s_gl.glLoadPaletteFromModelViewMatrixOES = (glLoadPaletteFromModelViewMatrixOES_t) s_gles_lib->findSymbol("glLoadPaletteFromModelViewMatrixOES"); + s_gl.glMatrixIndexPointerOES = (glMatrixIndexPointerOES_t) s_gles_lib->findSymbol("glMatrixIndexPointerOES"); + s_gl.glWeightPointerOES = (glWeightPointerOES_t) s_gles_lib->findSymbol("glWeightPointerOES"); + s_gl.glQueryMatrixxOES = (glQueryMatrixxOES_t) s_gles_lib->findSymbol("glQueryMatrixxOES"); + s_gl.glDepthRangefOES = (glDepthRangefOES_t) s_gles_lib->findSymbol("glDepthRangefOES"); + s_gl.glFrustumfOES = (glFrustumfOES_t) s_gles_lib->findSymbol("glFrustumfOES"); + s_gl.glOrthofOES = (glOrthofOES_t) s_gles_lib->findSymbol("glOrthofOES"); + s_gl.glClipPlanefOES = (glClipPlanefOES_t) s_gles_lib->findSymbol("glClipPlanefOES"); + s_gl.glGetClipPlanefOES = (glGetClipPlanefOES_t) s_gles_lib->findSymbol("glGetClipPlanefOES"); + s_gl.glClearDepthfOES = (glClearDepthfOES_t) s_gles_lib->findSymbol("glClearDepthfOES"); + s_gl.glTexGenfOES = (glTexGenfOES_t) s_gles_lib->findSymbol("glTexGenfOES"); + s_gl.glTexGenfvOES = (glTexGenfvOES_t) s_gles_lib->findSymbol("glTexGenfvOES"); + s_gl.glTexGeniOES = (glTexGeniOES_t) s_gles_lib->findSymbol("glTexGeniOES"); + s_gl.glTexGenivOES = (glTexGenivOES_t) s_gles_lib->findSymbol("glTexGenivOES"); + s_gl.glTexGenxOES = (glTexGenxOES_t) s_gles_lib->findSymbol("glTexGenxOES"); + s_gl.glTexGenxvOES = (glTexGenxvOES_t) s_gles_lib->findSymbol("glTexGenxvOES"); + s_gl.glGetTexGenfvOES = (glGetTexGenfvOES_t) s_gles_lib->findSymbol("glGetTexGenfvOES"); + s_gl.glGetTexGenivOES = (glGetTexGenivOES_t) s_gles_lib->findSymbol("glGetTexGenivOES"); + s_gl.glGetTexGenxvOES = (glGetTexGenxvOES_t) s_gles_lib->findSymbol("glGetTexGenxvOES"); + s_gl.glBindVertexArrayOES = (glBindVertexArrayOES_t) s_gles_lib->findSymbol("glBindVertexArrayOES"); + s_gl.glDeleteVertexArraysOES = (glDeleteVertexArraysOES_t) s_gles_lib->findSymbol("glDeleteVertexArraysOES"); + s_gl.glGenVertexArraysOES = (glGenVertexArraysOES_t) s_gles_lib->findSymbol("glGenVertexArraysOES"); + s_gl.glIsVertexArrayOES = (glIsVertexArrayOES_t) s_gles_lib->findSymbol("glIsVertexArrayOES"); + s_gl.glDiscardFramebufferEXT = (glDiscardFramebufferEXT_t) s_gles_lib->findSymbol("glDiscardFramebufferEXT"); + s_gl.glMultiDrawArraysEXT = (glMultiDrawArraysEXT_t) s_gles_lib->findSymbol("glMultiDrawArraysEXT"); + s_gl.glMultiDrawElementsEXT = (glMultiDrawElementsEXT_t) s_gles_lib->findSymbol("glMultiDrawElementsEXT"); + s_gl.glClipPlanefIMG = (glClipPlanefIMG_t) s_gles_lib->findSymbol("glClipPlanefIMG"); + s_gl.glClipPlanexIMG = (glClipPlanexIMG_t) s_gles_lib->findSymbol("glClipPlanexIMG"); + s_gl.glRenderbufferStorageMultisampleIMG = (glRenderbufferStorageMultisampleIMG_t) s_gles_lib->findSymbol("glRenderbufferStorageMultisampleIMG"); + s_gl.glFramebufferTexture2DMultisampleIMG = (glFramebufferTexture2DMultisampleIMG_t) s_gles_lib->findSymbol("glFramebufferTexture2DMultisampleIMG"); + s_gl.glDeleteFencesNV = (glDeleteFencesNV_t) s_gles_lib->findSymbol("glDeleteFencesNV"); + s_gl.glGenFencesNV = (glGenFencesNV_t) s_gles_lib->findSymbol("glGenFencesNV"); + s_gl.glIsFenceNV = (glIsFenceNV_t) s_gles_lib->findSymbol("glIsFenceNV"); + s_gl.glTestFenceNV = (glTestFenceNV_t) s_gles_lib->findSymbol("glTestFenceNV"); + s_gl.glGetFenceivNV = (glGetFenceivNV_t) s_gles_lib->findSymbol("glGetFenceivNV"); + s_gl.glFinishFenceNV = (glFinishFenceNV_t) s_gles_lib->findSymbol("glFinishFenceNV"); + s_gl.glSetFenceNV = (glSetFenceNV_t) s_gles_lib->findSymbol("glSetFenceNV"); + s_gl.glGetDriverControlsQCOM = (glGetDriverControlsQCOM_t) s_gles_lib->findSymbol("glGetDriverControlsQCOM"); + s_gl.glGetDriverControlStringQCOM = (glGetDriverControlStringQCOM_t) s_gles_lib->findSymbol("glGetDriverControlStringQCOM"); + s_gl.glEnableDriverControlQCOM = (glEnableDriverControlQCOM_t) s_gles_lib->findSymbol("glEnableDriverControlQCOM"); + s_gl.glDisableDriverControlQCOM = (glDisableDriverControlQCOM_t) s_gles_lib->findSymbol("glDisableDriverControlQCOM"); + s_gl.glExtGetTexturesQCOM = (glExtGetTexturesQCOM_t) s_gles_lib->findSymbol("glExtGetTexturesQCOM"); + s_gl.glExtGetBuffersQCOM = (glExtGetBuffersQCOM_t) s_gles_lib->findSymbol("glExtGetBuffersQCOM"); + s_gl.glExtGetRenderbuffersQCOM = (glExtGetRenderbuffersQCOM_t) s_gles_lib->findSymbol("glExtGetRenderbuffersQCOM"); + s_gl.glExtGetFramebuffersQCOM = (glExtGetFramebuffersQCOM_t) s_gles_lib->findSymbol("glExtGetFramebuffersQCOM"); + s_gl.glExtGetTexLevelParameterivQCOM = (glExtGetTexLevelParameterivQCOM_t) s_gles_lib->findSymbol("glExtGetTexLevelParameterivQCOM"); + s_gl.glExtTexObjectStateOverrideiQCOM = (glExtTexObjectStateOverrideiQCOM_t) s_gles_lib->findSymbol("glExtTexObjectStateOverrideiQCOM"); + s_gl.glExtGetTexSubImageQCOM = (glExtGetTexSubImageQCOM_t) s_gles_lib->findSymbol("glExtGetTexSubImageQCOM"); + s_gl.glExtGetBufferPointervQCOM = (glExtGetBufferPointervQCOM_t) s_gles_lib->findSymbol("glExtGetBufferPointervQCOM"); + s_gl.glExtGetShadersQCOM = (glExtGetShadersQCOM_t) s_gles_lib->findSymbol("glExtGetShadersQCOM"); + s_gl.glExtGetProgramsQCOM = (glExtGetProgramsQCOM_t) s_gles_lib->findSymbol("glExtGetProgramsQCOM"); + s_gl.glExtIsProgramBinaryQCOM = (glExtIsProgramBinaryQCOM_t) s_gles_lib->findSymbol("glExtIsProgramBinaryQCOM"); + s_gl.glExtGetProgramBinarySourceQCOM = (glExtGetProgramBinarySourceQCOM_t) s_gles_lib->findSymbol("glExtGetProgramBinarySourceQCOM"); + s_gl.glStartTilingQCOM = (glStartTilingQCOM_t) s_gles_lib->findSymbol("glStartTilingQCOM"); + s_gl.glEndTilingQCOM = (glEndTilingQCOM_t) s_gles_lib->findSymbol("glEndTilingQCOM"); + + return true; +} + +// +// This function is called only during initialiation before +// any thread has been created - hence it should NOT be thread safe. +// +void *gl_dispatch_get_proc_func(const char *name, void *userData) +{ + if (!s_gles_lib) { + return NULL; + } + return (void *)s_gles_lib->findSymbol(name); +} diff --git a/emulator/opengl/host/libs/libOpenglRender/GLDispatch.h b/emulator/opengl/host/libs/libOpenglRender/GLDispatch.h new file mode 100644 index 0000000..5fe98f1 --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/GLDispatch.h @@ -0,0 +1,300 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _GLES_DISPATCH_H +#define _GLES_DISPATCH_H + +#include "gl_proc.h" + + +struct GLDispatch { + glAlphaFunc_t glAlphaFunc; + glClearColor_t glClearColor; + glClearDepthf_t glClearDepthf; + glClipPlanef_t glClipPlanef; + glColor4f_t glColor4f; + glDepthRangef_t glDepthRangef; + glFogf_t glFogf; + glFogfv_t glFogfv; + glFrustumf_t glFrustumf; + glGetClipPlanef_t glGetClipPlanef; + glGetFloatv_t glGetFloatv; + glGetLightfv_t glGetLightfv; + glGetMaterialfv_t glGetMaterialfv; + glGetTexEnvfv_t glGetTexEnvfv; + glGetTexParameterfv_t glGetTexParameterfv; + glLightModelf_t glLightModelf; + glLightModelfv_t glLightModelfv; + glLightf_t glLightf; + glLightfv_t glLightfv; + glLineWidth_t glLineWidth; + glLoadMatrixf_t glLoadMatrixf; + glMaterialf_t glMaterialf; + glMaterialfv_t glMaterialfv; + glMultMatrixf_t glMultMatrixf; + glMultiTexCoord4f_t glMultiTexCoord4f; + glNormal3f_t glNormal3f; + glOrthof_t glOrthof; + glPointParameterf_t glPointParameterf; + glPointParameterfv_t glPointParameterfv; + glPointSize_t glPointSize; + glPolygonOffset_t glPolygonOffset; + glRotatef_t glRotatef; + glScalef_t glScalef; + glTexEnvf_t glTexEnvf; + glTexEnvfv_t glTexEnvfv; + glTexParameterf_t glTexParameterf; + glTexParameterfv_t glTexParameterfv; + glTranslatef_t glTranslatef; + glActiveTexture_t glActiveTexture; + glAlphaFuncx_t glAlphaFuncx; + glBindBuffer_t glBindBuffer; + glBindTexture_t glBindTexture; + glBlendFunc_t glBlendFunc; + glBufferData_t glBufferData; + glBufferSubData_t glBufferSubData; + glClear_t glClear; + glClearColorx_t glClearColorx; + glClearDepthx_t glClearDepthx; + glClearStencil_t glClearStencil; + glClientActiveTexture_t glClientActiveTexture; + glClipPlanex_t glClipPlanex; + glColor4ub_t glColor4ub; + glColor4x_t glColor4x; + glColorMask_t glColorMask; + glColorPointer_t glColorPointer; + glCompressedTexImage2D_t glCompressedTexImage2D; + glCompressedTexSubImage2D_t glCompressedTexSubImage2D; + glCopyTexImage2D_t glCopyTexImage2D; + glCopyTexSubImage2D_t glCopyTexSubImage2D; + glCullFace_t glCullFace; + glDeleteBuffers_t glDeleteBuffers; + glDeleteTextures_t glDeleteTextures; + glDepthFunc_t glDepthFunc; + glDepthMask_t glDepthMask; + glDepthRangex_t glDepthRangex; + glDisable_t glDisable; + glDisableClientState_t glDisableClientState; + glDrawArrays_t glDrawArrays; + glDrawElements_t glDrawElements; + glEnable_t glEnable; + glEnableClientState_t glEnableClientState; + glFinish_t glFinish; + glFlush_t glFlush; + glFogx_t glFogx; + glFogxv_t glFogxv; + glFrontFace_t glFrontFace; + glFrustumx_t glFrustumx; + glGetBooleanv_t glGetBooleanv; + glGetBufferParameteriv_t glGetBufferParameteriv; + glGetClipPlanex_t glGetClipPlanex; + glGenBuffers_t glGenBuffers; + glGenTextures_t glGenTextures; + glGetError_t glGetError; + glGetFixedv_t glGetFixedv; + glGetIntegerv_t glGetIntegerv; + glGetLightxv_t glGetLightxv; + glGetMaterialxv_t glGetMaterialxv; + glGetPointerv_t glGetPointerv; + glGetString_t glGetString; + glGetTexEnviv_t glGetTexEnviv; + glGetTexEnvxv_t glGetTexEnvxv; + glGetTexParameteriv_t glGetTexParameteriv; + glGetTexParameterxv_t glGetTexParameterxv; + glHint_t glHint; + glIsBuffer_t glIsBuffer; + glIsEnabled_t glIsEnabled; + glIsTexture_t glIsTexture; + glLightModelx_t glLightModelx; + glLightModelxv_t glLightModelxv; + glLightx_t glLightx; + glLightxv_t glLightxv; + glLineWidthx_t glLineWidthx; + glLoadIdentity_t glLoadIdentity; + glLoadMatrixx_t glLoadMatrixx; + glLogicOp_t glLogicOp; + glMaterialx_t glMaterialx; + glMaterialxv_t glMaterialxv; + glMatrixMode_t glMatrixMode; + glMultMatrixx_t glMultMatrixx; + glMultiTexCoord4x_t glMultiTexCoord4x; + glNormal3x_t glNormal3x; + glNormalPointer_t glNormalPointer; + glOrthox_t glOrthox; + glPixelStorei_t glPixelStorei; + glPointParameterx_t glPointParameterx; + glPointParameterxv_t glPointParameterxv; + glPointSizex_t glPointSizex; + glPolygonOffsetx_t glPolygonOffsetx; + glPopMatrix_t glPopMatrix; + glPushMatrix_t glPushMatrix; + glReadPixels_t glReadPixels; + glRotatex_t glRotatex; + glSampleCoverage_t glSampleCoverage; + glSampleCoveragex_t glSampleCoveragex; + glScalex_t glScalex; + glScissor_t glScissor; + glShadeModel_t glShadeModel; + glStencilFunc_t glStencilFunc; + glStencilMask_t glStencilMask; + glStencilOp_t glStencilOp; + glTexCoordPointer_t glTexCoordPointer; + glTexEnvi_t glTexEnvi; + glTexEnvx_t glTexEnvx; + glTexEnviv_t glTexEnviv; + glTexEnvxv_t glTexEnvxv; + glTexImage2D_t glTexImage2D; + glTexParameteri_t glTexParameteri; + glTexParameterx_t glTexParameterx; + glTexParameteriv_t glTexParameteriv; + glTexParameterxv_t glTexParameterxv; + glTexSubImage2D_t glTexSubImage2D; + glTranslatex_t glTranslatex; + glVertexPointer_t glVertexPointer; + glViewport_t glViewport; + glPointSizePointerOES_t glPointSizePointerOES; + glBlendEquationSeparateOES_t glBlendEquationSeparateOES; + glBlendFuncSeparateOES_t glBlendFuncSeparateOES; + glBlendEquationOES_t glBlendEquationOES; + glDrawTexsOES_t glDrawTexsOES; + glDrawTexiOES_t glDrawTexiOES; + glDrawTexxOES_t glDrawTexxOES; + glDrawTexsvOES_t glDrawTexsvOES; + glDrawTexivOES_t glDrawTexivOES; + glDrawTexxvOES_t glDrawTexxvOES; + glDrawTexfOES_t glDrawTexfOES; + glDrawTexfvOES_t glDrawTexfvOES; + glEGLImageTargetTexture2DOES_t glEGLImageTargetTexture2DOES; + glEGLImageTargetRenderbufferStorageOES_t glEGLImageTargetRenderbufferStorageOES; + glAlphaFuncxOES_t glAlphaFuncxOES; + glClearColorxOES_t glClearColorxOES; + glClearDepthxOES_t glClearDepthxOES; + glClipPlanexOES_t glClipPlanexOES; + glColor4xOES_t glColor4xOES; + glDepthRangexOES_t glDepthRangexOES; + glFogxOES_t glFogxOES; + glFogxvOES_t glFogxvOES; + glFrustumxOES_t glFrustumxOES; + glGetClipPlanexOES_t glGetClipPlanexOES; + glGetFixedvOES_t glGetFixedvOES; + glGetLightxvOES_t glGetLightxvOES; + glGetMaterialxvOES_t glGetMaterialxvOES; + glGetTexEnvxvOES_t glGetTexEnvxvOES; + glGetTexParameterxvOES_t glGetTexParameterxvOES; + glLightModelxOES_t glLightModelxOES; + glLightModelxvOES_t glLightModelxvOES; + glLightxOES_t glLightxOES; + glLightxvOES_t glLightxvOES; + glLineWidthxOES_t glLineWidthxOES; + glLoadMatrixxOES_t glLoadMatrixxOES; + glMaterialxOES_t glMaterialxOES; + glMaterialxvOES_t glMaterialxvOES; + glMultMatrixxOES_t glMultMatrixxOES; + glMultiTexCoord4xOES_t glMultiTexCoord4xOES; + glNormal3xOES_t glNormal3xOES; + glOrthoxOES_t glOrthoxOES; + glPointParameterxOES_t glPointParameterxOES; + glPointParameterxvOES_t glPointParameterxvOES; + glPointSizexOES_t glPointSizexOES; + glPolygonOffsetxOES_t glPolygonOffsetxOES; + glRotatexOES_t glRotatexOES; + glSampleCoveragexOES_t glSampleCoveragexOES; + glScalexOES_t glScalexOES; + glTexEnvxOES_t glTexEnvxOES; + glTexEnvxvOES_t glTexEnvxvOES; + glTexParameterxOES_t glTexParameterxOES; + glTexParameterxvOES_t glTexParameterxvOES; + glTranslatexOES_t glTranslatexOES; + glIsRenderbufferOES_t glIsRenderbufferOES; + glBindRenderbufferOES_t glBindRenderbufferOES; + glDeleteRenderbuffersOES_t glDeleteRenderbuffersOES; + glGenRenderbuffersOES_t glGenRenderbuffersOES; + glRenderbufferStorageOES_t glRenderbufferStorageOES; + glGetRenderbufferParameterivOES_t glGetRenderbufferParameterivOES; + glIsFramebufferOES_t glIsFramebufferOES; + glBindFramebufferOES_t glBindFramebufferOES; + glDeleteFramebuffersOES_t glDeleteFramebuffersOES; + glGenFramebuffersOES_t glGenFramebuffersOES; + glCheckFramebufferStatusOES_t glCheckFramebufferStatusOES; + glFramebufferRenderbufferOES_t glFramebufferRenderbufferOES; + glFramebufferTexture2DOES_t glFramebufferTexture2DOES; + glGetFramebufferAttachmentParameterivOES_t glGetFramebufferAttachmentParameterivOES; + glGenerateMipmapOES_t glGenerateMipmapOES; + glMapBufferOES_t glMapBufferOES; + glUnmapBufferOES_t glUnmapBufferOES; + glGetBufferPointervOES_t glGetBufferPointervOES; + glCurrentPaletteMatrixOES_t glCurrentPaletteMatrixOES; + glLoadPaletteFromModelViewMatrixOES_t glLoadPaletteFromModelViewMatrixOES; + glMatrixIndexPointerOES_t glMatrixIndexPointerOES; + glWeightPointerOES_t glWeightPointerOES; + glQueryMatrixxOES_t glQueryMatrixxOES; + glDepthRangefOES_t glDepthRangefOES; + glFrustumfOES_t glFrustumfOES; + glOrthofOES_t glOrthofOES; + glClipPlanefOES_t glClipPlanefOES; + glGetClipPlanefOES_t glGetClipPlanefOES; + glClearDepthfOES_t glClearDepthfOES; + glTexGenfOES_t glTexGenfOES; + glTexGenfvOES_t glTexGenfvOES; + glTexGeniOES_t glTexGeniOES; + glTexGenivOES_t glTexGenivOES; + glTexGenxOES_t glTexGenxOES; + glTexGenxvOES_t glTexGenxvOES; + glGetTexGenfvOES_t glGetTexGenfvOES; + glGetTexGenivOES_t glGetTexGenivOES; + glGetTexGenxvOES_t glGetTexGenxvOES; + glBindVertexArrayOES_t glBindVertexArrayOES; + glDeleteVertexArraysOES_t glDeleteVertexArraysOES; + glGenVertexArraysOES_t glGenVertexArraysOES; + glIsVertexArrayOES_t glIsVertexArrayOES; + glDiscardFramebufferEXT_t glDiscardFramebufferEXT; + glMultiDrawArraysEXT_t glMultiDrawArraysEXT; + glMultiDrawElementsEXT_t glMultiDrawElementsEXT; + glClipPlanefIMG_t glClipPlanefIMG; + glClipPlanexIMG_t glClipPlanexIMG; + glRenderbufferStorageMultisampleIMG_t glRenderbufferStorageMultisampleIMG; + glFramebufferTexture2DMultisampleIMG_t glFramebufferTexture2DMultisampleIMG; + glDeleteFencesNV_t glDeleteFencesNV; + glGenFencesNV_t glGenFencesNV; + glIsFenceNV_t glIsFenceNV; + glTestFenceNV_t glTestFenceNV; + glGetFenceivNV_t glGetFenceivNV; + glFinishFenceNV_t glFinishFenceNV; + glSetFenceNV_t glSetFenceNV; + glGetDriverControlsQCOM_t glGetDriverControlsQCOM; + glGetDriverControlStringQCOM_t glGetDriverControlStringQCOM; + glEnableDriverControlQCOM_t glEnableDriverControlQCOM; + glDisableDriverControlQCOM_t glDisableDriverControlQCOM; + glExtGetTexturesQCOM_t glExtGetTexturesQCOM; + glExtGetBuffersQCOM_t glExtGetBuffersQCOM; + glExtGetRenderbuffersQCOM_t glExtGetRenderbuffersQCOM; + glExtGetFramebuffersQCOM_t glExtGetFramebuffersQCOM; + glExtGetTexLevelParameterivQCOM_t glExtGetTexLevelParameterivQCOM; + glExtTexObjectStateOverrideiQCOM_t glExtTexObjectStateOverrideiQCOM; + glExtGetTexSubImageQCOM_t glExtGetTexSubImageQCOM; + glExtGetBufferPointervQCOM_t glExtGetBufferPointervQCOM; + glExtGetShadersQCOM_t glExtGetShadersQCOM; + glExtGetProgramsQCOM_t glExtGetProgramsQCOM; + glExtIsProgramBinaryQCOM_t glExtIsProgramBinaryQCOM; + glExtGetProgramBinarySourceQCOM_t glExtGetProgramBinarySourceQCOM; + glStartTilingQCOM_t glStartTilingQCOM; + glEndTilingQCOM_t glEndTilingQCOM; +}; + +bool init_gl_dispatch(); +void *gl_dispatch_get_proc_func(const char *name, void *userData); + +extern GLDispatch s_gl; +#endif diff --git a/emulator/opengl/host/libs/libOpenglRender/NativeLinuxSubWindow.cpp b/emulator/opengl/host/libs/libOpenglRender/NativeLinuxSubWindow.cpp new file mode 100644 index 0000000..ff335df --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/NativeLinuxSubWindow.cpp @@ -0,0 +1,48 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "NativeSubWindow.h" + +static Bool WaitForMapNotify(Display *d, XEvent *e, char *arg) +{ + if (e->type == MapNotify && e->xmap.window == (Window)arg) { + return 1; + } + return 0; +} + +static Display *s_display = NULL; + +EGLNativeWindowType createSubWindow(FBNativeWindowType p_window, + EGLNativeDisplayType* display_out, + int x, int y,int width, int height){ + + // The call to this function is protected by a lock + // in FrameBuffer so it is safe to check and initialize s_display here + if (!s_display) s_display = XOpenDisplay(NULL); + *display_out = s_display; + + XSetWindowAttributes wa; + wa.event_mask = StructureNotifyMask; + Window win = XCreateWindow(*display_out,p_window,x,y, width,height,0,CopyFromParent,CopyFromParent,CopyFromParent,CWEventMask,&wa); + XMapWindow(*display_out,win); + XEvent e; + XIfEvent(*display_out, &e, WaitForMapNotify, (char *)win); + return win; +} + +void destroySubWindow(EGLNativeDisplayType dis,EGLNativeWindowType win){ + XDestroyWindow(dis, win); +} diff --git a/emulator/opengl/host/libs/libOpenglRender/NativeMacSubWindow.m b/emulator/opengl/host/libs/libOpenglRender/NativeMacSubWindow.m new file mode 100644 index 0000000..f57f661 --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/NativeMacSubWindow.m @@ -0,0 +1,64 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "NativeSubWindow.h" +#include <Cocoa/Cocoa.h> + +/* + * EmuGLView inherit from NSView and override the isOpaque + * method to return YES. That prevents drawing of underlying window/view + * when the view needs to be redrawn. + */ +@interface EmuGLView : NSView { +} @end + +@implementation EmuGLView + + - (BOOL)isOpaque { + return YES; + } + +@end + + +EGLNativeWindowType createSubWindow(FBNativeWindowType p_window, + EGLNativeDisplayType* display_out, + int x, int y,int width, int height){ + NSWindow *win = (NSWindow *)p_window; + if (!win) { + return NULL; + } + + /* (x,y) assume an upper-left origin, but Cocoa uses a lower-left origin */ + NSRect content_rect = [win contentRectForFrameRect:[win frame]]; + int cocoa_y = (int)content_rect.size.height - (y + height); + NSRect contentRect = NSMakeRect(x, cocoa_y, width, height); + + NSView *glView = [[EmuGLView alloc] initWithFrame:contentRect]; + if (glView) { + [[win contentView] addSubview:glView]; + [win makeKeyAndOrderFront:nil]; + } + + return (EGLNativeWindowType)glView; +} + +void destroySubWindow(EGLNativeDisplayType dis,EGLNativeWindowType win){ + if(win){ + NSView *glView = (NSView *)win; + [glView removeFromSuperview]; + [glView release]; + } +} diff --git a/emulator/opengl/host/libs/libOpenglRender/NativeSubWindow.h b/emulator/opengl/host/libs/libOpenglRender/NativeSubWindow.h new file mode 100644 index 0000000..1965978 --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/NativeSubWindow.h @@ -0,0 +1,37 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef NATIVE_SUB_WINDOW_H +#define NATIVE_SUB_WINDOW_H + +#include <EGL/egl.h> +#include "libOpenglRender/render_api_platform_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +EGLNativeWindowType createSubWindow(FBNativeWindowType p_window, + EGLNativeDisplayType* display_out, + int x, int y,int width, int height); + + +void destroySubWindow(EGLNativeDisplayType dis,EGLNativeWindowType win); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/emulator/opengl/host/libs/libOpenglRender/NativeWindowsSubWindow.cpp b/emulator/opengl/host/libs/libOpenglRender/NativeWindowsSubWindow.cpp new file mode 100644 index 0000000..e519b68 --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/NativeWindowsSubWindow.cpp @@ -0,0 +1,57 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "NativeSubWindow.h" +#include <stdio.h> + +LRESULT CALLBACK myWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) +{ + return DefWindowProc(hwnd, uMsg, wParam, lParam); +} + +EGLNativeWindowType createSubWindow(FBNativeWindowType p_window, + EGLNativeDisplayType* display_out, + int x, int y,int width, int height){ + WNDCLASS wc; + wc.style = CS_OWNDC |CS_HREDRAW |CS_VREDRAW; // redraw if size changes + wc.lpfnWndProc = myWndProc; // points to window procedure + wc.cbClsExtra = 0; // no extra class memory + wc.cbWndExtra = sizeof(void*); // save extra window memory, to store VasWindow instance + wc.hInstance = NULL; // handle to instance + wc.hIcon = NULL; // predefined app. icon + wc.hCursor = NULL; + wc.hbrBackground = NULL; // no background brush + wc.lpszMenuName = NULL; // name of menu resource + wc.lpszClassName = "subWin"; // name of window class + + RegisterClass(&wc); + printf("creating window %d %d %d %d\n",x,y,width,height); + EGLNativeWindowType ret = CreateWindowEx( + WS_EX_NOPARENTNOTIFY, // do not bother our parent window + "subWin", + "sub", + WS_CHILD|WS_DISABLED, + x,y,width,height, + p_window, + NULL, + NULL, + NULL); + ShowWindow(ret,SW_SHOW); + return ret; +} + +void destroySubWindow(EGLNativeDisplayType dis,EGLNativeWindowType win){ + PostMessage(win, WM_CLOSE, 0, 0); +} diff --git a/emulator/opengl/host/libs/libOpenglRender/ReadBuffer.cpp b/emulator/opengl/host/libs/libOpenglRender/ReadBuffer.cpp new file mode 100644 index 0000000..837b094 --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/ReadBuffer.cpp @@ -0,0 +1,73 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "ReadBuffer.h" +#include <string.h> +#include <assert.h> +#include <limits.h> +#include "ErrorLog.h" + +ReadBuffer::ReadBuffer(IOStream *stream, size_t bufsize) +{ + m_size = bufsize; + m_stream = stream; + m_buf = (unsigned char*)malloc(m_size*sizeof(unsigned char)); + m_validData = 0; + m_readPtr = m_buf; +} + +ReadBuffer::~ReadBuffer() +{ + free(m_buf); +} + +int ReadBuffer::getData() +{ + if ((m_validData > 0) && (m_readPtr > m_buf)) { + memmove(m_buf, m_readPtr, m_validData); + } + // get fresh data into the buffer; + size_t len = m_size - m_validData; + if (len==0) { + //we need to inc our buffer + size_t new_size = m_size*2; + unsigned char* new_buf; + if (new_size < m_size) { // overflow check + new_size = INT_MAX; + } + + new_buf = (unsigned char*)realloc(m_buf, new_size); + if (!new_buf) { + ERR("Failed to alloc %zu bytes for ReadBuffer\n", new_size); + return -1; + } + m_size = new_size; + m_buf = new_buf; + len = m_size - m_validData; + } + m_readPtr = m_buf; + if (NULL != m_stream->read(m_buf + m_validData, &len)) { + m_validData += len; + return len; + } + return -1; +} + +void ReadBuffer::consume(size_t amount) +{ + assert(amount <= m_validData); + m_validData -= amount; + m_readPtr += amount; +} diff --git a/emulator/opengl/host/libs/libOpenglRender/ReadBuffer.h b/emulator/opengl/host/libs/libOpenglRender/ReadBuffer.h new file mode 100644 index 0000000..f2dfbce --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/ReadBuffer.h @@ -0,0 +1,36 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _READ_BUFFER_H +#define _READ_BUFFER_H + +#include "IOStream.h" + +class ReadBuffer { +public: + ReadBuffer(IOStream *stream, size_t bufSize); + ~ReadBuffer(); + int getData(); // get fresh data from the stream + unsigned char *buf() { return m_readPtr; } // return the next read location + size_t validData() { return m_validData; } // return the amount of valid data in readptr + void consume(size_t amount); // notify that 'amount' data has been consumed; +private: + unsigned char *m_buf; + unsigned char *m_readPtr; + size_t m_size; + size_t m_validData; + IOStream *m_stream; +}; +#endif diff --git a/emulator/opengl/host/libs/libOpenglRender/RenderContext.cpp b/emulator/opengl/host/libs/libOpenglRender/RenderContext.cpp new file mode 100644 index 0000000..f5cbd67 --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/RenderContext.cpp @@ -0,0 +1,76 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "RenderContext.h" +#include "FBConfig.h" +#include "FrameBuffer.h" +#include "EGLDispatch.h" +#include "GLDispatch.h" + +RenderContext *RenderContext::create(int p_config, + RenderContextPtr p_shareContext, + bool p_isGL2) +{ + const FBConfig *fbconf = FBConfig::get(p_config); + if (!fbconf) { + return NULL; + } + + RenderContext *c = new RenderContext(); + if (!c) { + return NULL; + } + + EGLContext share = EGL_NO_CONTEXT; + if (p_shareContext.Ptr() != NULL) { + share = p_shareContext->getEGLContext(); + } + + GLint glContextAttribs[] = { + EGL_CONTEXT_CLIENT_VERSION, 1, + EGL_NONE + }; + + if (p_isGL2) { + glContextAttribs[1] = 2; + c->m_isGL2 = true; + } + + c->m_ctx = s_egl.eglCreateContext(FrameBuffer::getFB()->getDisplay(), + fbconf->getEGLConfig(), share, + glContextAttribs); + + if (c->m_ctx == EGL_NO_CONTEXT) { + delete c; + return NULL; + } + + c->m_config = p_config; + return c; +} + +RenderContext::RenderContext() : + m_ctx(EGL_NO_CONTEXT), + m_config(0), + m_isGL2(false) +{ +} + +RenderContext::~RenderContext() +{ + if (m_ctx != EGL_NO_CONTEXT) { + s_egl.eglDestroyContext(FrameBuffer::getFB()->getDisplay(), m_ctx); + } +} diff --git a/emulator/opengl/host/libs/libOpenglRender/RenderContext.h b/emulator/opengl/host/libs/libOpenglRender/RenderContext.h new file mode 100644 index 0000000..9cbb5fc --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/RenderContext.h @@ -0,0 +1,49 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _LIBRENDER_RENDERCONTEXT_H +#define _LIBRENDER_RENDERCONTEXT_H + +#include "SmartPtr.h" +#include <EGL/egl.h> +#include "GLDecoderContextData.h" + +class RenderContext; +typedef SmartPtr<RenderContext> RenderContextPtr; + +class RenderContext +{ +public: + static RenderContext *create(int p_config, RenderContextPtr p_shareContext, + bool p_isGL2 = false); + ~RenderContext(); + int getConfig() const { return m_config; } + + EGLContext getEGLContext() const { return m_ctx; } + bool isGL2() const { return m_isGL2; } + + GLDecoderContextData & decoderContextData() { return m_contextData; } + +private: + RenderContext(); + +private: + EGLContext m_ctx; + int m_config; + bool m_isGL2; + GLDecoderContextData m_contextData; +}; + +#endif diff --git a/emulator/opengl/host/libs/libOpenglRender/RenderControl.cpp b/emulator/opengl/host/libs/libOpenglRender/RenderControl.cpp new file mode 100644 index 0000000..6b8f8fd --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/RenderControl.cpp @@ -0,0 +1,360 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "renderControl_dec.h" +#include "FrameBuffer.h" +#include "FBConfig.h" +#include "EGLDispatch.h" +#include "GLDispatch.h" +#include "GL2Dispatch.h" +#include "ThreadInfo.h" + +static const GLint rendererVersion = 1; + +static GLint rcGetRendererVersion() +{ + return rendererVersion; +} + +static EGLint rcGetEGLVersion(EGLint* major, EGLint* minor) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + if (!fb) { + return EGL_FALSE; + } + *major = (EGLint)fb->getCaps().eglMajor; + *minor = (EGLint)fb->getCaps().eglMinor; + + return EGL_TRUE; +} + +static EGLint rcQueryEGLString(EGLenum name, void* buffer, EGLint bufferSize) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + if (!fb) { + return 0; + } + + const char *str = s_egl.eglQueryString(fb->getDisplay(), name); + if (!str) { + return 0; + } + + int len = strlen(str) + 1; + if (!buffer || len > bufferSize) { + return -len; + } + + strcpy((char *)buffer, str); + return len; +} + +static EGLint rcGetGLString(EGLenum name, void* buffer, EGLint bufferSize) +{ + RenderThreadInfo *tInfo = getRenderThreadInfo(); + if (!tInfo || !tInfo->currContext.Ptr()) { + return 0; + } + + const char *str = NULL; +#ifdef WITH_GLES2 + if (tInfo->currContext->isGL2()) { + str = (const char *)s_gl2.glGetString(name); + } + else { +#endif + str = (const char *)s_gl.glGetString(name); +#ifdef WITH_GLES2 + } +#endif + + if (!str) { + return 0; + } + + int len = strlen(str) + 1; + if (!buffer || len > bufferSize) { + return -len; + } + + strcpy((char *)buffer, str); + return len; +} + +static EGLint rcGetNumConfigs(uint32_t* numAttribs) +{ + if (numAttribs) { + *numAttribs = FBConfig::getNumAttribs(); + } + return FBConfig::getNumConfigs(); +} + +static EGLint rcGetConfigs(uint32_t bufSize, GLuint* buffer) +{ + int configSize = FBConfig::getNumAttribs(); + int nConfigs = FBConfig::getNumConfigs(); + uint32_t neededSize = (nConfigs + 1) * configSize * sizeof(GLuint); + if (!buffer || bufSize < neededSize) { + return -neededSize; + } + FBConfig::packConfigsInfo(buffer); + return nConfigs; +} + +static EGLint rcChooseConfig(EGLint *attribs, uint32_t attribs_size, uint32_t *configs, uint32_t configs_size) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + if (!fb) { + return 0; + } + + return FBConfig::chooseConfig(fb, attribs, configs, configs_size); +} + +static EGLint rcGetFBParam(EGLint param) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + if (!fb) { + return 0; + } + + EGLint ret = 0; + + switch(param) { + case FB_WIDTH: + ret = fb->getWidth(); + break; + case FB_HEIGHT: + ret = fb->getHeight(); + break; + case FB_XDPI: + ret = 72; // XXX: should be implemented + break; + case FB_YDPI: + ret = 72; // XXX: should be implemented + break; + case FB_FPS: + ret = 60; + break; + case FB_MIN_SWAP_INTERVAL: + ret = 1; // XXX: should be implemented + break; + case FB_MAX_SWAP_INTERVAL: + ret = 1; // XXX: should be implemented + break; + default: + break; + } + + return ret; +} + +static uint32_t rcCreateContext(uint32_t config, + uint32_t share, uint32_t glVersion) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + if (!fb) { + return 0; + } + + HandleType ret = fb->createRenderContext(config, share, glVersion == 2); + return ret; +} + +static void rcDestroyContext(uint32_t context) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + if (!fb) { + return; + } + + fb->DestroyRenderContext(context); +} + +static uint32_t rcCreateWindowSurface(uint32_t config, + uint32_t width, uint32_t height) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + if (!fb) { + return 0; + } + + return fb->createWindowSurface(config, width, height); +} + +static void rcDestroyWindowSurface(uint32_t windowSurface) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + if (!fb) { + return; + } + + fb->DestroyWindowSurface( windowSurface ); +} + +static uint32_t rcCreateColorBuffer(uint32_t width, + uint32_t height, GLenum internalFormat) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + if (!fb) { + return 0; + } + + return fb->createColorBuffer(width, height, internalFormat); +} + +static void rcOpenColorBuffer(uint32_t colorbuffer) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + if (!fb) { + return; + } + fb->openColorBuffer( colorbuffer ); +} + +static void rcCloseColorBuffer(uint32_t colorbuffer) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + if (!fb) { + return; + } + fb->closeColorBuffer( colorbuffer ); +} + +static int rcFlushWindowColorBuffer(uint32_t windowSurface) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + if (!fb) { + return -1; + } + fb->flushWindowSurfaceColorBuffer(windowSurface); + return 0; +} + +static void rcSetWindowColorBuffer(uint32_t windowSurface, + uint32_t colorBuffer) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + if (!fb) { + return; + } + fb->setWindowSurfaceColorBuffer(windowSurface, colorBuffer); +} + +static EGLint rcMakeCurrent(uint32_t context, + uint32_t drawSurf, uint32_t readSurf) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + if (!fb) { + return EGL_FALSE; + } + + bool ret = fb->bindContext(context, drawSurf, readSurf); + + return (ret ? EGL_TRUE : EGL_FALSE); +} + +static void rcFBPost(uint32_t colorBuffer) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + if (!fb) { + return; + } + + fb->post(colorBuffer); +} + +static void rcFBSetSwapInterval(EGLint interval) +{ + // XXX: TBD - should be implemented +} + +static void rcBindTexture(uint32_t colorBuffer) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + if (!fb) { + return; + } + + fb->bindColorBufferToTexture(colorBuffer); +} + +static void rcBindRenderbuffer(uint32_t colorBuffer) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + if (!fb) { + return; + } + + fb->bindColorBufferToRenderbuffer(colorBuffer); +} + +static EGLint rcColorBufferCacheFlush(uint32_t colorBuffer, + EGLint postCount, int forRead) +{ + // XXX: TBD - should be implemented + return 0; +} + +static void rcReadColorBuffer(uint32_t colorBuffer, + GLint x, GLint y, + GLint width, GLint height, + GLenum format, GLenum type, void* pixels) +{ + // XXX: TBD - should be implemented +} + +static int rcUpdateColorBuffer(uint32_t colorBuffer, + GLint x, GLint y, + GLint width, GLint height, + GLenum format, GLenum type, void* pixels) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + if (!fb) { + return -1; + } + + fb->updateColorBuffer(colorBuffer, x, y, width, height, format, type, pixels); + return 0; +} + +void initRenderControlContext(renderControl_decoder_context_t *dec) +{ + dec->set_rcGetRendererVersion(rcGetRendererVersion); + dec->set_rcGetEGLVersion(rcGetEGLVersion); + dec->set_rcQueryEGLString(rcQueryEGLString); + dec->set_rcGetGLString(rcGetGLString); + dec->set_rcGetNumConfigs(rcGetNumConfigs); + dec->set_rcGetConfigs(rcGetConfigs); + dec->set_rcChooseConfig(rcChooseConfig); + dec->set_rcGetFBParam(rcGetFBParam); + dec->set_rcCreateContext(rcCreateContext); + dec->set_rcDestroyContext(rcDestroyContext); + dec->set_rcCreateWindowSurface(rcCreateWindowSurface); + dec->set_rcDestroyWindowSurface(rcDestroyWindowSurface); + dec->set_rcCreateColorBuffer(rcCreateColorBuffer); + dec->set_rcOpenColorBuffer(rcOpenColorBuffer); + dec->set_rcCloseColorBuffer(rcCloseColorBuffer); + dec->set_rcSetWindowColorBuffer(rcSetWindowColorBuffer); + dec->set_rcFlushWindowColorBuffer(rcFlushWindowColorBuffer); + dec->set_rcMakeCurrent(rcMakeCurrent); + dec->set_rcFBPost(rcFBPost); + dec->set_rcFBSetSwapInterval(rcFBSetSwapInterval); + dec->set_rcBindTexture(rcBindTexture); + dec->set_rcBindRenderbuffer(rcBindRenderbuffer); + dec->set_rcColorBufferCacheFlush(rcColorBufferCacheFlush); + dec->set_rcReadColorBuffer(rcReadColorBuffer); + dec->set_rcUpdateColorBuffer(rcUpdateColorBuffer); +} diff --git a/emulator/opengl/host/libs/libOpenglRender/RenderControl.h b/emulator/opengl/host/libs/libOpenglRender/RenderControl.h new file mode 100644 index 0000000..233e809 --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/RenderControl.h @@ -0,0 +1,21 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _RENDER_CONTROL_H +#define _RENDER_CONTROL_H + +void initRenderControlContext(renderControl_decoder_context_t *dec); + +#endif diff --git a/emulator/opengl/host/libs/libOpenglRender/RenderServer.cpp b/emulator/opengl/host/libs/libOpenglRender/RenderServer.cpp new file mode 100644 index 0000000..78f305c --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/RenderServer.cpp @@ -0,0 +1,142 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "RenderServer.h" +#include "TcpStream.h" +#ifdef _WIN32 +#include "Win32PipeStream.h" +#else +#include "UnixStream.h" +#endif +#include "RenderThread.h" +#include "FrameBuffer.h" +#include <set> + +typedef std::set<RenderThread *> RenderThreadsSet; + +RenderServer::RenderServer() : + m_listenSock(NULL), + m_exiting(false) +{ +} + +extern "C" int gRendererStreamMode; + +RenderServer *RenderServer::create(int port) +{ + RenderServer *server = new RenderServer(); + if (!server) { + return NULL; + } + + if (gRendererStreamMode == STREAM_MODE_TCP) { + server->m_listenSock = new TcpStream(); + } else { +#ifdef _WIN32 + server->m_listenSock = new Win32PipeStream(); +#else + server->m_listenSock = new UnixStream(); +#endif + } + + if (server->m_listenSock->listen(port) < 0) { + ERR("RenderServer::create failed to listen on port %d\n", port); + delete server; + return NULL; + } + + return server; +} + +int RenderServer::Main() +{ + RenderThreadsSet threads; + + while(1) { + SocketStream *stream = m_listenSock->accept(); + if (!stream) { + fprintf(stderr,"Error accepting connection, aborting\n"); + break; + } + + unsigned int clientFlags; + if (!stream->readFully(&clientFlags, sizeof(unsigned int))) { + fprintf(stderr,"Error reading clientFlags\n"); + delete stream; + continue; + } + + DBG("\n\n\n\n Got new stream!!!! \n\n\n\n\n"); + // check if we have been requested to exit while waiting on accept + if ((clientFlags & IOSTREAM_CLIENT_EXIT_SERVER) != 0) { + m_exiting = true; + break; + } + + RenderThread *rt = RenderThread::create(stream); + if (!rt) { + fprintf(stderr,"Failed to create RenderThread\n"); + delete stream; + } + + if (!rt->start()) { + fprintf(stderr,"Failed to start RenderThread\n"); + delete stream; + delete rt; + } + + // + // remove from the threads list threads which are + // no longer running + // + for (RenderThreadsSet::iterator n,t = threads.begin(); + t != threads.end(); + t = n) { + // first find next iterator + n = t; + n++; + + // delete and erase the current iterator + // if thread is no longer running + if ((*t)->isFinished()) { + delete (*t); + threads.erase(t); + } + } + + // insert the added thread to the list + threads.insert(rt); + + DBG("Started new RenderThread\n"); + } + + // + // Wait for all threads to finish + // + for (RenderThreadsSet::iterator t = threads.begin(); + t != threads.end(); + t++) { + int exitStatus; + (*t)->wait(&exitStatus); + delete (*t); + } + threads.clear(); + + // + // de-initialize the FrameBuffer object + // + FrameBuffer::finalize(); + return 0; +} diff --git a/emulator/opengl/host/libs/libOpenglRender/RenderServer.h b/emulator/opengl/host/libs/libOpenglRender/RenderServer.h new file mode 100644 index 0000000..98e9890 --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/RenderServer.h @@ -0,0 +1,38 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _LIB_OPENGL_RENDER_RENDER_SERVER_H +#define _LIB_OPENGL_RENDER_RENDER_SERVER_H + +#include "SocketStream.h" +#include "osThread.h" + +class RenderServer : public osUtils::Thread +{ +public: + static RenderServer *create(int port); + virtual int Main(); + + bool isExiting() const { return m_exiting; } + +private: + RenderServer(); + +private: + SocketStream *m_listenSock; + bool m_exiting; +}; + +#endif diff --git a/emulator/opengl/host/libs/libOpenglRender/RenderThread.cpp b/emulator/opengl/host/libs/libOpenglRender/RenderThread.cpp new file mode 100644 index 0000000..0119133 --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/RenderThread.cpp @@ -0,0 +1,162 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "RenderThread.h" +#include "RenderControl.h" +#include "ThreadInfo.h" +#include "ReadBuffer.h" +#include "TimeUtils.h" +#include "GLDispatch.h" +#include "GL2Dispatch.h" +#include "EGLDispatch.h" + +#define STREAM_BUFFER_SIZE 4*1024*1024 + +RenderThread::RenderThread() : + osUtils::Thread(), + m_stream(NULL), + m_finished(false) +{ +} + +RenderThread *RenderThread::create(IOStream *p_stream) +{ + RenderThread *rt = new RenderThread(); + if (!rt) { + return NULL; + } + + rt->m_stream = p_stream; + + return rt; +} + +int RenderThread::Main() +{ + RenderThreadInfo * tInfo = getRenderThreadInfo(); + // + // initialize decoders + // + tInfo->m_glDec.initGL( gl_dispatch_get_proc_func, NULL ); + tInfo->m_gl2Dec.initGL( gl2_dispatch_get_proc_func, NULL ); + initRenderControlContext( &m_rcDec ); + + ReadBuffer readBuf(m_stream, STREAM_BUFFER_SIZE); + + int stats_totalBytes = 0; + long long stats_t0 = GetCurrentTimeMS(); + + // + // open dump file if RENDER_DUMP_DIR is defined + // + const char *dump_dir = getenv("RENDERER_DUMP_DIR"); + FILE *dumpFP = NULL; + if (dump_dir) { + size_t bsize = strlen(dump_dir) + 32; + char *fname = new char[bsize]; + snprintf(fname,bsize,"%s/stream_%p", dump_dir, this); + dumpFP = fopen(fname, "wb"); + if (!dumpFP) { + fprintf(stderr,"Warning: stream dump failed to open file %s\n",fname); + } + delete [] fname; + } + + while (1) { + + int stat = readBuf.getData(); + if (stat <= 0) { + break; + } + + // + // log received bandwidth statistics + // + stats_totalBytes += readBuf.validData(); + long long dt = GetCurrentTimeMS() - stats_t0; + if (dt > 1000) { + float dts = (float)dt / 1000.0f; + //printf("Used Bandwidth %5.3f MB/s\n", ((float)stats_totalBytes / dts) / (1024.0f*1024.0f)); + stats_totalBytes = 0; + stats_t0 = GetCurrentTimeMS(); + } + + // + // dump stream to file if needed + // + if (dumpFP) { + int skip = readBuf.validData() - stat; + fwrite(readBuf.buf()+skip, 1, readBuf.validData()-skip, dumpFP); + fflush(dumpFP); + } + + bool progress; + do { + progress = false; + + // + // try to process some of the command buffer using the GLESv1 decoder + // + size_t last = tInfo->m_glDec.decode(readBuf.buf(), readBuf.validData(), m_stream); + if (last > 0) { + progress = true; + readBuf.consume(last); + } + + // + // try to process some of the command buffer using the GLESv2 decoder + // + last = tInfo->m_gl2Dec.decode(readBuf.buf(), readBuf.validData(), m_stream); + if (last > 0) { + progress = true; + readBuf.consume(last); + } + + // + // try to process some of the command buffer using the + // renderControl decoder + // + last = m_rcDec.decode(readBuf.buf(), readBuf.validData(), m_stream); + if (last > 0) { + readBuf.consume(last); + progress = true; + } + + } while( progress ); + + } + + if (dumpFP) { + fclose(dumpFP); + } + + // + // release the thread from any EGL context + // if bound to context. + // + EGLDisplay eglDpy = s_egl.eglGetCurrentDisplay(); + if (eglDpy != EGL_NO_DISPLAY) { + s_egl.eglMakeCurrent(eglDpy, + EGL_NO_SURFACE, + EGL_NO_SURFACE, + EGL_NO_CONTEXT); + } + + // + // flag that this thread has finished execution + m_finished = true; + + return 0; +} diff --git a/emulator/opengl/host/libs/libOpenglRender/RenderThread.h b/emulator/opengl/host/libs/libOpenglRender/RenderThread.h new file mode 100644 index 0000000..67d423f --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/RenderThread.h @@ -0,0 +1,41 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _LIB_OPENGL_RENDER_RENDER_THREAD_H +#define _LIB_OPENGL_RENDER_RENDER_THREAD_H + +#include "IOStream.h" +#include "GLDecoder.h" +#include "renderControl_dec.h" +#include "osThread.h" + +class RenderThread : public osUtils::Thread +{ +public: + static RenderThread *create(IOStream *p_stream); + + bool isFinished() const { return m_finished; } + +private: + RenderThread(); + virtual int Main(); + +private: + IOStream *m_stream; + renderControl_decoder_context_t m_rcDec; + bool m_finished; +}; + +#endif diff --git a/emulator/opengl/host/libs/libOpenglRender/ThreadInfo.cpp b/emulator/opengl/host/libs/libOpenglRender/ThreadInfo.cpp new file mode 100644 index 0000000..2f2a962 --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/ThreadInfo.cpp @@ -0,0 +1,53 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "ThreadInfo.h" + +#ifdef __linux__ + +static __thread RenderThreadInfo *tinfo = NULL; + +RenderThreadInfo *getRenderThreadInfo() +{ + if (!tinfo) { + tinfo = new RenderThreadInfo(); + } + return tinfo; +} + +#else + +#include <cutils/threads.h> +static thread_store_t s_tls = THREAD_STORE_INITIALIZER; + +static void tlsDestruct(void *ptr) +{ + if (ptr) { + RenderThreadInfo *ti = (RenderThreadInfo *)ptr; + delete ti; + } +} + +RenderThreadInfo *getRenderThreadInfo() +{ + RenderThreadInfo *ti = (RenderThreadInfo *)thread_store_get(&s_tls); + if (!ti) { + ti = new RenderThreadInfo(); + thread_store_set(&s_tls, ti, tlsDestruct); + } + return ti; +} +#endif + diff --git a/emulator/opengl/host/libs/libOpenglRender/ThreadInfo.h b/emulator/opengl/host/libs/libOpenglRender/ThreadInfo.h new file mode 100644 index 0000000..b147290 --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/ThreadInfo.h @@ -0,0 +1,35 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _LIB_OPENGL_RENDER_THREAD_INFO_H +#define _LIB_OPENGL_RENDER_THREAD_INFO_H + +#include "RenderContext.h" +#include "WindowSurface.h" +#include "GLDecoder.h" +#include "GL2Decoder.h" + +struct RenderThreadInfo +{ + RenderContextPtr currContext; + WindowSurfacePtr currDrawSurf; + WindowSurfacePtr currReadSurf; + GLDecoder m_glDec; + GL2Decoder m_gl2Dec; +}; + +RenderThreadInfo *getRenderThreadInfo(); + +#endif diff --git a/emulator/opengl/host/libs/libOpenglRender/WindowSurface.cpp b/emulator/opengl/host/libs/libOpenglRender/WindowSurface.cpp new file mode 100644 index 0000000..3674120 --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/WindowSurface.cpp @@ -0,0 +1,236 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "WindowSurface.h" +#include "FBConfig.h" +#include "FrameBuffer.h" +#include <GLES/glext.h> +#include "EGLDispatch.h" +#include "GLDispatch.h" +#include "GL2Dispatch.h" +#include <stdio.h> +#include <string.h> +#include "GLErrorLog.h" + +WindowSurface::WindowSurface() : + m_fbObj(0), + m_depthRB(0), + m_stencilRB(0), + m_eglSurface(NULL), + m_attachedColorBuffer(NULL), + m_readContext(NULL), + m_drawContext(NULL), + m_width(0), + m_height(0), + m_pbufWidth(0), + m_pbufHeight(0) +{ +} + +WindowSurface::~WindowSurface() +{ + s_egl.eglDestroySurface(FrameBuffer::getFB()->getDisplay(), m_eglSurface); +} + +WindowSurface *WindowSurface::create(int p_config, int p_width, int p_height) +{ + const FBConfig *fbconf = FBConfig::get(p_config); + if (!fbconf) { + return NULL; + } + + // allocate space for the WindowSurface object + WindowSurface *win = new WindowSurface(); + if (!win) { + return NULL; + } + win->m_fbconf = fbconf; + + FrameBuffer *fb = FrameBuffer::getFB(); + const FrameBufferCaps &caps = fb->getCaps(); + + // + // Create a pbuffer to be used as the egl surface + // for that window. + // + if (!win->resizePbuffer(p_width, p_height)) { + delete win; + return NULL; + } + + win->m_width = p_width; + win->m_height = p_height; + + return win; +} + +// +// flushColorBuffer - The function makes sure that the +// previous attached color buffer is updated, if copy or blit should be done +// in order to update it - it is being done here. +// +void WindowSurface::flushColorBuffer() +{ + if (m_attachedColorBuffer.Ptr() != NULL) { + blitToColorBuffer(); + } +} + +// +// setColorBuffer - this function is called when a new color buffer needs to +// be attached to the surface. The function doesn't make sure that the +// previous attached color buffer is updated, this is done by flushColorBuffer +// +void WindowSurface::setColorBuffer(ColorBufferPtr p_colorBuffer) +{ + m_attachedColorBuffer = p_colorBuffer; + + // + // resize the window if the attached color buffer is of different + // size + // + unsigned int cbWidth = m_attachedColorBuffer->getWidth(); + unsigned int cbHeight = m_attachedColorBuffer->getHeight(); + + if (cbWidth != m_width || cbHeight != m_height) { + + if (m_pbufWidth && m_pbufHeight) { + // if we use pbuffer, need to resize it + resizePbuffer(cbWidth, cbHeight); + } + + m_width = cbWidth; + m_height = cbHeight; + } +} + +// +// This function is called after the context and eglSurface is already +// bound in the current thread (eglMakeCurrent has been called). +// This function should take actions required on the other surface objects +// when being bind/unbound +// +void WindowSurface::bind(RenderContextPtr p_ctx, SurfaceBindType p_bindType) +{ + if (p_bindType == SURFACE_BIND_READ) { + m_readContext = p_ctx; + } + else if (p_bindType == SURFACE_BIND_DRAW) { + m_drawContext = p_ctx; + } + else if (p_bindType == SURFACE_BIND_READDRAW) { + m_readContext = p_ctx; + m_drawContext = p_ctx; + } + else { + return; // bad param + } + +} + +void WindowSurface::blitToColorBuffer() +{ + if (!m_width && !m_height) return; + + if (m_attachedColorBuffer->getWidth() != m_width || + m_attachedColorBuffer->getHeight() != m_height) { + // XXX: should never happen - how this needs to be handled? + return; + } + + // + // Make the surface current + // + EGLContext prevContext = s_egl.eglGetCurrentContext(); + EGLSurface prevReadSurf = s_egl.eglGetCurrentSurface(EGL_READ); + EGLSurface prevDrawSurf = s_egl.eglGetCurrentSurface(EGL_DRAW); + FrameBuffer *fb = FrameBuffer::getFB(); + if (!s_egl.eglMakeCurrent(fb->getDisplay(), m_eglSurface, + m_eglSurface, m_drawContext->getEGLContext())) { + return; + } + + m_attachedColorBuffer->blitFromCurrentReadBuffer(); + + // restore current context/surface + s_egl.eglMakeCurrent(fb->getDisplay(), prevDrawSurf, + prevReadSurf, prevContext); + +} + +bool WindowSurface::resizePbuffer(unsigned int p_width, unsigned int p_height) +{ + if (m_eglSurface && + m_pbufWidth == p_width && + m_pbufHeight == p_height) { + // no need to resize + return true; + } + + FrameBuffer *fb = FrameBuffer::getFB(); + + EGLContext prevContext = s_egl.eglGetCurrentContext(); + EGLSurface prevReadSurf = s_egl.eglGetCurrentSurface(EGL_READ); + EGLSurface prevDrawSurf = s_egl.eglGetCurrentSurface(EGL_DRAW); + EGLSurface prevPbuf = m_eglSurface; + bool needRebindContext = m_eglSurface && + (prevReadSurf == m_eglSurface || + prevDrawSurf == m_eglSurface); + + if (needRebindContext) { + s_egl.eglMakeCurrent(fb->getDisplay(), EGL_NO_SURFACE, + EGL_NO_SURFACE, EGL_NO_CONTEXT); + } + + // + // Destroy previous surface + // + if (m_eglSurface) { + s_egl.eglDestroySurface(fb->getDisplay(), m_eglSurface); + m_eglSurface = NULL; + } + + const FrameBufferCaps &caps = fb->getCaps(); + + // + // Create pbuffer surface. + // + EGLint pbufAttribs[5]; + pbufAttribs[0] = EGL_WIDTH; + pbufAttribs[1] = p_width; + pbufAttribs[2] = EGL_HEIGHT; + pbufAttribs[3] = p_height; + pbufAttribs[4] = EGL_NONE; + + m_eglSurface = s_egl.eglCreatePbufferSurface(fb->getDisplay(), + m_fbconf->getEGLConfig(), + pbufAttribs); + if (m_eglSurface == EGL_NO_SURFACE) { + fprintf(stderr, "Renderer error: failed to create/resize pbuffer!!\n"); + return false; + } + + m_pbufWidth = p_width; + m_pbufHeight = p_height; + + if (needRebindContext) { + s_egl.eglMakeCurrent(fb->getDisplay(), + (prevDrawSurf==prevPbuf) ? m_eglSurface : prevDrawSurf, + (prevReadSurf==prevPbuf) ? m_eglSurface : prevReadSurf, + prevContext); + } + + return true; +} diff --git a/emulator/opengl/host/libs/libOpenglRender/WindowSurface.h b/emulator/opengl/host/libs/libOpenglRender/WindowSurface.h new file mode 100644 index 0000000..1b655c9 --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/WindowSurface.h @@ -0,0 +1,71 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _LIBRENDER_WINDOWSURFACE_H +#define _LIBRENDER_WINDOWSURFACE_H + +#include "ColorBuffer.h" +#include "RenderContext.h" +#include "FBConfig.h" +#include "SmartPtr.h" +#include "FixedBuffer.h" +#include <EGL/egl.h> +#include <GLES/gl.h> + +enum SurfaceBindType { + SURFACE_BIND_READ, + SURFACE_BIND_DRAW, + SURFACE_BIND_READDRAW +}; + +class WindowSurface +{ +public: + static WindowSurface *create(int p_config, int p_width, int p_height); + ~WindowSurface(); + EGLSurface getEGLSurface() const { return m_eglSurface; } + + void setColorBuffer(ColorBufferPtr p_colorBuffer); + void flushColorBuffer(); + void bind(RenderContextPtr p_ctx, SurfaceBindType p_bindType); + +private: + WindowSurface(); + + void blitToColorBuffer(); // copy pbuffer content with texload and blit + bool resizePbuffer(unsigned int p_width, unsigned int p_height); + +private: + GLuint m_fbObj; // GLES Framebuffer object (when EGLimage is used) + GLuint m_depthRB; + GLuint m_stencilRB; + EGLSurface m_eglSurface; + ColorBufferPtr m_attachedColorBuffer; + RenderContextPtr m_readContext; + RenderContextPtr m_drawContext; + GLuint m_width; + GLuint m_height; + GLuint m_pbufWidth; + GLuint m_pbufHeight; + bool m_useEGLImage; + bool m_useBindToTexture; + FixedBuffer m_xferBuffer; + FixedBuffer m_xUpdateBuf; + const FBConfig *m_fbconf; +}; + +typedef SmartPtr<WindowSurface> WindowSurfacePtr; + +#endif diff --git a/emulator/opengl/host/libs/libOpenglRender/egl_proc.h b/emulator/opengl/host/libs/libOpenglRender/egl_proc.h new file mode 100644 index 0000000..01dc4ae --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/egl_proc.h @@ -0,0 +1,68 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _EGL_PROC_H +#define _EGL_PROC_H + +#include <EGL/egl.h> +#define EGL_EGLEXT_PROTOTYPES +#include <EGL/eglext.h> + +typedef EGLint (EGLAPIENTRY *eglGetError_t) (); +typedef EGLDisplay (EGLAPIENTRY *eglGetDisplay_t) (EGLNativeDisplayType); +typedef EGLBoolean (EGLAPIENTRY *eglInitialize_t) (EGLDisplay, EGLint*, EGLint*); +typedef EGLBoolean (EGLAPIENTRY *eglTerminate_t) (EGLDisplay); +typedef char* (EGLAPIENTRY *eglQueryString_t) (EGLDisplay, EGLint); +typedef EGLBoolean (EGLAPIENTRY *eglGetConfigs_t) (EGLDisplay, EGLConfig*, EGLint, EGLint*); +typedef EGLBoolean (EGLAPIENTRY *eglChooseConfig_t) (EGLDisplay, const EGLint*, EGLConfig*, EGLint, EGLint*); +typedef EGLBoolean (EGLAPIENTRY *eglGetConfigAttrib_t) (EGLDisplay, EGLConfig, EGLint, EGLint*); +typedef EGLSurface (EGLAPIENTRY *eglCreateWindowSurface_t) (EGLDisplay, EGLConfig, EGLNativeWindowType, const EGLint*); +typedef EGLSurface (EGLAPIENTRY *eglCreatePbufferSurface_t) (EGLDisplay, EGLConfig, const EGLint*); +typedef EGLSurface (EGLAPIENTRY *eglCreatePixmapSurface_t) (EGLDisplay, EGLConfig, EGLNativePixmapType, const EGLint*); +typedef EGLBoolean (EGLAPIENTRY *eglDestroySurface_t) (EGLDisplay, EGLSurface); +typedef EGLBoolean (EGLAPIENTRY *eglQuerySurface_t) (EGLDisplay, EGLSurface, EGLint, EGLint*); +typedef EGLBoolean (EGLAPIENTRY *eglBindAPI_t) (EGLenum); +typedef EGLenum (* eglQueryAPI_t) (); +typedef EGLBoolean (EGLAPIENTRY *eglWaitClient_t) (); +typedef EGLBoolean (EGLAPIENTRY *eglReleaseThread_t) (); +typedef EGLSurface (EGLAPIENTRY *eglCreatePbufferFromClientBuffer_t) (EGLDisplay, EGLenum, EGLClientBuffer, EGLConfig, const EGLint*); +typedef EGLBoolean (EGLAPIENTRY *eglSurfaceAttrib_t) (EGLDisplay, EGLSurface, EGLint, EGLint); +typedef EGLBoolean (EGLAPIENTRY *eglBindTexImage_t) (EGLDisplay, EGLSurface, EGLint); +typedef EGLBoolean (EGLAPIENTRY *eglReleaseTexImage_t) (EGLDisplay, EGLSurface, EGLint); +typedef EGLBoolean (EGLAPIENTRY *eglSwapInterval_t) (EGLDisplay, EGLint); +typedef EGLContext (EGLAPIENTRY *eglCreateContext_t) (EGLDisplay, EGLConfig, EGLContext, const EGLint*); +typedef EGLBoolean (EGLAPIENTRY *eglDestroyContext_t) (EGLDisplay, EGLContext); +typedef EGLBoolean (EGLAPIENTRY *eglMakeCurrent_t) (EGLDisplay, EGLSurface, EGLSurface, EGLContext); +typedef EGLContext (EGLAPIENTRY *eglGetCurrentContext_t) (); +typedef EGLSurface (EGLAPIENTRY *eglGetCurrentSurface_t) (EGLint); +typedef EGLDisplay (EGLAPIENTRY *eglGetCurrentDisplay_t) (); +typedef EGLBoolean (EGLAPIENTRY *eglQueryContext_t) (EGLDisplay, EGLContext, EGLint, EGLint*); +typedef EGLBoolean (EGLAPIENTRY *eglWaitGL_t) (); +typedef EGLBoolean (EGLAPIENTRY *eglWaitNative_t) (EGLint); +typedef EGLBoolean (EGLAPIENTRY *eglSwapBuffers_t) (EGLDisplay, EGLSurface); +typedef EGLBoolean (EGLAPIENTRY *eglCopyBuffers_t) (EGLDisplay, EGLSurface, EGLNativePixmapType); +typedef __eglMustCastToProperFunctionPointerType (EGLAPIENTRY *eglGetProcAddress_t) (const char*); +typedef EGLBoolean (EGLAPIENTRY *eglLockSurfaceKHR_t) (EGLDisplay, EGLSurface, const EGLint*); +typedef EGLBoolean (EGLAPIENTRY *eglUnlockSurfaceKHR_t) (EGLDisplay, EGLSurface); +typedef EGLImageKHR (EGLAPIENTRY *eglCreateImageKHR_t) (EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const EGLint*); +typedef EGLBoolean (EGLAPIENTRY *eglDestroyImageKHR_t) (EGLDisplay, EGLImageKHR image); +typedef EGLSyncKHR (EGLAPIENTRY *eglCreateSyncKHR_t) (EGLDisplay, EGLenum, const EGLint*); +typedef EGLBoolean (EGLAPIENTRY *eglDestroySyncKHR_t) (EGLDisplay, EGLSyncKHR sync); +typedef EGLint (EGLAPIENTRY *eglClientWaitSyncKHR_t) (EGLDisplay, EGLSyncKHR, EGLint, EGLTimeKHR timeout); +typedef EGLBoolean (EGLAPIENTRY *eglSignalSyncKHR_t) (EGLDisplay, EGLSyncKHR, EGLenum); +typedef EGLBoolean (EGLAPIENTRY *eglGetSyncAttribKHR_t) (EGLDisplay, EGLSyncKHR, EGLint, EGLint*); +typedef EGLBoolean (EGLAPIENTRY *eglSetSwapRectangleANDROID_t) (EGLDisplay, EGLSurface, EGLint, EGLint, EGLint, EGLint); + +#endif // of _EGL_PROC_H diff --git a/emulator/opengl/host/libs/libOpenglRender/gl_proc.h b/emulator/opengl/host/libs/libOpenglRender/gl_proc.h new file mode 100644 index 0000000..465a10d --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/gl_proc.h @@ -0,0 +1,296 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _GLES_PROC_H +#define _GLES_PROC_H + +#include <GLES/gl.h> +#define GL_GLEXT_PROTOTYPES +#include <GLES/glext.h> + +typedef void (GL_APIENTRY *glAlphaFunc_t) (GLenum, GLclampf); +typedef void (GL_APIENTRY *glClearColor_t) (GLclampf, GLclampf, GLclampf, GLclampf); +typedef void (GL_APIENTRY *glClearDepthf_t) (GLclampf); +typedef void (GL_APIENTRY *glClipPlanef_t) (GLenum, const GLfloat*); +typedef void (GL_APIENTRY *glColor4f_t) (GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (GL_APIENTRY *glDepthRangef_t) (GLclampf, GLclampf); +typedef void (GL_APIENTRY *glFogf_t) (GLenum, GLfloat); +typedef void (GL_APIENTRY *glFogfv_t) (GLenum, const GLfloat*); +typedef void (GL_APIENTRY *glFrustumf_t) (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (GL_APIENTRY *glGetClipPlanef_t) (GLenum, GLfloat); +typedef void (GL_APIENTRY *glGetFloatv_t) (GLenum, GLfloat*); +typedef void (GL_APIENTRY *glGetLightfv_t) (GLenum, GLenum, GLfloat*); +typedef void (GL_APIENTRY *glGetMaterialfv_t) (GLenum, GLenum, GLfloat*); +typedef void (GL_APIENTRY *glGetTexEnvfv_t) (GLenum, GLenum, GLfloat*); +typedef void (GL_APIENTRY *glGetTexParameterfv_t) (GLenum, GLenum, GLfloat*); +typedef void (GL_APIENTRY *glLightModelf_t) (GLenum, GLfloat); +typedef void (GL_APIENTRY *glLightModelfv_t) (GLenum, const GLfloat*); +typedef void (GL_APIENTRY *glLightf_t) (GLenum, GLenum, GLfloat); +typedef void (GL_APIENTRY *glLightfv_t) (GLenum, GLenum, const GLfloat*); +typedef void (GL_APIENTRY *glLineWidth_t) (GLfloat); +typedef void (GL_APIENTRY *glLoadMatrixf_t) (const GLfloat*); +typedef void (GL_APIENTRY *glMaterialf_t) (GLenum, GLenum, GLfloat); +typedef void (GL_APIENTRY *glMaterialfv_t) (GLenum, GLenum, const GLfloat*); +typedef void (GL_APIENTRY *glMultMatrixf_t) (const GLfloat*); +typedef void (GL_APIENTRY *glMultiTexCoord4f_t) (GLenum, GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (GL_APIENTRY *glNormal3f_t) (GLfloat, GLfloat, GLfloat); +typedef void (GL_APIENTRY *glOrthof_t) (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (GL_APIENTRY *glPointParameterf_t) (GLenum, GLfloat); +typedef void (GL_APIENTRY *glPointParameterfv_t) (GLenum, const GLfloat*); +typedef void (GL_APIENTRY *glPointSize_t) (GLfloat); +typedef void (GL_APIENTRY *glPolygonOffset_t) (GLfloat, GLfloat); +typedef void (GL_APIENTRY *glRotatef_t) (GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (GL_APIENTRY *glScalef_t) (GLfloat, GLfloat, GLfloat); +typedef void (GL_APIENTRY *glTexEnvf_t) (GLenum, GLenum, GLfloat); +typedef void (GL_APIENTRY *glTexEnvfv_t) (GLenum, GLenum, const GLfloat*); +typedef void (GL_APIENTRY *glTexParameterf_t) (GLenum, GLenum, GLfloat); +typedef void (GL_APIENTRY *glTexParameterfv_t) (GLenum, GLenum, const GLfloat*); +typedef void (GL_APIENTRY *glTranslatef_t) (GLfloat, GLfloat, GLfloat); +typedef void (GL_APIENTRY *glActiveTexture_t) (GLenum); +typedef void (GL_APIENTRY *glAlphaFuncx_t) (GLenum, GLclampx); +typedef void (GL_APIENTRY *glBindBuffer_t) (GLenum, GLuint); +typedef void (GL_APIENTRY *glBindTexture_t) (GLenum, GLuint); +typedef void (GL_APIENTRY *glBlendFunc_t) (GLenum, GLenum); +typedef void (GL_APIENTRY *glBufferData_t) (GLenum, GLsizeiptr, const GLvoid*, GLenum); +typedef void (GL_APIENTRY *glBufferSubData_t) (GLenum, GLintptr, GLsizeiptr, const GLvoid*); +typedef void (GL_APIENTRY *glClear_t) (GLbitfield); +typedef void (GL_APIENTRY *glClearColorx_t) (GLclampx, GLclampx, GLclampx, GLclampx); +typedef void (GL_APIENTRY *glClearDepthx_t) (GLclampx); +typedef void (GL_APIENTRY *glClearStencil_t) (GLint); +typedef void (GL_APIENTRY *glClientActiveTexture_t) (GLenum); +typedef void (GL_APIENTRY *glClipPlanex_t) (GLenum, const GLfixed*); +typedef void (GL_APIENTRY *glColor4ub_t) (GLubyte, GLubyte, GLubyte, GLubyte); +typedef void (GL_APIENTRY *glColor4x_t) (GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (GL_APIENTRY *glColorMask_t) (GLboolean, GLboolean, GLboolean, GLboolean); +typedef void (GL_APIENTRY *glColorPointer_t) (GLint, GLenum, GLsizei, const GLvoid*); +typedef void (GL_APIENTRY *glCompressedTexImage2D_t) (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid*); +typedef void (GL_APIENTRY *glCompressedTexSubImage2D_t) (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid*); +typedef void (GL_APIENTRY *glCopyTexImage2D_t) (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLsizei, GLint); +typedef void (GL_APIENTRY *glCopyTexSubImage2D_t) (GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei); +typedef void (GL_APIENTRY *glCullFace_t) (GLenum); +typedef void (GL_APIENTRY *glDeleteBuffers_t) (GLsizei, const GLuint*); +typedef void (GL_APIENTRY *glDeleteTextures_t) (GLsizei, const GLuint*); +typedef void (GL_APIENTRY *glDepthFunc_t) (GLenum); +typedef void (GL_APIENTRY *glDepthMask_t) (GLboolean); +typedef void (GL_APIENTRY *glDepthRangex_t) (GLclampx, GLclampx); +typedef void (GL_APIENTRY *glDisable_t) (GLenum); +typedef void (GL_APIENTRY *glDisableClientState_t) (GLenum); +typedef void (GL_APIENTRY *glDrawArrays_t) (GLenum, GLint, GLsizei); +typedef void (GL_APIENTRY *glDrawElements_t) (GLenum, GLsizei, GLenum, const GLvoid*); +typedef void (GL_APIENTRY *glEnable_t) (GLenum); +typedef void (GL_APIENTRY *glEnableClientState_t) (GLenum); +typedef void (GL_APIENTRY *glFinish_t) (); +typedef void (GL_APIENTRY *glFlush_t) (); +typedef void (GL_APIENTRY *glFogx_t) (GLenum, GLfixed); +typedef void (GL_APIENTRY *glFogxv_t) (GLenum, const GLfixed*); +typedef void (GL_APIENTRY *glFrontFace_t) (GLenum); +typedef void (GL_APIENTRY *glFrustumx_t) (GLfixed, GLfixed, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (GL_APIENTRY *glGetBooleanv_t) (GLenum, GLboolean*); +typedef void (GL_APIENTRY *glGetBufferParameteriv_t) (GLenum, GLenum, GLint*); +typedef void (GL_APIENTRY *glGetClipPlanex_t) (GLenum, GLfixed); +typedef void (GL_APIENTRY *glGenBuffers_t) (GLsizei, GLuint*); +typedef void (GL_APIENTRY *glGenTextures_t) (GLsizei, GLuint*); +typedef GLenum (GL_APIENTRY *glGetError_t) (); +typedef void (GL_APIENTRY *glGetFixedv_t) (GLenum, GLfixed*); +typedef void (GL_APIENTRY *glGetIntegerv_t) (GLenum, GLint*); +typedef void (GL_APIENTRY *glGetLightxv_t) (GLenum, GLenum, GLfixed*); +typedef void (GL_APIENTRY *glGetMaterialxv_t) (GLenum, GLenum, GLfixed*); +typedef void (GL_APIENTRY *glGetPointerv_t) (GLenum, GLvoid*); +typedef const GLubyte* (GL_APIENTRY *glGetString_t) (GLenum); +typedef void (GL_APIENTRY *glGetTexEnviv_t) (GLenum, GLenum, GLint*); +typedef void (GL_APIENTRY *glGetTexEnvxv_t) (GLenum, GLenum, GLfixed*); +typedef void (GL_APIENTRY *glGetTexParameteriv_t) (GLenum, GLenum, GLint*); +typedef void (GL_APIENTRY *glGetTexParameterxv_t) (GLenum, GLenum, GLfixed*); +typedef void (GL_APIENTRY *glHint_t) (GLenum, GLenum); +typedef GLboolean (GL_APIENTRY *glIsBuffer_t) (GLuint); +typedef GLboolean (GL_APIENTRY *glIsEnabled_t) (GLenum); +typedef GLboolean (GL_APIENTRY *glIsTexture_t) (GLuint); +typedef void (GL_APIENTRY *glLightModelx_t) (GLenum, GLfixed); +typedef void (GL_APIENTRY *glLightModelxv_t) (GLenum, const GLfixed*); +typedef void (GL_APIENTRY *glLightx_t) (GLenum, GLenum, GLfixed); +typedef void (GL_APIENTRY *glLightxv_t) (GLenum, GLenum, const GLfixed*); +typedef void (GL_APIENTRY *glLineWidthx_t) (GLfixed); +typedef void (GL_APIENTRY *glLoadIdentity_t) (); +typedef void (GL_APIENTRY *glLoadMatrixx_t) (const GLfixed*); +typedef void (GL_APIENTRY *glLogicOp_t) (GLenum); +typedef void (GL_APIENTRY *glMaterialx_t) (GLenum, GLenum, GLfixed); +typedef void (GL_APIENTRY *glMaterialxv_t) (GLenum, GLenum, const GLfixed*); +typedef void (GL_APIENTRY *glMatrixMode_t) (GLenum); +typedef void (GL_APIENTRY *glMultMatrixx_t) (const GLfixed*); +typedef void (GL_APIENTRY *glMultiTexCoord4x_t) (GLenum, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (GL_APIENTRY *glNormal3x_t) (GLfixed, GLfixed, GLfixed); +typedef void (GL_APIENTRY *glNormalPointer_t) (GLenum, GLsizei, const GLvoid*); +typedef void (GL_APIENTRY *glOrthox_t) (GLfixed, GLfixed, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (GL_APIENTRY *glPixelStorei_t) (GLenum, GLint); +typedef void (GL_APIENTRY *glPointParameterx_t) (GLenum, GLfixed); +typedef void (GL_APIENTRY *glPointParameterxv_t) (GLenum, const GLfixed*); +typedef void (GL_APIENTRY *glPointSizex_t) (GLfixed); +typedef void (GL_APIENTRY *glPolygonOffsetx_t) (GLfixed, GLfixed); +typedef void (GL_APIENTRY *glPopMatrix_t) (); +typedef void (GL_APIENTRY *glPushMatrix_t) (); +typedef void (GL_APIENTRY *glReadPixels_t) (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid*); +typedef void (GL_APIENTRY *glRotatex_t) (GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (GL_APIENTRY *glSampleCoverage_t) (GLclampf, GLboolean); +typedef void (GL_APIENTRY *glSampleCoveragex_t) (GLclampx, GLboolean); +typedef void (GL_APIENTRY *glScalex_t) (GLfixed, GLfixed, GLfixed); +typedef void (GL_APIENTRY *glScissor_t) (GLint, GLint, GLsizei, GLsizei); +typedef void (GL_APIENTRY *glShadeModel_t) (GLenum); +typedef void (GL_APIENTRY *glStencilFunc_t) (GLenum, GLint, GLuint); +typedef void (GL_APIENTRY *glStencilMask_t) (GLuint); +typedef void (GL_APIENTRY *glStencilOp_t) (GLenum, GLenum, GLenum); +typedef void (GL_APIENTRY *glTexCoordPointer_t) (GLint, GLenum, GLsizei, const GLvoid*); +typedef void (GL_APIENTRY *glTexEnvi_t) (GLenum, GLenum, GLint); +typedef void (GL_APIENTRY *glTexEnvx_t) (GLenum, GLenum, GLfixed); +typedef void (GL_APIENTRY *glTexEnviv_t) (GLenum, GLenum, const GLint*); +typedef void (GL_APIENTRY *glTexEnvxv_t) (GLenum, GLenum, const GLfixed*); +typedef void (GL_APIENTRY *glTexImage2D_t) (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid*); +typedef void (GL_APIENTRY *glTexParameteri_t) (GLenum, GLenum, GLint); +typedef void (GL_APIENTRY *glTexParameterx_t) (GLenum, GLenum, GLfixed); +typedef void (GL_APIENTRY *glTexParameteriv_t) (GLenum, GLenum, const GLint*); +typedef void (GL_APIENTRY *glTexParameterxv_t) (GLenum, GLenum, const GLfixed*); +typedef void (GL_APIENTRY *glTexSubImage2D_t) (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid*); +typedef void (GL_APIENTRY *glTranslatex_t) (GLfixed, GLfixed, GLfixed); +typedef void (GL_APIENTRY *glVertexPointer_t) (GLint, GLenum, GLsizei, const GLvoid*); +typedef void (GL_APIENTRY *glViewport_t) (GLint, GLint, GLsizei, GLsizei); +typedef void (GL_APIENTRY *glPointSizePointerOES_t) (GLenum, GLsizei, const GLvoid*); +typedef void (GL_APIENTRY *glBlendEquationSeparateOES_t) (GLenum, GLenum); +typedef void (GL_APIENTRY *glBlendFuncSeparateOES_t) (GLenum, GLenum, GLenum, GLenum); +typedef void (GL_APIENTRY *glBlendEquationOES_t) (GLenum); +typedef void (GL_APIENTRY *glDrawTexsOES_t) (GLshort, GLshort, GLshort, GLshort, GLshort); +typedef void (GL_APIENTRY *glDrawTexiOES_t) (GLint, GLint, GLint, GLint, GLint); +typedef void (GL_APIENTRY *glDrawTexxOES_t) (GLfixed, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (GL_APIENTRY *glDrawTexsvOES_t) (const GLshort*); +typedef void (GL_APIENTRY *glDrawTexivOES_t) (const GLint*); +typedef void (GL_APIENTRY *glDrawTexxvOES_t) (const GLfixed*); +typedef void (GL_APIENTRY *glDrawTexfOES_t) (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (GL_APIENTRY *glDrawTexfvOES_t) (const GLfloat*); +typedef void (GL_APIENTRY *glEGLImageTargetTexture2DOES_t) (GLenum, GLeglImageOES); +typedef void (GL_APIENTRY *glEGLImageTargetRenderbufferStorageOES_t) (GLenum, GLeglImageOES); +typedef void (GL_APIENTRY *glAlphaFuncxOES_t) (GLenum, GLclampx); +typedef void (GL_APIENTRY *glClearColorxOES_t) (GLclampx, GLclampx, GLclampx, GLclampx); +typedef void (GL_APIENTRY *glClearDepthxOES_t) (GLclampx); +typedef void (GL_APIENTRY *glClipPlanexOES_t) (GLenum, const GLfixed*); +typedef void (GL_APIENTRY *glColor4xOES_t) (GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (GL_APIENTRY *glDepthRangexOES_t) (GLclampx, GLclampx); +typedef void (GL_APIENTRY *glFogxOES_t) (GLenum, GLfixed); +typedef void (GL_APIENTRY *glFogxvOES_t) (GLenum, const GLfixed*); +typedef void (GL_APIENTRY *glFrustumxOES_t) (GLfixed, GLfixed, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (GL_APIENTRY *glGetClipPlanexOES_t) (GLenum, GLfixed); +typedef void (GL_APIENTRY *glGetFixedvOES_t) (GLenum, GLfixed*); +typedef void (GL_APIENTRY *glGetLightxvOES_t) (GLenum, GLenum, GLfixed*); +typedef void (GL_APIENTRY *glGetMaterialxvOES_t) (GLenum, GLenum, GLfixed*); +typedef void (GL_APIENTRY *glGetTexEnvxvOES_t) (GLenum, GLenum, GLfixed*); +typedef void (GL_APIENTRY *glGetTexParameterxvOES_t) (GLenum, GLenum, GLfixed*); +typedef void (GL_APIENTRY *glLightModelxOES_t) (GLenum, GLfixed); +typedef void (GL_APIENTRY *glLightModelxvOES_t) (GLenum, const GLfixed*); +typedef void (GL_APIENTRY *glLightxOES_t) (GLenum, GLenum, GLfixed); +typedef void (GL_APIENTRY *glLightxvOES_t) (GLenum, GLenum, const GLfixed*); +typedef void (GL_APIENTRY *glLineWidthxOES_t) (GLfixed); +typedef void (GL_APIENTRY *glLoadMatrixxOES_t) (const GLfixed*); +typedef void (GL_APIENTRY *glMaterialxOES_t) (GLenum, GLenum, GLfixed); +typedef void (GL_APIENTRY *glMaterialxvOES_t) (GLenum, GLenum, const GLfixed*); +typedef void (GL_APIENTRY *glMultMatrixxOES_t) (const GLfixed*); +typedef void (GL_APIENTRY *glMultiTexCoord4xOES_t) (GLenum, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (GL_APIENTRY *glNormal3xOES_t) (GLfixed, GLfixed, GLfixed); +typedef void (GL_APIENTRY *glOrthoxOES_t) (GLfixed, GLfixed, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (GL_APIENTRY *glPointParameterxOES_t) (GLenum, GLfixed); +typedef void (GL_APIENTRY *glPointParameterxvOES_t) (GLenum, const GLfixed*); +typedef void (GL_APIENTRY *glPointSizexOES_t) (GLfixed); +typedef void (GL_APIENTRY *glPolygonOffsetxOES_t) (GLfixed, GLfixed); +typedef void (GL_APIENTRY *glRotatexOES_t) (GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (GL_APIENTRY *glSampleCoveragexOES_t) (GLclampx, GLboolean); +typedef void (GL_APIENTRY *glScalexOES_t) (GLfixed, GLfixed, GLfixed); +typedef void (GL_APIENTRY *glTexEnvxOES_t) (GLenum, GLenum, GLfixed); +typedef void (GL_APIENTRY *glTexEnvxvOES_t) (GLenum, GLenum, const GLfixed*); +typedef void (GL_APIENTRY *glTexParameterxOES_t) (GLenum, GLenum, GLfixed); +typedef void (GL_APIENTRY *glTexParameterxvOES_t) (GLenum, GLenum, const GLfixed*); +typedef void (GL_APIENTRY *glTranslatexOES_t) (GLfixed, GLfixed, GLfixed); +typedef GLboolean (GL_APIENTRY *glIsRenderbufferOES_t) (GLuint); +typedef void (GL_APIENTRY *glBindRenderbufferOES_t) (GLenum, GLuint); +typedef void (GL_APIENTRY *glDeleteRenderbuffersOES_t) (GLsizei, const GLuint*); +typedef void (GL_APIENTRY *glGenRenderbuffersOES_t) (GLsizei, GLuint*); +typedef void (GL_APIENTRY *glRenderbufferStorageOES_t) (GLenum, GLenum, GLsizei, GLsizei); +typedef void (GL_APIENTRY *glGetRenderbufferParameterivOES_t) (GLenum, GLenum, GLint*); +typedef GLboolean (GL_APIENTRY *glIsFramebufferOES_t) (GLuint); +typedef void (GL_APIENTRY *glBindFramebufferOES_t) (GLenum, GLuint); +typedef void (GL_APIENTRY *glDeleteFramebuffersOES_t) (GLsizei, const GLuint*); +typedef void (GL_APIENTRY *glGenFramebuffersOES_t) (GLsizei, GLuint*); +typedef GLenum (GL_APIENTRY *glCheckFramebufferStatusOES_t) (GLenum); +typedef void (GL_APIENTRY *glFramebufferRenderbufferOES_t) (GLenum, GLenum, GLenum, GLuint); +typedef void (GL_APIENTRY *glFramebufferTexture2DOES_t) (GLenum, GLenum, GLenum, GLuint, GLint); +typedef void (GL_APIENTRY *glGetFramebufferAttachmentParameterivOES_t) (GLenum, GLenum, GLenum, GLint*); +typedef void (GL_APIENTRY *glGenerateMipmapOES_t) (GLenum); +typedef void* (GL_APIENTRY *glMapBufferOES_t) (GLenum, GLenum); +typedef GLboolean (GL_APIENTRY *glUnmapBufferOES_t) (GLenum); +typedef void (GL_APIENTRY *glGetBufferPointervOES_t) (GLenum, GLenum, GLvoid*); +typedef void (GL_APIENTRY *glCurrentPaletteMatrixOES_t) (GLuint); +typedef void (GL_APIENTRY *glLoadPaletteFromModelViewMatrixOES_t) (); +typedef void (GL_APIENTRY *glMatrixIndexPointerOES_t) (GLint, GLenum, GLsizei, const GLvoid*); +typedef void (GL_APIENTRY *glWeightPointerOES_t) (GLint, GLenum, GLsizei, const GLvoid*); +typedef GLbitfield (GL_APIENTRY *glQueryMatrixxOES_t) (GLfixed, GLint); +typedef void (GL_APIENTRY *glDepthRangefOES_t) (GLclampf, GLclampf); +typedef void (GL_APIENTRY *glFrustumfOES_t) (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (GL_APIENTRY *glOrthofOES_t) (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (GL_APIENTRY *glClipPlanefOES_t) (GLenum, const GLfloat*); +typedef void (GL_APIENTRY *glGetClipPlanefOES_t) (GLenum, GLfloat); +typedef void (GL_APIENTRY *glClearDepthfOES_t) (GLclampf); +typedef void (GL_APIENTRY *glTexGenfOES_t) (GLenum, GLenum, GLfloat); +typedef void (GL_APIENTRY *glTexGenfvOES_t) (GLenum, GLenum, const GLfloat*); +typedef void (GL_APIENTRY *glTexGeniOES_t) (GLenum, GLenum, GLint); +typedef void (GL_APIENTRY *glTexGenivOES_t) (GLenum, GLenum, const GLint*); +typedef void (GL_APIENTRY *glTexGenxOES_t) (GLenum, GLenum, GLfixed); +typedef void (GL_APIENTRY *glTexGenxvOES_t) (GLenum, GLenum, const GLfixed*); +typedef void (GL_APIENTRY *glGetTexGenfvOES_t) (GLenum, GLenum, GLfloat*); +typedef void (GL_APIENTRY *glGetTexGenivOES_t) (GLenum, GLenum, GLint*); +typedef void (GL_APIENTRY *glGetTexGenxvOES_t) (GLenum, GLenum, GLfixed*); +typedef void (GL_APIENTRY *glBindVertexArrayOES_t) (GLuint); +typedef void (GL_APIENTRY *glDeleteVertexArraysOES_t) (GLsizei, const GLuint*); +typedef void (GL_APIENTRY *glGenVertexArraysOES_t) (GLsizei, GLuint*); +typedef GLboolean (GL_APIENTRY *glIsVertexArrayOES_t) (GLuint); +typedef void (GL_APIENTRY *glDiscardFramebufferEXT_t) (GLenum, GLsizei, const GLenum*); +typedef void (GL_APIENTRY *glMultiDrawArraysEXT_t) (GLenum, GLint*, GLsizei*, GLsizei); +typedef void (GL_APIENTRY *glMultiDrawElementsEXT_t) (GLenum, const GLsizei*, GLenum, const GLvoid**, GLsizei); +typedef void (GL_APIENTRY *glClipPlanefIMG_t) (GLenum, const GLfloat*); +typedef void (GL_APIENTRY *glClipPlanexIMG_t) (GLenum, const GLfixed*); +typedef void (GL_APIENTRY *glRenderbufferStorageMultisampleIMG_t) (GLenum, GLsizei, GLenum, GLsizei, GLsizei); +typedef void (GL_APIENTRY *glFramebufferTexture2DMultisampleIMG_t) (GLenum, GLenum, GLenum, GLuint, GLint, GLsizei); +typedef void (GL_APIENTRY *glDeleteFencesNV_t) (GLsizei, const GLuint*); +typedef void (GL_APIENTRY *glGenFencesNV_t) (GLsizei, GLuint*); +typedef GLboolean (GL_APIENTRY *glIsFenceNV_t) (GLuint); +typedef GLboolean (GL_APIENTRY *glTestFenceNV_t) (GLuint); +typedef void (GL_APIENTRY *glGetFenceivNV_t) (GLuint, GLenum, GLint*); +typedef void (GL_APIENTRY *glFinishFenceNV_t) (GLuint); +typedef void (GL_APIENTRY *glSetFenceNV_t) (GLuint, GLenum); +typedef void (GL_APIENTRY *glGetDriverControlsQCOM_t) (GLint*, GLsizei, GLuint*); +typedef void (GL_APIENTRY *glGetDriverControlStringQCOM_t) (GLuint, GLsizei, GLsizei*, GLchar*); +typedef void (GL_APIENTRY *glEnableDriverControlQCOM_t) (GLuint); +typedef void (GL_APIENTRY *glDisableDriverControlQCOM_t) (GLuint); +typedef void (GL_APIENTRY *glExtGetTexturesQCOM_t) (GLuint*, GLint, GLint*); +typedef void (GL_APIENTRY *glExtGetBuffersQCOM_t) (GLuint*, GLint, GLint*); +typedef void (GL_APIENTRY *glExtGetRenderbuffersQCOM_t) (GLuint*, GLint, GLint*); +typedef void (GL_APIENTRY *glExtGetFramebuffersQCOM_t) (GLuint*, GLint, GLint*); +typedef void (GL_APIENTRY *glExtGetTexLevelParameterivQCOM_t) (GLuint, GLenum, GLint, GLenum, GLint*); +typedef void (GL_APIENTRY *glExtTexObjectStateOverrideiQCOM_t) (GLenum, GLenum, GLint); +typedef void (GL_APIENTRY *glExtGetTexSubImageQCOM_t) (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, GLvoid*); +typedef void (GL_APIENTRY *glExtGetBufferPointervQCOM_t) (GLenum, GLvoid*); +typedef void (GL_APIENTRY *glExtGetShadersQCOM_t) (GLuint*, GLint, GLint*); +typedef void (GL_APIENTRY *glExtGetProgramsQCOM_t) (GLuint*, GLint, GLint*); +typedef GLboolean (GL_APIENTRY *glExtIsProgramBinaryQCOM_t) (GLuint); +typedef void (GL_APIENTRY *glExtGetProgramBinarySourceQCOM_t) (GLuint, GLenum, GLchar*, GLint*); +typedef void (GL_APIENTRY *glStartTilingQCOM_t) (GLuint, GLuint, GLuint, GLuint, GLbitfield); +typedef void (GL_APIENTRY *glEndTilingQCOM_t) (GLbitfield); + + +#endif diff --git a/emulator/opengl/host/libs/libOpenglRender/render_api.cpp b/emulator/opengl/host/libs/libOpenglRender/render_api.cpp new file mode 100644 index 0000000..c8d3e06 --- /dev/null +++ b/emulator/opengl/host/libs/libOpenglRender/render_api.cpp @@ -0,0 +1,359 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "libOpenglRender/render_api.h" +#include "IOStream.h" +#include "FrameBuffer.h" +#include "RenderServer.h" +#include "osProcess.h" +#include "TimeUtils.h" + +#include "TcpStream.h" +#ifdef _WIN32 +#include "Win32PipeStream.h" +#else +#include "UnixStream.h" +#endif + +#include "EGLDispatch.h" +#include "GLDispatch.h" +#include "GL2Dispatch.h" + +static osUtils::childProcess *s_renderProc = NULL; +static RenderServer *s_renderThread = NULL; +static int s_renderPort = 0; + +static IOStream *createRenderThread(int p_stream_buffer_size, + unsigned int clientFlags); + +// +// For now run the renderer as a thread inside the calling +// process instead as running it in a separate process for all +// platforms. +// at the future we want it to run as a seperate process except for +// Mac OS X since it is imposibble on this platform to make one process +// render to a window created by another process. +// +//#ifdef __APPLE__ +#define RENDER_API_USE_THREAD +//#endif + +bool initLibrary(void) +{ + // + // Load EGL Plugin + // + if (!init_egl_dispatch()) { + // Failed to load EGL + printf("Failed to init_egl_dispatch\n"); + return false; + } + + // + // Load GLES Plugin + // + if (!init_gl_dispatch()) { + // Failed to load GLES + ERR("Failed to init_gl_dispatch\n"); + return false; + } + + /* failure to init the GLES2 dispatch table is not fatal */ + init_gl2_dispatch(); + + return true; +} + +bool initOpenGLRenderer(int width, int height, int portNum, + OnPostFn onPost, void* onPostContext) +{ + + // + // Fail if renderer is already initialized + // + if (s_renderProc || s_renderThread) { + return false; + } + + s_renderPort = portNum; + +#ifdef RENDER_API_USE_THREAD // should be defined for mac + // + // initialize the renderer and listen to connections + // on a thread in the current process. + // + bool inited = FrameBuffer::initialize(width, height, onPost, onPostContext); + if (!inited) { + return false; + } + + s_renderThread = RenderServer::create(portNum); + if (!s_renderThread) { + return false; + } + + s_renderThread->start(); + +#else + if (onPost) { + // onPost callback not supported with separate renderer process. + // + // If we ever revive separate process support, we could make the choice + // between thread and process at runtime instead of compile time, and + // choose the thread path if an onPost callback is requested. Or, the + // callback could be supported with a separate process using shmem or + // other IPC mechanism. + return false; + } + + // + // Launch emulator_renderer + // + char cmdLine[128]; + snprintf(cmdLine, 128, "emulator_renderer -windowid %d -port %d -x %d -y %d -width %d -height %d", + (int)window, portNum, x, y, width, height); + + s_renderProc = osUtils::childProcess::create(cmdLine, NULL); + if (!s_renderProc) { + return false; + } + + // + // try to connect to the renderer in order to check it + // was successfully initialized. + // + int nTrys = 0; + IOStream *dummy = NULL; + do { + ++nTrys; + + // + // Wait a bit to make the renderer process a chance to be + // initialized. + // On Windows we need during this time to handle windows + // events since the renderer generates a subwindow of this + // process's window, we need to be responsive for windows + // during this time to let the renderer generates this subwindow. + // +#ifndef _WIN32 + TimeSleepMS(300); +#else + long long t0 = GetCurrentTimeMS(); + while( (GetCurrentTimeMS() - t0) < 300 ) { + MSG msg; + int n = 0; + while( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) + { + n++; + TranslateMessage( &msg ); + DispatchMessage( &msg ); + } + if (n == 0) TimeSleepMS(10); + } +#endif + + dummy = createRenderThread(8, 0); + + if (!dummy) { + // stop if the process is no longer running + if (!osUtils::isProcessRunning(s_renderProc->getPID())) { + break; + } + } + } while(!dummy && nTrys < 10); // give up after 3 seconds, XXX: ??? + + if (!dummy) { + // + // Failed - make sure the process is killed + // + osUtils::KillProcess(s_renderProc->getPID(), true); + delete s_renderProc; + s_renderProc = NULL; + return false; + } + + // destroy the dummy connection + delete dummy; +#endif + + return true; +} + +bool stopOpenGLRenderer() +{ + bool ret = false; + + // open a dummy connection to the renderer to make it + // realize the exit request. + // (send the exit request in clientFlags) + IOStream *dummy = createRenderThread(8, IOSTREAM_CLIENT_EXIT_SERVER); + if (!dummy) return false; + + if (s_renderProc) { + // + // wait for the process to exit + // + int exitStatus; + ret = s_renderProc->wait(&exitStatus); + + delete s_renderProc; + s_renderProc = NULL; + } + else if (s_renderThread) { + + // wait for the thread to exit + int status; + ret = s_renderThread->wait(&status); + + delete s_renderThread; + s_renderThread = NULL; + } + + return ret; +} + +bool createOpenGLSubwindow(FBNativeWindowType window, + int x, int y, int width, int height, float zRot) +{ + if (s_renderThread) { + return FrameBuffer::setupSubWindow(window,x,y,width,height, zRot); + } + else { + // + // XXX: should be implemented by sending the renderer process + // a request + ERR("%s not implemented for separate renderer process !!!\n", + __FUNCTION__); + } + return false; +} + +bool destroyOpenGLSubwindow() +{ + if (s_renderThread) { + return FrameBuffer::removeSubWindow(); + } + else { + // + // XXX: should be implemented by sending the renderer process + // a request + ERR("%s not implemented for separate renderer process !!!\n", + __FUNCTION__); + return false; + } +} + +void setOpenGLDisplayRotation(float zRot) +{ + if (s_renderThread) { + FrameBuffer *fb = FrameBuffer::getFB(); + if (fb) { + fb->setDisplayRotation(zRot); + } + } + else { + // + // XXX: should be implemented by sending the renderer process + // a request + ERR("%s not implemented for separate renderer process !!!\n", + __FUNCTION__); + } +} + +void repaintOpenGLDisplay() +{ + if (s_renderThread) { + FrameBuffer *fb = FrameBuffer::getFB(); + if (fb) { + fb->repost(); + } + } + else { + // + // XXX: should be implemented by sending the renderer process + // a request + ERR("%s not implemented for separate renderer process !!!\n", + __FUNCTION__); + } +} + + +/* NOTE: For now, always use TCP mode by default, until the emulator + * has been updated to support Unix and Win32 pipes + */ +#define DEFAULT_STREAM_MODE STREAM_MODE_TCP + +int gRendererStreamMode = DEFAULT_STREAM_MODE; + +IOStream *createRenderThread(int p_stream_buffer_size, unsigned int clientFlags) +{ + SocketStream* stream = NULL; + + if (gRendererStreamMode == STREAM_MODE_TCP) { + stream = new TcpStream(p_stream_buffer_size); + } else { +#ifdef _WIN32 + stream = new Win32PipeStream(p_stream_buffer_size); +#else /* !_WIN32 */ + stream = new UnixStream(p_stream_buffer_size); +#endif + } + + if (!stream) { + ERR("createRenderThread failed to create stream\n"); + return NULL; + } + if (stream->connect(s_renderPort) < 0) { + ERR("createRenderThread failed to connect\n"); + delete stream; + return NULL; + } + + // + // send clientFlags to the renderer + // + unsigned int *pClientFlags = + (unsigned int *)stream->allocBuffer(sizeof(unsigned int)); + *pClientFlags = clientFlags; + stream->commitBuffer(sizeof(unsigned int)); + + return stream; +} + +int +setStreamMode(int mode) +{ + switch (mode) { + case STREAM_MODE_DEFAULT: + mode = DEFAULT_STREAM_MODE; + break; + + case STREAM_MODE_TCP: + break; + +#ifndef _WIN32 + case STREAM_MODE_UNIX: + break; +#else /* _WIN32 */ + case STREAM_MODE_PIPE: + break; +#endif /* _WIN32 */ + default: + // Invalid stream mode + return -1; + } + gRendererStreamMode = mode; + return 0; +} diff --git a/emulator/opengl/host/libs/renderControl_dec/Android.mk b/emulator/opengl/host/libs/renderControl_dec/Android.mk new file mode 100644 index 0000000..3253a34 --- /dev/null +++ b/emulator/opengl/host/libs/renderControl_dec/Android.mk @@ -0,0 +1,19 @@ +LOCAL_PATH := $(call my-dir) + + +### host library ############################################ +$(call emugl-begin-host-static-library,lib_renderControl_dec) +$(call emugl-import,libOpenglCodecCommon) +$(call emugl-gen-decoder,$(EMUGL_PATH)/system/renderControl_enc,renderControl) +# For renderControl_types.h +$(call emugl-export,C_INCLUDES,$(EMUGL_PATH)/system/renderControl_enc) +$(call emugl-end-module) + +### host library, 64-bit #################################### +$(call emugl-begin-host-static-library,lib64_renderControl_dec) +$(call emugl-import,lib64OpenglCodecCommon) +$(call emugl-gen-decoder,$(EMUGL_PATH)/system/renderControl_enc,renderControl) +# For renderControl_types.h +$(call emugl-export,C_INCLUDES,$(EMUGL_PATH)/system/renderControl_enc) +$(call emugl-export,CFLAGS,-m64) +$(call emugl-end-module) diff --git a/emulator/opengl/host/renderer/Android.mk b/emulator/opengl/host/renderer/Android.mk new file mode 100644 index 0000000..55fcb80 --- /dev/null +++ b/emulator/opengl/host/renderer/Android.mk @@ -0,0 +1,14 @@ +LOCAL_PATH:=$(call my-dir) + +# host renderer process ########################### +$(call emugl-begin-host-executable,emulator_renderer) +$(call emugl-import,libOpenglRender) +LOCAL_SRC_FILES := main.cpp +LOCAL_CFLAGS += -O0 -g + +#ifeq ($(HOST_OS),windows) +#LOCAL_LDLIBS += -lws2_32 +#endif + +$(call emugl-end-module) + diff --git a/emulator/opengl/host/renderer/main.cpp b/emulator/opengl/host/renderer/main.cpp new file mode 100644 index 0000000..ae7ace3 --- /dev/null +++ b/emulator/opengl/host/renderer/main.cpp @@ -0,0 +1,174 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "RenderServer.h" +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include "FrameBuffer.h" + +#include <sys/types.h> +#include <unistd.h> +#include <codec_defs.h> +#ifdef _WIN32 +#include <winsock2.h> +#endif + +#ifdef __linux__ +#include <X11/Xlib.h> +#endif + +static void printUsage(const char *progName) +{ + fprintf(stderr, "Usage: %s -windowid <windowid> [options]\n", progName); + fprintf(stderr, " -windowid <windowid> - window id to render into\n"); + fprintf(stderr, " -port <portNum> - listening TCP port number\n"); + fprintf(stderr, " -x <num> - render subwindow x position\n"); + fprintf(stderr, " -y <num> - render subwindow y position\n"); + fprintf(stderr, " -width <num> - render subwindow width\n"); + fprintf(stderr, " -height <num> - render subwindow height\n"); + exit(-1); +} + +int main(int argc, char *argv[]) +{ + int portNum = CODEC_SERVER_PORT; + int winX = 0; + int winY = 0; + int winWidth = 320; + int winHeight = 480; + FBNativeWindowType windowId = NULL; + int iWindowId = 0; + + // + // Parse command line arguments + // + for (int i=1; i<argc; i++) { + if (!strcmp(argv[i], "-windowid")) { + if (++i >= argc || sscanf(argv[i],"%d", &iWindowId) != 1) { + printUsage(argv[0]); + } + } + else if (!strncmp(argv[i], "-port", 5)) { + if (++i >= argc || sscanf(argv[i],"%d", &portNum) != 1) { + printUsage(argv[0]); + } + } + else if (!strncmp(argv[i], "-x", 2)) { + if (++i >= argc || sscanf(argv[i],"%d", &winX) != 1) { + printUsage(argv[0]); + } + } + else if (!strncmp(argv[i], "-y", 2)) { + if (++i >= argc || sscanf(argv[i],"%d", &winY) != 1) { + printUsage(argv[0]); + } + } + else if (!strncmp(argv[i], "-width", 6)) { + if (++i >= argc || sscanf(argv[i],"%d", &winWidth) != 1) { + printUsage(argv[0]); + } + } + else if (!strncmp(argv[i], "-height", 7)) { + if (++i >= argc || sscanf(argv[i],"%d", &winHeight) != 1) { + printUsage(argv[0]); + } + } + } + + windowId = (FBNativeWindowType)iWindowId; + if (!windowId) { + // window id must be provided + printUsage(argv[0]); + } + +#if 0 //Enable to attach gdb to renderer on startup + fprintf(stderr, "renderer pid %d , press any key to continue...\n", getpid()); + getchar(); +#else + fprintf(stderr, "renderer pid %d \n", getpid()); +#endif + +#ifdef _WIN32 + WSADATA wsaData; + int rc = WSAStartup( MAKEWORD(2,2), &wsaData); + if (rc != 0) { + printf( "could not initialize Winsock\n" ); + } +#endif + +#ifdef __linux__ + // some OpenGL implementations may call X functions + // it is safer to synchronize all X calls made by all the + // rendering threads. (although the calls we do are locked + // in the FrameBuffer singleton object). + XInitThreads(); +#endif + + // + // initialize Framebuffer + // + bool inited = FrameBuffer::initialize(winWidth, winHeight, NULL, NULL); + if (!inited) { + fprintf(stderr,"Failed to initialize Framebuffer\n"); + return -1; + } + + inited = FrameBuffer::setupSubWindow(windowId, + winX, winY, winWidth, winHeight, 0.0); + if (!inited) { + fprintf(stderr,"Failed to create subwindow Framebuffer\n"); + return -1; + } + + // + // Create and run a render server listening to the given port number + // + RenderServer *server = RenderServer::create(portNum); + if (!server) { + fprintf(stderr,"Cannot initialize render server\n"); + return -1; + } + +#ifndef _WIN32 + // + // run the server listener loop + // + server->Main(); +#else + // + // on windows we need to handle messages for the + // created subwindow. So we run the server on a seperate + // thread and running the windows message pump loop + // in this main thread. + // + server->start(); + + // + // Dispatch events for the subwindow + // During termination of the render server, the FrameBuffer + // will be finalized, the Framebuffer subwindow will + // get destroyed and the following loop will exit. + // + MSG msg; + HWND hWnd = FrameBuffer::getFB()->getSubWindow(); + while( GetMessage(&msg, hWnd, 0, 0) > 0 ) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } +#endif + + return 0; +} diff --git a/emulator/opengl/host/tools/emugen/Android.mk b/emulator/opengl/host/tools/emugen/Android.mk new file mode 100644 index 0000000..ad9ab06 --- /dev/null +++ b/emulator/opengl/host/tools/emugen/Android.mk @@ -0,0 +1,26 @@ +ifneq ($(HOST_OS),windows) + +LOCAL_PATH:=$(call my-dir) + +$(call emugl-begin-host-executable,emugen) + + LOCAL_SRC_FILES := \ + ApiGen.cpp \ + EntryPoint.cpp \ + main.cpp \ + strUtils.cpp \ + TypeFactory.cpp + +$(call emugl-end-module) + +# The location of the emugen host tool that is used to generate wire +# protocol encoders/ decoders. This variable is used by other emugl modules. +EMUGL_EMUGEN := $(LOCAL_BUILT_MODULE) + +else # windows build + +# on windows use the build host emugen executable +# (that will be the linux exeutable when using mingw build) +EMUGL_EMUGEN := $(BUILD_OUT_EXECUTABLES)/emugen + +endif diff --git a/emulator/opengl/host/tools/emugen/ApiGen.cpp b/emulator/opengl/host/tools/emugen/ApiGen.cpp new file mode 100644 index 0000000..bf2d244 --- /dev/null +++ b/emulator/opengl/host/tools/emugen/ApiGen.cpp @@ -0,0 +1,1081 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "ApiGen.h" +#include "EntryPoint.h" +#include <stdio.h> +#include <stdlib.h> +#include "strUtils.h" +#include <errno.h> +#include <sys/types.h> + +/* Define this to 1 to enable support for the 'isLarge' variable flag + * that instructs the encoder to send large data buffers by a direct + * write through the pipe (i.e. without copying it into a temporary + * buffer. This has definite performance benefits when using a QEMU Pipe. + * + * Set to 0 otherwise. + */ +#define WITH_LARGE_SUPPORT 1 + +EntryPoint * ApiGen::findEntryByName(const std::string & name) +{ + EntryPoint * entry = NULL; + + size_t n = this->size(); + for (size_t i = 0; i < n; i++) { + if (at(i).name() == name) { + entry = &(at(i)); + break; + } + } + return entry; +} + +void ApiGen::printHeader(FILE *fp) const +{ + fprintf(fp, "// Generated Code - DO NOT EDIT !!\n"); + fprintf(fp, "// generated by 'emugen'\n"); +} + +int ApiGen::genProcTypes(const std::string &filename, SideType side) +{ + FILE *fp = fopen(filename.c_str(), "wt"); + if (fp == NULL) { + perror(filename.c_str()); + return -1; + } + printHeader(fp); + + const char* basename = m_basename.c_str(); + + fprintf(fp, "#ifndef __%s_%s_proc_t_h\n", basename, sideString(side)); + fprintf(fp, "#define __%s_%s_proc_t_h\n", basename, sideString(side)); + fprintf(fp, "\n\n"); + fprintf(fp, "\n#include \"%s_types.h\"\n",basename); + fprintf(fp, "#ifndef %s_APIENTRY\n",basename); + fprintf(fp, "#define %s_APIENTRY \n",basename); + fprintf(fp, "#endif\n"); + + + for (size_t i = 0; i < size(); i++) { + EntryPoint *e = &at(i); + + fprintf(fp, "typedef "); + e->retval().printType(fp); + fprintf(fp, " (%s_APIENTRY *%s_%s_proc_t) (", basename, e->name().c_str(), sideString(side)); + if (side == CLIENT_SIDE) { fprintf(fp, "void * ctx"); } + if (e->customDecoder() && side == SERVER_SIDE) { fprintf(fp, "void *ctx"); } + + VarsArray & evars = e->vars(); + size_t n = evars.size(); + + for (size_t j = 0; j < n; j++) { + if (!evars[j].isVoid()) { + if (j != 0 || side == CLIENT_SIDE || (side == SERVER_SIDE && e->customDecoder())) fprintf(fp, ", "); + evars[j].printType(fp); + } + } + fprintf(fp, ");\n"); + } + fprintf(fp, "\n\n#endif\n"); + return 0; +} + +int ApiGen::genFuncTable(const std::string &filename, SideType side) +{ + FILE *fp = fopen(filename.c_str(), "wt"); + if (fp == NULL) { + perror(filename.c_str()); + return -1; + } + printHeader(fp); + + fprintf(fp, "#ifndef __%s_%s_ftable_t_h\n", m_basename.c_str(), sideString(side)); + fprintf(fp, "#define __%s_%s_ftable_t_h\n", m_basename.c_str(), sideString(side)); + fprintf(fp, "\n\n"); + fprintf(fp, "static struct _%s_funcs_by_name {\n", m_basename.c_str()); + fprintf(fp, + "\tconst char *name;\n" \ + "\tvoid *proc;\n" \ + "} %s_funcs_by_name[] = {\n", m_basename.c_str()); + + + for (size_t i = 0; i < size(); i++) { + EntryPoint *e = &at(i); + if (e->notApi()) continue; + fprintf(fp, "\t{\"%s\", (void*)%s},\n", e->name().c_str(), e->name().c_str()); + } + fprintf(fp, "};\n"); + fprintf(fp, "static int %s_num_funcs = sizeof(%s_funcs_by_name) / sizeof(struct _%s_funcs_by_name);\n", + m_basename.c_str(), m_basename.c_str(), m_basename.c_str()); + fprintf(fp, "\n\n#endif\n"); + return 0; +} + + +int ApiGen::genContext(const std::string & filename, SideType side) +{ + FILE *fp = fopen(filename.c_str(), "wt"); + if (fp == NULL) { + perror(filename.c_str()); + return -1; + } + printHeader(fp); + + fprintf(fp, "#ifndef __%s_%s_context_t_h\n", m_basename.c_str(), sideString(side)); + fprintf(fp, "#define __%s_%s_context_t_h\n", m_basename.c_str(), sideString(side)); + + // fprintf(fp, "\n#include \"%s_types.h\"\n", m_basename.c_str()); + fprintf(fp, "\n#include \"%s_%s_proc.h\"\n", m_basename.c_str(), sideString(side)); + + StringVec & contextHeaders = side == CLIENT_SIDE ? m_clientContextHeaders : m_serverContextHeaders; + for (size_t i = 0; i < contextHeaders.size(); i++) { + fprintf(fp, "#include %s\n", contextHeaders[i].c_str()); + } + fprintf(fp, "\n"); + + fprintf(fp, "\nstruct %s_%s_context_t {\n\n", m_basename.c_str(), sideString(side)); + for (size_t i = 0; i < size(); i++) { + EntryPoint *e = &at(i); + fprintf(fp, "\t%s_%s_proc_t %s;\n", e->name().c_str(), sideString(side), e->name().c_str()); + } + // accessors + fprintf(fp, "\t//Accessors \n"); + + for (size_t i = 0; i < size(); i++) { + EntryPoint *e = &at(i); + const char *n = e->name().c_str(); + const char *s = sideString(side); + fprintf(fp, "\tvirtual %s_%s_proc_t set_%s(%s_%s_proc_t f) { %s_%s_proc_t retval = %s; %s = f; return retval;}\n", n, s, n, n, s, n, s, n, n); + } + + // virtual destructor + fprintf(fp, "\t virtual ~%s_%s_context_t() {}\n", m_basename.c_str(), sideString(side)); + // accessor + if (side == CLIENT_SIDE || side == WRAPPER_SIDE) { + fprintf(fp, "\n\ttypedef %s_%s_context_t *CONTEXT_ACCESSOR_TYPE(void);\n", + m_basename.c_str(), sideString(side)); + fprintf(fp, "\tstatic void setContextAccessor(CONTEXT_ACCESSOR_TYPE *f);\n"); + } + + // init function + fprintf(fp, "\tint initDispatchByName( void *(*getProc)(const char *name, void *userData), void *userData);\n"); + + //client site set error virtual func + if (side == CLIENT_SIDE) { + fprintf(fp, "\tvirtual void setError(unsigned int error){};\n"); + fprintf(fp, "\tvirtual unsigned int getError(){ return 0; };\n"); + } + + fprintf(fp, "};\n"); + + fprintf(fp, "\n#endif\n"); + fclose(fp); + return 0; +} + +int ApiGen::genEntryPoints(const std::string & filename, SideType side) +{ + + if (side != CLIENT_SIDE && side != WRAPPER_SIDE) { + fprintf(stderr, "Entry points are only defined for Client and Wrapper components\n"); + return -999; + } + + + FILE *fp = fopen(filename.c_str(), "wt"); + if (fp == NULL) { + perror(filename.c_str()); + return errno; + } + + printHeader(fp); + fprintf(fp, "#include <stdio.h>\n"); + fprintf(fp, "#include <stdlib.h>\n"); + fprintf(fp, "#include \"%s_%s_context.h\"\n", m_basename.c_str(), sideString(side)); + fprintf(fp, "\n"); + + fprintf(fp, "#ifndef GL_TRUE\n"); + fprintf(fp, "extern \"C\" {\n"); + + for (size_t i = 0; i < size(); i++) { + fprintf(fp, "\t"); at(i).print(fp, false); fprintf(fp, ";\n"); + } + fprintf(fp, "};\n\n"); + fprintf(fp, "#endif\n"); + + fprintf(fp, "#ifndef GET_CONTEXT\n"); + fprintf(fp, "static %s_%s_context_t::CONTEXT_ACCESSOR_TYPE *getCurrentContext = NULL;\n", + m_basename.c_str(), sideString(side)); + + fprintf(fp, + "void %s_%s_context_t::setContextAccessor(CONTEXT_ACCESSOR_TYPE *f) { getCurrentContext = f; }\n", + m_basename.c_str(), sideString(side)); + fprintf(fp, "#define GET_CONTEXT %s_%s_context_t * ctx = getCurrentContext() \n", + m_basename.c_str(), sideString(side)); + fprintf(fp, "#endif\n\n"); + + + for (size_t i = 0; i < size(); i++) { + EntryPoint *e = &at(i); + e->print(fp); + fprintf(fp, "{\n"); + fprintf(fp, "\tGET_CONTEXT; \n"); + + bool shouldReturn = !e->retval().isVoid(); + bool shouldCallWithContext = (side == CLIENT_SIDE); + //param check + if (shouldCallWithContext) { + for (size_t j=0; j<e->vars().size(); j++) { + if (e->vars()[j].paramCheckExpression() != "") + fprintf(fp, "\t%s\n", e->vars()[j].paramCheckExpression().c_str()); + } + } + fprintf(fp, "\t %sctx->%s(%s", + shouldReturn ? "return " : "", + e->name().c_str(), + shouldCallWithContext ? "ctx" : ""); + size_t nvars = e->vars().size(); + + for (size_t j = 0; j < nvars; j++) { + if (!e->vars()[j].isVoid()) { + fprintf(fp, "%s %s", + j != 0 || shouldCallWithContext ? "," : "", + e->vars()[j].name().c_str()); + } + } + fprintf(fp, ");\n"); + fprintf(fp, "}\n\n"); + } + fclose(fp); + return 0; +} + + +int ApiGen::genOpcodes(const std::string &filename) +{ + FILE *fp = fopen(filename.c_str(), "wt"); + if (fp == NULL) { + perror(filename.c_str()); + return errno; + } + + printHeader(fp); + fprintf(fp, "#ifndef __GUARD_%s_opcodes_h_\n", m_basename.c_str()); + fprintf(fp, "#define __GUARD_%s_opcodes_h_\n\n", m_basename.c_str()); + for (size_t i = 0; i < size(); i++) { + fprintf(fp, "#define OP_%s \t\t\t\t\t%u\n", at(i).name().c_str(), (unsigned int)i + m_baseOpcode); + } + fprintf(fp, "#define OP_last \t\t\t\t\t%u\n", (unsigned int)size() + m_baseOpcode); + fprintf(fp,"\n\n#endif\n"); + fclose(fp); + return 0; + +} +int ApiGen::genAttributesTemplate(const std::string &filename ) +{ + FILE *fp = fopen(filename.c_str(), "wt"); + if (fp == NULL) { + perror(filename.c_str()); + return -1; + } + + for (size_t i = 0; i < size(); i++) { + if (at(i).hasPointers()) { + fprintf(fp, "#"); + at(i).print(fp); + fprintf(fp, "%s\n\n", at(i).name().c_str()); + } + } + fclose(fp); + return 0; +} + +int ApiGen::genEncoderHeader(const std::string &filename) +{ + FILE *fp = fopen(filename.c_str(), "wt"); + if (fp == NULL) { + perror(filename.c_str()); + return -1; + } + + printHeader(fp); + std::string classname = m_basename + "_encoder_context_t"; + + fprintf(fp, "\n#ifndef GUARD_%s\n", classname.c_str()); + fprintf(fp, "#define GUARD_%s\n\n", classname.c_str()); + + fprintf(fp, "#include \"IOStream.h\"\n"); + fprintf(fp, "#include \"%s_%s_context.h\"\n\n\n", m_basename.c_str(), sideString(CLIENT_SIDE)); + + for (size_t i = 0; i < m_encoderHeaders.size(); i++) { + fprintf(fp, "#include %s\n", m_encoderHeaders[i].c_str()); + } + fprintf(fp, "\n"); + + fprintf(fp, "struct %s : public %s_%s_context_t {\n\n", + classname.c_str(), m_basename.c_str(), sideString(CLIENT_SIDE)); + fprintf(fp, "\tIOStream *m_stream;\n\n"); + + fprintf(fp, "\t%s(IOStream *stream);\n\n", classname.c_str()); + fprintf(fp, "\n};\n\n"); + + fprintf(fp,"extern \"C\" {\n"); + + for (size_t i = 0; i < size(); i++) { + fprintf(fp, "\t"); + at(i).print(fp, false, "_enc", /* classname + "::" */"", "void *self"); + fprintf(fp, ";\n"); + } + fprintf(fp, "};\n"); + fprintf(fp, "#endif"); + + fclose(fp); + return 0; +} + +// Format the byte length expression for a given variable into a user-provided buffer +// If the variable type is not a pointer, this is simply its size as a decimal constant +// If the variable is a pointer, this will be an expression provided by the .attrib file +// through the 'len' attribute. +// +// Returns 1 if the variable is a pointer, 0 otherwise +// +static int getVarEncodingSizeExpression(Var& var, EntryPoint* e, char* buff, size_t bufflen) +{ + int ret = 0; + if (!var.isPointer()) { + snprintf(buff, bufflen, "%u", (unsigned int) var.type()->bytes()); + } else { + ret = 1; + const char* lenExpr = var.lenExpression().c_str(); + const char* varname = var.name().c_str(); + if (e != NULL && lenExpr[0] == '\0') { + fprintf(stderr, "%s: data len is undefined for '%s'\n", + e->name().c_str(), varname); + } + if (var.nullAllowed()) { + snprintf(buff, bufflen, "((%s != NULL) ? %s : 0)", varname, lenExpr); + } else { + snprintf(buff, bufflen, "%s", lenExpr); + } + } + return ret; +} + +static int writeVarEncodingSize(Var& var, FILE* fp) +{ + int ret = 0; + if (!var.isPointer()) { + fprintf(fp, "%u", (unsigned int) var.type()->bytes()); + } else { + ret = 1; + fprintf(fp, "__size_%s", var.name().c_str()); + } + return ret; +} + + + +static void writeVarEncodingExpression(Var& var, FILE* fp) +{ + const char* varname = var.name().c_str(); + + if (var.isPointer()) { + // encode a pointer header + fprintf(fp, "\t*(unsigned int *)(ptr) = __size_%s; ptr += 4;\n", varname); + + Var::PointerDir dir = var.pointerDir(); + if (dir == Var::POINTER_INOUT || dir == Var::POINTER_IN) { + if (var.nullAllowed()) { + fprintf(fp, "\tif (%s != NULL) ", varname); + } else { + fprintf(fp, "\t"); + } + + if (var.packExpression().size() != 0) { + fprintf(fp, "%s;", var.packExpression().c_str()); + } else { + fprintf(fp, "memcpy(ptr, %s, __size_%s);", + varname, varname); + } + + fprintf(fp, "ptr += __size_%s;\n", varname); + } + } else { + // encode a non pointer variable + if (!var.isVoid()) { + fprintf(fp, "\t*(%s *) (ptr) = %s; ptr += %u;\n", + var.type()->name().c_str(), varname, + (uint) var.type()->bytes()); + } + } +} + +#if WITH_LARGE_SUPPORT +static void writeVarLargeEncodingExpression(Var& var, FILE* fp) +{ + const char* varname = var.name().c_str(); + + fprintf(fp, "\tstream->writeFully(&__size_%s,4);\n", varname); + if (var.nullAllowed()) { + fprintf(fp, "\tif (%s != NULL) ", varname); + } else { + fprintf(fp, "\t"); + } + if (var.writeExpression() != "") { + fprintf(fp, "%s", var.writeExpression().c_str()); + } else { + fprintf(fp, "stream->writeFully(%s, __size_%s)", varname, varname); + } + fprintf(fp, ";\n"); +} +#endif /* WITH_LARGE_SUPPORT */ + +int ApiGen::genEncoderImpl(const std::string &filename) +{ + FILE *fp = fopen(filename.c_str(), "wt"); + if (fp == NULL) { + perror(filename.c_str()); + return -1; + } + + printHeader(fp); + fprintf(fp, "\n\n#include <string.h>\n"); + fprintf(fp, "#include \"%s_opcodes.h\"\n\n", m_basename.c_str()); + fprintf(fp, "#include \"%s_enc.h\"\n\n\n", m_basename.c_str()); + fprintf(fp, "#include <stdio.h>\n"); + std::string classname = m_basename + "_encoder_context_t"; + size_t n = size(); + + // unsupport printout + fprintf(fp, + "static void enc_unsupported()\n{\n\tALOGE(\"Function is unsupported\\n\");\n}\n\n"); + + // entry points; + for (size_t i = 0; i < n; i++) { + EntryPoint *e = &at(i); + + if (e->unsupported()) continue; + + + e->print(fp, true, "_enc", /* classname + "::" */"", "void *self"); + fprintf(fp, "{\n"); + +// fprintf(fp, "\n\tDBG(\">>>> %s\\n\");\n", e->name().c_str()); + fprintf(fp, "\n\t%s *ctx = (%s *)self;\n", + classname.c_str(), + classname.c_str()); + fprintf(fp, "\tIOStream *stream = ctx->m_stream;\n\n"); + VarsArray & evars = e->vars(); + size_t maxvars = evars.size(); + size_t j; + + char buff[256]; + + // Define the __size_XXX variables that contain the size of data + // associated with pointers. + for (j = 0; j < maxvars; j++) { + Var& var = evars[j]; + + if (!var.isPointer()) + continue; + + const char* varname = var.name().c_str(); + fprintf(fp, "\tconst unsigned int __size_%s = ", varname); + + getVarEncodingSizeExpression(var, e, buff, sizeof(buff)); + fprintf(fp, "%s;\n", buff); + } + +#if WITH_LARGE_SUPPORT + // We need to take care of 'isLarge' variable in a special way + // Anything before an isLarge variable can be packed into a single + // buffer, which is then commited. Each isLarge variable is a pointer + // to data that can be written to directly through the pipe, which + // will be instant when using a QEMU pipe + + size_t nvars = 0; + size_t npointers = 0; + + // First, compute the total size, 8 bytes for the opcode + payload size + fprintf(fp, "\t unsigned char *ptr;\n"); + fprintf(fp, "\t const size_t packetSize = 8"); + + for (j = 0; j < maxvars; j++) { + fprintf(fp, " + "); + npointers += writeVarEncodingSize(evars[j], fp); + } + if (npointers > 0) { + fprintf(fp, " + %zu*4", npointers); + } + fprintf(fp, ";\n"); + + // We need to divide the packet into fragments. Each fragment contains + // either copied arguments to a temporary buffer, or direct writes for + // large variables. + // + // The first fragment must also contain the opcode+payload_size + // + nvars = 0; + while (nvars < maxvars || maxvars == 0) { + + // Skip over non-large fields + for (j = nvars; j < maxvars; j++) { + if (evars[j].isLarge()) + break; + } + + // Write a fragment if needed. + if (nvars == 0 || j > nvars) { + const char* plus = ""; + + if (nvars == 0 && j == maxvars) { + // Simple shortcut for the common case where we don't have large variables; + fprintf(fp, "\tptr = stream->alloc(packetSize);\n"); + + } else { + // allocate buffer from the stream until the first large variable + fprintf(fp, "\tptr = stream->alloc("); + plus = ""; + + if (nvars == 0) { + fprintf(fp,"8"); plus = " + "; + } + if (j > nvars) { + npointers = 0; + for (j = nvars; j < maxvars && !evars[j].isLarge(); j++) { + fprintf(fp, "%s", plus); plus = " + "; + npointers += writeVarEncodingSize(evars[j], fp); + } + if (npointers > 0) { + fprintf(fp, "%s%zu*4", plus, npointers); plus = " + "; + } + } + fprintf(fp,");\n"); + } + + // encode packet header if needed. + if (nvars == 0) { + fprintf(fp, "\t*(unsigned int *)(ptr) = OP_%s; ptr += 4;\n", e->name().c_str()); + fprintf(fp, "\t*(unsigned int *)(ptr) = (unsigned int) packetSize; ptr += 4;\n"); + } + + if (maxvars == 0) + break; + + // encode non-large fields in this fragment + for (j = nvars; j < maxvars && !evars[j].isLarge(); j++) { + writeVarEncodingExpression(evars[j],fp); + } + + // Ensure the fragment is commited if it is followed by a large variable + if (j < maxvars) { + fprintf(fp, "\tstream->flush();\n"); + } + } + + // If we have one or more large variables, write them directly. + // As size + data + for ( ; j < maxvars && evars[j].isLarge(); j++) { + writeVarLargeEncodingExpression(evars[j], fp); + } + + nvars = j; + } + +#else /* !WITH_LARGE_SUPPORT */ + size_t nvars = evars.size(); + size_t npointers = 0; + fprintf(fp, "\t const size_t packetSize = 8"); + for (size_t j = 0; j < nvars; j++) { + npointers += getVarEncodingSizeExpression(evars[j],e,buff,sizeof(buff)); + fprintf(fp, " + %s", buff); + } + fprintf(fp, " + %u * 4;\n", (unsigned int) npointers); + + // allocate buffer from the stream; + fprintf(fp, "\t unsigned char *ptr = stream->alloc(packetSize);\n\n"); + + // encode into the stream; + fprintf(fp, "\t*(unsigned int *)(ptr) = OP_%s; ptr += 4;\n", e->name().c_str()); + fprintf(fp, "\t*(unsigned int *)(ptr) = (unsigned int) packetSize; ptr += 4;\n\n"); + + // out variables + for (size_t j = 0; j < nvars; j++) { + writeVarEncodingExpression(evars[j], fp); + } +#endif /* !WITH_LARGE_SUPPORT */ + + // in variables; + for (size_t j = 0; j < nvars; j++) { + if (evars[j].isPointer()) { + Var::PointerDir dir = evars[j].pointerDir(); + if (dir == Var::POINTER_INOUT || dir == Var::POINTER_OUT) { + const char* varname = evars[j].name().c_str(); + if (evars[j].nullAllowed()) { + fprintf(fp, "\tif (%s != NULL) ",varname); + } else { + fprintf(fp, "\t"); + } + fprintf(fp, "stream->readback(%s, __size_%s);\n", + varname, varname); + } + } + } +//XXX fprintf(fp, "\n\tDBG(\"<<<< %s\\n\");\n", e->name().c_str()); + // todo - return value for pointers + if (e->retval().isPointer()) { + fprintf(stderr, "WARNING: %s : return value of pointer is unsupported\n", + e->name().c_str()); + fprintf(fp, "\t return NULL;\n"); + } else if (e->retval().type()->name() != "void") { + fprintf(fp, "\n\t%s retval;\n", e->retval().type()->name().c_str()); + fprintf(fp, "\tstream->readback(&retval, %u);\n",(uint) e->retval().type()->bytes()); + fprintf(fp, "\treturn retval;\n"); + } + fprintf(fp, "}\n\n"); + } + + // constructor + fprintf(fp, "%s::%s(IOStream *stream)\n{\n", classname.c_str(), classname.c_str()); + fprintf(fp, "\tm_stream = stream;\n\n"); + + for (size_t i = 0; i < n; i++) { + EntryPoint *e = &at(i); + if (e->unsupported()) { + fprintf(fp, "\tset_%s((%s_%s_proc_t)(enc_unsupported));\n", e->name().c_str(), e->name().c_str(), sideString(CLIENT_SIDE)); + } else { + fprintf(fp, "\tset_%s(%s_enc);\n", e->name().c_str(), e->name().c_str()); + } + /** + if (e->unsupsported()) { + fprintf(fp, "\tmemcpy((void *)(&%s), (const void *)(&enc_unsupported), sizeof(%s));\n", + e->name().c_str(), + e->name().c_str()); + } else { + fprintf(fp, "\t%s = %s_enc;\n", e->name().c_str(), e->name().c_str()); + } + **/ + } + fprintf(fp, "}\n\n"); + + fclose(fp); + return 0; +} + + +int ApiGen::genDecoderHeader(const std::string &filename) +{ + FILE *fp = fopen(filename.c_str(), "wt"); + if (fp == NULL) { + perror(filename.c_str()); + return -1; + } + + printHeader(fp); + std::string classname = m_basename + "_decoder_context_t"; + + fprintf(fp, "\n#ifndef GUARD_%s\n", classname.c_str()); + fprintf(fp, "#define GUARD_%s\n\n", classname.c_str()); + + fprintf(fp, "#include \"IOStream.h\" \n"); + fprintf(fp, "#include \"%s_%s_context.h\"\n\n\n", m_basename.c_str(), sideString(SERVER_SIDE)); + + for (size_t i = 0; i < m_decoderHeaders.size(); i++) { + fprintf(fp, "#include %s\n", m_decoderHeaders[i].c_str()); + } + fprintf(fp, "\n"); + + fprintf(fp, "struct %s : public %s_%s_context_t {\n\n", + classname.c_str(), m_basename.c_str(), sideString(SERVER_SIDE)); + fprintf(fp, "\tsize_t decode(void *buf, size_t bufsize, IOStream *stream);\n"); + fprintf(fp, "\n};\n\n"); + fprintf(fp, "#endif\n"); + + fclose(fp); + return 0; +} + +int ApiGen::genContextImpl(const std::string &filename, SideType side) +{ + FILE *fp = fopen(filename.c_str(), "wt"); + if (fp == NULL) { + perror(filename.c_str()); + return -1; + } + printHeader(fp); + + std::string classname = m_basename + "_" + sideString(side) + "_context_t"; + size_t n = size(); + fprintf(fp, "\n\n#include <string.h>\n"); + fprintf(fp, "#include \"%s_%s_context.h\"\n\n\n", m_basename.c_str(), sideString(side)); + fprintf(fp, "#include <stdio.h>\n\n"); + + // init function; + fprintf(fp, "int %s::initDispatchByName(void *(*getProc)(const char *, void *userData), void *userData)\n{\n", classname.c_str()); + fprintf(fp, "\tvoid *ptr;\n\n"); + for (size_t i = 0; i < n; i++) { + EntryPoint *e = &at(i); + fprintf(fp, "\tptr = getProc(\"%s\", userData); set_%s((%s_%s_proc_t)ptr);\n", + e->name().c_str(), + e->name().c_str(), + e->name().c_str(), + sideString(side)); + + } + fprintf(fp, "\treturn 0;\n"); + fprintf(fp, "}\n\n"); + fclose(fp); + return 0; +} + +int ApiGen::genDecoderImpl(const std::string &filename) +{ + FILE *fp = fopen(filename.c_str(), "wt"); + if (fp == NULL) { + perror(filename.c_str()); + return -1; + } + + printHeader(fp); + + std::string classname = m_basename + "_decoder_context_t"; + + size_t n = size(); + + fprintf(fp, "\n\n#include <string.h>\n"); + fprintf(fp, "#include \"%s_opcodes.h\"\n\n", m_basename.c_str()); + fprintf(fp, "#include \"%s_dec.h\"\n\n\n", m_basename.c_str()); + fprintf(fp, "#include <stdio.h>\n\n"); + fprintf(fp, "typedef unsigned int tsize_t; // Target \"size_t\", which is 32-bit for now. It may or may not be the same as host's size_t when emugen is compiled.\n\n"); + + // decoder switch; + fprintf(fp, "size_t %s::decode(void *buf, size_t len, IOStream *stream)\n{\n", classname.c_str()); + fprintf(fp, + " \n\ +\tsize_t pos = 0;\n\ +\tif (len < 8) return pos; \n\ +\tunsigned char *ptr = (unsigned char *)buf;\n\ +\tbool unknownOpcode = false; \n\ +#ifdef CHECK_GL_ERROR \n\ +\tchar lastCall[256] = {0}; \n\ +#endif \n\ +\twhile ((len - pos >= 8) && !unknownOpcode) { \n\ +\t\tvoid *params[%u]; \n\ +\t\tint opcode = *(int *)ptr; \n\ +\t\tunsigned int packetLen = *(int *)(ptr + 4);\n\ +\t\tif (len - pos < packetLen) return pos; \n\ +\t\tswitch(opcode) {\n", + (uint) m_maxEntryPointsParams); + + for (size_t f = 0; f < n; f++) { + enum Pass_t { PASS_TmpBuffAlloc = 0, PASS_MemAlloc, PASS_DebugPrint, PASS_FunctionCall, PASS_Epilog, PASS_LAST }; + EntryPoint *e = &at(f); + + // construct a printout string; + std::string printString = ""; + for (size_t i = 0; i < e->vars().size(); i++) { + Var *v = &e->vars()[i]; + if (!v->isVoid()) printString += (v->isPointer() ? "%p(%u)" : v->type()->printFormat()) + " "; + } + printString += ""; + // TODO - add for return value; + + fprintf(fp, "\t\t\tcase OP_%s:\n", e->name().c_str()); + fprintf(fp, "\t\t\t{\n"); + + bool totalTmpBuffExist = false; + std::string totalTmpBuffOffset = "0"; + std::string *tmpBufOffset = new std::string[e->vars().size()]; + + // construct retval type string + std::string retvalType; + if (!e->retval().isVoid()) { + retvalType = e->retval().type()->name(); + } + + for (int pass = PASS_TmpBuffAlloc; pass < PASS_LAST; pass++) { + if (pass == PASS_FunctionCall && !e->retval().isVoid() && !e->retval().isPointer()) { + fprintf(fp, "\t\t\t*(%s *)(&tmpBuf[%s]) = ", retvalType.c_str(), + totalTmpBuffOffset.c_str()); + } + + + if (pass == PASS_FunctionCall) { + fprintf(fp, "\t\t\tthis->%s(", e->name().c_str()); + if (e->customDecoder()) { + fprintf(fp, "this"); // add a context to the call + } + } else if (pass == PASS_DebugPrint) { + fprintf(fp, "#ifdef DEBUG_PRINTOUT\n"); + fprintf(fp, "\t\t\tfprintf(stderr,\"%s: %s(%s)\\n\"", m_basename.c_str(), e->name().c_str(), printString.c_str()); + if (e->vars().size() > 0 && !e->vars()[0].isVoid()) fprintf(fp, ","); + } + + std::string varoffset = "8"; // skip the header + VarsArray & evars = e->vars(); + // allocate memory for out pointers; + for (size_t j = 0; j < evars.size(); j++) { + Var *v = & evars[j]; + if (!v->isVoid()) { + if ((pass == PASS_FunctionCall) && (j != 0 || e->customDecoder())) fprintf(fp, ", "); + if (pass == PASS_DebugPrint && j != 0) fprintf(fp, ", "); + + if (!v->isPointer()) { + if (pass == PASS_FunctionCall || pass == PASS_DebugPrint) { + fprintf(fp, "*(%s *)(ptr + %s)", v->type()->name().c_str(), varoffset.c_str()); + } + varoffset += " + " + toString(v->type()->bytes()); + } else { + if (v->pointerDir() == Var::POINTER_IN || v->pointerDir() == Var::POINTER_INOUT) { + if (pass == PASS_MemAlloc && v->pointerDir() == Var::POINTER_INOUT) { + fprintf(fp, "\t\t\tsize_t tmpPtr%uSize = (size_t)*(unsigned int *)(ptr + %s);\n", + (uint) j, varoffset.c_str()); + fprintf(fp, "unsigned char *tmpPtr%u = (ptr + %s + 4);\n", + (uint) j, varoffset.c_str()); + } + if (pass == PASS_FunctionCall) { + if (v->nullAllowed()) { + fprintf(fp, "*((unsigned int *)(ptr + %s)) == 0 ? NULL : (%s)(ptr + %s + 4)", + varoffset.c_str(), v->type()->name().c_str(), varoffset.c_str()); + } else { + fprintf(fp, "(%s)(ptr + %s + 4)", + v->type()->name().c_str(), varoffset.c_str()); + } + } else if (pass == PASS_DebugPrint) { + fprintf(fp, "(%s)(ptr + %s + 4), *(unsigned int *)(ptr + %s)", + v->type()->name().c_str(), varoffset.c_str(), + varoffset.c_str()); + } + varoffset += " + 4 + *(tsize_t *)(ptr +" + varoffset + ")"; + } else { // out pointer; + if (pass == PASS_TmpBuffAlloc) { + fprintf(fp, "\t\t\tsize_t tmpPtr%uSize = (size_t)*(unsigned int *)(ptr + %s);\n", + (uint) j, varoffset.c_str()); + if (!totalTmpBuffExist) { + fprintf(fp, "\t\t\tsize_t totalTmpSize = tmpPtr%uSize;\n", (uint)j); + } else { + fprintf(fp, "\t\t\ttotalTmpSize += tmpPtr%uSize;\n", (uint)j); + } + tmpBufOffset[j] = totalTmpBuffOffset; + char tmpPtrName[16]; + sprintf(tmpPtrName," + tmpPtr%uSize", (uint)j); + totalTmpBuffOffset += std::string(tmpPtrName); + totalTmpBuffExist = true; + } else if (pass == PASS_MemAlloc) { + fprintf(fp, "\t\t\tunsigned char *tmpPtr%u = &tmpBuf[%s];\n", + (uint)j, tmpBufOffset[j].c_str()); + } else if (pass == PASS_FunctionCall) { + if (v->nullAllowed()) { + fprintf(fp, "tmpPtr%uSize == 0 ? NULL : (%s)(tmpPtr%u)", + (uint) j, v->type()->name().c_str(), (uint) j); + } else { + fprintf(fp, "(%s)(tmpPtr%u)", v->type()->name().c_str(), (uint) j); + } + } else if (pass == PASS_DebugPrint) { + fprintf(fp, "(%s)(tmpPtr%u), *(unsigned int *)(ptr + %s)", + v->type()->name().c_str(), (uint) j, + varoffset.c_str()); + } + varoffset += " + 4"; + } + } + } + } + + if (pass == PASS_FunctionCall || pass == PASS_DebugPrint) fprintf(fp, ");\n"); + if (pass == PASS_DebugPrint) fprintf(fp, "#endif\n"); + + if (pass == PASS_TmpBuffAlloc) { + if (!e->retval().isVoid() && !e->retval().isPointer()) { + if (!totalTmpBuffExist) + fprintf(fp, "\t\t\tsize_t totalTmpSize = sizeof(%s);\n", retvalType.c_str()); + else + fprintf(fp, "\t\t\ttotalTmpSize += sizeof(%s);\n", retvalType.c_str()); + + totalTmpBuffExist = true; + } + if (totalTmpBuffExist) { + fprintf(fp, "\t\t\tunsigned char *tmpBuf = stream->alloc(totalTmpSize);\n"); + } + } + + if (pass == PASS_Epilog) { + // send back out pointers data as well as retval + if (totalTmpBuffExist) { + fprintf(fp, "\t\t\tstream->flush();\n"); + } + + fprintf(fp, "\t\t\tpos += *(int *)(ptr + 4);\n"); + fprintf(fp, "\t\t\tptr += *(int *)(ptr + 4);\n"); + } + + } // pass; + fprintf(fp, "\t\t\t}\n"); + fprintf(fp, "#ifdef CHECK_GL_ERROR\n"); + fprintf(fp, "\t\t\tsprintf(lastCall, \"%s\");\n", e->name().c_str()); + fprintf(fp, "#endif\n"); + fprintf(fp, "\t\t\tbreak;\n"); + + delete [] tmpBufOffset; + } + fprintf(fp, "\t\t\tdefault:\n"); + fprintf(fp, "\t\t\t\tunknownOpcode = true;\n"); + fprintf(fp, "\t\t} //switch\n"); + if (strstr(m_basename.c_str(), "gl")) { + fprintf(fp, "#ifdef CHECK_GL_ERROR\n"); + fprintf(fp, "\tint err = this->glGetError();\n"); + fprintf(fp, "\tif (err) fprintf(stderr, \"%s Error: 0x%%X in %%s\\n\", err, lastCall);\n", m_basename.c_str()); + fprintf(fp, "#endif\n"); + } + fprintf(fp, "\t} // while\n"); + fprintf(fp, "\treturn pos;\n"); + fprintf(fp, "}\n"); + + fclose(fp); + return 0; +} + +int ApiGen::readSpec(const std::string & filename) +{ + FILE *specfp = fopen(filename.c_str(), "rt"); + if (specfp == NULL) { + return -1; + } + + char line[1000]; + unsigned int lc = 0; + while (fgets(line, sizeof(line), specfp) != NULL) { + lc++; + EntryPoint ref; + if (ref.parse(lc, std::string(line))) { + push_back(ref); + updateMaxEntryPointsParams(ref.vars().size()); + } + } + fclose(specfp); + return 0; +} + +int ApiGen::readAttributes(const std::string & attribFilename) +{ + enum { ST_NAME, ST_ATT } state; + + FILE *fp = fopen(attribFilename.c_str(), "rt"); + if (fp == NULL) { + perror(attribFilename.c_str()); + return -1; + } + char buf[1000]; + + state = ST_NAME; + EntryPoint *currentEntry = NULL; + size_t lc = 0; + bool globalAttributes = false; + while (fgets(buf, sizeof(buf), fp) != NULL) { + lc++; + std::string line(buf); + if (line.size() == 0) continue; // could that happen? + + if (line.at(0) == '#') continue; // comment + + size_t first = line.find_first_not_of(" \t\n"); + if (state == ST_ATT && (first == std::string::npos || first == 0)) state = ST_NAME; + + line = trim(line); + if (line.size() == 0 || line.at(0) == '#') continue; + + switch(state) { + case ST_NAME: + if (line == "GLOBAL") { + globalAttributes = true; + } else { + globalAttributes = false; + currentEntry = findEntryByName(line); + if (currentEntry == NULL) { + fprintf(stderr, "WARNING: %u: attribute of non existant entry point %s\n", (unsigned int)lc, line.c_str()); + } + } + state = ST_ATT; + break; + case ST_ATT: + if (globalAttributes) { + setGlobalAttribute(line, lc); + } else if (currentEntry != NULL) { + currentEntry->setAttribute(line, lc); + } + break; + } + } + return 0; +} + + +int ApiGen::setGlobalAttribute(const std::string & line, size_t lc) +{ + size_t pos = 0; + size_t last; + std::string token = getNextToken(line, pos, &last, WHITESPACE); + pos = last; + + if (token == "base_opcode") { + std::string str = getNextToken(line, pos, &last, WHITESPACE); + if (str.size() == 0) { + fprintf(stderr, "line %u: missing value for base_opcode\n", (uint) lc); + } else { + setBaseOpcode(atoi(str.c_str())); + } + } else if (token == "encoder_headers") { + std::string str = getNextToken(line, pos, &last, WHITESPACE); + pos = last; + while (str.size() != 0) { + encoderHeaders().push_back(str); + str = getNextToken(line, pos, &last, WHITESPACE); + pos = last; + } + } else if (token == "client_context_headers") { + std::string str = getNextToken(line, pos, &last, WHITESPACE); + pos = last; + while (str.size() != 0) { + clientContextHeaders().push_back(str); + str = getNextToken(line, pos, &last, WHITESPACE); + pos = last; + } + } else if (token == "server_context_headers") { + std::string str = getNextToken(line, pos, &last, WHITESPACE); + pos = last; + while (str.size() != 0) { + serverContextHeaders().push_back(str); + str = getNextToken(line, pos, &last, WHITESPACE); + pos = last; + } + } else if (token == "decoder_headers") { + std::string str = getNextToken(line, pos, &last, WHITESPACE); + pos = last; + while (str.size() != 0) { + decoderHeaders().push_back(str); + str = getNextToken(line, pos, &last, WHITESPACE); + pos = last; + } + } + else { + fprintf(stderr, "WARNING: %u : unknown global attribute %s\n", (unsigned int)lc, line.c_str()); + } + + return 0; +} + diff --git a/emulator/opengl/host/tools/emugen/ApiGen.h b/emulator/opengl/host/tools/emugen/ApiGen.h new file mode 100644 index 0000000..1627ef6 --- /dev/null +++ b/emulator/opengl/host/tools/emugen/ApiGen.h @@ -0,0 +1,95 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef __API_GEN_H_ +#define __API_GEN_H_ + +#include <vector> +#include <string.h> +#include "EntryPoint.h" + + +class ApiGen : public std::vector<EntryPoint> { + +public: + typedef std::vector<std::string> StringVec; + typedef enum { CLIENT_SIDE, SERVER_SIDE, WRAPPER_SIDE } SideType; + + ApiGen(const std::string & basename) : + m_basename(basename), + m_maxEntryPointsParams(0), + m_baseOpcode(0) + { } + virtual ~ApiGen() {} + int readSpec(const std::string & filename); + int readAttributes(const std::string & attribFilename); + size_t maxEntryPointsParams() { return m_maxEntryPointsParams; } + void updateMaxEntryPointsParams(size_t val) { + if (m_maxEntryPointsParams == 0 || val > m_maxEntryPointsParams) m_maxEntryPointsParams = val; + } + int baseOpcode() { return m_baseOpcode; } + void setBaseOpcode(int base) { m_baseOpcode = base; } + + const char *sideString(SideType side) { + const char *retval; + switch(side) { + case CLIENT_SIDE: + retval = "client"; + break; + case SERVER_SIDE: + retval = "server"; + break; + case WRAPPER_SIDE: + retval = "wrapper"; + break; + } + return retval; + } + + StringVec & clientContextHeaders() { return m_clientContextHeaders; } + StringVec & encoderHeaders() { return m_encoderHeaders; } + StringVec & serverContextHeaders() { return m_serverContextHeaders; } + StringVec & decoderHeaders() { return m_decoderHeaders; } + + EntryPoint * findEntryByName(const std::string & name); + int genOpcodes(const std::string &filename); + int genAttributesTemplate(const std::string &filename); + int genProcTypes(const std::string &filename, SideType side); + int genFuncTable(const std::string &filename, SideType side); + + int genContext(const std::string &filename, SideType side); + int genContextImpl(const std::string &filename, SideType side); + + int genEntryPoints(const std::string &filename, SideType side); + + int genEncoderHeader(const std::string &filename); + int genEncoderImpl(const std::string &filename); + + int genDecoderHeader(const std::string &filename); + int genDecoderImpl(const std::string &filename); + +protected: + virtual void printHeader(FILE *fp) const; + std::string m_basename; + StringVec m_clientContextHeaders; + StringVec m_encoderHeaders; + StringVec m_serverContextHeaders; + StringVec m_decoderHeaders; + size_t m_maxEntryPointsParams; // record the maximum number of parameters in the entry points; + int m_baseOpcode; + int setGlobalAttribute(const std::string & line, size_t lc); +}; + +#endif diff --git a/emulator/opengl/host/tools/emugen/EntryPoint.cpp b/emulator/opengl/host/tools/emugen/EntryPoint.cpp new file mode 100644 index 0000000..43b904b --- /dev/null +++ b/emulator/opengl/host/tools/emugen/EntryPoint.cpp @@ -0,0 +1,376 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include <stdio.h> +#include "EntryPoint.h" +#include <string> +#include "TypeFactory.h" +#include "strUtils.h" +#include <sstream> + + +EntryPoint::EntryPoint() +{ + reset(); +} + +EntryPoint::~EntryPoint() +{ +} + +void EntryPoint::reset() +{ + m_unsupported = false; + m_customDecoder = false; + m_notApi = false; + m_vars.empty(); +} + +bool parseTypeField(const std::string & f, std::string *vartype, std::string *varname) +{ + size_t pos = 0, last; + bool done = false; + + + *vartype = ""; + if (varname != NULL) *varname = ""; + + enum { ST_TYPE, ST_NAME, ST_END } state = ST_TYPE; + + while(!done) { + + std::string str = getNextToken(f, pos, &last, WHITESPACE); + if (str.size() == 0) break; + + switch(state) { + case ST_TYPE: + if (str == "const") { + pos = last; + *vartype = "const "; + } else { + // must be a type name; + *vartype += str; + state = ST_NAME; + pos = last; + } + break; + case ST_NAME: + if (str.size() == 0) { + done = true; + } else if (str == "*") { + (*vartype) += "*"; + pos = last; + } else if (varname == NULL) { + done = true; + } else { + while (str[0] == '*') { + (*vartype) += "*"; + str[0] = ' '; + str = trim(str); + } + *varname = str; + done = true; + } + break; + case ST_END: + break; + } + } + return true; +} + +// return true for valid line (need to get into the entry points list) +bool EntryPoint::parse(unsigned int lc, const std::string & str) +{ + size_t pos, last; + std::string field; + + reset(); + std::string linestr = trim(str); + + if (linestr.size() == 0) return false; + if (linestr.at(0) == '#') return false; + + // skip PREFIX + field = getNextToken(linestr, 0, &last, "("); + pos = last + 1; + // return type + field = getNextToken(linestr, pos, &last, ",)"); + std::string retTypeName; + if (!parseTypeField(field, &retTypeName, NULL)) { + fprintf(stderr, "line: %d: Parsing error in field <%s>\n", lc, field.c_str()); + return false; + } + pos = last + 1; + const VarType *theType = TypeFactory::instance()->getVarTypeByName(retTypeName); + if (theType->name() == "UNKNOWN") { + fprintf(stderr, "UNKNOWN retval: %s\n", linestr.c_str()); + } + + m_retval.init(std::string(""), theType, std::string(""), Var::POINTER_OUT, std::string(""), std::string("")); + + // function name + m_name = getNextToken(linestr, pos, &last, ",)"); + pos = last + 1; + + // parameters; + int nvars = 0; + while (pos < linestr.size() - 1) { + field = getNextToken(linestr, pos, &last, ",)"); + std::string vartype, varname; + if (!parseTypeField(field, &vartype, &varname)) { + fprintf(stderr, "line: %d: Parsing error in field <%s>\n", lc, field.c_str()); + return false; + } + nvars++; + const VarType *v = TypeFactory::instance()->getVarTypeByName(vartype); + if (v->id() == 0) { + fprintf(stderr, "%d: Unknown type: %s\n", lc, vartype.c_str()); + } else { + if (varname == "" && + !(v->name() == "void" && !v->isPointer())) { + std::ostringstream oss; + oss << "var" << nvars; + varname = oss.str(); + } + + m_vars.push_back(Var(varname, v, std::string(""), Var::POINTER_IN, "", "")); + } + pos = last + 1; + } + return true; +} + +void EntryPoint::print(FILE *fp, bool newline, + const std::string & name_suffix, + const std::string & name_prefix, + const std::string & ctx_param ) const +{ + fprintf(fp, "%s %s%s%s(", + m_retval.type()->name().c_str(), + name_prefix.c_str(), + m_name.c_str(), + name_suffix.c_str()); + + if (ctx_param != "") fprintf(fp, "%s ", ctx_param.c_str()); + + for (size_t i = 0; i < m_vars.size(); i++) { + if (m_vars[i].isVoid()) continue; + if (i != 0 || ctx_param != "") fprintf(fp, ", "); + fprintf(fp, "%s %s", m_vars[i].type()->name().c_str(), + m_vars[i].name().c_str()); + } + fprintf(fp, ")%s", newline? "\n" : ""); +} + +Var * EntryPoint::var(const std::string & name) +{ + Var *v = NULL; + for (size_t i = 0; i < m_vars.size(); i++) { + if (m_vars[i].name() == name) { + v = &m_vars[i]; + break; + } + } + return v; +} + +bool EntryPoint::hasPointers() +{ + bool pointers = false; + if (m_retval.isPointer()) pointers = true; + if (!pointers) { + for (size_t i = 0; i < m_vars.size(); i++) { + if (m_vars[i].isPointer()) { + pointers = true; + break; + } + } + } + return pointers; +} + +int EntryPoint::setAttribute(const std::string &line, size_t lc) +{ + size_t pos = 0; + size_t last; + std::string token = getNextToken(line, 0, &last, WHITESPACE); + + if (token == "len") { + pos = last; + std::string varname = getNextToken(line, pos, &last, WHITESPACE); + + if (varname.size() == 0) { + fprintf(stderr, "ERROR: %u: Missing variable name in 'len' attribute\n", (unsigned int)lc); + return -1; + } + Var * v = var(varname); + if (v == NULL) { + fprintf(stderr, "ERROR: %u: variable %s is not a parameter of %s\n", + (unsigned int)lc, varname.c_str(), name().c_str()); + return -2; + } + // set the size expression into var + pos = last; + v->setLenExpression(line.substr(pos)); + } else if (token == "param_check") { + pos = last; + std::string varname = getNextToken(line, pos, &last, WHITESPACE); + + if (varname.size() == 0) { + fprintf(stderr, "ERROR: %u: Missing variable name in 'param_check' attribute\n", (unsigned int)lc); + return -1; + } + Var * v = var(varname); + if (v == NULL) { + fprintf(stderr, "ERROR: %u: variable %s is not a parameter of %s\n", + (unsigned int)lc, varname.c_str(), name().c_str()); + return -2; + } + // set the size expression into var + pos = last; + v->setParamCheckExpression(line.substr(pos)); + + } else if (token == "dir") { + pos = last; + std::string varname = getNextToken(line, pos, &last, WHITESPACE); + if (varname.size() == 0) { + fprintf(stderr, "ERROR: %u: Missing variable name in 'dir' attribute\n", (unsigned int)lc); + return -1; + } + Var * v = var(varname); + if (v == NULL) { + fprintf(stderr, "ERROR: %u: variable %s is not a parameter of %s\n", + (unsigned int)lc, varname.c_str(), name().c_str()); + return -2; + } + + pos = last; + std::string pointerDirStr = getNextToken(line, pos, &last, WHITESPACE); + if (pointerDirStr.size() == 0) { + fprintf(stderr, "ERROR: %u: missing pointer directions\n", (unsigned int)lc); + return -3; + } + + if (pointerDirStr == "out") { + v->setPointerDir(Var::POINTER_OUT); + } else if (pointerDirStr == "inout") { + v->setPointerDir(Var::POINTER_INOUT); + } else if (pointerDirStr == "in") { + v->setPointerDir(Var::POINTER_IN); + } else { + fprintf(stderr, "ERROR: %u: unknow pointer direction %s\n", (unsigned int)lc, pointerDirStr.c_str()); + } + } else if (token == "var_flag") { + pos = last; + std::string varname = getNextToken(line, pos, &last, WHITESPACE); + if (varname.size() == 0) { + fprintf(stderr, "ERROR: %u: Missing variable name in 'var_flag' attribute\n", (unsigned int)lc); + return -1; + } + Var * v = var(varname); + if (v == NULL) { + fprintf(stderr, "ERROR: %u: variable %s is not a parameter of %s\n", + (unsigned int)lc, varname.c_str(), name().c_str()); + return -2; + } + int count = 0; + for (;;) { + pos = last; + std::string flag = getNextToken(line, pos, &last, WHITESPACE); + if (flag.size() == 0) { + if (count == 0) { + fprintf(stderr, "ERROR: %u: missing flag\n", (unsigned int) lc); + return -3; + } + break; + } + count++; + + if (flag == "nullAllowed") { + if (v->isPointer()) { + v->setNullAllowed(true); + } else { + fprintf(stderr, "WARNING: %u: setting nullAllowed for non-pointer variable %s\n", + (unsigned int) lc, v->name().c_str()); + } + } else if (flag == "isLarge") { + if (v->isPointer()) { + v->setIsLarge(true); + } else { + fprintf(stderr, "WARNING: %u: setting isLarge flag for a non-pointer variable %s\n", + (unsigned int) lc, v->name().c_str()); + } + } else { + fprintf(stderr, "WARNING: %u: unknow flag %s\n", (unsigned int)lc, flag.c_str()); + } + } + } else if (token == "custom_pack") { + pos = last; + std::string varname = getNextToken(line, pos, &last, WHITESPACE); + + if (varname.size() == 0) { + fprintf(stderr, "ERROR: %u: Missing variable name in 'custom_pack' attribute\n", (unsigned int)lc); + return -1; + } + Var * v = var(varname); + if (v == NULL) { + fprintf(stderr, "ERROR: %u: variable %s is not a parameter of %s\n", + (unsigned int)lc, varname.c_str(), name().c_str()); + return -2; + } + // set the size expression into var + pos = last; + v->setPackExpression(line.substr(pos)); + } else if (token == "custom_write") { + pos = last; + std::string varname = getNextToken(line, pos, &last, WHITESPACE); + + if (varname.size() == 0) { + fprintf(stderr, "ERROR: %u: Missing variable name in 'custom_write' attribute\n", (unsigned int)lc); + return -1; + } + Var * v = var(varname); + if (v == NULL) { + fprintf(stderr, "ERROR: %u: variable %s is not a parameter of %s\n", + (unsigned int)lc, varname.c_str(), name().c_str()); + return -2; + } + // set the size expression into var + pos = last; + v->setWriteExpression(line.substr(pos)); + } else if (token == "flag") { + pos = last; + std::string flag = getNextToken(line, pos, &last, WHITESPACE); + if (flag.size() == 0) { + fprintf(stderr, "ERROR: %u: missing flag\n", (unsigned int) lc); + return -4; + } + + if (flag == "unsupported") { + setUnsupported(true); + } else if (flag == "custom_decoder") { + setCustomDecoder(true); + } else if (flag == "not_api") { + setNotApi(true); + } else { + fprintf(stderr, "WARNING: %u: unknown flag %s\n", (unsigned int)lc, flag.c_str()); + } + } else { + fprintf(stderr, "WARNING: %u: unknown attribute %s\n", (unsigned int)lc, token.c_str()); + } + + return 0; +} diff --git a/emulator/opengl/host/tools/emugen/EntryPoint.h b/emulator/opengl/host/tools/emugen/EntryPoint.h new file mode 100644 index 0000000..77b8a7f --- /dev/null +++ b/emulator/opengl/host/tools/emugen/EntryPoint.h @@ -0,0 +1,67 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef __EntryPoint__H__ +#define __EntryPoint__H__ + +#include <string> +#include <vector> +#include <stdio.h> + +#include "Var.h" + +//--------------------------------------------------- + +typedef std::vector<Var> VarsArray; + +class EntryPoint { +public: + EntryPoint(); + virtual ~EntryPoint(); + bool parse(unsigned int lc, const std::string & str); + void reset(); // reset the class to empty; + void print(FILE *fp = stdout, bool newline = true, + const std::string & name_suffix = std::string(""), + const std::string & name_prefix = std::string(""), + const std::string & ctx_param = std::string("")) const; + const std::string & name() const { return m_name; } + VarsArray & vars() { return m_vars; } + Var & retval() { return m_retval; } + Var * var(const std::string & name); + bool hasPointers(); + bool unsupported() const { return m_unsupported; } + void setUnsupported(bool state) { m_unsupported = state; } + bool customDecoder() { return m_customDecoder; } + void setCustomDecoder(bool state) { m_customDecoder = state; } + bool notApi() const { return m_notApi; } + void setNotApi(bool state) { m_notApi = state; } + int setAttribute(const std::string &line, size_t lc); + +private: + enum { PR_RETVAL = 0, PR_NAME, PR_VARS, PR_DONE } prState; + std::string m_name; + Var m_retval; + VarsArray m_vars; + bool m_unsupported; + bool m_customDecoder; + bool m_notApi; + + void err(unsigned int lc, const char *msg) { + fprintf(stderr, "line %d: %s\n", lc, msg); + } +}; + + +#endif diff --git a/emulator/opengl/host/tools/emugen/README b/emulator/opengl/host/tools/emugen/README new file mode 100644 index 0000000..0fe85f9 --- /dev/null +++ b/emulator/opengl/host/tools/emugen/README @@ -0,0 +1,332 @@ +Introduction: +------------- +The emugen tool is a tool to generate a wire protocol implementation +based on provided API. The tool generates c++ encoder code that takes +API calls and encodes them into the wire and decoder code that decodes +the wire stream and calls server matching API. +The emugen tool includes additional functionality that enables to +generate an wrapper library. The wrapper library provides entry points +for the specified API, where each entry routes the call via a dispatch +table. The dispatch table may be initialized as required by a specific application. + +The following paragraphs includes the following: + * Wire Protocol Description + * Input files description & format + * Generated code description. + + +Note: In this document, the caller is referred to as Encoder or Client +and the callee is referred to as the Decoder or Server. These terms +are used interchangeably by the context. + + + +Wire Protocol packet structure: +------------------------------- +A general Encoder->Decoder packet is structured as following: +struct Packet { + unsigned int opcode; + unsigned int packet_len; + … parameter 1 + … parameter 2 +}; +A general Decoder->Encoder reply is expected to be received in the +context of the ‘call’ that triggered it, thus it includes the reply +data only, with no context headers. In precise term terms, a reply +packet will look like: + +struct { + ...// reply data +}; + +consider the following function call: +int foo(int p1, short s1) +will be encoded into : +{ + 101, // foo opcode + 14, // sizeof(opcode) + sizeof(packet_len) + sizeof(int) + sizeof(short) + p1, // 4 bytes + s1 // 2 bytes +} + +Since ‘foo’ returns value, the caller is expected to read back the return packet from the server->client stream. The return value in this example is in thus the return packet is: +{ + int retval; +} + + +Pointer decoding: +---------------- +The wire protocol also allows exchanging of pointer data +(arrays). Pointers are defined with directions: + + in : Data is sent from the caller to the calle + out: Data is sent from the callee to the caller + in_out: data is sent from the caller and return in place. + +‘in’ and ‘in_out’ encoded with their len: +{ + unsinged int pointer_data_len; + unsigned char data[pointer_data_len];… // pointer data +} + +‘out’ pointers are encoded by data length only: +{ +unsigned int pointer_data_len; +} + +‘out’ and ‘in_out’ pointer’s data is returned in the return +packet. For example, consider the following call: + +int foo(int n, int *ptr); // assume that ‘data’ is in_out pointer which contains ‘n’ ints + +The caller packet will have the following form: +{ + 101, // foo opcode + xx, sizeof(opcode) + sizeof(datalen) + sizeof(int) + sizeof(unsigned int) + n * sizeof(int); + n, // the n parameter + n * sizeof(int), // size of the data in ptr + … // n* sizeof(int) bytes +} + +The return packet is; +{ + …. // n * sizeof(int) bytes of data return in ptr + retval // sizeof(int) - the return value of the function; +} + +Endianess +--------- +The Wire protocol is designed to impose minimum overhead on the client +side. Thus, the data endianness that is sent across the wire is +determined by the ‘client’ side. It is up to the server side to +determine the client endianess and marshal the packets as required. + + + +Emugen input files - protocol specification +------------------------------------------- +The protocol generated by emugen consists of two input files: + +1. basename.in - A sepcification of the protocol RPC procedures. This +part of the specification is expected to be generated automatically +from c/c++ header files or similar. + +‘basename’ is the basename for the protocol and will be used to prefix +the files that are generated for this protocol. A line in the .in +file has the following format: + +[prefix](retvalType, FuncName, <param type> [param name],...) +where + retvalType - The function return value type + FuncName - function name + <param type> mandatory parameter type + [param name] - optional parameter name +Examples: +GL_ENTRY(void, glVertex1f, float v) +XXX(int *, foo, int n, float, short) +XXX(void, glFlush, void) + +Note: Empty lines in the file are ignored. A line starts with # is a comment + +2. basename.attrib - Attributes information of the API. +This file includes additional flags, pointers datalen information and +global attributes of the protocol. For uptodate format of the file, +please refer to the specification file in the project source +tree. The format of the .attrib file is described below. + +3. basename.types - Types information + +This files describes the types that are described by the API. A type +is defined as follows: +<type name> <size in bits> <print format string> <is a pointer? true|false> +where: +<type name> is the name of the type as described in the API +<size in bits> 0, 8, 16, 32 sizes are accepted +<print format string> a string to format the value of the type, as +acceted by printf(3) +<is pointer?> true or false string species whether the type should be +treated as a pointer. + +example: +GLint 32 %d false +GLint* 32 %p true +GLptr 32 %p true + +Encoder generated code files +---------------------------- +In order to generate the encoder files, one should run the ‘emugen’ +tool as follows: + +emugen -i <input directory> -E <encoder files output directory> <basename> +where: + <input directory> containes the api specification files (basename.in + basename.attrib) + <encoder directory> - a directory name to generate the encoder output files + basename - The basename for the api. + +Assuming the basename is ‘api’, The following files are generated: + +api_opcodes.h - defines the protocol opcodes. The first opcode value +is 0, unless defined otherwise in the .attrib file + +api_entry.cpp - defines entry points for the functions that are +defined by the protocol. this File also includes a function call +‘setContextAccessor(void *(*f)()). This function should be used to +provide a callback function that is used by the functions to access +the encoder context. For example, such callback could fetch the +context from a Thread Local Storage (TLS) location. + +api_client_proc.h - type defintions for the protocol procedures. + +api_client_context.h - defines the client side dispatch table data +structure that stores the encoding functions. This data structure also +includes ‘accessors’ methods such that library user can override +default entries for special case handling. + +api_client_context.cpp - defines an initialization function for +dispatch table + +api_enc.h - This header file defines the encoder data strcuture. The +encoder data structure inherits its functionality from the +‘client_context’ class above and adds encoding and streaming +functionality. + +api_enc.cpp - Encoder implementation. + +Decoder generated files +----------------------- +In order to generate the decoder files, one should run the ‘emugen’ +tool as follows: +emugen -i <input directory> -D <decoder files output directory> basename +where: + <input directory> containes the api specification files (basename.in + basename.attrib) + <decoder directory> - a directory name to generate the decoder output files + basename - The basename for the api. + +With resepct to the example above, Emugen will generate the following +files: + +api_opcodes.h - Protocol opcodes + +api_server_proc.h - type definitions for the server side procedures + +api_server_context.h - dispatch table the decoder functions + +api_server_context.cpp - dispatch table initialization function +api_dec.h - Decoder header file + +api_dec.cpp - Decoder implementation. In addtion, this file includes +an intiailization function that uses a user provided callback to +initialize the API server implementation. An example for such +initialization is loading a set of functions from a shared library +module. + +Wrapper generated files +----------------------- +In order to generate a wrapper library files, one should run the +'emugen' tool as follows: + +emugen -i <input directory> -W <wrapper files output directory> basename +where: + <input directory> containes the api specification files (basename.in + basename.attrib) + <wrapper directory> - a directory name to generate the wrapper output files + basename - The basename for the api. + +With resepct to the example above, Emugen will generate the following +files: + +api_wrapper_proc.h - type definitions for the wrapper procedures + +api_wrapper_context.h - dispatch table the wrapper functions + +api_wrapper_context.cpp - dispatch table initialization function +api_wrapper_entry.cpp - entry points for the API + + +.attrib file format description: +------------------------------- +The .attrib file is an input file to emugen and is used to provide + additional information that is required for the code generation. +The file format is as follows: + +a line that starts with # is ignored (comment) +a empty line just whitespace of (" " "\t" "\n") is ignored. + +The file is divided into 'sections', each describes a specific API +function call. A section starts with the name of the function in +column 0. + +A section that starts with the reserved word 'GLOBAL' provides global +attributes. + +below are few sections examples: + +GLOBAL + encoder_headers string.h kuku.h + +glVertex3fv + len data (size) +glTexImage2D + len pixels (pixels == NULL? 0 : (format_pixel_size(internalformat) * width * height * type_size(type))) + + +Global section flags description: + +base_opcode + set the base opcode value for this api + format: base_opcode 100 + +encoder_headers + a list of headers that will be included in the encoder header file + format: encoder_headers <stdio.h> "kuku.h" + +client_context_headers + a list of headers that will be included in the client context header file + format: client_context_headers <stdio.h> "kuku.h" + +decoder_headers + a list of headers that will be included in the decoder header file + format: decoder_headers <stdio.h> "kuku.h" + +server_context_headers + a list of headers that will be included in the server context header file + format: server_context_headers <stdio.h> "kuku.h" + + +Entry point flags description: + + len + desciption : provide an expression to calcualte an expression data len + format: len <var name> <c expression that calcluates the data len> + +custom_pack + description: provide an expression to pack data into the stream. + format: custom_pack <var name> <c++ expression that pack data from var into the stream> + The stream is represented by a (unsigned char *)ptr. The expression may also refer + to other function parameters. In addition, the expression may refer to 'void *self' which + is the encoding context as provided by the caller. + + dir + description : set a pointer direction (in - for data that goes + to the codec, out from data that returns from the codec. + format: dir <varname> <[in | out | inout]> + + var_flag + description : set variable flags + format: var_flag <varname> < nullAllowed | isLarge | ... > + + nullAllowed -> for pointer variables, indicates that NULL is a valid value + isLarge -> for pointer variables, indicates that the data should be sent without an intermediate copy + + flag + description: set entry point flag; + format: flag < unsupported | ... > + supported flags are: + unsupported - The encoder side implementation is pointed to "unsuppored reporting function". + custom_decoder - The decoder is expected to be provided with + custom implementation. The call to the + deocder function includes a pointer to the + context + not_api - the function is not native gl api + + diff --git a/emulator/opengl/host/tools/emugen/TypeFactory.cpp b/emulator/opengl/host/tools/emugen/TypeFactory.cpp new file mode 100644 index 0000000..8884225 --- /dev/null +++ b/emulator/opengl/host/tools/emugen/TypeFactory.cpp @@ -0,0 +1,156 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "TypeFactory.h" +#include "VarType.h" +#include <string> +#include <map> +#include <stdio.h> +#include <stdlib.h> +#include "strUtils.h" + + +TypeFactory * TypeFactory::m_instance = NULL; + +static Var0 g_var0; +static Var8 g_var8; +static Var16 g_var16; +static Var32 g_var32; + +typedef std::map<std::string, VarType> TypeMap; +static TypeMap g_varMap; +static bool g_initialized = false; +static int g_typeId = 0; + + +static VarConverter * getVarConverter(int size) +{ + VarConverter *v = NULL; + + switch(size) { + case 0: v = &g_var0; break; + case 8: v = &g_var8; break; + case 16: v = &g_var16; break; + case 32: v = &g_var32; break; + } + return v; +} + +#define ADD_TYPE(name, size, printformat,ispointer) \ + g_varMap.insert(std::pair<std::string, VarType>(name, VarType(g_typeId++, name, &g_var##size , printformat , ispointer))); + +void TypeFactory::initBaseTypes() +{ + g_initialized = true; + ADD_TYPE("UNKNOWN", 0, "0x%x", false); + ADD_TYPE("void", 0, "0x%x", false); + ADD_TYPE("char", 8, "%c", false); + ADD_TYPE("int", 32, "%d", false); + ADD_TYPE("float", 32, "%d", false); + ADD_TYPE("short", 16, "%d", false); +} + +int TypeFactory::initFromFile(const std::string &filename) +{ + if (!g_initialized) { + initBaseTypes(); + } + + FILE *fp = fopen(filename.c_str(), "rt"); + if (fp == NULL) { + perror(filename.c_str()); + return -1; + } + char line[1000]; + int lc = 0; + while(fgets(line, sizeof(line), fp) != NULL) { + lc++; + std::string str = trim(line); + if (str.size() == 0 || str.at(0) == '#') { + continue; + } + size_t pos = 0, last; + std::string name; + name = getNextToken(str, pos, &last, WHITESPACE); + if (name.size() == 0) { + fprintf(stderr, "Error: %d : missing type name\n", lc); + return -2; + } + pos = last + 1; + std::string size; + size = getNextToken(str, pos, &last, WHITESPACE); + if (size.size() == 0) { + fprintf(stderr, "Error: %d : missing type width\n", lc); + return -2; + } + pos = last + 1; + std::string printString; + printString = getNextToken(str, pos, &last, WHITESPACE); + if (printString.size() == 0) { + fprintf(stderr, "Error: %d : missing print-string\n", lc); + return -2; + } + + pos = last + 1; + std::string pointerDef; + pointerDef = getNextToken(str, pos, &last, WHITESPACE); + if (pointerDef.size() == 0) { + fprintf(stderr, "Error: %d : missing ispointer definition\n", lc); + return -2; + } + + bool isPointer=false; + if (std::string("true")==pointerDef) + isPointer = true; + else if (std::string("false")==pointerDef) + isPointer = false; + else + { + fprintf(stderr, "Error: %d : invalid isPointer definition, must be either \"true\" or \"false\"\n", lc); + return -2; + } + + VarConverter *v = getVarConverter(atoi(size.c_str())); + if (v == NULL) { + fprintf(stderr, "Error: %d : unknown var width: %d\n", lc, atoi(size.c_str())); + return -1; + } + + if (getVarTypeByName(name)->id() != 0) { + fprintf(stderr, + "Warining: %d : type %s is already known, definition in line %d is taken\n", + lc, name.c_str(), lc); + } + g_varMap.insert(std::pair<std::string, VarType>(name, VarType(g_typeId++, name, v ,printString,isPointer))); + std::string constName = "const " + name; + g_varMap.insert(std::pair<std::string, VarType>(constName, VarType(g_typeId++, constName, v ,printString,isPointer))); //add a const type + } + g_initialized = true; + return 0; +} + + +const VarType * TypeFactory::getVarTypeByName(const std::string & type) +{ + if (!g_initialized) { + initBaseTypes(); + } + TypeMap::iterator i = g_varMap.find(type); + if (i == g_varMap.end()) { + i = g_varMap.find("UNKNOWN"); + } + return &(i->second); +} + diff --git a/emulator/opengl/host/tools/emugen/TypeFactory.h b/emulator/opengl/host/tools/emugen/TypeFactory.h new file mode 100644 index 0000000..deee2ca --- /dev/null +++ b/emulator/opengl/host/tools/emugen/TypeFactory.h @@ -0,0 +1,37 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef __TYPE__FACTORY__H__ +#define __TYPE__FACTORY__H__ + +#include <string> +#include "VarType.h" + +class TypeFactory { +public: + static TypeFactory *instance() { + if (m_instance == NULL) { + m_instance = new TypeFactory; + } + return m_instance; + } + const VarType * getVarTypeByName(const std::string &type); + int initFromFile(const std::string &filename); +private: + static TypeFactory *m_instance; + void initBaseTypes(); + TypeFactory() {} +}; +#endif diff --git a/emulator/opengl/host/tools/emugen/Var.h b/emulator/opengl/host/tools/emugen/Var.h new file mode 100644 index 0000000..322c66a --- /dev/null +++ b/emulator/opengl/host/tools/emugen/Var.h @@ -0,0 +1,110 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef __VAR__H__ +#define __VAR__H__ + +#include "VarType.h" +#include <string> +#include <stdio.h> + +class Var { +public: + // pointer data direction - from the client point of view. + typedef enum { POINTER_OUT = 0x1, POINTER_IN = 0x2, POINTER_INOUT = 0x3 } PointerDir; + Var() : + m_name(""), + m_type(NULL), + m_lenExpression(""), + m_pointerDir(POINTER_IN), + m_nullAllowed(false), + m_isLarge(false), + m_packExpression(""), + m_writeExpression(""), + m_paramCheckExpression("") + + { + } + + Var(const std::string & name, + const VarType * vartype, + const std::string & lenExpression, + PointerDir dir, + const std::string &packExpression, + const std::string &writeExpression) : + m_name(name), + m_type(const_cast<VarType *>(vartype)), + m_lenExpression(lenExpression), + m_pointerDir(dir), + m_nullAllowed(false), + m_isLarge(false), + m_packExpression(packExpression), + m_writeExpression(writeExpression), + m_paramCheckExpression("") + { + } + + void init(const std::string name, const VarType * vartype, + std::string lenExpression, + PointerDir dir, + std::string packExpression, + std::string writeExpression) { + m_name = name; + m_type = vartype; + m_lenExpression = lenExpression; + m_packExpression = packExpression; + m_writeExpression = writeExpression; + m_pointerDir = dir; + m_nullAllowed = false; + m_isLarge = false; + + } + + const std::string & name() const { return m_name; } + const VarType * type() const { return m_type; } + bool isPointer() const { return m_type->isPointer(); } + bool isVoid() const { return ((m_type->bytes() == 0) && (!m_type->isPointer())); } + const std::string & lenExpression() const { return m_lenExpression; } + const std::string & packExpression() const { return(m_packExpression); } + const std::string & writeExpression() const { return(m_writeExpression); } + const std::string & paramCheckExpression() const { return m_paramCheckExpression; } + void setLenExpression(const std::string & lenExpression) { m_lenExpression = lenExpression; } + void setPackExpression(const std::string & packExpression) { m_packExpression = packExpression; } + void setWriteExpression(const std::string & writeExpression) { m_writeExpression = writeExpression; } + void setParamCheckExpression(const std::string & paramCheckExpression) { m_paramCheckExpression = paramCheckExpression; } + void setPointerDir(PointerDir dir) { m_pointerDir = dir; } + PointerDir pointerDir() { return m_pointerDir; } + void setNullAllowed(bool state) { m_nullAllowed = state; } + void setIsLarge(bool state) { m_isLarge = state; } + bool nullAllowed() const { return m_nullAllowed; } + bool isLarge() const { return m_isLarge; } + void printType(FILE *fp) { fprintf(fp, "%s", m_type->name().c_str()); } + void printTypeName(FILE *fp) { printType(fp); fprintf(fp, " %s", m_name.c_str()); } + +private: + std::string m_name; + const VarType * m_type; + bool m_pointer; // is this variable a pointer; + std::string m_lenExpression; // an expression to calcualte a pointer data size + PointerDir m_pointerDir; + bool m_nullAllowed; + bool m_isLarge; + std::string m_packExpression; // an expression to pack data into the stream + std::string m_writeExpression; // an expression to write data into the stream + std::string m_paramCheckExpression; //an expression to check parameter value + +}; + +#endif diff --git a/emulator/opengl/host/tools/emugen/VarType.h b/emulator/opengl/host/tools/emugen/VarType.h new file mode 100644 index 0000000..41bb645 --- /dev/null +++ b/emulator/opengl/host/tools/emugen/VarType.h @@ -0,0 +1,78 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef __VARTYPE__H__ +#define __VARTYPE__H__ + +#include <string> + +class VarConverter { +public: + VarConverter(size_t bytes) : m_bytes(bytes) {} + size_t bytes() const { return m_bytes; } +private: + size_t m_bytes; +}; + +class Var8 : public VarConverter { +public: + Var8() : VarConverter(1) {} +}; + +class Var16 : public VarConverter { +public: + Var16() : VarConverter(2) {} +}; + +class Var32 : public VarConverter { +public: + Var32() : VarConverter(4) {} +}; + +class Var0 : public VarConverter { +public: + Var0() : VarConverter(0) {} +}; + + +class VarType { +public: + VarType() : + m_id(0), m_name("default_constructed"), m_converter(NULL), m_printFomrat("0x%x"), m_isPointer(false) + { + } + + VarType(size_t id, const std::string & name, const VarConverter * converter, const std::string & printFormat , const bool isPointer) : + m_id(id), m_name(name), m_converter(const_cast<VarConverter *>(converter)), m_printFomrat(printFormat), m_isPointer(isPointer) + { + } + + ~VarType() + { + } + const std::string & name() const { return m_name; } + const std::string & printFormat() const { return m_printFomrat; } + size_t bytes() const { return m_converter->bytes(); } + bool isPointer() const { return m_isPointer; } + size_t id() const { return m_id; } +private: + size_t m_id; + std::string m_name; + VarConverter * m_converter; + std::string m_printFomrat; + bool m_isPointer; +}; + +#endif diff --git a/emulator/opengl/host/tools/emugen/errors.h b/emulator/opengl/host/tools/emugen/errors.h new file mode 100644 index 0000000..d09c292 --- /dev/null +++ b/emulator/opengl/host/tools/emugen/errors.h @@ -0,0 +1,24 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef _ERRORS_H_ +#define _ERRORS_H_ + +#define BAD_USAGE -1 +#define BAD_SPEC_FILE -2 +#define BAD_TYPES_FILE -3 +#define BAD_ATTRIBUTES_FILE -4 + +#endif diff --git a/emulator/opengl/host/tools/emugen/main.cpp b/emulator/opengl/host/tools/emugen/main.cpp new file mode 100644 index 0000000..96377f2 --- /dev/null +++ b/emulator/opengl/host/tools/emugen/main.cpp @@ -0,0 +1,164 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include <stdio.h> +#include <stdlib.h> +#include "errors.h" +#include "EntryPoint.h" +#include "strUtils.h" +#include "ApiGen.h" +#include "TypeFactory.h" + +const std::string SPEC_EXTENSION = std::string(".in"); +const std::string ATTRIB_EXTENSION = std::string(".attrib"); +const std::string TYPES_EXTENTION = std::string(".types"); + + +void usage(const char *filename) +{ + fprintf(stderr, "Usage: %s [options] <base name>\n", filename); + fprintf(stderr, "\t-h: This message\n"); + fprintf(stderr, "\t-E <dir>: generate encoder into dir\n"); + fprintf(stderr, "\t-D <dir>: generate decoder into dir\n"); + fprintf(stderr, "\t-i: input dir, local directory by default\n"); + fprintf(stderr, "\t-T : generate attribute template into the input directory\n\t\tno other files are generated\n"); + fprintf(stderr, "\t-W : generate wrapper into dir\n"); +} + +int main(int argc, char *argv[]) +{ + std::string encoderDir = ""; + std::string decoderDir = ""; + std::string wrapperDir = ""; + std::string inDir = "."; + bool generateAttributesTemplate = false; + + int c; + while((c = getopt(argc, argv, "TE:D:i:hW:")) != -1) { + switch(c) { + case 'W': + wrapperDir = std::string(optarg); + break; + case 'T': + generateAttributesTemplate = true; + break; + case 'h': + usage(argv[0]); + exit(0); + break; + case 'E': + encoderDir = std::string(optarg); + break; + case 'D': + decoderDir = std::string(optarg); + break; + case 'i': + inDir = std::string(optarg); + break; + case ':': + fprintf(stderr, "Missing argument !!\n"); + // fall through + default: + usage(argv[0]); + exit(0); + } + } + + if (optind >= argc) { + fprintf(stderr, "Usage: %s [options] <base name> \n", argv[0]); + return BAD_USAGE; + } + + if (encoderDir.size() == 0 && + decoderDir.size() == 0 && + generateAttributesTemplate == false && + wrapperDir.size() == 0) { + fprintf(stderr, "No output specified - aborting\n"); + return BAD_USAGE; + } + + std::string baseName = std::string(argv[optind]); + ApiGen apiEntries(baseName); + + // init types; + std::string typesFilename = inDir + "/" + baseName + TYPES_EXTENTION; + + if (TypeFactory::instance()->initFromFile(typesFilename) < 0) { + fprintf(stderr, "missing or error reading types file: %s...ignored\n", typesFilename.c_str()); + } + + std::string filename = inDir + "/" + baseName + SPEC_EXTENSION; + if (apiEntries.readSpec(filename) < 0) { + perror(filename.c_str()); + return BAD_SPEC_FILE; + } + + + if (generateAttributesTemplate) { + apiEntries.genAttributesTemplate(inDir + "/" + baseName + ATTRIB_EXTENSION); + exit(0); + } + + std::string attribFileName = inDir + "/" + baseName + ATTRIB_EXTENSION; + if (apiEntries.readAttributes(attribFileName) < 0) { + perror(attribFileName.c_str()); + fprintf(stderr, "failed to parse attributes\n"); + exit(1); + } + + if (encoderDir.size() != 0) { + + apiEntries.genOpcodes(encoderDir + "/" + baseName + "_opcodes.h"); + apiEntries.genContext(encoderDir + "/" + baseName + "_client_context.h", ApiGen::CLIENT_SIDE); + apiEntries.genContextImpl(encoderDir + "/" + baseName + "_client_context.cpp", ApiGen::CLIENT_SIDE); + + apiEntries.genProcTypes(encoderDir + "/" + baseName + "_client_proc.h", ApiGen::CLIENT_SIDE); + apiEntries.genFuncTable(encoderDir + "/" + baseName + "_ftable.h", ApiGen::CLIENT_SIDE); + + apiEntries.genEntryPoints(encoderDir + "/" + baseName + "_entry.cpp", ApiGen::CLIENT_SIDE); + apiEntries.genEncoderHeader(encoderDir + "/" + baseName + "_enc.h"); + apiEntries.genEncoderImpl(encoderDir + "/" + baseName + "_enc.cpp"); + } + + if (decoderDir.size() != 0) { + apiEntries.genOpcodes(decoderDir + "/" + baseName + "_opcodes.h"); + apiEntries.genProcTypes(decoderDir + "/" + baseName + "_server_proc.h", ApiGen::SERVER_SIDE); + apiEntries.genContext(decoderDir + "/" + baseName + "_server_context.h", ApiGen::SERVER_SIDE); + apiEntries.genContextImpl(decoderDir + "/" + baseName + "_server_context.cpp", ApiGen::SERVER_SIDE); + apiEntries.genDecoderHeader(decoderDir + "/" + baseName + "_dec.h"); + apiEntries.genDecoderImpl(decoderDir + "/" + baseName + "_dec.cpp"); + } + + if (wrapperDir.size() != 0) { + apiEntries.genProcTypes(wrapperDir + "/" + baseName + "_wrapper_proc.h", ApiGen::WRAPPER_SIDE); + apiEntries.genContext(wrapperDir + "/" + baseName + "_wrapper_context.h", ApiGen::WRAPPER_SIDE); + apiEntries.genContextImpl(wrapperDir + "/" + baseName + "_wrapper_context.cpp", ApiGen::WRAPPER_SIDE); + apiEntries.genEntryPoints(wrapperDir + "/" + baseName + "_wrapper_entry.cpp", ApiGen::WRAPPER_SIDE); + } + +#ifdef DEBUG_DUMP + int withPointers = 0; + printf("%d functions found\n", int(apiEntries.size())); + for (int i = 0; i < apiEntries.size(); i++) { + if (apiEntries[i].hasPointers()) { + withPointers++; + apiEntries[i].print(); + } + } + fprintf(stdout, "%d entries has poitners\n", withPointers); +#endif + +} + diff --git a/emulator/opengl/host/tools/emugen/strUtils.cpp b/emulator/opengl/host/tools/emugen/strUtils.cpp new file mode 100644 index 0000000..357054b --- /dev/null +++ b/emulator/opengl/host/tools/emugen/strUtils.cpp @@ -0,0 +1,49 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include "strUtils.h" + +using namespace std; + + +std::string getNextToken(const std::string & str, size_t pos, size_t * last, const std::string & delim) +{ + if (str.size() == 0 || pos >= str.size()) return ""; + + pos = str.find_first_not_of(WHITESPACE, pos); + if (pos == std::string::npos) return ""; + + *last = str.find_first_of(delim, pos); + if (*last == std::string::npos) *last = str.size(); + std::string retval = str.substr(pos, *last - pos); + retval = trim(retval); + return retval; +} + + +std::string trim(const string & str) +{ + string result; + string::size_type start = str.find_first_not_of(WHITESPACE, 0); + string::size_type end = str.find_last_not_of(WHITESPACE); + if (start == string::npos || end == string::npos) { + result = string(""); + } else { + result = str.substr(start, end - start + 1); + } + return result; +} + + diff --git a/emulator/opengl/host/tools/emugen/strUtils.h b/emulator/opengl/host/tools/emugen/strUtils.h new file mode 100644 index 0000000..3fa0908 --- /dev/null +++ b/emulator/opengl/host/tools/emugen/strUtils.h @@ -0,0 +1,33 @@ +/* +* Copyright (C) 2011 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef STR_UTILS_H_ +#define STR_UTILS_H_ + +#include <string> +#include <sstream> + +#define WHITESPACE " \t\n" + +std::string trim(const std::string & str); +std::string getNextToken(const std::string & str, size_t pos, size_t * last, const std::string & delim); +template <class T> std::string inline toString(const T& t) { + std::stringstream ss; + ss << t; + return ss.str(); + +} + +#endif |