diff options
author | Jesse Hall <jessehall@google.com> | 2012-04-16 12:49:39 -0700 |
---|---|---|
committer | Jesse Hall <jessehall@google.com> | 2012-04-16 15:54:18 -0700 |
commit | ce6c3389061fb9fcdefc94fab2044a8e11600b52 (patch) | |
tree | fedd1a11cbd21ec14bf00be83b8712054f8c5506 | |
parent | ad0111a77b0f0908cc945dc6e8e8949b75cb8886 (diff) | |
download | sdk-ce6c3389061fb9fcdefc94fab2044a8e11600b52.zip sdk-ce6c3389061fb9fcdefc94fab2044a8e11600b52.tar.gz sdk-ce6c3389061fb9fcdefc94fab2044a8e11600b52.tar.bz2 |
Move emulator GLES from development.git to sdk.git
The emulator GLES support has two interfaces: a host shared library
interface used by QEMU, and a protocol between the platform and the
host. The host library interface is not versioned; QEMU and the GLES
renderer must match. The protocol on the other hand must be backwards
compatible: a new GLES renderer must support an older platform image.
Thus for branching purposes it makes more sense to put the GLES
renderer in sdk.git, which is branched along with qemu.git for SDK
releases. Platform images will be built against the protocol version
in the platform branch of sdk.git.
Change-Id: I2c3bce627ecfd0a4b3e688d1839fe10755a21e58
315 files changed, 56685 insertions, 0 deletions
diff --git a/build/sdk_only_whitelist.mk b/build/sdk_only_whitelist.mk index e3dfaab..7a07297 100644 --- a/build/sdk_only_whitelist.mk +++ b/build/sdk_only_whitelist.mk @@ -30,6 +30,7 @@ subdirs += \ prebuilts/tools \ sdk/avdlauncher \ sdk/emulator/mksdcard \ + sdk/emulator/opengl \ sdk/find_java \ sdk/find_lock \ sdk/sdklauncher diff --git a/emulator/opengl/Android.mk b/emulator/opengl/Android.mk new file mode 100644 index 0000000..2c1cb64 --- /dev/null +++ b/emulator/opengl/Android.mk @@ -0,0 +1,94 @@ +# This is the top-level build file for the Android HW OpenGL ES emulation +# in Android. +# +# You must define BUILD_EMULATOR_OPENGL to 'true' in your environment to +# build the following files. +# +# Also define BUILD_EMULATOR_OPENGL_DRIVER to 'true' to build the gralloc +# stuff as well. +# +ifeq (true,$(BUILD_EMULATOR_OPENGL)) + +# Top-level for all modules +EMUGL_PATH := $(call my-dir) + +# Directory containing common headers used by several modules +# This is always set to a module's LOCAL_C_INCLUDES +# See the definition of emugl-begin-module in common.mk +# +EMUGL_COMMON_INCLUDES := $(EMUGL_PATH)/host/include/libOpenglRender + +# common cflags used by several modules +# This is always set to a module's LOCAL_CFLAGS +# See the definition of emugl-begin-module in common.mk +# +EMUGL_COMMON_CFLAGS := -DWITH_GLES2 + +# Uncomment the following line if you want to enable debug traces +# in the GLES emulation libraries. +# EMUGL_COMMON_CFLAGS += -DEMUGL_DEBUG=1 + +# Include common definitions used by all the modules included later +# in this build file. This contains the definition of all useful +# emugl-xxxx functions. +# +include $(EMUGL_PATH)/common.mk + +# IMPORTANT: ORDER IS CRUCIAL HERE +# +# For the import/export feature to work properly, you must include +# modules below in correct order. That is, if module B depends on +# module A, then it must be included after module A below. +# +# This ensures that anything exported by module A will be correctly +# be imported by module B when it is declared. +# +# Note that the build system will complain if you try to import a +# module that hasn't been declared yet anyway. +# + +# First, build the emugen host source-generation tool +# +# It will be used by other modules to generate wire protocol encode/decoder +# source files (see all emugl-gen-decoder/encoder in common.mk) +# +include $(EMUGL_PATH)/host/tools/emugen/Android.mk +include $(EMUGL_PATH)/shared/OpenglOsUtils/Android.mk +include $(EMUGL_PATH)/shared/OpenglCodecCommon/Android.mk + +# System static libraries +include $(EMUGL_PATH)/system/GLESv1_enc/Android.mk +include $(EMUGL_PATH)/system/GLESv2_enc/Android.mk +include $(EMUGL_PATH)/system/renderControl_enc/Android.mk +include $(EMUGL_PATH)/system/OpenglSystemCommon/Android.mk + +# System shared libraries +include $(EMUGL_PATH)/system/GLESv1/Android.mk +include $(EMUGL_PATH)/system/GLESv2/Android.mk + +include $(EMUGL_PATH)/system/gralloc/Android.mk +include $(EMUGL_PATH)/system/egl/Android.mk + +# Host static libraries +include $(EMUGL_PATH)/host/libs/GLESv1_dec/Android.mk +include $(EMUGL_PATH)/host/libs/GLESv2_dec/Android.mk +include $(EMUGL_PATH)/host/libs/renderControl_dec/Android.mk +include $(EMUGL_PATH)/tests/ut_rendercontrol_dec/Android.mk +include $(EMUGL_PATH)/host/libs/Translator/GLcommon/Android.mk +include $(EMUGL_PATH)/host/libs/Translator/GLES_CM/Android.mk +include $(EMUGL_PATH)/host/libs/Translator/GLES_V2/Android.mk +include $(EMUGL_PATH)/host/libs/Translator/EGL/Android.mk + +# Host shared libraries +include $(EMUGL_PATH)/host/libs/libOpenglRender/Android.mk + +# Host executables +include $(EMUGL_PATH)/host/renderer/Android.mk + +# Host unit-test for the renderer. + +include $(EMUGL_PATH)/tests/translator_tests/MacCommon/Android.mk +include $(EMUGL_PATH)/tests/translator_tests/GLES_CM/Android.mk +include $(EMUGL_PATH)/tests/translator_tests/GLES_V2/Android.mk + +endif # BUILD_EMULATOR_OPENGL == true diff --git a/emulator/opengl/DESIGN b/emulator/opengl/DESIGN new file mode 100644 index 0000000..1da44b7 --- /dev/null +++ b/emulator/opengl/DESIGN @@ -0,0 +1,593 @@ +Android Hardware OpenGLES emulation design overview +=================================================== + +Introduction: +------------- + +Hardware GLES emulation in the Android platform is implemented with a mix +of components, which are: + + - Several host "translator" libraries. They implement the EGL, GLES 1.1 and + GLES 2.0 ABIs defined by Khronos, and translate the corresponding function + calls into calls to the appropriate desktop APIs, i.e.: + + - Xgl (Linux), AGL (OS X) or WGL (Windows) for EGL + - desktop GL 2.0 for GLES 1.1 and GLES 2.0 + + _________ __________ __________ + | | | | | | HOST + |TRANSLATOR |TRANSLATOR| |TRANSLATOR| HOST + | EGL | | GLES 1.1 | | GLES 2.0 | TRANSLATOR + |_________| |__________| |__________| LIBRARIES + | | | + - - - | - - - - - - - - - | - - - - - - - - - | - - - - - + | | | + ____v____ ____v_____ _____v____ HOST + | | | | | | SYSTEM + | Xgl | | GL 2.0 | | GL 2.0 | LIBRARIES + |_________| |__________| |__________| + + + + - Several system libraries inside the emulated guest system that implement + the same EGL / GLES 1.1 and GLES 2.0 ABIs. + + They collect the sequence of EGL/GLES function calls and translate then + into a custom wire protocol stream that is sent to the emulator program + through a high-speed communication channel called a "QEMU Pipe". + + For now, all you need to know is that the pipe is implemented with a + custom kernel driver, and provides for _very_ fast bandwidth. All read() + and writes() from/to the pipes are essentially instantaneous from the + guest's point of view. + + + _________ __________ __________ + | | | | | | + |EMULATION| |EMULATION | |EMULATION | GUEST + | EGL | | GLES 1.1 | | GLES 2.0 | SYSTEM + |_________| |__________| |__________| LIBRARIES + | | | + - - - | - - - - - - - - - | - - - - - - - - - | - - - - - + | | | + ____v____________________v____________________v____ GUEST + | | KERNEL + | QEMU PIPE | + |___________________________________________________| + | + - - - - - - - - - - - - - -|- - - - - - - - - - - - - - - - + | + v + EMULATOR + + - Specific code inside the emulator program that is capable of transmitting + the wire protocol stream to a special rendering library or process (called + the "renderer" here), which understands the format. + + | + | PROTOCOL BYTE STREAM + _____v_____ + | | + | EMULATOR | + |___________| + | + | UNMODIFIED PROTOCOL BYTE STREAM + _____v_____ + | | + | RENDERER | + |___________| + + + - The renderer decodes the EGL/GLES commands from the wire + protocol stream, and dispatches them to the translator libraries + appropriately. + + | + | PROTOCOL BYTE STREAM + _____v_____ + | | + | RENDERER | + |___________| + | | | + +-----------------+ | +-----------------+ + | | | + ____v____ ___v______ ____v_____ + | | | | | | HOST + |TRANSLATOR |TRANSLATOR| |TRANSLATOR| HOST + | EGL | | GLES 1.1 | | GLES 2.0 | TRANSLATOR + |_________| |__________| |__________| LIBRARIES + + + + - In reality, the protocol stream flows in both directions, even though most + of the commands result in data going from the guest to the host. A complete + picture of the emulation would thus be: + + + + + + _________ __________ __________ + | | | | | | + |EMULATION| |EMULATION | |EMULATION | GUEST + | EGL | | GLES 1.1 | | GLES 2.0 | SYSTEM + |_________| |__________| |__________| LIBRARIES + ^ ^ ^ + | | | + - - - | - - - - - - - - - | - - - - - - - - - | - - - - - + | | | + ____v____________________v____________________v____ GUEST + | | KERNEL + | QEMU PIPE | + |___________________________________________________| + ^ + | + - - - - - - - - - - - - - -|- - - - - - - - - - - - - - - - + | + | PROTOCOL BYTE STREAM + _____v_____ + | | + | EMULATOR | + |___________| + ^ + | UNMODIFIED PROTOCOL BYTE STREAM + _____v_____ + | | + | RENDERER | + |___________| + ^ ^ ^ + | | | + +-----------------+ | +-----------------+ + | | | + ____v____ ___v______ ____v_____ + | | | | | | + |TRANSLATOR |TRANSLATOR| |TRANSLATOR| HOST + | EGL | | GLES 1.1 | | GLES 2.0 | TRANSLATOR + |_________| |__________| |__________| LIBRARIES + ^ ^ ^ + | | | + - - - | - - - - - - - - - | - - - - - - - - - | - - - - - + | | | + ____v____ ____v_____ _____v____ HOST + | | | | | | SYSTEM + | Xgl | | GL 2.0 | | GL 2.0 | LIBRARIES + |_________| |__________| |__________| + + (NOTE: 'Xgl' is for Linux only, replace 'AGL' on OS X, and 'WGL' on Windows). + + +Note that, in the above graphics, only the host system libraries at the bottom +are _not_ provided by Android. + + +Design Requirements: +-------------------- + +The above design comes from several important requirements that were decided +early in the project: + +1 - The ability to run the renderer in a separate process from the emulator + itself is important. + + For various practical reasons, we plan to completely separate the core QEMU + emulation from the UI window by using two distinct processes. As such, the + renderer will be implemented as a library inside the UI program, but will + need to receive protocol bytes from the QEMU process. + + The communication channel will be either a fast Unix socket or a Win32 + named pipe between these two. A shared memory segment with appropriate + synchronization primitives might also be used if performance becomes + an issue. + + This explains why the emulator doesn't alter or even try to parse the + protocol byte stream. It only acts as a dumb proxy between the guest + system and the renderer. This also avoids adding lots of GLES-specific + code inside the QEMU code base which is terribly complex. + +2 - The ability to use vendor-specific desktop EGL/GLES libraries is + important. + + GPU vendors like NVidia, AMD or ARM all provide host versions of the + EGL/GLES libraries that emulate their respectivie embedded graphics + chipset. + + The renderer library can be configured to use these instead of the + translator libraries provided with this project. This can be useful to + more accurately emulate the behaviour of specific devices. + + Moreover, these vendor libraries typically expose vendor-specific + extensions that are not provided by the translator libraries. We cannot + expose them without modifying our code, but it's important to be able + to do so without too much pain. + + +Code organization: +------------------ + +All source code for the components above is spread over multiple directories +in the Android source trees: + + - The emulator sources are under $ANDROID/external/qemu, which we'll + call $QEMU in the rest of this document. + + - The guest and system libraries are under + $ANDROID/development/tools/emulator/opengl, which we'll call $EMUGL + + - The QEMU Pipe kernel driver is under $KERNEL/drivers/misc/qemupipe + +Where $ANDROID is the top of the open-source Android source tree, and +$KERNEL is the top of the qemu-specific kernel source tree (using one +of the android-goldfish-xxxx branches here). + +The emulator sources related to this projects are: + + $QEMU/hw/goldfish_pipe.c -> implement QEMU pipe virtual hardware + $QEMU/hw/opengles.c -> implement GLES initialization + $QEMU/hw/hw-pipe-net.c -> implements the communication channel + between the QEMU Pipe and the renderer library + +The other sources are: + + $EMUGL/system -> system libraries + $EMUGL/host -> host libraries (translator + renderer) + $EMUGL/shared -> shared libraries, used both in the guest and the host + $EMUGL/tests -> various test programs + + +Translator libraries: +--------------------- + +There are three translator host libraries provided by this project: + + libEGL_translator -> EGL 1.2 translation + libGLES_CM_translator -> GLES 1.1 translation + libGLES_V2_translator -> GLES 2.0 translation + +The full name of the library will depend on the host system. +For simplicity, only the library name suffix will change (i.e. the +'lib' prefix is not dropped on Windows), i.e.: + + libEGL_translator.so -> for Linux + libEGL_translator.dylib -> for OS X + libEGL_translator.dll -> for Windows + +The source code for these libraries is located under the following +path in the Android source tree: + + $EMUGL/host/libs/Translator/EGL + $EMUGL/host/libs/Translator/GLES_CM + $EMUGL/host/libs/Translator/GLES_V2 + +The translator libraries also use a common routines defined under: + + $EMUGL/host/libs/Translator/GLcommon + + +Wire Protocol Overiew: +---------------------- + +The "wire protocol" is implemented as follows: + + - EGL/GLES function calls are described through several "specification" + files, which describes the types, function signatures and various + attributes for each one of them. + + - These files are read by a tool called "emugen" which generates C + source files and headers based on the specification. These correspond + to both encoding, decoding and "wrappers" (more on this later). + + - System "encoder" static libraries are built using some of these generated + files. They contain code that can serialize EGL/GLES calls into simple + byte messages and send it through a generic "IOStream" object. + + - Host "decoder" static libraries are also built using some of these + generated files. Their code retrieves byte messages from an "IOStream" + object, and translates them into function callbacks. + +IOStream abstraction: +- - - - - - - - - - - + +The "IOStream" is a very simple abstract class used to send byte messages +both in the guest and host. It is defined through a shared header under +$EMUGL/host/include/libOpenglRender/IOStream.h + +Note that despite the path, this header is included by *both* host and guest +source code. The main idea around IOStream's design is that to send a message, +one does the following: + + 1/ call stream->allocBuffer(size), which returns the address of a + memory buffer of at least 'size' bytes. + + 2/ write the content of the serialized command (usually a header + some + payload) directly into the buffer + + 3/ call stream->commitBuffer() to send it. + +Alternatively, one can also pack several commands into a single buffer with +stream->alloc() and stream->flush(), as in: + + 1/ buf1 = stream->alloc(size1) + 2/ write first command bytes into buf1 + 3/ buf2 = stream->alloc(size2) + 4/ write second command bytes into buf2 + 5/ stream->flush() + +Finally, there are also explict read/write methods like stream->readFully() +or stream->writeFully() which can be used when you don't want an intermediate +buffer. This is used in certain cases by the implementation, e.g. to avoid +an intermediate memory copy when sending texture data from the guest to the +host. + +The host IOStream implementations are under $EMUGL/shared/OpenglCodecCommon/, +see in particular: + + $EMUGL/shared/OpenglCodecCommon/TcpStream.cpp -> using local TCP sockets + $EMUGL/shared/OpenglCodecCommon/UnixStream.cpp -> using Unix sockets + $EMUGL/shared/OpenglCodecCommon/Win32PipeStream.cpp -> using Win32 named pipes + +The guest IOStream implementation uses the TcpStream.cpp above, as well as +an alternative QEMU-specific source: + + $EMUGL/system/OpenglSystemCommon/QemuPipeStream.cpp -> uses QEMU pipe from the guest + +The QEMU Pipe implementation is _significantly_ faster (about 20x) due to +several reasons: + + - all succesful read() and write() operations through it are instantaneous + from the guest's point of view. + + - all buffer/memory copies are performed directly by the emulator, and thus + much faster than performing the same thing inside the kernel with emulated + ARM instructions. + + - it doesn't need to go through a kernel TCP/IP stack that will wrap the + data into TCP/IP/MAC packets, send them to an emulated ethernet device, + which is itself connected to an internal firewall implementation that + will unwrap the packets, re-assemble them, then send them through BSD + sockets to the host kernel. + +However, would it be necessary, you could write a guest IOStream implementation +that uses a different transport. If you do, please look at +$EMUGL/system/OpenglCodecCommon/HostConnection.cpp which contains the code +used to connect the guest to the host, on a per-thread basis. + + +Source code auto-generation: +- - - - - - - - - - - - - - + +The 'emugen' tool is located under $EMUGL/host/tools/emugen. There is a README +file that explains how it works. + +You can also look at the following specifications files: + +For GLES 1.1: + $EMUGL/system/GLESv1_enc/gl.types + $EMUGL/system/GLESv1_enc/gl.in + $EMUGL/system/GLESv1_enc/gl.attrib + $EMUGL/system/GLESv1_enc/gl.addon + +For GLES 2.0: + $EMUGL/system/GLESv2_enc/gl2.types + $EMUGL/system/GLESv2_enc/gl2.in + $EMUGL/system/GLESv2_enc/gl2.attrib + $EMUGL/system/GLESv2_enc/gl2.addon + +For EGL: + $EMUGL/system/renderControl_enc/renderControl.types + $EMUGL/system/renderControl_enc/renderControl.in + $EMUGL/system/renderControl_enc/renderControl.attrib + $EMUGL/system/renderControl_enc/renderControl.addon + +Note that the EGL specification files are under a directory named +"renderControl_enc" and have filenames that begin with "renderControl" + +This is mainly for historic reasons now, but is also related to the fact that +this part of the wire protocol contains support functions/calls/specifications +that are not part of the EGL specification itself, but add a few features +required to make everything works. For example, they have calls related to +the "gralloc" system library module used to manage graphics surfaces at a +lower level than EGL. + +Generally speaking, guest encoder sources are located under directories +named $EMUGL/system/<name>_enc/, while the corresponding host decoder +sources will be under $EMUGL/host/libs/<name>_dec/ + +However, all these sources use the same spec files located under the +encoding directories. The decoders may even need to include a few +non-auto-generated header files from the encoder directories. + + + +System libraries: +----------------- + +Meta EGL/GLES system libraries, and egl.cfg: +- - - - - - - - - - - - - - - - - - - - - - + +It is important to understand that the emulation-specific EGL/GLES libraries +are not directly linked by applications at runtime. Instead, the system +provides a set of "meta" EGL/GLES libraries that will load the appropriate +hardware-specific libraries on first use. + +More specifically, the system libEGL.so contains a "loader" which will try +to load: + + - hardware-specific EGL/GLES libraries + - the software-based rendering libraries (called "libagl") + +The system libEGL.so is also capable of merging the EGL configs of both the +hardware and software libraries transparently to the application. The system +libGLESv1_CM.so and libGLESv2.so, work with it to ensure that the thread's +current context will be linked to either the hardware or software libraries +depending on the config selected. + +For the record, the loader's source code in under +frameworks/base/opengl/libs/EGL/Loader.cpp. It depends on a file named +/system/lib/egl/egl.cfg which must contain two lines that look like: + + 0 1 <name> + 0 0 android + +The first number in each line is a display number, and must be 0 since the +system's EGL/GLES libraries don't support anything else. + +The second number must be 1 to indicate hardware libraries, and 0 to indicate +a software one. The line corresponding to the hardware library, if any, must +always appear before the one for the software library. + +The third field is a name corresponding to a shared library suffix. It really +means that the corresponding libraries will be named libEGL_<name>.so, +libGLESv1_CM_<name>.so and libGLESv2_<name>.so. Moreover these libraries must +be placed under /system/lib/egl/ + +The name "android" is reserved for the system software renderer. + +The egl.cfg that comes with this project uses the name "emulation" for the +hardware libraries. This means that it provides an egl.cfg file that contains +the following lines: + + 0 1 emulation + 0 0 android + +See $EMUGL/system/egl/egl.cfg and more generally the following build files: + + $EMUGL/system/egl/Android.mk + $EMUGL/system/GLESv1/Android.mk + $EMUGL/system/GLESv2/Android.mk + +to see how the libraries are named and placed under /system/lib/egl/ by the +build system. + + +Emulation libraries: +- - - - - - - - - - - + +The emulator-specific libraries are under the following: + + $EMUGL/system/egl/ + $EMUGL/system/GLESv1/ + $EMUGL/system/GLESv2/ + +The code for GLESv1 and GLESv2 is pretty small, since it mostly link against +the static encoding libraries. + +The code for EGL is a bit more complex, because it needs to deal with +extensions dynamically. I.e. if an extension is not available on the host +it shouldn't be exposed by the library at runtime. So the EGL code queries +the host for the list of available extensions in order to return them to +clients. Similarly, it must query the list of valid EGLConfigs for the +current host system. + + +"gralloc" module implementation: +- - - - - - - - - - - - - - - - - + +In addition to EGL/GLES libraries, the Android system requires a +hardware-specific library to manage graphics surfaces at a level lower than +EGL. This library must be what is called in Android land as a "HAL module". + +A "HAL module" must provide interfaces defined by Android's HAL +(Hardware Abstraction Library). These interface definitions can be found +under $ANDROID/hardware/libhardware/include/ + +Of all possible HAL modules, the "gralloc" one is used by the system's +SurfaceFlinger to allocate framebuffers and other graphics memory regions, +as well as eventually lock/unlock/swap them when needed. + +The code under $EMUGL/system/gralloc/ implements the module required by the +GLES emulation project. It's not very long, but there are a few things to +notice here: + +- first, it will probe the guest system to determine if the emulator that + is running the virtual device really supports GPU emulation. In certain + circumstances this may not be possible. + + If this is the case, then the module will redirect all calls to the + "default" gralloc module that is normally used by the system when + software-only rendering is enabled. + + The probing happens in the function "fallback_init" which gets called + when the module is first opened. This initializes the 'sFallback' variable + to a pointer to the default gralloc module when required. + +- second, this module is used by SurfaceFlinger to display "software surfaces", + i.e. those that are backed by system memory pixel buffers, and written to + directly through the Skia graphics library (i.e. the non-accelerated ones). + + the default module simply copies the pixel data from the surface to the + virtual framebuffer i/o memory, but this project's gralloc module sends it + to the renderer through the QEMU Pipe instead. + + It turns out that this results in _faster_ rendering/frame-rates overall, + because memory copies inside the guest are slow, while QEMU pipe transfers + are done directly in the emulator. + + +Host Renderer: +-------------- + +The host renderer library is located under $EMUGL/host/libs/libOpenglRender, +and it provides an interface described by the headers under +$EMUGL/host/include/libOpenglRender/render_api.h (e.g. for use by the emulator). + +In a nutshell, the rendering library is responsible for the following: + + - Providing a virtual off-screen video surface where everything will get + rendered at runtime. Its dimensions are fixed by the call to + initOpenglRender() that must happen just after the library is + initialized. + + - Provide a way to display the virtual video surface on a host application's + UI. This is done by calling createOpenGLSubWindow() which takes as argument + the window ID or handle of a parent window, some display dimensions and + a rotation angle. This allows the surface to be scaled/rotated when it is + displayed, even if the dimensions of the video surface do not change. + + - Provide a way to listen to incoming EGL/GLES commands from the guest. + This is done by providing a so-called "port number" to initOpenglRender(). + + By default, the port number corresponds to a local TCP port number that the + renderer will bind to and listen. Every new connection to this port will + correspond to the creation of a new guest host connection, each such + connection corresponding to a distinct thread in the guest system. + + For performance reasons, it is possible to listen to either Unix sockets + (on Linux and OS X), or to a Win32 named pipe (on Windows). To do so, one + had to call setStreamType() between library initialization + (i.e. initLibrary()) and construction (i.e. initOpenglRender()). + + Note that in these modes, the port number is still used to differentiate + between several emulator instances. These details are normally handled by + the emulator code so you shouldn't care too much. + +Note that an earlier version of the interface allowed a client of the renderer +library to provide its own IOStream implementation. However, this wasn't very +convenient for a number of reasons. This maybe something that could be done +again if it makes sense, but for now the performance numbers are pretty good. + + +Host emulator: +-------------- + +The code under $QEMU/android/opengles.c is in charge of dynamically loading +the rendering library and initializing / constructing it properly. + +QEMU pipe connections to the 'opengles' service are piped through the code +in $QEMU/android/hw-pipe-net.c. Look for the openglesPipe_init() function, +which is in charge of creating a connection to the renderer library +(either through a TCP socket, or a Unix pipe depending on configuration. +support for Win32 named pipes hasn't been implemented yet in the emulator) +whenever a guest process opens the "opengles" service through /dev/qemu_pipe. + +There is also some support code for the display of the GLES framebuffer +(through the renderer library's subwindow) under $QEMU/skin/window. + +Note that at the moment, scaling and rotation are supported. However, +brightness emulation (which used to modify the pixel values from the +hardware framebuffer before displaying them) doesn't work. + +Another issue is that it is not possible to display anything on top of the +GL subwindow at the moment. E.g. this will obscure the emulated trackball +image (that is normally toggled with Ctrl-T during emulation, or enabled +by pressing the Delete key). + diff --git a/emulator/opengl/README b/emulator/opengl/README new file mode 100644 index 0000000..1a7536e --- /dev/null +++ b/emulator/opengl/README @@ -0,0 +1,94 @@ +This directory contains the modules related to hardware OpenGL ES emulation. + +I. Overview of components: +========================== + +The 'emugen' tool is used to generate several source files related to the +EGL/GLES command stream used between the guest and the host during emulation. + + host/tools/emugen -> emugen program + +Note that emugen is capable of generating, from a single set of specification +files, three types of auto-generated sources: + + - sources to encode commands into a byte stream. + - sources to decode the byte stream into commands. + - sources to wrap normal procedural EGL/GLES calls into context-aware ones. + +Modules under the system/ directory corresponds to code that runs on the +guest, and implement the marshalling of EGL/GLES commands into a stream of +bytes sent to the host through a fast pipe mechanism. + + system/GLESv1_enc -> encoder for GLES 1.1 commands + system/GLESv2_enc -> encoder for GLES 2.0 commands + system/renderControl_enc -> encoder for rendering control commands + system/egl -> emulator-specific guest EGL library + system/GLESv1 -> emulator-specific guest GLES 1.1 library + system/gralloc -> emulator-specific gralloc module + system/OpenglSystemCommon -> library of common routines + +Modules under the host/ directory corresponds to code that runs on the +host, and implement the decoding of the command stream, translation of +EGL/GLES commands into desktop GL 2.0 ones, and rendering to an off-screen +buffer. + + host/libs/GLESv1_dec -> decoder for GLES 1.1 commands + host/libs/GLESv2_dec -> decoder for GLES 2.0 commands + host/libs/renderControl_dec -> decoder for rendering control commands + + host/libs/Translator/EGL -> translator for EGL commands + host/libs/Translator/GLES_CM -> translator for GLES 1.1 commands + host/libs/Translator/GLES_V2 -> translator for GLES 2.0 commands + host/libs/Translator/GLcommon -> library of common translation routines + + host/libs/libOpenglRender -> rendering library (uses all host libs above) + can be used by the 'renderer' program below, + or directly linked into the emulator UI program. + + host/renderer/ -> stand-alone renderer program executable. + this can run in head-less mode and receive requests from + several emulators at the same time. It is the receiving + end of all command streams. + +Modules under the test/ directory correspond to test programs that are useful +to debug the various modules described above: + + tests/EGL_host_wrapper -> a small library used to dynamically load the + desktop libEGL.so or a replacement named by the + ANDROID_EGL_LIB environment variable. This lib + provides all EGL entry points. + + tests/emulator_test_renderer -> a small program to run the rendering library + in a single SDL window on the host desktop. + + tests/gles_android_wrapper -> guest EGL / GLES libraries that are run on + the device to run some tests. Replace the + system/egl and system/GLESv1 modules for now. + + tests/translator_tests/GLES_CM -> desktop GLESv1 translation unit test + tests/translator_tests/GLES_V2 -> desktop GLESv2 translation unit test + tests/translator_tests/MacCommon -> used by translation tests on Mac only. + + tests/ut_rendercontrol_enc -> guest library used by tests/ut_renderer + tests/ut_rendercontrol_dec -> host library used by tests/ut_renderer + tests/ut_renderer -> unit-test for render control and rendering library. + + +II. Build system considerations: +-------------------------------- + +The dependencies on the more than 20 components described in the previous +section are pretty sophisticated, involving lots of auto-generated code and +non-trivial placement for guest/device libraries. + +To simplify the development and maintenance of these modules, a set of +helper GNU Make function is defined in common.mk, and included from the +Android.mk in this directory. + +These functions all begin with the "emugl-" prefix, and can be used to +declare modules, what information they export to other modules, or import +from them, and also what kind of auto-generated sources they depend on. + +Look at the comments inside common.mk and the Android.mk of the modules +to better understand what's happening. + diff --git a/emulator/opengl/common.mk b/emulator/opengl/common.mk new file mode 100644 index 0000000..82f652d --- /dev/null +++ b/emulator/opengl/common.mk @@ -0,0 +1,341 @@ +# This top-level build file is included by all modules that implement +# the hardware OpenGL ES emulation for Android. +# +# We use it to ensure that all sub-Makefiles are included in the right +# order for various variable definitions and usage to happen in the correct +# order. +# + +# The following macros are used to start a new GLES emulation module. +# +# This will define LOCAL_MODULE as $1, plus a few other variables +# needed by the build system (e.g. LOCAL_MODULE_TAGS, LOCAL_MODULE_CLASS...) +# +# NOTE: You still need to define LOCAL_PATH before this +# +# Usage example: +# +# $(call emugl-begin-static-library,<name>) +# LOCAL_SRC_FILES := .... +# LOCAL_C_INCLUDES += .... +# $(call emugl-end-module) +# +emugl-begin-static-library = $(call emugl-begin-module,$1,STATIC_LIBRARY) +emugl-begin-shared-library = $(call emugl-begin-module,$1,SHARED_LIBRARY) +emugl-begin-host-static-library = $(call emugl-begin-module,$1,HOST_STATIC_LIBRARY,HOST) +emugl-begin-host-shared-library = $(call emugl-begin-module,$1,HOST_SHARED_LIBRARY,HOST) +emugl-begin-host-executable = $(call emugl-begin-module,$1,HOST_EXECUTABLE,HOST) + +# Internal list of all declared modules (used for sanity checking) +_emugl_modules := +_emugl_HOST_modules := + +# do not use directly, see functions above instead +emugl-begin-module = \ + $(eval include $(CLEAR_VARS)) \ + $(eval LOCAL_MODULE := $1) \ + $(eval LOCAL_MODULE_TAGS := debug) \ + $(eval LOCAL_MODULE_CLASS := $(patsubst HOST_%,%,$(patsubst %EXECUTABLE,%EXECUTABLES,$(patsubst %LIBRARY,%LIBRARIES,$2)))) \ + $(eval LOCAL_IS_HOST_MODULE := $(if $3,true,))\ + $(eval LOCAL_C_INCLUDES := $(EMUGL_COMMON_INCLUDES)) \ + $(eval LOCAL_CFLAGS := $(EMUGL_COMMON_CFLAGS)) \ + $(eval LOCAL_PRELINK_MODULE := false)\ + $(eval _EMUGL_INCLUDE_TYPE := $(BUILD_$2)) \ + $(call _emugl-init-module,$1,$2,$3) + +# Used to end a module definition, see function definitions above +emugl-end-module = \ + $(eval include $(_EMUGL_INCLUDE_TYPE))\ + $(eval _EMUGL_INCLUDE_TYPE :=) \ + $(eval _emugl_$(_emugl_HOST)modules += $(_emugl_MODULE))\ + $(if $(EMUGL_DEBUG),$(call emugl-dump-module)) + +# Managing module exports and imports. +# +# A module can 'import' another module, by calling emugl-import. This will +# make the current LOCAL_MODULE inherit various definitions exported from +# the imported module. +# +# Module exports are defined by calling emugl-export. Here is an example: +# +# $(call emugl-begin-static-library,foo) +# LOCAL_SRC_FILES := foo.c +# $(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) +# $(call emugl-export,SHARED_LIBRARIES,libcutils) +# $(call emugl-end-module) +# +# $(call emugl-begin-shared-library,bar) +# LOCAL_SRC_FILES := bar.cpp +# $(call emugl-import,foo) +# $(call emugl-end-module) +# +# Here, we define a static library named 'foo' which exports an include +# path and a shared library requirement, and a shared library 'bar' which +# imports it. +# +# What this means is that: +# +# - 'bar' will automatically inherit foo's LOCAL_PATH in its LOCAL_C_INCLUDES +# - 'bar' will automatically inherit libcutils in its own LOCAL_SHARED_LIBRARIES +# +# Note that order of declaration matters. If 'foo' is defined after 'bar' in +# the example above, nothing will work correctly because dependencies are +# computed at import time. +# +# +# IMPORTANT: Imports are transitive, i.e. when module A imports B, +# it automatically imports anything imported by B too. + +# This is the list of recognized export types we support for now. +EMUGL_EXPORT_TYPES := \ + CFLAGS \ + LDLIBS \ + LDFLAGS \ + C_INCLUDES \ + SHARED_LIBRARIES \ + STATIC_LIBRARIES \ + ADDITIONAL_DEPENDENCIES + +# Initialize a module in our database +# $1: Module name +# $2: Module type +# $3: "HOST" for a host module, empty for a target one. +_emugl-init-module = \ + $(eval _emugl_HOST := $(if $3,HOST_,))\ + $(eval _emugl_MODULE := $(_emugl_HOST)$1)\ + $(if $(filter $(_emugl_$(_emugl_HOST)modules),$(_emugl_MODULE)),\ + $(error There is already a $(if $3,host,) module named $1!)\ + )\ + $(eval _mod = $(_emugl_MODULE)) \ + $(eval _emugl.$(_mod).type := $(patsubst HOST_%,%,$2))\ + $(eval _emugl.$(_mod).imports :=) \ + $(eval _emugl,$(_mod).moved :=) \ + $(foreach _type,$(EMUGL_EXPORT_TYPES),\ + $(eval _emugl.$(_mod).export.$(_type) :=)\ + ) + +# Called to indicate that a module exports a given local variable for its +# users. This also adds this to LOCAL_$1 +# $1: Local variable type (e.g. CFLAGS, LDLIBS, etc...) +# $2: Value(s) to append to the export +emugl-export = \ + $(eval _emugl.$(_emugl_MODULE).export.$1 += $2)\ + $(eval LOCAL_$1 := $2 $(LOCAL_$1)) + +emugl-export-outer = \ + $(eval _emugl.$(_emugl_MODULE).export.$1 += $2) + +# Called to indicate that a module imports the exports of another module +# $1: list of modules to import +# +emugl-import = \ + $(foreach _imod,$1,\ + $(call _emugl-module-import,$(_emugl_HOST)$(_imod))\ + ) + +_emugl-module-import = \ + $(eval _mod := $(_emugl_MODULE))\ + $(if $(filter-out $(_emugl_$(_emugl_HOST)modules),$1),\ + $(info Unknown imported emugles module: $1)\ + $(if $(_emugl_HOST),\ + $(eval _names := $(patsubst HOST_%,%,$(_emugl_HOST_modules))),\ + $(eval _names := $(_emugl_modules))\ + )\ + $(info Please one of the following names: $(_names))\ + $(error Aborting)\ + )\ + $(if $(filter-out $(_emugl.$(_mod).imports),$1),\ + $(eval _emugl.$(_mod).imports += $1)\ + $(foreach _sub,$(_emugl.$1.imports),\ + $(call _emugl-module-import,$(_sub))\ + )\ + $(foreach _type,$(EMUGL_EXPORT_TYPES),\ + $(eval LOCAL_$(_type) := $(_emugl.$1.export.$(_type)) $(LOCAL_$(_type)))\ + )\ + $(if $(filter EXECUTABLE SHARED_LIBRARY,$(_emugl.$(_emugl_MODULE).type)),\ + $(if $(filter STATIC_LIBRARY,$(_emugl.$1.type)),\ + $(eval LOCAL_STATIC_LIBRARIES := $(1:HOST_%=%) $(LOCAL_STATIC_LIBRARIES))\ + )\ + $(if $(filter SHARED_LIBRARY,$(_emugl.$1.type)),\ + $(if $(_emugl.$1.moved),,\ + $(eval LOCAL_SHARED_LIBRARIES := $(1:HOST_%=%) $(LOCAL_SHARED_LIBRARIES))\ + )\ + )\ + )\ + ) + +_emugl-dump-list = \ + $(foreach _list_item,$(strip $1),$(info . $(_list_item))) + +emugl-dump-module = \ + $(info MODULE=$(_emugl_MODULE))\ + $(info . HOST=$(_emugl_HOST))\ + $(info . TYPE=$(_emugl.$(_emugl_MODULE).type))\ + $(info . IMPORTS=$(_emugl.$(_emugl_MODULE).imports))\ + $(foreach _type,$(EMUGL_EXPORT_TYPES),\ + $(if $(filter C_INCLUDES ADDITIONAL_DEPENDENCIES,$(_type)),\ + $(info . EXPORT.$(_type) :=)\ + $(call _emugl-dump-list,$(_emugl.$(_emugl_MODULE).export.$(_type)))\ + $(info . LOCAL_$(_type) :=)\ + $(call _emugl-dump-list,$(LOCAL_$(_type)))\ + ,\ + $(info . EXPORT.$(_type) := $(strip $(_emugl.$(_emugl_MODULE).export.$(_type))))\ + $(info . LOCAL_$(_type) := $(strip $(LOCAL_$(_type))))\ + )\ + )\ + $(info . LOCAL_SRC_FILES := $(LOCAL_SRC_FILES))\ + +# This function can be called to generate the decoder source files. +# LOCAL_MODULE and LOCAL_MODULE_CLASS must be defined or the build will abort. +# Source files will be stored in the local intermediates directory that will +# be automatically added to your LOCAL_C_INCLUDES. +# +# Usage: +# $(call emugl-gen-decoder,<input-dir>,<basename>) +# +emugl-gen-decoder = \ + $(eval _emugl_out := $(call local-intermediates-dir))\ + $(call emugl-gen-decoder-generic,$(_emugl_out),$1,$2)\ + $(call emugl-export,C_INCLUDES,$(_emugl_out)) + +# This function can be called to generate the encoder source files. +# LOCAL_MODULE and LOCAL_MODULE_CLASS must be defined or the build will abort. +# Source files will be stored in the local intermediates directory that will +# be automatically added to your LOCAL_C_INCLUDES. +# Usage: +# $(call emugl-gen-encoder,<input-dir>,<basename>) +# +emugl-gen-encoder = \ + $(eval _emugl_out := $(call local-intermediates-dir)) \ + $(call emugl-gen-encoder-generic,$(_emugl_out),$1,$2) \ + $(call emugl-export,C_INCLUDES,$(_emugl_out)) + + +# This function can be called to generate the wrapper source files. +# LOCAL_MODULE and LOCAL_MODULE_CLASS must be defined or the build will abort. +# Source files will be stored in the local intermediates directory that will +# be automatically added to your LOCAL_C_INCLUDES. +# Usage: +# $(call emugl-gen-wrapper,<input-dir>,<basename>) +# +emugl-gen-wrapper = \ + $(eval _emugl_out := $(call local-intermediates-dir)) \ + $(call emugl-gen-wrapper-generic,$(_emugl_out),$1,$2) \ + $(call emugl-export,C_INCLUDES,$(_emugl_out)) + +# IMPORTANT: EMUGL_EMUGEN is defined under host/tools/emugen/Android.mk +# + +# DO NOT CALL DIRECTLY, USE emugl-gen-decoder instead. +# +# The following function can be called to generate wire protocol decoder +# source files, Usage is: +# +# $(call emugl-gen-decoder-generic,<dst-dir>,<src-dir>,<basename>) +# +# <dst-dir> is the destination directory where the generated sources are stored +# <src-dir> is the source directory where to find <basename>.attrib, etc.. +# <basename> is the emugen basename (see host/tools/emugen/README) +# +emugl-gen-decoder-generic = $(eval $(emugl-gen-decoder-generic-ev)) + +define emugl-gen-decoder-generic-ev +_emugl_dec := $$1/$$3 +_emugl_src := $$2/$$3 +GEN := $$(_emugl_dec)_dec.cpp \ + $$(_emugl_dec)_dec.h \ + $$(_emugl_dec)_opcodes.h \ + $$(_emugl_dec)_server_context.h \ + $$(_emugl_dec)_server_context.cpp + +$$(GEN): PRIVATE_PATH := $$(LOCAL_PATH) +$$(GEN): PRIVATE_CUSTOM_TOOL := $$(EMUGL_EMUGEN) -D $$1 -i $$2 $$3 +$$(GEN): $$(EMUGL_EMUGEN) $$(_emugl_src).attrib $$(_emugl_src).in $$(_emugl_src).types + $$(transform-generated-source) + +$$(call emugl-export,ADDITIONAL_DEPENDENCIES,$$(GEN)) +LOCAL_GENERATED_SOURCES += $$(GEN) +LOCAL_C_INCLUDES += $$1 +endef + +# DO NOT CALL DIRECTLY, USE emugl-gen-encoder instead. +# +# The following function can be called to generate wire protocol encoder +# source files, Usage is: +# +# $(call emugl-gen-encoder-generic,<dst-dir>,<src-dir>,<basename>) +# +# <dst-dir> is the destination directory where the generated sources are stored +# <src-dir> is the source directory where to find <basename>.attrib, etc.. +# <basename> is the emugen basename (see host/tools/emugen/README) +# +emugl-gen-encoder-generic = $(eval $(emugl-gen-encoder-generic-ev)) + +define emugl-gen-encoder-generic-ev +_emugl_enc := $$1/$$3 +_emugl_src := $$2/$$3 +GEN := $$(_emugl_enc)_entry.cpp \ + $$(_emugl_enc)_enc.cpp \ + $$(_emugl_enc)_enc.h \ + $$(_emugl_enc)_ftable.h \ + $$(_emugl_enc)_opcodes.h \ + $$(_emugl_enc)_client_context.h \ + $$(_emugl_enc)_client_context.cpp + +$$(GEN): PRIVATE_PATH := $$(LOCAL_PATH) +$$(GEN): PRIVATE_CUSTOM_TOOL := $$(EMUGL_EMUGEN) -E $$1 -i $$2 $$3 +$$(GEN): $$(EMUGL_EMUGEN) $$(_emugl_src).attrib $$(_emugl_src).in $$(_emugl_src).types + $$(transform-generated-source) + +$$(call emugl-export,ADDITIONAL_DEPENDENCIES,$$(GEN)) +LOCAL_GENERATED_SOURCES += $$(GEN) +LOCAL_C_INCLUDES += $$1 +endef + + +# DO NOT CALL DIRECTLY, USE emugl-gen-wrapper instead. +# +# The following function can be called to generate GL library wrapper +# Usage is: +# +# $(call emugl-gen-wrapper-generic,<dst-dir>,<src-dir>,<basename>) +# +# <dst-dir> is the destination directory where the generated sources are stored +# <src-dir> is the source directory where to find <basename>.attrib, etc.. +# <basename> is the emugen basename (see host/tools/emugen/README) +# +emugl-gen-wrapper-generic = $(eval $(emugl-gen-wrapper-generic-ev)) + +define emugl-gen-wrapper-generic-ev +_emugl_wrap := $$1/$$3 +_emugl_src := $$2/$$3 +GEN := $$(_emugl_wrap)_wrapper_entry.cpp \ + $$(_emugl_wrap)_wrapper_context.cpp \ + $$(_emugl_wrap)_wrapper_context.h \ + $$(_emugl_wrap)_wrapper_proc.h + +$$(GEN): PRIVATE_PATH := $$(LOCAL_PATH) +$$(GEN): PRIVATE_CUSTOM_TOOL := $$(EMUGL_EMUGEN) -W $$1 -i $$2 $$3 +$$(GEN): $$(EMUGL_EMUGEN) $$(_emugl_src).attrib $$(_emugl_src).in $$(_emugl_src).types + $$(transform-generated-source) + +$$(call emugl-export,ADDITIONAL_DEPENDENCIES,$$(GEN)) +LOCAL_GENERATED_SOURCES += $$(GEN) +LOCAL_C_INCLUDES += $$1 + +#ifneq ($$(HOST_OS),windows) +$$(call emugl-export,LDFLAGS,-ldl) +#endif + +endef + +# Call this function when your shared library must be placed in a non-standard +# library path (i.e. not under /system/lib +# $1: library sub-path,relative to /system/lib +# For example: $(call emugl-set-shared-library-subpath,egl) +emugl-set-shared-library-subpath = \ + $(eval LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/$1)\ + $(eval LOCAL_UNSTRIPPED_PATH := $(TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)/$1)\ + $(eval _emugl.$(LOCAL_MODULE).moved := true)\ + $(call emugl-export-outer,ADDITIONAL_DEPENDENCIES,$(LOCAL_MODULE_PATH)/$(LOCAL_MODULE)$(TARGET_SHLIB_SUFFIX)) + 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 diff --git a/emulator/opengl/shared/OpenglCodecCommon/Android.mk b/emulator/opengl/shared/OpenglCodecCommon/Android.mk new file mode 100644 index 0000000..7deb058 --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/Android.mk @@ -0,0 +1,54 @@ +# This build script corresponds to a library containing many definitions +# common to both the guest and the host. They relate to +# +LOCAL_PATH := $(call my-dir) + +commonSources := \ + GLClientState.cpp \ + GLSharedGroup.cpp \ + glUtils.cpp \ + SocketStream.cpp \ + TcpStream.cpp \ + TimeUtils.cpp + +host_commonSources := $(commonSources) + +ifeq ($(HOST_OS),windows) + host_commonSources += Win32PipeStream.cpp +else + host_commonSources += UnixStream.cpp +endif + + +### CodecCommon guest ############################################## +$(call emugl-begin-static-library,libOpenglCodecCommon) + +LOCAL_SRC_FILES := $(commonSources) + +LOCAL_CFLAGS += -DLOG_TAG=\"eglCodecCommon\" + +$(call emugl-export,SHARED_LIBRARIES,libcutils libutils) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) +$(call emugl-end-module) + + +### OpenglCodecCommon host ############################################## +$(call emugl-begin-host-static-library,libOpenglCodecCommon) + +LOCAL_SRC_FILES := $(host_commonSources) + +$(call emugl-export,STATIC_LIBRARIES,libcutils) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) +$(call emugl-end-module) + + +### OpenglCodecCommon host, 64-bit ######################################### +$(call emugl-begin-host-static-library,lib64OpenglCodecCommon) + +LOCAL_SRC_FILES := $(host_commonSources) + +$(call emugl-export,STATIC_LIBRARIES,lib64cutils) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) +$(call emugl-export,CFLAGS,-m64) +$(call emugl-end-module) + diff --git a/emulator/opengl/shared/OpenglCodecCommon/ErrorLog.h b/emulator/opengl/shared/OpenglCodecCommon/ErrorLog.h new file mode 100644 index 0000000..6f41fd7 --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/ErrorLog.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 _ERROR_LOG_H_ +#define _ERROR_LOG_H_ + +#if (HAVE_ANDROID_OS == 1) +# include <cutils/log.h> +# define ERR(...) ALOGE(__VA_ARGS__) +# ifdef EMUGL_DEBUG +# define DBG(...) ALOGD(__VA_ARGS__) +# else +# define DBG(...) ((void)0) +# endif +#else +# include <stdio.h> +# define ERR(...) fprintf(stderr, __VA_ARGS__) +# ifdef EMUGL_DEBUG +# define DBG(...) fprintf(stderr, __VA_ARGS__) +# else +# define DBG(...) ((void)0) +# endif +#endif + +#endif diff --git a/emulator/opengl/shared/OpenglCodecCommon/FixedBuffer.h b/emulator/opengl/shared/OpenglCodecCommon/FixedBuffer.h new file mode 100644 index 0000000..30b9a80 --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/FixedBuffer.h @@ -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. +*/ +#ifndef _FIXED_BUFFER_H +#define _FIXED_BUFFER_H + +class FixedBuffer { +public: + FixedBuffer(size_t initialSize = 0) { + m_buffer = NULL; + m_bufferLen = 0; + alloc(m_bufferLen); + } + + ~FixedBuffer() { + delete [] m_buffer; + m_bufferLen = 0; + } + + void * alloc(size_t size) { + if (m_bufferLen >= size) + return (void *)(m_buffer); + + if (m_buffer != NULL) + delete[] m_buffer; + + m_bufferLen = size; + m_buffer = new unsigned char[m_bufferLen]; + if (m_buffer == NULL) + m_bufferLen = 0; + + return m_buffer; + } + void *ptr() { return m_buffer; } + size_t len() { return m_bufferLen; } +private: + unsigned char *m_buffer; + size_t m_bufferLen; +}; + +#endif diff --git a/emulator/opengl/shared/OpenglCodecCommon/GLClientState.cpp b/emulator/opengl/shared/OpenglCodecCommon/GLClientState.cpp new file mode 100644 index 0000000..9795490 --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/GLClientState.cpp @@ -0,0 +1,417 @@ +/* +* 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 "GLClientState.h" +#include "ErrorLog.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "glUtils.h" +#include <cutils/log.h> + +#ifndef MAX +#define MAX(a, b) ((a) < (b) ? (b) : (a)) +#endif + +GLClientState::GLClientState(int nLocations) +{ + if (nLocations < LAST_LOCATION) { + nLocations = LAST_LOCATION; + } + m_nLocations = nLocations; + m_states = new VertexAttribState[m_nLocations]; + for (int i = 0; i < m_nLocations; i++) { + m_states[i].enabled = 0; + m_states[i].enableDirty = false; + } + m_currentArrayVbo = 0; + m_currentIndexVbo = 0; + // init gl constans; + m_states[VERTEX_LOCATION].glConst = GL_VERTEX_ARRAY; + m_states[NORMAL_LOCATION].glConst = GL_NORMAL_ARRAY; + m_states[COLOR_LOCATION].glConst = GL_COLOR_ARRAY; + m_states[POINTSIZE_LOCATION].glConst = GL_POINT_SIZE_ARRAY_OES; + m_states[TEXCOORD0_LOCATION].glConst = GL_TEXTURE_COORD_ARRAY; + m_states[TEXCOORD1_LOCATION].glConst = GL_TEXTURE_COORD_ARRAY; + m_states[TEXCOORD2_LOCATION].glConst = GL_TEXTURE_COORD_ARRAY; + m_states[TEXCOORD3_LOCATION].glConst = GL_TEXTURE_COORD_ARRAY; + m_states[TEXCOORD4_LOCATION].glConst = GL_TEXTURE_COORD_ARRAY; + m_states[TEXCOORD5_LOCATION].glConst = GL_TEXTURE_COORD_ARRAY; + m_states[TEXCOORD6_LOCATION].glConst = GL_TEXTURE_COORD_ARRAY; + m_states[TEXCOORD7_LOCATION].glConst = GL_TEXTURE_COORD_ARRAY; + m_states[MATRIXINDEX_LOCATION].glConst = GL_MATRIX_INDEX_ARRAY_OES; + m_states[WEIGHT_LOCATION].glConst = GL_WEIGHT_ARRAY_OES; + m_activeTexture = 0; + m_currentProgram = 0; + + m_pixelStore.unpack_alignment = 4; + m_pixelStore.pack_alignment = 4; + + memset(m_tex.unit, 0, sizeof(m_tex.unit)); + m_tex.activeUnit = &m_tex.unit[0]; + m_tex.textures = NULL; + m_tex.numTextures = 0; + m_tex.allocTextures = 0; +} + +GLClientState::~GLClientState() +{ + delete m_states; +} + +void GLClientState::enable(int location, int state) +{ + if (!validLocation(location)) { + return; + } + + m_states[location].enableDirty |= (state != m_states[location].enabled); + m_states[location].enabled = state; +} + +void GLClientState::setState(int location, int size, GLenum type, GLboolean normalized, GLsizei stride, const void *data) +{ + if (!validLocation(location)) { + return; + } + m_states[location].size = size; + m_states[location].type = type; + m_states[location].stride = stride; + m_states[location].data = (void*)data; + m_states[location].bufferObject = m_currentArrayVbo; + m_states[location].elementSize = glSizeof(type) * size; + m_states[location].normalized = normalized; +} + +void GLClientState::setBufferObject(int location, GLuint id) +{ + if (!validLocation(location)) { + return; + } + + m_states[location].bufferObject = id; +} + +const GLClientState::VertexAttribState * GLClientState::getState(int location) +{ + if (!validLocation(location)) { + return NULL; + } + return & m_states[location]; +} + +const GLClientState::VertexAttribState * GLClientState::getStateAndEnableDirty(int location, bool *enableChanged) +{ + if (!validLocation(location)) { + return NULL; + } + + if (enableChanged) { + *enableChanged = m_states[location].enableDirty; + } + + m_states[location].enableDirty = false; + return & m_states[location]; +} + +int GLClientState::getLocation(GLenum loc) +{ + int retval; + + switch(loc) { + case GL_VERTEX_ARRAY: + retval = int(VERTEX_LOCATION); + break; + case GL_NORMAL_ARRAY: + retval = int(NORMAL_LOCATION); + break; + case GL_COLOR_ARRAY: + retval = int(COLOR_LOCATION); + break; + case GL_POINT_SIZE_ARRAY_OES: + retval = int(POINTSIZE_LOCATION); + break; + case GL_TEXTURE_COORD_ARRAY: + retval = int (TEXCOORD0_LOCATION + m_activeTexture); + break; + case GL_MATRIX_INDEX_ARRAY_OES: + retval = int (MATRIXINDEX_LOCATION); + break; + case GL_WEIGHT_ARRAY_OES: + retval = int (WEIGHT_LOCATION); + break; + default: + retval = loc; + } + return retval; +} + +void GLClientState::getClientStatePointer(GLenum pname, GLvoid** params) +{ + const GLClientState::VertexAttribState *state = NULL; + switch (pname) { + case GL_VERTEX_ARRAY_POINTER: { + state = getState(GLClientState::VERTEX_LOCATION); + break; + } + case GL_NORMAL_ARRAY_POINTER: { + state = getState(GLClientState::NORMAL_LOCATION); + break; + } + case GL_COLOR_ARRAY_POINTER: { + state = getState(GLClientState::COLOR_LOCATION); + break; + } + case GL_TEXTURE_COORD_ARRAY_POINTER: { + state = getState(getActiveTexture() + GLClientState::TEXCOORD0_LOCATION); + break; + } + case GL_POINT_SIZE_ARRAY_POINTER_OES: { + state = getState(GLClientState::POINTSIZE_LOCATION); + break; + } + case GL_MATRIX_INDEX_ARRAY_POINTER_OES: { + state = getState(GLClientState::MATRIXINDEX_LOCATION); + break; + } + case GL_WEIGHT_ARRAY_POINTER_OES: { + state = getState(GLClientState::WEIGHT_LOCATION); + break; + } + } + if (state && params) + *params = state->data; +} + +int GLClientState::setPixelStore(GLenum param, GLint value) +{ + int retval = 0; + switch(param) { + case GL_UNPACK_ALIGNMENT: + if (value == 1 || value == 2 || value == 4 || value == 8) { + m_pixelStore.unpack_alignment = value; + } else { + retval = GL_INVALID_VALUE; + } + break; + case GL_PACK_ALIGNMENT: + if (value == 1 || value == 2 || value == 4 || value == 8) { + m_pixelStore.pack_alignment = value; + } else { + retval = GL_INVALID_VALUE; + } + break; + default: + retval = GL_INVALID_ENUM; + } + return retval; +} + + + + +size_t GLClientState::pixelDataSize(GLsizei width, GLsizei height, GLenum format, GLenum type, int pack) const +{ + int pixelsize = glUtilsPixelBitSize(format, type) >> 3; + + int alignment = pack ? m_pixelStore.pack_alignment : m_pixelStore.unpack_alignment; + + if (pixelsize == 0 ) { + ERR("unknown pixel size: width: %d height: %d format: %d type: %d pack: %d align: %d\n", + width, height, format, type, pack, alignment); + } + size_t linesize = pixelsize * width; + size_t aligned_linesize = int(linesize / alignment) * alignment; + if (aligned_linesize < linesize) { + aligned_linesize += alignment; + } + return aligned_linesize * height; +} + +GLenum GLClientState::setActiveTextureUnit(GLenum texture) +{ + GLuint unit = texture - GL_TEXTURE0; + if (unit >= MAX_TEXTURE_UNITS) { + return GL_INVALID_OPERATION; + } + m_tex.activeUnit = &m_tex.unit[unit]; + return GL_NO_ERROR; +} + +GLenum GLClientState::getActiveTextureUnit() const +{ + return GL_TEXTURE0 + (m_tex.activeUnit - &m_tex.unit[0]); +} + +void GLClientState::enableTextureTarget(GLenum target) +{ + switch (target) { + case GL_TEXTURE_2D: + m_tex.activeUnit->enables |= (1u << TEXTURE_2D); + break; + case GL_TEXTURE_EXTERNAL_OES: + m_tex.activeUnit->enables |= (1u << TEXTURE_EXTERNAL); + break; + } +} + +void GLClientState::disableTextureTarget(GLenum target) +{ + switch (target) { + case GL_TEXTURE_2D: + m_tex.activeUnit->enables &= ~(1u << TEXTURE_2D); + break; + case GL_TEXTURE_EXTERNAL_OES: + m_tex.activeUnit->enables &= ~(1u << TEXTURE_EXTERNAL); + break; + } +} + +GLenum GLClientState::getPriorityEnabledTarget(GLenum allDisabled) const +{ + unsigned int enables = m_tex.activeUnit->enables; + if (enables & (1u << TEXTURE_EXTERNAL)) { + return GL_TEXTURE_EXTERNAL_OES; + } else if (enables & (1u << TEXTURE_2D)) { + return GL_TEXTURE_2D; + } else { + return allDisabled; + } +} + +int GLClientState::compareTexId(const void* pid, const void* prec) +{ + const GLuint* id = (const GLuint*)pid; + const TextureRec* rec = (const TextureRec*)prec; + return (GLint)(*id) - (GLint)rec->id; +} + +GLenum GLClientState::bindTexture(GLenum target, GLuint texture, + GLboolean* firstUse) +{ + GLboolean first = GL_FALSE; + TextureRec* texrec = NULL; + if (texture != 0) { + if (m_tex.textures) { + texrec = (TextureRec*)bsearch(&texture, m_tex.textures, + m_tex.numTextures, sizeof(TextureRec), compareTexId); + } + if (!texrec) { + if (!(texrec = addTextureRec(texture, target))) { + return GL_OUT_OF_MEMORY; + } + first = GL_TRUE; + } + if (target != texrec->target) { + return GL_INVALID_OPERATION; + } + } + + switch (target) { + case GL_TEXTURE_2D: + m_tex.activeUnit->texture[TEXTURE_2D] = texture; + break; + case GL_TEXTURE_EXTERNAL_OES: + m_tex.activeUnit->texture[TEXTURE_EXTERNAL] = texture; + break; + } + + if (firstUse) { + *firstUse = first; + } + + return GL_NO_ERROR; +} + +GLClientState::TextureRec* GLClientState::addTextureRec(GLuint id, + GLenum target) +{ + if (m_tex.numTextures == m_tex.allocTextures) { + const GLuint MAX_TEXTURES = 0xFFFFFFFFu; + + GLuint newAlloc; + if (MAX_TEXTURES - m_tex.allocTextures >= m_tex.allocTextures) { + newAlloc = MAX(4, 2 * m_tex.allocTextures); + } else { + if (m_tex.allocTextures == MAX_TEXTURES) { + return NULL; + } + newAlloc = MAX_TEXTURES; + } + + TextureRec* newTextures = (TextureRec*)realloc(m_tex.textures, + newAlloc * sizeof(TextureRec)); + if (!newTextures) { + return NULL; + } + + m_tex.textures = newTextures; + m_tex.allocTextures = newAlloc; + } + + TextureRec* tex = m_tex.textures + m_tex.numTextures; + TextureRec* prev = tex - 1; + while (tex != m_tex.textures && id < prev->id) { + *tex-- = *prev--; + } + tex->id = id; + tex->target = target; + m_tex.numTextures++; + + return tex; +} + +GLuint GLClientState::getBoundTexture(GLenum target) const +{ + switch (target) { + case GL_TEXTURE_2D: + return m_tex.activeUnit->texture[TEXTURE_2D]; + case GL_TEXTURE_EXTERNAL_OES: + return m_tex.activeUnit->texture[TEXTURE_EXTERNAL]; + default: + return 0; + } +} + +void GLClientState::deleteTextures(GLsizei n, const GLuint* textures) +{ + // Updating the textures array could be made more efficient when deleting + // several textures: + // - compacting the array could be done in a single pass once the deleted + // textures are marked, or + // - could swap deleted textures to the end and re-sort. + TextureRec* texrec; + for (const GLuint* texture = textures; texture != textures + n; texture++) { + texrec = (TextureRec*)bsearch(texture, m_tex.textures, + m_tex.numTextures, sizeof(TextureRec), compareTexId); + if (texrec) { + const TextureRec* end = m_tex.textures + m_tex.numTextures; + memmove(texrec, texrec + 1, + (end - texrec - 1) * sizeof(TextureRec)); + m_tex.numTextures--; + + for (TextureUnit* unit = m_tex.unit; + unit != m_tex.unit + MAX_TEXTURE_UNITS; + unit++) + { + if (unit->texture[TEXTURE_2D] == *texture) { + unit->texture[TEXTURE_2D] = 0; + } else if (unit->texture[TEXTURE_EXTERNAL] == *texture) { + unit->texture[TEXTURE_EXTERNAL] = 0; + } + } + } + } +} diff --git a/emulator/opengl/shared/OpenglCodecCommon/GLClientState.h b/emulator/opengl/shared/OpenglCodecCommon/GLClientState.h new file mode 100644 index 0000000..c86329b --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/GLClientState.h @@ -0,0 +1,441 @@ +/* +* 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_CLIENT_STATE_H_ +#define _GL_CLIENT_STATE_H_ + +#define GL_API +#ifndef ANDROID +#define GL_APIENTRY +#define GL_APIENTRYP +#endif + +#include <GLES/gl.h> +#include <GLES/glext.h> +#include <GLES2/gl2.h> +#include <GLES2/gl2ext.h> + +#include <stdio.h> +#include <stdlib.h> +#include "ErrorLog.h" +#include "codec_defs.h" + +class GLClientState { +public: + typedef enum { + VERTEX_LOCATION = 0, + NORMAL_LOCATION = 1, + COLOR_LOCATION = 2, + POINTSIZE_LOCATION = 3, + TEXCOORD0_LOCATION = 4, + TEXCOORD1_LOCATION = 5, + TEXCOORD2_LOCATION = 6, + TEXCOORD3_LOCATION = 7, + TEXCOORD4_LOCATION = 8, + TEXCOORD5_LOCATION = 9, + TEXCOORD6_LOCATION = 10, + TEXCOORD7_LOCATION = 11, + MATRIXINDEX_LOCATION = 12, + WEIGHT_LOCATION = 13, + LAST_LOCATION = 14 + } StateLocation; + + typedef struct { + GLint enabled; + GLint size; + GLenum type; + GLsizei stride; + void *data; + GLuint bufferObject; + GLenum glConst; + unsigned int elementSize; + bool enableDirty; // true if any enable state has changed since last draw + bool normalized; + } VertexAttribState; + + typedef struct { + int unpack_alignment; + int pack_alignment; + } PixelStoreState; + + enum { + MAX_TEXTURE_UNITS = 32, + }; + +public: + GLClientState(int nLocations = CODEC_MAX_VERTEX_ATTRIBUTES); + ~GLClientState(); + int nLocations() { return m_nLocations; } + const PixelStoreState *pixelStoreState() { return &m_pixelStore; } + int setPixelStore(GLenum param, GLint value); + GLuint currentArrayVbo() { return m_currentArrayVbo; } + GLuint currentIndexVbo() { return m_currentIndexVbo; } + void enable(int location, int state); + void setState(int location, int size, GLenum type, GLboolean normalized, GLsizei stride, const void *data); + void setBufferObject(int location, GLuint id); + const VertexAttribState *getState(int location); + const VertexAttribState *getStateAndEnableDirty(int location, bool *enableChanged); + int getLocation(GLenum loc); + void setActiveTexture(int texUnit) {m_activeTexture = texUnit; }; + int getActiveTexture() const { return m_activeTexture; } + + int bindBuffer(GLenum target, GLuint id) + { + int err = 0; + switch(target) { + case GL_ARRAY_BUFFER: + m_currentArrayVbo = id; + break; + case GL_ELEMENT_ARRAY_BUFFER: + m_currentIndexVbo = id; + break; + default: + err = -1; + } + return err; + } + + int getBuffer(GLenum target) + { + int ret=0; + switch (target) { + case GL_ARRAY_BUFFER: + ret = m_currentArrayVbo; + break; + case GL_ELEMENT_ARRAY_BUFFER: + ret = m_currentIndexVbo; + break; + default: + ret = -1; + } + return ret; + } + size_t pixelDataSize(GLsizei width, GLsizei height, GLenum format, GLenum type, int pack) const; + + void setCurrentProgram(GLint program) { m_currentProgram = program; } + GLint currentProgram() const { return m_currentProgram; } + + /* OES_EGL_image_external + * + * These functions manipulate GL state which interacts with the + * OES_EGL_image_external extension, to support client-side emulation on + * top of host implementations that don't have it. + * + * Most of these calls should only be used with TEXTURE_2D or + * TEXTURE_EXTERNAL_OES texture targets; TEXTURE_CUBE_MAP or other extension + * targets should bypass this. An exception is bindTexture(), which should + * see all glBindTexture() calls for any target. + */ + + // glActiveTexture(GL_TEXTURE0 + i) + // Sets the active texture unit. Up to MAX_TEXTURE_UNITS are supported. + GLenum setActiveTextureUnit(GLenum texture); + GLenum getActiveTextureUnit() const; + + // glEnable(GL_TEXTURE_(2D|EXTERNAL_OES)) + void enableTextureTarget(GLenum target); + + // glDisable(GL_TEXTURE_(2D|EXTERNAL_OES)) + void disableTextureTarget(GLenum target); + + // Implements the target priority logic: + // * Return GL_TEXTURE_EXTERNAL_OES if enabled, else + // * Return GL_TEXTURE_2D if enabled, else + // * Return the allDisabled value. + // For some cases passing GL_TEXTURE_2D for allDisabled makes callee code + // simpler; for other cases passing a recognizable enum like GL_ZERO or + // GL_INVALID_ENUM is appropriate. + GLenum getPriorityEnabledTarget(GLenum allDisabled) const; + + // glBindTexture(GL_TEXTURE_*, ...) + // Set the target binding of the active texture unit to texture. Returns + // GL_NO_ERROR on success or GL_INVALID_OPERATION if the texture has + // previously been bound to a different target. If firstUse is not NULL, + // it is set to indicate whether this is the first use of the texture. + // For accurate error detection, bindTexture should be called for *all* + // targets, not just 2D and EXTERNAL_OES. + GLenum bindTexture(GLenum target, GLuint texture, GLboolean* firstUse); + + // Return the texture currently bound to GL_TEXTURE_(2D|EXTERNAL_OES). + GLuint getBoundTexture(GLenum target) const; + + // glDeleteTextures(...) + // Remove references to the to-be-deleted textures. + void deleteTextures(GLsizei n, const GLuint* textures); + +private: + PixelStoreState m_pixelStore; + VertexAttribState *m_states; + int m_nLocations; + GLuint m_currentArrayVbo; + GLuint m_currentIndexVbo; + int m_activeTexture; + GLint m_currentProgram; + + bool validLocation(int location) { return (location >= 0 && location < m_nLocations); } + + enum TextureTarget { + TEXTURE_2D = 0, + TEXTURE_EXTERNAL = 1, + TEXTURE_TARGET_COUNT + }; + struct TextureUnit { + unsigned int enables; + GLuint texture[TEXTURE_TARGET_COUNT]; + }; + struct TextureRec { + GLuint id; + GLenum target; + }; + struct TextureState { + TextureUnit unit[MAX_TEXTURE_UNITS]; + TextureUnit* activeUnit; + TextureRec* textures; + GLuint numTextures; + GLuint allocTextures; + }; + TextureState m_tex; + + static int compareTexId(const void* pid, const void* prec); + TextureRec* addTextureRec(GLuint id, GLenum target); + +public: + void getClientStatePointer(GLenum pname, GLvoid** params); + + template <class T> + int getVertexAttribParameter(GLuint index, GLenum param, T *ptr) + { + bool handled = true; + const VertexAttribState *vertexAttrib = getState(index); + if (vertexAttrib == NULL) { + ERR("getVeterxAttriParameter for non existant index %d\n", index); + // set gl error; + return handled; + } + + switch(param) { + case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: + *ptr = (T)(vertexAttrib->bufferObject); + break; + case GL_VERTEX_ATTRIB_ARRAY_ENABLED: + *ptr = (T)(vertexAttrib->enabled); + break; + case GL_VERTEX_ATTRIB_ARRAY_SIZE: + *ptr = (T)(vertexAttrib->size); + break; + case GL_VERTEX_ATTRIB_ARRAY_STRIDE: + *ptr = (T)(vertexAttrib->stride); + break; + case GL_VERTEX_ATTRIB_ARRAY_TYPE: + *ptr = (T)(vertexAttrib->type); + break; + case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: + *ptr = (T)(vertexAttrib->normalized); + break; + case GL_CURRENT_VERTEX_ATTRIB: + handled = false; + break; + default: + handled = false; + ERR("unknown vertex-attrib parameter param %d\n", param); + } + return handled; + } + + template <class T> + bool getClientStateParameter(GLenum param, T* ptr) + { + bool isClientStateParam = false; + switch (param) { + case GL_CLIENT_ACTIVE_TEXTURE: { + GLint tex = getActiveTexture() + GL_TEXTURE0; + *ptr = tex; + isClientStateParam = true; + break; + } + case GL_VERTEX_ARRAY_SIZE: { + const GLClientState::VertexAttribState *state = getState(GLClientState::VERTEX_LOCATION); + *ptr = state->size; + isClientStateParam = true; + break; + } + case GL_VERTEX_ARRAY_TYPE: { + const GLClientState::VertexAttribState *state = getState(GLClientState::VERTEX_LOCATION); + *ptr = state->type; + isClientStateParam = true; + break; + } + case GL_VERTEX_ARRAY_STRIDE: { + const GLClientState::VertexAttribState *state = getState(GLClientState::VERTEX_LOCATION); + *ptr = state->stride; + isClientStateParam = true; + break; + } + case GL_COLOR_ARRAY_SIZE: { + const GLClientState::VertexAttribState *state = getState(GLClientState::COLOR_LOCATION); + *ptr = state->size; + isClientStateParam = true; + break; + } + case GL_COLOR_ARRAY_TYPE: { + const GLClientState::VertexAttribState *state = getState(GLClientState::COLOR_LOCATION); + *ptr = state->type; + isClientStateParam = true; + break; + } + case GL_COLOR_ARRAY_STRIDE: { + const GLClientState::VertexAttribState *state = getState(GLClientState::COLOR_LOCATION); + *ptr = state->stride; + isClientStateParam = true; + break; + } + case GL_NORMAL_ARRAY_TYPE: { + const GLClientState::VertexAttribState *state = getState(GLClientState::NORMAL_LOCATION); + *ptr = state->type; + isClientStateParam = true; + break; + } + case GL_NORMAL_ARRAY_STRIDE: { + const GLClientState::VertexAttribState *state = getState(GLClientState::NORMAL_LOCATION); + *ptr = state->stride; + isClientStateParam = true; + break; + } + case GL_TEXTURE_COORD_ARRAY_SIZE: { + const GLClientState::VertexAttribState *state = getState(getActiveTexture() + GLClientState::TEXCOORD0_LOCATION); + *ptr = state->size; + isClientStateParam = true; + break; + } + case GL_TEXTURE_COORD_ARRAY_TYPE: { + const GLClientState::VertexAttribState *state = getState(getActiveTexture() + GLClientState::TEXCOORD0_LOCATION); + *ptr = state->type; + isClientStateParam = true; + break; + } + case GL_TEXTURE_COORD_ARRAY_STRIDE: { + const GLClientState::VertexAttribState *state = getState(getActiveTexture() + GLClientState::TEXCOORD0_LOCATION); + *ptr = state->stride; + isClientStateParam = true; + break; + } + case GL_POINT_SIZE_ARRAY_TYPE_OES: { + const GLClientState::VertexAttribState *state = getState(GLClientState::POINTSIZE_LOCATION); + *ptr = state->type; + isClientStateParam = true; + break; + } + case GL_POINT_SIZE_ARRAY_STRIDE_OES: { + const GLClientState::VertexAttribState *state = getState(GLClientState::POINTSIZE_LOCATION); + *ptr = state->stride; + isClientStateParam = true; + break; + } + case GL_MATRIX_INDEX_ARRAY_SIZE_OES: { + const GLClientState::VertexAttribState *state = getState(GLClientState::MATRIXINDEX_LOCATION); + *ptr = state->size; + isClientStateParam = true; + break; + } + case GL_MATRIX_INDEX_ARRAY_TYPE_OES: { + const GLClientState::VertexAttribState *state = getState(GLClientState::MATRIXINDEX_LOCATION); + *ptr = state->type; + isClientStateParam = true; + break; + } + case GL_MATRIX_INDEX_ARRAY_STRIDE_OES: { + const GLClientState::VertexAttribState *state = getState(GLClientState::MATRIXINDEX_LOCATION); + *ptr = state->stride; + isClientStateParam = true; + break; + } + case GL_WEIGHT_ARRAY_SIZE_OES: { + const GLClientState::VertexAttribState *state = getState(GLClientState::WEIGHT_LOCATION); + *ptr = state->size; + isClientStateParam = true; + break; + } + case GL_WEIGHT_ARRAY_TYPE_OES: { + const GLClientState::VertexAttribState *state = getState(GLClientState::WEIGHT_LOCATION); + *ptr = state->type; + isClientStateParam = true; + break; + } + case GL_WEIGHT_ARRAY_STRIDE_OES: { + const GLClientState::VertexAttribState *state = getState(GLClientState::WEIGHT_LOCATION); + *ptr = state->stride; + isClientStateParam = true; + break; + } + case GL_VERTEX_ARRAY_BUFFER_BINDING: { + const GLClientState::VertexAttribState *state = getState(GLClientState::VERTEX_LOCATION); + *ptr = state->bufferObject; + isClientStateParam = true; + break; + } + case GL_NORMAL_ARRAY_BUFFER_BINDING: { + const GLClientState::VertexAttribState *state = getState(GLClientState::NORMAL_LOCATION); + *ptr = state->bufferObject; + isClientStateParam = true; + break; + } + case GL_COLOR_ARRAY_BUFFER_BINDING: { + const GLClientState::VertexAttribState *state = getState(GLClientState::COLOR_LOCATION); + *ptr = state->bufferObject; + isClientStateParam = true; + break; + } + case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING: { + const GLClientState::VertexAttribState *state = getState(getActiveTexture()+GLClientState::TEXCOORD0_LOCATION); + *ptr = state->bufferObject; + isClientStateParam = true; + break; + } + case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES: { + const GLClientState::VertexAttribState *state = getState(GLClientState::POINTSIZE_LOCATION); + *ptr = state->bufferObject; + isClientStateParam = true; + break; + } + case GL_MATRIX_INDEX_ARRAY_BUFFER_BINDING_OES: { + const GLClientState::VertexAttribState *state = getState(GLClientState::MATRIXINDEX_LOCATION); + *ptr = state->bufferObject; + isClientStateParam = true; + break; + } + case GL_WEIGHT_ARRAY_BUFFER_BINDING_OES: { + const GLClientState::VertexAttribState *state = getState(GLClientState::WEIGHT_LOCATION); + *ptr = state->bufferObject; + isClientStateParam = true; + break; + } + case GL_ARRAY_BUFFER_BINDING: { + int buffer = getBuffer(GL_ARRAY_BUFFER); + *ptr = buffer; + isClientStateParam = true; + break; + } + case GL_ELEMENT_ARRAY_BUFFER_BINDING: { + int buffer = getBuffer(GL_ELEMENT_ARRAY_BUFFER); + *ptr = buffer; + isClientStateParam = true; + break; + } + } + return isClientStateParam; + } + +}; +#endif diff --git a/emulator/opengl/shared/OpenglCodecCommon/GLDecoderContextData.h b/emulator/opengl/shared/OpenglCodecCommon/GLDecoderContextData.h new file mode 100644 index 0000000..23785ae --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/GLDecoderContextData.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 _GL_DECODER_CONTEXT_DATA_H_ +#define _GL_DECODER_CONTEXT_DATA_H_ + +#include <assert.h> +#include <string.h> +#include "FixedBuffer.h" +#include "codec_defs.h" + +class GLDecoderContextData { +public: + typedef enum { + VERTEX_LOCATION = 0, + NORMAL_LOCATION = 1, + COLOR_LOCATION = 2, + POINTSIZE_LOCATION = 3, + TEXCOORD0_LOCATION = 4, + TEXCOORD1_LOCATION = 5, + TEXCOORD2_LOCATION = 6, + TEXCOORD3_LOCATION = 7, + TEXCOORD4_LOCATION = 8, + TEXCOORD5_LOCATION = 9, + TEXCOORD6_LOCATION = 10, + TEXCOORD7_LOCATION = 11, + MATRIXINDEX_LOCATION = 12, + WEIGHT_LOCATION = 13, + LAST_LOCATION = 14 + } PointerDataLocation; + + GLDecoderContextData(int nLocations = CODEC_MAX_VERTEX_ATTRIBUTES) : + m_nLocations(nLocations) + { + m_pointerData = new FixedBuffer[m_nLocations]; + } + + ~GLDecoderContextData() { + delete [] m_pointerData; + } + + void storePointerData(unsigned int loc, void *data, size_t len) { + + assert(loc < m_nLocations); + m_pointerData[loc].alloc(len); + memcpy(m_pointerData[loc].ptr(), data, len); + } + void *pointerData(unsigned int loc) { + assert(loc < m_nLocations); + return m_pointerData[loc].ptr(); + } +private: + FixedBuffer *m_pointerData; + int m_nLocations; +}; + +#endif diff --git a/emulator/opengl/shared/OpenglCodecCommon/GLErrorLog.h b/emulator/opengl/shared/OpenglCodecCommon/GLErrorLog.h new file mode 100644 index 0000000..5654aea --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/GLErrorLog.h @@ -0,0 +1,34 @@ +/* +* 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 __GL_ERROR_LOG_H__ +#define __GL_ERROR_LOG_H__ + +#include "ErrorLog.h" + +#ifdef CHECK_GL_ERROR +void dbg(){} +#define GET_GL_ERROR(gl) \ + { \ + int err = gl.glGetError(); \ + if (err) { dbg(); ERR("Error: 0x%X in %s (%s:%d)\n", err, __FUNCTION__, __FILE__, __LINE__); } \ + } + +#else +#define GET_GL_ERROR(gl) +#endif + +#endif //__GL_ERROR_LOG_H__ diff --git a/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp b/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp new file mode 100644 index 0000000..8504f7f --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp @@ -0,0 +1,469 @@ +/* +* 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 "GLSharedGroup.h" + +/**** BufferData ****/ + +BufferData::BufferData() : m_size(0) {}; +BufferData::BufferData(GLsizeiptr size, void * data) : m_size(size) +{ + void * buffer = NULL; + if (size>0) buffer = m_fixedBuffer.alloc(size); + if (data) memcpy(buffer, data, size); +} + +/**** ProgramData ****/ +ProgramData::ProgramData() : m_numIndexes(0), + m_initialized(false), + m_locShiftWAR(false) +{ + m_Indexes = NULL; +} + +void ProgramData::initProgramData(GLuint numIndexes) +{ + m_initialized = true; + m_numIndexes = numIndexes; + delete[] m_Indexes; + m_Indexes = new IndexInfo[numIndexes]; + m_locShiftWAR = false; +} + +bool ProgramData::isInitialized() +{ + return m_initialized; +} + +ProgramData::~ProgramData() +{ + delete[] m_Indexes; + m_Indexes = NULL; +} + +void ProgramData::setIndexInfo(GLuint index, GLint base, GLint size, GLenum type) +{ + if (index>=m_numIndexes) + return; + m_Indexes[index].base = base; + m_Indexes[index].size = size; + m_Indexes[index].type = type; + if (index > 0) { + m_Indexes[index].appBase = m_Indexes[index-1].appBase + + m_Indexes[index-1].size; + } + else { + m_Indexes[index].appBase = 0; + } + m_Indexes[index].hostLocsPerElement = 1; + m_Indexes[index].flags = 0; + m_Indexes[index].samplerValue = 0; +} + +void ProgramData::setIndexFlags(GLuint index, GLuint flags) +{ + if (index >= m_numIndexes) + return; + m_Indexes[index].flags |= flags; +} + +GLuint ProgramData::getIndexForLocation(GLint location) +{ + GLuint index = m_numIndexes; + GLint minDist = -1; + for (GLuint i=0;i<m_numIndexes;++i) + { + GLint dist = location - m_Indexes[i].base; + if (dist >= 0 && + (minDist < 0 || dist < minDist)) { + index = i; + minDist = dist; + } + } + return index; +} + +GLenum ProgramData::getTypeForLocation(GLint location) +{ + GLuint index = getIndexForLocation(location); + if (index<m_numIndexes) { + return m_Indexes[index].type; + } + return 0; +} + +void ProgramData::setupLocationShiftWAR() +{ + m_locShiftWAR = false; + for (GLuint i=0; i<m_numIndexes; i++) { + if (0 != (m_Indexes[i].base & 0xffff)) { + return; + } + } + // if we have one uniform at location 0, we do not need the WAR. + if (m_numIndexes > 1) { + m_locShiftWAR = true; + } +} + +GLint ProgramData::locationWARHostToApp(GLint hostLoc, GLint arrIndex) +{ + if (!m_locShiftWAR) return hostLoc; + + GLuint index = getIndexForLocation(hostLoc); + if (index<m_numIndexes) { + if (arrIndex > 0) { + m_Indexes[index].hostLocsPerElement = + (hostLoc - m_Indexes[index].base) / arrIndex; + } + return m_Indexes[index].appBase + arrIndex; + } + return -1; +} + +GLint ProgramData::locationWARAppToHost(GLint appLoc) +{ + if (!m_locShiftWAR) return appLoc; + + for(GLuint i=0; i<m_numIndexes; i++) { + GLint elemIndex = appLoc - m_Indexes[i].appBase; + if (elemIndex >= 0 && elemIndex < m_Indexes[i].size) { + return m_Indexes[i].base + + elemIndex * m_Indexes[i].hostLocsPerElement; + } + } + return -1; +} + +GLint ProgramData::getNextSamplerUniform(GLint index, GLint* val, GLenum* target) +{ + for (GLint i = index + 1; i >= 0 && i < (GLint)m_numIndexes; i++) { + if (m_Indexes[i].type == GL_SAMPLER_2D) { + if (val) *val = m_Indexes[i].samplerValue; + if (target) { + if (m_Indexes[i].flags & INDEX_FLAG_SAMPLER_EXTERNAL) { + *target = GL_TEXTURE_EXTERNAL_OES; + } else { + *target = GL_TEXTURE_2D; + } + } + return i; + } + } + return -1; +} + +bool ProgramData::setSamplerUniform(GLint appLoc, GLint val, GLenum* target) +{ + for (GLuint i = 0; i < m_numIndexes; i++) { + GLint elemIndex = appLoc - m_Indexes[i].appBase; + if (elemIndex >= 0 && elemIndex < m_Indexes[i].size) { + if (m_Indexes[i].type == GL_TEXTURE_2D) { + m_Indexes[i].samplerValue = val; + if (target) { + if (m_Indexes[i].flags & INDEX_FLAG_SAMPLER_EXTERNAL) { + *target = GL_TEXTURE_EXTERNAL_OES; + } else { + *target = GL_TEXTURE_2D; + } + } + return true; + } + } + } + return false; +} + +bool ProgramData::attachShader(GLuint shader) +{ + size_t n = m_shaders.size(); + for (size_t i = 0; i < n; i++) { + if (m_shaders[i] == shader) { + return false; + } + } + // AKA m_shaders.push_back(), but that has an ambiguous call to insertAt() + // due to the default parameters. This is the desired insertAt() overload. + m_shaders.insertAt(shader, m_shaders.size(), 1); + return true; +} + +bool ProgramData::detachShader(GLuint shader) +{ + size_t n = m_shaders.size(); + for (size_t i = 0; i < n; i++) { + if (m_shaders[i] == shader) { + m_shaders.removeAt(i); + return true; + } + } + return false; +} + +/***** GLSharedGroup ****/ + +GLSharedGroup::GLSharedGroup() : + m_buffers(android::DefaultKeyedVector<GLuint, BufferData*>(NULL)), + m_programs(android::DefaultKeyedVector<GLuint, ProgramData*>(NULL)), + m_shaders(android::DefaultKeyedVector<GLuint, ShaderData*>(NULL)) +{ +} + +GLSharedGroup::~GLSharedGroup() +{ + m_buffers.clear(); + m_programs.clear(); +} + +BufferData * GLSharedGroup::getBufferData(GLuint bufferId) +{ + android::AutoMutex _lock(m_lock); + return m_buffers.valueFor(bufferId); +} + +void GLSharedGroup::addBufferData(GLuint bufferId, GLsizeiptr size, void * data) +{ + android::AutoMutex _lock(m_lock); + m_buffers.add(bufferId, new BufferData(size, data)); +} + +void GLSharedGroup::updateBufferData(GLuint bufferId, GLsizeiptr size, void * data) +{ + android::AutoMutex _lock(m_lock); + m_buffers.replaceValueFor(bufferId, new BufferData(size, data)); +} + +GLenum GLSharedGroup::subUpdateBufferData(GLuint bufferId, GLintptr offset, GLsizeiptr size, void * data) +{ + android::AutoMutex _lock(m_lock); + BufferData * buf = m_buffers.valueFor(bufferId); + if ((!buf) || (buf->m_size < offset+size) || (offset < 0) || (size<0)) return GL_INVALID_VALUE; + + //it's safe to update now + memcpy((char*)buf->m_fixedBuffer.ptr() + offset, data, size); + return GL_NO_ERROR; +} + +void GLSharedGroup::deleteBufferData(GLuint bufferId) +{ + android::AutoMutex _lock(m_lock); + m_buffers.removeItem(bufferId); +} + +void GLSharedGroup::addProgramData(GLuint program) +{ + android::AutoMutex _lock(m_lock); + ProgramData *pData = m_programs.valueFor(program); + if (pData) + { + m_programs.removeItem(program); + delete pData; + } + + m_programs.add(program,new ProgramData()); +} + +void GLSharedGroup::initProgramData(GLuint program, GLuint numIndexes) +{ + android::AutoMutex _lock(m_lock); + ProgramData *pData = m_programs.valueFor(program); + if (pData) + { + pData->initProgramData(numIndexes); + } +} + +bool GLSharedGroup::isProgramInitialized(GLuint program) +{ + android::AutoMutex _lock(m_lock); + ProgramData* pData = m_programs.valueFor(program); + if (pData) + { + return pData->isInitialized(); + } + return false; +} + +void GLSharedGroup::deleteProgramData(GLuint program) +{ + android::AutoMutex _lock(m_lock); + ProgramData *pData = m_programs.valueFor(program); + if (pData) + delete pData; + m_programs.removeItem(program); +} + +void GLSharedGroup::attachShader(GLuint program, GLuint shader) +{ + android::AutoMutex _lock(m_lock); + ProgramData* programData = m_programs.valueFor(program); + ssize_t idx = m_shaders.indexOfKey(shader); + if (programData && idx >= 0) { + if (programData->attachShader(shader)) { + refShaderDataLocked(idx); + } + } +} + +void GLSharedGroup::detachShader(GLuint program, GLuint shader) +{ + android::AutoMutex _lock(m_lock); + ProgramData* programData = m_programs.valueFor(program); + ssize_t idx = m_shaders.indexOfKey(shader); + if (programData && idx >= 0) { + if (programData->detachShader(shader)) { + unrefShaderDataLocked(idx); + } + } +} + +void GLSharedGroup::setProgramIndexInfo(GLuint program, GLuint index, GLint base, GLint size, GLenum type, const char* name) +{ + android::AutoMutex _lock(m_lock); + ProgramData* pData = m_programs.valueFor(program); + if (pData) + { + pData->setIndexInfo(index,base,size,type); + + if (type == GL_SAMPLER_2D) { + size_t n = pData->getNumShaders(); + for (size_t i = 0; i < n; i++) { + GLuint shaderId = pData->getShader(i); + ShaderData* shader = m_shaders.valueFor(shaderId); + if (!shader) continue; + ShaderData::StringList::iterator nameIter = shader->samplerExternalNames.begin(); + ShaderData::StringList::iterator nameEnd = shader->samplerExternalNames.end(); + while (nameIter != nameEnd) { + if (*nameIter == name) { + pData->setIndexFlags(index, ProgramData::INDEX_FLAG_SAMPLER_EXTERNAL); + break; + } + ++nameIter; + } + } + } + } +} + +GLenum GLSharedGroup::getProgramUniformType(GLuint program, GLint location) +{ + android::AutoMutex _lock(m_lock); + ProgramData* pData = m_programs.valueFor(program); + GLenum type=0; + if (pData) + { + type = pData->getTypeForLocation(location); + } + return type; +} + +bool GLSharedGroup::isProgram(GLuint program) +{ + android::AutoMutex _lock(m_lock); + ProgramData* pData = m_programs.valueFor(program); + return (pData!=NULL); +} + +void GLSharedGroup::setupLocationShiftWAR(GLuint program) +{ + android::AutoMutex _lock(m_lock); + ProgramData* pData = m_programs.valueFor(program); + if (pData) pData->setupLocationShiftWAR(); +} + +GLint GLSharedGroup::locationWARHostToApp(GLuint program, GLint hostLoc, GLint arrIndex) +{ + android::AutoMutex _lock(m_lock); + ProgramData* pData = m_programs.valueFor(program); + if (pData) return pData->locationWARHostToApp(hostLoc, arrIndex); + else return hostLoc; +} + +GLint GLSharedGroup::locationWARAppToHost(GLuint program, GLint appLoc) +{ + android::AutoMutex _lock(m_lock); + ProgramData* pData = m_programs.valueFor(program); + if (pData) return pData->locationWARAppToHost(appLoc); + else return appLoc; +} + +bool GLSharedGroup::needUniformLocationWAR(GLuint program) +{ + android::AutoMutex _lock(m_lock); + ProgramData* pData = m_programs.valueFor(program); + if (pData) return pData->needUniformLocationWAR(); + return false; +} + +GLint GLSharedGroup::getNextSamplerUniform(GLuint program, GLint index, GLint* val, GLenum* target) const +{ + android::AutoMutex _lock(m_lock); + ProgramData* pData = m_programs.valueFor(program); + return pData ? pData->getNextSamplerUniform(index, val, target) : -1; +} + +bool GLSharedGroup::setSamplerUniform(GLuint program, GLint appLoc, GLint val, GLenum* target) +{ + android::AutoMutex _lock(m_lock); + ProgramData* pData = m_programs.valueFor(program); + return pData ? pData->setSamplerUniform(appLoc, val, target) : false; +} + +bool GLSharedGroup::addShaderData(GLuint shader) +{ + android::AutoMutex _lock(m_lock); + ShaderData* data = new ShaderData; + if (data) { + if (m_shaders.add(shader, data) < 0) { + delete data; + data = NULL; + } + data->refcount = 1; + } + return data != NULL; +} + +ShaderData* GLSharedGroup::getShaderData(GLuint shader) +{ + android::AutoMutex _lock(m_lock); + return m_shaders.valueFor(shader); +} + +void GLSharedGroup::unrefShaderData(GLuint shader) +{ + android::AutoMutex _lock(m_lock); + ssize_t idx = m_shaders.indexOfKey(shader); + if (idx >= 0) { + unrefShaderDataLocked(idx); + } +} + +void GLSharedGroup::refShaderDataLocked(ssize_t shaderIdx) +{ + assert(shaderIdx >= 0 && shaderIdx <= m_shaders.size()); + ShaderData* data = m_shaders.valueAt(shaderIdx); + data->refcount++; +} + +void GLSharedGroup::unrefShaderDataLocked(ssize_t shaderIdx) +{ + assert(shaderIdx >= 0 && shaderIdx <= m_shaders.size()); + ShaderData* data = m_shaders.valueAt(shaderIdx); + if (--data->refcount == 0) { + delete data; + m_shaders.removeItemsAt(shaderIdx); + } +} diff --git a/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.h b/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.h new file mode 100644 index 0000000..61b8f00 --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.h @@ -0,0 +1,143 @@ +/* +* 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_SHARED_GROUP_H_ +#define _GL_SHARED_GROUP_H_ + +#define GL_API +#ifndef ANDROID +#define GL_APIENTRY +#define GL_APIENTRYP +#endif + +#include <GLES/gl.h> +#include <GLES/glext.h> +#include <GLES2/gl2.h> +#include <GLES2/gl2ext.h> + +#include <stdio.h> +#include <stdlib.h> +#include "ErrorLog.h" +#include <utils/KeyedVector.h> +#include <utils/List.h> +#include <utils/String8.h> +#include <utils/threads.h> +#include "FixedBuffer.h" +#include "SmartPtr.h" + +struct BufferData { + BufferData(); + BufferData(GLsizeiptr size, void * data); + GLsizeiptr m_size; + FixedBuffer m_fixedBuffer; +}; + +class ProgramData { +private: + typedef struct _IndexInfo { + GLint base; + GLint size; + GLenum type; + GLint appBase; + GLint hostLocsPerElement; + GLuint flags; + GLint samplerValue; // only set for sampler uniforms + } IndexInfo; + + GLuint m_numIndexes; + IndexInfo* m_Indexes; + bool m_initialized; + bool m_locShiftWAR; + + android::Vector<GLuint> m_shaders; + +public: + enum { + INDEX_FLAG_SAMPLER_EXTERNAL = 0x00000001, + }; + + ProgramData(); + void initProgramData(GLuint numIndexes); + bool isInitialized(); + virtual ~ProgramData(); + void setIndexInfo(GLuint index, GLint base, GLint size, GLenum type); + void setIndexFlags(GLuint index, GLuint flags); + GLuint getIndexForLocation(GLint location); + GLenum getTypeForLocation(GLint location); + + bool needUniformLocationWAR() const { return m_locShiftWAR; } + void setupLocationShiftWAR(); + GLint locationWARHostToApp(GLint hostLoc, GLint arrIndex); + GLint locationWARAppToHost(GLint appLoc); + + GLint getNextSamplerUniform(GLint index, GLint* val, GLenum* target); + bool setSamplerUniform(GLint appLoc, GLint val, GLenum* target); + + bool attachShader(GLuint shader); + bool detachShader(GLuint shader); + size_t getNumShaders() const { return m_shaders.size(); } + GLuint getShader(size_t i) const { return m_shaders[i]; } +}; + +struct ShaderData { + typedef android::List<android::String8> StringList; + StringList samplerExternalNames; + int refcount; +}; + +class GLSharedGroup { +private: + android::DefaultKeyedVector<GLuint, BufferData*> m_buffers; + android::DefaultKeyedVector<GLuint, ProgramData*> m_programs; + android::DefaultKeyedVector<GLuint, ShaderData*> m_shaders; + mutable android::Mutex m_lock; + + void refShaderDataLocked(ssize_t shaderIdx); + void unrefShaderDataLocked(ssize_t shaderIdx); + +public: + GLSharedGroup(); + ~GLSharedGroup(); + BufferData * getBufferData(GLuint bufferId); + void addBufferData(GLuint bufferId, GLsizeiptr size, void * data); + void updateBufferData(GLuint bufferId, GLsizeiptr size, void * data); + GLenum subUpdateBufferData(GLuint bufferId, GLintptr offset, GLsizeiptr size, void * data); + void deleteBufferData(GLuint); + + bool isProgram(GLuint program); + bool isProgramInitialized(GLuint program); + void addProgramData(GLuint program); + void initProgramData(GLuint program, GLuint numIndexes); + void attachShader(GLuint program, GLuint shader); + void detachShader(GLuint program, GLuint shader); + void deleteProgramData(GLuint program); + void setProgramIndexInfo(GLuint program, GLuint index, GLint base, GLint size, GLenum type, const char* name); + GLenum getProgramUniformType(GLuint program, GLint location); + void setupLocationShiftWAR(GLuint program); + GLint locationWARHostToApp(GLuint program, GLint hostLoc, GLint arrIndex); + GLint locationWARAppToHost(GLuint program, GLint appLoc); + bool needUniformLocationWAR(GLuint program); + GLint getNextSamplerUniform(GLuint program, GLint index, GLint* val, GLenum* target) const; + bool setSamplerUniform(GLuint program, GLint appLoc, GLint val, GLenum* target); + + bool addShaderData(GLuint shader); + // caller must hold a reference to the shader as long as it holds the pointer + ShaderData* getShaderData(GLuint shader); + void unrefShaderData(GLuint shader); +}; + +typedef SmartPtr<GLSharedGroup> GLSharedGroupPtr; + +#endif //_GL_SHARED_GROUP_H_ diff --git a/emulator/opengl/shared/OpenglCodecCommon/Makefile b/emulator/opengl/shared/OpenglCodecCommon/Makefile new file mode 100644 index 0000000..e8bf431 --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/Makefile @@ -0,0 +1,13 @@ + +ROOT=../.. + +include $(ROOT)/make/commondefs + +CXXFILES = TcpStream.cpp GLClientState.cpp glUtils.cpp +CXXINCS += -I$(ROOT)/libs/GLESv1 -I$(ROOT)/include + +LIBRARY_NAME = libcodecCommon.a + +include $(COMMONRULES) + + diff --git a/emulator/opengl/shared/OpenglCodecCommon/SmartPtr.h b/emulator/opengl/shared/OpenglCodecCommon/SmartPtr.h new file mode 100644 index 0000000..4bdfbe4 --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/SmartPtr.h @@ -0,0 +1,167 @@ +/* +* 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; + } + + operator void*() const { + return (void *)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/shared/OpenglCodecCommon/SocketStream.cpp b/emulator/opengl/shared/OpenglCodecCommon/SocketStream.cpp new file mode 100644 index 0000000..f7a2314 --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/SocketStream.cpp @@ -0,0 +1,168 @@ +/* +* 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 "SocketStream.h" +#include <cutils/sockets.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> + +#ifndef _WIN32 +#include <netinet/in.h> +#include <netinet/tcp.h> +#include <sys/un.h> +#else +#include <ws2tcpip.h> +#endif + +SocketStream::SocketStream(size_t bufSize) : + IOStream(bufSize), + m_sock(-1), + m_bufsize(bufSize), + m_buf(NULL) +{ +} + +SocketStream::SocketStream(int sock, size_t bufSize) : + IOStream(bufSize), + m_sock(sock), + m_bufsize(bufSize), + m_buf(NULL) +{ +} + +SocketStream::~SocketStream() +{ + if (m_sock >= 0) { +#ifdef _WIN32 + closesocket(m_sock); +#else + ::close(m_sock); +#endif + } + if (m_buf != NULL) { + free(m_buf); + m_buf = NULL; + } +} + + +void *SocketStream::allocBuffer(size_t minSize) +{ + size_t allocSize = (m_bufsize < minSize ? minSize : m_bufsize); + if (!m_buf) { + m_buf = (unsigned char *)malloc(allocSize); + } + else if (m_bufsize < allocSize) { + unsigned char *p = (unsigned char *)realloc(m_buf, allocSize); + if (p != NULL) { + m_buf = p; + m_bufsize = allocSize; + } else { + ERR("%s: realloc (%zu) failed\n", __FUNCTION__, allocSize); + free(m_buf); + m_buf = NULL; + m_bufsize = 0; + } + } + + return m_buf; +}; + +int SocketStream::commitBuffer(size_t size) +{ + return writeFully(m_buf, size); +} + +int SocketStream::writeFully(const void* buffer, size_t size) +{ + if (!valid()) return -1; + + size_t res = size; + int retval = 0; + + while (res > 0) { + ssize_t stat = ::send(m_sock, (const char *)buffer + (size - res), res, 0); + if (stat < 0) { + if (errno != EINTR) { + retval = stat; + ERR("%s: failed: %s\n", __FUNCTION__, strerror(errno)); + break; + } + } else { + res -= stat; + } + } + return retval; +} + +const unsigned char *SocketStream::readFully(void *buf, size_t len) +{ + const unsigned char* ret = NULL; + if (!valid()) return NULL; + if (!buf) { + return NULL; // do not allow NULL buf in that implementation + } + size_t res = len; + while (res > 0) { + ssize_t stat = ::recv(m_sock, (char *)(buf) + len - res, res, 0); + if (stat > 0) { + res -= stat; + continue; + } + if (stat == 0 || errno != EINTR) { // client shutdown or error + return NULL; + } + } + return (const unsigned char *)buf; +} + +const unsigned char *SocketStream::read( void *buf, size_t *inout_len) +{ + if (!valid()) return NULL; + if (!buf) { + return NULL; // do not allow NULL buf in that implementation + } + + int n; + do { + n = recv(buf, *inout_len); + } while( n < 0 && errno == EINTR ); + + if (n > 0) { + *inout_len = n; + return (const unsigned char *)buf; + } + + return NULL; +} + +int SocketStream::recv(void *buf, size_t len) +{ + if (!valid()) return int(ERR_INVALID_SOCKET); + int res = 0; + while(true) { + res = ::recv(m_sock, (char *)buf, len, 0); + if (res < 0) { + if (errno == EINTR) { + continue; + } + } + break; + } + return res; +} diff --git a/emulator/opengl/shared/OpenglCodecCommon/SocketStream.h b/emulator/opengl/shared/OpenglCodecCommon/SocketStream.h new file mode 100644 index 0000000..3a501b4 --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/SocketStream.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 __SOCKET_STREAM_H +#define __SOCKET_STREAM_H + +#include <stdlib.h> +#include "IOStream.h" + +class SocketStream : public IOStream { +public: + typedef enum { ERR_INVALID_SOCKET = -1000 } SocketStreamError; + + explicit SocketStream(size_t bufsize = 10000); + virtual ~SocketStream(); + + virtual int listen(unsigned short port) = 0; + virtual SocketStream *accept() = 0; + virtual int connect(unsigned short port) = 0; + + virtual void *allocBuffer(size_t minSize); + virtual int commitBuffer(size_t size); + virtual const unsigned char *readFully(void *buf, size_t len); + virtual const unsigned char *read(void *buf, size_t *inout_len); + + bool valid() { return m_sock >= 0; } + virtual int recv(void *buf, size_t len); + virtual int writeFully(const void *buf, size_t len); + +protected: + int m_sock; + size_t m_bufsize; + unsigned char *m_buf; + + SocketStream(int sock, size_t bufSize); +}; + +#endif /* __SOCKET_STREAM_H */ diff --git a/emulator/opengl/shared/OpenglCodecCommon/TcpStream.cpp b/emulator/opengl/shared/OpenglCodecCommon/TcpStream.cpp new file mode 100644 index 0000000..4da2cec --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/TcpStream.cpp @@ -0,0 +1,91 @@ +/* +* 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 "TcpStream.h" +#include <cutils/sockets.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> + +#ifndef _WIN32 +#include <netinet/in.h> +#include <netinet/tcp.h> +#else +#include <ws2tcpip.h> +#endif + +TcpStream::TcpStream(size_t bufSize) : + SocketStream(bufSize) +{ +} + +TcpStream::TcpStream(int sock, size_t bufSize) : + SocketStream(sock, bufSize) +{ + // disable Nagle algorithm to improve bandwidth of small + // packets which are quite common in our implementation. +#ifdef _WIN32 + DWORD flag; +#else + int flag; +#endif + flag = 1; + setsockopt( sock, IPPROTO_TCP, TCP_NODELAY, (const char*)&flag, sizeof(flag) ); +} + +int TcpStream::listen(unsigned short port) +{ + m_sock = socket_loopback_server(port, SOCK_STREAM); + if (!valid()) return int(ERR_INVALID_SOCKET); + + return 0; +} + +SocketStream * TcpStream::accept() +{ + int clientSock = -1; + + while (true) { + struct sockaddr_in addr; + socklen_t len = sizeof(addr); + clientSock = ::accept(m_sock, (sockaddr *)&addr, &len); + + if (clientSock < 0 && errno == EINTR) { + continue; + } + break; + } + + TcpStream *clientStream = NULL; + + if (clientSock >= 0) { + clientStream = new TcpStream(clientSock, m_bufsize); + } + return clientStream; +} + +int TcpStream::connect(unsigned short port) +{ + return connect("127.0.0.1",port); +} + +int TcpStream::connect(const char* hostname, unsigned short port) +{ + m_sock = socket_network_client(hostname, port, SOCK_STREAM); + if (!valid()) return -1; + return 0; +} diff --git a/emulator/opengl/shared/OpenglCodecCommon/TcpStream.h b/emulator/opengl/shared/OpenglCodecCommon/TcpStream.h new file mode 100644 index 0000000..811a871 --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/TcpStream.h @@ -0,0 +1,32 @@ +/* +* 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 __TCP_STREAM_H +#define __TCP_STREAM_H + +#include "SocketStream.h" + +class TcpStream : public SocketStream { +public: + explicit TcpStream(size_t bufsize = 10000); + virtual int listen(unsigned short port); + virtual SocketStream *accept(); + virtual int connect(unsigned short port); + int connect(const char* hostname, unsigned short port); +private: + TcpStream(int sock, size_t bufSize); +}; + +#endif diff --git a/emulator/opengl/shared/OpenglCodecCommon/TimeUtils.cpp b/emulator/opengl/shared/OpenglCodecCommon/TimeUtils.cpp new file mode 100644 index 0000000..50aeb03 --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/TimeUtils.cpp @@ -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. +*/ +#include "TimeUtils.h" + +#ifdef _WIN32 +#include <windows.h> +#include <time.h> +#include <stdio.h> +#elif defined(__linux__) +#include <stdlib.h> +#include <sys/time.h> +#include <time.h> +#include <unistd.h> +#else +#include <sys/time.h> +#include <unistd.h> +#endif + +long long GetCurrentTimeMS() +{ +#ifdef _WIN32 + static LARGE_INTEGER freq; + static bool bNotInit = true; + if ( bNotInit ) { + bNotInit = (QueryPerformanceFrequency( &freq ) == FALSE); + } + LARGE_INTEGER currVal; + QueryPerformanceCounter( &currVal ); + + return currVal.QuadPart / (freq.QuadPart / 1000); + +#elif defined(__linux__) + + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + long long iDiff = (now.tv_sec * 1000LL) + now.tv_nsec/1000000LL; + return iDiff; + +#else /* Others, e.g. OS X */ + + struct timeval now; + gettimeofday(&now, NULL); + long long iDiff = (now.tv_sec * 1000LL) + now.tv_usec/1000LL; + return iDiff; + +#endif +} + +void TimeSleepMS(int p_mili) +{ +#ifdef _WIN32 + Sleep(p_mili); +#else + usleep(p_mili * 1000); +#endif +} diff --git a/emulator/opengl/shared/OpenglCodecCommon/TimeUtils.h b/emulator/opengl/shared/OpenglCodecCommon/TimeUtils.h new file mode 100644 index 0000000..bc4fd1c --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/TimeUtils.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 _TIME_UTILS_H +#define _TIME_UTILS_H + +long long GetCurrentTimeMS(); +void TimeSleepMS(int p_mili); + +#endif diff --git a/emulator/opengl/shared/OpenglCodecCommon/UnixStream.cpp b/emulator/opengl/shared/OpenglCodecCommon/UnixStream.cpp new file mode 100644 index 0000000..8e463a3 --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/UnixStream.cpp @@ -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. +*/ +#include "UnixStream.h" +#include <cutils/sockets.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> + +#include <netinet/in.h> +#include <netinet/tcp.h> +#include <sys/un.h> +#include <sys/stat.h> + +/* Not all systems define PATH_MAX, those who don't generally don't + * have a limit on the maximum path size, so use a value that is + * large enough for our very limited needs. + */ +#ifndef PATH_MAX +#define PATH_MAX 128 +#endif + +UnixStream::UnixStream(size_t bufSize) : + SocketStream(bufSize) +{ +} + +UnixStream::UnixStream(int sock, size_t bufSize) : + SocketStream(sock, bufSize) +{ +} + +/* Initialize a sockaddr_un with the appropriate values corresponding + * to a given 'virtual port'. Returns 0 on success, -1 on error. + */ +static int +make_unix_path(char *path, size_t pathlen, int port_number) +{ + char tmp[PATH_MAX]; // temp directory + int ret = 0; + + // First, create user-specific temp directory if needed + const char* user = getenv("USER"); + if (user != NULL) { + struct stat st; + snprintf(tmp, sizeof(tmp), "/tmp/android-%s", user); + do { + ret = ::lstat(tmp, &st); + } while (ret < 0 && errno == EINTR); + + if (ret < 0 && errno == ENOENT) { + do { + ret = ::mkdir(tmp, 0766); + } while (ret < 0 && errno == EINTR); + if (ret < 0) { + ERR("Could not create temp directory: %s", tmp); + user = NULL; // will fall-back to /tmp + } + } + else if (ret < 0) { + user = NULL; // will fallback to /tmp + } + } + + if (user == NULL) { // fallback to /tmp in case of error + snprintf(tmp, sizeof(tmp), "/tmp"); + } + + // Now, initialize it properly + snprintf(path, pathlen, "%s/qemu-gles-%d", tmp, port_number); + return 0; +} + + +int UnixStream::listen(unsigned short port) +{ + char path[PATH_MAX]; + + if (make_unix_path(path, sizeof(path), port) < 0) { + return -1; + } + + m_sock = socket_local_server(path, ANDROID_SOCKET_NAMESPACE_FILESYSTEM, SOCK_STREAM); + if (!valid()) return int(ERR_INVALID_SOCKET); + + return 0; +} + +SocketStream * UnixStream::accept() +{ + int clientSock = -1; + + while (true) { + struct sockaddr_un addr; + socklen_t len = sizeof(addr); + clientSock = ::accept(m_sock, (sockaddr *)&addr, &len); + + if (clientSock < 0 && errno == EINTR) { + continue; + } + break; + } + + UnixStream *clientStream = NULL; + + if (clientSock >= 0) { + clientStream = new UnixStream(clientSock, m_bufsize); + } + return clientStream; +} + +int UnixStream::connect(unsigned short port) +{ + char path[PATH_MAX]; + + if (make_unix_path(path, sizeof(path), port) < 0) + return -1; + + m_sock = socket_local_client(path, ANDROID_SOCKET_NAMESPACE_FILESYSTEM, SOCK_STREAM); + if (!valid()) return -1; + + return 0; +} diff --git a/emulator/opengl/shared/OpenglCodecCommon/UnixStream.h b/emulator/opengl/shared/OpenglCodecCommon/UnixStream.h new file mode 100644 index 0000000..c184b19 --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/UnixStream.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 __UNIX_STREAM_H +#define __UNIX_STREAM_H + +#include "SocketStream.h" + +class UnixStream : public SocketStream { +public: + explicit UnixStream(size_t bufsize = 10000); + virtual int listen(unsigned short port); + virtual SocketStream *accept(); + virtual int connect(unsigned short port); +private: + UnixStream(int sock, size_t bufSize); +}; + +#endif diff --git a/emulator/opengl/shared/OpenglCodecCommon/Win32PipeStream.cpp b/emulator/opengl/shared/OpenglCodecCommon/Win32PipeStream.cpp new file mode 100644 index 0000000..e1a0b9b --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/Win32PipeStream.cpp @@ -0,0 +1,239 @@ +/* +* 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 "Win32PipeStream.h" + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <windows.h> + +#ifndef _WIN32 +#error ONLY BUILD THIS SOURCE FILE FOR WINDOWS! +#endif + +/* The official documentation states that the name of a given named + * pipe cannot be more than 256 characters long. + */ +#define NAMED_PIPE_MAX 256 + +Win32PipeStream::Win32PipeStream(size_t bufSize) : + SocketStream(bufSize), + m_pipe(INVALID_HANDLE_VALUE) +{ +} + +Win32PipeStream::Win32PipeStream(HANDLE pipe, size_t bufSize) : + SocketStream(-1, bufSize), + m_pipe(pipe) +{ +} + +Win32PipeStream::~Win32PipeStream() +{ + if (m_pipe != INVALID_HANDLE_VALUE) { + CloseHandle(m_pipe); + m_pipe = INVALID_HANDLE_VALUE; + } +} + +/* Initialize the pipe name corresponding to a given port + */ +static void +make_pipe_name(char *path, size_t pathlen, int port_number) +{ + snprintf(path, pathlen, "\\\\.\\pipe\\qemu-gles-%d", port_number); +} + + +/* Technical note: Named pipes work differently from BSD Sockets. + * One does not create/bind a pipe, and collect a new handle each + * time a client connects with accept(). + * + * Instead, the server creates a new pipe instance each time it wants + * to get a new client connection, then calls ConnectNamedPipe() to + * wait for a connection. + * + * So listen() is a no-op, and accept() really creates the pipe handle. + * + * Also, connect() must create a pipe handle with CreateFile() and + * wait for a server instance with WaitNamedPipe() + */ +int Win32PipeStream::listen(unsigned short port) +{ + // just save the port number for accept() + m_port = port; + return 0; +} + +SocketStream * Win32PipeStream::accept() +{ + char path[NAMED_PIPE_MAX+1]; + SocketStream* clientStream; + HANDLE pipe; + + make_pipe_name(path, sizeof(path), m_port); + + pipe = ::CreateNamedPipe( + path, // pipe name + PIPE_ACCESS_DUPLEX, // read-write access + PIPE_TYPE_BYTE | // byte-oriented writes + PIPE_READMODE_BYTE | // byte-oriented reads + PIPE_WAIT, // blocking operations + PIPE_UNLIMITED_INSTANCES, // no limit on clients + 4096, // input buffer size + 4096, // output buffer size + 0, // client time-out + NULL); // default security attributes + + if (pipe == INVALID_HANDLE_VALUE) { + ERR("%s: CreateNamedPipe failed %d\n", __FUNCTION__, (int)GetLastError()); + return NULL; + } + + // Stupid Win32 API design: If a client is already connected, then + // ConnectNamedPipe will return 0, and GetLastError() will return + // ERROR_PIPE_CONNECTED. This is not an error! It just means that the + // function didn't have to wait. + // + if (::ConnectNamedPipe(pipe, NULL) == 0 && GetLastError() != ERROR_PIPE_CONNECTED) { + ERR("%s: ConnectNamedPipe failed: %d\n", __FUNCTION__, (int)GetLastError()); + CloseHandle(pipe); + return NULL; + } + + clientStream = new Win32PipeStream(pipe, m_bufsize); + return clientStream; +} + +int Win32PipeStream::connect(unsigned short port) +{ + char path[NAMED_PIPE_MAX+1]; + HANDLE pipe; + int tries = 10; + + make_pipe_name(path, sizeof(path), port); + + /* We're going to loop in order to wait for the pipe server to + * be setup properly. + */ + for (; tries > 0; tries--) { + pipe = ::CreateFile( + path, // pipe name + GENERIC_READ | GENERIC_WRITE, // read & write + 0, // no sharing + NULL, // default security attrs + OPEN_EXISTING, // open existing pipe + 0, // default attributes + NULL); // no template file + + /* If we have a valid pipe handle, break from the loop */ + if (pipe != INVALID_HANDLE_VALUE) { + break; + } + + /* We can get here if the pipe is busy, i.e. if the server hasn't + * create a new pipe instance to service our request. In which case + * GetLastError() will return ERROR_PIPE_BUSY. + * + * If so, then use WaitNamedPipe() to wait for a decent time + * to try again. + */ + if (GetLastError() != ERROR_PIPE_BUSY) { + /* Not ERROR_PIPE_BUSY */ + ERR("%s: CreateFile failed: %d\n", __FUNCTION__, (int)GetLastError()); + errno = EINVAL; + return -1; + } + + /* Wait for 5 seconds */ + if ( !WaitNamedPipe(path, 5000) ) { + ERR("%s: WaitNamedPipe failed: %d\n", __FUNCTION__, (int)GetLastError()); + errno = EINVAL; + return -1; + } + } + + m_pipe = pipe; + return 0; +} + +/* Special buffer methods, since we can't use socket functions here */ + +int Win32PipeStream::commitBuffer(size_t size) +{ + if (m_pipe == INVALID_HANDLE_VALUE) + return -1; + + size_t res = size; + int retval = 0; + + while (res > 0) { + DWORD written; + if (! ::WriteFile(m_pipe, (const char *)m_buf + (size - res), res, &written, NULL)) { + retval = -1; + ERR("%s: failed: %d\n", __FUNCTION__, (int)GetLastError()); + break; + } + res -= written; + } + return retval; +} + +const unsigned char *Win32PipeStream::readFully(void *buf, size_t len) +{ + const unsigned char* ret = NULL; + + if (m_pipe == INVALID_HANDLE_VALUE) + return NULL; + + if (!buf) { + return NULL; // do not allow NULL buf in that implementation + } + + size_t res = len; + while (res > 0) { + DWORD readcount = 0; + if (! ::ReadFile(m_pipe, (char *)buf + (len - res), res, &readcount, NULL) || readcount == 0) { + errno = (int)GetLastError(); + return NULL; + } + res -= readcount; + } + return (const unsigned char *)buf; +} + +const unsigned char *Win32PipeStream::read( void *buf, size_t *inout_len) +{ + size_t len = *inout_len; + DWORD readcount; + + if (m_pipe == INVALID_HANDLE_VALUE) + return NULL; + + if (!buf) { + return NULL; // do not allow NULL buf in that implementation + } + + if (!::ReadFile(m_pipe, (char *)buf, len, &readcount, NULL)) { + errno = (int)GetLastError(); + return NULL; + } + + *inout_len = (size_t)readcount; + return (const unsigned char *)buf; +} diff --git a/emulator/opengl/shared/OpenglCodecCommon/Win32PipeStream.h b/emulator/opengl/shared/OpenglCodecCommon/Win32PipeStream.h new file mode 100644 index 0000000..4114545 --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/Win32PipeStream.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 __WIN32_PIPE_STREAM_H +#define __WIN32_PIPE_STREAM_H + +#include "SocketStream.h" +#include <windows.h> + +class Win32PipeStream : public SocketStream { +public: + explicit Win32PipeStream(size_t bufsize = 10000); + virtual ~Win32PipeStream(); + virtual int listen(unsigned short port); + virtual SocketStream *accept(); + virtual int connect(unsigned short port); + + virtual int commitBuffer(size_t size); + virtual const unsigned char *readFully(void *buf, size_t len); + virtual const unsigned char *read(void *buf, size_t *inout_len); + +private: + Win32PipeStream(HANDLE pipe, size_t bufSize); + HANDLE m_pipe; + int m_port; +}; + + +#endif diff --git a/emulator/opengl/shared/OpenglCodecCommon/codec_defs.h b/emulator/opengl/shared/OpenglCodecCommon/codec_defs.h new file mode 100644 index 0000000..f19f514 --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/codec_defs.h @@ -0,0 +1,23 @@ +/* +* 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 _CODEC_DEFS_H +#define _CODEC_DEFS_H + +#define CODEC_SERVER_PORT 22468 + +#define CODEC_MAX_VERTEX_ATTRIBUTES 64 + +#endif diff --git a/emulator/opengl/shared/OpenglCodecCommon/glUtils.cpp b/emulator/opengl/shared/OpenglCodecCommon/glUtils.cpp new file mode 100644 index 0000000..4b7fc89 --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/glUtils.cpp @@ -0,0 +1,471 @@ +/* +* 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 "glUtils.h" +#include <string.h> +#include "ErrorLog.h" +#include <IOStream.h> + +size_t glSizeof(GLenum type) +{ + size_t retval = 0; + switch(type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + retval = 1; + break; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + case GL_HALF_FLOAT_OES: + retval = 2; + break; + case GL_INT: + case GL_FLOAT: + case GL_FIXED: + case GL_BOOL: + retval = 4; + break; +#ifdef GL_DOUBLE + case GL_DOUBLE: + retval = 8; + break; +#endif + case GL_FLOAT_VEC2: + case GL_INT_VEC2: + case GL_BOOL_VEC2: + retval = 8; + break; + case GL_INT_VEC3: + case GL_BOOL_VEC3: + case GL_FLOAT_VEC3: + retval = 12; + break; + case GL_FLOAT_VEC4: + case GL_BOOL_VEC4: + case GL_INT_VEC4: + case GL_FLOAT_MAT2: + retval = 16; + break; + case GL_FLOAT_MAT3: + retval = 36; + break; + case GL_FLOAT_MAT4: + retval = 64; + break; + case GL_SAMPLER_2D: + case GL_SAMPLER_CUBE: + retval = 4; + break; + default: + ERR("**** ERROR unknown type 0x%x (%s,%d)\n", type, __FUNCTION__,__LINE__); + } + return retval; + +} + +size_t glUtilsParamSize(GLenum param) +{ + size_t s = 0; + + switch(param) + { + case GL_DEPTH_TEST: + case GL_DEPTH_FUNC: + case GL_DEPTH_BITS: + case GL_MAX_CLIP_PLANES: + case GL_GREEN_BITS: + case GL_MAX_MODELVIEW_STACK_DEPTH: + case GL_MAX_PROJECTION_STACK_DEPTH: + case GL_MAX_TEXTURE_STACK_DEPTH: + case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES: + case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES: + case GL_NUM_COMPRESSED_TEXTURE_FORMATS: + 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_ALPHA_TEST: + case GL_BLEND_DST: + case GL_BLEND_SRC: + case GL_BLEND: + case GL_LOGIC_OP_MODE: + case GL_SCISSOR_TEST: + case GL_MAX_TEXTURE_UNITS: + case GL_ACTIVE_TEXTURE: + case GL_ALPHA_BITS: + case GL_ARRAY_BUFFER_BINDING: + case GL_BLUE_BITS: + case GL_CLIENT_ACTIVE_TEXTURE: + case GL_CLIP_PLANE0: + case GL_CLIP_PLANE1: + case GL_CLIP_PLANE2: + case GL_CLIP_PLANE3: + case GL_CLIP_PLANE4: + case GL_CLIP_PLANE5: + case GL_COLOR_ARRAY: + case GL_COLOR_ARRAY_BUFFER_BINDING: + case GL_COLOR_ARRAY_SIZE: + case GL_COLOR_ARRAY_STRIDE: + case GL_COLOR_ARRAY_TYPE: + case GL_COLOR_LOGIC_OP: + case GL_COLOR_MATERIAL: + case GL_PACK_ALIGNMENT: + case GL_PERSPECTIVE_CORRECTION_HINT: + case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES: + case GL_POINT_SIZE_ARRAY_STRIDE_OES: + case GL_POINT_SIZE_ARRAY_TYPE_OES: + case GL_POINT_SMOOTH: + case GL_POINT_SMOOTH_HINT: + case GL_POINT_SPRITE_OES: + case GL_COORD_REPLACE_OES: + case GL_COMBINE_ALPHA: + case GL_SRC0_RGB: + case GL_SRC1_RGB: + case GL_SRC2_RGB: + case GL_OPERAND0_RGB: + case GL_OPERAND1_RGB: + case GL_OPERAND2_RGB: + case GL_SRC0_ALPHA: + case GL_SRC1_ALPHA: + case GL_SRC2_ALPHA: + case GL_OPERAND0_ALPHA: + case GL_OPERAND1_ALPHA: + case GL_OPERAND2_ALPHA: + case GL_RGB_SCALE: + case GL_ALPHA_SCALE: + case GL_COMBINE_RGB: + case GL_POLYGON_OFFSET_FACTOR: + case GL_POLYGON_OFFSET_FILL: + case GL_POLYGON_OFFSET_UNITS: + case GL_RED_BITS: + case GL_RESCALE_NORMAL: + case GL_SAMPLE_ALPHA_TO_COVERAGE: + case GL_SAMPLE_ALPHA_TO_ONE: + case GL_SAMPLE_BUFFERS: + case GL_SAMPLE_COVERAGE: + case GL_SAMPLE_COVERAGE_INVERT: + case GL_SAMPLE_COVERAGE_VALUE: + case GL_SAMPLES: + case GL_STENCIL_BITS: + case GL_STENCIL_CLEAR_VALUE: + case GL_STENCIL_FUNC: + case GL_STENCIL_TEST: + case GL_STENCIL_VALUE_MASK: + case GL_STENCIL_BACK_FUNC: + case GL_STENCIL_BACK_VALUE_MASK: + case GL_STENCIL_BACK_REF: + case GL_STENCIL_BACK_FAIL: + case GL_STENCIL_BACK_PASS_DEPTH_FAIL: + case GL_STENCIL_BACK_PASS_DEPTH_PASS: + case GL_STENCIL_BACK_WRITEMASK: + case GL_TEXTURE_2D: + case GL_TEXTURE_BINDING_2D: + case GL_TEXTURE_BINDING_CUBE_MAP: + case GL_TEXTURE_BINDING_EXTERNAL_OES: + case GL_TEXTURE_COORD_ARRAY: + 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: + case GL_UNPACK_ALIGNMENT: + case GL_VERTEX_ARRAY: + case GL_VERTEX_ARRAY_BUFFER_BINDING: + case GL_VERTEX_ARRAY_SIZE: + case GL_VERTEX_ARRAY_STRIDE: + case GL_VERTEX_ARRAY_TYPE: + case GL_SPOT_CUTOFF: + case GL_TEXTURE_MIN_FILTER: + case GL_TEXTURE_MAG_FILTER: + case GL_TEXTURE_WRAP_S: + case GL_TEXTURE_WRAP_T: + case GL_GENERATE_MIPMAP: + case GL_GENERATE_MIPMAP_HINT: + case GL_RENDERBUFFER_WIDTH_OES: + case GL_RENDERBUFFER_HEIGHT_OES: + case GL_RENDERBUFFER_INTERNAL_FORMAT_OES: + case GL_RENDERBUFFER_RED_SIZE_OES: + case GL_RENDERBUFFER_GREEN_SIZE_OES: + case GL_RENDERBUFFER_BLUE_SIZE_OES: + case GL_RENDERBUFFER_ALPHA_SIZE_OES: + case GL_RENDERBUFFER_DEPTH_SIZE_OES: + case GL_RENDERBUFFER_STENCIL_SIZE_OES: + case GL_RENDERBUFFER_BINDING: + case GL_FRAMEBUFFER_BINDING: + case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_OES: + case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_OES: + case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_OES: + case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_OES: + case GL_FENCE_STATUS_NV: + case GL_FENCE_CONDITION_NV: + case GL_TEXTURE_WIDTH_QCOM: + case GL_TEXTURE_HEIGHT_QCOM: + case GL_TEXTURE_DEPTH_QCOM: + case GL_TEXTURE_INTERNAL_FORMAT_QCOM: + case GL_TEXTURE_FORMAT_QCOM: + case GL_TEXTURE_TYPE_QCOM: + case GL_TEXTURE_IMAGE_VALID_QCOM: + case GL_TEXTURE_NUM_LEVELS_QCOM: + case GL_TEXTURE_TARGET_QCOM: + case GL_TEXTURE_OBJECT_VALID_QCOM: + case GL_BLEND_EQUATION_RGB_OES: + case GL_BLEND_EQUATION_ALPHA_OES: + case GL_BLEND_DST_RGB_OES: + case GL_BLEND_SRC_RGB_OES: + case GL_BLEND_DST_ALPHA_OES: + case GL_BLEND_SRC_ALPHA_OES: + case GL_MAX_LIGHTS: + case GL_SHADER_TYPE: + case GL_DELETE_STATUS: + case GL_COMPILE_STATUS: + case GL_INFO_LOG_LENGTH: + case GL_SHADER_SOURCE_LENGTH: + case GL_CURRENT_PROGRAM: + case GL_LINK_STATUS: + case GL_VALIDATE_STATUS: + case GL_ATTACHED_SHADERS: + case GL_ACTIVE_UNIFORMS: + case GL_ACTIVE_ATTRIBUTES: + case GL_SUBPIXEL_BITS: + case GL_MAX_CUBE_MAP_TEXTURE_SIZE: + case GL_NUM_SHADER_BINARY_FORMATS: + case GL_SHADER_COMPILER: + case GL_MAX_VERTEX_ATTRIBS: + case GL_MAX_VERTEX_UNIFORM_VECTORS: + case GL_MAX_VARYING_VECTORS: + case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: + case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: + case GL_MAX_FRAGMENT_UNIFORM_VECTORS: + case GL_MAX_RENDERBUFFER_SIZE: + case GL_MAX_TEXTURE_IMAGE_UNITS: + case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES: + case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: + case GL_LINE_WIDTH: + 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_VERTEX_ATTRIB: + 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: + case GL_COLOR_CLEAR_VALUE: + case GL_COLOR_WRITEMASK: + case GL_AMBIENT_AND_DIFFUSE: + case GL_BLEND_COLOR: + s = 4; + break; + case GL_MODELVIEW_MATRIX: + case GL_PROJECTION_MATRIX: + case GL_TEXTURE_MATRIX: + s = 16; + break; + default: + ERR("glUtilsParamSize: unknow param 0x%08x\n", param); + s = 1; // assume 1 + } + return s; +} + +void glUtilsPackPointerData(unsigned char *dst, unsigned char *src, + int size, GLenum type, unsigned int stride, + unsigned int datalen) +{ + unsigned int vsize = size * glSizeof(type); + if (stride == 0) stride = vsize; + + if (stride == vsize) { + memcpy(dst, src, datalen); + } else { + for (unsigned int i = 0; i < datalen; i += vsize) { + memcpy(dst, src, vsize); + dst += vsize; + src += stride; + } + } +} + +void glUtilsWritePackPointerData(void* _stream, unsigned char *src, + int size, GLenum type, unsigned int stride, + unsigned int datalen) +{ + IOStream* stream = reinterpret_cast<IOStream*>(_stream); + + unsigned int vsize = size * glSizeof(type); + if (stride == 0) stride = vsize; + + if (stride == vsize) { + stream->writeFully(src, datalen); + } else { + for (unsigned int i = 0; i < datalen; i += vsize) { + stream->writeFully(src, (size_t)vsize); + src += stride; + } + } +} + +int glUtilsPixelBitSize(GLenum format, GLenum type) +{ + int components = 0; + int componentsize = 0; + int pixelsize = 0; + switch(type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + componentsize = 8; + break; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + 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_RGB565_OES: + case GL_RGB5_A1_OES: + case GL_RGBA4_OES: + pixelsize = 16; + break; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + case GL_FIXED: + case GL_UNSIGNED_INT_24_8_OES: + pixelsize = 32; + break; + default: + ERR("glUtilsPixelBitSize: unknown pixel type - assuming pixel data 0\n"); + componentsize = 0; + } + + if (pixelsize == 0) { + switch(format) { +#if 0 + case GL_RED: + case GL_GREEN: + case GL_BLUE: +#endif + case GL_ALPHA: + case GL_LUMINANCE: + case GL_DEPTH_COMPONENT: + case GL_DEPTH_STENCIL_OES: + components = 1; + break; + case GL_LUMINANCE_ALPHA: + components = 2; + break; + case GL_RGB: +#if 0 + case GL_BGR: +#endif + components = 3; + break; + case GL_RGBA: + case GL_BGRA_EXT: + components = 4; + break; + default: + ERR("glUtilsPixelBitSize: unknown pixel format...\n"); + components = 0; + } + pixelsize = components * componentsize; + } + + return pixelsize; +} + +// pack a list of strings into one. +void glUtilsPackStrings(char *ptr, char **strings, GLint *length, GLsizei count) +{ + char *p = ptr; + *p = '\0'; + for (int i = 0; i < count; i++) { + int l=0; + if (strings[i]!=NULL) { + if (length == NULL || length[i] < 0) { + l = strlen(strings[i]); + strcat(p, strings[i]); + } else { + l = length[i]; + strncat(p, strings[i], l); + } + } + p += l; + } +} + +// claculate the length of a list of strings +int glUtilsCalcShaderSourceLen( char **strings, GLint *length, GLsizei count) +{ + int len = 0; + for (int i = 0; i < count; i++) { + int l; + if (length == NULL || length[i] < 0) { + l = strings[i]!=NULL ? strlen(strings[i]) : 0; + } else { + l = length[i]; + } + len += l; + } + return len; + +} diff --git a/emulator/opengl/shared/OpenglCodecCommon/glUtils.h b/emulator/opengl/shared/OpenglCodecCommon/glUtils.h new file mode 100644 index 0000000..f8857f1 --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/glUtils.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 __GL_UTILS_H__ +#define __GL_UTILS_H__ + +#include <stdio.h> +#include <stdlib.h> + +#ifdef GL_API + #undef GL_API +#endif +#define GL_API + +#ifdef GL_APIENTRY + #undef GL_APIENTRY +#endif + +#ifdef GL_APIENTRYP + #undef GL_APIENTRYP +#endif +#define GL_APIENTRYP + +#ifndef ANDROID +#define GL_APIENTRY +#endif + +#include <GLES/gl.h> +#include <GLES/glext.h> +#include <GLES2/gl2.h> +#include <GLES2/gl2ext.h> + +#ifdef __cplusplus +extern "C" { +#endif + + size_t glSizeof(GLenum type); + size_t glUtilsParamSize(GLenum param); + void glUtilsPackPointerData(unsigned char *dst, unsigned char *str, + int size, GLenum type, unsigned int stride, + unsigned int datalen); + void glUtilsWritePackPointerData(void* stream, unsigned char *src, + int size, GLenum type, unsigned int stride, + unsigned int datalen); + int glUtilsPixelBitSize(GLenum format, GLenum type); + void glUtilsPackStrings(char *ptr, char **strings, GLint *length, GLsizei count); + int glUtilsCalcShaderSourceLen(char **strings, GLint *length, GLsizei count); +#ifdef __cplusplus +}; +#endif + +namespace GLUtils { + + template <class T> void minmax(T *indices, int count, int *min, int *max) { + *min = -1; + *max = -1; + T *ptr = indices; + for (int i = 0; i < count; i++) { + if (*min == -1 || *ptr < *min) *min = *ptr; + if (*max == -1 || *ptr > *max) *max = *ptr; + ptr++; + } + } + + template <class T> void shiftIndices(T *indices, int count, int offset) { + T *ptr = indices; + for (int i = 0; i < count; i++) { + *ptr += offset; + ptr++; + } + } + + + template <class T> void shiftIndices(T *src, T *dst, int count, int offset) + { + for (int i = 0; i < count; i++) { + *dst = *src + offset; + dst++; + src++; + } + } +}; // namespace GLUtils +#endif diff --git a/emulator/opengl/shared/OpenglCodecCommon/gl_base_types.h b/emulator/opengl/shared/OpenglCodecCommon/gl_base_types.h new file mode 100644 index 0000000..d7bdef8 --- /dev/null +++ b/emulator/opengl/shared/OpenglCodecCommon/gl_base_types.h @@ -0,0 +1,62 @@ +/* +* 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_BASE_TYPES__H +#define __GL_BASE_TYPES__H + +#include <KHR/khrplatform.h> + +#ifndef gl_APIENTRY +#define gl_APIENTRY KHRONOS_APIENTRY +#endif + +#ifndef gl2_APIENTRY +#define gl2_APIENTRY KHRONOS_APIENTRY +#endif + +typedef void GLvoid; +typedef unsigned int GLenum; +typedef unsigned char GLboolean; +typedef unsigned int GLbitfield; +typedef char GLchar; +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; +typedef char *GLstr; +/* JR XXX Treating this as an in handle - is this correct? */ +typedef void * GLeglImageOES; + +/* ErrorCode */ +#ifndef GL_INVALID_ENUM +#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 +#endif + +#endif diff --git a/emulator/opengl/shared/OpenglOsUtils/Android.mk b/emulator/opengl/shared/OpenglOsUtils/Android.mk new file mode 100644 index 0000000..82391cd --- /dev/null +++ b/emulator/opengl/shared/OpenglOsUtils/Android.mk @@ -0,0 +1,57 @@ +# This build script corresponds to a small library containing +# OS-specific support functions for: +# - thread-local storage +# - dynamic library loading +# - child process creation and wait (probably not needed in guest) +# +LOCAL_PATH := $(call my-dir) + +### Guest library ############################################## +$(call emugl-begin-static-library,libOpenglOsUtils) + + $(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) + $(call emugl-export,LDLIBS,-ldl) + + LOCAL_SRC_FILES := \ + osProcessUnix.cpp \ + osThreadUnix.cpp \ + osDynLibrary.cpp + +$(call emugl-end-module) + + +### Host library ############################################## + +host_common_SRC_FILES := osDynLibrary.cpp +host_common_LDLIBS := + +ifeq ($(HOST_OS),windows) + host_common_SRC_FILES += \ + osProcessWin.cpp \ + osThreadWin.cpp + host_common_LDLIBS += -lws2_32 -lpsapi +else + host_common_SRC_FILES += \ + osProcessUnix.cpp \ + osThreadUnix.cpp + host_common_LDLIBS += -ldl +endif + +ifeq ($(HOST_OS),linux) + host_common_LDLIBS += -lpthread -lrt +endif + +### 32-bit host library #### +$(call emugl-begin-host-static-library,libOpenglOsUtils) + $(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) + LOCAL_SRC_FILES = $(host_common_SRC_FILES) + $(call emugl-export,LDLIBS,$(host_common_LDLIBS)) +$(call emugl-end-module) + +### 64-bit host library #### +$(call emugl-begin-host-static-library,lib64OpenglOsUtils) + $(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) + LOCAL_SRC_FILES = $(host_common_SRC_FILES) + $(call emugl-export,LDLIBS,$(host_common_LDLIBS)) + $(call emugl-export,CFLAGS,-m64) +$(call emugl-end-module) diff --git a/emulator/opengl/shared/OpenglOsUtils/osDynLibrary.cpp b/emulator/opengl/shared/OpenglOsUtils/osDynLibrary.cpp new file mode 100644 index 0000000..e8e6ab7 --- /dev/null +++ b/emulator/opengl/shared/OpenglOsUtils/osDynLibrary.cpp @@ -0,0 +1,79 @@ +/* +* 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 "osDynLibrary.h" + +#ifndef _WIN32 +#include <dlfcn.h> +#endif +#include <stdio.h> + +namespace osUtils { + +dynLibrary *dynLibrary::open(const char *p_libName) +{ + dynLibrary *lib = new dynLibrary(); + if (!lib) { + return NULL; + } + +#ifdef _WIN32 + lib->m_lib = LoadLibrary(p_libName); +#else // !WIN32 + lib->m_lib = dlopen(p_libName, RTLD_NOW); +#endif + + if (lib->m_lib == NULL) { + printf("Failed to load %s\n", p_libName); +#ifndef _WIN32 + printf("error %s\n", dlerror()); //only on linux +#endif + delete lib; + return NULL; + } + + return lib; +} + +dynLibrary::dynLibrary() : + m_lib(NULL) +{ +} + +dynLibrary::~dynLibrary() +{ + if (NULL != m_lib) { +#ifdef _WIN32 + FreeLibrary(m_lib); +#else // !WIN32 + dlclose(m_lib); +#endif + } +} + +dynFuncPtr dynLibrary::findSymbol(const char *p_symName) +{ + if (NULL == m_lib) { + return NULL; + } + +#ifdef _WIN32 + return (dynFuncPtr) GetProcAddress(m_lib, p_symName); +#else // !WIN32 + return (dynFuncPtr) dlsym(m_lib, p_symName); +#endif +} + +} // of namespace osUtils diff --git a/emulator/opengl/shared/OpenglOsUtils/osDynLibrary.h b/emulator/opengl/shared/OpenglOsUtils/osDynLibrary.h new file mode 100644 index 0000000..c83fbf3 --- /dev/null +++ b/emulator/opengl/shared/OpenglOsUtils/osDynLibrary.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 _OSUTILS_DYN_LIBRARY_H +#define _OSUTILS_DYN_LIBRARY_H + +#ifdef _WIN32 +#include <windows.h> +#endif + +namespace osUtils { + +typedef void (*dynFuncPtr)(void); + +class dynLibrary +{ +public: + static dynLibrary *open(const char *p_libName); + ~dynLibrary(); + + dynFuncPtr findSymbol(const char *p_symName); + +private: + dynLibrary(); + +private: +#ifdef _WIN32 + HMODULE m_lib; +#else + void *m_lib; +#endif +}; + +} // of namespace osUtils + + + +// Macro to compose emugl shared library name under various OS and bitness +// eg. +// on x86_64, EMUGL_LIBNAME("foo") --> "lib64foo.so" + +#ifdef _WIN32 +# define DLL_EXTENSION "" // _WIN32 LoadLibrary only accept name w/o .dll extension +#elif defined(__APPLE__) +# define DLL_EXTENSION ".dylib" +#else +# define DLL_EXTENSION ".so" +#endif + +#if defined(__x86_64__) +# define EMUGL_LIBNAME(name) "lib64" name DLL_EXTENSION +#elif defined(__i386__) +# define EMUGL_LIBNAME(name) "lib" name DLL_EXTENSION +#else +/* This header is included by target w/o using EMUGL_LIBNAME(). Don't #error, leave it undefined */ +#endif + + +#endif diff --git a/emulator/opengl/shared/OpenglOsUtils/osProcess.h b/emulator/opengl/shared/OpenglOsUtils/osProcess.h new file mode 100644 index 0000000..82b31b3 --- /dev/null +++ b/emulator/opengl/shared/OpenglOsUtils/osProcess.h @@ -0,0 +1,62 @@ +/* +* 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 _OSUTILS_PROCESS_H +#define _OSUTILS_PROCESS_H + +#ifdef _WIN32 +#include <windows.h> +#endif + +namespace osUtils { + +class childProcess +{ +public: + static childProcess *create(const char *p_cmdLine, const char *p_startdir); + ~childProcess(); + + int getPID() + { +#ifdef _WIN32 + return m_proc.dwProcessId; +#else + return(m_pid); +#endif + } + + int tryWait(bool& isAlive); + bool wait(int *exitStatus); + +private: + childProcess() {}; + +private: +#ifdef _WIN32 + PROCESS_INFORMATION m_proc; +#else + int m_pid; +#endif +}; + +int ProcessGetPID(); +int ProcessGetTID(); +bool ProcessGetName(char *p_outName, int p_outNameLen); +int KillProcess(int pid, bool wait); +bool isProcessRunning(int pid); + +} // of namespace osUtils + +#endif diff --git a/emulator/opengl/shared/OpenglOsUtils/osProcessUnix.cpp b/emulator/opengl/shared/OpenglOsUtils/osProcessUnix.cpp new file mode 100644 index 0000000..c97ff58 --- /dev/null +++ b/emulator/opengl/shared/OpenglOsUtils/osProcessUnix.cpp @@ -0,0 +1,210 @@ +/* +* 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 "osProcess.h" +#include <stdio.h> +#include <stdlib.h> +#include <sys/wait.h> +#include <sys/types.h> +#include <poll.h> +#include <pthread.h> +#include <string.h> +#include <pwd.h> +#include <paths.h> +#include <errno.h> +#include <signal.h> +#include <unistd.h> +#include <assert.h> + +namespace osUtils { + +// +// buildArgList converts a command line into null terminated argument list. +// to be used with execv or execvp. +// each argument is seperated by space or tab, to specify multiple words +// at the same argument place it inside single-quoted or double-quoted string. +// +static char **buildArgList(const char *command) +{ + char **argv = NULL; + int argvSize = 0; + int nArgs = 0; + char *tmpcmd = strdup(command); + char *t = tmpcmd; + char *strStart = NULL; + int i = 0; + + #define ADD_ARG \ + { \ + nArgs++; \ + if (!argv) { \ + argvSize = 12; \ + argv = (char **)malloc(argvSize * sizeof(char *)); \ + } \ + else if (nArgs > argvSize) { \ + argvSize += 12; \ + argv = (char **)realloc(argv, argvSize * sizeof(char *)); \ + } \ + argv[nArgs-1] = t; \ + t = NULL; \ + } + + while( tmpcmd[i] != '\0' ) { + if (!strStart) { + if (tmpcmd[i] == '"' || tmpcmd[i] == '\'') { + strStart = &tmpcmd[i]; + } + else if (tmpcmd[i] == ' ' || tmpcmd[i] == '\t') { + tmpcmd[i] = '\0'; + if (t) ADD_ARG; + } + else if (!t) { + t = &tmpcmd[i]; + } + } + else if (tmpcmd[i] == *strStart) { + t = strStart; + strStart = NULL; + } + + i++; + } + if (t) { + ADD_ARG; + } + if (nArgs > 0) { + ADD_ARG; // for NULL terminating list + } + + return argv; +} + +static pid_t start_process(const char *command,const char *startDir) +{ + pid_t pid; + + pid = fork(); + + if (pid < 0) { + return pid; + } + else if (pid == 0) { + // + // Close all opened file descriptors + // + for (int i=3; i<256; i++) { + close(i); + } + + if (startDir) { + chdir(startDir); + } + + char **argv = buildArgList(command); + if (!argv) { + return -1; + } + execvp(argv[0], argv); + + perror("execl"); + exit(-101); + } + + return pid; +} + +childProcess * +childProcess::create(const char *p_cmdLine, const char *p_startdir) +{ + childProcess *child = new childProcess(); + if (!child) { + return NULL; + } + + child->m_pid = start_process(p_cmdLine, p_startdir); + if (child->m_pid < 0) { + delete child; + return NULL; + } + + return child; +} + +childProcess::~childProcess() +{ +} + +bool +childProcess::wait(int *exitStatus) +{ + int ret=0; + if (m_pid>0) { + pid_t pid = waitpid(m_pid,&ret,0); + if (pid != -1) { + m_pid=-1; + if (exitStatus) { + *exitStatus = ret; + } + return true; + } + } + return false; +} + +int +childProcess::tryWait(bool &isAlive) +{ + int ret=0; + isAlive = false; + if (m_pid>0) { + pid_t pid = waitpid(m_pid,&ret,WNOHANG); + if (pid == 0) { + isAlive = true; + } + } + + return ((char)WEXITSTATUS(ret)); +} + +int ProcessGetPID() +{ + return getpid(); +} + +int KillProcess(int pid, bool wait) +{ + if (pid<1) { + return false; + } + + if (0!=kill(pid,SIGTERM)) { + return false; + } + + if (wait) { + if (waitpid(pid,NULL,0)<0) { + return false; + } + } + + return true; +} + +bool isProcessRunning(int pid) +{ + return (kill(pid,0) == 0); +} + +} // of namespace osUtils diff --git a/emulator/opengl/shared/OpenglOsUtils/osProcessWin.cpp b/emulator/opengl/shared/OpenglOsUtils/osProcessWin.cpp new file mode 100644 index 0000000..6ff0fdf --- /dev/null +++ b/emulator/opengl/shared/OpenglOsUtils/osProcessWin.cpp @@ -0,0 +1,171 @@ +/* +* 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 "osProcess.h" +#include <windows.h> +#include <string> +#include <stdlib.h> +#include <psapi.h> + +namespace osUtils { + +childProcess * +childProcess::create(const char *p_cmdLine, const char *p_startdir) +{ + childProcess *child = new childProcess(); + if (!child) { + return NULL; + } + + STARTUPINFOA si; + ZeroMemory(&si, sizeof(si)); + + ZeroMemory(&child->m_proc, sizeof(child->m_proc)); + BOOL ret = CreateProcessA( + NULL , + (LPSTR)p_cmdLine, + NULL, + NULL, + FALSE, + CREATE_DEFAULT_ERROR_MODE, + NULL, + (p_startdir != NULL ? p_startdir : ".\\"), + &si, + &child->m_proc); + if (ret == 0) { + delete child; + return NULL; + } + + // close the thread handle we do not need it, + // keep the process handle for wait/trywait operations, will + // be closed on destruction + CloseHandle(child->m_proc.hThread); + + return child; +} + +childProcess::~childProcess() +{ + if (m_proc.hProcess) { + CloseHandle(m_proc.hProcess); + } +} + +bool +childProcess::wait(int *exitStatus) +{ +DWORD _exitStatus; + + if (WaitForSingleObject(m_proc.hProcess, INFINITE) == WAIT_FAILED) { + return false; + } + + if (!GetExitCodeProcess(m_proc.hProcess, &_exitStatus)) + { + return false; + } + + if (exitStatus) { + *exitStatus = _exitStatus; + } + + return true; +} + +int +childProcess::tryWait(bool& isAlive) +{ + DWORD status = WaitForSingleObject(m_proc.hProcess, 0); + + if(status == WAIT_OBJECT_0) + { + // process has exited + isAlive = false; + GetExitCodeProcess(m_proc.hProcess, &status); + } + else if (status == WAIT_TIMEOUT) + { + isAlive = true; + status = 0; + } + + return status; + +} + +int ProcessGetPID() +{ + return GetCurrentProcessId(); +} + +int ProcessGetTID() +{ + return GetCurrentThreadId(); +} + +bool ProcessGetName(char *p_outName, int p_outNameLen) +{ + return 0 != GetModuleFileNameEx( GetCurrentProcess(), NULL, p_outName, p_outNameLen); +} + +int KillProcess(int pid, bool wait) +{ + DWORD exitStatus = 1; + HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid); + + if (NULL == hProc) { + return 0; + } + + // + // Terminate the process + // + TerminateProcess(hProc, 0x55); + + if (wait) { + // + // Wait for it to be terminated + // + if(WaitForSingleObject(hProc, INFINITE) == WAIT_FAILED) { + CloseHandle(hProc); + return 0; + } + + if (!GetExitCodeProcess(hProc, &exitStatus)) { + CloseHandle(hProc); + return 0; + } + } + + CloseHandle(hProc); + + return exitStatus; +} + +bool isProcessRunning(int pid) +{ + bool isRunning = false; + + HANDLE process = OpenProcess(SYNCHRONIZE, FALSE, pid); + if (NULL != process) { + DWORD ret = WaitForSingleObject(process, 0); + CloseHandle(process); + isRunning = (ret == WAIT_TIMEOUT); + } + return isRunning; +} + +} // of namespace osUtils diff --git a/emulator/opengl/shared/OpenglOsUtils/osThread.h b/emulator/opengl/shared/OpenglOsUtils/osThread.h new file mode 100644 index 0000000..970396d --- /dev/null +++ b/emulator/opengl/shared/OpenglOsUtils/osThread.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 _OSUTILS_THREAD_H +#define _OSUTILS_THREAD_H + +#ifdef _WIN32 +#include <windows.h> +#else // !WIN32 +#include <pthread.h> +#endif + +namespace osUtils { + +class Thread +{ +public: + Thread(); + virtual ~Thread(); + + virtual int Main() = 0; + + bool start(); + bool wait(int *exitStatus); + bool trywait(int *exitStatus); + +private: +#ifdef _WIN32 + static DWORD WINAPI thread_main(void *p_arg); +#else // !WIN32 + static void* thread_main(void *p_arg); +#endif + +private: +#ifdef _WIN32 + HANDLE m_thread; + DWORD m_threadId; +#else // !WIN32 + pthread_t m_thread; + int m_exitStatus; + pthread_mutex_t m_lock; +#endif + bool m_isRunning; +}; + +} // of namespace osUtils + +#endif diff --git a/emulator/opengl/shared/OpenglOsUtils/osThreadUnix.cpp b/emulator/opengl/shared/OpenglOsUtils/osThreadUnix.cpp new file mode 100644 index 0000000..d8879eb --- /dev/null +++ b/emulator/opengl/shared/OpenglOsUtils/osThreadUnix.cpp @@ -0,0 +1,94 @@ +/* +* 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 "osThread.h" + +namespace osUtils { + +Thread::Thread() : + m_thread((pthread_t)NULL), + m_exitStatus(0), + m_isRunning(false) +{ + pthread_mutex_init(&m_lock, NULL); +} + +Thread::~Thread() +{ + pthread_mutex_destroy(&m_lock); +} + +bool +Thread::start() +{ + pthread_mutex_lock(&m_lock); + m_isRunning = true; + int ret = pthread_create(&m_thread, NULL, Thread::thread_main, this); + if(ret) { + m_isRunning = false; + } + pthread_mutex_unlock(&m_lock); + return m_isRunning; +} + +bool +Thread::wait(int *exitStatus) +{ + if (!m_isRunning) { + return false; + } + + void *retval; + if (pthread_join(m_thread,&retval)) { + return false; + } + + long long int ret=(long long int)retval; + if (exitStatus) { + *exitStatus = (int)ret; + } + return true; +} + +bool +Thread::trywait(int *exitStatus) +{ + bool ret = false; + + pthread_mutex_lock(&m_lock); + if (!m_isRunning) { + *exitStatus = m_exitStatus; + ret = true; + } + pthread_mutex_unlock(&m_lock); + return ret; +} + +void * +Thread::thread_main(void *p_arg) +{ + Thread *self = (Thread *)p_arg; + int ret = self->Main(); + + pthread_mutex_lock(&self->m_lock); + self->m_isRunning = false; + self->m_exitStatus = ret; + pthread_mutex_unlock(&self->m_lock); + + return (void*)ret; +} + +} // of namespace osUtils + diff --git a/emulator/opengl/shared/OpenglOsUtils/osThreadWin.cpp b/emulator/opengl/shared/OpenglOsUtils/osThreadWin.cpp new file mode 100644 index 0000000..2d563f8 --- /dev/null +++ b/emulator/opengl/shared/OpenglOsUtils/osThreadWin.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 "osThread.h" + +namespace osUtils { + +Thread::Thread() : + m_thread(NULL), + m_threadId(0), + m_isRunning(false) +{ +} + +Thread::~Thread() +{ + if(m_thread) { + CloseHandle(m_thread); + } +} + +bool +Thread::start() +{ + m_isRunning = true; + m_thread = CreateThread(NULL, 0, &Thread::thread_main, this, 0, &m_threadId); + if(!m_thread) { + m_isRunning = false; + } + return m_isRunning; +} + +bool +Thread::wait(int *exitStatus) +{ + if (!m_isRunning) { + return false; + } + + if(WaitForSingleObject(m_thread, INFINITE) == WAIT_FAILED) { + return false; + } + + DWORD retval; + if (!GetExitCodeThread(m_thread,&retval)) { + return false; + } + + m_isRunning = 0; + + if (exitStatus) { + *exitStatus = retval; + } + return true; +} + +bool +Thread::trywait(int *exitStatus) +{ + if (!m_isRunning) { + return false; + } + + if(WaitForSingleObject(m_thread, 0) == WAIT_OBJECT_0) { + + DWORD retval; + if (!GetExitCodeThread(m_thread,&retval)) { + return true; + } + + if (exitStatus) { + *exitStatus = retval; + } + return true; + } + + return false; +} + +DWORD WINAPI +Thread::thread_main(void *p_arg) +{ + Thread *self = (Thread *)p_arg; + int ret = self->Main(); + self->m_isRunning = false; + return ret; +} + +} // of namespace osUtils diff --git a/emulator/opengl/system/GLESv1/Android.mk b/emulator/opengl/system/GLESv1/Android.mk new file mode 100644 index 0000000..97356b7 --- /dev/null +++ b/emulator/opengl/system/GLESv1/Android.mk @@ -0,0 +1,12 @@ +LOCAL_PATH := $(call my-dir) + +### GLESv1 implementation ########################################### +$(call emugl-begin-shared-library,libGLESv1_CM_emulation) +$(call emugl-import,libOpenglSystemCommon libGLESv1_enc lib_renderControl_enc) + +LOCAL_CFLAGS += -DLOG_TAG=\"GLES_emulation\" -DGL_GLEXT_PROTOTYPES + +LOCAL_SRC_FILES := gl.cpp +LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/egl + +$(call emugl-end-module) diff --git a/emulator/opengl/system/GLESv1/gl.cpp b/emulator/opengl/system/GLESv1/gl.cpp new file mode 100644 index 0000000..8ecb504 --- /dev/null +++ b/emulator/opengl/system/GLESv1/gl.cpp @@ -0,0 +1,146 @@ +/* +* 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 "EGLClientIface.h" +#include "HostConnection.h" +#include "GLEncoder.h" +#include "GLES/gl.h" +#include "GLES/glext.h" +#include "ErrorLog.h" +#include "gralloc_cb.h" +#include "ThreadInfo.h" + + +//XXX: fix this macro to get the context from fast tls path +#define GET_CONTEXT GLEncoder * ctx = getEGLThreadInfo()->hostConn->glEncoder(); + +#include "gl_entry.cpp" + +//The functions table +#include "gl_ftable.h" + +static EGLClient_eglInterface * s_egl = NULL; +static EGLClient_glesInterface * s_gl = NULL; + +#define DEFINE_AND_VALIDATE_HOST_CONNECTION(ret) \ + HostConnection *hostCon = HostConnection::get(); \ + if (!hostCon) { \ + ALOGE("egl: Failed to get host connection\n"); \ + return ret; \ + } \ + renderControl_encoder_context_t *rcEnc = hostCon->rcEncoder(); \ + if (!rcEnc) { \ + ALOGE("egl: Failed to get renderControl encoder context\n"); \ + return ret; \ + } + +//GL extensions +void glEGLImageTargetTexture2DOES(void * self, GLenum target, GLeglImageOES image) +{ + DBG("glEGLImageTargetTexture2DOES v1 target=%#x image=%p", target, image); + //TODO: check error - we don't have a way to set gl error + android_native_buffer_t* native_buffer = (android_native_buffer_t*)image; + + if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) { + return; + } + + if (native_buffer->common.version != sizeof(android_native_buffer_t)) { + return; + } + + GET_CONTEXT; + DEFINE_AND_VALIDATE_HOST_CONNECTION(); + + ctx->override2DTextureTarget(target); + rcEnc->rcBindTexture(rcEnc, + ((cb_handle_t *)(native_buffer->handle))->hostHandle); + ctx->restore2DTextureTarget(); + + return; +} + +void glEGLImageTargetRenderbufferStorageOES(void *self, GLenum target, GLeglImageOES image) +{ + DBG("glEGLImageTargetRenderbufferStorageOES v1 target=%#x image=%p", + target, image); + //TODO: check error - we don't have a way to set gl error + android_native_buffer_t* native_buffer = (android_native_buffer_t*)image; + + if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) { + return; + } + + if (native_buffer->common.version != sizeof(android_native_buffer_t)) { + return; + } + + DEFINE_AND_VALIDATE_HOST_CONNECTION(); + rcEnc->rcBindRenderbuffer(rcEnc, + ((cb_handle_t *)(native_buffer->handle))->hostHandle); + + return; +} + +void * getProcAddress(const char * procname) +{ + // search in GL function table + for (int i=0; i<gl_num_funcs; i++) { + if (!strcmp(gl_funcs_by_name[i].name, procname)) { + return gl_funcs_by_name[i].proc; + } + } + return NULL; +} + +void finish() +{ + glFinish(); +} + +const GLubyte *my_glGetString (void *self, GLenum name) +{ + if (s_egl) { + return (const GLubyte*)s_egl->getGLString(name); + } + return NULL; +} + +void init() +{ + GET_CONTEXT; + ctx->set_glEGLImageTargetTexture2DOES(glEGLImageTargetTexture2DOES); + ctx->set_glEGLImageTargetRenderbufferStorageOES(glEGLImageTargetRenderbufferStorageOES); + ctx->set_glGetString(my_glGetString); +} + +extern "C" { +EGLClient_glesInterface * init_emul_gles(EGLClient_eglInterface *eglIface) +{ + s_egl = eglIface; + + if (!s_gl) { + s_gl = new EGLClient_glesInterface(); + s_gl->getProcAddress = getProcAddress; + s_gl->finish = finish; + s_gl->init = init; + } + + return s_gl; +} +} //extern + + diff --git a/emulator/opengl/system/GLESv1_enc/Android.mk b/emulator/opengl/system/GLESv1_enc/Android.mk new file mode 100644 index 0000000..25c8c49 --- /dev/null +++ b/emulator/opengl/system/GLESv1_enc/Android.mk @@ -0,0 +1,18 @@ +LOCAL_PATH := $(call my-dir) + +### GLESv1_enc Encoder ########################################### +$(call emugl-begin-shared-library,libGLESv1_enc) + +LOCAL_CFLAGS += -DLOG_TAG=\"emuglGLESv1_enc\" + +LOCAL_SRC_FILES := \ + GLEncoder.cpp \ + GLEncoderUtils.cpp + +$(call emugl-gen-encoder,$(LOCAL_PATH),gl) + +$(call emugl-import,libOpenglCodecCommon) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) +$(call emugl-export,C_INCLUDES,$(intermediates)) + +$(call emugl-end-module) diff --git a/emulator/opengl/system/GLESv1_enc/GLEncoder.cpp b/emulator/opengl/system/GLESv1_enc/GLEncoder.cpp new file mode 100644 index 0000000..4414f24 --- /dev/null +++ b/emulator/opengl/system/GLESv1_enc/GLEncoder.cpp @@ -0,0 +1,989 @@ +/* +* 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 "GLEncoder.h" +#include "glUtils.h" +#include "FixedBuffer.h" +#include <cutils/log.h> +#include <assert.h> + +#ifndef MIN +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#endif + +static GLubyte *gVendorString= (GLubyte *) "Android"; +static GLubyte *gRendererString= (GLubyte *) "Android HW-GLES 1.0"; +static GLubyte *gVersionString= (GLubyte *) "OpenGL ES-CM 1.0"; +static GLubyte *gExtensionsString= (GLubyte *) ""; // no extensions at this point; + +#define SET_ERROR_IF(condition,err) if((condition)) { \ + ALOGE("%s:%s:%d GL error 0x%x\n", __FILE__, __FUNCTION__, __LINE__, err); \ + ctx->setError(err); \ + return; \ + } + + +#define RET_AND_SET_ERROR_IF(condition,err,ret) if((condition)) { \ + ALOGE("%s:%s:%d GL error 0x%x\n", __FILE__, __FUNCTION__, __LINE__, err); \ + ctx->setError(err); \ + return ret; \ + } + +GLenum GLEncoder::s_glGetError(void * self) +{ + GLEncoder *ctx = (GLEncoder *)self; + GLenum err = ctx->getError(); + if(err != GL_NO_ERROR) { + ctx->setError(GL_NO_ERROR); + return err; + } + + return ctx->m_glGetError_enc(self); + +} + +GLint * GLEncoder::getCompressedTextureFormats() +{ + if (m_compressedTextureFormats == NULL) { + this->glGetIntegerv(this, GL_NUM_COMPRESSED_TEXTURE_FORMATS, + &m_num_compressedTextureFormats); + if (m_num_compressedTextureFormats > 0) { + // get number of texture formats; + m_compressedTextureFormats = new GLint[m_num_compressedTextureFormats]; + this->glGetCompressedTextureFormats(this, m_num_compressedTextureFormats, m_compressedTextureFormats); + } + } + return m_compressedTextureFormats; +} + +void GLEncoder::s_glGetIntegerv(void *self, GLenum param, GLint *ptr) +{ + GLEncoder *ctx = (GLEncoder *)self; + assert(ctx->m_state != NULL); + GLClientState* state = ctx->m_state; + + switch (param) { + case GL_COMPRESSED_TEXTURE_FORMATS: { + GLint * compressedTextureFormats = ctx->getCompressedTextureFormats(); + if (ctx->m_num_compressedTextureFormats > 0 && + compressedTextureFormats != NULL) { + memcpy(ptr, compressedTextureFormats, + ctx->m_num_compressedTextureFormats * sizeof(GLint)); + } + break; + } + + case GL_MAX_TEXTURE_UNITS: + ctx->m_glGetIntegerv_enc(self, param, ptr); + *ptr = MIN(*ptr, GLClientState::MAX_TEXTURE_UNITS); + break; + + case GL_TEXTURE_BINDING_2D: + *ptr = state->getBoundTexture(GL_TEXTURE_2D); + break; + + case GL_TEXTURE_BINDING_EXTERNAL_OES: + *ptr = state->getBoundTexture(GL_TEXTURE_EXTERNAL_OES); + break; + + default: + if (!state->getClientStateParameter<GLint>(param,ptr)) { + ctx->m_glGetIntegerv_enc(self, param, ptr); + } + break; + } +} + +void GLEncoder::s_glGetFloatv(void *self, GLenum param, GLfloat *ptr) +{ + GLEncoder *ctx = (GLEncoder *)self; + assert(ctx->m_state != NULL); + GLClientState* state = ctx->m_state; + + switch (param) { + case GL_COMPRESSED_TEXTURE_FORMATS: { + GLint * compressedTextureFormats = ctx->getCompressedTextureFormats(); + if (ctx->m_num_compressedTextureFormats > 0 && + compressedTextureFormats != NULL) { + for (int i = 0; i < ctx->m_num_compressedTextureFormats; i++) { + ptr[i] = (GLfloat) compressedTextureFormats[i]; + } + } + break; + } + + case GL_MAX_TEXTURE_UNITS: + ctx->m_glGetFloatv_enc(self, param, ptr); + *ptr = MIN(*ptr, (GLfloat)GLClientState::MAX_TEXTURE_UNITS); + break; + + case GL_TEXTURE_BINDING_2D: + *ptr = (GLfloat)state->getBoundTexture(GL_TEXTURE_2D); + break; + + case GL_TEXTURE_BINDING_EXTERNAL_OES: + *ptr = (GLfloat)state->getBoundTexture(GL_TEXTURE_EXTERNAL_OES); + break; + + default: + if (!state->getClientStateParameter<GLfloat>(param,ptr)) { + ctx->m_glGetFloatv_enc(self, param, ptr); + } + break; + } +} + +void GLEncoder::s_glGetFixedv(void *self, GLenum param, GLfixed *ptr) +{ + GLEncoder *ctx = (GLEncoder *)self; + assert(ctx->m_state != NULL); + GLClientState* state = ctx->m_state; + + switch (param) { + case GL_COMPRESSED_TEXTURE_FORMATS: { + GLint * compressedTextureFormats = ctx->getCompressedTextureFormats(); + if (ctx->m_num_compressedTextureFormats > 0 && + compressedTextureFormats != NULL) { + for (int i = 0; i < ctx->m_num_compressedTextureFormats; i++) { + ptr[i] = compressedTextureFormats[i] << 16; + } + } + break; + } + + case GL_MAX_TEXTURE_UNITS: + ctx->m_glGetFixedv_enc(self, param, ptr); + *ptr = MIN(*ptr, GLClientState::MAX_TEXTURE_UNITS << 16); + break; + + case GL_TEXTURE_BINDING_2D: + *ptr = state->getBoundTexture(GL_TEXTURE_2D) << 16; + break; + + case GL_TEXTURE_BINDING_EXTERNAL_OES: + *ptr = state->getBoundTexture(GL_TEXTURE_EXTERNAL_OES) << 16; + break; + + default: + if (!state->getClientStateParameter<GLfixed>(param,ptr)) { + ctx->m_glGetFixedv_enc(self, param, ptr); + } + break; + } +} + +void GLEncoder::s_glGetBooleanv(void *self, GLenum param, GLboolean *ptr) +{ + GLEncoder *ctx = (GLEncoder *)self; + assert(ctx->m_state != NULL); + GLClientState* state = ctx->m_state; + + switch (param) { + case GL_COMPRESSED_TEXTURE_FORMATS: { + GLint* compressedTextureFormats = ctx->getCompressedTextureFormats(); + if (ctx->m_num_compressedTextureFormats > 0 && + compressedTextureFormats != NULL) { + for (int i = 0; i < ctx->m_num_compressedTextureFormats; i++) { + ptr[i] = compressedTextureFormats[i] != 0 ? GL_TRUE : GL_FALSE; + } + } + break; + } + + case GL_TEXTURE_BINDING_2D: + *ptr = state->getBoundTexture(GL_TEXTURE_2D) != 0 ? GL_TRUE : GL_FALSE; + break; + + case GL_TEXTURE_BINDING_EXTERNAL_OES: + *ptr = state->getBoundTexture(GL_TEXTURE_EXTERNAL_OES) != 0 + ? GL_TRUE : GL_FALSE; + break; + + default: + if (!state->getClientStateParameter<GLboolean>(param,ptr)) { + ctx->m_glGetBooleanv_enc(self, param, ptr); + } + break; + } +} + +void GLEncoder::s_glGetPointerv(void * self, GLenum param, GLvoid **params) +{ + GLEncoder * ctx = (GLEncoder *) self; + assert(ctx->m_state != NULL); + ctx->m_state->getClientStatePointer(param,params); +} + +void GLEncoder::s_glFlush(void *self) +{ + GLEncoder *ctx = (GLEncoder *)self; + ctx->m_glFlush_enc(self); + ctx->m_stream->flush(); +} + +const GLubyte *GLEncoder::s_glGetString(void *self, GLenum name) +{ + GLubyte *retval = (GLubyte *) ""; + switch(name) { + case GL_VENDOR: + retval = gVendorString; + break; + case GL_RENDERER: + retval = gRendererString; + break; + case GL_VERSION: + retval = gVersionString; + break; + case GL_EXTENSIONS: + retval = gExtensionsString; + break; + } + return retval; +} + +void GLEncoder::s_glPixelStorei(void *self, GLenum param, GLint value) +{ + GLEncoder *ctx = (GLEncoder *)self; + ctx->m_glPixelStorei_enc(ctx, param, value); + ALOG_ASSERT(ctx->m_state, "GLEncoder::s_glPixelStorei"); + ctx->m_state->setPixelStore(param, value); +} + +void GLEncoder::s_glVertexPointer(void *self, int size, GLenum type, GLsizei stride, const void *data) +{ + GLEncoder *ctx = (GLEncoder *)self; + assert(ctx->m_state != NULL); + ctx->m_state->setState(GLClientState::VERTEX_LOCATION, size, type, false, stride, data); +} + +void GLEncoder::s_glNormalPointer(void *self, GLenum type, GLsizei stride, const void *data) +{ + GLEncoder *ctx = (GLEncoder *)self; + assert(ctx->m_state != NULL); + ctx->m_state->setState(GLClientState::NORMAL_LOCATION, 3, type, false, stride, data); +} + +void GLEncoder::s_glColorPointer(void *self, int size, GLenum type, GLsizei stride, const void *data) +{ + GLEncoder *ctx = (GLEncoder *)self; + assert(ctx->m_state != NULL); + ctx->m_state->setState(GLClientState::COLOR_LOCATION, size, type, false, stride, data); +} + +void GLEncoder::s_glPointsizePointer(void *self, GLenum type, GLsizei stride, const void *data) +{ + GLEncoder *ctx = (GLEncoder *)self; + assert(ctx->m_state != NULL); + ctx->m_state->setState(GLClientState::POINTSIZE_LOCATION, 1, type, false, stride, data); +} + +void GLEncoder::s_glClientActiveTexture(void *self, GLenum texture) +{ + GLEncoder *ctx = (GLEncoder *)self; + assert(ctx->m_state != NULL); + ctx->m_state->setActiveTexture(texture - GL_TEXTURE0); +} + +void GLEncoder::s_glTexcoordPointer(void *self, int size, GLenum type, GLsizei stride, const void *data) +{ + GLEncoder *ctx = (GLEncoder *)self; + assert(ctx->m_state != NULL); + int loc = ctx->m_state->getLocation(GL_TEXTURE_COORD_ARRAY); + ctx->m_state->setState(loc, size, type, false, stride, data); +} + +void GLEncoder::s_glMatrixIndexPointerOES(void *self, int size, GLenum type, GLsizei stride, const void * data) +{ + GLEncoder *ctx = (GLEncoder *)self; + assert(ctx->m_state != NULL); + int loc = ctx->m_state->getLocation(GL_MATRIX_INDEX_ARRAY_OES); + ctx->m_state->setState(loc, size, type, false, stride, data); +} + +void GLEncoder::s_glWeightPointerOES(void * self, int size, GLenum type, GLsizei stride, const void * data) +{ + GLEncoder *ctx = (GLEncoder *)self; + assert(ctx->m_state != NULL); + int loc = ctx->m_state->getLocation(GL_WEIGHT_ARRAY_OES); + ctx->m_state->setState(loc, size, type, false, stride, data); +} + +void GLEncoder::s_glEnableClientState(void *self, GLenum state) +{ + GLEncoder *ctx = (GLEncoder *) self; + assert(ctx->m_state != NULL); + int loc = ctx->m_state->getLocation(state); + ctx->m_state->enable(loc, 1); +} + +void GLEncoder::s_glDisableClientState(void *self, GLenum state) +{ + GLEncoder *ctx = (GLEncoder *) self; + assert(ctx->m_state != NULL); + int loc = ctx->m_state->getLocation(state); + ctx->m_state->enable(loc, 0); +} + +GLboolean GLEncoder::s_glIsEnabled(void *self, GLenum cap) +{ + GLEncoder *ctx = (GLEncoder *) self; + assert(ctx->m_state != NULL); + int loc = ctx->m_state->getLocation(cap); + const GLClientState::VertexAttribState *state = ctx->m_state->getState(loc); + + if (state!=NULL) + return state->enabled; + + return ctx->m_glIsEnabled_enc(self,cap); +} + +void GLEncoder::s_glBindBuffer(void *self, GLenum target, GLuint id) +{ + GLEncoder *ctx = (GLEncoder *) self; + assert(ctx->m_state != NULL); + ctx->m_state->bindBuffer(target, id); + // TODO set error state if needed; + ctx->m_glBindBuffer_enc(self, target, id); +} + +void GLEncoder::s_glBufferData(void * self, GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage) +{ + GLEncoder *ctx = (GLEncoder *) self; + GLuint bufferId = ctx->m_state->getBuffer(target); + SET_ERROR_IF(bufferId==0, GL_INVALID_OPERATION); + SET_ERROR_IF(size<0, GL_INVALID_VALUE); + + ctx->m_shared->updateBufferData(bufferId, size, (void*)data); + ctx->m_glBufferData_enc(self, target, size, data, usage); +} + +void GLEncoder::s_glBufferSubData(void * self, GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) +{ + GLEncoder *ctx = (GLEncoder *) self; + GLuint bufferId = ctx->m_state->getBuffer(target); + SET_ERROR_IF(bufferId==0, GL_INVALID_OPERATION); + + GLenum res = ctx->m_shared->subUpdateBufferData(bufferId, offset, size, (void*)data); + SET_ERROR_IF(res, res); + + ctx->m_glBufferSubData_enc(self, target, offset, size, data); +} + +void GLEncoder::s_glDeleteBuffers(void * self, GLsizei n, const GLuint * buffers) +{ + GLEncoder *ctx = (GLEncoder *) self; + SET_ERROR_IF(n<0, GL_INVALID_VALUE); + for (int i=0; i<n; i++) { + ctx->m_shared->deleteBufferData(buffers[i]); + ctx->m_glDeleteBuffers_enc(self,1,&buffers[i]); + } +} + +void GLEncoder::sendVertexData(unsigned int first, unsigned int count) +{ + assert(m_state != NULL); + for (int i = 0; i < GLClientState::LAST_LOCATION; i++) { + bool enableDirty; + const GLClientState::VertexAttribState *state = m_state->getStateAndEnableDirty(i, &enableDirty); + + // do not process if state not valid + if (!state) continue; + + // do not send disable state if state was already disabled + if (!enableDirty && !state->enabled) continue; + + if ( i >= GLClientState::TEXCOORD0_LOCATION && + i <= GLClientState::TEXCOORD7_LOCATION ) { + m_glClientActiveTexture_enc(this, GL_TEXTURE0 + i - GLClientState::TEXCOORD0_LOCATION); + } + + if (state->enabled) { + + if (enableDirty) + m_glEnableClientState_enc(this, state->glConst); + + unsigned int datalen = state->elementSize * count; + int stride = state->stride; + if (stride == 0) stride = state->elementSize; + int firstIndex = stride * first; + + if (state->bufferObject == 0) { + + switch(i) { + case GLClientState::VERTEX_LOCATION: + this->glVertexPointerData(this, state->size, state->type, state->stride, + (unsigned char *)state->data + firstIndex, datalen); + break; + case GLClientState::NORMAL_LOCATION: + this->glNormalPointerData(this, state->type, state->stride, + (unsigned char *)state->data + firstIndex, datalen); + break; + case GLClientState::COLOR_LOCATION: + this->glColorPointerData(this, state->size, state->type, state->stride, + (unsigned char *)state->data + firstIndex, datalen); + break; + case GLClientState::TEXCOORD0_LOCATION: + case GLClientState::TEXCOORD1_LOCATION: + case GLClientState::TEXCOORD2_LOCATION: + case GLClientState::TEXCOORD3_LOCATION: + case GLClientState::TEXCOORD4_LOCATION: + case GLClientState::TEXCOORD5_LOCATION: + case GLClientState::TEXCOORD6_LOCATION: + case GLClientState::TEXCOORD7_LOCATION: + this->glTexCoordPointerData(this, i - GLClientState::TEXCOORD0_LOCATION, state->size, state->type, state->stride, + (unsigned char *)state->data + firstIndex, datalen); + break; + case GLClientState::POINTSIZE_LOCATION: + this->glPointSizePointerData(this, state->type, state->stride, + (unsigned char *) state->data + firstIndex, datalen); + break; + case GLClientState::WEIGHT_LOCATION: + this->glWeightPointerData(this, state->size, state->type, state->stride, + (unsigned char * ) state->data + firstIndex, datalen); + break; + case GLClientState::MATRIXINDEX_LOCATION: + this->glMatrixIndexPointerData(this, state->size, state->type, state->stride, + (unsigned char *)state->data + firstIndex, datalen); + break; + } + } else { + this->m_glBindBuffer_enc(this, GL_ARRAY_BUFFER, state->bufferObject); + + switch(i) { + case GLClientState::VERTEX_LOCATION: + this->glVertexPointerOffset(this, state->size, state->type, state->stride, + (GLuint)state->data + firstIndex); + break; + case GLClientState::NORMAL_LOCATION: + this->glNormalPointerOffset(this, state->type, state->stride, + (GLuint) state->data + firstIndex); + break; + case GLClientState::POINTSIZE_LOCATION: + this->glPointSizePointerOffset(this, state->type, state->stride, + (GLuint) state->data + firstIndex); + break; + case GLClientState::COLOR_LOCATION: + this->glColorPointerOffset(this, state->size, state->type, state->stride, + (GLuint) state->data + firstIndex); + break; + case GLClientState::TEXCOORD0_LOCATION: + case GLClientState::TEXCOORD1_LOCATION: + case GLClientState::TEXCOORD2_LOCATION: + case GLClientState::TEXCOORD3_LOCATION: + case GLClientState::TEXCOORD4_LOCATION: + case GLClientState::TEXCOORD5_LOCATION: + case GLClientState::TEXCOORD6_LOCATION: + case GLClientState::TEXCOORD7_LOCATION: + this->glTexCoordPointerOffset(this, state->size, state->type, state->stride, + (GLuint) state->data + firstIndex); + break; + case GLClientState::WEIGHT_LOCATION: + this->glWeightPointerOffset(this,state->size,state->type,state->stride, + (GLuint)state->data+firstIndex); + break; + case GLClientState::MATRIXINDEX_LOCATION: + this->glMatrixIndexPointerOffset(this,state->size,state->type,state->stride, + (GLuint)state->data+firstIndex); + break; + } + this->m_glBindBuffer_enc(this, GL_ARRAY_BUFFER, m_state->currentArrayVbo()); + } + } else { + this->m_glDisableClientState_enc(this, state->glConst); + } + } +} + +void GLEncoder::s_glDrawArrays(void *self, GLenum mode, GLint first, GLsizei count) +{ + GLEncoder *ctx = (GLEncoder *)self; + + ctx->sendVertexData(first, count); + ctx->m_glDrawArrays_enc(ctx, mode, /*first*/ 0, count); +} + +void GLEncoder::s_glDrawElements(void *self, GLenum mode, GLsizei count, GLenum type, const void *indices) +{ + + GLEncoder *ctx = (GLEncoder *)self; + assert(ctx->m_state != NULL); + SET_ERROR_IF(count<0, GL_INVALID_VALUE); + + bool has_immediate_arrays = false; + bool has_indirect_arrays = false; + + for (int i = 0; i < GLClientState::LAST_LOCATION; i++) { + const GLClientState::VertexAttribState *state = ctx->m_state->getState(i); + if (state->enabled) { + if (state->bufferObject != 0) { + has_indirect_arrays = true; + } else { + has_immediate_arrays = true; + } + } + } + + if (!has_immediate_arrays && !has_indirect_arrays) { + ALOGE("glDrawElements: no data bound to the command - ignoring\n"); + return; + } + + bool adjustIndices = true; + if (ctx->m_state->currentIndexVbo() != 0) { + if (!has_immediate_arrays) { + ctx->sendVertexData(0, count); + ctx->m_glBindBuffer_enc(self, GL_ELEMENT_ARRAY_BUFFER, ctx->m_state->currentIndexVbo()); + ctx->glDrawElementsOffset(ctx, mode, count, type, (GLuint)indices); + adjustIndices = false; + } else { + BufferData * buf = ctx->m_shared->getBufferData(ctx->m_state->currentIndexVbo()); + ctx->m_glBindBuffer_enc(self, GL_ELEMENT_ARRAY_BUFFER, 0); + indices = (void*)((GLintptr)buf->m_fixedBuffer.ptr() + (GLintptr)indices); + } + } + if (adjustIndices) { + void *adjustedIndices = (void*)indices; + int minIndex = 0, maxIndex = 0; + + switch(type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + GLUtils::minmax<unsigned char>((unsigned char *)indices, count, &minIndex, &maxIndex); + if (minIndex != 0) { + adjustedIndices = ctx->m_fixedBuffer.alloc(glSizeof(type) * count); + GLUtils::shiftIndices<unsigned char>((unsigned char *)indices, + (unsigned char *)adjustedIndices, + count, -minIndex); + } + break; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + GLUtils::minmax<unsigned short>((unsigned short *)indices, count, &minIndex, &maxIndex); + if (minIndex != 0) { + adjustedIndices = ctx->m_fixedBuffer.alloc(glSizeof(type) * count); + GLUtils::shiftIndices<unsigned short>((unsigned short *)indices, + (unsigned short *)adjustedIndices, + count, -minIndex); + } + break; + default: + ALOGE("unsupported index buffer type %d\n", type); + } + if (has_indirect_arrays || 1) { + ctx->sendVertexData(minIndex, maxIndex - minIndex + 1); + ctx->glDrawElementsData(ctx, mode, count, type, adjustedIndices, + count * glSizeof(type)); + // XXX - OPTIMIZATION (see the other else branch) should be implemented + if(!has_indirect_arrays) { + //ALOGD("unoptimized drawelements !!!\n"); + } + } else { + // we are all direct arrays and immidate mode index array - + // rebuild the arrays and the index array; + ALOGE("glDrawElements: direct index & direct buffer data - will be implemented in later versions;\n"); + } + } +} + +void GLEncoder::s_glActiveTexture(void* self, GLenum texture) +{ + GLEncoder* ctx = (GLEncoder*)self; + GLClientState* state = ctx->m_state; + GLenum err; + + if ((err = state->setActiveTextureUnit(texture)) != GL_NO_ERROR) { + ALOGE("%s:%s:%d GL error %#x\n", __FILE__, __FUNCTION__, __LINE__, err); + ctx->setError(err); + return; + } + + ctx->m_glActiveTexture_enc(ctx, texture); +} + +void GLEncoder::s_glBindTexture(void* self, GLenum target, GLuint texture) +{ + GLEncoder* ctx = (GLEncoder*)self; + GLClientState* state = ctx->m_state; + GLenum err; + + GLboolean firstUse; + if ((err = state->bindTexture(target, texture, &firstUse)) != GL_NO_ERROR) { + ALOGE("%s:%s:%d GL error %#x\n", __FILE__, __FUNCTION__, __LINE__, err); + ctx->setError(err); + return; + } + + if (target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES) { + ctx->m_glBindTexture_enc(ctx, target, texture); + return; + } + + GLenum priorityTarget = state->getPriorityEnabledTarget(GL_TEXTURE_2D); + + if (target == GL_TEXTURE_EXTERNAL_OES && firstUse) { + // set TEXTURE_EXTERNAL_OES default states which differ from TEXTURE_2D + ctx->m_glBindTexture_enc(ctx, GL_TEXTURE_2D, texture); + ctx->m_glTexParameteri_enc(ctx, GL_TEXTURE_2D, + GL_TEXTURE_MIN_FILTER, GL_LINEAR); + ctx->m_glTexParameteri_enc(ctx, GL_TEXTURE_2D, + GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + ctx->m_glTexParameteri_enc(ctx, GL_TEXTURE_2D, + GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + if (target != priorityTarget) { + ctx->m_glBindTexture_enc(ctx, GL_TEXTURE_2D, + state->getBoundTexture(GL_TEXTURE_2D)); + } + } + + if (target == priorityTarget) { + ctx->m_glBindTexture_enc(ctx, GL_TEXTURE_2D, texture); + } +} + +void GLEncoder::s_glDeleteTextures(void* self, GLsizei n, const GLuint* textures) +{ + GLEncoder* ctx = (GLEncoder*)self; + GLClientState* state = ctx->m_state; + + state->deleteTextures(n, textures); + ctx->m_glDeleteTextures_enc(ctx, n, textures); +} + +void GLEncoder::s_glDisable(void* self, GLenum cap) +{ + GLEncoder* ctx = (GLEncoder*)self; + GLClientState* state = ctx->m_state; + + if (cap == GL_TEXTURE_2D || cap == GL_TEXTURE_EXTERNAL_OES) { + GLenum prevTarget = state->getPriorityEnabledTarget(GL_INVALID_ENUM); + state->disableTextureTarget(cap); + GLenum currTarget = state->getPriorityEnabledTarget(GL_INVALID_ENUM); + + if (prevTarget != currTarget) { + if (currTarget == GL_INVALID_ENUM) { + ctx->m_glDisable_enc(ctx, GL_TEXTURE_2D); + currTarget = GL_TEXTURE_2D; + } + // maintain the invariant that when TEXTURE_EXTERNAL_OES is + // disabled, the TEXTURE_2D binding is active, even if + // TEXTURE_2D is also disabled. + ctx->m_glBindTexture_enc(ctx, GL_TEXTURE_2D, + state->getBoundTexture(currTarget)); + } + + } else { + ctx->m_glDisable_enc(ctx, cap); + } +} + +void GLEncoder::s_glEnable(void* self, GLenum cap) +{ + GLEncoder* ctx = (GLEncoder*)self; + GLClientState* state = ctx->m_state; + + if (cap == GL_TEXTURE_2D || cap == GL_TEXTURE_EXTERNAL_OES) { + GLenum prevTarget = state->getPriorityEnabledTarget(GL_INVALID_ENUM); + state->enableTextureTarget(cap); + GLenum currTarget = state->getPriorityEnabledTarget(GL_INVALID_ENUM); + + if (prevTarget != currTarget) { + if (prevTarget == GL_INVALID_ENUM) { + ctx->m_glEnable_enc(ctx, GL_TEXTURE_2D); + } + if (currTarget == GL_TEXTURE_EXTERNAL_OES) { + ctx->m_glBindTexture_enc(ctx, GL_TEXTURE_2D, + state->getBoundTexture(currTarget)); + } + } + + } else { + ctx->m_glEnable_enc(ctx, cap); + } +} + +void GLEncoder::s_glGetTexParameterfv(void* self, + GLenum target, GLenum pname, GLfloat* params) +{ + GLEncoder* ctx = (GLEncoder*)self; + const GLClientState* state = ctx->m_state; + + if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) { + ctx->override2DTextureTarget(target); + ctx->m_glGetTexParameterfv_enc(ctx, GL_TEXTURE_2D, pname, params); + ctx->restore2DTextureTarget(); + } else { + ctx->m_glGetTexParameterfv_enc(ctx, target, pname, params); + } +} + +void GLEncoder::s_glGetTexParameteriv(void* self, + GLenum target, GLenum pname, GLint* params) +{ + GLEncoder* ctx = (GLEncoder*)self; + const GLClientState* state = ctx->m_state; + + switch (pname) { + case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES: + *params = 1; + break; + + default: + if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) { + ctx->override2DTextureTarget(target); + ctx->m_glGetTexParameteriv_enc(ctx, GL_TEXTURE_2D, pname, params); + ctx->restore2DTextureTarget(); + } else { + ctx->m_glGetTexParameteriv_enc(ctx, target, pname, params); + } + break; + } +} + +void GLEncoder::s_glGetTexParameterxv(void* self, + GLenum target, GLenum pname, GLfixed* params) +{ + GLEncoder* ctx = (GLEncoder*)self; + const GLClientState* state = ctx->m_state; + + if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) { + ctx->override2DTextureTarget(target); + ctx->m_glGetTexParameterxv_enc(ctx, GL_TEXTURE_2D, pname, params); + ctx->restore2DTextureTarget(); + } else { + ctx->m_glGetTexParameterxv_enc(ctx, target, pname, params); + } +} + +static bool isValidTextureExternalParam(GLenum pname, GLenum param) +{ + switch (pname) { + case GL_TEXTURE_MIN_FILTER: + case GL_TEXTURE_MAG_FILTER: + return param == GL_NEAREST || param == GL_LINEAR; + + case GL_TEXTURE_WRAP_S: + case GL_TEXTURE_WRAP_T: + return param == GL_CLAMP_TO_EDGE; + + case GL_GENERATE_MIPMAP: + return param == GL_FALSE; + + default: + return true; + } +} + +void GLEncoder::s_glTexParameterf(void* self, + GLenum target, GLenum pname, GLfloat param) +{ + GLEncoder* ctx = (GLEncoder*)self; + const GLClientState* state = ctx->m_state; + + SET_ERROR_IF((target == GL_TEXTURE_EXTERNAL_OES && + !isValidTextureExternalParam(pname, (GLenum)param)), + GL_INVALID_ENUM); + + if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) { + ctx->override2DTextureTarget(target); + ctx->m_glTexParameterf_enc(ctx, GL_TEXTURE_2D, pname, param); + ctx->restore2DTextureTarget(); + } else { + ctx->m_glTexParameterf_enc(ctx, target, pname, param); + } +} + +void GLEncoder::s_glTexParameterfv(void* self, + GLenum target, GLenum pname, const GLfloat* params) +{ + GLEncoder* ctx = (GLEncoder*)self; + const GLClientState* state = ctx->m_state; + + SET_ERROR_IF((target == GL_TEXTURE_EXTERNAL_OES && + !isValidTextureExternalParam(pname, (GLenum)params[0])), + GL_INVALID_ENUM); + + if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) { + ctx->override2DTextureTarget(target); + ctx->m_glTexParameterfv_enc(ctx, GL_TEXTURE_2D, pname, params); + ctx->restore2DTextureTarget(); + } else { + ctx->m_glTexParameterfv_enc(ctx, target, pname, params); + } +} + +void GLEncoder::s_glTexParameteri(void* self, + GLenum target, GLenum pname, GLint param) +{ + GLEncoder* ctx = (GLEncoder*)self; + const GLClientState* state = ctx->m_state; + + SET_ERROR_IF((target == GL_TEXTURE_EXTERNAL_OES && + !isValidTextureExternalParam(pname, (GLenum)param)), + GL_INVALID_ENUM); + + if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) { + ctx->override2DTextureTarget(target); + ctx->m_glTexParameteri_enc(ctx, GL_TEXTURE_2D, pname, param); + ctx->restore2DTextureTarget(); + } else { + ctx->m_glTexParameteri_enc(ctx, target, pname, param); + } +} + +void GLEncoder::s_glTexParameterx(void* self, + GLenum target, GLenum pname, GLfixed param) +{ + GLEncoder* ctx = (GLEncoder*)self; + const GLClientState* state = ctx->m_state; + + SET_ERROR_IF((target == GL_TEXTURE_EXTERNAL_OES && + !isValidTextureExternalParam(pname, (GLenum)param)), + GL_INVALID_ENUM); + + if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) { + ctx->override2DTextureTarget(target); + ctx->m_glTexParameterx_enc(ctx, GL_TEXTURE_2D, pname, param); + ctx->restore2DTextureTarget(); + } else { + ctx->m_glTexParameterx_enc(ctx, target, pname, param); + } +} + +void GLEncoder::s_glTexParameteriv(void* self, + GLenum target, GLenum pname, const GLint* params) +{ + GLEncoder* ctx = (GLEncoder*)self; + const GLClientState* state = ctx->m_state; + + SET_ERROR_IF((target == GL_TEXTURE_EXTERNAL_OES && + !isValidTextureExternalParam(pname, (GLenum)params[0])), + GL_INVALID_ENUM); + + if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) { + ctx->override2DTextureTarget(target); + ctx->m_glTexParameteriv_enc(ctx, GL_TEXTURE_2D, pname, params); + ctx->restore2DTextureTarget(); + } else { + ctx->m_glTexParameteriv_enc(ctx, target, pname, params); + } +} + +void GLEncoder::s_glTexParameterxv(void* self, + GLenum target, GLenum pname, const GLfixed* params) +{ + GLEncoder* ctx = (GLEncoder*)self; + const GLClientState* state = ctx->m_state; + + SET_ERROR_IF((target == GL_TEXTURE_EXTERNAL_OES && + !isValidTextureExternalParam(pname, (GLenum)params[0])), + GL_INVALID_ENUM); + + if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) { + ctx->override2DTextureTarget(target); + ctx->m_glTexParameterxv_enc(ctx, GL_TEXTURE_2D, pname, params); + ctx->restore2DTextureTarget(); + } else { + ctx->m_glTexParameterxv_enc(ctx, target, pname, params); + } +} + +void GLEncoder::override2DTextureTarget(GLenum target) +{ + if ((target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) && + target != m_state->getPriorityEnabledTarget(GL_TEXTURE_2D)) { + m_glBindTexture_enc(this, GL_TEXTURE_2D, + m_state->getBoundTexture(target)); + } +} + +void GLEncoder::restore2DTextureTarget() +{ + GLenum priorityTarget = m_state->getPriorityEnabledTarget(GL_TEXTURE_2D); + m_glBindTexture_enc(this, GL_TEXTURE_2D, + m_state->getBoundTexture(priorityTarget)); +} + +GLEncoder::GLEncoder(IOStream *stream) : gl_encoder_context_t(stream) +{ + m_initialized = false; + m_state = NULL; + m_error = GL_NO_ERROR; + m_num_compressedTextureFormats = 0; + m_compressedTextureFormats = NULL; + // overrides; + m_glFlush_enc = set_glFlush(s_glFlush); + m_glPixelStorei_enc = set_glPixelStorei(s_glPixelStorei); + m_glVertexPointer_enc = set_glVertexPointer(s_glVertexPointer); + m_glNormalPointer_enc = set_glNormalPointer(s_glNormalPointer); + m_glColorPointer_enc = set_glColorPointer(s_glColorPointer); + m_glPointSizePointerOES_enc = set_glPointSizePointerOES(s_glPointsizePointer); + m_glClientActiveTexture_enc = set_glClientActiveTexture(s_glClientActiveTexture); + m_glTexCoordPointer_enc = set_glTexCoordPointer(s_glTexcoordPointer); + m_glMatrixIndexPointerOES_enc = set_glMatrixIndexPointerOES(s_glMatrixIndexPointerOES); + m_glWeightPointerOES_enc = set_glWeightPointerOES(s_glWeightPointerOES); + + m_glGetIntegerv_enc = set_glGetIntegerv(s_glGetIntegerv); + m_glGetFloatv_enc = set_glGetFloatv(s_glGetFloatv); + m_glGetBooleanv_enc = set_glGetBooleanv(s_glGetBooleanv); + m_glGetFixedv_enc = set_glGetFixedv(s_glGetFixedv); + m_glGetPointerv_enc = set_glGetPointerv(s_glGetPointerv); + + m_glBindBuffer_enc = set_glBindBuffer(s_glBindBuffer); + m_glBufferData_enc = set_glBufferData(s_glBufferData); + m_glBufferSubData_enc = set_glBufferSubData(s_glBufferSubData); + m_glDeleteBuffers_enc = set_glDeleteBuffers(s_glDeleteBuffers); + + m_glEnableClientState_enc = set_glEnableClientState(s_glEnableClientState); + m_glDisableClientState_enc = set_glDisableClientState(s_glDisableClientState); + m_glIsEnabled_enc = set_glIsEnabled(s_glIsEnabled); + m_glDrawArrays_enc = set_glDrawArrays(s_glDrawArrays); + m_glDrawElements_enc = set_glDrawElements(s_glDrawElements); + set_glGetString(s_glGetString); + set_glFinish(s_glFinish); + m_glGetError_enc = set_glGetError(s_glGetError); + + m_glActiveTexture_enc = set_glActiveTexture(s_glActiveTexture); + m_glBindTexture_enc = set_glBindTexture(s_glBindTexture); + m_glDeleteTextures_enc = set_glDeleteTextures(s_glDeleteTextures); + m_glDisable_enc = set_glDisable(s_glDisable); + m_glEnable_enc = set_glEnable(s_glEnable); + m_glGetTexParameterfv_enc = set_glGetTexParameterfv(s_glGetTexParameterfv); + m_glGetTexParameteriv_enc = set_glGetTexParameteriv(s_glGetTexParameteriv); + m_glGetTexParameterxv_enc = set_glGetTexParameterxv(s_glGetTexParameterxv); + m_glTexParameterf_enc = set_glTexParameterf(s_glTexParameterf); + m_glTexParameterfv_enc = set_glTexParameterfv(s_glTexParameterfv); + m_glTexParameteri_enc = set_glTexParameteri(s_glTexParameteri); + m_glTexParameterx_enc = set_glTexParameterx(s_glTexParameterx); + m_glTexParameteriv_enc = set_glTexParameteriv(s_glTexParameteriv); + m_glTexParameterxv_enc = set_glTexParameterxv(s_glTexParameterxv); +} + +GLEncoder::~GLEncoder() +{ + delete [] m_compressedTextureFormats; +} + +size_t GLEncoder::pixelDataSize(GLsizei width, GLsizei height, GLenum format, GLenum type, int pack) +{ + assert(m_state != NULL); + return m_state->pixelDataSize(width, height, format, type, pack); +} + +void GLEncoder::s_glFinish(void *self) +{ + GLEncoder *ctx = (GLEncoder *)self; + ctx->glFinishRoundTrip(self); +} diff --git a/emulator/opengl/system/GLESv1_enc/GLEncoder.h b/emulator/opengl/system/GLESv1_enc/GLEncoder.h new file mode 100644 index 0000000..effc53f --- /dev/null +++ b/emulator/opengl/system/GLESv1_enc/GLEncoder.h @@ -0,0 +1,149 @@ +/* +* 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_ENCODER_H_ +#define _GL_ENCODER_H_ + +#include "gl_enc.h" +#include "GLClientState.h" +#include "GLSharedGroup.h" +#include "FixedBuffer.h" + +class GLEncoder : public gl_encoder_context_t { + +public: + GLEncoder(IOStream *stream); + virtual ~GLEncoder(); + void setClientState(GLClientState *state) { + m_state = state; + } + void setSharedGroup(GLSharedGroupPtr shared) { m_shared = shared; } + void flush() { m_stream->flush(); } + size_t pixelDataSize(GLsizei width, GLsizei height, GLenum format, GLenum type, int pack); + + void setInitialized(){ m_initialized = true; }; + bool isInitialized(){ return m_initialized; }; + + virtual void setError(GLenum error){ m_error = error; }; + virtual GLenum getError() { return m_error; }; + + void override2DTextureTarget(GLenum target); + void restore2DTextureTarget(); + +private: + + bool m_initialized; + GLClientState *m_state; + GLSharedGroupPtr m_shared; + GLenum m_error; + FixedBuffer m_fixedBuffer; + GLint *m_compressedTextureFormats; + GLint m_num_compressedTextureFormats; + + GLint *getCompressedTextureFormats(); + // original functions; + glGetError_client_proc_t m_glGetError_enc; + glGetIntegerv_client_proc_t m_glGetIntegerv_enc; + glGetFloatv_client_proc_t m_glGetFloatv_enc; + glGetFixedv_client_proc_t m_glGetFixedv_enc; + glGetBooleanv_client_proc_t m_glGetBooleanv_enc; + glGetPointerv_client_proc_t m_glGetPointerv_enc; + + glPixelStorei_client_proc_t m_glPixelStorei_enc; + glVertexPointer_client_proc_t m_glVertexPointer_enc; + glNormalPointer_client_proc_t m_glNormalPointer_enc; + glColorPointer_client_proc_t m_glColorPointer_enc; + glPointSizePointerOES_client_proc_t m_glPointSizePointerOES_enc; + glTexCoordPointer_client_proc_t m_glTexCoordPointer_enc; + glClientActiveTexture_client_proc_t m_glClientActiveTexture_enc; + glMatrixIndexPointerOES_client_proc_t m_glMatrixIndexPointerOES_enc; + glWeightPointerOES_client_proc_t m_glWeightPointerOES_enc; + + glBindBuffer_client_proc_t m_glBindBuffer_enc; + glBufferData_client_proc_t m_glBufferData_enc; + glBufferSubData_client_proc_t m_glBufferSubData_enc; + glDeleteBuffers_client_proc_t m_glDeleteBuffers_enc; + + glEnableClientState_client_proc_t m_glEnableClientState_enc; + glDisableClientState_client_proc_t m_glDisableClientState_enc; + glIsEnabled_client_proc_t m_glIsEnabled_enc; + glDrawArrays_client_proc_t m_glDrawArrays_enc; + glDrawElements_client_proc_t m_glDrawElements_enc; + glFlush_client_proc_t m_glFlush_enc; + + glActiveTexture_client_proc_t m_glActiveTexture_enc; + glBindTexture_client_proc_t m_glBindTexture_enc; + glDeleteTextures_client_proc_t m_glDeleteTextures_enc; + glDisable_client_proc_t m_glDisable_enc; + glEnable_client_proc_t m_glEnable_enc; + glGetTexParameterfv_client_proc_t m_glGetTexParameterfv_enc; + glGetTexParameteriv_client_proc_t m_glGetTexParameteriv_enc; + glGetTexParameterxv_client_proc_t m_glGetTexParameterxv_enc; + glTexParameterf_client_proc_t m_glTexParameterf_enc; + glTexParameterfv_client_proc_t m_glTexParameterfv_enc; + glTexParameteri_client_proc_t m_glTexParameteri_enc; + glTexParameterx_client_proc_t m_glTexParameterx_enc; + glTexParameteriv_client_proc_t m_glTexParameteriv_enc; + glTexParameterxv_client_proc_t m_glTexParameterxv_enc; + + // statics + static GLenum s_glGetError(void * self); + static void s_glGetIntegerv(void *self, GLenum pname, GLint *ptr); + static void s_glGetBooleanv(void *self, GLenum pname, GLboolean *ptr); + static void s_glGetFloatv(void *self, GLenum pname, GLfloat *ptr); + static void s_glGetFixedv(void *self, GLenum pname, GLfixed *ptr); + static void s_glGetPointerv(void *self, GLenum pname, GLvoid **params); + + static void s_glFlush(void * self); + static const GLubyte * s_glGetString(void *self, GLenum name); + static void s_glVertexPointer(void *self, int size, GLenum type, GLsizei stride, const void *data); + static void s_glNormalPointer(void *self, GLenum type, GLsizei stride, const void *data); + static void s_glColorPointer(void *self, int size, GLenum type, GLsizei stride, const void *data); + static void s_glPointsizePointer(void *self, GLenum type, GLsizei stride, const void *data); + static void s_glClientActiveTexture(void *self, GLenum texture); + static void s_glTexcoordPointer(void *self, int size, GLenum type, GLsizei stride, const void *data); + static void s_glMatrixIndexPointerOES(void *self, int size, GLenum type, GLsizei stride, const void * data); + static void s_glWeightPointerOES(void *self, int size, GLenum type, GLsizei stride, const void * data); + static void s_glDisableClientState(void *self, GLenum state); + static void s_glEnableClientState(void *self, GLenum state); + static GLboolean s_glIsEnabled(void *self, GLenum cap); + static void s_glBindBuffer(void *self, GLenum target, GLuint id); + static void s_glBufferData(void *self, GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage); + static void s_glBufferSubData(void *self, GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); + static void s_glDeleteBuffers(void *self, GLsizei n, const GLuint * buffers); + + static void s_glDrawArrays(void *self, GLenum mode, GLint first, GLsizei count); + static void s_glDrawElements(void *self, GLenum mode, GLsizei count, GLenum type, const void *indices); + static void s_glPixelStorei(void *self, GLenum param, GLint value); + + static void s_glFinish(void *self); + void sendVertexData(unsigned first, unsigned count); + + static void s_glActiveTexture(void* self, GLenum texture); + static void s_glBindTexture(void* self, GLenum target, GLuint texture); + static void s_glDeleteTextures(void* self, GLsizei n, const GLuint* textures); + static void s_glDisable(void* self, GLenum cap); + static void s_glEnable(void* self, GLenum cap); + static void s_glGetTexParameterfv(void* self, GLenum target, GLenum pname, GLfloat* params); + static void s_glGetTexParameteriv(void* self, GLenum target, GLenum pname, GLint* params); + static void s_glGetTexParameterxv(void* self, GLenum target, GLenum pname, GLfixed* params); + static void s_glTexParameterf(void* self, GLenum target, GLenum pname, GLfloat param); + static void s_glTexParameterfv(void* self, GLenum target, GLenum pname, const GLfloat* params); + static void s_glTexParameteri(void* self, GLenum target, GLenum pname, GLint param); + static void s_glTexParameterx(void* self, GLenum target, GLenum pname, GLfixed param); + static void s_glTexParameteriv(void* self, GLenum target, GLenum pname, const GLint* params); + static void s_glTexParameterxv(void* self, GLenum target, GLenum pname, const GLfixed* params); +}; +#endif diff --git a/emulator/opengl/system/GLESv1_enc/GLEncoderUtils.cpp b/emulator/opengl/system/GLESv1_enc/GLEncoderUtils.cpp new file mode 100644 index 0000000..7866d53 --- /dev/null +++ b/emulator/opengl/system/GLESv1_enc/GLEncoderUtils.cpp @@ -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. +*/ +#include <stdio.h> +#include <stdlib.h> +#include "GLEncoder.h" + +size_t pixelDataSize(void *self, GLsizei width, GLsizei height, GLenum format, GLenum type, int pack) +{ + GLEncoder *ctx = (GLEncoder *)self; + return ctx->pixelDataSize(width, height, format, type, pack); +} diff --git a/emulator/opengl/system/GLESv1_enc/GLEncoderUtils.h b/emulator/opengl/system/GLESv1_enc/GLEncoderUtils.h new file mode 100644 index 0000000..1d0c847 --- /dev/null +++ b/emulator/opengl/system/GLESv1_enc/GLEncoderUtils.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 GL_ENCODER_UTILS_H +#define GL_ENCLODER_UTILS_H + +extern "C" { + size_t pixelDataSize(void *self, GLsizei width, GLsizei height, GLenum format, GLenum type, int pack); +}; +#endif diff --git a/emulator/opengl/system/GLESv1_enc/gl.addon b/emulator/opengl/system/GLESv1_enc/gl.addon new file mode 100644 index 0000000..2331f87 --- /dev/null +++ b/emulator/opengl/system/GLESv1_enc/gl.addon @@ -0,0 +1,15 @@ +GL_ENTRY(void, glVertexPointerOffset, GLint size, GLenum type, GLsizei stride, GLuint offset) +GL_ENTRY(void, glColorPointerOffset, GLint size, GLenum type, GLsizei stride, GLuint offset) +GL_ENTRY(void, glNormalPointerOffset, GLenum type, GLsizei stride, GLuint offset) +GL_ENTRY(void, glPointSizePointerOffset, GLenum type, GLsizei stride, GLuint offset) +GL_ENTRY(void, glTexCoordPointerOffset, GLint size, GLenum type, GLsizei stride, GLuint offset) + +GL_ENTRY(void, glVertexPointerData, GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen) +GL_ENTRY(void, glColorPointerData, GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen) +GL_ENTRY(void, glNormalPointerData, GLenum type, GLsizei stride, void * data, GLuint datalen) +GL_ENTRY(void, glTexCoordPointerData, GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen) +GL_ENTRY(void, glPointSizePointerData, GLenum type, GLsizei stride, void * data, GLuint datalen) + +GL_ENTRY(void, glDrawElementsOffset, GLenum mode, GLsizei count, GLenum type, GLuint offset); +GL_ENTRY(void, glDrawElementsData, GLenum mode, GLsizei count, GLenum type, void *data, GLuint datalen); + diff --git a/emulator/opengl/system/GLESv1_enc/gl.attrib b/emulator/opengl/system/GLESv1_enc/gl.attrib new file mode 100644 index 0000000..9b84f89 --- /dev/null +++ b/emulator/opengl/system/GLESv1_enc/gl.attrib @@ -0,0 +1,691 @@ +GLOBAL + base_opcode 1024 + encoder_headers "glUtils.h" "GLEncoderUtils.h" + +#void glClipPlanef(GLenum plane, GLfloat *equation) +glClipPlanef + dir equation in + len equation (4 * sizeof(float)) + +#void glFogfv(GLenum pname, GLfloat *params) +glFogfv + len params (glUtilsParamSize(pname) * sizeof(GLfloat)) + +#void glGetFloatv(GLenum pname, GLfloat *params) +glGetFloatv + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLfloat)) + +#void glGetLightfv(GLenum light, GLenum pname, GLfloat *params) +glGetLightfv + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLfloat)) + +#void glGetMaterialfv(GLenum face, GLenum pname, GLfloat *params) +glGetMaterialfv + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLfloat)) + +#void glGetTexEnvfv(GLenum env, GLenum pname, GLfloat *params) +glGetTexEnvfv + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLfloat)) + +#void glGetTexParameterfv(GLenum target, GLenum pname, GLfloat *params) +glGetTexParameterfv + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLfloat)) + +#void glLightModelfv(GLenum pname, GLfloat *params) +glLightModelfv + len params (glUtilsParamSize(pname) * sizeof(GLfloat)) + +#void glLightfv(GLenum light, GLenum pname, GLfloat *params) +glLightfv + len params (glUtilsParamSize(pname) * sizeof(GLfloat)) + +#void glLoadMatrixf(GLfloat *m) +glLoadMatrixf + len m (16 * sizeof(GLfloat)) + +#void glMaterialfv(GLenum face, GLenum pname, GLfloat *params) +glMaterialfv + len params (glUtilsParamSize(pname) * sizeof(GLfloat)) + +#void glMultMatrixf(GLfloat *m) +glMultMatrixf + len m (16 * sizeof(GLfloat)) + +#void glPointParameterfv(GLenum pname, GLfloat *params) +glPointParameterfv + len params (glUtilsParamSize(pname) * sizeof(GLfloat)) + +#void glTexEnvfv(GLenum target, GLenum pname, GLfloat *params) +glTexEnvfv + len params (glUtilsParamSize(pname) * sizeof(GLfloat)) + +#void glTexParameterfv(GLenum target, GLenum pname, GLfloat *params) +glTexParameterfv + len params (glUtilsParamSize(pname) * sizeof(GLfloat)) + +#void glBufferData(GLenum target, GLsizeiptr size, GLvoid *data, GLenum usage) +glBufferData + len data size + +#void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data) +glBufferSubData + dir data in + len data size + +#void glClipPlanex(GLenum plane, GLfixed *eqn) +glClipPlanex + dir eqn in + len eqn (4 * sizeof(GLfixed)) + +#void glColorPointer(GLint size, GLenum type, GLsizei stride, GLvoid *pointer) +#we treat the pointer as offset to a VBO +glColorPointer + len pointer (sizeof(unsigned int)) + flag unsupported + +#void glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, GLvoid *data) +glCompressedTexImage2D + len data imageSize + var_flag data nullAllowed + +#void glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, GLvoid *data) +glCompressedTexSubImage2D + len data imageSize + +#void glDeleteBuffers(GLsizei n, GLuint *buffers) +glDeleteBuffers + len buffers (n * sizeof(GLuint)) + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#void glDeleteTextures(GLsizei n, GLuint *textures) +glDeleteTextures + len textures (n * sizeof(GLuint)) + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#this function is marked as unsupported - it shouldn't be called directly +#instead it translated into - glDrawDirectElements and glDrawIndirectElements +#void glDrawElements(GLenum mode, GLsizei count, GLenum type, GLvoid *indices) +glDrawElements + flag unsupported + + +#void glFogxv(GLenum pname, GLfixed *params) +glFogxv + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glGetBooleanv(GLenum pname, GLboolean *params) +glGetBooleanv + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLboolean)) + +#void glGetBufferParameteriv(GLenum target, GLenum pname, GLint *params) +glGetBufferParameteriv + len params (sizeof(GLint)) + dir params out + +#void glGenBuffers(GLsizei n, GLuint *buffers) +glGenBuffers + len buffers (n * sizeof(GLuint)) + dir buffers out + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#void glGenTextures(GLsizei n, GLuint *textures) +glGenTextures + len textures (n * sizeof(GLuint)) + dir textures out + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#void glGetFixedv(GLenum pname, GLfixed *params) +glGetFixedv + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glGetIntegerv(GLenum pname, GLint *params) +glGetIntegerv + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLint)) + +#void glGetLightxv(GLenum light, GLenum pname, GLfixed *params) +glGetLightxv + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glGetMaterialxv(GLenum face, GLenum pname, GLfixed *params) +glGetMaterialxv + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glGetPointerv(GLenum pname, void **params) +glGetPointerv + flag unsupported + +#GLubyte* glGetString(GLenum name) +glGetString + flag unsupported + +#void glGetTexEnviv(GLenum env, GLenum pname, GLint *params) +glGetTexEnviv + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLint)) + +#void glGetTexEnvxv(GLenum env, GLenum pname, GLfixed *params) +glGetTexEnvxv + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glGetTexParameteriv(GLenum target, GLenum pname, GLint *params) +glGetTexParameteriv + dir params out + len params (sizeof(GLint)) + +#void glGetTexParameterxv(GLenum target, GLenum pname, GLfixed *params) +glGetTexParameterxv + dir params out + len params (sizeof(GLfixed)) + +#void glLightModelxv(GLenum pname, GLfixed *params) +glLightModelxv + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glLightxv(GLenum light, GLenum pname, GLfixed *params) +glLightxv + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glLoadMatrixx(GLfixed *m) +glLoadMatrixx + len m (16 * sizeof(GLfixed)) + +#void glMaterialxv(GLenum face, GLenum pname, GLfixed *params) +glMaterialxv + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glMultMatrixx(GLfixed *m) +glMultMatrixx + len m (16 * sizeof(GLfixed)) + +#void glNormalPointer(GLenum type, GLsizei stride, GLvoid *pointer) +#we treat the pointer as an offset to a VBO +glNormalPointer + len pointer (sizeof(unsigned int)) + flag unsupported + +#void glPointParameterxv(GLenum pname, GLfixed *params) +glPointParameterxv + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) +glReadPixels + dir pixels out + len pixels pixelDataSize(self, width, height, format, type, 1) + +#void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, GLvoid *pointer) +glTexCoordPointer + len pointer (sizeof(unsigned int)) + flag unsupported + +#void glTexEnviv(GLenum target, GLenum pname, GLint *params) +glTexEnviv + len params (glUtilsParamSize(pname) * sizeof(GLint)) + +#void glTexEnvxv(GLenum target, GLenum pname, GLfixed *params) +glTexEnvxv + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLvoid *pixels) +glTexImage2D + dir pixels in + len pixels pixelDataSize(self, width, height, format, type, 0) + var_flag pixels nullAllowed isLarge + +#void glTexParameteriv(GLenum target, GLenum pname, GLint *params) +glTexParameteriv + len params (glUtilsParamSize(pname) * sizeof(GLint)) + +#void glTexParameterxv(GLenum target, GLenum pname, GLfixed *params) +glTexParameterxv + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) +glTexSubImage2D + len pixels pixelDataSize(self, width, height, format, type, 0) + var_flag pixels isLarge + +#void glVertexPointer(GLint size, GLenum type, GLsizei stride, GLvoid *pointer) +# we treat the pointer as an offset to a VBO +glVertexPointer + flag unsupported + +#void glPointSizePointerOES(GLenum type, GLsizei stride, GLvoid *pointer) +glPointSizePointerOES + len pointer (sizeof(unsigned int)) + flag unsupported + +#void glGetClipPlanef(GLenum pname, GLfloat * eqn) +glGetClipPlanef + dir eqn out + len eqn (4 * sizeof(GLfloat)) + +#void glVertexPointerData(GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen) +glVertexPointerData + len data datalen + custom_pack data glUtilsPackPointerData((unsigned char *)ptr, (unsigned char *)data, size, type, stride, datalen) + flag custom_decoder + flag not_api + +#void glColorPointerData(GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen) +glColorPointerData + len data datalen + flag custom_decoder + custom_pack data glUtilsPackPointerData((unsigned char *)ptr, (unsigned char *)data, size, type, stride, datalen) + flag not_api + +#void glNormalPointerData(GLenum type, GLsizei stride, void *data, GLuint datalen) +glNormalPointerData + len data datalen + flag custom_decoder + custom_pack data glUtilsPackPointerData((unsigned char *)ptr, (unsigned char *)data, 3, type, stride, datalen) + flag not_api + +#void glPointSizePointerData(GLenum type, GLsizei stride, void *data, GLuint datalen) +glPointSizePointerData + len data datalen + flag custom_decoder + custom_pack data glUtilsPackPointerData((unsigned char *)ptr, (unsigned char *)data, 1, type, stride, datalen) + flag not_api + +#void glTexCoordPointerData(GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen) +glTexCoordPointerData + len data datalen + flag custom_decoder + custom_pack data glUtilsPackPointerData((unsigned char *)ptr, (unsigned char *)data, size, type, stride, datalen) + flag not_api + +#void glWeightPointerData(GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen) +glWeightPointerData + len data datalen + custom_pack data glUtilsPackPointerData((unsigned char *)ptr, (unsigned char*)data, size, type, stride, datalen) + flag custom_decoder + flag not_api + +#void glMatrixIndexPointerData(GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen) +glMatrixIndexPointerData + len data datalen + custom_pack data glUtilsPackPointerData((unsigned char *)ptr, (unsigned char*)data, size, type, stride, datalen) + flag custom_decoder + flag not_api + +glVertexPointerOffset + flag custom_decoder + flag not_api +glNormalPointerOffset + flag custom_decoder + flag not_api +glTexCoordPointerOffset + flag custom_decoder + flag not_api +glPointSizePointerOffset + flag custom_decoder + flag not_api +glColorPointerOffset + flag custom_decoder + flag not_api +glWeightPointerOffset + flag custom_decoder + flag not_api +glMatrixIndexPointerOffset + flag custom_decoder + flag not_api + +glDrawElementsData + len data datalen + flag custom_decoder + flag not_api + +glDrawElementsOffset + flag custom_decoder + flag not_api + +glGetCompressedTextureFormats + dir formats out + len formats (count * sizeof(GLint)) + flag custom_decoder + flag not_api + +glFinishRoundTrip + flag custom_decoder + flag not_api + +#gles1 extensions + +#void glDrawTexsvOES(GLshort *coords) +glDrawTexsvOES + len coords (5 * sizeof(GLshort)) + +#void glDrawTexivOES(GLint *coords) +glDrawTexivOES + len coords (5 * sizeof(GLint)) + +#void glDrawTexxvOES(GLfixed *coords) +glDrawTexxvOES + len coords (5 * sizeof(GLfixed)) + +#void glDrawTexfvOES(GLfloat *coords) +glDrawTexfvOES + len coords (5 * sizeof(GLfloat)) + +#glClipPlanexOES(GLenum plane, const GLfixed * equation) +glClipPlanexOES + dir equation in + len equation (4 * sizeof(GLfixed)) + +#glClipPlanexIMG(GLenum plane, const GLfixed * equation) +glClipPlanexIMG + dir equation in + len equation (4 * sizeof(GLfixed)) + +#void glFogxvOES(GLenum pname, GLfixed *params) +glFogxvOES + dir params in + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glGetClipPlanexOES(GLenum pname, GLfixed * eqn) +glGetClipPlanexOES + dir eqn out + len eqn (4 * sizeof(GLfixed)) + +#void glGetClipPlanex(GLenum pname, GLfixed * eqn) +glGetClipPlanex + dir eqn out + len eqn (4 * sizeof(GLfixed)) + +#void glGetFixedvOES(GLenum pname, GLfixed *params) +glGetFixedvOES + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glGetLightxvOES(GLenum light, GLenum pname, GLfixed *params) +glGetLightxvOES + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glGetMaterialxvOES(GLenum face, GLenum pname, GLfixed *params) +glGetMaterialxvOES + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glGetTexEnvxvOES(GLenum env, GLenum pname, GLfixed *params) +glGetTexEnvxvOES + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glGetTexParameterxvOES(GLenum target, GLenum pname, GLfixed *params) +glGetTexParameterxvOES + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glLightModelxvOES(GLenum pname, GLfixed *params) +glLightModelxvOES + dir params in + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glLightxvOES(GLenum light, GLenum pname, GLfixed *params) +glLightxvOES + dir params in + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glLoadMatrixxOES(GLfixed *m) +glLoadMatrixxOES + dir m in + len m (16 * sizeof(GLfixed)) + +#void glMaterialxvOES(GLenum face, GLenum pname, GLfixed *params) +glMaterialxvOES + dir params in + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glMultMatrixxOES(GLfixed *m) +glMultMatrixxOES + dir m in + len m (16 * sizeof(GLfixed)) + +#void glPointParameterxvOES(GLenum pname, GLfixed *params) +glPointParameterxvOES + dir params in + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glTexEnvxvOES(GLenum target, GLenum pname, GLfixed *params) +glTexEnvxvOES + dir params in + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glTexParameterxvOES(GLenum target, GLenum pname, GLfixed *params) +glTexParameterxvOES + dir params in + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glDeleteRenderbuffersOES(GLsizei n, GLuint *renderbuffers) +glDeleteRenderbuffersOES + dir renderbuffers in + len renderbuffers (n * sizeof(GLuint)) + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#void glGenRenderbuffersOES(GLsizei n, GLuint *renderbuffers) +glGenRenderbuffersOES + dir renderbuffers out + len renderbuffers (n * sizeof(GLuint)) + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#void glGetRenderbufferParameterivOES(GLenum target, GLenum pname, GLint *params) +glGetRenderbufferParameterivOES + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLint)) + +#void glDeleteFramebuffersOES(GLsizei n, GLuint *framebuffers) +glDeleteFramebuffersOES + dir framebuffers in + len framebuffers (n * sizeof(GLuint)) + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#void glGenFramebuffersOES(GLsizei n, GLuint *framebuffers) +glGenFramebuffersOES + dir framebuffers out + len framebuffers (n * sizeof(GLuint)) + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#void glGetFramebufferAttachmentParameterivOES(GLenum target, GLenum attachment, GLenum pname, GLint *params) +glGetFramebufferAttachmentParameterivOES + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLint)) + +#void* glMapBufferOES(GLenum target, GLenum access) +glMapBufferOES + flag unsupported + +#void glGetBufferPointervOES(GLenum target, GLenum pname, GLvoid ** params) +glGetBufferPointervOES + flag unsupported + +#void glMatrixIndexPointerOES(GLint size, GLenum type, GLsizei stride, GLvoid *pointer) +glMatrixIndexPointerOES + len pointer (sizeof(unsigned int)) + flag unsupported + +#void glWeightPointerOES(GLint size, GLenum type, GLsizei stride, GLvoid *pointer) +glWeightPointerOES + len pointer (sizeof(unsigned int)) + flag unsupported + +#glQueryMatrixxOES(GLfixed * mantissa, GLint * exponent) +glQueryMatrixxOES + dir mantissa out + len mantissa (16 * sizeof(GLfixed)) + dir exponent out + len exponent (16 * sizeof(GLfixed)) + +#void glClipPlanefOES(GLenum plane, GLfloat *equation) +glClipPlanefOES + dir equation in + len equation (4 * sizeof(GLfloat)) + +#void glClipPlanefIMG(GLenum plane, GLfloat *equation) +glClipPlanefIMG + dir equation in + len equation (4 * sizeof(GLfloat)) + +#void glGetClipPlanefOES(GLenum pname, GLfloat * eqn) +glGetClipPlanefOES + dir eqn out + len eqn (4 * sizeof(GLfloat)) + +#void glTexGenfvOES(GLenum coord, GLenum pname, GLfloat *params) +glTexGenfvOES + len params (glUtilsParamSize(pname) * sizeof(GLfloat)) + +#void glTexGenivOES(GLenum coord, GLenum pname, GLint *params) +glTexGenivOES + len params (glUtilsParamSize(pname) * sizeof(GLint)) + +#void glTexGenxvOES(GLenum coord, GLenum pname, GLfixed *params) +glTexGenxvOES + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glGetTexGenfvOES(GLenum coord, GLenum pname, GLfloat *params) +glGetTexGenfvOES + len params (glUtilsParamSize(pname) * sizeof(GLfloat)) + +#void glGetTexGenivOES(GLenum coord, GLenum pname, GLint *params) +glGetTexGenivOES + len params (glUtilsParamSize(pname) * sizeof(GLint)) + +#void glGetTexGenxvOES(GLenum coord, GLenum pname, GLfixed *params) +glGetTexGenxvOES + len params (glUtilsParamSize(pname) * sizeof(GLfixed)) + +#void glDeleteVertexArraysOES(GLsizei n, const GLuint *arrays) +glDeleteVertexArraysOES + dir arrays in + len arrays (n * sizeof(GLuint)) + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#void glGenVertexArraysOES(GLsizei n, GLuint *arrays) +glGenVertexArraysOES + dir arrays out + len arrays (n * sizeof(GLuint)) + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#void glDiscardFramebufferEXT(GLenum target, GLsizei numAttachments, const GLenum *attachments) +glDiscardFramebufferEXT + dir attachments in + len attachments (numAttachments * sizeof(const GLenum)) + +#void glMultiDrawArraysEXT(GLenum mode, GLint *first, GLsizei *count, GLsizei primcount) +glMultiDrawArraysEXT + flag unsupported + +#void glMultiDrawElementsEXT(GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount) +glMultiDrawElementsEXT + flag unsupported + +#void glMultiDrawArraysSUN(GLenum mode, GLint *first, GLsizei *count, GLsizei primcount) +glMultiDrawArraysSUN + flag unsupported + +#void glMultiDrawElementsSUN(GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount) +glMultiDrawElementsSUN + flag unsupported + +#void glDeleteFencesNV(GLsizei n, const GLuint *fences) +glDeleteFencesNV + dir fences in + len fences (n * sizeof(GLuint)) + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#void glGenFencesNV(GLsizei n, GLuint *fences) +glGenFencesNV + dir fences in + len fences (n * sizeof(GLuint)) + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#void glGetFenceivNV(GLuint fence, GLenum pname, GLint *params) +glGetFenceivNV + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLint)) + +#void glGetDriverControlsQCOM(GLint *num, GLsizei size, GLuint *driverControls) +glGetDriverControlsQCOM + dir num out + len num (1 * sizeof(GLint)) + dir driverControls out + len driverControls (size * sizeof(GLuint)) + +#void glGetDriverControlStringQCOM(GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString) +glGetDriverControlStringQCOM + dir length out + len length (1 * sizeof(GLsizei)) + dir driverControlString out + len driverControlString (1 * sizeof(GLchar)) + +#void glExtGetTexturesQCOM(GLuint *textures, GLint maxTextures, GLint *numTextures) +glExtGetTexturesQCOM + dir textures out + len textures (maxTextures * sizeof(GLuint)) + dir numTextures out + len numTextures (1 * sizeof(GLint)) + +#void glExtGetBuffersQCOM(GLuint *buffers, GLint maxBuffers, GLint *numBuffers) +glExtGetBuffersQCOM + dir buffers out + len buffers (maxBuffers * sizeof(GLuint)) + dir numBuffers out + len numBuffers (1 * sizeof(GLint)) + +#void glExtGetRenderbuffersQCOM(GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers) +glExtGetRenderbuffersQCOM + dir renderbuffers out + len renderbuffers (maxRenderbuffers * sizeof(GLuint)) + dir numRenderbuffers out + len numRenderbuffers (1 * sizeof(GLint)) + +#void glExtGetFramebuffersQCOM(GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers) +glExtGetFramebuffersQCOM + dir framebuffers out + len framebuffers (maxFramebuffers * sizeof(GLuint)) + dir numFramebuffers out + len numFramebuffers (1 * sizeof(GLint)) + +#void glExtGetTexLevelParameterivQCOM(GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params) +glExtGetTexLevelParameterivQCOM + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLint)) + +#void glExtGetTexSubImageQCOM(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels) +glExtGetTexSubImageQCOM + dir texels out + len texels (depth * pixelDataSize(self, width, height, format, type, 0)) + +#void glExtGetBufferPointervQCOM(GLenum target, GLvoid **params) +glExtGetBufferPointervQCOM + flag unsupported + +#void glExtGetShadersQCOM(GLuint *shaders, GLint maxShaders, GLint *numShaders) +glExtGetShadersQCOM + dir shaders out + len shaders (maxShaders * sizeof(GLuint)) + dir numShaders out + len numShaders (1 * sizeof(GLint)) + +#void glExtGetProgramsQCOM(GLuint *programs, GLint maxPrograms, GLint *numPrograms) +glExtGetProgramsQCOM + dir programs out + len programs (maxPrograms * sizeof(GLuint)) + dir numPrograms out + len numPrograms (1 * sizeof(GLint)) + +#void glExtGetProgramBinarySourceQCOM(GLuint program, GLenum shadertype, GLchar *source, GLint *length) +glExtGetProgramBinarySourceQCOM + flag unsupported diff --git a/emulator/opengl/system/GLESv1_enc/gl.in b/emulator/opengl/system/GLESv1_enc/gl.in new file mode 100644 index 0000000..4340608 --- /dev/null +++ b/emulator/opengl/system/GLESv1_enc/gl.in @@ -0,0 +1,299 @@ +GL_ENTRY(void, glAlphaFunc, GLenum func, GLclampf ref) +GL_ENTRY(void, glClearColor, GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) +GL_ENTRY(void, glClearDepthf, GLclampf depth) +GL_ENTRY(void, glClipPlanef, GLenum plane, const GLfloat *equation) +GL_ENTRY(void, glColor4f, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) +GL_ENTRY(void, glDepthRangef, GLclampf zNear, GLclampf zFar) +GL_ENTRY(void, glFogf, GLenum pname, GLfloat param) +GL_ENTRY(void, glFogfv, GLenum pname, const GLfloat *params) +GL_ENTRY(void, glFrustumf, GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) +GL_ENTRY(void, glGetClipPlanef, GLenum pname, GLfloat* eqn) +GL_ENTRY(void, glGetFloatv, GLenum pname, GLfloat *params) +GL_ENTRY(void, glGetLightfv, GLenum light, GLenum pname, GLfloat *params) +GL_ENTRY(void, glGetMaterialfv, GLenum face, GLenum pname, GLfloat *params) +GL_ENTRY(void, glGetTexEnvfv, GLenum env, GLenum pname, GLfloat *params) +GL_ENTRY(void, glGetTexParameterfv, GLenum target, GLenum pname, GLfloat *params) +GL_ENTRY(void, glLightModelf, GLenum pname, GLfloat param) +GL_ENTRY(void, glLightModelfv, GLenum pname, const GLfloat *params) +GL_ENTRY(void, glLightf, GLenum light, GLenum pname, GLfloat param) +GL_ENTRY(void, glLightfv, GLenum light, GLenum pname, const GLfloat *params) +GL_ENTRY(void, glLineWidth, GLfloat width) +GL_ENTRY(void, glLoadMatrixf, const GLfloat *m) +GL_ENTRY(void, glMaterialf, GLenum face, GLenum pname, GLfloat param) +GL_ENTRY(void, glMaterialfv, GLenum face, GLenum pname, const GLfloat *params) +GL_ENTRY(void, glMultMatrixf, const GLfloat *m) +GL_ENTRY(void, glMultiTexCoord4f, GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) +GL_ENTRY(void, glNormal3f, GLfloat nx, GLfloat ny, GLfloat nz) +GL_ENTRY(void, glOrthof, GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) +GL_ENTRY(void, glPointParameterf, GLenum pname, GLfloat param) +GL_ENTRY(void, glPointParameterfv, GLenum pname, const GLfloat *params) +GL_ENTRY(void, glPointSize, GLfloat size) +GL_ENTRY(void, glPolygonOffset, GLfloat factor, GLfloat units) +GL_ENTRY(void, glRotatef, GLfloat angle, GLfloat x, GLfloat y, GLfloat z) +GL_ENTRY(void, glScalef, GLfloat x, GLfloat y, GLfloat z) +GL_ENTRY(void, glTexEnvf, GLenum target, GLenum pname, GLfloat param) +GL_ENTRY(void, glTexEnvfv, GLenum target, GLenum pname, const GLfloat *params) +GL_ENTRY(void, glTexParameterf, GLenum target, GLenum pname, GLfloat param) +GL_ENTRY(void, glTexParameterfv, GLenum target, GLenum pname, const GLfloat *params) +GL_ENTRY(void, glTranslatef, GLfloat x, GLfloat y, GLfloat z) +GL_ENTRY(void, glActiveTexture, GLenum texture) +GL_ENTRY(void, glAlphaFuncx, GLenum func, GLclampx ref) +GL_ENTRY(void, glBindBuffer, GLenum target, GLuint buffer) +GL_ENTRY(void, glBindTexture, GLenum target, GLuint texture) +GL_ENTRY(void, glBlendFunc, GLenum sfactor, GLenum dfactor) +GL_ENTRY(void, glBufferData, GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage) +GL_ENTRY(void, glBufferSubData, GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data) +GL_ENTRY(void, glClear, GLbitfield mask) +GL_ENTRY(void, glClearColorx, GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha) +GL_ENTRY(void, glClearDepthx, GLclampx depth) +GL_ENTRY(void, glClearStencil, GLint s) +GL_ENTRY(void, glClientActiveTexture, GLenum texture) +GL_ENTRY(void, glColor4ub, GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) +GL_ENTRY(void, glColor4x, GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha) +GL_ENTRY(void, glColorMask, GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) +GL_ENTRY(void, glColorPointer, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) +GL_ENTRY(void, glCompressedTexImage2D, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) +GL_ENTRY(void, glCompressedTexSubImage2D, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data) +GL_ENTRY(void, glCopyTexImage2D, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) +GL_ENTRY(void, glCopyTexSubImage2D, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) +GL_ENTRY(void, glCullFace, GLenum mode) +GL_ENTRY(void, glDeleteBuffers, GLsizei n, const GLuint *buffers) +GL_ENTRY(void, glDeleteTextures, GLsizei n, const GLuint *textures) +GL_ENTRY(void, glDepthFunc, GLenum func) +GL_ENTRY(void, glDepthMask, GLboolean flag) +GL_ENTRY(void, glDepthRangex, GLclampx zNear, GLclampx zFar) +GL_ENTRY(void, glDisable, GLenum cap) +GL_ENTRY(void, glDisableClientState, GLenum array) +GL_ENTRY(void, glDrawArrays, GLenum mode, GLint first, GLsizei count) +GL_ENTRY(void, glDrawElements, GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) +GL_ENTRY(void, glEnable, GLenum cap) +GL_ENTRY(void, glEnableClientState, GLenum array) +GL_ENTRY(void, glFinish, void) +GL_ENTRY(void, glFlush, void) +GL_ENTRY(void, glFogx, GLenum pname, GLfixed param) +GL_ENTRY(void, glFogxv, GLenum pname, const GLfixed *params) +GL_ENTRY(void, glFrontFace, GLenum mode) +GL_ENTRY(void, glFrustumx, GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) +GL_ENTRY(void, glGetBooleanv, GLenum pname, GLboolean *params) +GL_ENTRY(void, glGetBufferParameteriv, GLenum target, GLenum pname, GLint *params) +GL_ENTRY(void, glClipPlanex, GLenum pname, const GLfixed * eqn) +GL_ENTRY(void, glGenBuffers, GLsizei n, GLuint *buffers) +GL_ENTRY(void, glGenTextures, GLsizei n, GLuint *textures) +GL_ENTRY(GLenum, glGetError, void) +GL_ENTRY(void, glGetFixedv, GLenum pname, GLfixed *params) +GL_ENTRY(void, glGetIntegerv, GLenum pname, GLint *params) +GL_ENTRY(void, glGetLightxv, GLenum light, GLenum pname, GLfixed *params) +GL_ENTRY(void, glGetMaterialxv, GLenum face, GLenum pname, GLfixed *params) +GL_ENTRY(void, glGetPointerv, GLenum pname, GLvoid **params) +GL_ENTRY(const GLubyte *, glGetString, GLenum name) +GL_ENTRY(void, glGetTexEnviv, GLenum env, GLenum pname, GLint *params) +GL_ENTRY(void, glGetTexEnvxv, GLenum env, GLenum pname, GLfixed *params) +GL_ENTRY(void, glGetTexParameteriv, GLenum target, GLenum pname, GLint *params) +GL_ENTRY(void, glGetTexParameterxv, GLenum target, GLenum pname, GLfixed *params) +GL_ENTRY(void, glHint, GLenum target, GLenum mode) +GL_ENTRY(GLboolean, glIsBuffer, GLuint buffer) +GL_ENTRY(GLboolean, glIsEnabled, GLenum cap) +GL_ENTRY(GLboolean, glIsTexture, GLuint texture) +GL_ENTRY(void, glLightModelx, GLenum pname, GLfixed param) +GL_ENTRY(void, glLightModelxv, GLenum pname, const GLfixed *params) +GL_ENTRY(void, glLightx, GLenum light, GLenum pname, GLfixed param) +GL_ENTRY(void, glLightxv, GLenum light, GLenum pname, const GLfixed *params) +GL_ENTRY(void, glLineWidthx, GLfixed width) +GL_ENTRY(void, glLoadIdentity, void) +GL_ENTRY(void, glLoadMatrixx, const GLfixed *m) +GL_ENTRY(void, glLogicOp, GLenum opcode) +GL_ENTRY(void, glMaterialx, GLenum face, GLenum pname, GLfixed param) +GL_ENTRY(void, glMaterialxv, GLenum face, GLenum pname, const GLfixed *params) +GL_ENTRY(void, glMatrixMode, GLenum mode) +GL_ENTRY(void, glMultMatrixx, const GLfixed *m) +GL_ENTRY(void, glMultiTexCoord4x, GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q) +GL_ENTRY(void, glNormal3x, GLfixed nx, GLfixed ny, GLfixed nz) +GL_ENTRY(void, glNormalPointer, GLenum type, GLsizei stride, const GLvoid *pointer) +GL_ENTRY(void, glOrthox, GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) +GL_ENTRY(void, glPixelStorei, GLenum pname, GLint param) +GL_ENTRY(void, glPointParameterx, GLenum pname, GLfixed param) +GL_ENTRY(void, glPointParameterxv, GLenum pname, const GLfixed *params) +GL_ENTRY(void, glPointSizex, GLfixed size) +GL_ENTRY(void, glPolygonOffsetx, GLfixed factor, GLfixed units) +GL_ENTRY(void, glPopMatrix, void) +GL_ENTRY(void, glPushMatrix, void) +GL_ENTRY(void, glReadPixels, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) +GL_ENTRY(void, glRotatex, GLfixed angle, GLfixed x, GLfixed y, GLfixed z) +GL_ENTRY(void, glSampleCoverage, GLclampf value, GLboolean invert) +GL_ENTRY(void, glSampleCoveragex, GLclampx value, GLboolean invert) +GL_ENTRY(void, glScalex, GLfixed x, GLfixed y, GLfixed z) +GL_ENTRY(void, glScissor, GLint x, GLint y, GLsizei width, GLsizei height) +GL_ENTRY(void, glShadeModel, GLenum mode) +GL_ENTRY(void, glStencilFunc, GLenum func, GLint ref, GLuint mask) +GL_ENTRY(void, glStencilMask, GLuint mask) +GL_ENTRY(void, glStencilOp, GLenum fail, GLenum zfail, GLenum zpass) +GL_ENTRY(void, glTexCoordPointer, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) +GL_ENTRY(void, glTexEnvi, GLenum target, GLenum pname, GLint param) +GL_ENTRY(void, glTexEnvx, GLenum target, GLenum pname, GLfixed param) +GL_ENTRY(void, glTexEnviv, GLenum target, GLenum pname, const GLint *params) +GL_ENTRY(void, glTexEnvxv, GLenum target, GLenum pname, const GLfixed *params) +GL_ENTRY(void, glTexImage2D, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels) +GL_ENTRY(void, glTexParameteri, GLenum target, GLenum pname, GLint param) +GL_ENTRY(void, glTexParameterx, GLenum target, GLenum pname, GLfixed param) +GL_ENTRY(void, glTexParameteriv, GLenum target, GLenum pname, const GLint *params) +GL_ENTRY(void, glTexParameterxv, GLenum target, GLenum pname, const GLfixed *params) +GL_ENTRY(void, glTexSubImage2D, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels) +GL_ENTRY(void, glTranslatex, GLfixed x, GLfixed y, GLfixed z) +GL_ENTRY(void, glVertexPointer, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) +GL_ENTRY(void, glViewport, GLint x, GLint y, GLsizei width, GLsizei height) +GL_ENTRY(void, glPointSizePointerOES, GLenum type, GLsizei stride, const GLvoid *pointer) + +GL_ENTRY(void, glVertexPointerOffset, GLint size, GLenum type, GLsizei stride, GLuint offset) +GL_ENTRY(void, glColorPointerOffset, GLint size, GLenum type, GLsizei stride, GLuint offset) +GL_ENTRY(void, glNormalPointerOffset, GLenum type, GLsizei stride, GLuint offset) +GL_ENTRY(void, glPointSizePointerOffset, GLenum type, GLsizei stride, GLuint offset) +GL_ENTRY(void, glTexCoordPointerOffset, GLint size, GLenum type, GLsizei stride, GLuint offset) +GL_ENTRY(void, glWeightPointerOffset, GLint size, GLenum type, GLsizei stride, GLuint offset) +GL_ENTRY(void, glMatrixIndexPointerOffset, GLint size, GLenum type, GLsizei stride, GLuint offset) + +GL_ENTRY(void, glVertexPointerData, GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen) +GL_ENTRY(void, glColorPointerData, GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen) +GL_ENTRY(void, glNormalPointerData, GLenum type, GLsizei stride, void * data, GLuint datalen) +GL_ENTRY(void, glTexCoordPointerData, GLint unit, GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen) +GL_ENTRY(void, glPointSizePointerData, GLenum type, GLsizei stride, void * data, GLuint datalen) +GL_ENTRY(void, glWeightPointerData, GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen) +GL_ENTRY(void, glMatrixIndexPointerData, GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen) + +GL_ENTRY(void, glDrawElementsOffset, GLenum mode, GLsizei count, GLenum type, GLuint offset) +GL_ENTRY(void, glDrawElementsData, GLenum mode, GLsizei count, GLenum type, void *data, GLuint datalen) +GL_ENTRY(void, glGetCompressedTextureFormats, int count, GLint *formats); + +GL_ENTRY(int, glFinishRoundTrip, void) + +#opengl extensions + +GL_ENTRY(void, glBlendEquationSeparateOES, GLenum modeRGB, GLenum modeAlpha) +GL_ENTRY(void, glBlendFuncSeparateOES, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) +GL_ENTRY(void, glBlendEquationOES, GLenum mode) +GL_ENTRY(void, glDrawTexsOES, GLshort x, GLshort y, GLshort z, GLshort width, GLshort height) +GL_ENTRY(void, glDrawTexiOES, GLint x, GLint y, GLint z, GLint width, GLint height) +GL_ENTRY(void, glDrawTexxOES, GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height) +GL_ENTRY(void, glDrawTexsvOES, const GLshort *coords) +GL_ENTRY(void, glDrawTexivOES, const GLint *coords) +GL_ENTRY(void, glDrawTexxvOES, const GLfixed *coords) +GL_ENTRY(void, glDrawTexfOES, GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height) +GL_ENTRY(void, glDrawTexfvOES, const GLfloat *coords) +GL_ENTRY(void, glEGLImageTargetTexture2DOES, GLenum target, GLeglImageOES image) +GL_ENTRY(void, glEGLImageTargetRenderbufferStorageOES, GLenum target, GLeglImageOES image) +GL_ENTRY(void, glAlphaFuncxOES, GLenum func, GLclampx ref) +GL_ENTRY(void, glClearColorxOES, GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha) +GL_ENTRY(void, glClearDepthxOES, GLclampx depth) +GL_ENTRY(void, glClipPlanexOES, GLenum plane, const GLfixed * equation) +GL_ENTRY(void, glClipPlanexIMG, GLenum plane, const GLfixed * equation) +GL_ENTRY(void, glColor4xOES, GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha) +GL_ENTRY(void, glDepthRangexOES, GLclampx zNear, GLclampx zFar) +GL_ENTRY(void, glFogxOES, GLenum pname, GLfixed param) +GL_ENTRY(void, glFogxvOES, GLenum pname, const GLfixed *params) +GL_ENTRY(void, glFrustumxOES, GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) +GL_ENTRY(void, glGetClipPlanexOES, GLenum pname, GLfixed* eqn) +GL_ENTRY(void, glGetClipPlanex, GLenum pname, GLfixed* eqn) +GL_ENTRY(void, glGetFixedvOES, GLenum pname, GLfixed *params) +GL_ENTRY(void, glGetLightxvOES, GLenum light, GLenum pname, GLfixed *params) +GL_ENTRY(void, glGetMaterialxvOES, GLenum face, GLenum pname, GLfixed *params) +GL_ENTRY(void, glGetTexEnvxvOES, GLenum env, GLenum pname, GLfixed *params) +GL_ENTRY(void, glGetTexParameterxvOES, GLenum target, GLenum pname, GLfixed *params) +GL_ENTRY(void, glLightModelxOES, GLenum pname, GLfixed param) +GL_ENTRY(void, glLightModelxvOES, GLenum pname, const GLfixed *params) +GL_ENTRY(void, glLightxOES, GLenum light, GLenum pname, GLfixed param) +GL_ENTRY(void, glLightxvOES, GLenum light, GLenum pname, const GLfixed *params) +GL_ENTRY(void, glLineWidthxOES, GLfixed width) +GL_ENTRY(void, glLoadMatrixxOES, const GLfixed *m) +GL_ENTRY(void, glMaterialxOES, GLenum face, GLenum pname, GLfixed param) +GL_ENTRY(void, glMaterialxvOES, GLenum face, GLenum pname, const GLfixed *params) +GL_ENTRY(void, glMultMatrixxOES, const GLfixed *m) +GL_ENTRY(void, glMultiTexCoord4xOES, GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q) +GL_ENTRY(void, glNormal3xOES, GLfixed nx, GLfixed ny, GLfixed nz) +GL_ENTRY(void, glOrthoxOES, GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) +GL_ENTRY(void, glPointParameterxOES, GLenum pname, GLfixed param) +GL_ENTRY(void, glPointParameterxvOES, GLenum pname, const GLfixed *params) +GL_ENTRY(void, glPointSizexOES, GLfixed size) +GL_ENTRY(void, glPolygonOffsetxOES, GLfixed factor, GLfixed units) +GL_ENTRY(void, glRotatexOES, GLfixed angle, GLfixed x, GLfixed y, GLfixed z) +GL_ENTRY(void, glSampleCoveragexOES, GLclampx value, GLboolean invert) +GL_ENTRY(void, glScalexOES, GLfixed x, GLfixed y, GLfixed z) +GL_ENTRY(void, glTexEnvxOES, GLenum target, GLenum pname, GLfixed param) +GL_ENTRY(void, glTexEnvxvOES, GLenum target, GLenum pname, const GLfixed *params) +GL_ENTRY(void, glTexParameterxOES, GLenum target, GLenum pname, GLfixed param) +GL_ENTRY(void, glTexParameterxvOES, GLenum target, GLenum pname, const GLfixed *params) +GL_ENTRY(void, glTranslatexOES, GLfixed x, GLfixed y, GLfixed z) +GL_ENTRY(GLboolean, glIsRenderbufferOES, GLuint renderbuffer) +GL_ENTRY(void, glBindRenderbufferOES, GLenum target, GLuint renderbuffer) +GL_ENTRY(void, glDeleteRenderbuffersOES, GLsizei n, const GLuint* renderbuffers) +GL_ENTRY(void, glGenRenderbuffersOES, GLsizei n, GLuint* renderbuffers) +GL_ENTRY(void, glRenderbufferStorageOES, GLenum target, GLenum internalformat, GLsizei width, GLsizei height) +GL_ENTRY(void, glGetRenderbufferParameterivOES, GLenum target, GLenum pname, GLint* params) +GL_ENTRY(GLboolean, glIsFramebufferOES, GLuint framebuffer) +GL_ENTRY(void, glBindFramebufferOES, GLenum target, GLuint framebuffer) +GL_ENTRY(void, glDeleteFramebuffersOES, GLsizei n, const GLuint* framebuffers) +GL_ENTRY(void, glGenFramebuffersOES, GLsizei n, GLuint* framebuffers) +GL_ENTRY(GLenum, glCheckFramebufferStatusOES, GLenum target) +GL_ENTRY(void, glFramebufferRenderbufferOES, GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) +GL_ENTRY(void, glFramebufferTexture2DOES, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) +GL_ENTRY(void, glGetFramebufferAttachmentParameterivOES, GLenum target, GLenum attachment, GLenum pname, GLint* params) +GL_ENTRY(void, glGenerateMipmapOES, GLenum target) +GL_ENTRY(void*, glMapBufferOES, GLenum target, GLenum access) +GL_ENTRY(GLboolean, glUnmapBufferOES, GLenum target) +GL_ENTRY(void, glGetBufferPointervOES, GLenum target, GLenum pname, GLvoid* *params) +GL_ENTRY(void, glCurrentPaletteMatrixOES, GLuint matrixpaletteindex) +GL_ENTRY(void, glLoadPaletteFromModelViewMatrixOES, void) +GL_ENTRY(void, glMatrixIndexPointerOES, GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) +GL_ENTRY(void, glWeightPointerOES, GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) +GL_ENTRY(GLbitfield, glQueryMatrixxOES, GLfixed * mantissa, GLint * exponent) +GL_ENTRY(void, glDepthRangefOES, GLclampf zNear, GLclampf zFar) +GL_ENTRY(void, glFrustumfOES, GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) +GL_ENTRY(void, glOrthofOES, GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) +GL_ENTRY(void, glClipPlanefOES, GLenum plane, const GLfloat *equation) +GL_ENTRY(void, glClipPlanefIMG, GLenum plane, const GLfloat *equation) +GL_ENTRY(void, glGetClipPlanefOES, GLenum pname, GLfloat * eqn) +GL_ENTRY(void, glClearDepthfOES, GLclampf depth) +GL_ENTRY(void, glTexGenfOES, GLenum coord, GLenum pname, GLfloat param) +GL_ENTRY(void, glTexGenfvOES, GLenum coord, GLenum pname, const GLfloat *params) +GL_ENTRY(void, glTexGeniOES, GLenum coord, GLenum pname, GLint param) +GL_ENTRY(void, glTexGenivOES, GLenum coord, GLenum pname, const GLint *params) +GL_ENTRY(void, glTexGenxOES, GLenum coord, GLenum pname, GLfixed param) +GL_ENTRY(void, glTexGenxvOES, GLenum coord, GLenum pname, const GLfixed *params) +GL_ENTRY(void, glGetTexGenfvOES, GLenum coord, GLenum pname, GLfloat *params) +GL_ENTRY(void, glGetTexGenivOES, GLenum coord, GLenum pname, GLint *params) +GL_ENTRY(void, glGetTexGenxvOES, GLenum coord, GLenum pname, GLfixed *params) +GL_ENTRY(void, glBindVertexArrayOES, GLuint array) +GL_ENTRY(void, glDeleteVertexArraysOES, GLsizei n, const GLuint *arrays) +GL_ENTRY(void, glGenVertexArraysOES, GLsizei n, GLuint *arrays) +GL_ENTRY(GLboolean, glIsVertexArrayOES, GLuint array) +GL_ENTRY(void, glDiscardFramebufferEXT, GLenum target, GLsizei numAttachments, const GLenum *attachments) +GL_ENTRY(void, glMultiDrawArraysEXT, GLenum mode, GLint *first, GLsizei *count, GLsizei primcount) +GL_ENTRY(void, glMultiDrawElementsEXT, GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount) +GL_ENTRY(void, glMultiDrawArraysSUN, GLenum mode, GLint *first, GLsizei *count, GLsizei primcount) +GL_ENTRY(void, glMultiDrawElementsSUN, GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount) +GL_ENTRY(void, glRenderbufferStorageMultisampleIMG, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height) +GL_ENTRY(void, glFramebufferTexture2DMultisampleIMG, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples) +GL_ENTRY(void, glDeleteFencesNV, GLsizei n, const GLuint *fences) +GL_ENTRY(void, glGenFencesNV, GLsizei n, GLuint *fences) +GL_ENTRY(GLboolean, glIsFenceNV, GLuint fence) +GL_ENTRY(GLboolean, glTestFenceNV, GLuint fence) +GL_ENTRY(void, glGetFenceivNV, GLuint fence, GLenum pname, GLint *params) +GL_ENTRY(void, glFinishFenceNV, GLuint fence) +GL_ENTRY(void, glSetFenceNV, GLuint fence, GLenum condition) +GL_ENTRY(void, glGetDriverControlsQCOM, GLint *num, GLsizei size, GLuint *driverControls) +GL_ENTRY(void, glGetDriverControlStringQCOM, GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString) +GL_ENTRY(void, glEnableDriverControlQCOM, GLuint driverControl) +GL_ENTRY(void, glDisableDriverControlQCOM, GLuint driverControl) +GL_ENTRY(void, glExtGetTexturesQCOM, GLuint *textures, GLint maxTextures, GLint *numTextures) +GL_ENTRY(void, glExtGetBuffersQCOM, GLuint *buffers, GLint maxBuffers, GLint *numBuffers) +GL_ENTRY(void, glExtGetRenderbuffersQCOM, GLuint * renderbuffers, GLint maxRenderbuffers, GLint * numRenderbuffers) +GL_ENTRY(void, glExtGetFramebuffersQCOM, GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers) +GL_ENTRY(void, glExtGetTexLevelParameterivQCOM, GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params) +GL_ENTRY(void, glExtTexObjectStateOverrideiQCOM, GLenum target, GLenum pname, GLint param) +GL_ENTRY(void, glExtGetTexSubImageQCOM, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels) +GL_ENTRY(void, glExtGetBufferPointervQCOM, GLenum target, GLvoid* *params) +GL_ENTRY(void, glExtGetShadersQCOM, GLuint *shaders, GLint maxShaders, GLint *numShaders) +GL_ENTRY(void, glExtGetProgramsQCOM, GLuint *programs, GLint maxPrograms, GLint *numPrograms) +GL_ENTRY(GLboolean, glExtIsProgramBinaryQCOM, GLuint program) +GL_ENTRY(void, glExtGetProgramBinarySourceQCOM, GLuint program, GLenum shadertype, GLchar *source, GLint *length) +GL_ENTRY(void, glStartTilingQCOM, GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask) +GL_ENTRY(void, glEndTilingQCOM, GLbitfield preserveMask) + diff --git a/emulator/opengl/system/GLESv1_enc/gl.types b/emulator/opengl/system/GLESv1_enc/gl.types new file mode 100644 index 0000000..b269c01 --- /dev/null +++ b/emulator/opengl/system/GLESv1_enc/gl.types @@ -0,0 +1,33 @@ +GLbitfield 32 0x%08x false +GLboolean 8 %d false +GLclampf 32 %f false +GLclampx 32 0x%08x false +GLeglImageOES 32 %p false +GLenum 32 0x%08x false +GLfixed 32 0x%08x false +GLfloat 32 %f false +GLint 32 %d false +GLintptr 32 %p false +GLshort 16 %d false +GLsizei 32 %d false +GLsizeiptr 32 %p false +GLubyte 8 0x%02x false +GLuint 32 %u false +GLvoid 0 %x false +GLchar 8 %d false +GLenum* 32 0x%08x true +GLboolean* 32 0x%08x true +GLclampf* 32 0x%08x true +GLclampx* 32 0x%08x true +GLeglImageOES* 32 0x%08x true +GLfixed* 32 0x%08x true +GLfloat* 32 0x%08x true +GLint* 32 0x%08x true +GLshort* 32 0x%08x true +GLsizei* 32 0x%08x true +GLubyte* 32 0x%08x true +GLuint* 32 0x%08x true +GLvoid* 32 0x%08x true +GLchar* 32 0x%08x true +GLvoid** 32 0x%08x true +void* 32 0x%08x true diff --git a/emulator/opengl/system/GLESv1_enc/gl_types.h b/emulator/opengl/system/GLESv1_enc/gl_types.h new file mode 100644 index 0000000..36fabfb --- /dev/null +++ b/emulator/opengl/system/GLESv1_enc/gl_types.h @@ -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. +*/ +#ifndef __GL_TYPES__H +#define __GL_TYPES__H + +#include "gl_base_types.h" +#endif diff --git a/emulator/opengl/system/GLESv2/Android.mk b/emulator/opengl/system/GLESv2/Android.mk new file mode 100644 index 0000000..c299522 --- /dev/null +++ b/emulator/opengl/system/GLESv2/Android.mk @@ -0,0 +1,12 @@ +LOCAL_PATH := $(call my-dir) + +### GLESv2 implementation ########################################### +$(call emugl-begin-shared-library,libGLESv2_emulation) +$(call emugl-import,libOpenglSystemCommon libGLESv2_enc lib_renderControl_enc) + +LOCAL_CFLAGS += -DLOG_TAG=\"GLESv2_emulation\" -DGL_GLEXT_PROTOTYPES + +LOCAL_SRC_FILES := gl2.cpp +LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/egl + +$(call emugl-end-module) diff --git a/emulator/opengl/system/GLESv2/gl2.cpp b/emulator/opengl/system/GLESv2/gl2.cpp new file mode 100644 index 0000000..b32dd74 --- /dev/null +++ b/emulator/opengl/system/GLESv2/gl2.cpp @@ -0,0 +1,143 @@ +/* +* 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 "EGLClientIface.h" +#include "HostConnection.h" +#include "GL2Encoder.h" +#include "GLES/gl.h" +#include "GLES/glext.h" +#include "ErrorLog.h" +#include "gralloc_cb.h" +#include "ThreadInfo.h" + +//XXX: fix this macro to get the context from fast tls path +#define GET_CONTEXT GL2Encoder * ctx = getEGLThreadInfo()->hostConn->gl2Encoder(); + +#include "gl2_entry.cpp" + +//The functions table +#include "gl2_ftable.h" + + +static EGLClient_eglInterface * s_egl = NULL; +static EGLClient_glesInterface * s_gl = NULL; + +#define DEFINE_AND_VALIDATE_HOST_CONNECTION(ret) \ + HostConnection *hostCon = HostConnection::get(); \ + if (!hostCon) { \ + ALOGE("egl: Failed to get host connection\n"); \ + return ret; \ + } \ + renderControl_encoder_context_t *rcEnc = hostCon->rcEncoder(); \ + if (!rcEnc) { \ + ALOGE("egl: Failed to get renderControl encoder context\n"); \ + return ret; \ + } + +//GL extensions +void glEGLImageTargetTexture2DOES(void * self, GLenum target, GLeglImageOES image) +{ + DBG("glEGLImageTargetTexture2DOES v2 target=%#x img=%p\n", target, image); + //TODO: check error - we don't have a way to set gl error + android_native_buffer_t* native_buffer = (android_native_buffer_t*)image; + + if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) { + return; + } + + if (native_buffer->common.version != sizeof(android_native_buffer_t)) { + return; + } + + GET_CONTEXT; + DEFINE_AND_VALIDATE_HOST_CONNECTION(); + + ctx->override2DTextureTarget(target); + rcEnc->rcBindTexture(rcEnc, ((cb_handle_t *)(native_buffer->handle))->hostHandle); + ctx->restore2DTextureTarget(); + + return; +} + +void glEGLImageTargetRenderbufferStorageOES(void *self, GLenum target, GLeglImageOES image) +{ + DBG("glEGLImageTargetRenderbufferStorageOES v2 image=%p\n", image); + //TODO: check error - we don't have a way to set gl error + android_native_buffer_t* native_buffer = (android_native_buffer_t*)image; + + if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) { + return; + } + + if (native_buffer->common.version != sizeof(android_native_buffer_t)) { + return; + } + + DEFINE_AND_VALIDATE_HOST_CONNECTION(); + rcEnc->rcBindRenderbuffer(rcEnc, ((cb_handle_t *)(native_buffer->handle))->hostHandle); + + return; +} + +void * getProcAddress(const char * procname) +{ + // search in GL function table + for (int i=0; i<gl2_num_funcs; i++) { + if (!strcmp(gl2_funcs_by_name[i].name, procname)) { + return gl2_funcs_by_name[i].proc; + } + } + return NULL; +} + +void finish() +{ + glFinish(); +} + +const GLubyte *my_glGetString (void *self, GLenum name) +{ + if (s_egl) { + return (const GLubyte*)s_egl->getGLString(name); + } + return NULL; +} + +void init() +{ + GET_CONTEXT; + ctx->set_glEGLImageTargetTexture2DOES(glEGLImageTargetTexture2DOES); + ctx->set_glEGLImageTargetRenderbufferStorageOES(glEGLImageTargetRenderbufferStorageOES); + ctx->set_glGetString(my_glGetString); +} + +extern "C" { +EGLClient_glesInterface * init_emul_gles(EGLClient_eglInterface *eglIface) +{ + s_egl = eglIface; + + if (!s_gl) { + s_gl = new EGLClient_glesInterface(); + s_gl->getProcAddress = getProcAddress; + s_gl->finish = finish; + s_gl->init = init; + } + + return s_gl; +} +} //extern + + diff --git a/emulator/opengl/system/GLESv2_enc/Android.mk b/emulator/opengl/system/GLESv2_enc/Android.mk new file mode 100644 index 0000000..2a4d2f4 --- /dev/null +++ b/emulator/opengl/system/GLESv2_enc/Android.mk @@ -0,0 +1,18 @@ +LOCAL_PATH := $(call my-dir) + +### GLESv2_enc Encoder ########################################### +$(call emugl-begin-shared-library,libGLESv2_enc) + +LOCAL_SRC_FILES := \ + GL2EncoderUtils.cpp \ + GL2Encoder.cpp + +LOCAL_CFLAGS += -DLOG_TAG=\"emuglGLESv2_enc\" + +$(call emugl-gen-encoder,$(LOCAL_PATH),gl2) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) +$(call emugl-import,libOpenglCodecCommon) + +$(call emugl-end-module) + + diff --git a/emulator/opengl/system/GLESv2_enc/GL2Encoder.cpp b/emulator/opengl/system/GLESv2_enc/GL2Encoder.cpp new file mode 100644 index 0000000..d8fedf3 --- /dev/null +++ b/emulator/opengl/system/GLESv2_enc/GL2Encoder.cpp @@ -0,0 +1,1197 @@ +/* +* 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 "GL2Encoder.h" +#include <assert.h> +#include <ctype.h> + +#ifndef MIN +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#endif + +static GLubyte *gVendorString= (GLubyte *) "Android"; +static GLubyte *gRendererString= (GLubyte *) "Android HW-GLES 2.0"; +static GLubyte *gVersionString= (GLubyte *) "OpenGL ES 2.0"; +static GLubyte *gExtensionsString= (GLubyte *) ""; // no extensions at this point; + +#define SET_ERROR_IF(condition,err) if((condition)) { \ + ALOGE("%s:%s:%d GL error 0x%x\n", __FILE__, __FUNCTION__, __LINE__, err); \ + ctx->setError(err); \ + return; \ + } + + +#define RET_AND_SET_ERROR_IF(condition,err,ret) if((condition)) { \ + ALOGE("%s:%s:%d GL error 0x%x\n", __FILE__, __FUNCTION__, __LINE__, err); \ + ctx->setError(err); \ + return ret; \ + } + + +GL2Encoder::GL2Encoder(IOStream *stream) : gl2_encoder_context_t(stream) +{ + m_initialized = false; + m_state = NULL; + m_error = GL_NO_ERROR; + m_num_compressedTextureFormats = 0; + m_compressedTextureFormats = NULL; + //overrides + m_glFlush_enc = set_glFlush(s_glFlush); + m_glPixelStorei_enc = set_glPixelStorei(s_glPixelStorei); + m_glGetString_enc = set_glGetString(s_glGetString); + m_glBindBuffer_enc = set_glBindBuffer(s_glBindBuffer); + m_glBufferData_enc = set_glBufferData(s_glBufferData); + m_glBufferSubData_enc = set_glBufferSubData(s_glBufferSubData); + m_glDeleteBuffers_enc = set_glDeleteBuffers(s_glDeleteBuffers); + m_glDrawArrays_enc = set_glDrawArrays(s_glDrawArrays); + m_glDrawElements_enc = set_glDrawElements(s_glDrawElements); + m_glGetIntegerv_enc = set_glGetIntegerv(s_glGetIntegerv); + m_glGetFloatv_enc = set_glGetFloatv(s_glGetFloatv); + m_glGetBooleanv_enc = set_glGetBooleanv(s_glGetBooleanv); + m_glVertexAttribPointer_enc = set_glVertexAttribPointer(s_glVertexAtrribPointer); + m_glEnableVertexAttribArray_enc = set_glEnableVertexAttribArray(s_glEnableVertexAttribArray); + m_glDisableVertexAttribArray_enc = set_glDisableVertexAttribArray(s_glDisableVertexAttribArray); + m_glGetVertexAttribiv_enc = set_glGetVertexAttribiv(s_glGetVertexAttribiv); + m_glGetVertexAttribfv_enc = set_glGetVertexAttribfv(s_glGetVertexAttribfv); + m_glGetVertexAttribPointerv = set_glGetVertexAttribPointerv(s_glGetVertexAttribPointerv); + set_glShaderSource(s_glShaderSource); + set_glFinish(s_glFinish); + m_glGetError_enc = set_glGetError(s_glGetError); + m_glLinkProgram_enc = set_glLinkProgram(s_glLinkProgram); + m_glDeleteProgram_enc = set_glDeleteProgram(s_glDeleteProgram); + m_glGetUniformiv_enc = set_glGetUniformiv(s_glGetUniformiv); + m_glGetUniformfv_enc = set_glGetUniformfv(s_glGetUniformfv); + m_glCreateProgram_enc = set_glCreateProgram(s_glCreateProgram); + m_glCreateShader_enc = set_glCreateShader(s_glCreateShader); + m_glDeleteShader_enc = set_glDeleteShader(s_glDeleteShader); + m_glAttachShader_enc = set_glAttachShader(s_glAttachShader); + m_glDetachShader_enc = set_glDetachShader(s_glDetachShader); + m_glGetUniformLocation_enc = set_glGetUniformLocation(s_glGetUniformLocation); + m_glUseProgram_enc = set_glUseProgram(s_glUseProgram); + + m_glUniform1f_enc = set_glUniform1f(s_glUniform1f); + m_glUniform1fv_enc = set_glUniform1fv(s_glUniform1fv); + m_glUniform1i_enc = set_glUniform1i(s_glUniform1i); + m_glUniform1iv_enc = set_glUniform1iv(s_glUniform1iv); + m_glUniform2f_enc = set_glUniform2f(s_glUniform2f); + m_glUniform2fv_enc = set_glUniform2fv(s_glUniform2fv); + m_glUniform2i_enc = set_glUniform2i(s_glUniform2i); + m_glUniform2iv_enc = set_glUniform2iv(s_glUniform2iv); + m_glUniform3f_enc = set_glUniform3f(s_glUniform3f); + m_glUniform3fv_enc = set_glUniform3fv(s_glUniform3fv); + m_glUniform3i_enc = set_glUniform3i(s_glUniform3i); + m_glUniform3iv_enc = set_glUniform3iv(s_glUniform3iv); + m_glUniform4f_enc = set_glUniform4f(s_glUniform4f); + m_glUniform4fv_enc = set_glUniform4fv(s_glUniform4fv); + m_glUniform4i_enc = set_glUniform4i(s_glUniform4i); + m_glUniform4iv_enc = set_glUniform4iv(s_glUniform4iv); + m_glUniformMatrix2fv_enc = set_glUniformMatrix2fv(s_glUniformMatrix2fv); + m_glUniformMatrix3fv_enc = set_glUniformMatrix3fv(s_glUniformMatrix3fv); + m_glUniformMatrix4fv_enc = set_glUniformMatrix4fv(s_glUniformMatrix4fv); + + m_glActiveTexture_enc = set_glActiveTexture(s_glActiveTexture); + m_glBindTexture_enc = set_glBindTexture(s_glBindTexture); + m_glDeleteTextures_enc = set_glDeleteTextures(s_glDeleteTextures); + m_glGetTexParameterfv_enc = set_glGetTexParameterfv(s_glGetTexParameterfv); + m_glGetTexParameteriv_enc = set_glGetTexParameteriv(s_glGetTexParameteriv); + m_glTexParameterf_enc = set_glTexParameterf(s_glTexParameterf); + m_glTexParameterfv_enc = set_glTexParameterfv(s_glTexParameterfv); + m_glTexParameteri_enc = set_glTexParameteri(s_glTexParameteri); + m_glTexParameteriv_enc = set_glTexParameteriv(s_glTexParameteriv); +} + +GL2Encoder::~GL2Encoder() +{ + delete m_compressedTextureFormats; +} + +GLenum GL2Encoder::s_glGetError(void * self) +{ + GL2Encoder *ctx = (GL2Encoder *)self; + GLenum err = ctx->getError(); + if(err != GL_NO_ERROR) { + ctx->setError(GL_NO_ERROR); + return err; + } + + return ctx->m_glGetError_enc(self); + +} + +void GL2Encoder::s_glFlush(void *self) +{ + GL2Encoder *ctx = (GL2Encoder *) self; + ctx->m_glFlush_enc(self); + ctx->m_stream->flush(); +} + +const GLubyte *GL2Encoder::s_glGetString(void *self, GLenum name) +{ + GLubyte *retval = (GLubyte *) ""; + switch(name) { + case GL_VENDOR: + retval = gVendorString; + break; + case GL_RENDERER: + retval = gRendererString; + break; + case GL_VERSION: + retval = gVersionString; + break; + case GL_EXTENSIONS: + retval = gExtensionsString; + break; + } + return retval; +} + +void GL2Encoder::s_glPixelStorei(void *self, GLenum param, GLint value) +{ + GL2Encoder *ctx = (GL2Encoder *)self; + ctx->m_glPixelStorei_enc(ctx, param, value); + assert(ctx->m_state != NULL); + ctx->m_state->setPixelStore(param, value); +} + + +void GL2Encoder::s_glBindBuffer(void *self, GLenum target, GLuint id) +{ + GL2Encoder *ctx = (GL2Encoder *) self; + assert(ctx->m_state != NULL); + ctx->m_state->bindBuffer(target, id); + // TODO set error state if needed; + ctx->m_glBindBuffer_enc(self, target, id); +} + +void GL2Encoder::s_glBufferData(void * self, GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage) +{ + GL2Encoder *ctx = (GL2Encoder *) self; + GLuint bufferId = ctx->m_state->getBuffer(target); + SET_ERROR_IF(bufferId==0, GL_INVALID_OPERATION); + SET_ERROR_IF(size<0, GL_INVALID_VALUE); + + ctx->m_shared->updateBufferData(bufferId, size, (void*)data); + ctx->m_glBufferData_enc(self, target, size, data, usage); +} + +void GL2Encoder::s_glBufferSubData(void * self, GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) +{ + GL2Encoder *ctx = (GL2Encoder *) self; + GLuint bufferId = ctx->m_state->getBuffer(target); + SET_ERROR_IF(bufferId==0, GL_INVALID_OPERATION); + + GLenum res = ctx->m_shared->subUpdateBufferData(bufferId, offset, size, (void*)data); + SET_ERROR_IF(res, res); + + ctx->m_glBufferSubData_enc(self, target, offset, size, data); +} + +void GL2Encoder::s_glDeleteBuffers(void * self, GLsizei n, const GLuint * buffers) +{ + GL2Encoder *ctx = (GL2Encoder *) self; + SET_ERROR_IF(n<0, GL_INVALID_VALUE); + for (int i=0; i<n; i++) { + ctx->m_shared->deleteBufferData(buffers[i]); + ctx->m_glDeleteBuffers_enc(self,1,&buffers[i]); + } +} + +void GL2Encoder::s_glVertexAtrribPointer(void *self, GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * ptr) +{ + GL2Encoder *ctx = (GL2Encoder *)self; + assert(ctx->m_state != NULL); + ctx->m_state->setState(indx, size, type, normalized, stride, ptr); +} + +void GL2Encoder::s_glGetIntegerv(void *self, GLenum param, GLint *ptr) +{ + GL2Encoder *ctx = (GL2Encoder *) self; + assert(ctx->m_state != NULL); + GLClientState* state = ctx->m_state; + + switch (param) { + case GL_NUM_SHADER_BINARY_FORMATS: + *ptr = 0; + break; + case GL_SHADER_BINARY_FORMATS: + // do nothing + break; + + case GL_COMPRESSED_TEXTURE_FORMATS: { + GLint *compressedTextureFormats = ctx->getCompressedTextureFormats(); + if (ctx->m_num_compressedTextureFormats > 0 && + compressedTextureFormats != NULL) { + memcpy(ptr, compressedTextureFormats, + ctx->m_num_compressedTextureFormats * sizeof(GLint)); + } + break; + } + + case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: + case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: + case GL_MAX_TEXTURE_IMAGE_UNITS: + ctx->m_glGetIntegerv_enc(self, param, ptr); + *ptr = MIN(*ptr, GLClientState::MAX_TEXTURE_UNITS); + break; + + case GL_TEXTURE_BINDING_2D: + *ptr = state->getBoundTexture(GL_TEXTURE_2D); + break; + case GL_TEXTURE_BINDING_EXTERNAL_OES: + *ptr = state->getBoundTexture(GL_TEXTURE_EXTERNAL_OES); + break; + + default: + if (!ctx->m_state->getClientStateParameter<GLint>(param, ptr)) { + ctx->m_glGetIntegerv_enc(self, param, ptr); + } + break; + } +} + + +void GL2Encoder::s_glGetFloatv(void *self, GLenum param, GLfloat *ptr) +{ + GL2Encoder *ctx = (GL2Encoder *)self; + assert(ctx->m_state != NULL); + GLClientState* state = ctx->m_state; + + switch (param) { + case GL_NUM_SHADER_BINARY_FORMATS: + *ptr = 0; + break; + case GL_SHADER_BINARY_FORMATS: + // do nothing + break; + + case GL_COMPRESSED_TEXTURE_FORMATS: { + GLint *compressedTextureFormats = ctx->getCompressedTextureFormats(); + if (ctx->m_num_compressedTextureFormats > 0 && + compressedTextureFormats != NULL) { + for (int i = 0; i < ctx->m_num_compressedTextureFormats; i++) { + ptr[i] = (GLfloat) compressedTextureFormats[i]; + } + } + break; + } + + case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: + case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: + case GL_MAX_TEXTURE_IMAGE_UNITS: + ctx->m_glGetFloatv_enc(self, param, ptr); + *ptr = MIN(*ptr, (GLfloat)GLClientState::MAX_TEXTURE_UNITS); + break; + + case GL_TEXTURE_BINDING_2D: + *ptr = (GLfloat)state->getBoundTexture(GL_TEXTURE_2D); + break; + case GL_TEXTURE_BINDING_EXTERNAL_OES: + *ptr = (GLfloat)state->getBoundTexture(GL_TEXTURE_EXTERNAL_OES); + break; + + default: + if (!ctx->m_state->getClientStateParameter<GLfloat>(param, ptr)) { + ctx->m_glGetFloatv_enc(self, param, ptr); + } + break; + } +} + + +void GL2Encoder::s_glGetBooleanv(void *self, GLenum param, GLboolean *ptr) +{ + GL2Encoder *ctx = (GL2Encoder *)self; + assert(ctx->m_state != NULL); + GLClientState* state = ctx->m_state; + + switch (param) { + case GL_NUM_SHADER_BINARY_FORMATS: + *ptr = GL_FALSE; + break; + case GL_SHADER_BINARY_FORMATS: + // do nothing + break; + + case GL_COMPRESSED_TEXTURE_FORMATS: { + GLint *compressedTextureFormats = ctx->getCompressedTextureFormats(); + if (ctx->m_num_compressedTextureFormats > 0 && + compressedTextureFormats != NULL) { + for (int i = 0; i < ctx->m_num_compressedTextureFormats; i++) { + ptr[i] = compressedTextureFormats[i] != 0 ? GL_TRUE : GL_FALSE; + } + } + break; + } + + case GL_TEXTURE_BINDING_2D: + *ptr = state->getBoundTexture(GL_TEXTURE_2D) != 0 ? GL_TRUE : GL_FALSE; + break; + case GL_TEXTURE_BINDING_EXTERNAL_OES: + *ptr = state->getBoundTexture(GL_TEXTURE_EXTERNAL_OES) != 0 + ? GL_TRUE : GL_FALSE; + break; + + default: + if (!ctx->m_state->getClientStateParameter<GLboolean>(param, ptr)) { + ctx->m_glGetBooleanv_enc(self, param, ptr); + } + break; + } +} + + +void GL2Encoder::s_glEnableVertexAttribArray(void *self, GLuint index) +{ + GL2Encoder *ctx = (GL2Encoder *)self; + assert(ctx->m_state); + ctx->m_state->enable(index, 1); +} + +void GL2Encoder::s_glDisableVertexAttribArray(void *self, GLuint index) +{ + GL2Encoder *ctx = (GL2Encoder *)self; + assert(ctx->m_state); + ctx->m_state->enable(index, 0); +} + + +void GL2Encoder::s_glGetVertexAttribiv(void *self, GLuint index, GLenum pname, GLint *params) +{ + GL2Encoder *ctx = (GL2Encoder *)self; + assert(ctx->m_state); + + if (!ctx->m_state->getVertexAttribParameter<GLint>(index, pname, params)) { + ctx->m_glGetVertexAttribiv_enc(self, index, pname, params); + } +} + +void GL2Encoder::s_glGetVertexAttribfv(void *self, GLuint index, GLenum pname, GLfloat *params) +{ + GL2Encoder *ctx = (GL2Encoder *)self; + assert(ctx->m_state); + + if (!ctx->m_state->getVertexAttribParameter<GLfloat>(index, pname, params)) { + ctx->m_glGetVertexAttribfv_enc(self, index, pname, params); + } +} + +void GL2Encoder::s_glGetVertexAttribPointerv(void *self, GLuint index, GLenum pname, GLvoid **pointer) +{ + GL2Encoder *ctx = (GL2Encoder *)self; + if (ctx->m_state == NULL) return; + + const GLClientState::VertexAttribState *va_state = ctx->m_state->getState(index); + if (va_state != NULL) { + *pointer = va_state->data; + } +} + + +void GL2Encoder::sendVertexAttributes(GLint first, GLsizei count) +{ + assert(m_state); + + for (int i = 0; i < m_state->nLocations(); i++) { + bool enableDirty; + const GLClientState::VertexAttribState *state = m_state->getStateAndEnableDirty(i, &enableDirty); + + if (!state) { + continue; + } + + if (!enableDirty && !state->enabled) { + continue; + } + + + if (state->enabled) { + m_glEnableVertexAttribArray_enc(this, i); + + unsigned int datalen = state->elementSize * count; + int stride = state->stride == 0 ? state->elementSize : state->stride; + int firstIndex = stride * first; + + if (state->bufferObject == 0) { + this->glVertexAttribPointerData(this, i, state->size, state->type, state->normalized, state->stride, + (unsigned char *)state->data + firstIndex, datalen); + } else { + this->m_glBindBuffer_enc(this, GL_ARRAY_BUFFER, state->bufferObject); + this->glVertexAttribPointerOffset(this, i, state->size, state->type, state->normalized, state->stride, + (GLuint) state->data + firstIndex); + this->m_glBindBuffer_enc(this, GL_ARRAY_BUFFER, m_state->currentArrayVbo()); + } + } else { + this->m_glDisableVertexAttribArray_enc(this, i); + } + } +} + +void GL2Encoder::s_glDrawArrays(void *self, GLenum mode, GLint first, GLsizei count) +{ + GL2Encoder *ctx = (GL2Encoder *)self; + ctx->sendVertexAttributes(first, count); + ctx->m_glDrawArrays_enc(ctx, mode, 0, count); +} + + +void GL2Encoder::s_glDrawElements(void *self, GLenum mode, GLsizei count, GLenum type, const void *indices) +{ + + GL2Encoder *ctx = (GL2Encoder *)self; + assert(ctx->m_state != NULL); + SET_ERROR_IF(count<0, GL_INVALID_VALUE); + + bool has_immediate_arrays = false; + bool has_indirect_arrays = false; + int nLocations = ctx->m_state->nLocations(); + + for (int i = 0; i < nLocations; i++) { + const GLClientState::VertexAttribState *state = ctx->m_state->getState(i); + if (state->enabled) { + if (state->bufferObject != 0) { + has_indirect_arrays = true; + } else { + has_immediate_arrays = true; + } + } + } + + if (!has_immediate_arrays && !has_indirect_arrays) { + ALOGE("glDrawElements: no data bound to the command - ignoring\n"); + return; + } + + bool adjustIndices = true; + if (ctx->m_state->currentIndexVbo() != 0) { + if (!has_immediate_arrays) { + ctx->sendVertexAttributes(0, count); + ctx->m_glBindBuffer_enc(self, GL_ELEMENT_ARRAY_BUFFER, ctx->m_state->currentIndexVbo()); + ctx->glDrawElementsOffset(ctx, mode, count, type, (GLuint)indices); + adjustIndices = false; + } else { + BufferData * buf = ctx->m_shared->getBufferData(ctx->m_state->currentIndexVbo()); + ctx->m_glBindBuffer_enc(self, GL_ELEMENT_ARRAY_BUFFER, 0); + indices = (void*)((GLintptr)buf->m_fixedBuffer.ptr() + (GLintptr)indices); + } + } + if (adjustIndices) { + void *adjustedIndices = (void*)indices; + int minIndex = 0, maxIndex = 0; + + switch(type) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + GLUtils::minmax<unsigned char>((unsigned char *)indices, count, &minIndex, &maxIndex); + if (minIndex != 0) { + adjustedIndices = ctx->m_fixedBuffer.alloc(glSizeof(type) * count); + GLUtils::shiftIndices<unsigned char>((unsigned char *)indices, + (unsigned char *)adjustedIndices, + count, -minIndex); + } + break; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + GLUtils::minmax<unsigned short>((unsigned short *)indices, count, &minIndex, &maxIndex); + if (minIndex != 0) { + adjustedIndices = ctx->m_fixedBuffer.alloc(glSizeof(type) * count); + GLUtils::shiftIndices<unsigned short>((unsigned short *)indices, + (unsigned short *)adjustedIndices, + count, -minIndex); + } + break; + default: + ALOGE("unsupported index buffer type %d\n", type); + } + if (has_indirect_arrays || 1) { + ctx->sendVertexAttributes(minIndex, maxIndex - minIndex + 1); + ctx->glDrawElementsData(ctx, mode, count, type, adjustedIndices, + count * glSizeof(type)); + // XXX - OPTIMIZATION (see the other else branch) should be implemented + if(!has_indirect_arrays) { + //ALOGD("unoptimized drawelements !!!\n"); + } + } else { + // we are all direct arrays and immidate mode index array - + // rebuild the arrays and the index array; + ALOGE("glDrawElements: direct index & direct buffer data - will be implemented in later versions;\n"); + } + } +} + + +GLint * GL2Encoder::getCompressedTextureFormats() +{ + if (m_compressedTextureFormats == NULL) { + this->glGetIntegerv(this, GL_NUM_COMPRESSED_TEXTURE_FORMATS, + &m_num_compressedTextureFormats); + if (m_num_compressedTextureFormats > 0) { + // get number of texture formats; + m_compressedTextureFormats = new GLint[m_num_compressedTextureFormats]; + this->glGetCompressedTextureFormats(this, m_num_compressedTextureFormats, m_compressedTextureFormats); + } + } + return m_compressedTextureFormats; +} + +// Replace uses of samplerExternalOES with sampler2D, recording the names of +// modified shaders in data. Also remove +// #extension GL_OES_EGL_image_external : require +// statements. +// +// This implementation assumes the input has already been pre-processed. If not, +// a few cases will be mishandled: +// +// 1. "mySampler" will be incorrectly recorded as being a samplerExternalOES in +// the following code: +// #if 1 +// uniform sampler2D mySampler; +// #else +// uniform samplerExternalOES mySampler; +// #endif +// +// 2. Comments that look like sampler declarations will be incorrectly modified +// and recorded: +// // samplerExternalOES hahaFooledYou +// +// 3. However, GLSL ES does not have a concatentation operator, so things like +// this (valid in C) are invalid and not a problem: +// #define SAMPLER(TYPE, NAME) uniform sampler#TYPE NAME +// SAMPLER(ExternalOES, mySampler); +// +static bool replaceSamplerExternalWith2D(char* const str, ShaderData* const data) +{ + static const char STR_HASH_EXTENSION[] = "#extension"; + static const char STR_GL_OES_EGL_IMAGE_EXTERNAL[] = "GL_OES_EGL_image_external"; + static const char STR_SAMPLER_EXTERNAL_OES[] = "samplerExternalOES"; + static const char STR_SAMPLER2D_SPACE[] = "sampler2D "; + + // -- overwrite all "#extension GL_OES_EGL_image_external : xxx" statements + char* c = str; + while ((c = strstr(c, STR_HASH_EXTENSION))) { + char* start = c; + c += sizeof(STR_HASH_EXTENSION)-1; + while (isspace(*c) && *c != '\0') { + c++; + } + if (strncmp(c, STR_GL_OES_EGL_IMAGE_EXTERNAL, + sizeof(STR_GL_OES_EGL_IMAGE_EXTERNAL)-1) == 0) + { + // #extension statements are terminated by end of line + c = start; + while (*c != '\0' && *c != '\r' && *c != '\n') { + *c++ = ' '; + } + } + } + + // -- replace "samplerExternalOES" with "sampler2D" and record name + c = str; + while ((c = strstr(c, STR_SAMPLER_EXTERNAL_OES))) { + // Make sure "samplerExternalOES" isn't a substring of a larger token + if (c == str || !isspace(*(c-1))) { + c++; + continue; + } + char* sampler_start = c; + c += sizeof(STR_SAMPLER_EXTERNAL_OES)-1; + if (!isspace(*c) && *c != '\0') { + continue; + } + + // capture sampler name + while (isspace(*c) && *c != '\0') { + c++; + } + if (!isalpha(*c) && *c != '_') { + // not an identifier + return false; + } + char* name_start = c; + do { + c++; + } while (isalnum(*c) || *c == '_'); + data->samplerExternalNames.push_back( + android::String8(name_start, c - name_start)); + + // memcpy instead of strcpy since we don't want the NUL terminator + memcpy(sampler_start, STR_SAMPLER2D_SPACE, sizeof(STR_SAMPLER2D_SPACE)-1); + } + + return true; +} + +void GL2Encoder::s_glShaderSource(void *self, GLuint shader, GLsizei count, const GLchar **string, const GLint *length) +{ + GL2Encoder* ctx = (GL2Encoder*)self; + ShaderData* shaderData = ctx->m_shared->getShaderData(shader); + SET_ERROR_IF(!shaderData, GL_INVALID_VALUE); + + int len = glUtilsCalcShaderSourceLen((char**)string, (GLint*)length, count); + char *str = new char[len + 1]; + glUtilsPackStrings(str, (char**)string, (GLint*)length, count); + + // TODO: pre-process str before calling replaceSamplerExternalWith2D(). + // Perhaps we can borrow Mesa's pre-processor? + + if (!replaceSamplerExternalWith2D(str, shaderData)) { + delete str; + ctx->setError(GL_OUT_OF_MEMORY); + return; + } + + ctx->glShaderString(ctx, shader, str, len + 1); + delete str; +} + +void GL2Encoder::s_glFinish(void *self) +{ + GL2Encoder *ctx = (GL2Encoder *)self; + ctx->glFinishRoundTrip(self); +} + +void GL2Encoder::s_glLinkProgram(void * self, GLuint program) +{ + GL2Encoder *ctx = (GL2Encoder *)self; + ctx->m_glLinkProgram_enc(self, program); + + GLint linkStatus = 0; + ctx->glGetProgramiv(self,program,GL_LINK_STATUS,&linkStatus); + if (!linkStatus) + return; + + //get number of active uniforms in the program + GLint numUniforms=0; + ctx->glGetProgramiv(self, program, GL_ACTIVE_UNIFORMS, &numUniforms); + ctx->m_shared->initProgramData(program,numUniforms); + + //get the length of the longest uniform name + GLint maxLength=0; + ctx->glGetProgramiv(self, program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength); + + GLint size; + GLenum type; + GLchar *name = new GLchar[maxLength+1]; + GLint location; + //for each active uniform, get its size and starting location. + for (GLint i=0 ; i<numUniforms ; ++i) + { + ctx->glGetActiveUniform(self, program, i, maxLength, NULL, &size, &type, name); + location = ctx->m_glGetUniformLocation_enc(self, program, name); + ctx->m_shared->setProgramIndexInfo(program, i, location, size, type, name); + } + ctx->m_shared->setupLocationShiftWAR(program); + + delete[] name; +} + +void GL2Encoder::s_glDeleteProgram(void *self, GLuint program) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + ctx->m_glDeleteProgram_enc(self, program); + + ctx->m_shared->deleteProgramData(program); +} + +void GL2Encoder::s_glGetUniformiv(void *self, GLuint program, GLint location, GLint* params) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + SET_ERROR_IF(!ctx->m_shared->isProgram(program), GL_INVALID_VALUE); + SET_ERROR_IF(!ctx->m_shared->isProgramInitialized(program), GL_INVALID_OPERATION); + GLint hostLoc = ctx->m_shared->locationWARAppToHost(program, location); + SET_ERROR_IF(ctx->m_shared->getProgramUniformType(program,hostLoc)==0, GL_INVALID_OPERATION); + ctx->m_glGetUniformiv_enc(self, program, hostLoc, params); +} +void GL2Encoder::s_glGetUniformfv(void *self, GLuint program, GLint location, GLfloat* params) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + SET_ERROR_IF(!ctx->m_shared->isProgram(program), GL_INVALID_VALUE); + SET_ERROR_IF(!ctx->m_shared->isProgramInitialized(program), GL_INVALID_OPERATION); + GLint hostLoc = ctx->m_shared->locationWARAppToHost(program,location); + SET_ERROR_IF(ctx->m_shared->getProgramUniformType(program,hostLoc)==0, GL_INVALID_OPERATION); + ctx->m_glGetUniformfv_enc(self, program, hostLoc, params); +} + +GLuint GL2Encoder::s_glCreateProgram(void * self) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLuint program = ctx->m_glCreateProgram_enc(self); + if (program!=0) + ctx->m_shared->addProgramData(program); + return program; +} + +GLuint GL2Encoder::s_glCreateShader(void *self, GLenum shaderType) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLuint shader = ctx->m_glCreateShader_enc(self, shaderType); + if (shader != 0) { + if (!ctx->m_shared->addShaderData(shader)) { + ctx->m_glDeleteShader_enc(self, shader); + return 0; + } + } + return shader; +} + +void GL2Encoder::s_glDeleteShader(void *self, GLenum shader) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + ctx->m_glDeleteShader_enc(self,shader); + ctx->m_shared->unrefShaderData(shader); +} + +void GL2Encoder::s_glAttachShader(void *self, GLuint program, GLuint shader) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + ctx->m_glAttachShader_enc(self, program, shader); + ctx->m_shared->attachShader(program, shader); +} + +void GL2Encoder::s_glDetachShader(void *self, GLuint program, GLuint shader) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + ctx->m_glDetachShader_enc(self, program, shader); + ctx->m_shared->detachShader(program, shader); +} + +int GL2Encoder::s_glGetUniformLocation(void *self, GLuint program, const GLchar *name) +{ + if (!name) return -1; + + GL2Encoder *ctx = (GL2Encoder*)self; + + // if we need the uniform location WAR + // parse array index from the end of the name string + int arrIndex = 0; + bool needLocationWAR = ctx->m_shared->needUniformLocationWAR(program); + if (needLocationWAR) { + int namelen = strlen(name); + if (name[namelen-1] == ']') { + char *brace = strrchr(name,'['); + if (!brace || sscanf(brace+1,"%d",&arrIndex) != 1) { + return -1; + } + + } + } + + int hostLoc = ctx->m_glGetUniformLocation_enc(self, program, name); + if (hostLoc >= 0 && needLocationWAR) { + return ctx->m_shared->locationWARHostToApp(program, hostLoc, arrIndex); + } + return hostLoc; +} + +bool GL2Encoder::updateHostTexture2DBinding(GLenum texUnit, GLenum newTarget) +{ + if (newTarget != GL_TEXTURE_2D && newTarget != GL_TEXTURE_EXTERNAL_OES) + return false; + + m_state->setActiveTextureUnit(texUnit); + + GLenum oldTarget = m_state->getPriorityEnabledTarget(GL_TEXTURE_2D); + if (newTarget != oldTarget) { + if (newTarget == GL_TEXTURE_EXTERNAL_OES) { + m_state->disableTextureTarget(GL_TEXTURE_2D); + m_state->enableTextureTarget(GL_TEXTURE_EXTERNAL_OES); + } else { + m_state->disableTextureTarget(GL_TEXTURE_EXTERNAL_OES); + m_state->enableTextureTarget(GL_TEXTURE_2D); + } + m_glActiveTexture_enc(this, texUnit); + m_glBindTexture_enc(this, GL_TEXTURE_2D, + m_state->getBoundTexture(newTarget)); + return true; + } + + return false; +} + +void GL2Encoder::s_glUseProgram(void *self, GLuint program) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLClientState* state = ctx->m_state; + GLSharedGroupPtr shared = ctx->m_shared; + + ctx->m_glUseProgram_enc(self, program); + ctx->m_state->setCurrentProgram(program); + + GLenum origActiveTexture = state->getActiveTextureUnit(); + GLenum hostActiveTexture = origActiveTexture; + GLint samplerIdx = -1; + GLint samplerVal; + GLenum samplerTarget; + while ((samplerIdx = shared->getNextSamplerUniform(program, samplerIdx, &samplerVal, &samplerTarget)) != -1) { + if (samplerVal < 0 || samplerVal >= GLClientState::MAX_TEXTURE_UNITS) + continue; + if (ctx->updateHostTexture2DBinding(GL_TEXTURE0 + samplerVal, + samplerTarget)) + { + hostActiveTexture = GL_TEXTURE0 + samplerVal; + } + } + state->setActiveTextureUnit(origActiveTexture); + if (hostActiveTexture != origActiveTexture) { + ctx->m_glActiveTexture_enc(self, origActiveTexture); + } +} + +void GL2Encoder::s_glUniform1f(void *self , GLint location, GLfloat x) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform1f_enc(self, hostLoc, x); +} + +void GL2Encoder::s_glUniform1fv(void *self , GLint location, GLsizei count, const GLfloat* v) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform1fv_enc(self, hostLoc, count, v); +} + +void GL2Encoder::s_glUniform1i(void *self , GLint location, GLint x) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLClientState* state = ctx->m_state; + GLSharedGroupPtr shared = ctx->m_shared; + + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform1i_enc(self, hostLoc, x); + + GLenum target; + if (shared->setSamplerUniform(state->currentProgram(), location, x, &target)) { + GLenum origActiveTexture = state->getActiveTextureUnit(); + if (ctx->updateHostTexture2DBinding(GL_TEXTURE0 + x, target)) { + ctx->m_glActiveTexture_enc(self, origActiveTexture); + } + state->setActiveTextureUnit(origActiveTexture); + } +} + +void GL2Encoder::s_glUniform1iv(void *self , GLint location, GLsizei count, const GLint* v) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform1iv_enc(self, hostLoc, count, v); +} + +void GL2Encoder::s_glUniform2f(void *self , GLint location, GLfloat x, GLfloat y) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform2f_enc(self, hostLoc, x, y); +} + +void GL2Encoder::s_glUniform2fv(void *self , GLint location, GLsizei count, const GLfloat* v) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform2fv_enc(self, hostLoc, count, v); +} + +void GL2Encoder::s_glUniform2i(void *self , GLint location, GLint x, GLint y) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform2i_enc(self, hostLoc, x, y); +} + +void GL2Encoder::s_glUniform2iv(void *self , GLint location, GLsizei count, const GLint* v) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform2iv_enc(self, hostLoc, count, v); +} + +void GL2Encoder::s_glUniform3f(void *self , GLint location, GLfloat x, GLfloat y, GLfloat z) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform3f_enc(self, hostLoc, x, y, z); +} + +void GL2Encoder::s_glUniform3fv(void *self , GLint location, GLsizei count, const GLfloat* v) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform3fv_enc(self, hostLoc, count, v); +} + +void GL2Encoder::s_glUniform3i(void *self , GLint location, GLint x, GLint y, GLint z) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform3i_enc(self, hostLoc, x, y, z); +} + +void GL2Encoder::s_glUniform3iv(void *self , GLint location, GLsizei count, const GLint* v) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform3iv_enc(self, hostLoc, count, v); +} + +void GL2Encoder::s_glUniform4f(void *self , GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform4f_enc(self, hostLoc, x, y, z, w); +} + +void GL2Encoder::s_glUniform4fv(void *self , GLint location, GLsizei count, const GLfloat* v) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform4fv_enc(self, hostLoc, count, v); +} + +void GL2Encoder::s_glUniform4i(void *self , GLint location, GLint x, GLint y, GLint z, GLint w) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform4i_enc(self, hostLoc, x, y, z, w); +} + +void GL2Encoder::s_glUniform4iv(void *self , GLint location, GLsizei count, const GLint* v) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniform4iv_enc(self, hostLoc, count, v); +} + +void GL2Encoder::s_glUniformMatrix2fv(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniformMatrix2fv_enc(self, hostLoc, count, transpose, value); +} + +void GL2Encoder::s_glUniformMatrix3fv(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniformMatrix3fv_enc(self, hostLoc, count, transpose, value); +} + +void GL2Encoder::s_glUniformMatrix4fv(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) +{ + GL2Encoder *ctx = (GL2Encoder*)self; + GLint hostLoc = ctx->m_shared->locationWARAppToHost(ctx->m_state->currentProgram(),location); + ctx->m_glUniformMatrix4fv_enc(self, hostLoc, count, transpose, value); +} + +void GL2Encoder::s_glActiveTexture(void* self, GLenum texture) +{ + GL2Encoder* ctx = (GL2Encoder*)self; + GLClientState* state = ctx->m_state; + GLenum err; + + SET_ERROR_IF((err = state->setActiveTextureUnit(texture)) != GL_NO_ERROR, err); + + ctx->m_glActiveTexture_enc(ctx, texture); +} + +void GL2Encoder::s_glBindTexture(void* self, GLenum target, GLuint texture) +{ + GL2Encoder* ctx = (GL2Encoder*)self; + GLClientState* state = ctx->m_state; + GLenum err; + GLboolean firstUse; + + SET_ERROR_IF((err = state->bindTexture(target, texture, &firstUse)) != GL_NO_ERROR, err); + + if (target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES) { + ctx->m_glBindTexture_enc(ctx, target, texture); + return; + } + + GLenum priorityTarget = state->getPriorityEnabledTarget(GL_TEXTURE_2D); + + if (target == GL_TEXTURE_EXTERNAL_OES && firstUse) { + ctx->m_glBindTexture_enc(ctx, GL_TEXTURE_2D, texture); + ctx->m_glTexParameteri_enc(ctx, GL_TEXTURE_2D, + GL_TEXTURE_MIN_FILTER, GL_LINEAR); + ctx->m_glTexParameteri_enc(ctx, GL_TEXTURE_2D, + GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + ctx->m_glTexParameteri_enc(ctx, GL_TEXTURE_2D, + GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + if (target != priorityTarget) { + ctx->m_glBindTexture_enc(ctx, GL_TEXTURE_2D, + state->getBoundTexture(GL_TEXTURE_2D)); + } + } + + if (target == priorityTarget) { + ctx->m_glBindTexture_enc(ctx, GL_TEXTURE_2D, texture); + } +} + +void GL2Encoder::s_glDeleteTextures(void* self, GLsizei n, const GLuint* textures) +{ + GL2Encoder* ctx = (GL2Encoder*)self; + GLClientState* state = ctx->m_state; + + state->deleteTextures(n, textures); + ctx->m_glDeleteTextures_enc(ctx, n, textures); +} + +void GL2Encoder::s_glGetTexParameterfv(void* self, + GLenum target, GLenum pname, GLfloat* params) +{ + GL2Encoder* ctx = (GL2Encoder*)self; + const GLClientState* state = ctx->m_state; + + if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) { + ctx->override2DTextureTarget(target); + ctx->m_glGetTexParameterfv_enc(ctx, GL_TEXTURE_2D, pname, params); + ctx->restore2DTextureTarget(); + } else { + ctx->m_glGetTexParameterfv_enc(ctx, target, pname, params); + } +} + +void GL2Encoder::s_glGetTexParameteriv(void* self, + GLenum target, GLenum pname, GLint* params) +{ + GL2Encoder* ctx = (GL2Encoder*)self; + const GLClientState* state = ctx->m_state; + + switch (pname) { + case GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES: + *params = 1; + break; + + default: + if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) { + ctx->override2DTextureTarget(target); + ctx->m_glGetTexParameteriv_enc(ctx, GL_TEXTURE_2D, pname, params); + ctx->restore2DTextureTarget(); + } else { + ctx->m_glGetTexParameteriv_enc(ctx, target, pname, params); + } + break; + } +} + +static bool isValidTextureExternalParam(GLenum pname, GLenum param) +{ + switch (pname) { + case GL_TEXTURE_MIN_FILTER: + case GL_TEXTURE_MAG_FILTER: + return param == GL_NEAREST || param == GL_LINEAR; + + case GL_TEXTURE_WRAP_S: + case GL_TEXTURE_WRAP_T: + return param == GL_CLAMP_TO_EDGE; + + default: + return true; + } +} + +void GL2Encoder::s_glTexParameterf(void* self, + GLenum target, GLenum pname, GLfloat param) +{ + GL2Encoder* ctx = (GL2Encoder*)self; + const GLClientState* state = ctx->m_state; + + SET_ERROR_IF((target == GL_TEXTURE_EXTERNAL_OES && + !isValidTextureExternalParam(pname, (GLenum)param)), + GL_INVALID_ENUM); + + if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) { + ctx->override2DTextureTarget(target); + ctx->m_glTexParameterf_enc(ctx, GL_TEXTURE_2D, pname, param); + ctx->restore2DTextureTarget(); + } else { + ctx->m_glTexParameterf_enc(ctx, target, pname, param); + } +} + +void GL2Encoder::s_glTexParameterfv(void* self, + GLenum target, GLenum pname, const GLfloat* params) +{ + GL2Encoder* ctx = (GL2Encoder*)self; + const GLClientState* state = ctx->m_state; + + SET_ERROR_IF((target == GL_TEXTURE_EXTERNAL_OES && + !isValidTextureExternalParam(pname, (GLenum)params[0])), + GL_INVALID_ENUM); + + if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) { + ctx->override2DTextureTarget(target); + ctx->m_glTexParameterfv_enc(ctx, GL_TEXTURE_2D, pname, params); + ctx->restore2DTextureTarget(); + } else { + ctx->m_glTexParameterfv_enc(ctx, target, pname, params); + } +} + +void GL2Encoder::s_glTexParameteri(void* self, + GLenum target, GLenum pname, GLint param) +{ + GL2Encoder* ctx = (GL2Encoder*)self; + const GLClientState* state = ctx->m_state; + + SET_ERROR_IF((target == GL_TEXTURE_EXTERNAL_OES && + !isValidTextureExternalParam(pname, (GLenum)param)), + GL_INVALID_ENUM); + + if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) { + ctx->override2DTextureTarget(target); + ctx->m_glTexParameteri_enc(ctx, GL_TEXTURE_2D, pname, param); + ctx->restore2DTextureTarget(); + } else { + ctx->m_glTexParameteri_enc(ctx, target, pname, param); + } +} + +void GL2Encoder::s_glTexParameteriv(void* self, + GLenum target, GLenum pname, const GLint* params) +{ + GL2Encoder* ctx = (GL2Encoder*)self; + const GLClientState* state = ctx->m_state; + + SET_ERROR_IF((target == GL_TEXTURE_EXTERNAL_OES && + !isValidTextureExternalParam(pname, (GLenum)params[0])), + GL_INVALID_ENUM); + + if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) { + ctx->override2DTextureTarget(target); + ctx->m_glTexParameteriv_enc(ctx, GL_TEXTURE_2D, pname, params); + ctx->restore2DTextureTarget(); + } else { + ctx->m_glTexParameteriv_enc(ctx, target, pname, params); + } +} + +void GL2Encoder::override2DTextureTarget(GLenum target) +{ + if ((target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) && + target != m_state->getPriorityEnabledTarget(GL_TEXTURE_2D)) { + m_glBindTexture_enc(this, GL_TEXTURE_2D, + m_state->getBoundTexture(target)); + } +} + +void GL2Encoder::restore2DTextureTarget() +{ + GLenum priorityTarget = m_state->getPriorityEnabledTarget(GL_TEXTURE_2D); + m_glBindTexture_enc(this, GL_TEXTURE_2D, + m_state->getBoundTexture(priorityTarget)); +} diff --git a/emulator/opengl/system/GLESv2_enc/GL2Encoder.h b/emulator/opengl/system/GLESv2_enc/GL2Encoder.h new file mode 100644 index 0000000..f9235d7 --- /dev/null +++ b/emulator/opengl/system/GLESv2_enc/GL2Encoder.h @@ -0,0 +1,216 @@ +/* +* 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 _GL2_ENCODER_H_ +#define _GL2_ENCODER_H_ + +#include "gl2_enc.h" +#include "GLClientState.h" +#include "GLSharedGroup.h" +#include "FixedBuffer.h" + + +class GL2Encoder : public gl2_encoder_context_t { +public: + GL2Encoder(IOStream *stream); + virtual ~GL2Encoder(); + void setClientState(GLClientState *state) { + m_state = state; + } + void setSharedGroup(GLSharedGroupPtr shared){ m_shared = shared; } + const GLClientState *state() { return m_state; } + const GLSharedGroupPtr shared() { return m_shared; } + void flush() { m_stream->flush(); } + + void setInitialized(){ m_initialized = true; }; + bool isInitialized(){ return m_initialized; }; + + virtual void setError(GLenum error){ m_error = error; }; + virtual GLenum getError() { return m_error; }; + + void override2DTextureTarget(GLenum target); + void restore2DTextureTarget(); + +private: + + bool m_initialized; + GLClientState *m_state; + GLSharedGroupPtr m_shared; + GLenum m_error; + + GLint *m_compressedTextureFormats; + GLint m_num_compressedTextureFormats; + GLint *getCompressedTextureFormats(); + + FixedBuffer m_fixedBuffer; + + void sendVertexAttributes(GLint first, GLsizei count); + bool updateHostTexture2DBinding(GLenum texUnit, GLenum newTarget); + + glGetError_client_proc_t m_glGetError_enc; + static GLenum s_glGetError(void * self); + + glFlush_client_proc_t m_glFlush_enc; + static void s_glFlush(void * self); + + glPixelStorei_client_proc_t m_glPixelStorei_enc; + static void s_glPixelStorei(void *self, GLenum param, GLint value); + + glGetString_client_proc_t m_glGetString_enc; + static const GLubyte * s_glGetString(void *self, GLenum name); + + glBindBuffer_client_proc_t m_glBindBuffer_enc; + static void s_glBindBuffer(void *self, GLenum target, GLuint id); + + + glBufferData_client_proc_t m_glBufferData_enc; + static void s_glBufferData(void *self, GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage); + glBufferSubData_client_proc_t m_glBufferSubData_enc; + static void s_glBufferSubData(void *self, GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); + glDeleteBuffers_client_proc_t m_glDeleteBuffers_enc; + static void s_glDeleteBuffers(void *self, GLsizei n, const GLuint * buffers); + + glDrawArrays_client_proc_t m_glDrawArrays_enc; + static void s_glDrawArrays(void *self, GLenum mode, GLint first, GLsizei count); + + glDrawElements_client_proc_t m_glDrawElements_enc; + static void s_glDrawElements(void *self, GLenum mode, GLsizei count, GLenum type, const void *indices); + + + glGetIntegerv_client_proc_t m_glGetIntegerv_enc; + static void s_glGetIntegerv(void *self, GLenum pname, GLint *ptr); + + glGetFloatv_client_proc_t m_glGetFloatv_enc; + static void s_glGetFloatv(void *self, GLenum pname, GLfloat *ptr); + + glGetBooleanv_client_proc_t m_glGetBooleanv_enc; + static void s_glGetBooleanv(void *self, GLenum pname, GLboolean *ptr); + + glVertexAttribPointer_client_proc_t m_glVertexAttribPointer_enc; + static void s_glVertexAtrribPointer(void *self, GLuint indx, GLint size, GLenum type, + GLboolean normalized, GLsizei stride, const GLvoid * ptr); + + glEnableVertexAttribArray_client_proc_t m_glEnableVertexAttribArray_enc; + static void s_glEnableVertexAttribArray(void *self, GLuint index); + + glDisableVertexAttribArray_client_proc_t m_glDisableVertexAttribArray_enc; + static void s_glDisableVertexAttribArray(void *self, GLuint index); + + glGetVertexAttribiv_client_proc_t m_glGetVertexAttribiv_enc; + static void s_glGetVertexAttribiv(void *self, GLuint index, GLenum pname, GLint *params); + + glGetVertexAttribfv_client_proc_t m_glGetVertexAttribfv_enc; + static void s_glGetVertexAttribfv(void *self, GLuint index, GLenum pname, GLfloat *params); + + glGetVertexAttribPointerv_client_proc_t m_glGetVertexAttribPointerv; + static void s_glGetVertexAttribPointerv(void *self, GLuint index, GLenum pname, GLvoid **pointer); + + static void s_glShaderSource(void *self, GLuint shader, GLsizei count, const GLchar **string, const GLint *length); + + static void s_glFinish(void *self); + + glLinkProgram_client_proc_t m_glLinkProgram_enc; + static void s_glLinkProgram(void *self, GLuint program); + + glDeleteProgram_client_proc_t m_glDeleteProgram_enc; + static void s_glDeleteProgram(void * self, GLuint program); + + glGetUniformiv_client_proc_t m_glGetUniformiv_enc; + static void s_glGetUniformiv(void *self, GLuint program, GLint location , GLint *params); + + glGetUniformfv_client_proc_t m_glGetUniformfv_enc; + static void s_glGetUniformfv(void *self, GLuint program, GLint location , GLfloat *params); + + glCreateProgram_client_proc_t m_glCreateProgram_enc; + static GLuint s_glCreateProgram(void *self); + + glCreateShader_client_proc_t m_glCreateShader_enc; + static GLuint s_glCreateShader(void *self, GLenum shaderType); + + glDeleteShader_client_proc_t m_glDeleteShader_enc; + static void s_glDeleteShader(void *self, GLuint shader); + + glAttachShader_client_proc_t m_glAttachShader_enc; + static void s_glAttachShader(void *self, GLuint program, GLuint shader); + + glDetachShader_client_proc_t m_glDetachShader_enc; + static void s_glDetachShader(void *self, GLuint program, GLuint shader); + + glGetUniformLocation_client_proc_t m_glGetUniformLocation_enc; + static int s_glGetUniformLocation(void *self, GLuint program, const GLchar *name); + glUseProgram_client_proc_t m_glUseProgram_enc; + + glUniform1f_client_proc_t m_glUniform1f_enc; + glUniform1fv_client_proc_t m_glUniform1fv_enc; + glUniform1i_client_proc_t m_glUniform1i_enc; + glUniform1iv_client_proc_t m_glUniform1iv_enc; + glUniform2f_client_proc_t m_glUniform2f_enc; + glUniform2fv_client_proc_t m_glUniform2fv_enc; + glUniform2i_client_proc_t m_glUniform2i_enc; + glUniform2iv_client_proc_t m_glUniform2iv_enc; + glUniform3f_client_proc_t m_glUniform3f_enc; + glUniform3fv_client_proc_t m_glUniform3fv_enc; + glUniform3i_client_proc_t m_glUniform3i_enc; + glUniform3iv_client_proc_t m_glUniform3iv_enc; + glUniform4f_client_proc_t m_glUniform4f_enc; + glUniform4fv_client_proc_t m_glUniform4fv_enc; + glUniform4i_client_proc_t m_glUniform4i_enc; + glUniform4iv_client_proc_t m_glUniform4iv_enc; + glUniformMatrix2fv_client_proc_t m_glUniformMatrix2fv_enc; + glUniformMatrix3fv_client_proc_t m_glUniformMatrix3fv_enc; + glUniformMatrix4fv_client_proc_t m_glUniformMatrix4fv_enc; + + static void s_glUseProgram(void *self, GLuint program); + static void s_glUniform1f(void *self , GLint location, GLfloat x); + static void s_glUniform1fv(void *self , GLint location, GLsizei count, const GLfloat* v); + static void s_glUniform1i(void *self , GLint location, GLint x); + static void s_glUniform1iv(void *self , GLint location, GLsizei count, const GLint* v); + static void s_glUniform2f(void *self , GLint location, GLfloat x, GLfloat y); + static void s_glUniform2fv(void *self , GLint location, GLsizei count, const GLfloat* v); + static void s_glUniform2i(void *self , GLint location, GLint x, GLint y); + static void s_glUniform2iv(void *self , GLint location, GLsizei count, const GLint* v); + static void s_glUniform3f(void *self , GLint location, GLfloat x, GLfloat y, GLfloat z); + static void s_glUniform3fv(void *self , GLint location, GLsizei count, const GLfloat* v); + static void s_glUniform3i(void *self , GLint location, GLint x, GLint y, GLint z); + static void s_glUniform3iv(void *self , GLint location, GLsizei count, const GLint* v); + static void s_glUniform4f(void *self , GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w); + static void s_glUniform4fv(void *self , GLint location, GLsizei count, const GLfloat* v); + static void s_glUniform4i(void *self , GLint location, GLint x, GLint y, GLint z, GLint w); + static void s_glUniform4iv(void *self , GLint location, GLsizei count, const GLint* v); + static void s_glUniformMatrix2fv(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); + static void s_glUniformMatrix3fv(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); + static void s_glUniformMatrix4fv(void *self , GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); + + glActiveTexture_client_proc_t m_glActiveTexture_enc; + glBindTexture_client_proc_t m_glBindTexture_enc; + glDeleteTextures_client_proc_t m_glDeleteTextures_enc; + glGetTexParameterfv_client_proc_t m_glGetTexParameterfv_enc; + glGetTexParameteriv_client_proc_t m_glGetTexParameteriv_enc; + glTexParameterf_client_proc_t m_glTexParameterf_enc; + glTexParameterfv_client_proc_t m_glTexParameterfv_enc; + glTexParameteri_client_proc_t m_glTexParameteri_enc; + glTexParameteriv_client_proc_t m_glTexParameteriv_enc; + + static void s_glActiveTexture(void* self, GLenum texture); + static void s_glBindTexture(void* self, GLenum target, GLuint texture); + static void s_glDeleteTextures(void* self, GLsizei n, const GLuint* textures); + static void s_glGetTexParameterfv(void* self, GLenum target, GLenum pname, GLfloat* params); + static void s_glGetTexParameteriv(void* self, GLenum target, GLenum pname, GLint* params); + static void s_glTexParameterf(void* self, GLenum target, GLenum pname, GLfloat param); + static void s_glTexParameterfv(void* self, GLenum target, GLenum pname, const GLfloat* params); + static void s_glTexParameteri(void* self, GLenum target, GLenum pname, GLint param); + static void s_glTexParameteriv(void* self, GLenum target, GLenum pname, const GLint* params); +}; +#endif diff --git a/emulator/opengl/system/GLESv2_enc/GL2EncoderUtils.cpp b/emulator/opengl/system/GLESv2_enc/GL2EncoderUtils.cpp new file mode 100644 index 0000000..57d65c0 --- /dev/null +++ b/emulator/opengl/system/GLESv2_enc/GL2EncoderUtils.cpp @@ -0,0 +1,39 @@ +/* +* 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 "GL2Encoder.h" +#include <assert.h> + +size_t pixelDataSize(void *self, GLsizei width, GLsizei height, GLenum format, GLenum type, int pack) +{ + GL2Encoder *ctx = (GL2Encoder *)self; + assert (ctx->state() != NULL); + return ctx->state()->pixelDataSize(width, height, format, type, pack); +} + +size_t pixelDataSize3D(void *self, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, int pack) +{ + size_t layerSize = pixelDataSize(self, width, height, format, type, pack); + return layerSize * depth; +} + +GLenum uniformType(void * self, GLuint program, GLint location) +{ + GL2Encoder * ctx = (GL2Encoder *) self; + assert (ctx->shared() != NULL); + return ctx->shared()->getProgramUniformType(program, location); +} diff --git a/emulator/opengl/system/GLESv2_enc/GL2EncoderUtils.h b/emulator/opengl/system/GLESv2_enc/GL2EncoderUtils.h new file mode 100644 index 0000000..8e91aeb --- /dev/null +++ b/emulator/opengl/system/GLESv2_enc/GL2EncoderUtils.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 GL2_ENCODER_UTILS_H +#define GL2_ENCLODER_UTILS_H + +extern "C" { + size_t pixelDataSize(void *self, GLsizei width, GLsizei height, GLenum format, GLenum type, int pack); + size_t pixelDataSize3D(void *self, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, int pack); + GLenum uniformType(void * self, GLuint program, GLint location); +}; +#endif diff --git a/emulator/opengl/system/GLESv2_enc/gl2.attrib b/emulator/opengl/system/GLESv2_enc/gl2.attrib new file mode 100644 index 0000000..7fe9a66 --- /dev/null +++ b/emulator/opengl/system/GLESv2_enc/gl2.attrib @@ -0,0 +1,590 @@ +GLOBAL + base_opcode 2048 + encoder_headers <string.h> "glUtils.h" "GL2EncoderUtils.h" + +#void glBindAttribLocation(GLuint program, GLuint index, GLchar *name) +glBindAttribLocation + len name (strlen(name) + 1) + +#void glBufferData(GLenum target, GLsizeiptr size, GLvoid *data, GLenum usage) +glBufferData + len data size + var_flag data nullAllowed isLarge + +#void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data) +glBufferSubData + len data size + var_flag data isLarge + +#void glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, GLvoid *data) +glCompressedTexImage2D + len data imageSize + var_flag data nullAllowed isLarge + +#void glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, GLvoid *data) +glCompressedTexSubImage2D + len data imageSize + var_flag data isLarge + +#void glDeleteBuffers(GLsizei n, GLuint *buffers) +glDeleteBuffers + len buffers (n * sizeof(GLuint)) + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#void glDeleteFramebuffers(GLsizei n, GLuint *framebuffers) +glDeleteFramebuffers + len framebuffers (n * sizeof(GLuint)) + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#void glDeleteRenderbuffers(GLsizei n, GLuint *renderbuffers) +glDeleteRenderbuffers + len renderbuffers (n * sizeof(GLuint)) + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#void glDeleteTextures(GLsizei n, GLuint *textures) +glDeleteTextures + len textures (n * sizeof(GLuint)) + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#void glDrawElements(GLenum mode, GLsizei count, GLenum type, GLvoid *indices) +glDrawElements + flag unsupported + +#void glGenBuffers(GLsizei n, GLuint *buffers) +glGenBuffers + len buffers (n * sizeof(GLuint)) + dir buffers out + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#void glGenFramebuffers(GLsizei n, GLuint *framebuffers) +glGenFramebuffers + len framebuffers (n * sizeof(GLuint)) + dir framebuffers out + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#void glGenRenderbuffers(GLsizei n, GLuint *renderbuffers) +glGenRenderbuffers + len renderbuffers (n * sizeof(GLuint)) + dir renderbuffers out + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#void glGenTextures(GLsizei n, GLuint *textures) +glGenTextures + len textures (n * sizeof(GLuint)) + dir textures out + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#void glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) +glGetActiveAttrib + len name bufsize + dir name out + var_flag name nullAllowed + dir length out + len length (sizeof(GLsizei)) + var_flag length nullAllowed + dir size out + len size (sizeof(GLint)) + dir type out + len type (sizeof(GLenum)) + +#void glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) +glGetActiveUniform + len name bufsize + dir name out + var_flag name nullAllowed + dir length out + len length (sizeof(GLsizei)) + var_flag length nullAllowed + dir size out + len size (sizeof(GLint)) + dir type out + len type (sizeof(GLenum)) + + +#void glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders) +glGetAttachedShaders + len shaders (maxcount*sizeof(GLuint)) + dir shaders out + dir count out + var_flag count nullAllowed + len count (sizeof(GLsizei)) + +#int glGetAttribLocation(GLuint program, GLchar *name) +glGetAttribLocation + len name (strlen(name) + 1) + +#void glGetBooleanv(GLenum pname, GLboolean *params) +glGetBooleanv + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLboolean)) + +#void glGetBufferParameteriv(GLenum target, GLenum pname, GLint *params) +glGetBufferParameteriv + len params (sizeof(GLint)) + dir params out + +#void glGetFloatv(GLenum pname, GLfloat *params) +glGetFloatv + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLfloat)) + +#void glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint *params) +glGetFramebufferAttachmentParameteriv + dir params out + len params (sizeof(GLint)) + +#void glGetIntegerv(GLenum pname, GLint *params) +glGetIntegerv + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLint)) + +#void glGetProgramiv(GLuint program, GLenum pname, GLint *params) +glGetProgramiv + dir params out + len params sizeof(GLint) +#XXX - might change if extension constants that return more then one value + + +#void glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog) +glGetProgramInfoLog + dir infolog out + len infolog bufsize + dir length out + len length sizeof(GLsizei) + +#void glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params) +glGetRenderbufferParameteriv + dir params out + len params sizeof(GLint) +# XXX - might change if pname with value larger then one is added + +#void glGetShaderiv(GLuint shader, GLenum pname, GLint *params) +glGetShaderiv + dir params out + len params sizeof(GLint) +# XXX - might change if pname with value larger then one is added + +#void glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog) +glGetShaderInfoLog + dir length out + len length (sizeof(GLsizei)) + var_flag length nullAllowed + dir infolog out + len infolog bufsize + + +#void glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision) +glGetShaderPrecisionFormat + dir range out + len range (2 * sizeof(GLint)) + dir precision out + len precision (sizeof(GLint)) + +#void glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source) +glGetShaderSource + dir length out + len length (sizeof(GLsizei)) + var_flag length nullAllowed + dir source out + len source bufsize + +#GLubyte* glGetString(GLenum name) +glGetString + flag unsupported + +#void glGetTexParameterfv(GLenum target, GLenum pname, GLfloat *params) +glGetTexParameterfv + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLfloat)) + +#void glGetTexParameteriv(GLenum target, GLenum pname, GLint *params) +glGetTexParameteriv + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLint)) + +#void glGetUniformfv(GLuint program, GLint location, GLfloat *params) +glGetUniformfv + dir params out + len params glSizeof(uniformType(self, program, location)) + +#void glGetUniformiv(GLuint program, GLint location, GLint *params) +glGetUniformiv + dir params out + len params glSizeof(uniformType(self, program, location)) + +#int glGetUniformLocation(GLuint program, GLchar *name) +glGetUniformLocation + len name (strlen(name) + 1) + +# client-state shall be handled locally by the encoder in most cases. +# however, GL_CURRENT_VERTEX_ATTRIB and potential others are handled by the server side, +# thus we still need to implement it. +#void glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params) +glGetVertexAttribfv + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLfloat)) + +#see glGetVertexAttribfv for comments +#void glGetVertexAttribiv(GLuint index, GLenum pname, GLint *params) +glGetVertexAttribiv + dir params out + len params (glUtilsParamSize(pname) * sizeof(GLint)) + + + +#void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) +glReadPixels + dir pixels out + len pixels pixelDataSize(self, width, height, format, type, 1) + +#void glShaderBinary(GLsizei n, GLuint *shaders, GLenum binaryformat, GLvoid *binary, GLsizei length) +glShaderBinary + flag unsupported + +#void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLvoid *pixels) +glTexImage2D + dir pixels in + len pixels pixelDataSize(self, width, height, format, type, 0) + var_flag pixels nullAllowed isLarge + +#void glTexParameterfv(GLenum target, GLenum pname, GLfloat *params) +glTexParameterfv + len params (glUtilsParamSize(pname) * sizeof(GLfloat)) +#void glTexParameteriv(GLenum target, GLenum pname, GLint *params) +glTexParameteriv + len params (glUtilsParamSize(pname) * sizeof(GLint)) + +#void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) +glTexSubImage2D + len pixels pixelDataSize(self, width, height, format, type, 0) + var_flag pixels isLarge + +#void glUniform1fv(GLint location, GLsizei count, GLfloat *v) +glUniform1fv + len v (count * sizeof(GLfloat)) + +#void glUniform1iv(GLint location, GLsizei count, GLint *v) +glUniform1iv + len v (count * sizeof(GLint)) + +#void glUniform2fv(GLint location, GLsizei count, GLfloat *v) +glUniform2fv + len v (count * 2 * sizeof(GLfloat)) + +#void glUniform2iv(GLint location, GLsizei count, GLint *v) +glUniform2iv + len v (count * 2 * sizeof(GLint)) + +#void glUniform3fv(GLint location, GLsizei count, GLfloat *v) +glUniform3fv + len v (count * 3 * sizeof(GLfloat)) + +#void glUniform3iv(GLint location, GLsizei count, GLint *v) +glUniform3iv + len v (3 * count * sizeof(GLint)) + +#void glUniform4fv(GLint location, GLsizei count, GLfloat *v) +glUniform4fv + len v (4 * count * sizeof(GLfloat)) + +#void glUniform4iv(GLint location, GLsizei count, GLint *v) +glUniform4iv + len v (4 * count * sizeof(GLint)) + +#void glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, GLfloat *value) +glUniformMatrix2fv + len value (count * 4 * sizeof(GLfloat)) + +#void glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, GLfloat *value) +glUniformMatrix3fv + len value (count * 9 * sizeof(GLfloat)) + +#void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, GLfloat *value) +glUniformMatrix4fv + len value (count * 16 * sizeof(GLfloat)) + +#void glVertexAttrib1fv(GLuint indx, GLfloat *values) +glVertexAttrib1fv + len values (sizeof(GLfloat)) +#void glVertexAttrib2fv(GLuint indx, GLfloat *values) +glVertexAttrib2fv + len values (2 * sizeof(GLfloat)) + +#void glVertexAttrib3fv(GLuint indx, GLfloat *values) +glVertexAttrib3fv + len values (3 * sizeof(GLfloat)) + +#void glVertexAttrib4fv(GLuint indx, GLfloat *values) +glVertexAttrib4fv + len values (4 * sizeof(GLfloat)) + +#void glVertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLvoid *ptr) +glVertexAttribPointer + flag unsupported + +#void glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary) +glGetProgramBinaryOES + flag unsupported + +#void glProgramBinaryOES(GLuint program, GLenum binaryFormat, GLvoid *binary, GLint length) +glProgramBinaryOES + flag unsupported + +#void* glMapBufferOES(GLenum target, GLenum access) +glMapBufferOES + flag unsupported + +#void glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, GLvoid *pixels) +glTexImage3DOES + len pixels pixelDataSize3D(self, width, height, depth, format, type, 0) + var_flag pixels nullAllowed isLarge + +#void glTexSubImage3DOES(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *pixels) +glTexSubImage3DOES + len pixels pixelDataSize3D(self, width, height, depth, format, type, 0) + var_flag pixels isLarge + +#void glCompressedTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, GLvoid *data) +glCompressedTexImage3DOES + len data imageSize + var_flag data isLarge + +#void glCompressedTexSubImage3DOES(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, GLvoid *data) +glCompressedTexSubImage3DOES + len data imageSize + var_flag data isLarge + +#void glDeleteVertexArraysOES(GLsizei n, GLuint *arrays) +glDeleteVertexArraysOES + len arrays (n * sizeof(GLuint)) + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + +#void glGenVertexArraysOES(GLsizei n, GLuint *arrays) +glGenVertexArraysOES + len arrays (n * sizeof(GLuint)) + dir arrays out + param_check n if(n<0){ ctx->setError(GL_INVALID_VALUE); return; } + + +#void glDiscardFramebufferEXT(GLenum target, GLsizei numAttachments, GLenum *attachments) +glDiscardFramebufferEXT + len attachments (numAttachments * sizeof(GLenum)) + +#void glMultiDrawArraysEXT(GLenum mode, GLint *first, GLsizei *count, GLsizei primcount) +glMultiDrawArraysEXT + flag unsupported +#void glMultiDrawElementsEXT(GLenum mode, GLsizei *count, GLenum type, GLvoid *indices, GLsizei primcount) +glMultiDrawElementsEXT + flag unsupported + + +# handled by encoder +#void glShaderSource(GLuint shader, GLsizei count, GLstr *string, const GLint *length) +glShaderSource + flag unsupported + + + +#void glGetPerfMonitorGroupsAMD(GLint *numGroups, GLsizei groupsSize, GLuint *groups) +glGetPerfMonitorGroupsAMD + flag unsupported + +#void glGetPerfMonitorCountersAMD(GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters) +glGetPerfMonitorCountersAMD + flag unsupported + +#void glGetPerfMonitorGroupStringAMD(GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString) +glGetPerfMonitorGroupStringAMD + flag unsupported + +#void glGetPerfMonitorCounterStringAMD(GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString) +glGetPerfMonitorCounterStringAMD + flag unsupported + +#void glGetPerfMonitorCounterInfoAMD(GLuint group, GLuint counter, GLenum pname, GLvoid *data) +glGetPerfMonitorCounterInfoAMD + flag unsupported + +#void glGenPerfMonitorsAMD(GLsizei n, GLuint *monitors) +glGenPerfMonitorsAMD + flag unsupported + +#void glDeletePerfMonitorsAMD(GLsizei n, GLuint *monitors) +glDeletePerfMonitorsAMD + flag unsupported + +#void glSelectPerfMonitorCountersAMD(GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *countersList) +glSelectPerfMonitorCountersAMD + flag unsupported + +#void glBeginPerfMonitorAMD(GLuint monitor) +glBeginPerfMonitorAMD + flag unsupported + +#void glEndPerfMonitorAMD(GLuint monitor) +glEndPerfMonitorAMD + flag unsupported + +#void glGetPerfMonitorCounterDataAMD(GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten) +glGetPerfMonitorCounterDataAMD + flag unsupported + +#void glRenderbufferStorageMultisampleIMG(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height) +glRenderbufferStorageMultisampleIMG + flag unsupported + +#void glFramebufferTexture2DMultisampleIMG(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples) +glFramebufferTexture2DMultisampleIMG + flag unsupported + +#void glDeleteFencesNV(GLsizei n, GLuint *fences) +glDeleteFencesNV + flag unsupported + +#void glGenFencesNV(GLsizei n, GLuint *fences) +glGenFencesNV + flag unsupported + +#GLboolean glIsFenceNV(GLuint fence) +glIsFenceNV + flag unsupported + +#GLboolean glTestFenceNV(GLuint fence) +glTestFenceNV + flag unsupported + +#void glGetFenceivNV(GLuint fence, GLenum pname, GLint *params) +glGetFenceivNV + flag unsupported + +#void glFinishFenceNV(GLuint fence) +glFinishFenceNV + flag unsupported + +#void glSetFenceNV(GLuint fence, GLenum condition) +glSetFenceNV + flag unsupported + +#void glCoverageMaskNV(GLboolean mask) +glCoverageMaskNV + flag unsupported + +#void glCoverageOperationNV(GLenum operation) +glCoverageOperationNV + flag unsupported + +#void glGetDriverControlsQCOM(GLint *num, GLsizei size, GLuint *driverControls) +glGetDriverControlsQCOM + flag unsupported + +#void glGetDriverControlStringQCOM(GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString) +glGetDriverControlStringQCOM + flag unsupported + +#void glEnableDriverControlQCOM(GLuint driverControl) +glEnableDriverControlQCOM + flag unsupported + +#void glDisableDriverControlQCOM(GLuint driverControl) +glDisableDriverControlQCOM + flag unsupported + +#void glExtGetTexturesQCOM(GLuint *textures, GLint maxTextures, GLint *numTextures) +glExtGetTexturesQCOM + flag unsupported + +#void glExtGetBuffersQCOM(GLuint *buffers, GLint maxBuffers, GLint *numBuffers) +glExtGetBuffersQCOM + flag unsupported + +#void glExtGetRenderbuffersQCOM(GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers) +glExtGetRenderbuffersQCOM + flag unsupported + +#void glExtGetFramebuffersQCOM(GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers) +glExtGetFramebuffersQCOM + flag unsupported + +#void glExtGetTexLevelParameterivQCOM(GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params) +glExtGetTexLevelParameterivQCOM + flag unsupported + +#void glExtTexObjectStateOverrideiQCOM(GLenum target, GLenum pname, GLint param) +glExtTexObjectStateOverrideiQCOM + flag unsupported + +#void glExtGetTexSubImageQCOM(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels) +glExtGetTexSubImageQCOM + flag unsupported + +#void glExtGetBufferPointervQCOM(GLenum target, GLvoidptr *params) +glExtGetBufferPointervQCOM + flag unsupported + +#void glExtGetShadersQCOM(GLuint *shaders, GLint maxShaders, GLint *numShaders) +glExtGetShadersQCOM + flag unsupported + +#void glExtGetProgramsQCOM(GLuint *programs, GLint maxPrograms, GLint *numPrograms) +glExtGetProgramsQCOM + flag unsupported + +#GLboolean glExtIsProgramBinaryQCOM(GLuint program) +glExtIsProgramBinaryQCOM + flag unsupported + +#void glExtGetProgramBinarySourceQCOM(GLuint program, GLenum shadertype, GLchar *source, GLint *length) +glExtGetProgramBinarySourceQCOM + flag unsupported + +#void glStartTilingQCOM(GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask) +glStartTilingQCOM + flag unsupported + +#void glEndTilingQCOM(GLbitfield preserveMask) +glEndTilingQCOM + flag unsupported + + +#void glVertexAttribPointerData(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, void * data, GLuint datalen) +glVertexAttribPointerData + len data datalen + custom_pack data glUtilsPackPointerData((unsigned char *)ptr, (unsigned char *)data, size, type, stride, datalen) + flag custom_decoder + flag not_api + +glVertexAttribPointerOffset + flag custom_decoder + flag not_api + +#client-state, handled by the encoder +#GL_ENTRY(void, glGetVertexAttribPointerv, GLuint index, GLenum pname, GLvoid** pointer) +glGetVertexAttribPointerv + flag unsupported + +glDrawElementsData + len data datalen + flag custom_decoder + flag not_api + +glDrawElementsOffset + flag custom_decoder + flag not_api + +#GL_ENTRY(void, glGetCompressedTextureFormats, int count, GLint *formats) +glGetCompressedTextureFormats + dir formats out + len formats (count * sizeof(GLint)) + flag custom_decoder + flag not_api + +#GL_ENTRY(void, glShaderString, GLuint shader, GLchar *string, GLsizei len) +glShaderString + len string len + flag custom_decoder + flag not_api + +glFinishRoundTrip + flag custom_decoder + flag not_api + diff --git a/emulator/opengl/system/GLESv2_enc/gl2.in b/emulator/opengl/system/GLESv2_enc/gl2.in new file mode 100644 index 0000000..916153b --- /dev/null +++ b/emulator/opengl/system/GLESv2_enc/gl2.in @@ -0,0 +1,214 @@ +GL_ENTRY(void, glActiveTexture, GLenum texture) +GL_ENTRY(void, glAttachShader, GLuint program, GLuint shader) +GL_ENTRY(void, glBindAttribLocation, GLuint program, GLuint index, const GLchar* name) +GL_ENTRY(void, glBindBuffer, GLenum target, GLuint buffer) +GL_ENTRY(void, glBindFramebuffer, GLenum target, GLuint framebuffer) +GL_ENTRY(void, glBindRenderbuffer, GLenum target, GLuint renderbuffer) +GL_ENTRY(void, glBindTexture, GLenum target, GLuint texture) +GL_ENTRY(void, glBlendColor, GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) +GL_ENTRY(void, glBlendEquation, GLenum mode ) +GL_ENTRY(void, glBlendEquationSeparate, GLenum modeRGB, GLenum modeAlpha) +GL_ENTRY(void, glBlendFunc, GLenum sfactor, GLenum dfactor) +GL_ENTRY(void, glBlendFuncSeparate, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) +GL_ENTRY(void, glBufferData, GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage) +GL_ENTRY(void, glBufferSubData, GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data) +GL_ENTRY(GLenum, glCheckFramebufferStatus, GLenum target) +GL_ENTRY(void, glClear, GLbitfield mask) +GL_ENTRY(void, glClearColor, GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) +GL_ENTRY(void, glClearDepthf, GLclampf depth) +GL_ENTRY(void, glClearStencil, GLint s) +GL_ENTRY(void, glColorMask, GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) +GL_ENTRY(void, glCompileShader, GLuint shader) +GL_ENTRY(void, glCompressedTexImage2D, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid* data) +GL_ENTRY(void, glCompressedTexSubImage2D, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid* data) +GL_ENTRY(void, glCopyTexImage2D, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) +GL_ENTRY(void, glCopyTexSubImage2D, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) +GL_ENTRY(GLuint, glCreateProgram, void) +GL_ENTRY(GLuint, glCreateShader, GLenum type) +GL_ENTRY(void, glCullFace, GLenum mode) +GL_ENTRY(void, glDeleteBuffers, GLsizei n, const GLuint* buffers) +GL_ENTRY(void, glDeleteFramebuffers, GLsizei n, const GLuint* framebuffers) +GL_ENTRY(void, glDeleteProgram, GLuint program) +GL_ENTRY(void, glDeleteRenderbuffers, GLsizei n, const GLuint* renderbuffers) +GL_ENTRY(void, glDeleteShader, GLuint shader) +GL_ENTRY(void, glDeleteTextures, GLsizei n, const GLuint* textures) +GL_ENTRY(void, glDepthFunc, GLenum func) +GL_ENTRY(void, glDepthMask, GLboolean flag) +GL_ENTRY(void, glDepthRangef, GLclampf zNear, GLclampf zFar) +GL_ENTRY(void, glDetachShader, GLuint program, GLuint shader) +GL_ENTRY(void, glDisable, GLenum cap) +GL_ENTRY(void, glDisableVertexAttribArray, GLuint index) +GL_ENTRY(void, glDrawArrays, GLenum mode, GLint first, GLsizei count) +GL_ENTRY(void, glDrawElements, GLenum mode, GLsizei count, GLenum type, const GLvoid* indices) +GL_ENTRY(void, glEnable, GLenum cap) +GL_ENTRY(void, glEnableVertexAttribArray, GLuint index) +GL_ENTRY(void, glFinish, void) +GL_ENTRY(void, glFlush, void) +GL_ENTRY(void, glFramebufferRenderbuffer, GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) +GL_ENTRY(void, glFramebufferTexture2D, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) +GL_ENTRY(void, glFrontFace, GLenum mode) +GL_ENTRY(void, glGenBuffers, GLsizei n, GLuint* buffers) +GL_ENTRY(void, glGenerateMipmap, GLenum target) +GL_ENTRY(void, glGenFramebuffers, GLsizei n, GLuint* framebuffers) +GL_ENTRY(void, glGenRenderbuffers, GLsizei n, GLuint* renderbuffers) +GL_ENTRY(void, glGenTextures, GLsizei n, GLuint* textures) +GL_ENTRY(void, glGetActiveAttrib, GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name) +GL_ENTRY(void, glGetActiveUniform, GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name) +GL_ENTRY(void, glGetAttachedShaders, GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders) +GL_ENTRY(int, glGetAttribLocation, GLuint program, const GLchar* name) +GL_ENTRY(void, glGetBooleanv, GLenum pname, GLboolean* params) +GL_ENTRY(void, glGetBufferParameteriv, GLenum target, GLenum pname, GLint* params) +GL_ENTRY(GLenum, glGetError, void) +GL_ENTRY(void, glGetFloatv, GLenum pname, GLfloat* params) +GL_ENTRY(void, glGetFramebufferAttachmentParameteriv, GLenum target, GLenum attachment, GLenum pname, GLint* params) +GL_ENTRY(void, glGetIntegerv, GLenum pname, GLint* params) +GL_ENTRY(void, glGetProgramiv, GLuint program, GLenum pname, GLint* params) +GL_ENTRY(void, glGetProgramInfoLog, GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog) +GL_ENTRY(void, glGetRenderbufferParameteriv, GLenum target, GLenum pname, GLint* params) +GL_ENTRY(void, glGetShaderiv, GLuint shader, GLenum pname, GLint* params) +GL_ENTRY(void, glGetShaderInfoLog, GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog) +GL_ENTRY(void, glGetShaderPrecisionFormat, GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision) +GL_ENTRY(void, glGetShaderSource, GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source) +GL_ENTRY(const GLubyte*, glGetString, GLenum name) +GL_ENTRY(void, glGetTexParameterfv, GLenum target, GLenum pname, GLfloat* params) +GL_ENTRY(void, glGetTexParameteriv, GLenum target, GLenum pname, GLint* params) +GL_ENTRY(void, glGetUniformfv, GLuint program, GLint location, GLfloat* params) +GL_ENTRY(void, glGetUniformiv, GLuint program, GLint location, GLint* params) +GL_ENTRY(int, glGetUniformLocation, GLuint program, const GLchar* name) +GL_ENTRY(void, glGetVertexAttribfv, GLuint index, GLenum pname, GLfloat* params) +GL_ENTRY(void, glGetVertexAttribiv, GLuint index, GLenum pname, GLint* params) +GL_ENTRY(void, glGetVertexAttribPointerv, GLuint index, GLenum pname, GLvoid** pointer) +GL_ENTRY(void, glHint, GLenum target, GLenum mode) +GL_ENTRY(GLboolean, glIsBuffer, GLuint buffer) +GL_ENTRY(GLboolean, glIsEnabled, GLenum cap) +GL_ENTRY(GLboolean, glIsFramebuffer, GLuint framebuffer) +GL_ENTRY(GLboolean, glIsProgram, GLuint program) +GL_ENTRY(GLboolean, glIsRenderbuffer, GLuint renderbuffer) +GL_ENTRY(GLboolean, glIsShader, GLuint shader) +GL_ENTRY(GLboolean, glIsTexture, GLuint texture) +GL_ENTRY(void, glLineWidth, GLfloat width) +GL_ENTRY(void, glLinkProgram, GLuint program) +GL_ENTRY(void, glPixelStorei, GLenum pname, GLint param) +GL_ENTRY(void, glPolygonOffset, GLfloat factor, GLfloat units) +GL_ENTRY(void, glReadPixels, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels) +GL_ENTRY(void, glReleaseShaderCompiler, void) +GL_ENTRY(void, glRenderbufferStorage, GLenum target, GLenum internalformat, GLsizei width, GLsizei height) +GL_ENTRY(void, glSampleCoverage, GLclampf value, GLboolean invert) +GL_ENTRY(void, glScissor, GLint x, GLint y, GLsizei width, GLsizei height) +GL_ENTRY(void, glShaderBinary, GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length) +GL_ENTRY(void, glShaderSource, GLuint shader, GLsizei count, const GLchar** string, const GLint* length) +GL_ENTRY(void, glStencilFunc, GLenum func, GLint ref, GLuint mask) +GL_ENTRY(void, glStencilFuncSeparate, GLenum face, GLenum func, GLint ref, GLuint mask) +GL_ENTRY(void, glStencilMask, GLuint mask) +GL_ENTRY(void, glStencilMaskSeparate, GLenum face, GLuint mask) +GL_ENTRY(void, glStencilOp, GLenum fail, GLenum zfail, GLenum zpass) +GL_ENTRY(void, glStencilOpSeparate, GLenum face, GLenum fail, GLenum zfail, GLenum zpass) +GL_ENTRY(void, glTexImage2D, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels) +GL_ENTRY(void, glTexParameterf, GLenum target, GLenum pname, GLfloat param) +GL_ENTRY(void, glTexParameterfv, GLenum target, GLenum pname, const GLfloat* params) +GL_ENTRY(void, glTexParameteri, GLenum target, GLenum pname, GLint param) +GL_ENTRY(void, glTexParameteriv, GLenum target, GLenum pname, const GLint* params) +GL_ENTRY(void, glTexSubImage2D, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels) +GL_ENTRY(void, glUniform1f, GLint location, GLfloat x) +GL_ENTRY(void, glUniform1fv, GLint location, GLsizei count, const GLfloat* v) +GL_ENTRY(void, glUniform1i, GLint location, GLint x) +GL_ENTRY(void, glUniform1iv, GLint location, GLsizei count, const GLint* v) +GL_ENTRY(void, glUniform2f, GLint location, GLfloat x, GLfloat y) +GL_ENTRY(void, glUniform2fv, GLint location, GLsizei count, const GLfloat* v) +GL_ENTRY(void, glUniform2i, GLint location, GLint x, GLint y) +GL_ENTRY(void, glUniform2iv, GLint location, GLsizei count, const GLint* v) +GL_ENTRY(void, glUniform3f, GLint location, GLfloat x, GLfloat y, GLfloat z) +GL_ENTRY(void, glUniform3fv, GLint location, GLsizei count, const GLfloat* v) +GL_ENTRY(void, glUniform3i, GLint location, GLint x, GLint y, GLint z) +GL_ENTRY(void, glUniform3iv, GLint location, GLsizei count, const GLint* v) +GL_ENTRY(void, glUniform4f, GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w) +GL_ENTRY(void, glUniform4fv, GLint location, GLsizei count, const GLfloat* v) +GL_ENTRY(void, glUniform4i, GLint location, GLint x, GLint y, GLint z, GLint w) +GL_ENTRY(void, glUniform4iv, GLint location, GLsizei count, const GLint* v) +GL_ENTRY(void, glUniformMatrix2fv, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) +GL_ENTRY(void, glUniformMatrix3fv, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) +GL_ENTRY(void, glUniformMatrix4fv, GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) +GL_ENTRY(void, glUseProgram, GLuint program) +GL_ENTRY(void, glValidateProgram, GLuint program) +GL_ENTRY(void, glVertexAttrib1f, GLuint indx, GLfloat x) +GL_ENTRY(void, glVertexAttrib1fv, GLuint indx, const GLfloat* values) +GL_ENTRY(void, glVertexAttrib2f, GLuint indx, GLfloat x, GLfloat y) +GL_ENTRY(void, glVertexAttrib2fv, GLuint indx, const GLfloat* values) +GL_ENTRY(void, glVertexAttrib3f, GLuint indx, GLfloat x, GLfloat y, GLfloat z) +GL_ENTRY(void, glVertexAttrib3fv, GLuint indx, const GLfloat* values) +GL_ENTRY(void, glVertexAttrib4f, GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w) +GL_ENTRY(void, glVertexAttrib4fv, GLuint indx, const GLfloat* values) +GL_ENTRY(void, glVertexAttribPointer, GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr) +GL_ENTRY(void, glViewport, GLint x, GLint y, GLsizei width, GLsizei height) +GL_ENTRY(void, glEGLImageTargetTexture2DOES, GLenum target, GLeglImageOES image) +GL_ENTRY(void, glEGLImageTargetRenderbufferStorageOES, GLenum target, GLeglImageOES image) +GL_ENTRY(void, glGetProgramBinaryOES, GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary) +GL_ENTRY(void, glProgramBinaryOES, GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length) +GL_ENTRY(void*, glMapBufferOES, GLenum target, GLenum access) +GL_ENTRY(GLboolean, glUnmapBufferOES, GLenum target) +#GL_ENTRY(void, glGetBufferPointervOES, GLenum target, GLenum pname, GLvoid** params) +GL_ENTRY(void, glTexImage3DOES, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels) +GL_ENTRY(void, 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_ENTRY(void, glCopyTexSubImage3DOES, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height) +GL_ENTRY(void, glCompressedTexImage3DOES, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data) +GL_ENTRY(void, 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_ENTRY(void, glFramebufferTexture3DOES, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset) +GL_ENTRY(void, glBindVertexArrayOES, GLuint array) +GL_ENTRY(void, glDeleteVertexArraysOES, GLsizei n, const GLuint *arrays) +GL_ENTRY(void, glGenVertexArraysOES, GLsizei n, GLuint *arrays) +GL_ENTRY(GLboolean, glIsVertexArrayOES, GLuint array) +GL_ENTRY(void, glDiscardFramebufferEXT, GLenum target, GLsizei numAttachments, const GLenum *attachments) +GL_ENTRY(void, glMultiDrawArraysEXT, GLenum mode, GLint *first, GLsizei *count, GLsizei primcount) +GL_ENTRY(void, glMultiDrawElementsEXT, GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount) + +#not supported +GL_ENTRY(void, glGetPerfMonitorGroupsAMD, GLint *numGroups, GLsizei groupsSize, GLuint *groups) +GL_ENTRY(void, glGetPerfMonitorCountersAMD, GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters) +GL_ENTRY(void, glGetPerfMonitorGroupStringAMD, GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString) +GL_ENTRY(void, glGetPerfMonitorCounterStringAMD, GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString) +GL_ENTRY(void, glGetPerfMonitorCounterInfoAMD, GLuint group, GLuint counter, GLenum pname, GLvoid *data) +GL_ENTRY(void, glGenPerfMonitorsAMD, GLsizei n, GLuint *monitors) +GL_ENTRY(void, glDeletePerfMonitorsAMD, GLsizei n, GLuint *monitors) +GL_ENTRY(void, glSelectPerfMonitorCountersAMD, GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *countersList) +GL_ENTRY(void, glBeginPerfMonitorAMD, GLuint monitor) +GL_ENTRY(void, glEndPerfMonitorAMD, GLuint monitor) +GL_ENTRY(void, glGetPerfMonitorCounterDataAMD, GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten) + +GL_ENTRY(void, glRenderbufferStorageMultisampleIMG, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height) +GL_ENTRY(void, glFramebufferTexture2DMultisampleIMG, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples) +GL_ENTRY(void, glDeleteFencesNV, GLsizei n, const GLuint *fences) +GL_ENTRY(void, glGenFencesNV, GLsizei n, GLuint *fences) +GL_ENTRY(GLboolean, glIsFenceNV, GLuint fence) +GL_ENTRY(GLboolean, glTestFenceNV, GLuint fence) +GL_ENTRY(void, glGetFenceivNV, GLuint fence, GLenum pname, GLint *params) +GL_ENTRY(void, glFinishFenceNV, GLuint fence) +GL_ENTRY(void, glSetFenceNV, GLuint fence, GLenum condition) +GL_ENTRY(void, glCoverageMaskNV, GLboolean mask) +GL_ENTRY(void, glCoverageOperationNV, GLenum operation) +GL_ENTRY(void, glGetDriverControlsQCOM, GLint *num, GLsizei size, GLuint *driverControls) +GL_ENTRY(void, glGetDriverControlStringQCOM, GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString) +GL_ENTRY(void, glEnableDriverControlQCOM, GLuint driverControl) +GL_ENTRY(void, glDisableDriverControlQCOM, GLuint driverControl) +GL_ENTRY(void, glExtGetTexturesQCOM, GLuint *textures, GLint maxTextures, GLint *numTextures) +GL_ENTRY(void, glExtGetBuffersQCOM, GLuint *buffers, GLint maxBuffers, GLint *numBuffers) +GL_ENTRY(void, glExtGetRenderbuffersQCOM, GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers) +GL_ENTRY(void, glExtGetFramebuffersQCOM, GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers) +GL_ENTRY(void, glExtGetTexLevelParameterivQCOM, GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params) +GL_ENTRY(void, glExtTexObjectStateOverrideiQCOM, GLenum target, GLenum pname, GLint param) +GL_ENTRY(void, glExtGetTexSubImageQCOM, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels) +GL_ENTRY(void, glExtGetBufferPointervQCOM, GLenum target, GLvoidptr *params) +GL_ENTRY(void, glExtGetShadersQCOM, GLuint *shaders, GLint maxShaders, GLint *numShaders) +GL_ENTRY(void, glExtGetProgramsQCOM, GLuint *programs, GLint maxPrograms, GLint *numPrograms) +GL_ENTRY(GLboolean, glExtIsProgramBinaryQCOM, GLuint program) +GL_ENTRY(void, glExtGetProgramBinarySourceQCOM, GLuint program, GLenum shadertype, GLchar *source, GLint *length) +GL_ENTRY(void, glStartTilingQCOM, GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask) +GL_ENTRY(void, glEndTilingQCOM, GLbitfield preserveMask) + +# add-ons +GL_ENTRY(void, glVertexAttribPointerData, GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, void * data, GLuint datalen) +GL_ENTRY(void, glVertexAttribPointerOffset, GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLuint offset) +GL_ENTRY(void, glDrawElementsOffset, GLenum mode, GLsizei count, GLenum type, GLuint offset) +GL_ENTRY(void, glDrawElementsData, GLenum mode, GLsizei count, GLenum type, void *data, GLuint datalen) +GL_ENTRY(void, glGetCompressedTextureFormats, int count, GLint *formats) +GL_ENTRY(void, glShaderString, GLuint shader, const GLchar* string, GLsizei len) +GL_ENTRY(int, glFinishRoundTrip, void) diff --git a/emulator/opengl/system/GLESv2_enc/gl2.types b/emulator/opengl/system/GLESv2_enc/gl2.types new file mode 100644 index 0000000..4cee99e --- /dev/null +++ b/emulator/opengl/system/GLESv2_enc/gl2.types @@ -0,0 +1,37 @@ +GLbitfield 32 0x%08x false +GLboolean 8 %d false +GLclampf 32 %f false +GLclampx 32 0x%08x false +GLeglImageOES 32 %p false +GLenum 32 0x%08x false +GLfixed 32 0x%08x false +GLfloat 32 %f false +GLint 32 %d false +GLintptr 32 %p false +GLshort 16 %d false +GLsizei 32 %d false +GLsizeiptr 32 %p false +GLubyte 8 0x%02x false +GLuint 32 %u false +GLvoid 0 %x false +GLchar 8 %d false +GLenum* 32 0x%08x true +GLboolean* 32 0x%08x true +GLclampf* 32 0x%08x true +GLclampx* 32 0x%08x true +GLeglImageOES* 32 0x%08x true +GLfixed* 32 0x%08x true +GLfloat* 32 0x%08x true +GLint* 32 0x%08x true +GLshort* 32 0x%08x true +GLsizei* 32 0x%08x true +GLubyte* 32 0x%08x true +GLuint* 32 0x%08x true +GLvoid* 32 0x%08x true +GLchar* 32 0x%08x true +GLchar** 32 0x%08x true +GLvoid** 32 0x%08x true +void* 32 0x%08x true +GLstr 32 %s true +GLstr* 32 0x%08x true +GLvoidptr* 32 0x%08x true
\ No newline at end of file diff --git a/emulator/opengl/system/GLESv2_enc/gl2_types.h b/emulator/opengl/system/GLESv2_enc/gl2_types.h new file mode 100644 index 0000000..bfff61d --- /dev/null +++ b/emulator/opengl/system/GLESv2_enc/gl2_types.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 _GL_2_TYPES_H_ +#define _GL_2_TYPES_H_ +#include "gl_base_types.h" + +typedef void *GLvoidptr; +#endif diff --git a/emulator/opengl/system/OpenglSystemCommon/Android.mk b/emulator/opengl/system/OpenglSystemCommon/Android.mk new file mode 100644 index 0000000..6198748 --- /dev/null +++ b/emulator/opengl/system/OpenglSystemCommon/Android.mk @@ -0,0 +1,13 @@ +LOCAL_PATH := $(call my-dir) + +$(call emugl-begin-shared-library,libOpenglSystemCommon) +$(call emugl-import,libGLESv1_enc libGLESv2_enc lib_renderControl_enc) + +LOCAL_SRC_FILES := \ + HostConnection.cpp \ + QemuPipeStream.cpp \ + ThreadInfo.cpp + +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH) bionic/libc/private) + +$(call emugl-end-module) diff --git a/emulator/opengl/system/OpenglSystemCommon/EGLClientIface.h b/emulator/opengl/system/OpenglSystemCommon/EGLClientIface.h new file mode 100644 index 0000000..3c8cb55 --- /dev/null +++ b/emulator/opengl/system/OpenglSystemCommon/EGLClientIface.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 _SYSTEM_COMMON_EGL_CLIENT_IFACE_H +#define _SYSTEM_COMMON_EGL_CLIENT_IFACE_H + +struct EGLThreadInfo; // defined in ThreadInfo.h + +typedef struct { + EGLThreadInfo* (*getThreadInfo)(); + const char* (*getGLString)(int glEnum); +} EGLClient_eglInterface; + +typedef struct { + void* (*getProcAddress)(const char *funcName); + void (*init)(); + void (*finish)(); +} EGLClient_glesInterface; + +// +// Any GLES/GLES2 client API library should define a function named "init_emul_gles" +// with the following prototype, +// It will be called by EGL after loading the GLES library for initialization +// and exchanging interface function pointers. +// +typedef EGLClient_glesInterface *(*init_emul_gles_t)(EGLClient_eglInterface *eglIface); + +#endif diff --git a/emulator/opengl/system/OpenglSystemCommon/HostConnection.cpp b/emulator/opengl/system/OpenglSystemCommon/HostConnection.cpp new file mode 100644 index 0000000..940f5ae --- /dev/null +++ b/emulator/opengl/system/OpenglSystemCommon/HostConnection.cpp @@ -0,0 +1,153 @@ +/* +* 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 "HostConnection.h" +#include "TcpStream.h" +#include "QemuPipeStream.h" +#include "ThreadInfo.h" +#include <cutils/log.h> +#include "GLEncoder.h" +#include "GL2Encoder.h" + +#define STREAM_BUFFER_SIZE 4*1024*1024 +#define STREAM_PORT_NUM 22468 + +/* Set to 1 to use a QEMU pipe, or 0 for a TCP connection */ +#define USE_QEMU_PIPE 1 + +HostConnection::HostConnection() : + m_stream(NULL), + m_glEnc(NULL), + m_gl2Enc(NULL), + m_rcEnc(NULL) +{ +} + +HostConnection::~HostConnection() +{ + delete m_stream; + delete m_glEnc; + delete m_gl2Enc; + delete m_rcEnc; +} + +HostConnection *HostConnection::get() +{ + /* TODO: Make this configurable with a system property */ + const int useQemuPipe = USE_QEMU_PIPE; + + // Get thread info + EGLThreadInfo *tinfo = getEGLThreadInfo(); + if (!tinfo) { + return NULL; + } + + if (tinfo->hostConn == NULL) { + HostConnection *con = new HostConnection(); + if (NULL == con) { + return NULL; + } + + if (useQemuPipe) { + QemuPipeStream *stream = new QemuPipeStream(STREAM_BUFFER_SIZE); + if (!stream) { + ALOGE("Failed to create QemuPipeStream for host connection!!!\n"); + delete con; + return NULL; + } + if (stream->connect() < 0) { + ALOGE("Failed to connect to host (QemuPipeStream)!!!\n"); + delete stream; + delete con; + return NULL; + } + con->m_stream = stream; + } + else /* !useQemuPipe */ + { + TcpStream *stream = new TcpStream(STREAM_BUFFER_SIZE); + if (!stream) { + ALOGE("Failed to create TcpStream for host connection!!!\n"); + delete con; + return NULL; + } + + if (stream->connect("10.0.2.2", STREAM_PORT_NUM) < 0) { + ALOGE("Failed to connect to host (TcpStream)!!!\n"); + delete stream; + delete con; + return NULL; + } + con->m_stream = stream; + } + + // send zero 'clientFlags' to the host. + unsigned int *pClientFlags = + (unsigned int *)con->m_stream->allocBuffer(sizeof(unsigned int)); + *pClientFlags = 0; + con->m_stream->commitBuffer(sizeof(unsigned int)); + + ALOGD("HostConnection::get() New Host Connection established %p, tid %d\n", con, gettid()); + tinfo->hostConn = con; + } + + return tinfo->hostConn; +} + +GLEncoder *HostConnection::glEncoder() +{ + if (!m_glEnc) { + m_glEnc = new GLEncoder(m_stream); + DBG("HostConnection::glEncoder new encoder %p, tid %d", m_glEnc, gettid()); + m_glEnc->setContextAccessor(s_getGLContext); + } + return m_glEnc; +} + +GL2Encoder *HostConnection::gl2Encoder() +{ + if (!m_gl2Enc) { + m_gl2Enc = new GL2Encoder(m_stream); + DBG("HostConnection::gl2Encoder new encoder %p, tid %d", m_gl2Enc, gettid()); + m_gl2Enc->setContextAccessor(s_getGL2Context); + } + return m_gl2Enc; +} + +renderControl_encoder_context_t *HostConnection::rcEncoder() +{ + if (!m_rcEnc) { + m_rcEnc = new renderControl_encoder_context_t(m_stream); + } + return m_rcEnc; +} + +gl_client_context_t *HostConnection::s_getGLContext() +{ + EGLThreadInfo *ti = getEGLThreadInfo(); + if (ti->hostConn) { + return ti->hostConn->m_glEnc; + } + return NULL; +} + +gl2_client_context_t *HostConnection::s_getGL2Context() +{ + EGLThreadInfo *ti = getEGLThreadInfo(); + if (ti->hostConn) { + return ti->hostConn->m_gl2Enc; + } + return NULL; +} diff --git a/emulator/opengl/system/OpenglSystemCommon/HostConnection.h b/emulator/opengl/system/OpenglSystemCommon/HostConnection.h new file mode 100644 index 0000000..e7a5ac4 --- /dev/null +++ b/emulator/opengl/system/OpenglSystemCommon/HostConnection.h @@ -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. +*/ +#ifndef __COMMON_HOST_CONNECTION_H +#define __COMMON_HOST_CONNECTION_H + +#include "IOStream.h" +#include "renderControl_enc.h" + +class GLEncoder; +class gl_client_context_t; +class GL2Encoder; +class gl2_client_context_t; + +class HostConnection +{ +public: + static HostConnection *get(); + ~HostConnection(); + + GLEncoder *glEncoder(); + GL2Encoder *gl2Encoder(); + renderControl_encoder_context_t *rcEncoder(); + + void flush() { + if (m_stream) { + m_stream->flush(); + } + } + +private: + HostConnection(); + static gl_client_context_t *s_getGLContext(); + static gl2_client_context_t *s_getGL2Context(); + +private: + IOStream *m_stream; + GLEncoder *m_glEnc; + GL2Encoder *m_gl2Enc; + renderControl_encoder_context_t *m_rcEnc; +}; + +#endif diff --git a/emulator/opengl/system/OpenglSystemCommon/QemuPipeStream.cpp b/emulator/opengl/system/OpenglSystemCommon/QemuPipeStream.cpp new file mode 100644 index 0000000..50c3d8b --- /dev/null +++ b/emulator/opengl/system/OpenglSystemCommon/QemuPipeStream.cpp @@ -0,0 +1,190 @@ +/* +* 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 "QemuPipeStream.h" +#include <hardware/qemu_pipe.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> + +QemuPipeStream::QemuPipeStream(size_t bufSize) : + IOStream(bufSize), + m_sock(-1), + m_bufsize(bufSize), + m_buf(NULL) +{ +} + +QemuPipeStream::QemuPipeStream(int sock, size_t bufSize) : + IOStream(bufSize), + m_sock(sock), + m_bufsize(bufSize), + m_buf(NULL) +{ +} + +QemuPipeStream::~QemuPipeStream() +{ + if (m_sock >= 0) { + ::close(m_sock); + } + if (m_buf != NULL) { + free(m_buf); + } +} + + +int QemuPipeStream::connect(void) +{ + m_sock = qemu_pipe_open("opengles"); + if (!valid()) return -1; + return 0; +} + +void *QemuPipeStream::allocBuffer(size_t minSize) +{ + size_t allocSize = (m_bufsize < minSize ? minSize : m_bufsize); + if (!m_buf) { + m_buf = (unsigned char *)malloc(allocSize); + } + else if (m_bufsize < allocSize) { + unsigned char *p = (unsigned char *)realloc(m_buf, allocSize); + if (p != NULL) { + m_buf = p; + m_bufsize = allocSize; + } else { + ERR("realloc (%d) failed\n", allocSize); + free(m_buf); + m_buf = NULL; + m_bufsize = 0; + } + } + + return m_buf; +}; + +int QemuPipeStream::commitBuffer(size_t size) +{ + return writeFully(m_buf, size); +} + +int QemuPipeStream::writeFully(const void *buf, size_t len) +{ + //DBG(">> QemuPipeStream::writeFully %d\n", len); + if (!valid()) return -1; + + size_t res = len; + int retval = 0; + + while (res > 0) { + ssize_t stat = ::write(m_sock, (const char *)(buf) + (len - res), res); + if (stat > 0) { + res -= stat; + continue; + } + if (stat == 0) { /* EOF */ + ERR("QemuPipeStream::writeFully failed: premature EOF\n"); + retval = -1; + break; + } + if (errno == EINTR) { + continue; + } + retval = stat; + ERR("QemuPipeStream::writeFully failed: %s\n", strerror(errno)); + break; + } + //DBG("<< QemuPipeStream::writeFully %d\n", len ); + return retval; +} + +const unsigned char *QemuPipeStream::readFully(void *buf, size_t len) +{ + //DBG(">> QemuPipeStream::readFully %d\n", len); + if (!valid()) return NULL; + if (!buf) { + if (len>0) ERR("QemuPipeStream::readFully failed, buf=NULL, len %d", len); + return NULL; // do not allow NULL buf in that implementation + } + size_t res = len; + while (res > 0) { + ssize_t stat = ::read(m_sock, (char *)(buf) + len - res, len); + if (stat == 0) { + // client shutdown; + return NULL; + } else if (stat < 0) { + if (errno == EINTR) { + continue; + } else { + ERR("QemuPipeStream::readFully failed (buf %p): %s\n", + buf, strerror(errno)); + return NULL; + } + } else { + res -= stat; + } + } + //DBG("<< QemuPipeStream::readFully %d\n", len); + return (const unsigned char *)buf; +} + +const unsigned char *QemuPipeStream::read( void *buf, size_t *inout_len) +{ + //DBG(">> QemuPipeStream::read %d\n", *inout_len); + if (!valid()) return NULL; + if (!buf) { + ERR("QemuPipeStream::read failed, buf=NULL"); + return NULL; // do not allow NULL buf in that implementation + } + + int n = recv(buf, *inout_len); + + if (n > 0) { + *inout_len = n; + return (const unsigned char *)buf; + } + + //DBG("<< QemuPipeStream::read %d\n", *inout_len); + return NULL; +} + +int QemuPipeStream::recv(void *buf, size_t len) +{ + if (!valid()) return int(ERR_INVALID_SOCKET); + char* p = (char *)buf; + int ret = 0; + while(len > 0) { + int res = ::read(m_sock, p, len); + if (res > 0) { + p += res; + ret += res; + len -= res; + continue; + } + if (res == 0) { /* EOF */ + break; + } + if (errno == EINTR) + continue; + + /* A real error */ + if (ret == 0) + ret = -1; + break; + } + return ret; +} diff --git a/emulator/opengl/system/OpenglSystemCommon/QemuPipeStream.h b/emulator/opengl/system/OpenglSystemCommon/QemuPipeStream.h new file mode 100644 index 0000000..57ee399 --- /dev/null +++ b/emulator/opengl/system/OpenglSystemCommon/QemuPipeStream.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 __QEMU_PIPE_STREAM_H +#define __QEMU_PIPE_STREAM_H + +/* This file implements an IOStream that uses a QEMU fast-pipe + * to communicate with the emulator's 'opengles' service. See + * <hardware/qemu_pipe.h> for more details. + */ +#include <stdlib.h> +#include "IOStream.h" + +class QemuPipeStream : public IOStream { +public: + typedef enum { ERR_INVALID_SOCKET = -1000 } QemuPipeStreamError; + + explicit QemuPipeStream(size_t bufsize = 10000); + ~QemuPipeStream(); + int connect(void); + + virtual void *allocBuffer(size_t minSize); + virtual int commitBuffer(size_t size); + virtual const unsigned char *readFully( void *buf, size_t len); + virtual const unsigned char *read( void *buf, size_t *inout_len); + + bool valid() { return m_sock >= 0; } + int recv(void *buf, size_t len); + + virtual int writeFully(const void *buf, size_t len); + +private: + int m_sock; + size_t m_bufsize; + unsigned char *m_buf; + QemuPipeStream(int sock, size_t bufSize); +}; + +#endif diff --git a/emulator/opengl/system/OpenglSystemCommon/ThreadInfo.cpp b/emulator/opengl/system/OpenglSystemCommon/ThreadInfo.cpp new file mode 100644 index 0000000..75da8f2 --- /dev/null +++ b/emulator/opengl/system/OpenglSystemCommon/ThreadInfo.cpp @@ -0,0 +1,39 @@ +/* +* 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" +#include "cutils/threads.h" + +thread_store_t s_tls = THREAD_STORE_INITIALIZER; + +static void tlsDestruct(void *ptr) +{ + if (ptr) { + EGLThreadInfo *ti = (EGLThreadInfo *)ptr; + delete ti->hostConn; + delete ti; + } +} + +EGLThreadInfo *slow_getEGLThreadInfo() +{ + EGLThreadInfo *ti = (EGLThreadInfo *)thread_store_get(&s_tls); + if (ti) return ti; + + ti = new EGLThreadInfo(); + thread_store_set(&s_tls, ti, tlsDestruct); + + return ti; +} diff --git a/emulator/opengl/system/OpenglSystemCommon/ThreadInfo.h b/emulator/opengl/system/OpenglSystemCommon/ThreadInfo.h new file mode 100644 index 0000000..0328733 --- /dev/null +++ b/emulator/opengl/system/OpenglSystemCommon/ThreadInfo.h @@ -0,0 +1,59 @@ +/* +* 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 "HostConnection.h" +#include <pthread.h> +#ifdef HAVE_ANDROID_OS +#include <bionic_tls.h> +#endif + +struct EGLContext_t; + +struct EGLThreadInfo +{ + EGLThreadInfo() : currentContext(NULL), hostConn(NULL), eglError(EGL_SUCCESS) {} + + EGLContext_t *currentContext; + HostConnection *hostConn; + int eglError; +}; + + +EGLThreadInfo *slow_getEGLThreadInfo(); + +#ifdef HAVE_ANDROID_OS + // We have a dedicated TLS slot in bionic + inline EGLThreadInfo* getEGLThreadInfo() { + EGLThreadInfo *tInfo = + (EGLThreadInfo *)(((unsigned *)__get_tls())[TLS_SLOT_OPENGL]); + if (!tInfo) { + tInfo = slow_getEGLThreadInfo(); + ((uint32_t *)__get_tls())[TLS_SLOT_OPENGL] = (uint32_t)tInfo; + } + return tInfo; + } +#else + inline EGLThreadInfo* getEGLThreadInfo() { + return slow_getEGLThreadInfo(); + } +#endif + + + + +#endif // of _THREAD_INFO_H diff --git a/emulator/opengl/system/OpenglSystemCommon/gralloc_cb.h b/emulator/opengl/system/OpenglSystemCommon/gralloc_cb.h new file mode 100644 index 0000000..e879409 --- /dev/null +++ b/emulator/opengl/system/OpenglSystemCommon/gralloc_cb.h @@ -0,0 +1,106 @@ +/* +* 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 __GRALLOC_CB_H__ +#define __GRALLOC_CB_H__ + +#include <hardware/hardware.h> +#include <hardware/gralloc.h> +#include <cutils/native_handle.h> + +#define BUFFER_HANDLE_MAGIC ((int)0xabfabfab) +#define CB_HANDLE_NUM_INTS(nfds) (int)((sizeof(cb_handle_t) - (nfds)*sizeof(int)) / sizeof(int)) + +// +// Our buffer handle structure +// +struct cb_handle_t : public native_handle { + + cb_handle_t(int p_fd, int p_ashmemSize, int p_usage, + int p_width, int p_height, + int p_glFormat, int p_glType) : + fd(p_fd), + magic(BUFFER_HANDLE_MAGIC), + usage(p_usage), + width(p_width), + height(p_height), + glFormat(p_glFormat), + glType(p_glType), + ashmemSize(p_ashmemSize), + ashmemBase(NULL), + ashmemBasePid(0), + mappedPid(0), + lockedLeft(0), + lockedTop(0), + lockedWidth(0), + lockedHeight(0), + hostHandle(0) + { + version = sizeof(native_handle); + numFds = 0; + numInts = CB_HANDLE_NUM_INTS(numFds); + } + + ~cb_handle_t() { + magic = 0; + } + + void setFd(int p_fd) { + if (p_fd >= 0) { + numFds = 1; + } + else { + numFds = 0; + } + fd = p_fd; + numInts = CB_HANDLE_NUM_INTS(numFds); + } + + static bool validate(cb_handle_t * hnd) { + return (hnd && + hnd->version == sizeof(native_handle) && + hnd->magic == BUFFER_HANDLE_MAGIC && + hnd->numInts == CB_HANDLE_NUM_INTS(hnd->numFds)); + } + + bool canBePosted() { + return (0 != (usage & GRALLOC_USAGE_HW_FB)); + } + + // file-descriptors + int fd; // ashmem fd (-1 of ashmem region did not allocated, i.e. no SW access needed) + + // ints + int magic; // magic number in order to validate a pointer to be a cb_handle_t + int usage; // usage bits the buffer was created with + int width; // buffer width + int height; // buffer height + int glFormat; // OpenGL format enum used for host h/w color buffer + int glType; // OpenGL type enum used when uploading to host + int ashmemSize; // ashmem region size for the buffer (0 unless is HW_FB buffer or + // s/w access is needed) + int ashmemBase; // CPU address of the mapped ashmem region + int ashmemBasePid; // process id which mapped the ashmem region + int mappedPid; // process id which succeeded gralloc_register call + int lockedLeft; // region of buffer locked for s/w write + int lockedTop; + int lockedWidth; + int lockedHeight; + uint32_t hostHandle; +}; + + +#endif //__GRALLOC_CB_H__ diff --git a/emulator/opengl/system/egl/Android.mk b/emulator/opengl/system/egl/Android.mk new file mode 100644 index 0000000..da9398f --- /dev/null +++ b/emulator/opengl/system/egl/Android.mk @@ -0,0 +1,42 @@ +ifneq (false,$(BUILD_EMULATOR_OPENGL_DRIVER)) + +LOCAL_PATH := $(call my-dir) + +$(call emugl-begin-shared-library,libEGL_emulation) +$(call emugl-import,libOpenglSystemCommon) +$(call emugl-set-shared-library-subpath,egl) + +LOCAL_CFLAGS += -DLOG_TAG=\"EGL_emulation\" -DEGL_EGLEXT_PROTOTYPES -DWITH_GLES2 + +LOCAL_SRC_FILES := \ + eglDisplay.cpp \ + egl.cpp \ + ClientAPIExts.cpp + +LOCAL_SHARED_LIBRARIES += libdl + +# Used to access the Bionic private OpenGL TLS slot +LOCAL_C_INCLUDES += bionic/libc/private + +$(call emugl-end-module) + +#### egl.cfg #### + +# Ensure that this file is only copied to emulator-specific builds. +# Other builds are device-specific and will provide their own +# version of this file to point to the appropriate HW EGL libraries. +# +ifneq (,$(filter full full_x86 sdk sdk_x86 google_sdk google_sdk_x86,$(TARGET_PRODUCT))) +include $(CLEAR_VARS) + +LOCAL_MODULE := egl.cfg +LOCAL_SRC_FILES := $(LOCAL_MODULE) + +LOCAL_MODULE_PATH := $(TARGET_OUT)/lib/egl +LOCAL_MODULE_TAGS := debug +LOCAL_MODULE_CLASS := ETC + +include $(BUILD_PREBUILT) +endif # TARGET_PRODUCT in 'full sdk full_x86 sdk_x86 google_sdk google_sdk_x86) + +endif # BUILD_EMULATOR_OPENGL_DRIVER != false diff --git a/emulator/opengl/system/egl/ClientAPIExts.cpp b/emulator/opengl/system/egl/ClientAPIExts.cpp new file mode 100644 index 0000000..5e81afe --- /dev/null +++ b/emulator/opengl/system/egl/ClientAPIExts.cpp @@ -0,0 +1,157 @@ +/* +* 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 "ThreadInfo.h" +#include <GLES/gl.h> +#include <GLES/glext.h> +#include "eglContext.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[2]; + +#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(const EGLClient_glesInterface *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 \ + { \ + EGLThreadInfo* thread = getEGLThreadInfo(); \ + if (!thread->currentContext) { \ + return; \ + } \ + int idx = (int)thread->currentContext->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 \ + { \ + EGLThreadInfo* thread = getEGLThreadInfo(); \ + if (!thread->currentContext) { \ + return (rtype)0; \ + } \ + int idx = (int)thread->currentContext->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, (void*)_egl_ ## fname}, +#define API_ENTRY_RET(rtype,fname,params,args) \ + API_ENTRY(fname,params,args) + +static const struct _client_ext_funcs { + const char *fname; + void* 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. +// +void* 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/system/egl/ClientAPIExts.h b/emulator/opengl/system/egl/ClientAPIExts.h new file mode 100644 index 0000000..eee9172 --- /dev/null +++ b/emulator/opengl/system/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 "EGLClientIface.h" + +namespace ClientAPIExts +{ + +void initClientFuncs(const EGLClient_glesInterface *iface, int idx); +void* getProcAddress(const char *fname); + +} // of namespace ClientAPIExts + +#endif diff --git a/emulator/opengl/system/egl/ClientAPIExts.in b/emulator/opengl/system/egl/ClientAPIExts.in new file mode 100644 index 0000000..5850701 --- /dev/null +++ b/emulator/opengl/system/egl/ClientAPIExts.in @@ -0,0 +1,201 @@ +// +// Each extension function should have one of the following +// macro definitions: +// API_ENTRY(funcname, paramlist, arglist) +// -or- (if the function has a 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/system/egl/egl.cfg b/emulator/opengl/system/egl/egl.cfg new file mode 100644 index 0000000..9d3f2dc --- /dev/null +++ b/emulator/opengl/system/egl/egl.cfg @@ -0,0 +1 @@ +0 0 emulation diff --git a/emulator/opengl/system/egl/egl.cpp b/emulator/opengl/system/egl/egl.cpp new file mode 100644 index 0000000..5aa5bda --- /dev/null +++ b/emulator/opengl/system/egl/egl.cpp @@ -0,0 +1,1211 @@ +/* +* 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 "HostConnection.h" +#include "ThreadInfo.h" +#include "eglDisplay.h" +#include "egl_ftable.h" +#include <cutils/log.h> +#include "gralloc_cb.h" +#include "GLClientState.h" +#include "GLSharedGroup.h" +#include "eglContext.h" +#include "ClientAPIExts.h" + +#include "GLEncoder.h" +#ifdef WITH_GLES2 +#include "GL2Encoder.h" +#endif + +#include <system/window.h> + +template<typename T> +static T setErrorFunc(GLint error, T returnValue) { + getEGLThreadInfo()->eglError = error; + return returnValue; +} + +const char * eglStrError(EGLint err) +{ + switch (err){ + case EGL_SUCCESS: return "EGL_SUCCESS"; + case EGL_NOT_INITIALIZED: return "EGL_NOT_INITIALIZED"; + case EGL_BAD_ACCESS: return "EGL_BAD_ACCESS"; + case EGL_BAD_ALLOC: return "EGL_BAD_ALLOC"; + case EGL_BAD_ATTRIBUTE: return "EGL_BAD_ATTRIBUTE"; + case EGL_BAD_CONFIG: return "EGL_BAD_CONFIG"; + case EGL_BAD_CONTEXT: return "EGL_BAD_CONTEXT"; + case EGL_BAD_CURRENT_SURFACE: return "EGL_BAD_CURRENT_SURFACE"; + case EGL_BAD_DISPLAY: return "EGL_BAD_DISPLAY"; + case EGL_BAD_MATCH: return "EGL_BAD_MATCH"; + case EGL_BAD_NATIVE_PIXMAP: return "EGL_BAD_NATIVE_PIXMAP"; + case EGL_BAD_NATIVE_WINDOW: return "EGL_BAD_NATIVE_WINDOW"; + case EGL_BAD_PARAMETER: return "EGL_BAD_PARAMETER"; + case EGL_BAD_SURFACE: return "EGL_BAD_SURFACE"; + case EGL_CONTEXT_LOST: return "EGL_CONTEXT_LOST"; + default: return "UNKNOWN"; + } +} + +#define LOG_EGL_ERRORS 1 + +#ifdef LOG_EGL_ERRORS + +#define setErrorReturn(error, retVal) \ + { \ + ALOGE("tid %d: %s(%d): error 0x%x (%s)", gettid(), __FUNCTION__, __LINE__, error, eglStrError(error)); \ + return setErrorFunc(error, retVal); \ + } + +#define RETURN_ERROR(ret,err) \ + ALOGE("tid %d: %s(%d): error 0x%x (%s)", gettid(), __FUNCTION__, __LINE__, err, eglStrError(err)); \ + getEGLThreadInfo()->eglError = err; \ + return ret; + +#else //!LOG_EGL_ERRORS + +#define setErrorReturn(error, retVal) return setErrorFunc(error, retVal); + +#define RETURN_ERROR(ret,err) \ + getEGLThreadInfo()->eglError = err; \ + return ret; + +#endif //LOG_EGL_ERRORS + +#define VALIDATE_CONFIG(cfg,ret) \ + if(((int)cfg<0)||((int)cfg>s_display.getNumConfigs())) { \ + RETURN_ERROR(ret,EGL_BAD_CONFIG); \ + } + +#define VALIDATE_DISPLAY(dpy,ret) \ + if ((dpy) != (EGLDisplay)&s_display) { \ + RETURN_ERROR(ret, EGL_BAD_DISPLAY); \ + } + +#define VALIDATE_DISPLAY_INIT(dpy,ret) \ + VALIDATE_DISPLAY(dpy, ret) \ + if (!s_display.initialized()) { \ + RETURN_ERROR(ret, EGL_NOT_INITIALIZED); \ + } + +#define DEFINE_HOST_CONNECTION \ + HostConnection *hostCon = HostConnection::get(); \ + renderControl_encoder_context_t *rcEnc = (hostCon ? hostCon->rcEncoder() : NULL) + +#define DEFINE_AND_VALIDATE_HOST_CONNECTION(ret) \ + HostConnection *hostCon = HostConnection::get(); \ + if (!hostCon) { \ + ALOGE("egl: Failed to get host connection\n"); \ + return ret; \ + } \ + renderControl_encoder_context_t *rcEnc = hostCon->rcEncoder(); \ + if (!rcEnc) { \ + ALOGE("egl: Failed to get renderControl encoder context\n"); \ + return ret; \ + } + +#define VALIDATE_CONTEXT_RETURN(context,ret) \ + if (!context) { \ + RETURN_ERROR(ret,EGL_BAD_CONTEXT); \ + } + +#define VALIDATE_SURFACE_RETURN(surface, ret) \ + if (surface != EGL_NO_SURFACE) { \ + egl_surface_t* s( static_cast<egl_surface_t*>(surface) ); \ + if (s->dpy != (EGLDisplay)&s_display) \ + setErrorReturn(EGL_BAD_DISPLAY, EGL_FALSE); \ + } + + +EGLContext_t::EGLContext_t(EGLDisplay dpy, EGLConfig config, EGLContext_t* shareCtx) : + dpy(dpy), + config(config), + read(EGL_NO_SURFACE), + draw(EGL_NO_SURFACE), + shareCtx(shareCtx), + rcContext(0), + versionString(NULL), + vendorString(NULL), + rendererString(NULL), + extensionString(NULL) +{ + flags = 0; + version = 1; + clientState = new GLClientState(); + if (shareCtx) + sharedGroup = shareCtx->getSharedGroup(); + else + sharedGroup = GLSharedGroupPtr(new GLSharedGroup()); +}; + +EGLContext_t::~EGLContext_t() +{ + delete clientState; + delete [] versionString; + delete [] vendorString; + delete [] rendererString; + delete [] extensionString; +} + +// ---------------------------------------------------------------------------- +//egl_surface_t + +//we don't need to handle depth since it's handled when window created on the host + +struct egl_surface_t { + + EGLDisplay dpy; + EGLConfig config; + + + egl_surface_t(EGLDisplay dpy, EGLConfig config, EGLint surfaceType); + virtual ~egl_surface_t(); + + virtual void setSwapInterval(int interval) = 0; + virtual EGLBoolean swapBuffers() = 0; + + EGLint getSwapBehavior() const; + uint32_t getRcSurface() { return rcSurface; } + EGLint getSurfaceType() { return surfaceType; } + + EGLint getWidth(){ return width; } + EGLint getHeight(){ return height; } + void setTextureFormat(EGLint _texFormat) { texFormat = _texFormat; } + EGLint getTextureFormat() { return texFormat; } + void setTextureTarget(EGLint _texTarget) { texTarget = _texTarget; } + EGLint getTextureTarget() { return texTarget; } + +private: + // + //Surface attributes + // + EGLint width; + EGLint height; + EGLint texFormat; + EGLint texTarget; + +protected: + void setWidth(EGLint w) { width = w; } + void setHeight(EGLint h) { height = h; } + + EGLint surfaceType; + uint32_t rcSurface; //handle to surface created via remote control +}; + +egl_surface_t::egl_surface_t(EGLDisplay dpy, EGLConfig config, EGLint surfaceType) + : dpy(dpy), config(config), surfaceType(surfaceType), rcSurface(0) +{ + width = 0; + height = 0; + texFormat = EGL_NO_TEXTURE; + texTarget = EGL_NO_TEXTURE; +} + +EGLint egl_surface_t::getSwapBehavior() const { + return EGL_BUFFER_PRESERVED; +} + +egl_surface_t::~egl_surface_t() +{ +} + +// ---------------------------------------------------------------------------- +// egl_window_surface_t + +struct egl_window_surface_t : public egl_surface_t { + static egl_window_surface_t* create( + EGLDisplay dpy, EGLConfig config, EGLint surfType, + ANativeWindow* window); + + virtual ~egl_window_surface_t(); + + virtual void setSwapInterval(int interval); + virtual EGLBoolean swapBuffers(); + +private: + egl_window_surface_t( + EGLDisplay dpy, EGLConfig config, EGLint surfType, + ANativeWindow* window); + EGLBoolean init(); + + ANativeWindow* nativeWindow; + android_native_buffer_t* buffer; +}; + +egl_window_surface_t::egl_window_surface_t ( + EGLDisplay dpy, EGLConfig config, EGLint surfType, + ANativeWindow* window) +: egl_surface_t(dpy, config, surfType), + nativeWindow(window), + buffer(NULL) +{ + // keep a reference on the window + nativeWindow->common.incRef(&nativeWindow->common); + EGLint w,h; + nativeWindow->query(nativeWindow, NATIVE_WINDOW_WIDTH, &w); + setWidth(w); + nativeWindow->query(nativeWindow, NATIVE_WINDOW_HEIGHT, &h); + setHeight(h); +} + +EGLBoolean egl_window_surface_t::init() +{ + if (nativeWindow->dequeueBuffer(nativeWindow, &buffer) != NO_ERROR) { + setErrorReturn(EGL_BAD_ALLOC, EGL_FALSE); + } + nativeWindow->lockBuffer(nativeWindow, buffer); + + DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE); + rcSurface = rcEnc->rcCreateWindowSurface(rcEnc, (uint32_t)config, + getWidth(), getHeight()); + if (!rcSurface) { + ALOGE("rcCreateWindowSurface returned 0"); + return EGL_FALSE; + } + rcEnc->rcSetWindowColorBuffer(rcEnc, rcSurface, + ((cb_handle_t*)(buffer->handle))->hostHandle); + + return EGL_TRUE; +} + +egl_window_surface_t* egl_window_surface_t::create( + EGLDisplay dpy, EGLConfig config, EGLint surfType, + ANativeWindow* window) +{ + egl_window_surface_t* wnd = new egl_window_surface_t( + dpy, config, surfType, window); + if (wnd && !wnd->init()) { + delete wnd; + wnd = NULL; + } + return wnd; +} + +egl_window_surface_t::~egl_window_surface_t() { + DEFINE_HOST_CONNECTION; + if (rcSurface && rcEnc) { + rcEnc->rcDestroyWindowSurface(rcEnc, rcSurface); + } + if (buffer) { + nativeWindow->cancelBuffer(nativeWindow, buffer); + } + nativeWindow->common.decRef(&nativeWindow->common); +} + +void egl_window_surface_t::setSwapInterval(int interval) +{ + nativeWindow->setSwapInterval(nativeWindow, interval); +} + +EGLBoolean egl_window_surface_t::swapBuffers() +{ + DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE); + + rcEnc->rcFlushWindowColorBuffer(rcEnc, rcSurface); + + nativeWindow->queueBuffer(nativeWindow, buffer); + if (nativeWindow->dequeueBuffer(nativeWindow, &buffer)) { + buffer = NULL; + setErrorReturn(EGL_BAD_ALLOC, EGL_FALSE); + } + nativeWindow->lockBuffer(nativeWindow, buffer); + + rcEnc->rcSetWindowColorBuffer(rcEnc, rcSurface, + ((cb_handle_t *)(buffer->handle))->hostHandle); + + return EGL_TRUE; +} + +// ---------------------------------------------------------------------------- +//egl_pbuffer_surface_t + +struct egl_pbuffer_surface_t : public egl_surface_t { + static egl_pbuffer_surface_t* create(EGLDisplay dpy, EGLConfig config, + EGLint surfType, int32_t w, int32_t h, GLenum pixelFormat); + + virtual ~egl_pbuffer_surface_t(); + + virtual void setSwapInterval(int interval) {} + virtual EGLBoolean swapBuffers() { return EGL_TRUE; } + + uint32_t getRcColorBuffer() { return rcColorBuffer; } + +private: + egl_pbuffer_surface_t(EGLDisplay dpy, EGLConfig config, EGLint surfType, + int32_t w, int32_t h); + EGLBoolean init(GLenum format); + + uint32_t rcColorBuffer; +}; + +egl_pbuffer_surface_t::egl_pbuffer_surface_t(EGLDisplay dpy, EGLConfig config, + EGLint surfType, int32_t w, int32_t h) +: egl_surface_t(dpy, config, surfType), + rcColorBuffer(0) +{ + setWidth(w); + setHeight(h); +} + +egl_pbuffer_surface_t::~egl_pbuffer_surface_t() +{ + DEFINE_HOST_CONNECTION; + if (rcEnc) { + if (rcColorBuffer) rcEnc->rcCloseColorBuffer(rcEnc, rcColorBuffer); + if (rcSurface) rcEnc->rcDestroyWindowSurface(rcEnc, rcSurface); + } +} + +EGLBoolean egl_pbuffer_surface_t::init(GLenum pixelFormat) +{ + DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE); + + rcSurface = rcEnc->rcCreateWindowSurface(rcEnc, (uint32_t)config, + getWidth(), getHeight()); + if (!rcSurface) { + ALOGE("rcCreateWindowSurface returned 0"); + return EGL_FALSE; + } + + rcColorBuffer = rcEnc->rcCreateColorBuffer(rcEnc, getWidth(), getHeight(), + pixelFormat); + if (!rcColorBuffer) { + ALOGE("rcCreateColorBuffer returned 0"); + return EGL_FALSE; + } + + rcEnc->rcSetWindowColorBuffer(rcEnc, rcSurface, rcColorBuffer); + + return EGL_TRUE; +} + +egl_pbuffer_surface_t* egl_pbuffer_surface_t::create(EGLDisplay dpy, + EGLConfig config, EGLint surfType, int32_t w, int32_t h, + GLenum pixelFormat) +{ + egl_pbuffer_surface_t* pb = new egl_pbuffer_surface_t(dpy, config, surfType, + w, h); + if (pb && !pb->init(pixelFormat)) { + delete pb; + pb = NULL; + } + return pb; +} + +static const char *getGLString(int glEnum) +{ + EGLThreadInfo *tInfo = getEGLThreadInfo(); + if (!tInfo || !tInfo->currentContext) { + return NULL; + } + + const char** strPtr = NULL; + +#define GL_VENDOR 0x1F00 +#define GL_RENDERER 0x1F01 +#define GL_VERSION 0x1F02 +#define GL_EXTENSIONS 0x1F03 + + switch(glEnum) { + case GL_VERSION: + strPtr = &tInfo->currentContext->versionString; + break; + case GL_VENDOR: + strPtr = &tInfo->currentContext->vendorString; + break; + case GL_RENDERER: + strPtr = &tInfo->currentContext->rendererString; + break; + case GL_EXTENSIONS: + strPtr = &tInfo->currentContext->extensionString; + break; + } + + if (!strPtr) { + return NULL; + } + + if (*strPtr != NULL) { + // + // string is already cached + // + return *strPtr; + } + + // + // first query of that string - need to query host + // + DEFINE_AND_VALIDATE_HOST_CONNECTION(NULL); + char *hostStr = NULL; + int n = rcEnc->rcGetGLString(rcEnc, glEnum, NULL, 0); + if (n < 0) { + hostStr = new char[-n+1]; + n = rcEnc->rcGetGLString(rcEnc, glEnum, hostStr, -n); + if (n <= 0) { + delete [] hostStr; + hostStr = NULL; + } + } + + // + // keep the string in the context and return its value + // + *strPtr = hostStr; + return hostStr; +} + +// ---------------------------------------------------------------------------- + +// The one and only supported display object. +static eglDisplay s_display; + +static EGLClient_eglInterface s_eglIface = { + getThreadInfo: getEGLThreadInfo, + getGLString: getGLString +}; + +#define DBG_FUNC DBG("%s\n", __FUNCTION__) +EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id) +{ + // + // we support only EGL_DEFAULT_DISPLAY. + // + if (display_id != EGL_DEFAULT_DISPLAY) { + return EGL_NO_DISPLAY; + } + + return (EGLDisplay)&s_display; +} + +EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) +{ + VALIDATE_DISPLAY(dpy,EGL_FALSE); + + if (!s_display.initialize(&s_eglIface)) { + return EGL_FALSE; + } + if (major!=NULL) + *major = s_display.getVersionMajor(); + if (minor!=NULL) + *minor = s_display.getVersionMinor(); + return EGL_TRUE; +} + +EGLBoolean eglTerminate(EGLDisplay dpy) +{ + VALIDATE_DISPLAY_INIT(dpy, EGL_FALSE); + + s_display.terminate(); + return EGL_TRUE; +} + +EGLint eglGetError() +{ + EGLint error = getEGLThreadInfo()->eglError; + getEGLThreadInfo()->eglError = EGL_SUCCESS; + return error; +} + +__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) +{ + // search in EGL function table + for (int i=0; i<egl_num_funcs; i++) { + if (!strcmp(egl_funcs_by_name[i].name, procname)) { + return (__eglMustCastToProperFunctionPointerType)egl_funcs_by_name[i].proc; + } + } + + // + // Make sure display is initialized before searching in client APIs + // + if (!s_display.initialized()) { + if (!s_display.initialize(&s_eglIface)) { + return NULL; + } + } + + // look in gles client api's extensions table + return (__eglMustCastToProperFunctionPointerType)ClientAPIExts::getProcAddress(procname); + + // Fail - function not found. + return NULL; +} + +const char* eglQueryString(EGLDisplay dpy, EGLint name) +{ + VALIDATE_DISPLAY_INIT(dpy, NULL); + + return s_display.queryString(name); +} + +EGLBoolean eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config) +{ + VALIDATE_DISPLAY_INIT(dpy, NULL); + + if(!num_config) { + RETURN_ERROR(EGL_FALSE,EGL_BAD_PARAMETER); + } + + GLint numConfigs = s_display.getNumConfigs(); + if (!configs) { + *num_config = numConfigs; + return EGL_TRUE; + } + + int i=0; + for (i=0 ; i<numConfigs && i<config_size ; i++) { + *configs++ = (EGLConfig)i; + } + *num_config = i; + return EGL_TRUE; +} + +EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config) +{ + VALIDATE_DISPLAY_INIT(dpy, EGL_FALSE); + + int attribs_size = 0; + if (attrib_list) { + const EGLint * attrib_p = attrib_list; + while (attrib_p[0] != EGL_NONE) { + attribs_size += 2; + attrib_p += 2; + } + attribs_size++; //for the terminating EGL_NONE + } + + DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE); + *num_config = rcEnc->rcChooseConfig(rcEnc, (EGLint*)attrib_list, attribs_size * sizeof(EGLint), (uint32_t*)configs, config_size); + + return EGL_TRUE; +} + +EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value) +{ + VALIDATE_DISPLAY_INIT(dpy, NULL); + VALIDATE_CONFIG(config, EGL_FALSE); + + if (s_display.getConfigAttrib(config, attribute, value)) + { + return EGL_TRUE; + } + else + { + RETURN_ERROR(EGL_FALSE, EGL_BAD_ATTRIBUTE); + } +} + +EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list) +{ + VALIDATE_DISPLAY_INIT(dpy, NULL); + VALIDATE_CONFIG(config, EGL_FALSE); + if (win == 0) { + setErrorReturn(EGL_BAD_MATCH, EGL_NO_SURFACE); + } + + EGLint surfaceType; + if (s_display.getConfigAttrib(config, EGL_SURFACE_TYPE, &surfaceType) == EGL_FALSE) return EGL_FALSE; + + if (!(surfaceType & EGL_WINDOW_BIT)) { + setErrorReturn(EGL_BAD_MATCH, EGL_NO_SURFACE); + } + + if (static_cast<ANativeWindow*>(win)->common.magic != ANDROID_NATIVE_WINDOW_MAGIC) { + setErrorReturn(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); + } + + egl_surface_t* surface = egl_window_surface_t::create( + &s_display, config, surfaceType, static_cast<ANativeWindow*>(win)); + if (!surface) { + setErrorReturn(EGL_BAD_ALLOC, EGL_NO_SURFACE); + } + + return surface; +} + +EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list) +{ + VALIDATE_DISPLAY_INIT(dpy, NULL); + VALIDATE_CONFIG(config, EGL_FALSE); + + EGLint surfaceType; + if (s_display.getConfigAttrib(config, EGL_SURFACE_TYPE, &surfaceType) == EGL_FALSE) return EGL_FALSE; + + if (!(surfaceType & EGL_PBUFFER_BIT)) { + setErrorReturn(EGL_BAD_MATCH, EGL_NO_SURFACE); + } + + int32_t w = 0; + int32_t h = 0; + EGLint texFormat = EGL_NO_TEXTURE; + EGLint texTarget = EGL_NO_TEXTURE; + while (attrib_list[0]) { + switch (attrib_list[0]) { + case EGL_WIDTH: + w = attrib_list[1]; + break; + case EGL_HEIGHT: + h = attrib_list[1]; + break; + case EGL_TEXTURE_FORMAT: + texFormat = attrib_list[1]; + break; + case EGL_TEXTURE_TARGET: + texTarget = attrib_list[1]; + break; + default: + break; + }; + attrib_list+=2; + } + if (((texFormat == EGL_NO_TEXTURE)&&(texTarget != EGL_NO_TEXTURE)) || + ((texFormat != EGL_NO_TEXTURE)&&(texTarget == EGL_NO_TEXTURE))) { + setErrorReturn(EGL_BAD_MATCH, EGL_NO_SURFACE); + } + // TODO: check EGL_TEXTURE_FORMAT - need to support eglBindTexImage + + GLenum pixelFormat; + if (s_display.getConfigGLPixelFormat(config, &pixelFormat) == EGL_FALSE) + setErrorReturn(EGL_BAD_MATCH, EGL_NO_SURFACE); + + egl_surface_t* surface = egl_pbuffer_surface_t::create(dpy, config, + surfaceType, w, h, pixelFormat); + if (!surface) { + setErrorReturn(EGL_BAD_ALLOC, EGL_NO_SURFACE); + } + + //setup attributes + surface->setTextureFormat(texFormat); + surface->setTextureTarget(texTarget); + + return surface; +} + +EGLSurface eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list) +{ + //XXX: Pixmap not supported. The host cannot render to a pixmap resource + // located on host. In order to support Pixmaps we should either punt + // to s/w rendering -or- let the host render to a buffer that will be + // copied back to guest at some sync point. None of those methods not + // implemented and pixmaps are not used with OpenGL anyway ... + return EGL_NO_SURFACE; +} + +EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface eglSurface) +{ + VALIDATE_DISPLAY_INIT(dpy, EGL_FALSE); + VALIDATE_SURFACE_RETURN(eglSurface, EGL_FALSE); + + egl_surface_t* surface(static_cast<egl_surface_t*>(eglSurface)); + delete surface; + + return EGL_TRUE; +} + +EGLBoolean eglQuerySurface(EGLDisplay dpy, EGLSurface eglSurface, EGLint attribute, EGLint *value) +{ + VALIDATE_DISPLAY_INIT(dpy, EGL_FALSE); + VALIDATE_SURFACE_RETURN(eglSurface, EGL_FALSE); + + egl_surface_t* surface( static_cast<egl_surface_t*>(eglSurface) ); + EGLBoolean ret = EGL_TRUE; + switch (attribute) { + case EGL_CONFIG_ID: + ret = s_display.getConfigAttrib(surface->config, EGL_CONFIG_ID, value); + break; + case EGL_WIDTH: + *value = surface->getWidth(); + break; + case EGL_HEIGHT: + *value = surface->getHeight(); + break; + case EGL_TEXTURE_FORMAT: + *value = surface->getTextureFormat(); + break; + case EGL_TEXTURE_TARGET: + *value = surface->getTextureTarget(); + break; + case EGL_SWAP_BEHAVIOR: + *value = surface->getSwapBehavior(); + break; + case EGL_LARGEST_PBUFFER: + // not modified for a window or pixmap surface + // and we ignore it when creating a PBuffer surface (default is EGL_FALSE) + if (surface->getSurfaceType() & EGL_PBUFFER_BIT) *value = EGL_FALSE; + break; + //TODO: complete other attributes + default: + ALOGE("eglQuerySurface %x EGL_BAD_ATTRIBUTE", attribute); + ret = setErrorFunc(EGL_BAD_ATTRIBUTE, EGL_FALSE); + break; + } + + return ret; +} + +EGLBoolean eglBindAPI(EGLenum api) +{ + if (api != EGL_OPENGL_ES_API) + setErrorReturn(EGL_BAD_PARAMETER, EGL_FALSE); + return EGL_TRUE; +} + +EGLenum eglQueryAPI() +{ + return EGL_OPENGL_ES_API; +} + +EGLBoolean eglWaitClient() +{ + return eglWaitGL(); +} + +EGLBoolean eglReleaseThread() +{ + EGLThreadInfo *tInfo = getEGLThreadInfo(); + if (tInfo && tInfo->currentContext) { + return eglMakeCurrent(&s_display, EGL_NO_CONTEXT, EGL_NO_SURFACE, EGL_NO_SURFACE); + } + return EGL_TRUE; +} + +EGLSurface eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list) +{ + //TODO + ALOGW("%s not implemented", __FUNCTION__); + return 0; +} + +EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) +{ + //TODO + ALOGW("%s not implemented", __FUNCTION__); + return 0; +} + +EGLBoolean eglBindTexImage(EGLDisplay dpy, EGLSurface eglSurface, EGLint buffer) +{ + VALIDATE_DISPLAY_INIT(dpy, EGL_FALSE); + VALIDATE_SURFACE_RETURN(eglSurface, EGL_FALSE); + if (eglSurface == EGL_NO_SURFACE) { + setErrorReturn(EGL_BAD_SURFACE, EGL_FALSE); + } + + if (buffer != EGL_BACK_BUFFER) { + setErrorReturn(EGL_BAD_PARAMETER, EGL_FALSE); + } + + egl_surface_t* surface( static_cast<egl_surface_t*>(eglSurface) ); + + if (surface->getTextureFormat() == EGL_NO_TEXTURE) { + setErrorReturn(EGL_BAD_MATCH, EGL_FALSE); + } + + if (!(surface->getSurfaceType() & EGL_PBUFFER_BIT)) { + setErrorReturn(EGL_BAD_SURFACE, EGL_FALSE); + } + + //It's now safe to cast to pbuffer surface + egl_pbuffer_surface_t* pbSurface = (egl_pbuffer_surface_t*)surface; + + DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE); + rcEnc->rcBindTexture(rcEnc, pbSurface->getRcColorBuffer()); + + return GL_TRUE; +} + +EGLBoolean eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) +{ + //TODO + ALOGW("%s not implemented", __FUNCTION__); + return 0; +} + +EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) +{ + VALIDATE_DISPLAY_INIT(dpy, EGL_FALSE); + DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE); + + EGLContext_t* ctx = getEGLThreadInfo()->currentContext; + if (!ctx) { + setErrorReturn(EGL_BAD_CONTEXT, EGL_FALSE); + } + if (!ctx->draw) { + setErrorReturn(EGL_BAD_SURFACE, EGL_FALSE); + } + egl_surface_t* draw(static_cast<egl_surface_t*>(ctx->draw)); + draw->setSwapInterval(interval); + + rcEnc->rcFBSetSwapInterval(rcEnc, interval); //TODO: implement on the host + + return EGL_TRUE; +} + +EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list) +{ + VALIDATE_DISPLAY_INIT(dpy, EGL_NO_CONTEXT); + VALIDATE_CONFIG(config, EGL_NO_CONTEXT); + + EGLint version = 1; //default + while (attrib_list && attrib_list[0]) { + if (attrib_list[0] == EGL_CONTEXT_CLIENT_VERSION) version = attrib_list[1]; + attrib_list+=2; + } + + uint32_t rcShareCtx = 0; + EGLContext_t * shareCtx = NULL; + if (share_context) { + shareCtx = static_cast<EGLContext_t*>(share_context); + rcShareCtx = shareCtx->rcContext; + if (shareCtx->dpy != dpy) + setErrorReturn(EGL_BAD_MATCH, EGL_NO_CONTEXT); + } + + DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_NO_CONTEXT); + uint32_t rcContext = rcEnc->rcCreateContext(rcEnc, (uint32_t)config, rcShareCtx, version); + if (!rcContext) { + ALOGE("rcCreateContext returned 0"); + setErrorReturn(EGL_BAD_ALLOC, EGL_NO_CONTEXT); + } + + EGLContext_t * context = new EGLContext_t(dpy, config, shareCtx); + if (!context) + setErrorReturn(EGL_BAD_ALLOC, EGL_NO_CONTEXT); + + context->version = version; + context->rcContext = rcContext; + + + return context; +} + +EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) +{ + VALIDATE_DISPLAY_INIT(dpy, EGL_FALSE); + VALIDATE_CONTEXT_RETURN(ctx, EGL_FALSE); + + EGLContext_t * context = static_cast<EGLContext_t*>(ctx); + + if (getEGLThreadInfo()->currentContext == context) + { + eglMakeCurrent(dpy, EGL_NO_CONTEXT, EGL_NO_SURFACE, EGL_NO_SURFACE); + } + + if (context->rcContext) { + DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE); + rcEnc->rcDestroyContext(rcEnc, context->rcContext); + context->rcContext = 0; + } + + delete context; + return EGL_TRUE; +} + +EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) +{ + VALIDATE_DISPLAY_INIT(dpy, EGL_FALSE); + VALIDATE_SURFACE_RETURN(draw, EGL_FALSE); + VALIDATE_SURFACE_RETURN(read, EGL_FALSE); + + if ((read == EGL_NO_SURFACE && draw == EGL_NO_SURFACE) && (ctx != EGL_NO_CONTEXT)) + setErrorReturn(EGL_BAD_MATCH, EGL_FALSE); + if ((read != EGL_NO_SURFACE || draw != EGL_NO_SURFACE) && (ctx == EGL_NO_CONTEXT)) + setErrorReturn(EGL_BAD_MATCH, EGL_FALSE); + + EGLContext_t * context = static_cast<EGLContext_t*>(ctx); + uint32_t ctxHandle = (context) ? context->rcContext : 0; + egl_surface_t * drawSurf = static_cast<egl_surface_t *>(draw); + uint32_t drawHandle = (drawSurf) ? drawSurf->getRcSurface() : 0; + egl_surface_t * readSurf = static_cast<egl_surface_t *>(read); + uint32_t readHandle = (readSurf) ? readSurf->getRcSurface() : 0; + + // + // Nothing to do if no binding change has made + // + EGLThreadInfo *tInfo = getEGLThreadInfo(); + if (tInfo->currentContext == context && + (context == NULL || + (context && context->draw == draw && context->read == read))) { + return EGL_TRUE; + } + + if (context && (context->flags & EGLContext_t::IS_CURRENT) && (context != tInfo->currentContext)) { + //context is current to another thread + setErrorReturn(EGL_BAD_ACCESS, EGL_FALSE); + } + + DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE); + if (rcEnc->rcMakeCurrent(rcEnc, ctxHandle, drawHandle, readHandle) == EGL_FALSE) { + ALOGE("rcMakeCurrent returned EGL_FALSE"); + setErrorReturn(EGL_BAD_CONTEXT, EGL_FALSE); + } + + //Now make the local bind + if (context) { + context->draw = draw; + context->read = read; + context->flags |= EGLContext_t::IS_CURRENT; + //set the client state + if (context->version == 2) { + hostCon->gl2Encoder()->setClientState(context->getClientState()); + hostCon->gl2Encoder()->setSharedGroup(context->getSharedGroup()); + } + else { + hostCon->glEncoder()->setClientState(context->getClientState()); + hostCon->glEncoder()->setSharedGroup(context->getSharedGroup()); + } + } + else { + //release ClientState & SharedGroup + if (tInfo->currentContext->version == 2) { + hostCon->gl2Encoder()->setClientState(NULL); + hostCon->gl2Encoder()->setSharedGroup(GLSharedGroupPtr(NULL)); + } + else { + hostCon->glEncoder()->setClientState(NULL); + hostCon->glEncoder()->setSharedGroup(GLSharedGroupPtr(NULL)); + } + + } + + if (tInfo->currentContext) + tInfo->currentContext->flags &= ~EGLContext_t::IS_CURRENT; + + //Now make current + tInfo->currentContext = context; + + //Check maybe we need to init the encoder, if it's first eglMakeCurrent + if (tInfo->currentContext) { + if (tInfo->currentContext->version == 2) { + if (!hostCon->gl2Encoder()->isInitialized()) { + s_display.gles2_iface()->init(); + hostCon->gl2Encoder()->setInitialized(); + ClientAPIExts::initClientFuncs(s_display.gles2_iface(), 1); + } + } + else { + if (!hostCon->glEncoder()->isInitialized()) { + s_display.gles_iface()->init(); + hostCon->glEncoder()->setInitialized(); + ClientAPIExts::initClientFuncs(s_display.gles_iface(), 0); + } + } + } + + return EGL_TRUE; +} + +EGLContext eglGetCurrentContext() +{ + return getEGLThreadInfo()->currentContext; +} + +EGLSurface eglGetCurrentSurface(EGLint readdraw) +{ + EGLContext_t * context = getEGLThreadInfo()->currentContext; + if (!context) + return EGL_NO_SURFACE; //not an error + + switch (readdraw) { + case EGL_READ: + return context->read; + case EGL_DRAW: + return context->draw; + default: + setErrorReturn(EGL_BAD_PARAMETER, EGL_NO_SURFACE); + } +} + +EGLDisplay eglGetCurrentDisplay() +{ + EGLContext_t * context = getEGLThreadInfo()->currentContext; + if (!context) + return EGL_NO_DISPLAY; //not an error + + return context->dpy; +} + +EGLBoolean eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value) +{ + VALIDATE_DISPLAY_INIT(dpy, EGL_FALSE); + VALIDATE_CONTEXT_RETURN(ctx, EGL_FALSE); + + EGLContext_t * context = static_cast<EGLContext_t*>(ctx); + + EGLBoolean ret = EGL_TRUE; + switch (attribute) { + case EGL_CONFIG_ID: + ret = s_display.getConfigAttrib(context->config, EGL_CONFIG_ID, value); + break; + case EGL_CONTEXT_CLIENT_TYPE: + *value = EGL_OPENGL_ES_API; + break; + case EGL_CONTEXT_CLIENT_VERSION: + *value = context->version; + break; + case EGL_RENDER_BUFFER: + if (!context->draw) + *value = EGL_NONE; + else + *value = EGL_BACK_BUFFER; //single buffer not supported + break; + default: + ALOGE("eglQueryContext %x EGL_BAD_ATTRIBUTE", attribute); + setErrorReturn(EGL_BAD_ATTRIBUTE, EGL_FALSE); + break; + } + + return ret; +} + +EGLBoolean eglWaitGL() +{ + EGLThreadInfo *tInfo = getEGLThreadInfo(); + if (!tInfo || !tInfo->currentContext) { + return EGL_FALSE; + } + + if (tInfo->currentContext->version == 2) { + s_display.gles2_iface()->finish(); + } + else { + s_display.gles_iface()->finish(); + } + + return EGL_TRUE; +} + +EGLBoolean eglWaitNative(EGLint engine) +{ + return EGL_TRUE; +} + +EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface eglSurface) +{ + VALIDATE_DISPLAY_INIT(dpy, EGL_FALSE); + if (eglSurface == EGL_NO_SURFACE) + setErrorReturn(EGL_BAD_SURFACE, EGL_FALSE); + + DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE); + + egl_surface_t* d = static_cast<egl_surface_t*>(eglSurface); + if (d->dpy != dpy) + setErrorReturn(EGL_BAD_DISPLAY, EGL_FALSE); + + // post the surface + d->swapBuffers(); + + hostCon->flush(); + return EGL_TRUE; +} + +EGLBoolean eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target) +{ + //TODO :later + return 0; +} + +EGLBoolean eglLockSurfaceKHR(EGLDisplay display, EGLSurface surface, const EGLint *attrib_list) +{ + //TODO later + return 0; +} + +EGLBoolean eglUnlockSurfaceKHR(EGLDisplay display, EGLSurface surface) +{ + //TODO later + return 0; +} + +EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list) +{ + VALIDATE_DISPLAY_INIT(dpy, EGL_NO_IMAGE_KHR); + if (ctx != EGL_NO_CONTEXT) { + setErrorReturn(EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR); + } + if (target != EGL_NATIVE_BUFFER_ANDROID) { + setErrorReturn(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR); + } + + android_native_buffer_t* native_buffer = (android_native_buffer_t*)buffer; + + if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) + setErrorReturn(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR); + + if (native_buffer->common.version != sizeof(android_native_buffer_t)) + setErrorReturn(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR); + + switch (native_buffer->format) { + case HAL_PIXEL_FORMAT_RGBA_8888: + case HAL_PIXEL_FORMAT_RGBX_8888: + case HAL_PIXEL_FORMAT_RGB_888: + case HAL_PIXEL_FORMAT_RGB_565: + case HAL_PIXEL_FORMAT_BGRA_8888: + case HAL_PIXEL_FORMAT_RGBA_5551: + case HAL_PIXEL_FORMAT_RGBA_4444: + break; + default: + setErrorReturn(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR); + } + + native_buffer->common.incRef(&native_buffer->common); + return (EGLImageKHR)native_buffer; +} + +EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img) +{ + VALIDATE_DISPLAY_INIT(dpy, EGL_FALSE); + android_native_buffer_t* native_buffer = (android_native_buffer_t*)img; + + if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) + setErrorReturn(EGL_BAD_PARAMETER, EGL_FALSE); + + if (native_buffer->common.version != sizeof(android_native_buffer_t)) + setErrorReturn(EGL_BAD_PARAMETER, EGL_FALSE); + + native_buffer->common.decRef(&native_buffer->common); + + return EGL_TRUE; +} + +EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) +{ + //TODO later + return 0; +} + +EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) +{ + //TODO later + return 0; +} + +EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout) +{ + //TODO + return 0; +} + +EGLBoolean eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) +{ + //TODO later + return 0; +} + +EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value) +{ + //TODO later + return 0; +} diff --git a/emulator/opengl/system/egl/eglContext.h b/emulator/opengl/system/egl/eglContext.h new file mode 100644 index 0000000..2ca6d0c --- /dev/null +++ b/emulator/opengl/system/egl/eglContext.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 _EGL_CONTEXT_H +#define _EGL_CONTEXT_H + +#include "GLClientState.h" +#include "GLSharedGroup.h" + +struct EGLContext_t { + + enum { + IS_CURRENT = 0x00010000, + NEVER_CURRENT = 0x00020000 + }; + + EGLContext_t(EGLDisplay dpy, EGLConfig config, EGLContext_t* shareCtx); + ~EGLContext_t(); + uint32_t flags; + EGLDisplay dpy; + EGLConfig config; + EGLSurface read; + EGLSurface draw; + EGLContext_t * shareCtx; + EGLint version; + uint32_t rcContext; + const char* versionString; + const char* vendorString; + const char* rendererString; + const char* extensionString; + + GLClientState * getClientState(){ return clientState; } + GLSharedGroupPtr getSharedGroup(){ return sharedGroup; } +private: + GLClientState * clientState; + GLSharedGroupPtr sharedGroup; +}; + +#endif diff --git a/emulator/opengl/system/egl/eglDisplay.cpp b/emulator/opengl/system/egl/eglDisplay.cpp new file mode 100644 index 0000000..2497548 --- /dev/null +++ b/emulator/opengl/system/egl/eglDisplay.cpp @@ -0,0 +1,496 @@ +/* +* 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 "HostConnection.h" +#include <dlfcn.h> + +static const int systemEGLVersionMajor = 1; +static const int systemEGLVersionMinor = 4; +static const char systemEGLVendor[] = "Google Android emulator"; + +// list of extensions supported by this EGL implementation +// NOTE that each extension name should be suffixed with space +static const char systemStaticEGLExtensions[] = + "EGL_ANDROID_image_native_buffer "; + +// list of extensions supported by this EGL implementation only if supported +// on the host implementation. +// NOTE that each extension name should be suffixed with space +static const char systemDynamicEGLExtensions[] = + "EGL_KHR_image_base " + "EGL_KHR_gl_texture_2d_image "; + + +static void *s_gles_lib = NULL; +static void *s_gles2_lib = NULL; + +// The following function will be called when we (libEGL) +// gets unloaded +// At this point we want to unload the gles libraries we +// might have loaded during initialization +static void __attribute__ ((destructor)) do_on_unload(void) +{ + if (s_gles_lib) { + dlclose(s_gles_lib); + } + + if (s_gles2_lib) { + dlclose(s_gles2_lib); + } +} + +eglDisplay::eglDisplay() : + m_initialized(false), + m_major(0), + m_minor(0), + m_hostRendererVersion(0), + m_numConfigs(0), + m_numConfigAttribs(0), + m_attribs(DefaultKeyedVector<EGLint, EGLint>(ATTRIBUTE_NONE)), + m_configs(NULL), + m_gles_iface(NULL), + m_gles2_iface(NULL), + m_versionString(NULL), + m_vendorString(NULL), + m_extensionString(NULL) +{ + pthread_mutex_init(&m_lock, NULL); +} + +eglDisplay::~eglDisplay() +{ + pthread_mutex_destroy(&m_lock); +} + +bool eglDisplay::initialize(EGLClient_eglInterface *eglIface) +{ + pthread_mutex_lock(&m_lock); + if (!m_initialized) { + + // + // load GLES client API + // + m_gles_iface = loadGLESClientAPI("/system/lib/egl/libGLESv1_CM_emulation.so", + eglIface, + &s_gles_lib); + if (!m_gles_iface) { + pthread_mutex_unlock(&m_lock); + ALOGE("Failed to load gles1 iface"); + return false; + } + +#ifdef WITH_GLES2 + m_gles2_iface = loadGLESClientAPI("/system/lib/egl/libGLESv2_emulation.so", + eglIface, + &s_gles2_lib); + // Note that if loading gles2 failed, we can still run with no + // GLES2 support, having GLES2 is not mandatory. +#endif + + // + // establish connection with the host + // + HostConnection *hcon = HostConnection::get(); + if (!hcon) { + pthread_mutex_unlock(&m_lock); + ALOGE("Failed to establish connection with the host\n"); + return false; + } + + // + // get renderControl encoder instance + // + renderControl_encoder_context_t *rcEnc = hcon->rcEncoder(); + if (!rcEnc) { + pthread_mutex_unlock(&m_lock); + ALOGE("Failed to get renderControl encoder instance"); + return false; + } + + // + // Query host reneder and EGL version + // + m_hostRendererVersion = rcEnc->rcGetRendererVersion(rcEnc); + EGLint status = rcEnc->rcGetEGLVersion(rcEnc, &m_major, &m_minor); + if (status != EGL_TRUE) { + // host EGL initialization failed !! + pthread_mutex_unlock(&m_lock); + return false; + } + + // + // Take minimum version beween what we support and what the host support + // + if (m_major > systemEGLVersionMajor) { + m_major = systemEGLVersionMajor; + m_minor = systemEGLVersionMinor; + } + else if (m_major == systemEGLVersionMajor && + m_minor > systemEGLVersionMinor) { + m_minor = systemEGLVersionMinor; + } + + // + // Query the host for the set of configs + // + m_numConfigs = rcEnc->rcGetNumConfigs(rcEnc, (uint32_t*)&m_numConfigAttribs); + if (m_numConfigs <= 0 || m_numConfigAttribs <= 0) { + // just sanity check - should never happen + pthread_mutex_unlock(&m_lock); + return false; + } + + uint32_t nInts = m_numConfigAttribs * (m_numConfigs + 1); + EGLint tmp_buf[nInts]; + m_configs = new EGLint[nInts-m_numConfigAttribs]; + if (!m_configs) { + pthread_mutex_unlock(&m_lock); + return false; + } + + //EGLint n = rcEnc->rcGetConfigs(rcEnc, nInts*sizeof(EGLint), m_configs); + EGLint n = rcEnc->rcGetConfigs(rcEnc, nInts*sizeof(EGLint), (GLuint*)tmp_buf); + if (n != m_numConfigs) { + pthread_mutex_unlock(&m_lock); + return false; + } + + //Fill the attributes vector. + //The first m_numConfigAttribs values of tmp_buf are the actual attributes enums. + for (int i=0; i<m_numConfigAttribs; i++) { + m_attribs.add(tmp_buf[i], i); + } + + //Copy the actual configs data to m_configs + memcpy(m_configs, tmp_buf + m_numConfigAttribs, m_numConfigs*m_numConfigAttribs*sizeof(EGLint)); + + m_initialized = true; + } + pthread_mutex_unlock(&m_lock); + + processConfigs(); + + return true; +} + +void eglDisplay::processConfigs() +{ + for (int i=0; i<m_numConfigs; i++) { + EGLConfig config = (EGLConfig)i; + //Setup the EGL_NATIVE_VISUAL_ID attribute + PixelFormat format; + if (getConfigNativePixelFormat(config, &format)) { + setConfigAttrib(config, EGL_NATIVE_VISUAL_ID, format); + } + } +} + +void eglDisplay::terminate() +{ + pthread_mutex_lock(&m_lock); + if (m_initialized) { + m_initialized = false; + delete [] m_configs; + m_configs = NULL; + + if (m_versionString) { + free(m_versionString); + m_versionString = NULL; + } + if (m_vendorString) { + free(m_vendorString); + m_vendorString = NULL; + } + if (m_extensionString) { + free(m_extensionString); + m_extensionString = NULL; + } + } + pthread_mutex_unlock(&m_lock); +} + +EGLClient_glesInterface *eglDisplay::loadGLESClientAPI(const char *libName, + EGLClient_eglInterface *eglIface, + void **libHandle) +{ + void *lib = dlopen(libName, RTLD_NOW); + if (!lib) { + ALOGE("Failed to dlopen %s", libName); + return NULL; + } + + init_emul_gles_t init_gles_func = (init_emul_gles_t)dlsym(lib,"init_emul_gles"); + if (!init_gles_func) { + ALOGE("Failed to find init_emul_gles"); + dlclose((void*)lib); + return NULL; + } + + *libHandle = lib; + return (*init_gles_func)(eglIface); +} + +static char *queryHostEGLString(EGLint name) +{ + HostConnection *hcon = HostConnection::get(); + if (hcon) { + renderControl_encoder_context_t *rcEnc = hcon->rcEncoder(); + if (rcEnc) { + int n = rcEnc->rcQueryEGLString(rcEnc, name, NULL, 0); + if (n < 0) { + // allocate space for the string with additional + // space charachter to be suffixed at the end. + char *str = (char *)malloc(-n+2); + n = rcEnc->rcQueryEGLString(rcEnc, name, str, -n); + if (n > 0) { + // add extra space at end of string which will be + // needed later when filtering the extension list. + strcat(str, " "); + return str; + } + + free(str); + } + } + } + + return NULL; +} + +static bool findExtInList(const char* token, int tokenlen, const char* list) +{ + const char* p = list; + while (*p != '\0') { + const char* q = strchr(p, ' '); + if (q == NULL) { + /* should not happen, list must be space-terminated */ + break; + } + if (tokenlen == (q - p) && !memcmp(token, p, tokenlen)) { + return true; /* found it */ + } + p = q+1; + } + return false; /* not found */ +} + +static char *buildExtensionString() +{ + //Query host extension string + char *hostExt = queryHostEGLString(EGL_EXTENSIONS); + if (!hostExt || (hostExt[1] == '\0')) { + // no extensions on host - only static extension list supported + return strdup(systemStaticEGLExtensions); + } + + // + // Filter host extension list to include only extensions + // we can support (in the systemDynamicEGLExtensions list) + // + char *ext = (char *)hostExt; + char *c = ext; + char *insert = ext; + while(*c != '\0') { + if (*c == ' ') { + int len = c - ext; + if (findExtInList(ext, len, systemDynamicEGLExtensions)) { + if (ext != insert) { + memcpy(insert, ext, len+1); // including space + } + insert += (len + 1); + } + ext = c + 1; + } + c++; + } + *insert = '\0'; + + int n = strlen(hostExt); + if (n > 0) { + char *str; + asprintf(&str,"%s%s", systemStaticEGLExtensions, hostExt); + free((char*)hostExt); + return str; + } + else { + free((char*)hostExt); + return strdup(systemStaticEGLExtensions); + } +} + +const char *eglDisplay::queryString(EGLint name) +{ + if (name == EGL_CLIENT_APIS) { + return "OpenGL_ES"; + } + else if (name == EGL_VERSION) { + pthread_mutex_lock(&m_lock); + if (m_versionString) { + pthread_mutex_unlock(&m_lock); + return m_versionString; + } + + // build version string + asprintf(&m_versionString, "%d.%d", m_major, m_minor); + pthread_mutex_unlock(&m_lock); + + return m_versionString; + } + else if (name == EGL_VENDOR) { + pthread_mutex_lock(&m_lock); + if (m_vendorString) { + pthread_mutex_unlock(&m_lock); + return m_vendorString; + } + + // build vendor string + const char *hostVendor = queryHostEGLString(EGL_VENDOR); + + if (hostVendor) { + asprintf(&m_vendorString, "%s Host: %s", + systemEGLVendor, hostVendor); + free((char*)hostVendor); + } + else { + m_vendorString = (char *)systemEGLVendor; + } + pthread_mutex_unlock(&m_lock); + + return m_vendorString; + } + else if (name == EGL_EXTENSIONS) { + pthread_mutex_lock(&m_lock); + if (m_extensionString) { + pthread_mutex_unlock(&m_lock); + return m_extensionString; + } + + // build extension string + m_extensionString = buildExtensionString(); + pthread_mutex_unlock(&m_lock); + + return m_extensionString; + } + else { + ALOGE("[%s] Unknown name %d\n", __FUNCTION__, name); + return NULL; + } +} + +/* To get the value of attribute <a> of config <c> use the following formula: + * value = *(m_configs + (int)c*m_numConfigAttribs + a); + */ +EGLBoolean eglDisplay::getAttribValue(EGLConfig config, EGLint attribIdx, EGLint * value) +{ + if (attribIdx == ATTRIBUTE_NONE) + { + ALOGE("[%s] Bad attribute idx\n", __FUNCTION__); + return EGL_FALSE; + } + *value = *(m_configs + (int)config*m_numConfigAttribs + attribIdx); + return EGL_TRUE; +} + +EGLBoolean eglDisplay::getConfigAttrib(EGLConfig config, EGLint attrib, EGLint * value) +{ + //Though it seems that valueFor() is thread-safe, we don't take chanses + pthread_mutex_lock(&m_lock); + EGLBoolean ret = getAttribValue(config, m_attribs.valueFor(attrib), value); + pthread_mutex_unlock(&m_lock); + return ret; +} + +void eglDisplay::dumpConfig(EGLConfig config) +{ + EGLint value = 0; + DBG("^^^^^^^^^^ dumpConfig %d ^^^^^^^^^^^^^^^^^^", (int)config); + for (int i=0; i<m_numConfigAttribs; i++) { + getAttribValue(config, i, &value); + DBG("{%d}[%d] %d\n", (int)config, i, value); + } +} + +/* To set the value of attribute <a> of config <c> use the following formula: + * *(m_configs + (int)c*m_numConfigAttribs + a) = value; + */ +EGLBoolean eglDisplay::setAttribValue(EGLConfig config, EGLint attribIdx, EGLint value) +{ + if (attribIdx == ATTRIBUTE_NONE) + { + ALOGE("[%s] Bad attribute idx\n", __FUNCTION__); + return EGL_FALSE; + } + *(m_configs + (int)config*m_numConfigAttribs + attribIdx) = value; + return EGL_TRUE; +} + +EGLBoolean eglDisplay::setConfigAttrib(EGLConfig config, EGLint attrib, EGLint value) +{ + //Though it seems that valueFor() is thread-safe, we don't take chanses + pthread_mutex_lock(&m_lock); + EGLBoolean ret = setAttribValue(config, m_attribs.valueFor(attrib), value); + pthread_mutex_unlock(&m_lock); + return ret; +} + + +EGLBoolean eglDisplay::getConfigNativePixelFormat(EGLConfig config, PixelFormat * format) +{ + EGLint redSize, blueSize, greenSize, alphaSize; + + if ( !(getAttribValue(config, m_attribs.valueFor(EGL_RED_SIZE), &redSize) && + getAttribValue(config, m_attribs.valueFor(EGL_BLUE_SIZE), &blueSize) && + getAttribValue(config, m_attribs.valueFor(EGL_GREEN_SIZE), &greenSize) && + getAttribValue(config, m_attribs.valueFor(EGL_ALPHA_SIZE), &alphaSize)) ) + { + ALOGE("Couldn't find value for one of the pixel format attributes"); + return EGL_FALSE; + } + + //calculate the GL internal format + if ((redSize==8)&&(greenSize==8)&&(blueSize==8)&&(alphaSize==8)) *format = PIXEL_FORMAT_RGBA_8888; //XXX: BGR? + else if ((redSize==8)&&(greenSize==8)&&(blueSize==8)&&(alphaSize==0)) *format = PIXEL_FORMAT_RGBX_8888; //XXX or PIXEL_FORMAT_RGB_888 + else if ((redSize==5)&&(greenSize==6)&&(blueSize==5)&&(alphaSize==0)) *format = PIXEL_FORMAT_RGB_565; + else if ((redSize==5)&&(greenSize==5)&&(blueSize==5)&&(alphaSize==1)) *format = PIXEL_FORMAT_RGBA_5551; + else if ((redSize==4)&&(greenSize==4)&&(blueSize==4)&&(alphaSize==4)) *format = PIXEL_FORMAT_RGBA_4444; + else { + return EGL_FALSE; + } + return EGL_TRUE; +} +EGLBoolean eglDisplay::getConfigGLPixelFormat(EGLConfig config, GLenum * format) +{ + EGLint redSize, blueSize, greenSize, alphaSize; + + if ( !(getAttribValue(config, m_attribs.valueFor(EGL_RED_SIZE), &redSize) && + getAttribValue(config, m_attribs.valueFor(EGL_BLUE_SIZE), &blueSize) && + getAttribValue(config, m_attribs.valueFor(EGL_GREEN_SIZE), &greenSize) && + getAttribValue(config, m_attribs.valueFor(EGL_ALPHA_SIZE), &alphaSize)) ) + { + ALOGE("Couldn't find value for one of the pixel format attributes"); + return EGL_FALSE; + } + + //calculate the GL internal format + if ((redSize==8)&&(blueSize==8)&&(blueSize==8)&&(alphaSize==8)) *format = GL_RGBA; + else if ((redSize==8)&&(greenSize==8)&&(blueSize==8)&&(alphaSize==0)) *format = GL_RGB; + else if ((redSize==5)&&(greenSize==6)&&(blueSize==5)&&(alphaSize==0)) *format = GL_RGB565_OES; + else if ((redSize==5)&&(greenSize==5)&&(blueSize==5)&&(alphaSize==1)) *format = GL_RGB5_A1_OES; + else if ((redSize==4)&&(greenSize==4)&&(blueSize==4)&&(alphaSize==4)) *format = GL_RGBA4_OES; + else return EGL_FALSE; + + return EGL_TRUE; +} diff --git a/emulator/opengl/system/egl/eglDisplay.h b/emulator/opengl/system/egl/eglDisplay.h new file mode 100644 index 0000000..9d979d9 --- /dev/null +++ b/emulator/opengl/system/egl/eglDisplay.h @@ -0,0 +1,89 @@ +/* +* 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 _SYSTEM_EGL_DISPLAY_H +#define _SYSTEM_EGL_DISPLAY_H + +#include <pthread.h> +#include "glUtils.h" +#include <EGL/egl.h> +#include <EGL/eglext.h> +#include "EGLClientIface.h" +#include <utils/KeyedVector.h> + +#include <ui/PixelFormat.h> + +#define ATTRIBUTE_NONE -1 +//FIXME: are we in this namespace? +using namespace android; + +class eglDisplay +{ +public: + eglDisplay(); + ~eglDisplay(); + + bool initialize(EGLClient_eglInterface *eglIface); + void terminate(); + + int getVersionMajor() const { return m_major; } + int getVersionMinor() const { return m_minor; } + bool initialized() const { return m_initialized; } + + const char *queryString(EGLint name); + + const EGLClient_glesInterface *gles_iface() const { return m_gles_iface; } + const EGLClient_glesInterface *gles2_iface() const { return m_gles2_iface; } + + int getNumConfigs(){ return m_numConfigs; } + EGLBoolean getConfigAttrib(EGLConfig config, EGLint attrib, EGLint * value); + EGLBoolean setConfigAttrib(EGLConfig config, EGLint attrib, EGLint value); + EGLBoolean getConfigGLPixelFormat(EGLConfig config, GLenum * format); + EGLBoolean getConfigNativePixelFormat(EGLConfig config, PixelFormat * format); + + void dumpConfig(EGLConfig config); +private: + EGLClient_glesInterface *loadGLESClientAPI(const char *libName, + EGLClient_eglInterface *eglIface, + void **libHandle); + EGLBoolean getAttribValue(EGLConfig config, EGLint attribIdxi, EGLint * value); + EGLBoolean setAttribValue(EGLConfig config, EGLint attribIdxi, EGLint value); + void processConfigs(); + +private: + pthread_mutex_t m_lock; + bool m_initialized; + int m_major; + int m_minor; + int m_hostRendererVersion; + int m_numConfigs; + int m_numConfigAttribs; + + /* This is the mapping between an attribute name to it's index in any given config */ + DefaultKeyedVector<EGLint, EGLint> m_attribs; + /* This is an array of all config's attributes values stored in the following sequencial fasion (read: v[c,a] = the value of attribute <a> of config <c>) + * v[0,0],..,v[0,m_numConfigAttribs-1], + *... + * v[m_numConfigs-1,0],..,v[m_numConfigs-1,m_numConfigAttribs-1] + */ + EGLint *m_configs; + EGLClient_glesInterface *m_gles_iface; + EGLClient_glesInterface *m_gles2_iface; + char *m_versionString; + char *m_vendorString; + char *m_extensionString; +}; + +#endif diff --git a/emulator/opengl/system/egl/egl_ftable.h b/emulator/opengl/system/egl/egl_ftable.h new file mode 100644 index 0000000..b21da72 --- /dev/null +++ b/emulator/opengl/system/egl/egl_ftable.h @@ -0,0 +1,65 @@ +/* +* 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. +*/ +static const struct _egl_funcs_by_name { + const char *name; + void *proc; +} egl_funcs_by_name[] = { + {"eglGetError", (void *)eglGetError}, + {"eglGetDisplay", (void *)eglGetDisplay}, + {"eglInitialize", (void *)eglInitialize}, + {"eglTerminate", (void *)eglTerminate}, + {"eglQueryString", (void *)eglQueryString}, + {"eglGetConfigs", (void *)eglGetConfigs}, + {"eglChooseConfig", (void *)eglChooseConfig}, + {"eglGetConfigAttrib", (void *)eglGetConfigAttrib}, + {"eglCreateWindowSurface", (void *)eglCreateWindowSurface}, + {"eglCreatePbufferSurface", (void *)eglCreatePbufferSurface}, + {"eglCreatePixmapSurface", (void *)eglCreatePixmapSurface}, + {"eglDestroySurface", (void *)eglDestroySurface}, + {"eglQuerySurface", (void *)eglQuerySurface}, + {"eglBindAPI", (void *)eglBindAPI}, + {"eglQueryAPI", (void *)eglQueryAPI}, + {"eglWaitClient", (void *)eglWaitClient}, + {"eglReleaseThread", (void *)eglReleaseThread}, + {"eglCreatePbufferFromClientBuffer", (void *)eglCreatePbufferFromClientBuffer}, + {"eglSurfaceAttrib", (void *)eglSurfaceAttrib}, + {"eglBindTexImage", (void *)eglBindTexImage}, + {"eglReleaseTexImage", (void *)eglReleaseTexImage}, + {"eglSwapInterval", (void *)eglSwapInterval}, + {"eglCreateContext", (void *)eglCreateContext}, + {"eglDestroyContext", (void *)eglDestroyContext}, + {"eglMakeCurrent", (void *)eglMakeCurrent}, + {"eglGetCurrentContext", (void *)eglGetCurrentContext}, + {"eglGetCurrentSurface", (void *)eglGetCurrentSurface}, + {"eglGetCurrentDisplay", (void *)eglGetCurrentDisplay}, + {"eglQueryContext", (void *)eglQueryContext}, + {"eglWaitGL", (void *)eglWaitGL}, + {"eglWaitNative", (void *)eglWaitNative}, + {"eglSwapBuffers", (void *)eglSwapBuffers}, + {"eglCopyBuffers", (void *)eglCopyBuffers}, + {"eglGetProcAddress", (void *)eglGetProcAddress}, + {"eglLockSurfaceKHR", (void *)eglLockSurfaceKHR}, + {"eglUnlockSurfaceKHR", (void *)eglUnlockSurfaceKHR}, + {"eglCreateImageKHR", (void *)eglCreateImageKHR}, + {"eglDestroyImageKHR", (void *)eglDestroyImageKHR}, + {"eglCreateSyncKHR", (void *)eglCreateSyncKHR}, + {"eglDestroySyncKHR", (void *)eglDestroySyncKHR}, + {"eglClientWaitSyncKHR", (void *)eglClientWaitSyncKHR}, + {"eglSignalSyncKHR", (void *)eglSignalSyncKHR}, + {"eglGetSyncAttribKHR", (void *)eglGetSyncAttribKHR} +}; + +static const int egl_num_funcs = sizeof(egl_funcs_by_name) / sizeof(struct _egl_funcs_by_name); diff --git a/emulator/opengl/system/gralloc/Android.mk b/emulator/opengl/system/gralloc/Android.mk new file mode 100644 index 0000000..8705602 --- /dev/null +++ b/emulator/opengl/system/gralloc/Android.mk @@ -0,0 +1,19 @@ +ifneq (false,$(BUILD_EMULATOR_OPENGL_DRIVER)) + +LOCAL_PATH := $(call my-dir) + +$(call emugl-begin-shared-library,gralloc.goldfish) +$(call emugl-import,libGLESv1_enc lib_renderControl_enc libOpenglSystemCommon) +$(call emugl-set-shared-library-subpath,hw) + +LOCAL_CFLAGS += -DLOG_TAG=\"gralloc_goldfish\" + +LOCAL_SRC_FILES := gralloc.cpp + +# Need to access the special OPENGL TLS Slot +LOCAL_C_INCLUDES += bionic/libc/private +LOCAL_SHARED_LIBRARIES += libdl + +$(call emugl-end-module) + +endif # BUILD_EMULATOR_OPENGL_DRIVER != false diff --git a/emulator/opengl/system/gralloc/gralloc.cpp b/emulator/opengl/system/gralloc/gralloc.cpp new file mode 100644 index 0000000..baad99b --- /dev/null +++ b/emulator/opengl/system/gralloc/gralloc.cpp @@ -0,0 +1,831 @@ +/* +* 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 <string.h> +#include <pthread.h> +#ifdef HAVE_ANDROID_OS // just want PAGE_SIZE define +# include <asm/page.h> +#else +# include <sys/user.h> +#endif +#include <cutils/ashmem.h> +#include <unistd.h> +#include <errno.h> +#include <dlfcn.h> +#include <sys/mman.h> +#include "gralloc_cb.h" +#include "HostConnection.h" +#include "glUtils.h" +#include <cutils/log.h> +#include <cutils/properties.h> + +/* Set to 1 or 2 to enable debug traces */ +#define DEBUG 0 + +#if DEBUG >= 1 +# define D(...) ALOGD(__VA_ARGS__) +#else +# define D(...) ((void)0) +#endif + +#if DEBUG >= 2 +# define DD(...) ALOGD(__VA_ARGS__) +#else +# define DD(...) ((void)0) +#endif + +#define DBG_FUNC DBG("%s\n", __FUNCTION__) +// +// our private gralloc module structure +// +struct private_module_t { + gralloc_module_t base; +}; + +/* If not NULL, this is a pointer to the fallback module. + * This really is gralloc.default, which we'll use if we detect + * that the emulator we're running in does not support GPU emulation. + */ +static gralloc_module_t* sFallback; +static pthread_once_t sFallbackOnce = PTHREAD_ONCE_INIT; + +static void fallback_init(void); // forward + + +typedef struct _alloc_list_node { + buffer_handle_t handle; + _alloc_list_node *next; + _alloc_list_node *prev; +} AllocListNode; + +// +// Our gralloc device structure (alloc interface) +// +struct gralloc_device_t { + alloc_device_t device; + + AllocListNode *allocListHead; // double linked list of allocated buffers + pthread_mutex_t lock; +}; + +// +// Our framebuffer device structure +// +struct fb_device_t { + framebuffer_device_t device; +}; + +static int map_buffer(cb_handle_t *cb, void **vaddr) +{ + if (cb->fd < 0 || cb->ashmemSize <= 0) { + return -EINVAL; + } + + void *addr = mmap(0, cb->ashmemSize, PROT_READ | PROT_WRITE, + MAP_SHARED, cb->fd, 0); + if (addr == MAP_FAILED) { + return -errno; + } + + cb->ashmemBase = intptr_t(addr); + cb->ashmemBasePid = getpid(); + + *vaddr = addr; + return 0; +} + +#define DEFINE_HOST_CONNECTION \ + HostConnection *hostCon = HostConnection::get(); \ + renderControl_encoder_context_t *rcEnc = (hostCon ? hostCon->rcEncoder() : NULL) + +#define DEFINE_AND_VALIDATE_HOST_CONNECTION \ + HostConnection *hostCon = HostConnection::get(); \ + if (!hostCon) { \ + ALOGE("gralloc: Failed to get host connection\n"); \ + return -EIO; \ + } \ + renderControl_encoder_context_t *rcEnc = hostCon->rcEncoder(); \ + if (!rcEnc) { \ + ALOGE("gralloc: Failed to get renderControl encoder context\n"); \ + return -EIO; \ + } + + +// +// gralloc device functions (alloc interface) +// +static int gralloc_alloc(alloc_device_t* dev, + int w, int h, int format, int usage, + buffer_handle_t* pHandle, int* pStride) +{ + D("gralloc_alloc w=%d h=%d usage=0x%x\n", w, h, usage); + + gralloc_device_t *grdev = (gralloc_device_t *)dev; + if (!grdev || !pHandle || !pStride) + return -EINVAL; + + // + // Validate usage: buffer cannot be written both by s/w and h/w access. + // + bool sw_write = (0 != (usage & GRALLOC_USAGE_SW_WRITE_MASK)); + bool hw_write = (usage & GRALLOC_USAGE_HW_RENDER); + if (hw_write && sw_write) { + return -EINVAL; + } + + int ashmem_size = 0; + *pStride = 0; + GLenum glFormat = 0; + GLenum glType = 0; + + int bpp = 0; + switch (format) { + case HAL_PIXEL_FORMAT_RGBA_8888: + case HAL_PIXEL_FORMAT_RGBX_8888: + case HAL_PIXEL_FORMAT_BGRA_8888: + bpp = 4; + glFormat = GL_RGBA; + glType = GL_UNSIGNED_BYTE; + break; + case HAL_PIXEL_FORMAT_RGB_888: + bpp = 3; + glFormat = GL_RGB; + glType = GL_UNSIGNED_BYTE; + break; + case HAL_PIXEL_FORMAT_RGB_565: + bpp = 2; + glFormat = GL_RGB; + glType = GL_UNSIGNED_SHORT_5_6_5; + break; + case HAL_PIXEL_FORMAT_RGBA_5551: + bpp = 2; + glFormat = GL_RGB5_A1_OES; + glType = GL_UNSIGNED_SHORT_5_5_5_1; + break; + case HAL_PIXEL_FORMAT_RGBA_4444: + bpp = 2; + glFormat = GL_RGBA4_OES; + glType = GL_UNSIGNED_SHORT_4_4_4_4; + break; + + default: + return -EINVAL; + } + + if (usage & GRALLOC_USAGE_HW_FB) { + // keep space for postCounter + ashmem_size += sizeof(uint32_t); + } + + if (usage & (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK)) { + // keep space for image on guest memory if SW access is needed + int align = 1; + size_t bpr = (w*bpp + (align-1)) & ~(align-1); + ashmem_size += (bpr * h); + *pStride = bpr / bpp; + } + + D("gralloc_alloc ashmem_size=%d, tid %d\n", ashmem_size, gettid()); + + // + // Allocate space in ashmem if needed + // + int fd = -1; + if (ashmem_size > 0) { + // round to page size; + ashmem_size = (ashmem_size + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1); + + fd = ashmem_create_region("gralloc-buffer", ashmem_size); + if (fd < 0) { + ALOGE("gralloc_alloc failed to create ashmem region: %s\n", strerror(errno)); + return -errno; + } + } + + cb_handle_t *cb = new cb_handle_t(fd, ashmem_size, usage, + w, h, glFormat, glType); + + if (ashmem_size > 0) { + // + // map ashmem region if exist + // + void *vaddr; + int err = map_buffer(cb, &vaddr); + if (err) { + close(fd); + delete cb; + return err; + } + + cb->setFd(fd); + } + + // + // Allocate ColorBuffer handle on the host (only if h/w access is allowed) + // + if (usage & GRALLOC_USAGE_HW_MASK) { + DEFINE_HOST_CONNECTION; + if (hostCon && rcEnc) { + cb->hostHandle = rcEnc->rcCreateColorBuffer(rcEnc, w, h, glFormat); + D("Created host ColorBuffer 0x%x\n", cb->hostHandle); + } + + if (!cb->hostHandle) { + // Could not create colorbuffer on host !!! + close(fd); + delete cb; + return -EIO; + } + } + + // + // alloc succeeded - insert the allocated handle to the allocated list + // + AllocListNode *node = new AllocListNode(); + pthread_mutex_lock(&grdev->lock); + node->handle = cb; + node->next = grdev->allocListHead; + node->prev = NULL; + if (grdev->allocListHead) { + grdev->allocListHead->prev = node; + } + grdev->allocListHead = node; + pthread_mutex_unlock(&grdev->lock); + + *pHandle = cb; + return 0; +} + +static int gralloc_free(alloc_device_t* dev, + buffer_handle_t handle) +{ + const cb_handle_t *cb = (const cb_handle_t *)handle; + if (!cb_handle_t::validate((cb_handle_t*)cb)) { + ERR("gralloc_free: invalid handle"); + return -EINVAL; + } + + if (cb->hostHandle != 0) { + DEFINE_AND_VALIDATE_HOST_CONNECTION; + D("Closing host ColorBuffer 0x%x\n", cb->hostHandle); + rcEnc->rcCloseColorBuffer(rcEnc, cb->hostHandle); + } + + // + // detach and unmap ashmem area if present + // + if (cb->fd > 0) { + if (cb->ashmemSize > 0 && cb->ashmemBase) { + munmap((void *)cb->ashmemBase, cb->ashmemSize); + } + close(cb->fd); + } + + // remove it from the allocated list + gralloc_device_t *grdev = (gralloc_device_t *)dev; + pthread_mutex_lock(&grdev->lock); + AllocListNode *n = grdev->allocListHead; + while( n && n->handle != cb ) { + n = n->next; + } + if (n) { + // buffer found on list - remove it from list + if (n->next) { + n->next->prev = n->prev; + } + if (n->prev) { + n->prev->next = n->next; + } + else { + grdev->allocListHead = n->next; + } + + delete n; + } + pthread_mutex_unlock(&grdev->lock); + + delete cb; + + return 0; +} + +static int gralloc_device_close(struct hw_device_t *dev) +{ + gralloc_device_t* d = reinterpret_cast<gralloc_device_t*>(dev); + if (d) { + + // free still allocated buffers + while( d->allocListHead != NULL ) { + gralloc_free(&d->device, d->allocListHead->handle); + } + + // free device + free(d); + } + return 0; +} + +static int fb_compositionComplete(struct framebuffer_device_t* dev) +{ + return 0; +} + +// +// Framebuffer device functions +// +static int fb_post(struct framebuffer_device_t* dev, buffer_handle_t buffer) +{ + fb_device_t *fbdev = (fb_device_t *)dev; + cb_handle_t *cb = (cb_handle_t *)buffer; + + if (!fbdev || !cb_handle_t::validate(cb) || !cb->canBePosted()) { + return -EINVAL; + } + + // Make sure we have host connection + DEFINE_AND_VALIDATE_HOST_CONNECTION; + + // increment the post count of the buffer + uint32_t *postCountPtr = (uint32_t *)cb->ashmemBase; + if (!postCountPtr) { + // This should not happen + return -EINVAL; + } + (*postCountPtr)++; + + // send post request to host + rcEnc->rcFBPost(rcEnc, cb->hostHandle); + hostCon->flush(); + + return 0; +} + +static int fb_setUpdateRect(struct framebuffer_device_t* dev, + int l, int t, int w, int h) +{ + fb_device_t *fbdev = (fb_device_t *)dev; + + if (!fbdev) { + return -EINVAL; + } + + // Make sure we have host connection + DEFINE_AND_VALIDATE_HOST_CONNECTION; + + // send request to host + // TODO: XXX - should be implemented + //rcEnc->rc_XXX + + return 0; +} + +static int fb_setSwapInterval(struct framebuffer_device_t* dev, + int interval) +{ + fb_device_t *fbdev = (fb_device_t *)dev; + + if (!fbdev) { + return -EINVAL; + } + + // Make sure we have host connection + DEFINE_AND_VALIDATE_HOST_CONNECTION; + + // send request to host + rcEnc->rcFBSetSwapInterval(rcEnc, interval); + hostCon->flush(); + + return 0; +} + +static int fb_close(struct hw_device_t *dev) +{ + fb_device_t *fbdev = (fb_device_t *)dev; + + delete fbdev; + + return 0; +} + + +// +// gralloc module functions - refcount + locking interface +// +static int gralloc_register_buffer(gralloc_module_t const* module, + buffer_handle_t handle) +{ + pthread_once(&sFallbackOnce, fallback_init); + if (sFallback != NULL) { + return sFallback->registerBuffer(sFallback, handle); + } + + D("gralloc_register_buffer(%p) called", handle); + + private_module_t *gr = (private_module_t *)module; + cb_handle_t *cb = (cb_handle_t *)handle; + if (!gr || !cb_handle_t::validate(cb)) { + ERR("gralloc_register_buffer(%p): invalid buffer", cb); + return -EINVAL; + } + + if (cb->hostHandle != 0) { + DEFINE_AND_VALIDATE_HOST_CONNECTION; + D("Opening host ColorBuffer 0x%x\n", cb->hostHandle); + rcEnc->rcOpenColorBuffer(rcEnc, cb->hostHandle); + } + + // + // if the color buffer has ashmem region and it is not mapped in this + // process map it now. + // + if (cb->ashmemSize > 0 && cb->mappedPid != getpid()) { + void *vaddr; + int err = map_buffer(cb, &vaddr); + if (err) { + ERR("gralloc_register_buffer(%p): map failed: %s", cb, strerror(-err)); + return -err; + } + cb->mappedPid = getpid(); + } + + return 0; +} + +static int gralloc_unregister_buffer(gralloc_module_t const* module, + buffer_handle_t handle) +{ + if (sFallback != NULL) { + return sFallback->unregisterBuffer(sFallback, handle); + } + + private_module_t *gr = (private_module_t *)module; + cb_handle_t *cb = (cb_handle_t *)handle; + if (!gr || !cb_handle_t::validate(cb)) { + ERR("gralloc_unregister_buffer(%p): invalid buffer", cb); + return -EINVAL; + } + + if (cb->hostHandle != 0) { + DEFINE_AND_VALIDATE_HOST_CONNECTION; + D("Closing host ColorBuffer 0x%x\n", cb->hostHandle); + rcEnc->rcCloseColorBuffer(rcEnc, cb->hostHandle); + } + + // + // unmap ashmem region if it was previously mapped in this process + // (through register_buffer) + // + if (cb->ashmemSize > 0 && cb->mappedPid == getpid()) { + void *vaddr; + int err = munmap((void *)cb->ashmemBase, cb->ashmemSize); + if (err) { + ERR("gralloc_unregister_buffer(%p): unmap failed", cb); + return -EINVAL; + } + cb->ashmemBase = NULL; + cb->mappedPid = 0; + } + + D("gralloc_unregister_buffer(%p) done\n", cb); + + return 0; +} + +static int gralloc_lock(gralloc_module_t const* module, + buffer_handle_t handle, int usage, + int l, int t, int w, int h, + void** vaddr) +{ + if (sFallback != NULL) { + return sFallback->lock(sFallback, handle, usage, l, t, w, h, vaddr); + } + + private_module_t *gr = (private_module_t *)module; + cb_handle_t *cb = (cb_handle_t *)handle; + if (!gr || !cb_handle_t::validate(cb)) { + ALOGE("gralloc_lock bad handle\n"); + return -EINVAL; + } + + // Validate usage, + // 1. cannot be locked for hw access + // 2. lock for either sw read or write. + // 3. locked sw access must match usage during alloc time. + bool sw_read = (0 != (usage & GRALLOC_USAGE_SW_READ_MASK)); + bool sw_write = (0 != (usage & GRALLOC_USAGE_SW_WRITE_MASK)); + bool hw_read = (usage & GRALLOC_USAGE_HW_TEXTURE); + bool hw_write = (usage & GRALLOC_USAGE_HW_RENDER); + bool sw_read_allowed = (0 != (cb->usage & GRALLOC_USAGE_SW_READ_MASK)); + bool sw_write_allowed = (0 != (cb->usage & GRALLOC_USAGE_SW_WRITE_MASK)); + + if ( (hw_read || hw_write) || + (!sw_read && !sw_write) || + (sw_read && !sw_read_allowed) || + (sw_write && !sw_write_allowed) ) { + ALOGE("gralloc_lock usage mismatch usage=0x%x cb->usage=0x%x\n", usage, cb->usage); + return -EINVAL; + } + + EGLint postCount = 0; + void *cpu_addr = NULL; + + // + // make sure ashmem area is mapped if needed + // + if (cb->canBePosted() || sw_read || sw_write) { + if (cb->ashmemBasePid != getpid() || !cb->ashmemBase) { + return -EACCES; + } + + if (cb->canBePosted()) { + postCount = *((int *)cb->ashmemBase); + cpu_addr = (void *)(cb->ashmemBase + sizeof(int)); + } + else { + cpu_addr = (void *)(cb->ashmemBase); + } + } + + if (cb->hostHandle) { + // Make sure we have host connection + DEFINE_AND_VALIDATE_HOST_CONNECTION; + + // + // flush color buffer write cache on host and get its sync status. + // + int hostSyncStatus = rcEnc->rcColorBufferCacheFlush(rcEnc, cb->hostHandle, + postCount, + sw_read); + if (hostSyncStatus < 0) { + // host failed the color buffer sync - probably since it was already + // locked for write access. fail the lock. + ALOGE("gralloc_lock cacheFlush failed postCount=%d sw_read=%d\n", + postCount, sw_read); + return -EBUSY; + } + + // + // is virtual address required ? + // + if (sw_read || sw_write) { + *vaddr = cpu_addr; + } + } + + if (sw_write) { + // + // Keep locked region if locked for s/w write access. + // + cb->lockedLeft = l; + cb->lockedTop = t; + cb->lockedWidth = w; + cb->lockedHeight = h; + } + + return 0; +} + +static int gralloc_unlock(gralloc_module_t const* module, + buffer_handle_t handle) +{ + if (sFallback != NULL) { + return sFallback->unlock(sFallback, handle); + } + + private_module_t *gr = (private_module_t *)module; + cb_handle_t *cb = (cb_handle_t *)handle; + if (!gr || !cb_handle_t::validate(cb)) { + return -EINVAL; + } + + // + // if buffer was locked for s/w write, we need to update the host with + // the updated data + // + if (cb->lockedWidth > 0 && cb->lockedHeight > 0 && cb->hostHandle) { + + // Make sure we have host connection + DEFINE_AND_VALIDATE_HOST_CONNECTION; + + void *cpu_addr; + if (cb->canBePosted()) { + cpu_addr = (void *)(cb->ashmemBase + sizeof(int)); + } + else { + cpu_addr = (void *)(cb->ashmemBase); + } + + if (cb->lockedWidth < cb->width || cb->lockedHeight < cb->height) { + int bpp = glUtilsPixelBitSize(cb->glFormat, cb->glType) >> 3; + char *tmpBuf = new char[cb->lockedWidth * cb->lockedHeight * bpp]; + + int dst_line_len = cb->lockedWidth * bpp; + int src_line_len = cb->width * bpp; + char *src = (char *)cpu_addr + cb->lockedTop*src_line_len + cb->lockedLeft*bpp; + char *dst = tmpBuf; + for (int y=0; y<cb->lockedHeight; y++) { + memcpy(dst, src, dst_line_len); + src += src_line_len; + dst += dst_line_len; + } + + rcEnc->rcUpdateColorBuffer(rcEnc, cb->hostHandle, + cb->lockedLeft, cb->lockedTop, + cb->lockedWidth, cb->lockedHeight, + cb->glFormat, cb->glType, + tmpBuf); + + delete [] tmpBuf; + } + else { + rcEnc->rcUpdateColorBuffer(rcEnc, cb->hostHandle, 0, 0, + cb->width, cb->height, + cb->glFormat, cb->glType, + cpu_addr); + } + } + + cb->lockedWidth = cb->lockedHeight = 0; + return 0; +} + + +static int gralloc_device_open(const hw_module_t* module, + const char* name, + hw_device_t** device) +{ + int status = -EINVAL; + + D("gralloc_device_open %s\n", name); + + pthread_once( &sFallbackOnce, fallback_init ); + if (sFallback != NULL) { + return sFallback->common.methods->open(&sFallback->common, name, device); + } + + if (!strcmp(name, GRALLOC_HARDWARE_GPU0)) { + + // Create host connection and keep it in the TLS. + // return error if connection with host can not be established + HostConnection *hostCon = HostConnection::get(); + if (!hostCon) { + ALOGE("gralloc: failed to get host connection while opening %s\n", name); + return -EIO; + } + + // + // Allocate memory for the gralloc device (alloc interface) + // + gralloc_device_t *dev; + dev = (gralloc_device_t*)malloc(sizeof(gralloc_device_t)); + if (NULL == dev) { + return -ENOMEM; + } + + // Initialize our device structure + // + dev->device.common.tag = HARDWARE_DEVICE_TAG; + dev->device.common.version = 0; + dev->device.common.module = const_cast<hw_module_t*>(module); + dev->device.common.close = gralloc_device_close; + + dev->device.alloc = gralloc_alloc; + dev->device.free = gralloc_free; + dev->allocListHead = NULL; + pthread_mutex_init(&dev->lock, NULL); + + *device = &dev->device.common; + status = 0; + } + else if (!strcmp(name, GRALLOC_HARDWARE_FB0)) { + + // return error if connection with host can not be established + DEFINE_AND_VALIDATE_HOST_CONNECTION; + + // + // Query the host for Framebuffer attributes + // + D("gralloc: query Frabuffer attribs\n"); + EGLint width = rcEnc->rcGetFBParam(rcEnc, FB_WIDTH); + D("gralloc: width=%d\n", width); + EGLint height = rcEnc->rcGetFBParam(rcEnc, FB_HEIGHT); + D("gralloc: height=%d\n", height); + EGLint xdpi = rcEnc->rcGetFBParam(rcEnc, FB_XDPI); + D("gralloc: xdpi=%d\n", xdpi); + EGLint ydpi = rcEnc->rcGetFBParam(rcEnc, FB_YDPI); + D("gralloc: ydpi=%d\n", ydpi); + EGLint fps = rcEnc->rcGetFBParam(rcEnc, FB_FPS); + D("gralloc: fps=%d\n", fps); + EGLint min_si = rcEnc->rcGetFBParam(rcEnc, FB_MIN_SWAP_INTERVAL); + D("gralloc: min_swap=%d\n", min_si); + EGLint max_si = rcEnc->rcGetFBParam(rcEnc, FB_MAX_SWAP_INTERVAL); + D("gralloc: max_swap=%d\n", max_si); + + // + // Allocate memory for the framebuffer device + // + fb_device_t *dev; + dev = (fb_device_t*)malloc(sizeof(fb_device_t)); + if (NULL == dev) { + return -ENOMEM; + } + memset(dev, 0, sizeof(fb_device_t)); + + // Initialize our device structure + // + dev->device.common.tag = HARDWARE_DEVICE_TAG; + dev->device.common.version = 0; + dev->device.common.module = const_cast<hw_module_t*>(module); + dev->device.common.close = fb_close; + dev->device.setSwapInterval = fb_setSwapInterval; + dev->device.post = fb_post; + dev->device.setUpdateRect = 0; //fb_setUpdateRect; + dev->device.compositionComplete = fb_compositionComplete; //XXX: this is a dummy + + const_cast<uint32_t&>(dev->device.flags) = 0; + const_cast<uint32_t&>(dev->device.width) = width; + const_cast<uint32_t&>(dev->device.height) = height; + const_cast<int&>(dev->device.stride) = width; + const_cast<int&>(dev->device.format) = HAL_PIXEL_FORMAT_RGBA_8888; + const_cast<float&>(dev->device.xdpi) = xdpi; + const_cast<float&>(dev->device.ydpi) = ydpi; + const_cast<float&>(dev->device.fps) = fps; + const_cast<int&>(dev->device.minSwapInterval) = min_si; + const_cast<int&>(dev->device.maxSwapInterval) = max_si; + *device = &dev->device.common; + + status = 0; + } + + return status; +} + +// +// define the HMI symbol - our module interface +// +static struct hw_module_methods_t gralloc_module_methods = { + open: gralloc_device_open +}; + +struct private_module_t HAL_MODULE_INFO_SYM = { + base: { + common: { + tag: HARDWARE_MODULE_TAG, + version_major: 1, + version_minor: 0, + id: GRALLOC_HARDWARE_MODULE_ID, + name: "Graphics Memory Allocator Module", + author: "The Android Open Source Project", + methods: &gralloc_module_methods, + dso: NULL, + reserved: {0, } + }, + registerBuffer: gralloc_register_buffer, + unregisterBuffer: gralloc_unregister_buffer, + lock: gralloc_lock, + unlock: gralloc_unlock, + perform: NULL, + reserved_proc : {NULL, } + } +}; + +/* This function is called once to detect whether the emulator supports + * GPU emulation (this is done by looking at the qemu.gles kernel + * parameter, which must be > 0 if this is the case). + * + * If not, then load gralloc.default instead as a fallback. + */ +static void +fallback_init(void) +{ + char prop[PROPERTY_VALUE_MAX]; + void* module; + + property_get("ro.kernel.qemu.gles", prop, "0"); + if (atoi(prop) > 0) { + return; + } + ALOGD("Emulator without GPU emulation detected."); + module = dlopen("/system/lib/hw/gralloc.default.so", RTLD_LAZY|RTLD_LOCAL); + if (module != NULL) { + sFallback = reinterpret_cast<gralloc_module_t*>(dlsym(module, HAL_MODULE_INFO_SYM_AS_STR)); + if (sFallback == NULL) { + dlclose(module); + } + } + if (sFallback == NULL) { + ALOGE("Could not find software fallback module!?"); + } +} diff --git a/emulator/opengl/system/renderControl_enc/Android.mk b/emulator/opengl/system/renderControl_enc/Android.mk new file mode 100644 index 0000000..96f15a2 --- /dev/null +++ b/emulator/opengl/system/renderControl_enc/Android.mk @@ -0,0 +1,7 @@ +LOCAL_PATH := $(call my-dir) + +$(call emugl-begin-shared-library,lib_renderControl_enc) +$(call emugl-gen-encoder,$(LOCAL_PATH),renderControl) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) +$(call emugl-import,libOpenglCodecCommon) +$(call emugl-end-module) diff --git a/emulator/opengl/system/renderControl_enc/README b/emulator/opengl/system/renderControl_enc/README new file mode 100644 index 0000000..2ee1a57 --- /dev/null +++ b/emulator/opengl/system/renderControl_enc/README @@ -0,0 +1,136 @@ +The renderControl.in file in this directory defines an API which is decoded +on the android guest into a stream and get decoded and executed on the host. +It is used in order to query the host renderer as well as send the host renderer +control commands. + +The following describes each of the entries defined by this renderControl API. + + +GLint rcGetRendererVersion(); + This function queries the host renderer version number. + +EGLint rcGetEGLVersion(EGLint* major, EGLint* minor); + This function queries the host renderer for the EGL version + it supports. returns EGL_FALSE on failure. + +EGLint rcQueryEGLString(EGLenum name, void* buffer, EGLint bufferSize); + This function queries the host for EGL string (.i.e EGL_EXTENSIONS). + if buffer is NULL or the bufferSize is not big enough the return value + is the negative number of bytes required to store the string value + otherwise the string value is copied to buffer and its size is + returned. + +EGLint rcGetNumConfigs(uint32_t* numAttribs); + queries the host for the number of supported EGL configs. + The function returns the number of supported configs and returns in + numAttribs the number of attributes available for each config. + +EGLint rcGetConfigs(uint32_t bufSize, GLuint* buffer); + This function queries the host for the all set of supported configs + with their attribute values. + bufSize is the size of buffer, the size should be at least equal to + (numConfigs + 1) * numAttribs * sizeof(GLuint) + where numConfigs and numAttribs are the values returned in + rcGetNumConfigs. if bufSize is not big enough then the negative number + of required bytes is returned otherwise the function returns the number + of configs and buffer is filled as follows: The first 'numAttribs' + integer values are filled with the EGL enumerant describing a config + attribute, next for each config there are 'numAttribs' integer values + holding the attribute values for that config, the values are specified + in the same order as the attribute vector. + +EGLint rcChooseConfig(EGLint *attribs, uint32_t attribs_size, uint32_t *configs, uint32_t configs_size) + This function triggers an eglChooseConfig on the host, to get a list of + configs matching the given attribs values. + attribs - a list of attribute names followed by the desired values, terminated by EGL_NONE + attribs_size - the size of the list + configs - the returned matching configuration names (same names as familiar to the client in rcGetConfigs) + configs_size - the size of the configs buffers + returns - the actual number of matching configurations (<= configs_size) + +EGLint rcGetFBParam(EGLint param); + queries the host for framebuffer parameter, see renderControl_types.h + for possible values of 'param'. + +uint32_t rcCreateContext(uint32_t config, uint32_t share, uint32_t glVersion); + This function creates a rendering context on the host and returns its + handle. config is the config index for the context, share is either zero + or a handle to a sharing context. glVersion is either 1 or 2 for GLES1 + or GLES2 context respectively. + + +void rcDestroyContext(uint32_t context); + This function destroys a rendering context on the host. + context is a handle returned in rcCreateContext. + +uint32_t rcCreateWindowSurface(uint32_t config, uint32_t width, uint32_t height); + This function creates a 'window' surface on the host which can be then + bind for rendering through rcMakeCurrent. + The function returns a handle to the created window surface. + +void rcDestroyWindowSurface(uint32_t windowSurface); + This function destoys a window surface. + +uint32_t rcCreateColorBuffer(uint32_t width, uint32_t height, GLenum internalFormat); + This function creates a colorBuffer object on the host which can be then + be specified as a render target for a window surface through + rcSetWindowColorBuffer or to be displayed on the framebuffer window + through rcFBPost. + The function returns a handle to the colorBuffer object, with an initial + reference count of 1. + +void rcOpenColorBuffer(uint32_t colorbuffer); + Adds an additional reference to the colorbuffer, typically from a + different Android process than the one which created it. + +void rcCloseColorBuffer(uint32_t colorbuffer); + Removes a reference to the colorbuffer. When the reference count drops + to zero the colorbuffer is automatically destroyed. + +void rcFlushWindowColorBuffer(uint32_t windowSurface, uint32_t colorBuffer); + This flushes the current window color buffer + +void rcSetWindowColorBuffer(uint32_t windowSurface, uint32_t colorBuffer); + This set the target color buffer for a windowSurface, when set the + previous target colorBuffer gets updated before switching to the new + colorBuffer. + +EGLint rcMakeCurrent(uint32_t context, uint32_t drawSurf, uint32_t readSurf); + Binds a windowSurface(s) and current rendering context for the + calling thread. + +void rcFBPost(uint32_t colorBuffer); + This function causes the content of the colorBuffer object to be + displayed on the host framebuffer window. The function returns + immediatly, the buffer will be displayed at the next swap interval. + +void rcFBSetSwapInterval(EGLint interval); + Sets the swap interval for the host framebuffer window. + +void rcBindTexture(uint32_t colorBuffer); + This function instruct the host to bind the content of the specified + colorBuffer to the current binded texture object of the calling thread. + This function should be used to implement eglBindTexImage. + +EGLint rcColorBufferCacheFlush(uint32_t colorbuffer, EGLint postCount, int forRead); + This function returns only after all rendering requests for the specified + colorBuffer rendering target has been processed and after all 'postCount' + posts for the buffer requested previously through rcFBPost has been + processed. + if 'forRead' is not-zero, the function returns positive value in case + there was rendering done to the buffer since the last CacheFlush request + with non-zero 'forRead' value, otherwise the function returns zero or + negative value on failure. + +void rcReadColorBuffer(uint32_t colorbuffer, GLint x, GLint y, + GLint width, GLint height, GLenum format, + GLenum type, void* pixels); + This function queries the host for the pixel content of a colorBuffer's + subregion. It act the same as OpenGL glReadPixels however pixels + are always packed with alignment of 1. + +void rcUpdateColorBuffer(uint32_t colorbuffer, GLint x, GLint y, + GLint width, GLint height, GLenum format, + GLenum type, void* pixels); + Updates the content of a subregion of a colorBuffer object. + pixels are always unpacked with alignment of 1. diff --git a/emulator/opengl/system/renderControl_enc/renderControl.attrib b/emulator/opengl/system/renderControl_enc/renderControl.attrib new file mode 100644 index 0000000..8b9972f --- /dev/null +++ b/emulator/opengl/system/renderControl_enc/renderControl.attrib @@ -0,0 +1,41 @@ +GLOBAL + base_opcode 10000 + encoder_headers <stdint.h> <EGL/egl.h> "glUtils.h" + +rcGetEGLVersion + dir major out + len major sizeof(EGLint) + dir minor out + len minor sizeof(EGLint) + +rcQueryEGLString + dir buffer out + len buffer bufferSize + +rcGetGLString + dir buffer out + len buffer bufferSize + +rcGetNumConfigs + dir numAttribs out + len numAttribs sizeof(uint32_t) + +rcGetConfigs + dir buffer out + len buffer bufSize + +rcChooseConfig + dir attribs in + len attribs attribs_size + dir configs out + var_flag configs nullAllowed + len configs configs_size*sizeof(uint32_t) + +rcReadColorBuffer + dir pixels out + len pixels (((glUtilsPixelBitSize(format, type) * width) >> 3) * height) + +rcUpdateColorBuffer + dir pixels in + len pixels (((glUtilsPixelBitSize(format, type) * width) >> 3) * height) + var_flag pixels isLarge diff --git a/emulator/opengl/system/renderControl_enc/renderControl.in b/emulator/opengl/system/renderControl_enc/renderControl.in new file mode 100644 index 0000000..8281fd9 --- /dev/null +++ b/emulator/opengl/system/renderControl_enc/renderControl.in @@ -0,0 +1,25 @@ +GL_ENRTY(GLint, rcGetRendererVersion) +GL_ENTRY(EGLint, rcGetEGLVersion, EGLint *major, EGLint *minor) +GL_ENTRY(EGLint, rcQueryEGLString, EGLenum name, void *buffer, EGLint bufferSize) +GL_ENTRY(EGLint, rcGetGLString, EGLenum name, void *buffer, EGLint bufferSize) +GL_ENTRY(EGLint, rcGetNumConfigs, uint32_t *numAttribs) +GL_ENTRY(EGLint, rcGetConfigs, uint32_t bufSize, GLuint *buffer) +GL_ENTRY(EGLint, rcChooseConfig, EGLint *attribs, uint32_t attribs_size, uint32_t *configs, uint32_t configs_size) +GL_ENTRY(EGLint, rcGetFBParam, EGLint param) +GL_ENTRY(uint32_t, rcCreateContext, uint32_t config, uint32_t share, uint32_t glVersion) +GL_ENTRY(void, rcDestroyContext, uint32_t context) +GL_ENTRY(uint32_t, rcCreateWindowSurface, uint32_t config, uint32_t width, uint32_t height) +GL_ENTRY(void, rcDestroyWindowSurface, uint32_t windowSurface) +GL_ENTRY(uint32_t, rcCreateColorBuffer, uint32_t width, uint32_t height, GLenum internalFormat) +GL_ENTRY(void, rcOpenColorBuffer, uint32_t colorbuffer) +GL_ENTRY(void, rcCloseColorBuffer, uint32_t colorbuffer) +GL_ENTRY(void, rcSetWindowColorBuffer, uint32_t windowSurface, uint32_t colorBuffer) +GL_ENTRY(int, rcFlushWindowColorBuffer, uint32_t windowSurface) +GL_ENTRY(EGLint, rcMakeCurrent, uint32_t context, uint32_t drawSurf, uint32_t readSurf) +GL_ENTRY(void, rcFBPost, uint32_t colorBuffer) +GL_ENTRY(void, rcFBSetSwapInterval, EGLint interval) +GL_ENTRY(void, rcBindTexture, uint32_t colorBuffer) +GL_ENTRY(void, rcBindRenderbuffer, uint32_t colorBuffer) +GL_ENTRY(EGLint, rcColorBufferCacheFlush, uint32_t colorbuffer, EGLint postCount,int forRead) +GL_ENTRY(void, rcReadColorBuffer, uint32_t colorbuffer, GLint x, GLint y, GLint width, GLint height, GLenum format, GLenum type, void *pixels) +GL_ENTRY(int, rcUpdateColorBuffer, uint32_t colorbuffer, GLint x, GLint y, GLint width, GLint height, GLenum format, GLenum type, void *pixels) diff --git a/emulator/opengl/system/renderControl_enc/renderControl.types b/emulator/opengl/system/renderControl_enc/renderControl.types new file mode 100644 index 0000000..a7d96ab --- /dev/null +++ b/emulator/opengl/system/renderControl_enc/renderControl.types @@ -0,0 +1,11 @@ +uint32_t 32 0x%08x false +EGLint 32 0x%08x false +GLint 32 0x%08x false +GLuint 32 0x%08x false +GLenum 32 0x%08x false +EGLenum 32 0x%08x false +uint32_t* 32 0x%08x true +EGLint* 32 0x%08x true +GLint* 32 0x%08x true +GLuint* 32 0x%08x true +void* 32 0x%08x true diff --git a/emulator/opengl/system/renderControl_enc/renderControl_types.h b/emulator/opengl/system/renderControl_enc/renderControl_types.h new file mode 100644 index 0000000..da215bb --- /dev/null +++ b/emulator/opengl/system/renderControl_enc/renderControl_types.h @@ -0,0 +1,28 @@ +/* +* 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 <stdint.h> +#include <EGL/egl.h> +#include "glUtils.h" + +// values for 'param' argument of rcGetFBParam +#define FB_WIDTH 1 +#define FB_HEIGHT 2 +#define FB_XDPI 3 +#define FB_YDPI 4 +#define FB_FPS 5 +#define FB_MIN_SWAP_INTERVAL 6 +#define FB_MAX_SWAP_INTERVAL 7 diff --git a/emulator/opengl/tests/EGL_host_wrapper/Android.mk b/emulator/opengl/tests/EGL_host_wrapper/Android.mk new file mode 100644 index 0000000..19d8794 --- /dev/null +++ b/emulator/opengl/tests/EGL_host_wrapper/Android.mk @@ -0,0 +1,16 @@ +ifeq ($(HOST_OS),linux) + +LOCAL_PATH := $(call my-dir) + +$(call emugl-begin-host-static-library,libEGL_host_wrapper) + +LOCAL_SRC_FILES := \ + egl.cpp \ + egl_dispatch.cpp + +$(call emugl-export,LDLIBS,-ldl -pthread) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) + +$(call emugl-end-module) + +endif # HOST_OS == linux diff --git a/emulator/opengl/tests/EGL_host_wrapper/egl.cpp b/emulator/opengl/tests/EGL_host_wrapper/egl.cpp new file mode 100644 index 0000000..6fa27ac --- /dev/null +++ b/emulator/opengl/tests/EGL_host_wrapper/egl.cpp @@ -0,0 +1,277 @@ +/* +* 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 <string.h> +#include "egl_dispatch.h" +#include "egl_ftable.h" +#include <pthread.h> + +#define EGL_LIB "ANDROID_EGL_LIB" + +static struct egl_dispatch *s_dispatch = NULL; +static pthread_once_t eglDispatchInitialized = PTHREAD_ONCE_INIT; + +void initEglDispatch() +{ + // + // Load back-end EGL implementation library + // + char *eglLib = (char *) "libEGL.so"; + if (getenv(EGL_LIB) != NULL) { + eglLib = getenv(EGL_LIB); + } + + s_dispatch = loadEGL(eglLib); + if (!s_dispatch) { + fprintf(stderr,"FATAL ERROR: Could not load EGL lib [%s]\n", eglLib); + exit(-1); + } +} + +static struct egl_dispatch *getDispatch() +{ + pthread_once(&eglDispatchInitialized, initEglDispatch); + return s_dispatch; +} + +__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) +{ + for (int i=0; i<egl_num_funcs; i++) { + if (!strcmp(egl_funcs_by_name[i].name, procname)) { + return (__eglMustCastToProperFunctionPointerType)egl_funcs_by_name[i].proc; + } + } + + return getDispatch()->eglGetProcAddress(procname); +} + +//////////////// Path through functions ////////// + +EGLint eglGetError() +{ + return getDispatch()->eglGetError(); +} + +EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id) +{ + return getDispatch()->eglGetDisplay(display_id); +} + +EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) +{ + return getDispatch()->eglInitialize(dpy, major, minor); +} + +EGLBoolean eglTerminate(EGLDisplay dpy) +{ + return getDispatch()->eglTerminate(dpy); +} + +const char* eglQueryString(EGLDisplay dpy, EGLint name) +{ + return getDispatch()->eglQueryString(dpy, name); +} + +EGLBoolean eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config) +{ + return getDispatch()->eglGetConfigs(dpy, configs, config_size, num_config); +} + +EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config) +{ + return getDispatch()->eglChooseConfig(dpy, attrib_list, configs, config_size, num_config); +} + +EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value) +{ + return getDispatch()->eglGetConfigAttrib(dpy, config, attribute, value); +} + +EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list) +{ + return getDispatch()->eglCreateWindowSurface(dpy, config, win, attrib_list); +} + +EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list) +{ + return getDispatch()->eglCreatePbufferSurface(dpy, config, attrib_list); +} + +EGLSurface eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list) +{ + return getDispatch()->eglCreatePixmapSurface(dpy, config, pixmap, attrib_list); +} + +EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) +{ + return getDispatch()->eglDestroySurface(dpy, surface); +} + +EGLBoolean eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value) +{ + return getDispatch()->eglQuerySurface(dpy, surface, attribute, value); +} + +EGLBoolean eglBindAPI(EGLenum api) +{ + return getDispatch()->eglBindAPI(api); +} + +EGLenum eglQueryAPI() +{ + return getDispatch()->eglQueryAPI(); +} + +EGLBoolean eglWaitClient() +{ + return getDispatch()->eglWaitClient(); +} + +EGLBoolean eglReleaseThread() +{ + return getDispatch()->eglReleaseThread(); +} + +EGLSurface eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list) +{ + return getDispatch()->eglCreatePbufferFromClientBuffer(dpy, buftype, buffer, config, attrib_list); +} + +EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) +{ + return getDispatch()->eglSurfaceAttrib(dpy, surface, attribute, value); +} + +EGLBoolean eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) +{ + return getDispatch()->eglBindTexImage(dpy, surface, buffer); +} + +EGLBoolean eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) +{ + return getDispatch()->eglReleaseTexImage(dpy, surface, buffer); +} + +EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) +{ + return getDispatch()->eglSwapInterval(dpy, interval); +} + +EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list) +{ + return getDispatch()->eglCreateContext(dpy, config, share_context, attrib_list); +} + +EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) +{ + return getDispatch()->eglDestroyContext(dpy, ctx); +} + +EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) +{ + return getDispatch()->eglMakeCurrent(dpy, draw, read, ctx); +} + +EGLContext eglGetCurrentContext() +{ + return getDispatch()->eglGetCurrentContext(); +} + +EGLSurface eglGetCurrentSurface(EGLint readdraw) +{ + return getDispatch()->eglGetCurrentSurface(readdraw); +} + +EGLDisplay eglGetCurrentDisplay() +{ + return getDispatch()->eglGetCurrentDisplay(); +} + +EGLBoolean eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value) +{ + return getDispatch()->eglQueryContext(dpy, ctx, attribute, value); +} + +EGLBoolean eglWaitGL() +{ + return getDispatch()->eglWaitGL(); +} + +EGLBoolean eglWaitNative(EGLint engine) +{ + return getDispatch()->eglWaitNative(engine); +} + +EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) +{ + return getDispatch()->eglSwapBuffers(dpy, surface); +} + +EGLBoolean eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target) +{ + return getDispatch()->eglCopyBuffers(dpy, surface, target); +} + +EGLBoolean eglLockSurfaceKHR(EGLDisplay display, EGLSurface surface, const EGLint *attrib_list) +{ + return getDispatch()->eglLockSurfaceKHR(display, surface, attrib_list); +} + +EGLBoolean eglUnlockSurfaceKHR(EGLDisplay display, EGLSurface surface) +{ + return getDispatch()->eglUnlockSurfaceKHR(display, surface); +} + +EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list) +{ + return getDispatch()->eglCreateImageKHR(dpy, ctx, target, buffer, attrib_list); +} + +EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image) +{ + return getDispatch()->eglDestroyImageKHR(dpy, image); +} + +EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) +{ + return getDispatch()->eglCreateSyncKHR(dpy, type, attrib_list); +} + +EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) +{ + return getDispatch()->eglDestroySyncKHR(dpy, sync); +} + +EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout) +{ + return getDispatch()->eglClientWaitSyncKHR(dpy, sync, flags, timeout); +} + +EGLBoolean eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) +{ + return getDispatch()->eglSignalSyncKHR(dpy, sync, mode); +} + +EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value) +{ + return getDispatch()->eglGetSyncAttribKHR(dpy, sync, attribute, value); +} + +EGLBoolean eglSetSwapRectangleANDROID(EGLDisplay dpy, EGLSurface draw, EGLint left, EGLint top, EGLint width, EGLint height) +{ + return getDispatch()->eglSetSwapRectangleANDROID(dpy, draw, left, top, width, height); +} diff --git a/emulator/opengl/tests/EGL_host_wrapper/egl_dispatch.cpp b/emulator/opengl/tests/EGL_host_wrapper/egl_dispatch.cpp new file mode 100644 index 0000000..a9b8214 --- /dev/null +++ b/emulator/opengl/tests/EGL_host_wrapper/egl_dispatch.cpp @@ -0,0 +1,77 @@ +/* +* 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 <dlfcn.h> +#include "egl_dispatch.h" + + +egl_dispatch *loadEGL(const char *p_eglPath) +{ + void *libEGL = dlopen(p_eglPath, RTLD_NOW); + if (!libEGL) { + return NULL; + } + + egl_dispatch *disp = new egl_dispatch; + + void *ptr; + ptr = dlsym(libEGL,"eglGetError"); disp->set_eglGetError((eglGetError_t)ptr); + ptr = dlsym(libEGL,"eglGetDisplay"); disp->set_eglGetDisplay((eglGetDisplay_t)ptr); + ptr = dlsym(libEGL,"eglInitialize"); disp->set_eglInitialize((eglInitialize_t)ptr); + ptr = dlsym(libEGL,"eglTerminate"); disp->set_eglTerminate((eglTerminate_t)ptr); + ptr = dlsym(libEGL,"eglQueryString"); disp->set_eglQueryString((eglQueryString_t)ptr); + ptr = dlsym(libEGL,"eglGetConfigs"); disp->set_eglGetConfigs((eglGetConfigs_t)ptr); + ptr = dlsym(libEGL,"eglChooseConfig"); disp->set_eglChooseConfig((eglChooseConfig_t)ptr); + ptr = dlsym(libEGL,"eglGetConfigAttrib"); disp->set_eglGetConfigAttrib((eglGetConfigAttrib_t)ptr); + ptr = dlsym(libEGL,"eglCreateWindowSurface"); disp->set_eglCreateWindowSurface((eglCreateWindowSurface_t)ptr); + ptr = dlsym(libEGL,"eglCreatePbufferSurface"); disp->set_eglCreatePbufferSurface((eglCreatePbufferSurface_t)ptr); + ptr = dlsym(libEGL,"eglCreatePixmapSurface"); disp->set_eglCreatePixmapSurface((eglCreatePixmapSurface_t)ptr); + ptr = dlsym(libEGL,"eglDestroySurface"); disp->set_eglDestroySurface((eglDestroySurface_t)ptr); + ptr = dlsym(libEGL,"eglQuerySurface"); disp->set_eglQuerySurface((eglQuerySurface_t)ptr); + ptr = dlsym(libEGL,"eglBindAPI"); disp->set_eglBindAPI((eglBindAPI_t)ptr); + ptr = dlsym(libEGL,"eglQueryAPI"); disp->set_eglQueryAPI((eglQueryAPI_t)ptr); + ptr = dlsym(libEGL,"eglWaitClient"); disp->set_eglWaitClient((eglWaitClient_t)ptr); + ptr = dlsym(libEGL,"eglReleaseThread"); disp->set_eglReleaseThread((eglReleaseThread_t)ptr); + ptr = dlsym(libEGL,"eglCreatePbufferFromClientBuffer"); disp->set_eglCreatePbufferFromClientBuffer((eglCreatePbufferFromClientBuffer_t)ptr); + ptr = dlsym(libEGL,"eglSurfaceAttrib"); disp->set_eglSurfaceAttrib((eglSurfaceAttrib_t)ptr); + ptr = dlsym(libEGL,"eglBindTexImage"); disp->set_eglBindTexImage((eglBindTexImage_t)ptr); + ptr = dlsym(libEGL,"eglReleaseTexImage"); disp->set_eglReleaseTexImage((eglReleaseTexImage_t)ptr); + ptr = dlsym(libEGL,"eglSwapInterval"); disp->set_eglSwapInterval((eglSwapInterval_t)ptr); + ptr = dlsym(libEGL,"eglCreateContext"); disp->set_eglCreateContext((eglCreateContext_t)ptr); + ptr = dlsym(libEGL,"eglDestroyContext"); disp->set_eglDestroyContext((eglDestroyContext_t)ptr); + ptr = dlsym(libEGL,"eglMakeCurrent"); disp->set_eglMakeCurrent((eglMakeCurrent_t)ptr); + ptr = dlsym(libEGL,"eglGetCurrentContext"); disp->set_eglGetCurrentContext((eglGetCurrentContext_t)ptr); + ptr = dlsym(libEGL,"eglGetCurrentSurface"); disp->set_eglGetCurrentSurface((eglGetCurrentSurface_t)ptr); + ptr = dlsym(libEGL,"eglGetCurrentDisplay"); disp->set_eglGetCurrentDisplay((eglGetCurrentDisplay_t)ptr); + ptr = dlsym(libEGL,"eglQueryContext"); disp->set_eglQueryContext((eglQueryContext_t)ptr); + ptr = dlsym(libEGL,"eglWaitGL"); disp->set_eglWaitGL((eglWaitGL_t)ptr); + ptr = dlsym(libEGL,"eglWaitNative"); disp->set_eglWaitNative((eglWaitNative_t)ptr); + ptr = dlsym(libEGL,"eglSwapBuffers"); disp->set_eglSwapBuffers((eglSwapBuffers_t)ptr); + ptr = dlsym(libEGL,"eglCopyBuffers"); disp->set_eglCopyBuffers((eglCopyBuffers_t)ptr); + ptr = dlsym(libEGL,"eglGetProcAddress"); disp->set_eglGetProcAddress((eglGetProcAddress_t)ptr); + ptr = dlsym(libEGL,"eglLockSurfaceKHR"); disp->set_eglLockSurfaceKHR((eglLockSurfaceKHR_t)ptr); + ptr = dlsym(libEGL,"eglUnlockSurfaceKHR"); disp->set_eglUnlockSurfaceKHR((eglUnlockSurfaceKHR_t)ptr); + ptr = dlsym(libEGL,"eglCreateImageKHR"); disp->set_eglCreateImageKHR((eglCreateImageKHR_t)ptr); + ptr = dlsym(libEGL,"eglDestroyImageKHR"); disp->set_eglDestroyImageKHR((eglDestroyImageKHR_t)ptr); + ptr = dlsym(libEGL,"eglCreateSyncKHR"); disp->set_eglCreateSyncKHR((eglCreateSyncKHR_t)ptr); + ptr = dlsym(libEGL,"eglDestroySyncKHR"); disp->set_eglDestroySyncKHR((eglDestroySyncKHR_t)ptr); + ptr = dlsym(libEGL,"eglClientWaitSyncKHR"); disp->set_eglClientWaitSyncKHR((eglClientWaitSyncKHR_t)ptr); + ptr = dlsym(libEGL,"eglSignalSyncKHR"); disp->set_eglSignalSyncKHR((eglSignalSyncKHR_t)ptr); + ptr = dlsym(libEGL,"eglGetSyncAttribKHR"); disp->set_eglGetSyncAttribKHR((eglGetSyncAttribKHR_t)ptr); + ptr = dlsym(libEGL,"eglSetSwapRectangleANDROID"); disp->set_eglSetSwapRectangleANDROID((eglSetSwapRectangleANDROID_t)ptr); + + return disp; +} diff --git a/emulator/opengl/tests/EGL_host_wrapper/egl_dispatch.h b/emulator/opengl/tests/EGL_host_wrapper/egl_dispatch.h new file mode 100644 index 0000000..e5f67c9 --- /dev/null +++ b/emulator/opengl/tests/EGL_host_wrapper/egl_dispatch.h @@ -0,0 +1,115 @@ +/* +* 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 egl_dispatch { + 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; + //Accessors + eglGetError_t set_eglGetError(eglGetError_t f) { eglGetError_t retval = eglGetError; eglGetError = f; return retval;} + eglGetDisplay_t set_eglGetDisplay(eglGetDisplay_t f) { eglGetDisplay_t retval = eglGetDisplay; eglGetDisplay = f; return retval;} + eglInitialize_t set_eglInitialize(eglInitialize_t f) { eglInitialize_t retval = eglInitialize; eglInitialize = f; return retval;} + eglTerminate_t set_eglTerminate(eglTerminate_t f) { eglTerminate_t retval = eglTerminate; eglTerminate = f; return retval;} + eglQueryString_t set_eglQueryString(eglQueryString_t f) { eglQueryString_t retval = eglQueryString; eglQueryString = f; return retval;} + eglGetConfigs_t set_eglGetConfigs(eglGetConfigs_t f) { eglGetConfigs_t retval = eglGetConfigs; eglGetConfigs = f; return retval;} + eglChooseConfig_t set_eglChooseConfig(eglChooseConfig_t f) { eglChooseConfig_t retval = eglChooseConfig; eglChooseConfig = f; return retval;} + eglGetConfigAttrib_t set_eglGetConfigAttrib(eglGetConfigAttrib_t f) { eglGetConfigAttrib_t retval = eglGetConfigAttrib; eglGetConfigAttrib = f; return retval;} + eglCreateWindowSurface_t set_eglCreateWindowSurface(eglCreateWindowSurface_t f) { eglCreateWindowSurface_t retval = eglCreateWindowSurface; eglCreateWindowSurface = f; return retval;} + eglCreatePbufferSurface_t set_eglCreatePbufferSurface(eglCreatePbufferSurface_t f) { eglCreatePbufferSurface_t retval = eglCreatePbufferSurface; eglCreatePbufferSurface = f; return retval;} + eglCreatePixmapSurface_t set_eglCreatePixmapSurface(eglCreatePixmapSurface_t f) { eglCreatePixmapSurface_t retval = eglCreatePixmapSurface; eglCreatePixmapSurface = f; return retval;} + eglDestroySurface_t set_eglDestroySurface(eglDestroySurface_t f) { eglDestroySurface_t retval = eglDestroySurface; eglDestroySurface = f; return retval;} + eglQuerySurface_t set_eglQuerySurface(eglQuerySurface_t f) { eglQuerySurface_t retval = eglQuerySurface; eglQuerySurface = f; return retval;} + eglBindAPI_t set_eglBindAPI(eglBindAPI_t f) { eglBindAPI_t retval = eglBindAPI; eglBindAPI = f; return retval;} + eglQueryAPI_t set_eglQueryAPI(eglQueryAPI_t f) { eglQueryAPI_t retval = eglQueryAPI; eglQueryAPI = f; return retval;} + eglWaitClient_t set_eglWaitClient(eglWaitClient_t f) { eglWaitClient_t retval = eglWaitClient; eglWaitClient = f; return retval;} + eglReleaseThread_t set_eglReleaseThread(eglReleaseThread_t f) { eglReleaseThread_t retval = eglReleaseThread; eglReleaseThread = f; return retval;} + eglCreatePbufferFromClientBuffer_t set_eglCreatePbufferFromClientBuffer(eglCreatePbufferFromClientBuffer_t f) { eglCreatePbufferFromClientBuffer_t retval = eglCreatePbufferFromClientBuffer; eglCreatePbufferFromClientBuffer = f; return retval;} + eglSurfaceAttrib_t set_eglSurfaceAttrib(eglSurfaceAttrib_t f) { eglSurfaceAttrib_t retval = eglSurfaceAttrib; eglSurfaceAttrib = f; return retval;} + eglBindTexImage_t set_eglBindTexImage(eglBindTexImage_t f) { eglBindTexImage_t retval = eglBindTexImage; eglBindTexImage = f; return retval;} + eglReleaseTexImage_t set_eglReleaseTexImage(eglReleaseTexImage_t f) { eglReleaseTexImage_t retval = eglReleaseTexImage; eglReleaseTexImage = f; return retval;} + eglSwapInterval_t set_eglSwapInterval(eglSwapInterval_t f) { eglSwapInterval_t retval = eglSwapInterval; eglSwapInterval = f; return retval;} + eglCreateContext_t set_eglCreateContext(eglCreateContext_t f) { eglCreateContext_t retval = eglCreateContext; eglCreateContext = f; return retval;} + eglDestroyContext_t set_eglDestroyContext(eglDestroyContext_t f) { eglDestroyContext_t retval = eglDestroyContext; eglDestroyContext = f; return retval;} + eglMakeCurrent_t set_eglMakeCurrent(eglMakeCurrent_t f) { eglMakeCurrent_t retval = eglMakeCurrent; eglMakeCurrent = f; return retval;} + eglGetCurrentContext_t set_eglGetCurrentContext(eglGetCurrentContext_t f) { eglGetCurrentContext_t retval = eglGetCurrentContext; eglGetCurrentContext = f; return retval;} + eglGetCurrentSurface_t set_eglGetCurrentSurface(eglGetCurrentSurface_t f) { eglGetCurrentSurface_t retval = eglGetCurrentSurface; eglGetCurrentSurface = f; return retval;} + eglGetCurrentDisplay_t set_eglGetCurrentDisplay(eglGetCurrentDisplay_t f) { eglGetCurrentDisplay_t retval = eglGetCurrentDisplay; eglGetCurrentDisplay = f; return retval;} + eglQueryContext_t set_eglQueryContext(eglQueryContext_t f) { eglQueryContext_t retval = eglQueryContext; eglQueryContext = f; return retval;} + eglWaitGL_t set_eglWaitGL(eglWaitGL_t f) { eglWaitGL_t retval = eglWaitGL; eglWaitGL = f; return retval;} + eglWaitNative_t set_eglWaitNative(eglWaitNative_t f) { eglWaitNative_t retval = eglWaitNative; eglWaitNative = f; return retval;} + eglSwapBuffers_t set_eglSwapBuffers(eglSwapBuffers_t f) { eglSwapBuffers_t retval = eglSwapBuffers; eglSwapBuffers = f; return retval;} + eglCopyBuffers_t set_eglCopyBuffers(eglCopyBuffers_t f) { eglCopyBuffers_t retval = eglCopyBuffers; eglCopyBuffers = f; return retval;} + eglGetProcAddress_t set_eglGetProcAddress(eglGetProcAddress_t f) { eglGetProcAddress_t retval = eglGetProcAddress; eglGetProcAddress = f; return retval;} + eglLockSurfaceKHR_t set_eglLockSurfaceKHR(eglLockSurfaceKHR_t f) { eglLockSurfaceKHR_t retval = eglLockSurfaceKHR; eglLockSurfaceKHR = f; return retval;} + eglUnlockSurfaceKHR_t set_eglUnlockSurfaceKHR(eglUnlockSurfaceKHR_t f) { eglUnlockSurfaceKHR_t retval = eglUnlockSurfaceKHR; eglUnlockSurfaceKHR = f; return retval;} + eglCreateImageKHR_t set_eglCreateImageKHR(eglCreateImageKHR_t f) { eglCreateImageKHR_t retval = eglCreateImageKHR; eglCreateImageKHR = f; return retval;} + eglDestroyImageKHR_t set_eglDestroyImageKHR(eglDestroyImageKHR_t f) { eglDestroyImageKHR_t retval = eglDestroyImageKHR; eglDestroyImageKHR = f; return retval;} + eglCreateSyncKHR_t set_eglCreateSyncKHR(eglCreateSyncKHR_t f) { eglCreateSyncKHR_t retval = eglCreateSyncKHR; eglCreateSyncKHR = f; return retval;} + eglDestroySyncKHR_t set_eglDestroySyncKHR(eglDestroySyncKHR_t f) { eglDestroySyncKHR_t retval = eglDestroySyncKHR; eglDestroySyncKHR = f; return retval;} + eglClientWaitSyncKHR_t set_eglClientWaitSyncKHR(eglClientWaitSyncKHR_t f) { eglClientWaitSyncKHR_t retval = eglClientWaitSyncKHR; eglClientWaitSyncKHR = f; return retval;} + eglSignalSyncKHR_t set_eglSignalSyncKHR(eglSignalSyncKHR_t f) { eglSignalSyncKHR_t retval = eglSignalSyncKHR; eglSignalSyncKHR = f; return retval;} + eglGetSyncAttribKHR_t set_eglGetSyncAttribKHR(eglGetSyncAttribKHR_t f) { eglGetSyncAttribKHR_t retval = eglGetSyncAttribKHR; eglGetSyncAttribKHR = f; return retval;} + eglSetSwapRectangleANDROID_t set_eglSetSwapRectangleANDROID(eglSetSwapRectangleANDROID_t f) { eglSetSwapRectangleANDROID_t retval = eglSetSwapRectangleANDROID; eglSetSwapRectangleANDROID = f; return retval;} +}; + +egl_dispatch *loadEGL(const char *p_eglPath); + +#endif diff --git a/emulator/opengl/tests/EGL_host_wrapper/egl_ftable.h b/emulator/opengl/tests/EGL_host_wrapper/egl_ftable.h new file mode 100644 index 0000000..ee40585 --- /dev/null +++ b/emulator/opengl/tests/EGL_host_wrapper/egl_ftable.h @@ -0,0 +1,66 @@ +/* +* 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. +*/ +static struct _egl_funcs_by_name { + const char *name; + void *proc; +} egl_funcs_by_name[] = { + {"eglGetError", (void *)eglGetError}, + {"eglGetDisplay", (void *)eglGetDisplay}, + {"eglInitialize", (void *)eglInitialize}, + {"eglTerminate", (void *)eglTerminate}, + {"eglQueryString", (void *)eglQueryString}, + {"eglGetConfigs", (void *)eglGetConfigs}, + {"eglChooseConfig", (void *)eglChooseConfig}, + {"eglGetConfigAttrib", (void *)eglGetConfigAttrib}, + {"eglCreateWindowSurface", (void *)eglCreateWindowSurface}, + {"eglCreatePbufferSurface", (void *)eglCreatePbufferSurface}, + {"eglCreatePixmapSurface", (void *)eglCreatePixmapSurface}, + {"eglDestroySurface", (void *)eglDestroySurface}, + {"eglQuerySurface", (void *)eglQuerySurface}, + {"eglBindAPI", (void *)eglBindAPI}, + {"eglQueryAPI", (void *)eglQueryAPI}, + {"eglWaitClient", (void *)eglWaitClient}, + {"eglReleaseThread", (void *)eglReleaseThread}, + {"eglCreatePbufferFromClientBuffer", (void *)eglCreatePbufferFromClientBuffer}, + {"eglSurfaceAttrib", (void *)eglSurfaceAttrib}, + {"eglBindTexImage", (void *)eglBindTexImage}, + {"eglReleaseTexImage", (void *)eglReleaseTexImage}, + {"eglSwapInterval", (void *)eglSwapInterval}, + {"eglCreateContext", (void *)eglCreateContext}, + {"eglDestroyContext", (void *)eglDestroyContext}, + {"eglMakeCurrent", (void *)eglMakeCurrent}, + {"eglGetCurrentContext", (void *)eglGetCurrentContext}, + {"eglGetCurrentSurface", (void *)eglGetCurrentSurface}, + {"eglGetCurrentDisplay", (void *)eglGetCurrentDisplay}, + {"eglQueryContext", (void *)eglQueryContext}, + {"eglWaitGL", (void *)eglWaitGL}, + {"eglWaitNative", (void *)eglWaitNative}, + {"eglSwapBuffers", (void *)eglSwapBuffers}, + {"eglCopyBuffers", (void *)eglCopyBuffers}, + {"eglGetProcAddress", (void *)eglGetProcAddress}, + {"eglLockSurfaceKHR", (void *)eglLockSurfaceKHR}, + {"eglUnlockSurfaceKHR", (void *)eglUnlockSurfaceKHR}, + {"eglCreateImageKHR", (void *)eglCreateImageKHR}, + {"eglDestroyImageKHR", (void *)eglDestroyImageKHR}, + {"eglCreateSyncKHR", (void *)eglCreateSyncKHR}, + {"eglDestroySyncKHR", (void *)eglDestroySyncKHR}, + {"eglClientWaitSyncKHR", (void *)eglClientWaitSyncKHR}, + {"eglSignalSyncKHR", (void *)eglSignalSyncKHR}, + {"eglGetSyncAttribKHR", (void *)eglGetSyncAttribKHR}, + {"eglSetSwapRectangleANDROID", (void *)eglSetSwapRectangleANDROID} +}; + +static int egl_num_funcs = sizeof(egl_funcs_by_name) / sizeof(struct _egl_funcs_by_name); diff --git a/emulator/opengl/tests/EGL_host_wrapper/egl_proc.h b/emulator/opengl/tests/EGL_host_wrapper/egl_proc.h new file mode 100644 index 0000000..140c030 --- /dev/null +++ b/emulator/opengl/tests/EGL_host_wrapper/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 (* eglGetError_t) (); +typedef EGLDisplay (* eglGetDisplay_t) (EGLNativeDisplayType); +typedef EGLBoolean (* eglInitialize_t) (EGLDisplay, EGLint*, EGLint*); +typedef EGLBoolean (* eglTerminate_t) (EGLDisplay); +typedef char* (* eglQueryString_t) (EGLDisplay, EGLint); +typedef EGLBoolean (* eglGetConfigs_t) (EGLDisplay, EGLConfig*, EGLint, EGLint*); +typedef EGLBoolean (* eglChooseConfig_t) (EGLDisplay, const EGLint*, EGLConfig*, EGLint, EGLint*); +typedef EGLBoolean (* eglGetConfigAttrib_t) (EGLDisplay, EGLConfig, EGLint, EGLint*); +typedef EGLSurface (* eglCreateWindowSurface_t) (EGLDisplay, EGLConfig, EGLNativeWindowType, const EGLint*); +typedef EGLSurface (* eglCreatePbufferSurface_t) (EGLDisplay, EGLConfig, const EGLint*); +typedef EGLSurface (* eglCreatePixmapSurface_t) (EGLDisplay, EGLConfig, EGLNativePixmapType, const EGLint*); +typedef EGLBoolean (* eglDestroySurface_t) (EGLDisplay, EGLSurface); +typedef EGLBoolean (* eglQuerySurface_t) (EGLDisplay, EGLSurface, EGLint, EGLint*); +typedef EGLBoolean (* eglBindAPI_t) (EGLenum); +typedef EGLenum (* eglQueryAPI_t) (); +typedef EGLBoolean (* eglWaitClient_t) (); +typedef EGLBoolean (* eglReleaseThread_t) (); +typedef EGLSurface (* eglCreatePbufferFromClientBuffer_t) (EGLDisplay, EGLenum, EGLClientBuffer, EGLConfig, const EGLint*); +typedef EGLBoolean (* eglSurfaceAttrib_t) (EGLDisplay, EGLSurface, EGLint, EGLint); +typedef EGLBoolean (* eglBindTexImage_t) (EGLDisplay, EGLSurface, EGLint); +typedef EGLBoolean (* eglReleaseTexImage_t) (EGLDisplay, EGLSurface, EGLint); +typedef EGLBoolean (* eglSwapInterval_t) (EGLDisplay, EGLint); +typedef EGLContext (* eglCreateContext_t) (EGLDisplay, EGLConfig, EGLContext, const EGLint*); +typedef EGLBoolean (* eglDestroyContext_t) (EGLDisplay, EGLContext); +typedef EGLBoolean (* eglMakeCurrent_t) (EGLDisplay, EGLSurface, EGLSurface, EGLContext); +typedef EGLContext (* eglGetCurrentContext_t) (); +typedef EGLSurface (* eglGetCurrentSurface_t) (EGLint); +typedef EGLDisplay (* eglGetCurrentDisplay_t) (); +typedef EGLBoolean (* eglQueryContext_t) (EGLDisplay, EGLContext, EGLint, EGLint*); +typedef EGLBoolean (* eglWaitGL_t) (); +typedef EGLBoolean (* eglWaitNative_t) (EGLint); +typedef EGLBoolean (* eglSwapBuffers_t) (EGLDisplay, EGLSurface); +typedef EGLBoolean (* eglCopyBuffers_t) (EGLDisplay, EGLSurface, EGLNativePixmapType); +typedef __eglMustCastToProperFunctionPointerType (* eglGetProcAddress_t) (const char*); +typedef EGLBoolean (* eglLockSurfaceKHR_t) (EGLDisplay, EGLSurface, const EGLint*); +typedef EGLBoolean (* eglUnlockSurfaceKHR_t) (EGLDisplay, EGLSurface); +typedef EGLImageKHR (* eglCreateImageKHR_t) (EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const EGLint*); +typedef EGLBoolean (* eglDestroyImageKHR_t) (EGLDisplay, EGLImageKHR image); +typedef EGLSyncKHR (* eglCreateSyncKHR_t) (EGLDisplay, EGLenum, const EGLint*); +typedef EGLBoolean (* eglDestroySyncKHR_t) (EGLDisplay, EGLSyncKHR sync); +typedef EGLint (* eglClientWaitSyncKHR_t) (EGLDisplay, EGLSyncKHR, EGLint, EGLTimeKHR timeout); +typedef EGLBoolean (* eglSignalSyncKHR_t) (EGLDisplay, EGLSyncKHR, EGLenum); +typedef EGLBoolean (* eglGetSyncAttribKHR_t) (EGLDisplay, EGLSyncKHR, EGLint, EGLint*); +typedef EGLBoolean (* eglSetSwapRectangleANDROID_t) (EGLDisplay, EGLSurface, EGLint, EGLint, EGLint, EGLint); + +#endif // of _EGL_PROC_H diff --git a/emulator/opengl/tests/emulator_test_renderer/Android.mk b/emulator/opengl/tests/emulator_test_renderer/Android.mk new file mode 100644 index 0000000..9c4cfdd --- /dev/null +++ b/emulator/opengl/tests/emulator_test_renderer/Android.mk @@ -0,0 +1,22 @@ +LOCAL_PATH:=$(call my-dir) + +$(call emugl-begin-host-executable,emulator_test_renderer) +$(call emugl-import,libOpenglRender event_injector) + +LOCAL_SRC_FILES := main.cpp + +PREBUILT := $(HOST_PREBUILT_TAG) +LOCAL_SDL_CONFIG ?= prebuilts/tools/$(PREBUILT)/sdl/bin/sdl-config +LOCAL_SDL_CFLAGS := $(shell $(LOCAL_SDL_CONFIG) --cflags) +LOCAL_SDL_LDLIBS := $(filter-out %.a %.lib,$(shell $(LOCAL_SDL_CONFIG) --static-libs)) + +LOCAL_CFLAGS += $(LOCAL_SDL_CFLAGS) -g -O0 +LOCAL_LDLIBS += $(LOCAL_SDL_LDLIBS) + +ifeq ($(HOST_OS),windows) +LOCAL_LDLIBS += -lws2_32 +endif + +LOCAL_STATIC_LIBRARIES += libSDL libSDLmain + +$(call emugl-end-module) diff --git a/emulator/opengl/tests/emulator_test_renderer/main.cpp b/emulator/opengl/tests/emulator_test_renderer/main.cpp new file mode 100644 index 0000000..06abce7 --- /dev/null +++ b/emulator/opengl/tests/emulator_test_renderer/main.cpp @@ -0,0 +1,222 @@ +/* +* 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. +*/ +#undef HAVE_MALLOC_H +#include <SDL.h> +#include <SDL_syswm.h> +#include <stdio.h> +#include <string.h> +#include "libOpenglRender/render_api.h" +#include <EventInjector.h> + +static int convert_keysym(int sym); // forward + +#ifdef __linux__ +#include <X11/Xlib.h> +#endif +#ifdef _WIN32 + +#include <winsock2.h> +int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) +#else +int main(int argc, char *argv[]) +#endif +{ + int portNum = 22468; + int winWidth = 320; + int winHeight = 480; + int width, height; + int mouseDown = 0; + const char* env = getenv("ANDROID_WINDOW_SIZE"); + FBNativeWindowType windowId = NULL; + EventInjector* injector; + int consolePort = 5554; + + if (env && sscanf(env, "%dx%d", &width, &height) == 2) { + winWidth = width; + winHeight = height; + } + +#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 + + // + // Inialize SDL window + // + if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_VIDEO)) { + fprintf(stderr,"SDL init failed: %s\n", SDL_GetError()); + return -1; + } + + SDL_Surface *surface = SDL_SetVideoMode(winWidth, winHeight, 32, SDL_SWSURFACE); + if (surface == NULL) { + fprintf(stderr,"Failed to set video mode: %s\n", SDL_GetError()); + return -1; + } + + SDL_SysWMinfo wminfo; + memset(&wminfo, 0, sizeof(wminfo)); + SDL_GetWMInfo(&wminfo); +#ifdef _WIN32 + windowId = wminfo.window; + WSADATA wsaData; + int rc = WSAStartup( MAKEWORD(2,2), &wsaData); + if (rc != 0) { + printf( "could not initialize Winsock\n" ); + } +#elif __linux__ + windowId = wminfo.info.x11.window; +#elif __APPLE__ + windowId = wminfo.nsWindowPtr; +#endif + + printf("initializing renderer process\n"); + + // + // initialize OpenGL renderer to render in our window + // + bool inited = initOpenGLRenderer(winWidth, winHeight, portNum); + if (!inited) { + return -1; + } + printf("renderer process started\n"); + + float zRot = 0.0f; + inited = createOpenGLSubwindow(windowId, 0, 0, + winWidth, winHeight, zRot); + if (!inited) { + printf("failed to create OpenGL subwindow\n"); + stopOpenGLRenderer(); + return -1; + } + int subwinWidth = winWidth; + int subwinHeight = winHeight; + + injector = new EventInjector(consolePort); + + // Just wait until the window is closed + SDL_Event ev; + + for (;;) { + injector->wait(1000/15); + injector->poll(); + + while (SDL_PollEvent(&ev)) { + switch (ev.type) { + case SDL_MOUSEBUTTONDOWN: + if (!mouseDown) { + injector->sendMouseDown(ev.button.x, ev.button.y); + mouseDown = 1; + } + break; + case SDL_MOUSEBUTTONUP: + if (mouseDown) { + injector->sendMouseUp(ev.button.x,ev.button.y); + mouseDown = 0; + } + break; + case SDL_MOUSEMOTION: + if (mouseDown) + injector->sendMouseMotion(ev.button.x,ev.button.y); + break; + + case SDL_KEYDOWN: +#ifdef __APPLE__ + /* special code to deal with Command-Q properly */ + if (ev.key.keysym.sym == SDLK_q && + ev.key.keysym.mod & KMOD_META) { + goto EXIT; + } +#endif + injector->sendKeyDown(convert_keysym(ev.key.keysym.sym)); + + if (ev.key.keysym.sym == SDLK_KP_MINUS) { + subwinWidth /= 2; + subwinHeight /= 2; + + bool stat = destroyOpenGLSubwindow(); + printf("destroy subwin returned %d\n", stat); + stat = createOpenGLSubwindow(windowId, + (winWidth - subwinWidth) / 2, + (winHeight - subwinHeight) / 2, + subwinWidth, subwinHeight, + zRot); + printf("create subwin returned %d\n", stat); + } + else if (ev.key.keysym.sym == SDLK_KP_PLUS) { + subwinWidth *= 2; + subwinHeight *= 2; + + bool stat = destroyOpenGLSubwindow(); + printf("destroy subwin returned %d\n", stat); + stat = createOpenGLSubwindow(windowId, + (winWidth - subwinWidth) / 2, + (winHeight - subwinHeight) / 2, + subwinWidth, subwinHeight, + zRot); + printf("create subwin returned %d\n", stat); + } + else if (ev.key.keysym.sym == SDLK_KP_MULTIPLY) { + zRot += 10.0f; + setOpenGLDisplayRotation(zRot); + } + else if (ev.key.keysym.sym == SDLK_KP_ENTER) { + repaintOpenGLDisplay(); + } + break; + case SDL_KEYUP: + injector->sendKeyUp(convert_keysym(ev.key.keysym.sym)); + break; + case SDL_QUIT: + goto EXIT; + } + } + } +EXIT: + // + // stop the renderer + // + printf("stopping the renderer process\n"); + stopOpenGLRenderer(); + + return 0; +} + +static int convert_keysym(int sym) +{ +#define EE(x,y) SDLK_##x, EventInjector::KEY_##y, + static const int keymap[] = { + EE(LEFT,LEFT) + EE(RIGHT,RIGHT) + EE(DOWN,DOWN) + EE(UP,UP) + EE(RETURN,ENTER) + EE(F1,SOFT1) + EE(ESCAPE,BACK) + EE(HOME,HOME) + -1 + }; + int nn; + for (nn = 0; keymap[nn] >= 0; nn += 2) { + if (keymap[nn] == sym) + return keymap[nn+1]; + } + return sym; +} diff --git a/emulator/opengl/tests/event_injector/Android.mk b/emulator/opengl/tests/event_injector/Android.mk new file mode 100644 index 0000000..26eb476 --- /dev/null +++ b/emulator/opengl/tests/event_injector/Android.mk @@ -0,0 +1,13 @@ +LOCAL_PATH := $(call my-dir) + +$(call emugl-begin-host-static-library,event_injector) + +LOCAL_SRC_FILES := \ + EventInjector.cpp \ + sockets.c \ + emulator-console.c \ + iolooper-select.c + +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) + +$(call emugl-end-module) diff --git a/emulator/opengl/tests/event_injector/EventInjector.cpp b/emulator/opengl/tests/event_injector/EventInjector.cpp new file mode 100644 index 0000000..6dade6e --- /dev/null +++ b/emulator/opengl/tests/event_injector/EventInjector.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 "EventInjector.h" +#include "emulator-console.h" + +#define PRIVATE EventInjectorPrivate + +class PRIVATE +{ +public: + IoLooper* mLooper; + EmulatorConsole* mConsole; + + EventInjectorPrivate(int port) { + mLooper = iolooper_new(); + mConsole = emulatorConsole_new(port, mLooper); + } +}; + +EventInjector::EventInjector(int consolePort) +{ + mPrivate = new PRIVATE(consolePort); +} + +EventInjector::~EventInjector() +{ + delete mPrivate; +} + +void EventInjector::wait(int timeout_ms) +{ + iolooper_wait(mPrivate->mLooper, timeout_ms); +} + +void EventInjector::poll(void) +{ + emulatorConsole_poll(mPrivate->mConsole); +} + +void EventInjector::sendMouseDown( int x, int y ) +{ + emulatorConsole_sendMouseDown(mPrivate->mConsole, x, y); +} + +void EventInjector::sendMouseUp( int x, int y ) +{ + emulatorConsole_sendMouseUp(mPrivate->mConsole, x, y); +} + +void EventInjector::sendMouseMotion( int x, int y ) +{ + emulatorConsole_sendMouseMotion(mPrivate->mConsole, x, y); +} + +void EventInjector::sendKeyDown( int keycode ) +{ + emulatorConsole_sendKey(mPrivate->mConsole, keycode, 1); +} + +void EventInjector::sendKeyUp( int keycode ) +{ + emulatorConsole_sendKey(mPrivate->mConsole, keycode, 0); +} diff --git a/emulator/opengl/tests/event_injector/EventInjector.h b/emulator/opengl/tests/event_injector/EventInjector.h new file mode 100644 index 0000000..a8fded7 --- /dev/null +++ b/emulator/opengl/tests/event_injector/EventInjector.h @@ -0,0 +1,59 @@ +/* +* 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. +*/ +/* Event redirector is used to inject user events from a GL window + * into the emulated program. + */ +#ifndef EVENT_INJECTOR_H +#define EVENT_INJECTOR_H + +class EventInjectorPrivate; + +class EventInjector +{ +public: + EventInjector(int consolePort); + virtual ~EventInjector(); + + void wait( int timeout_ms ); + void poll( void ); + + void sendMouseDown( int x, int y ); + void sendMouseUp( int x, int y ); + void sendMouseMotion( int x, int y ); + void sendKeyDown( int keycode ); + void sendKeyUp( int keycode ); + + /* Keycode values expected by the Linux kernel, and the emulator */ + enum { + KEY_BACK = 158, + KEY_HOME = 102, + KEY_SOFT1 = 229, + KEY_LEFT = 105, + KEY_UP = 103, + KEY_DOWN = 108, + KEY_RIGHT = 106, + KEY_VOLUMEUP = 115, + KEY_VOLUMEDOWN = 114, + KEY_SEND = 231, + KEY_END = 107, + KEY_ENTER = 28, + }; + +private: + EventInjectorPrivate* mPrivate; +}; + +#endif /* EVENT_INJECTOR_H */ diff --git a/emulator/opengl/tests/event_injector/emulator-console.c b/emulator/opengl/tests/event_injector/emulator-console.c new file mode 100644 index 0000000..a8c49b2 --- /dev/null +++ b/emulator/opengl/tests/event_injector/emulator-console.c @@ -0,0 +1,345 @@ +/* +* 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 "emulator-console.h" +#include "sockets.h" +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#define DEBUG 0 +#if DEBUG >= 1 +# define D(...) printf(__VA_ARGS__), printf("\n") +#else +# define D(...) ((void)0) +#endif +#if DEBUG >= 2 +# define DD(...) printf(__VA_ARGS__), printf("\n") +#else +# define DD(...) ((void)0) +#endif + +#define ANEW0(p) (p) = calloc(sizeof(*(p)), 1) + +enum { + STATE_CONNECTING = 0, + STATE_CONNECTED, + STATE_WAITING, + STATE_ERROR = 2 +}; + +typedef struct Msg { + const char* data; // pointer to data + int size; // size of data + int sent; // already sent (so sent..size remain in buffer). + struct Msg* next; // next message in queue. +} Msg; + +static Msg* +msg_alloc( const char* data, int datalen ) +{ + Msg* msg; + + msg = malloc(sizeof(*msg) + datalen); + msg->data = (const char*)(msg + 1); + msg->size = datalen; + msg->sent = 0; + memcpy((char*)msg->data, data, datalen); + msg->next = NULL; + + return msg; +} + +static void +msg_free( Msg* msg ) +{ + free(msg); +} + +struct EmulatorConsole { + int fd; + IoLooper* looper; + int state; + Msg* out_msg; + SockAddress address; + int64_t waitUntil; +}; + +/* Read as much from the input as possible, ignoring it. + */ +static int +emulatorConsole_eatInput( EmulatorConsole* con ) +{ + for (;;) { + char temp[64]; + int ret = socket_recv(con->fd, temp, sizeof temp); + if (ret < 0) { + if (errno == EAGAIN || errno == EWOULDBLOCK) { + return 0; + } + return -1; + } + if (ret == 0) { + return -1; + } + DD("Console received: '%.*s'", ret, temp); + } +} + +static int +emulatorConsole_sendOutput( EmulatorConsole* con ) +{ + if (con->state != STATE_CONNECTED) { + errno = EINVAL; + return -1; + } + + while (con->out_msg != NULL) { + Msg* msg = con->out_msg; + int ret; + + ret = socket_send(con->fd, + msg->data + msg->sent, + msg->size - msg->sent); + if (ret > 0) { + DD("Console sent: '%.*s'", ret, msg->data + msg->sent); + + msg->sent += ret; + if (msg->sent == msg->size) { + con->out_msg = msg->next; + msg_free(msg); + } + continue; + } + if (ret < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) { + return 0; + } + con->state = STATE_ERROR; + D("Console error when sending: %s", strerror(errno)); + return -1; + } + iolooper_del_write(con->looper, con->fd); + return 0; +} + +static void +emulatorConsole_completeConnect(EmulatorConsole* con) +{ + D("Console connected!"); + iolooper_add_read(con->looper, con->fd); + iolooper_del_write(con->looper, con->fd); + con->state = STATE_CONNECTED; + if (con->out_msg != NULL) { + iolooper_add_write(con->looper, con->fd); + emulatorConsole_sendOutput(con); + } +} + +static void +emulatorConsole_retry(EmulatorConsole* con) +{ + /* Not possible yet, wait one second */ + D("Could not connect to emulator, waiting 1 second: %s", errno_str); + con->state = STATE_WAITING; + con->waitUntil = iolooper_now() + 5000; +} + +static void +emulatorConsole_connect(EmulatorConsole* con) +{ + D("Trying to connect!"); + if (con->fd < 0) { + con->fd = socket_create_inet( SOCKET_STREAM ); + if (con->fd < 0) { + D("ERROR: Could not create socket: %s", errno_str); + con->state = STATE_ERROR; + return; + } + socket_set_nonblock(con->fd); + } + con->state = STATE_CONNECTING; + if (socket_connect(con->fd, &con->address) < 0) { + if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINPROGRESS) { + iolooper_add_write(con->looper, con->fd); + } else { + emulatorConsole_retry(con); + } + return; + } + + emulatorConsole_completeConnect(con); +} + +static void +emulatorConsole_reset( EmulatorConsole* con ) +{ + D("Resetting console connection"); + while (con->out_msg) { + Msg* msg = con->out_msg; + con->out_msg = msg->next; + msg_free(msg); + } + iolooper_del_read(con->looper, con->fd); + iolooper_del_write(con->looper, con->fd); + socket_close(con->fd); + con->fd = -1; + emulatorConsole_connect(con); +} + +/* Create a new EmulatorConsole object to connect asynchronously to + * a given emulator port. Note that this should always succeeds since + * the connection is asynchronous. + */ +EmulatorConsole* +emulatorConsole_new(int port, IoLooper* looper) +{ + EmulatorConsole* con; + SockAddress addr; + + ANEW0(con); + con->looper = looper; + con->fd = -1; + sock_address_init_inet(&con->address, SOCK_ADDRESS_INET_LOOPBACK, port); + + emulatorConsole_connect(con); + return con; +} + +int +emulatorConsole_poll( EmulatorConsole* con ) +{ + int ret; + + if (con->state == STATE_WAITING) { + if (iolooper_now() >= con->waitUntil) + emulatorConsole_connect(con); + return 0; + } + + if (!iolooper_is_read(con->looper, con->fd) && + !iolooper_is_write(con->looper, con->fd)) + { + return 0; + } + +LOOP: + switch (con->state) { + case STATE_ERROR: + return -1; + + case STATE_CONNECTING: + // read socket error to determine success / error. + if (socket_get_error(con->fd) != 0) { + emulatorConsole_retry(con); + } else { + emulatorConsole_completeConnect(con); + } + return 0; + + case STATE_CONNECTED: + /* ignore input, if any */ + if (iolooper_is_read(con->looper, con->fd)) { + if (emulatorConsole_eatInput(con) < 0) { + goto SET_ERROR; + } + } + /* send outgoing data, if any */ + if (iolooper_is_write(con->looper, con->fd)) { + if (emulatorConsole_sendOutput(con) < 0) { + goto SET_ERROR; + } + } + return 0; + + default: + D("UNSUPPORTED STATE!"); + break; + } + +SET_ERROR: + D("Console ERROR!: %s\n", errno_str); + con->state = STATE_ERROR; + emulatorConsole_reset(con); + return -1; +} + +/* Send a message to the console asynchronously. Any answer will be + * ignored. */ +void +emulatorConsole_send( EmulatorConsole* con, const char* command ) +{ + int cmdlen = strlen(command); + Msg* msg; + Msg** plast; + + if (cmdlen == 0) + return; + + /* Append new message at end of outgoing list */ + msg = msg_alloc(command, cmdlen); + plast = &con->out_msg; + while (*plast) { + plast = &(*plast)->next; + } + *plast = msg; + if (con->out_msg == msg) { + iolooper_add_write(con->looper, con->fd); + } + emulatorConsole_sendOutput(con); +} + + +void +emulatorConsole_sendMouseDown( EmulatorConsole* con, int x, int y ) +{ + char temp[128]; + + D("sendMouseDown(%d,%d)", x, y); + snprintf(temp, sizeof temp, + "event send 3:0:%d 3:1:%d 1:330:1 0:0:0\r\n", + x, y); + emulatorConsole_send(con, temp); +} + +void +emulatorConsole_sendMouseMotion( EmulatorConsole* con, int x, int y ) +{ + /* Same as mouse down */ + emulatorConsole_sendMouseDown(con, x, y); +} + +void +emulatorConsole_sendMouseUp( EmulatorConsole* con, int x, int y ) +{ + char temp[128]; + + D("sendMouseUp(%d,%d)", x, y); + snprintf(temp, sizeof temp, + "event send 3:0:%d 3:1:%d 1:330:0 0:0:0\r\n", + x, y); + emulatorConsole_send(con, temp); +} + +#define EE(x,y) if (keycode == x) return y; + +void +emulatorConsole_sendKey( EmulatorConsole* con, int keycode, int down ) +{ + char temp[128]; + + snprintf(temp, sizeof temp, + "event send EV_KEY:%d:%d 0:0:0\r\n", keycode, down); + emulatorConsole_send(con, temp); +} diff --git a/emulator/opengl/tests/event_injector/emulator-console.h b/emulator/opengl/tests/event_injector/emulator-console.h new file mode 100644 index 0000000..19e9687 --- /dev/null +++ b/emulator/opengl/tests/event_injector/emulator-console.h @@ -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. +*/ +#ifndef ANDROID_EMULATOR_CONSOLE_H +#define ANDROID_EMULATOR_CONSOLE_H + +#include "iolooper.h" +#include "sockets.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct EmulatorConsole EmulatorConsole; + +/* Create a new EmulatorConsole object to connect asynchronously to + * a given emulator port. Note that this always succeeds since the + * connection is asynchronous. + */ +EmulatorConsole* emulatorConsole_new(int port, IoLooper* looper); + +/* Call this after an iolooper_poll() or iolooper_wait() to check + * the status of the console's socket and act upon it. + * + * Returns 0 on success, or -1 on error (which indicates disconnection!) + */ +int emulatorConsole_poll( EmulatorConsole* console ); + +/* Send a message to the console asynchronously. Any answer will be + * ignored. */ +void emulatorConsole_send( EmulatorConsole* console, const char* command ); + +void emulatorConsole_sendMouseDown( EmulatorConsole* con, int x, int y ); +void emulatorConsole_sendMouseMotion( EmulatorConsole* con, int x, int y ); +void emulatorConsole_sendMouseUp( EmulatorConsole* con, int x, int y ); + +void emulatorConsole_sendKey( EmulatorConsole* con, int keycode, int down ); + +#ifdef __cplusplus +} +#endif + +#endif /* ANDROID_EMULATOR_CONSOLE_H */ diff --git a/emulator/opengl/tests/event_injector/iolooper-select.c b/emulator/opengl/tests/event_injector/iolooper-select.c new file mode 100644 index 0000000..c5fc7c2 --- /dev/null +++ b/emulator/opengl/tests/event_injector/iolooper-select.c @@ -0,0 +1,274 @@ +/* +* 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 <errno.h> +#include <stdlib.h> +#include "iolooper.h" +#include "sockets.h" + +/* An implementation of iolooper.h based on Unix select() */ +#ifdef _WIN32 +# include <winsock2.h> +# include <time.h> +#else +# include <sys/types.h> +# include <sys/select.h> +# include <sys/time.h> +#endif + +struct IoLooper { + fd_set reads[1]; + fd_set writes[1]; + fd_set reads_result[1]; + fd_set writes_result[1]; + int max_fd; + int max_fd_valid; +}; + +IoLooper* +iolooper_new(void) +{ + IoLooper* iol = malloc(sizeof(*iol)); + iolooper_reset(iol); + return iol; +} + +void +iolooper_free( IoLooper* iol ) +{ + free(iol); +} + +void +iolooper_reset( IoLooper* iol ) +{ + FD_ZERO(iol->reads); + FD_ZERO(iol->writes); + iol->max_fd = -1; + iol->max_fd_valid = 1; +} + +static void +iolooper_add_fd( IoLooper* iol, int fd ) +{ + if (iol->max_fd_valid && fd > iol->max_fd) { + iol->max_fd = fd; + } +} + +static void +iolooper_del_fd( IoLooper* iol, int fd ) +{ + if (iol->max_fd_valid && fd == iol->max_fd) + iol->max_fd_valid = 0; +} + +void +iolooper_modify( IoLooper* iol, int fd, int oldflags, int newflags ) +{ + if (fd < 0) + return; + + int changed = oldflags ^ newflags; + + if ((changed & IOLOOPER_READ) != 0) { + if ((newflags & IOLOOPER_READ) != 0) + iolooper_add_read(iol, fd); + else + iolooper_del_read(iol, fd); + } + if ((changed & IOLOOPER_WRITE) != 0) { + if ((newflags & IOLOOPER_WRITE) != 0) + iolooper_add_write(iol, fd); + else + iolooper_del_write(iol, fd); + } +} + + +static int +iolooper_fd_count( IoLooper* iol ) +{ + int max_fd = iol->max_fd; + int fd; + + if (iol->max_fd_valid) + return max_fd + 1; + + /* recompute max fd */ + for (fd = 0; fd < FD_SETSIZE; fd++) { + if (!FD_ISSET(fd, iol->reads) && !FD_ISSET(fd, iol->writes)) + continue; + + max_fd = fd; + } + iol->max_fd = max_fd; + iol->max_fd_valid = 1; + + return max_fd + 1; +} + +void +iolooper_add_read( IoLooper* iol, int fd ) +{ + if (fd >= 0) { + iolooper_add_fd(iol, fd); + FD_SET(fd, iol->reads); + } +} + +void +iolooper_add_write( IoLooper* iol, int fd ) +{ + if (fd >= 0) { + iolooper_add_fd(iol, fd); + FD_SET(fd, iol->writes); + } +} + +void +iolooper_del_read( IoLooper* iol, int fd ) +{ + if (fd >= 0) { + iolooper_del_fd(iol, fd); + FD_CLR(fd, iol->reads); + } +} + +void +iolooper_del_write( IoLooper* iol, int fd ) +{ + if (fd >= 0) { + iolooper_del_fd(iol, fd); + FD_CLR(fd, iol->writes); + } +} + +int +iolooper_poll( IoLooper* iol ) +{ + int count = iolooper_fd_count(iol); + int ret; + fd_set errs; + + if (count == 0) + return 0; + + FD_ZERO(&errs); + + do { + struct timeval tv; + + tv.tv_sec = tv.tv_usec = 0; + + iol->reads_result[0] = iol->reads[0]; + iol->writes_result[0] = iol->writes[0]; + + ret = select( count, iol->reads_result, iol->writes_result, &errs, &tv); + } while (ret < 0 && errno == EINTR); + + return ret; +} + +int +iolooper_wait( IoLooper* iol, int64_t duration ) +{ + int count = iolooper_fd_count(iol); + int ret; + fd_set errs; + struct timeval tm0, *tm = NULL; + + if (count == 0) + return 0; + + if (duration < 0) + tm = NULL; + else { + tm = &tm0; + tm->tv_sec = duration / 1000; + tm->tv_usec = (duration - 1000*tm->tv_sec) * 1000; + } + + FD_ZERO(&errs); + + do { + iol->reads_result[0] = iol->reads[0]; + iol->writes_result[0] = iol->writes[0]; + + ret = select( count, iol->reads_result, iol->writes_result, &errs, tm); + if (ret == 0) { + // Indicates timeout + errno = ETIMEDOUT; + } + } while (ret < 0 && errno == EINTR); + + return ret; +} + + +int +iolooper_is_read( IoLooper* iol, int fd ) +{ + return FD_ISSET(fd, iol->reads_result); +} + +int +iolooper_is_write( IoLooper* iol, int fd ) +{ + return FD_ISSET(fd, iol->writes_result); +} + +int +iolooper_has_operations( IoLooper* iol ) +{ + return iolooper_fd_count(iol) > 0; +} + +int64_t +iolooper_now(void) +{ +#ifdef _WIN32 + FILETIME now; + int64_t now_100ns; + + GetSystemTimeAsFileTime(&now); + + /* Get the time as hundreds of nanosecond intervals since + 12:00 AM January 1t 1601 UTC. We don't really need + to compute the value relative to the Posix epoch */ + now_100ns = ((int64_t)now.dwHighDateTime << 32) | now.dwLowDateTime; + + /* 100 ns == 0.1 us == 0.0001 ms */ + return now_100ns / 10000LL; + +#else /* !_WIN32 */ + struct timeval time_now; + return gettimeofday(&time_now, NULL) ? -1 : (int64_t)time_now.tv_sec * 1000LL + + time_now.tv_usec / 1000; +#endif /* !_WIN32 */ +} + +int +iolooper_wait_absolute(IoLooper* iol, int64_t deadline) +{ + int64_t timeout = deadline - iolooper_now(); + + /* If the deadline has passed, set the timeout to 0, this allows us + * to poll the file descriptor nonetheless */ + if (timeout < 0) + timeout = 0; + + return iolooper_wait(iol, timeout); +} diff --git a/emulator/opengl/tests/event_injector/iolooper.h b/emulator/opengl/tests/event_injector/iolooper.h new file mode 100644 index 0000000..4aa3db7 --- /dev/null +++ b/emulator/opengl/tests/event_injector/iolooper.h @@ -0,0 +1,91 @@ +/* +* 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 IOLOOPER_H +#define IOLOOPER_H + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* An IOLooper is an abstraction for select() */ + +typedef struct IoLooper IoLooper; + +IoLooper* iolooper_new(void); +void iolooper_free( IoLooper* iol ); +void iolooper_reset( IoLooper* iol ); + +void iolooper_add_read( IoLooper* iol, int fd ); +void iolooper_add_write( IoLooper* iol, int fd ); +void iolooper_del_read( IoLooper* iol, int fd ); +void iolooper_del_write( IoLooper* iol, int fd ); + +enum { + IOLOOPER_READ = (1<<0), + IOLOOPER_WRITE = (1<<1), +}; +void iolooper_modify( IoLooper* iol, int fd, int oldflags, int newflags); + +int iolooper_poll( IoLooper* iol ); +/* Wrapper around select() + * Return: + * > 0 in case an I/O has occurred, or < 0 on error, or 0 on timeout with + * errno set to ETIMEDOUT. + */ +int iolooper_wait( IoLooper* iol, int64_t duration ); + +int iolooper_is_read( IoLooper* iol, int fd ); +int iolooper_is_write( IoLooper* iol, int fd ); +/* Returns 1 if this IoLooper has one or more file descriptor to interact with */ +int iolooper_has_operations( IoLooper* iol ); +/* Gets current time in milliseconds. + * Return: + * Number of milliseconds corresponded to the current time on success, or -1 + * on failure. + */ +int64_t iolooper_now(void); +/* Waits for an I/O to occur before specific absolute time. + * This routine should be used (instead of iolooper_wait) in cases when multiple + * sequential I/O should be completed within given time interval. For instance, + * consider the scenario, when "server" does two sequential writes, and "client" + * now has to read data transferred with these two distinct writes. It might be + * wasteful to do two reads, each with the same (large) timeout. Instead, it + * would be better to assign a deadline for both reads before the first read, + * and call iolooper_wait_absoulte with the same deadline value: + * int64_t deadline = iolooper_now() + TIMEOUT; + * if (iolooper_wait_absoulte(iol, deadline)) { + * // Process first buffer. + * (iolooper_wait_absoulte(iol, deadline)) { + * // Process second read + * } + * } + * Param: + * iol IoLooper instance for an I/O. + * deadline Deadline (absoulte time in milliseconds) before which an I/O should + * occur. + * Return: + * Number of I/O descriptors set in iol, if an I/O has occurred, 0 if no I/O + * occurred before the deadline, or -1 on error. + */ +int iolooper_wait_absolute(IoLooper* iol, int64_t deadline); + +#ifdef __cplusplus +} +#endif + +#endif /* IOLOOPER_H */ diff --git a/emulator/opengl/tests/event_injector/sockets.c b/emulator/opengl/tests/event_injector/sockets.c new file mode 100644 index 0000000..a2cc334 --- /dev/null +++ b/emulator/opengl/tests/event_injector/sockets.c @@ -0,0 +1,1554 @@ +/* +* 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 __linux__ /* Recent versions of glibc only define EAI_NODATA, which is an + extension to the POSIX standard, if _GNU_SOURCE is defined. */ +# define _GNU_SOURCE 1 +#endif + +#include "sockets.h" +#include <fcntl.h> +#include <stddef.h> +#include <stdlib.h> +#include <string.h> +#include <limits.h> +//#include "android/utils/path.h" +//#include "android/utils/debug.h" +//#include "android/utils/misc.h" +//#include "android/utils/system.h" + +#define D(...) ((void)0) + +#ifdef _WIN32 +# define xxWIN32_LEAN_AND_MEAN +# define _WIN32_WINNT 0x501 +# include <windows.h> +# include <winsock2.h> +# include <ws2tcpip.h> +#else /* !_WIN32 */ +# include <sys/ioctl.h> +# include <sys/socket.h> +# include <netinet/in.h> +# include <netinet/tcp.h> +# include <netdb.h> +# if HAVE_UNIX_SOCKETS +# include <sys/un.h> +# ifndef UNIX_PATH_MAX +# define UNIX_PATH_MAX (sizeof(((struct sockaddr_un*)0)->sun_path)-1) +# endif +# endif +#endif /* !_WIN32 */ + +#define MIN(x,y) ({ typeof(x) _x = (x); typeof(y) _y = (y); _x <= _y ? _x : _y; }) +#define AFREE(p) free(p) +#define AARRAY_NEW(p,count) (p) = malloc(sizeof(*(p))*(count)) +#define AARRAY_NEW0(p,count) (p) = calloc(sizeof(*(p)),(count)) + +/* QSOCKET_CALL is used to deal with the fact that EINTR happens pretty + * easily in QEMU since we use SIGALRM to implement periodic timers + */ +#ifdef _WIN32 +# define QSOCKET_CALL(_ret,_cmd) \ + do { _ret = (_cmd); } while ( _ret < 0 && WSAGetLastError() == WSAEINTR ) +#else +# define QSOCKET_CALL(_ret,_cmd) \ + do { \ + errno = 0; \ + do { _ret = (_cmd); } while ( _ret < 0 && errno == EINTR ); \ + } while (0); +#endif + +#ifdef _WIN32 + +#include <errno.h> + +static int winsock_error; + +#define WINSOCK_ERRORS_LIST \ + EE(WSA_INVALID_HANDLE,EINVAL,"invalid handle") \ + EE(WSA_NOT_ENOUGH_MEMORY,ENOMEM,"not enough memory") \ + EE(WSA_INVALID_PARAMETER,EINVAL,"invalid parameter") \ + EE(WSAEINTR,EINTR,"interrupted function call") \ + EE(WSAEALREADY,EALREADY,"operation already in progress") \ + EE(WSAEBADF,EBADF,"bad file descriptor") \ + EE(WSAEACCES,EACCES,"permission denied") \ + EE(WSAEFAULT,EFAULT,"bad address") \ + EE(WSAEINVAL,EINVAL,"invalid argument") \ + EE(WSAEMFILE,EMFILE,"too many opened files") \ + EE(WSAEWOULDBLOCK,EWOULDBLOCK,"resource temporarily unavailable") \ + EE(WSAEINPROGRESS,EINPROGRESS,"operation now in progress") \ + EE(WSAEALREADY,EAGAIN,"operation already in progress") \ + EE(WSAENOTSOCK,EBADF,"socket operation not on socket") \ + EE(WSAEDESTADDRREQ,EDESTADDRREQ,"destination address required") \ + EE(WSAEMSGSIZE,EMSGSIZE,"message too long") \ + EE(WSAEPROTOTYPE,EPROTOTYPE,"wrong protocol type for socket") \ + EE(WSAENOPROTOOPT,ENOPROTOOPT,"bad protocol option") \ + EE(WSAEADDRINUSE,EADDRINUSE,"address already in use") \ + EE(WSAEADDRNOTAVAIL,EADDRNOTAVAIL,"cannot assign requested address") \ + EE(WSAENETDOWN,ENETDOWN,"network is down") \ + EE(WSAENETUNREACH,ENETUNREACH,"network unreachable") \ + EE(WSAENETRESET,ENETRESET,"network dropped connection on reset") \ + EE(WSAECONNABORTED,ECONNABORTED,"software caused connection abort") \ + EE(WSAECONNRESET,ECONNRESET,"connection reset by peer") \ + EE(WSAENOBUFS,ENOBUFS,"no buffer space available") \ + EE(WSAEISCONN,EISCONN,"socket is already connected") \ + EE(WSAENOTCONN,ENOTCONN,"socket is not connected") \ + EE(WSAESHUTDOWN,ESHUTDOWN,"cannot send after socket shutdown") \ + EE(WSAETOOMANYREFS,ETOOMANYREFS,"too many references") \ + EE(WSAETIMEDOUT,ETIMEDOUT,"connection timed out") \ + EE(WSAECONNREFUSED,ECONNREFUSED,"connection refused") \ + EE(WSAELOOP,ELOOP,"cannot translate name") \ + EE(WSAENAMETOOLONG,ENAMETOOLONG,"name too long") \ + EE(WSAEHOSTDOWN,EHOSTDOWN,"host is down") \ + EE(WSAEHOSTUNREACH,EHOSTUNREACH,"no route to host") \ + +typedef struct { + int winsock; + int unix; + const char* string; +} WinsockError; + +static const WinsockError _winsock_errors[] = { +#define EE(w,u,s) { w, u, s }, + WINSOCK_ERRORS_LIST +#undef EE + { -1, -1, NULL } +}; + +/* this function reads the latest winsock error code and updates + * errno to a matching value. It also returns the new value of + * errno. + */ +static int +_fix_errno( void ) +{ + const WinsockError* werr = _winsock_errors; + int unix = EINVAL; /* generic error code */ + + winsock_error = WSAGetLastError(); + + for ( ; werr->string != NULL; werr++ ) { + if (werr->winsock == winsock_error) { + unix = werr->unix; + break; + } + } + errno = unix; + return -1; +} + +static int +_set_errno( int code ) +{ + winsock_error = -1; + errno = code; + return -1; +} + +/* this function returns a string describing the latest Winsock error */ +const char* +_errno_str(void) +{ + const WinsockError* werr = _winsock_errors; + const char* result = NULL; + + for ( ; werr->string; werr++ ) { + if (werr->winsock == winsock_error) { + result = werr->string; + break; + } + } + + if (result == NULL) { + result = "Unknown socket error"; + } + return result; +} +#else +static int +_fix_errno( void ) +{ + return -1; +} + +static int +_set_errno( int code ) +{ + errno = code; + return -1; +} +#endif + +/* socket types */ + +static int +socket_family_to_bsd( SocketFamily family ) +{ + switch (family) { + case SOCKET_INET: return AF_INET; + case SOCKET_IN6: return AF_INET6; +#if HAVE_UNIX_SOCKETS + case SOCKET_UNIX: return AF_LOCAL; +#endif + default: return -1; + } +} + +static int +socket_type_to_bsd( SocketType type ) +{ + switch (type) { + case SOCKET_DGRAM: return SOCK_DGRAM; + case SOCKET_STREAM: return SOCK_STREAM; + default: return 0; + } +} + +static SocketType +socket_type_from_bsd( int type ) +{ + switch (type) { + case SOCK_DGRAM: return SOCKET_DGRAM; + case SOCK_STREAM: return SOCKET_STREAM; + default: return (SocketType) SOCKET_UNSPEC; + } +} + +#if 0 +static int +socket_type_check( SocketType type ) +{ + return (type == SOCKET_DGRAM || type == SOCKET_STREAM); +} +#endif + +typedef union { + struct sockaddr sa[1]; + struct sockaddr_in in[1]; +#if HAVE_IN6_SOCKETS + struct sockaddr_in6 in6[1]; +#endif +#if HAVE_UNIX_SOCKETS + struct sockaddr_un un[1]; +#endif +} sockaddr_storage; + +/* socket addresses */ + +void +sock_address_init_inet( SockAddress* a, uint32_t ip, uint16_t port ) +{ + a->family = SOCKET_INET; + a->u.inet.port = port; + a->u.inet.address = ip; +} + +void +sock_address_init_in6 ( SockAddress* a, const uint8_t* ip6[16], uint16_t port ) +{ + a->family = SOCKET_IN6; + a->u.in6.port = port; + memcpy( a->u.in6.address, ip6, sizeof(a->u.in6.address) ); +} + +void +sock_address_init_unix( SockAddress* a, const char* path ) +{ + a->family = SOCKET_UNIX; + a->u._unix.path = strdup(path ? path : ""); + a->u._unix.owner = 1; +} + +void sock_address_done( SockAddress* a ) +{ + if (a->family == SOCKET_UNIX && a->u._unix.owner) { + a->u._unix.owner = 0; + free((char*)a->u._unix.path); + } +} + +static char* +format_char( char* buf, char* end, int c ) +{ + if (buf < end) { + if (buf+1 == end) { + *buf++ = 0; + } else { + *buf++ = (char) c; + *buf = 0; + } + } + return buf; +} + +static char* +format_str( char* buf, char* end, const char* str ) +{ + int len = strlen(str); + int avail = end - buf; + + if (len > avail) + len = avail; + + memcpy( buf, str, len ); + buf += len; + + if (buf == end) + buf[-1] = 0; + else + buf[0] = 0; + + return buf; +} + +static char* +format_unsigned( char* buf, char* end, unsigned val ) +{ + char temp[16]; + int nn; + + for ( nn = 0; val != 0; nn++ ) { + int rem = val % 10; + temp[nn] = '0'+rem; + val /= 10; + } + + if (nn == 0) + temp[nn++] = '0'; + + while (nn > 0) + buf = format_char(buf, end, temp[--nn]); + + return buf; +} + +static char* +format_hex( char* buf, char* end, unsigned val, int ndigits ) +{ + int shift = 4*ndigits; + static const char hex[16] = "0123456789abcdef"; + + while (shift >= 0) { + buf = format_char(buf, end, hex[(val >> shift) & 15]); + shift -= 4; + } + return buf; +} + +static char* +format_ip4( char* buf, char* end, uint32_t ip ) +{ + buf = format_unsigned( buf, end, (unsigned)(ip >> 24) ); + buf = format_char( buf, end, '.'); + buf = format_unsigned( buf, end, (unsigned)((ip >> 16) & 255)); + buf = format_char( buf, end, '.'); + buf = format_unsigned( buf, end, (unsigned)((ip >> 8) & 255)); + buf = format_char( buf, end, '.'); + buf = format_unsigned( buf, end, (unsigned)(ip & 255)); + return buf; +} + +static char* +format_ip6( char* buf, char* end, const uint8_t* ip6 ) +{ + int nn; + for (nn = 0; nn < 8; nn++) { + int val = (ip6[0] << 16) | ip6[1]; + ip6 += 2; + if (nn > 0) + buf = format_char(buf, end, ':'); + if (val == 0) + continue; + buf = format_hex(buf, end, val, 4); + } + return buf; +} + +const char* +sock_address_to_string( const SockAddress* a ) +{ + static char buf0[PATH_MAX]; + char *buf = buf0, *end = buf + sizeof(buf0); + + switch (a->family) { + case SOCKET_INET: + buf = format_ip4( buf, end, a->u.inet.address ); + buf = format_char( buf, end, ':' ); + buf = format_unsigned( buf, end, (unsigned) a->u.inet.port ); + break; + + case SOCKET_IN6: + buf = format_ip6( buf, end, a->u.in6.address ); + buf = format_char( buf, end, ':' ); + buf = format_unsigned( buf, end, (unsigned) a->u.in6.port ); + break; + + case SOCKET_UNIX: + buf = format_str( buf, end, a->u._unix.path ); + break; + + default: + return NULL; + } + + return buf0; +} + +int +sock_address_equal( const SockAddress* a, const SockAddress* b ) +{ + if (a->family != b->family) + return 0; + + switch (a->family) { + case SOCKET_INET: + return (a->u.inet.address == b->u.inet.address && + a->u.inet.port == b->u.inet.port); + + case SOCKET_IN6: + return (!memcmp(a->u.in6.address, b->u.in6.address, 16) && + a->u.in6.port == b->u.in6.port); + + case SOCKET_UNIX: + return (!strcmp(a->u._unix.path, b->u._unix.path)); + + default: + return 0; + } +} + +int +sock_address_get_port( const SockAddress* a ) +{ + switch (a->family) { + case SOCKET_INET: + return a->u.inet.port; + case SOCKET_IN6: + return a->u.in6.port; + default: + return -1; + } +} + +void +sock_address_set_port( SockAddress* a, uint16_t port ) +{ + switch (a->family) { + case SOCKET_INET: + a->u.inet.port = port; + break; + case SOCKET_IN6: + a->u.in6.port = port; + break; + default: + ; + } +} + +const char* +sock_address_get_path( const SockAddress* a ) +{ + if (a->family == SOCKET_UNIX) + return a->u._unix.path; + else + return NULL; +} + +int +sock_address_get_ip( const SockAddress* a ) +{ + if (a->family == SOCKET_INET) + return a->u.inet.address; + + return -1; +} + +#if 0 +char* +bufprint_sock_address( char* p, char* end, const SockAddress* a ) +{ + switch (a->family) { + case SOCKET_INET: + { + uint32_t ip = a->u.inet.address; + + return bufprint( p, end, "%d.%d.%d.%d:%d", + (ip >> 24) & 255, (ip >> 16) & 255, + (ip >> 8) & 255, ip & 255, + a->u.inet.port ); + } + case SOCKET_IN6: + { + int nn = 0; + const char* column = ""; + const uint8_t* tab = a->u.in6.address; + for (nn = 0; nn < 16; nn += 2) { + p = bufprint(p, end, "%s%04x", column, (tab[n] << 8) | tab[n+1]); + column = ":"; + } + return bufprint(p, end, ":%d", a->u.in6.port); + } + case SOCKET_UNIX: + { + return bufprint(p, end, "%s", a->u._unix.path); + } + default: + return p; + } +} +#endif + +static int +sock_address_to_bsd( const SockAddress* a, sockaddr_storage* paddress, socklen_t *psize ) +{ + switch (a->family) { + case SOCKET_INET: + { + struct sockaddr_in* dst = paddress->in; + + *psize = sizeof(*dst); + + memset( paddress, 0, *psize ); + + dst->sin_family = AF_INET; + dst->sin_port = htons(a->u.inet.port); + dst->sin_addr.s_addr = htonl(a->u.inet.address); + } + break; + +#if HAVE_IN6_SOCKETS + case SOCKET_IN6: + { + struct sockaddr_in6* dst = paddress->in6; + + *psize = sizeof(*dst); + + memset( paddress, 0, *psize ); + + dst->sin6_family = AF_INET6; + dst->sin6_port = htons(a->u.in6.port); + memcpy( dst->sin6_addr.s6_addr, a->u.in6.address, 16 ); + } + break; +#endif /* HAVE_IN6_SOCKETS */ + +#if HAVE_UNIX_SOCKETS + case SOCKET_UNIX: + { + int slen = strlen(a->u._unix.path); + struct sockaddr_un* dst = paddress->un; + + if (slen >= (int)UNIX_PATH_MAX) + return -1; + + memset( dst, 0, sizeof(*dst) ); + + dst->sun_family = AF_LOCAL; + memcpy( dst->sun_path, a->u._unix.path, slen ); + dst->sun_path[slen] = 0; + + *psize = (char*)&dst->sun_path[slen+1] - (char*)dst; + } + break; +#endif /* HAVE_UNIX_SOCKETS */ + + default: + return _set_errno(EINVAL); + } + + return 0; +} + +static int +sock_address_from_bsd( SockAddress* a, const void* from, size_t fromlen ) +{ + switch (((struct sockaddr *)from)->sa_family) { + case AF_INET: + { + const struct sockaddr_in* src = from; + + if (fromlen < sizeof(*src)) + return _set_errno(EINVAL); + + a->family = SOCKET_INET; + a->u.inet.port = ntohs(src->sin_port); + a->u.inet.address = ntohl(src->sin_addr.s_addr); + } + break; + +#ifdef HAVE_IN6_SOCKETS + case AF_INET6: + { + const struct sockaddr_in6* src = from; + + if (fromlen < sizeof(*src)) + return _set_errno(EINVAL); + + a->family = SOCKET_IN6; + a->u.in6.port = ntohs(src->sin6_port); + memcpy(a->u.in6.address, src->sin6_addr.s6_addr, 16); + } + break; +#endif + +#ifdef HAVE_UNIX_SOCKETS + case AF_LOCAL: + { + const struct sockaddr_un* src = from; + char* end; + + if (fromlen < sizeof(*src)) + return _set_errno(EINVAL); + + /* check that the path is zero-terminated */ + end = memchr(src->sun_path, 0, UNIX_PATH_MAX); + if (end == NULL) + return _set_errno(EINVAL); + + a->family = SOCKET_UNIX; + a->u._unix.owner = 1; + a->u._unix.path = strdup(src->sun_path); + } + break; +#endif + + default: + return _set_errno(EINVAL); + } + return 0; +} + + +int +sock_address_init_resolve( SockAddress* a, const char* hostname, uint16_t port, int preferIn6 ) +{ + struct addrinfo hints[1]; + struct addrinfo* res; + int ret; + + memset(hints, 0, sizeof(hints)); + hints->ai_family = preferIn6 ? AF_INET6 : AF_UNSPEC; + + ret = getaddrinfo(hostname, NULL, hints, &res); + if (ret != 0) { + int err; + + switch (ret) { + case EAI_AGAIN: /* server is down */ + case EAI_FAIL: /* server is sick */ + err = EHOSTDOWN; + break; + +#ifdef EAI_NODATA + case EAI_NODATA: +#endif + case EAI_NONAME: + err = ENOENT; + break; + + case EAI_MEMORY: + err = ENOMEM; + break; + + default: + err = EINVAL; + } + return _set_errno(err); + } + + /* Parse the returned list of addresses. */ + { + struct addrinfo* res_ipv4 = NULL; + struct addrinfo* res_ipv6 = NULL; + struct addrinfo* r; + + /* If preferIn6 is false, we stop on the first IPv4 address, + * otherwise, we stop on the first IPv6 one + */ + for (r = res; r != NULL; r = r->ai_next) { + if (r->ai_family == AF_INET && res_ipv4 == NULL) { + res_ipv4 = r; + if (!preferIn6) + break; + } + else if (r->ai_family == AF_INET6 && res_ipv6 == NULL) { + res_ipv6 = r; + if (preferIn6) + break; + } + } + + /* Select the best address in 'r', which will be NULL + * if there is no corresponding address. + */ + if (preferIn6) { + r = res_ipv6; + if (r == NULL) + r = res_ipv4; + } else { + r = res_ipv4; + if (r == NULL) + r = res_ipv6; + } + + if (r == NULL) { + ret = _set_errno(ENOENT); + goto Exit; + } + + /* Convert to a SockAddress */ + ret = sock_address_from_bsd( a, r->ai_addr, r->ai_addrlen ); + if (ret < 0) + goto Exit; + } + + /* need to set the port */ + switch (a->family) { + case SOCKET_INET: a->u.inet.port = port; break; + case SOCKET_IN6: a->u.in6.port = port; break; + default: ; + } + +Exit: + freeaddrinfo(res); + return ret; +} + +/* The Winsock headers for mingw lack some definitions */ +#ifndef AI_ADDRCONFIG +# define AI_ADDRCONFIG 0 +#endif + +SockAddress** +sock_address_list_create( const char* hostname, + const char* port, + unsigned flags ) +{ + SockAddress** list = NULL; + SockAddress* addr; + int nn, count, ret; + struct addrinfo ai, *res, *e; + + memset(&ai, 0, sizeof(ai)); + ai.ai_flags |= AI_ADDRCONFIG; + ai.ai_family = PF_UNSPEC; + + if (flags & SOCKET_LIST_FORCE_INET) + ai.ai_family = PF_INET; + else if (flags & SOCKET_LIST_FORCE_IN6) + ai.ai_family = PF_INET6; + + if (flags & SOCKET_LIST_PASSIVE) + ai.ai_flags |= AI_PASSIVE; + else + ai.ai_flags |= AI_CANONNAME; + + if (flags & SOCKET_LIST_DGRAM) + ai.ai_socktype = SOCK_DGRAM; + + while (1) { + struct addrinfo hints = ai; + + ret = getaddrinfo(hostname, port, &hints, &res); + if (ret == 0) + break; + + switch (ret) { +#ifdef EAI_ADDRFAMILY + case EAI_ADDRFAMILY: +#endif + case EAI_NODATA: + _set_errno(ENOENT); + break; + case EAI_FAMILY: + _set_errno(EAFNOSUPPORT); + break; + case EAI_AGAIN: + _set_errno(EAGAIN); + break; +#ifdef EAI_SYSTEM + case EAI_SYSTEM: + if (errno == EINTR) + continue; + break; +#endif + default: + _set_errno(EINVAL); + } + return NULL; + } + + /* allocate result list */ + for (count = 0, e = res; e != NULL; e = e->ai_next) + count += 1; + + AARRAY_NEW(list, count+1); + AARRAY_NEW(addr, count); + + for (nn = 0, e = res; e != NULL; e = e->ai_next) { + + ret = sock_address_from_bsd(addr, e->ai_addr, e->ai_addrlen); + if (ret < 0) + continue; + + list[nn++] = addr++; + } + list[nn] = NULL; + freeaddrinfo(res); + return list; +} + +SockAddress** +sock_address_list_create2(const char* host_and_port, unsigned flags ) +{ + char host_name[512]; + const char* actual_host_name = "localhost"; + // Parse host and port name. + const char* port_name = strchr(host_and_port, ':'); + if (port_name != NULL) { + int to_copy = MIN((int)sizeof(host_name)-1, port_name - host_and_port); + if (to_copy != 0) { + memcpy(host_name, host_and_port, to_copy); + host_name[to_copy] = '\0'; + actual_host_name = host_name; + port_name++; + } else { + return NULL; + } + } else { + port_name = host_and_port; + } + // Make sure that port_name is not empty. + if (port_name[0] == '\0') { + return NULL; + } + return sock_address_list_create(actual_host_name, port_name, flags); +} + +void +sock_address_list_free( SockAddress** list ) +{ + int nn; + SockAddress* addr; + + if (list == NULL) + return; + + addr = list[0]; + for (nn = 0; list[nn] != NULL; nn++) { + sock_address_done(list[nn]); + list[nn] = NULL; + } + AFREE(addr); + AFREE(list); +} + +int +sock_address_get_numeric_info( SockAddress* a, + char* host, + size_t hostlen, + char* serv, + size_t servlen ) +{ + struct sockaddr* saddr; + socklen_t slen; + int ret; + + switch (a->family) { + case SOCKET_INET: + saddr = (struct sockaddr*) &a->u.inet.address; + slen = sizeof(a->u.inet.address); + break; + +#if HAVE_IN6_SOCKET + case SOCKET_IN6: + saddr = (struct sockaddr*) &a->u.in6.address; + slen = sizeof(a->u.in6.address); + break; +#endif + default: + return _set_errno(EINVAL); + } + + ret = getnameinfo( saddr, slen, host, hostlen, serv, servlen, + NI_NUMERICHOST | NI_NUMERICSERV ); + + switch (ret) { + case 0: + break; + case EAI_AGAIN: + ret = EAGAIN; + break; + default: + ret = EINVAL; + } + return ret; +} + +int +socket_create( SocketFamily family, SocketType type ) +{ + int ret; + int sfamily = socket_family_to_bsd(family); + int stype = socket_type_to_bsd(type); + + if (sfamily < 0 || stype < 0) { + return _set_errno(EINVAL); + } + + QSOCKET_CALL(ret, socket(sfamily, stype, 0)); + if (ret < 0) + return _fix_errno(); + + return ret; +} + + +int +socket_create_inet( SocketType type ) +{ + return socket_create( SOCKET_INET, type ); +} + +#if HAVE_IN6_SOCKETS +int +socket_create_in6 ( SocketType type ) +{ + return socket_create( SOCKET_IN6, type ); +} +#endif + +#if HAVE_UNIX_SOCKETS +int +socket_create_unix( SocketType type ) +{ + return socket_create( SOCKET_UNIX, type ); +} +#endif + +int socket_can_read(int fd) +{ +#ifdef _WIN32 + unsigned long opt; + + if (ioctlsocket(fd, FIONREAD, &opt) < 0) + return 0; + + return opt; +#else + int opt; + + if (ioctl(fd, FIONREAD, &opt) < 0) + return 0; + + return opt; +#endif +} + +#define SOCKET_CALL(cmd) \ + int ret; \ + QSOCKET_CALL(ret, (cmd)); \ + if (ret < 0) \ + return _fix_errno(); \ + return ret; \ + +int +socket_send(int fd, const void* buf, int buflen) +{ + SOCKET_CALL(send(fd, buf, buflen, 0)) +} + +int +socket_send_oob( int fd, const void* buf, int buflen ) +{ + SOCKET_CALL(send(fd, buf, buflen, MSG_OOB)); +} + +int +socket_sendto(int fd, const void* buf, int buflen, const SockAddress* to) +{ + sockaddr_storage sa; + socklen_t salen; + + if (sock_address_to_bsd(to, &sa, &salen) < 0) + return -1; + + SOCKET_CALL(sendto(fd, buf, buflen, 0, sa.sa, salen)); +} + +int +socket_recv(int fd, void* buf, int len) +{ + SOCKET_CALL(recv(fd, buf, len, 0)); +} + +int +socket_recvfrom(int fd, void* buf, int len, SockAddress* from) +{ + sockaddr_storage sa; + socklen_t salen = sizeof(sa); + int ret; + + QSOCKET_CALL(ret,recvfrom(fd,buf,len,0,sa.sa,&salen)); + if (ret < 0) + return _fix_errno(); + + if (sock_address_from_bsd(from, &sa, salen) < 0) + return -1; + + return ret; +} + +int +socket_connect( int fd, const SockAddress* address ) +{ + sockaddr_storage addr; + socklen_t addrlen; + + if (sock_address_to_bsd(address, &addr, &addrlen) < 0) + return -1; + + SOCKET_CALL(connect(fd,addr.sa,addrlen)); +} + +int +socket_bind( int fd, const SockAddress* address ) +{ + sockaddr_storage addr; + socklen_t addrlen; + + if (sock_address_to_bsd(address, &addr, &addrlen) < 0) + return -1; + + SOCKET_CALL(bind(fd, addr.sa, addrlen)); +} + +int +socket_get_address( int fd, SockAddress* address ) +{ + sockaddr_storage addr; + socklen_t addrlen = sizeof(addr); + int ret; + + QSOCKET_CALL(ret, getsockname(fd, addr.sa, &addrlen)); + if (ret < 0) + return _fix_errno(); + + return sock_address_from_bsd(address, &addr, addrlen); +} + +int +socket_get_peer_address( int fd, SockAddress* address ) +{ + sockaddr_storage addr; + socklen_t addrlen = sizeof(addr); + int ret; + + QSOCKET_CALL(ret, getpeername(fd, addr.sa, &addrlen)); + if (ret < 0) + return _fix_errno(); + + return sock_address_from_bsd(address, &addr, addrlen); +} + +int +socket_listen( int fd, int backlog ) +{ + SOCKET_CALL(listen(fd, backlog)); +} + +int +socket_accept( int fd, SockAddress* address ) +{ + sockaddr_storage addr; + socklen_t addrlen = sizeof(addr); + int ret; + + QSOCKET_CALL(ret, accept(fd, addr.sa, &addrlen)); + if (ret < 0) + return _fix_errno(); + + if (address) { + if (sock_address_from_bsd(address, &addr, addrlen) < 0) { + socket_close(ret); + return -1; + } + } + return ret; +} + +static int +socket_getoption(int fd, int domain, int option, int defaut) +{ + int ret; + while (1) { +#ifdef _WIN32 + DWORD opt = (DWORD)-1; +#else + int opt = -1; +#endif + socklen_t optlen = sizeof(opt); + ret = getsockopt(fd, domain, option, (char*)&opt, &optlen); + if (ret == 0) + return (int)opt; + if (errno != EINTR) + return defaut; + } +#undef OPT_CAST +} + + +SocketType socket_get_type(int fd) +{ + int so_type = socket_getoption(fd, SOL_SOCKET, SO_TYPE, -1); + return socket_type_from_bsd(so_type); +} + +int socket_set_nonblock(int fd) +{ +#ifdef _WIN32 + unsigned long opt = 1; + return ioctlsocket(fd, FIONBIO, &opt); +#else + int flags = fcntl(fd, F_GETFL); + return fcntl(fd, F_SETFL, flags | O_NONBLOCK); +#endif +} + +int socket_set_blocking(int fd) +{ +#ifdef _WIN32 + unsigned long opt = 0; + return ioctlsocket(fd, FIONBIO, &opt); +#else + int flags = fcntl(fd, F_GETFL); + return fcntl(fd, F_SETFL, flags & ~O_NONBLOCK); +#endif +} + +static int +socket_setoption(int fd, int domain, int option, int _flag) +{ +#ifdef _WIN32 + DWORD flag = (DWORD) _flag; +#else + int flag = _flag; +#endif + return setsockopt( fd, domain, option, (const char*)&flag, sizeof(flag) ); +} + +int socket_set_xreuseaddr(int fd) +{ +#ifdef _WIN32 + /* on Windows, SO_REUSEADDR is used to indicate that several programs can + * bind to the same port. this is completely different from the Unix + * semantics. instead of SO_EXCLUSIVEADDR to ensure that explicitely prevent + * this. + */ + return socket_setoption(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, 1); +#else + return socket_setoption(fd, SOL_SOCKET, SO_REUSEADDR, 1); +#endif +} + + +int socket_set_oobinline(int fd) +{ + return socket_setoption(fd, SOL_SOCKET, SO_OOBINLINE, 1); +} + + +int socket_set_nodelay(int fd) +{ + return socket_setoption(fd, IPPROTO_TCP, TCP_NODELAY, 1); +} + +int socket_set_ipv6only(int fd) +{ +/* IPV6_ONLY is only supported since Vista on Windows, + * and the Mingw headers lack its definition anyway. + */ +#if defined(_WIN32) && !defined(IPV6_V6ONLY) + return 0; +#else + return socket_setoption(fd, IPPROTO_IPV6, IPV6_V6ONLY, 1); +#endif +} + + +int socket_get_error(int fd) +{ + return socket_getoption(fd, SOL_SOCKET, SO_ERROR, -1); +} + +#ifdef _WIN32 +#include <stdlib.h> + +static void socket_cleanup(void) +{ + WSACleanup(); +} + +int socket_init(void) +{ + WSADATA Data; + int ret, err; + + ret = WSAStartup(MAKEWORD(2,2), &Data); + if (ret != 0) { + err = WSAGetLastError(); + return -1; + } + atexit(socket_cleanup); + return 0; +} + +#else /* !_WIN32 */ + +int socket_init(void) +{ + return 0; /* nothing to do on Unix */ +} + +#endif /* !_WIN32 */ + +#ifdef _WIN32 + +void +socket_close( int fd ) +{ + int old_errno = errno; + + shutdown( fd, SD_BOTH ); + /* we want to drain the socket before closing it */ + //qemu_set_fd_handler( fd, socket_close_handler, NULL, (void*)fd ); + closesocket(fd); + + errno = old_errno; +} + +#else /* !_WIN32 */ + +#include <unistd.h> + +void +socket_close( int fd ) +{ + int old_errno = errno; + + shutdown( fd, SHUT_RDWR ); + close( fd ); + + errno = old_errno; +} + +#endif /* !_WIN32 */ + + +static int +socket_bind_server( int s, const SockAddress* to, SocketType type ) +{ + socket_set_xreuseaddr(s); + + if (socket_bind(s, to) < 0) { + D("could not bind server socket address %s: %s", + sock_address_to_string(to), errno_str); + goto FAIL; + } + + if (type == SOCKET_STREAM) { + if (socket_listen(s, 4) < 0) { + D("could not listen server socket %s: %s", + sock_address_to_string(to), errno_str); + goto FAIL; + } + } + return s; + +FAIL: + socket_close(s); + return -1; +} + + +static int +socket_connect_client( int s, const SockAddress* to ) +{ + if (socket_connect(s, to) < 0) { + D( "could not connect client socket to %s: %s\n", + sock_address_to_string(to), errno_str ); + socket_close(s); + return -1; + } + + socket_set_nonblock( s ); + return s; +} + + +static int +socket_in_server( int address, int port, SocketType type ) +{ + SockAddress addr; + int s; + + sock_address_init_inet( &addr, address, port ); + s = socket_create_inet( type ); + if (s < 0) + return -1; + + return socket_bind_server( s, &addr, type ); +} + + +static int +socket_in_client( SockAddress* to, SocketType type ) +{ + int s; + + s = socket_create_inet( type ); + if (s < 0) return -1; + + return socket_connect_client( s, to ); +} + + +int +socket_loopback_server( int port, SocketType type ) +{ + return socket_in_server( SOCK_ADDRESS_INET_LOOPBACK, port, type ); +} + +int +socket_loopback_client( int port, SocketType type ) +{ + SockAddress addr; + + sock_address_init_inet( &addr, SOCK_ADDRESS_INET_LOOPBACK, port ); + return socket_in_client( &addr, type ); +} + + +int +socket_network_client( const char* host, int port, SocketType type ) +{ + SockAddress addr; + + if (sock_address_init_resolve( &addr, host, port, 0) < 0) + return -1; + + return socket_in_client( &addr, type ); +} + + +int +socket_anyaddr_server( int port, SocketType type ) +{ + return socket_in_server( SOCK_ADDRESS_INET_ANY, port, type ); +} + +int +socket_accept_any( int server_fd ) +{ + int fd; + + QSOCKET_CALL(fd, accept( server_fd, NULL, 0 )); + if (fd < 0) { + D( "could not accept client connection from fd %d: %s", + server_fd, errno_str ); + return -1; + } + + /* set to non-blocking */ + socket_set_nonblock( fd ); + return fd; +} + + +#if HAVE_UNIX_SOCKETS + +int +socket_unix_server( const char* name, SocketType type ) +{ + SockAddress addr; + int s, ret; + + s = socket_create_unix( type ); + if (s < 0) + return -1; + + sock_address_init_unix( &addr, name ); + + do { + ret = unlink( name ); + } while (ret < 0 && errno == EINTR); + + ret = socket_bind_server( s, &addr, type ); + + sock_address_done( &addr ); + return ret; +} + +int +socket_unix_client( const char* name, SocketType type ) +{ + SockAddress addr; + int s, ret; + + s = socket_create_unix(type); + if (s < 0) + return -1; + + sock_address_init_unix( &addr, name ); + + ret = socket_connect_client( s, &addr ); + + sock_address_done( &addr ); + return ret; +} + +#endif /* HAVE_UNIX_SOCKETS */ + + + +int +socket_pair(int *fd1, int *fd2) +{ +#ifndef _WIN32 + int fds[2]; + int ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fds); + + if (!ret) { + socket_set_nonblock(fds[0]); + socket_set_nonblock(fds[1]); + *fd1 = fds[0]; + *fd2 = fds[1]; + } + return ret; +#else /* _WIN32 */ + /* on Windows, select() only works with network sockets, which + * means we absolutely cannot use Win32 PIPEs to implement + * socket pairs with the current event loop implementation. + * We're going to do like Cygwin: create a random pair + * of localhost TCP sockets and connect them together + */ + int s0, s1, s2, port; + struct sockaddr_in sockin; + socklen_t len; + + /* first, create the 'server' socket. + * a port number of 0 means 'any port between 1024 and 5000. + * see Winsock bind() documentation for details */ + s0 = socket_loopback_server( 0, SOCK_STREAM ); + if (s0 < 0) + return -1; + + /* now connect a client socket to it, we first need to + * extract the server socket's port number */ + len = sizeof sockin; + if (getsockname(s0, (struct sockaddr*) &sockin, &len) < 0) { + closesocket (s0); + return -1; + } + + port = ntohs(sockin.sin_port); + s2 = socket_loopback_client( port, SOCK_STREAM ); + if (s2 < 0) { + closesocket(s0); + return -1; + } + + /* we need to accept the connection on the server socket + * this will create the second socket for the pair + */ + len = sizeof sockin; + s1 = accept(s0, (struct sockaddr*) &sockin, &len); + if (s1 == INVALID_SOCKET) { + closesocket (s0); + closesocket (s2); + return -1; + } + socket_set_nonblock(s1); + + /* close server socket */ + closesocket(s0); + *fd1 = s1; + *fd2 = s2; + return 0; +#endif /* _WIN32 */ +} + + + +int +socket_mcast_inet_add_membership( int s, uint32_t ip ) +{ + struct ip_mreq imr; + + imr.imr_multiaddr.s_addr = htonl(ip); + imr.imr_interface.s_addr = htonl(INADDR_ANY); + + if ( setsockopt( s, IPPROTO_IP, IP_ADD_MEMBERSHIP, + (const char *)&imr, + sizeof(struct ip_mreq)) < 0 ) + { + return _fix_errno(); + } + return 0; +} + +int +socket_mcast_inet_drop_membership( int s, uint32_t ip ) +{ + struct ip_mreq imr; + + imr.imr_multiaddr.s_addr = htonl(ip); + imr.imr_interface.s_addr = htonl(INADDR_ANY); + + if ( setsockopt( s, IPPROTO_IP, IP_DROP_MEMBERSHIP, + (const char *)&imr, + sizeof(struct ip_mreq)) < 0 ) + { + return _fix_errno(); + } + return 0; +} + +int +socket_mcast_inet_set_loop( int s, int enabled ) +{ + return socket_setoption( s, IPPROTO_IP, IP_MULTICAST_LOOP, !!enabled ); +} + +int +socket_mcast_inet_set_ttl( int s, int ttl ) +{ + return socket_setoption( s, IPPROTO_IP, IP_MULTICAST_TTL, ttl ); +} + + +char* +host_name( void ) +{ + static char buf[256]; /* 255 is the max host name length supported by DNS */ + int ret; + + QSOCKET_CALL(ret, gethostname(buf, sizeof(buf))); + + if (ret < 0) + return "localhost"; + else + return buf; +} diff --git a/emulator/opengl/tests/event_injector/sockets.h b/emulator/opengl/tests/event_injector/sockets.h new file mode 100644 index 0000000..ea48c5f --- /dev/null +++ b/emulator/opengl/tests/event_injector/sockets.h @@ -0,0 +1,432 @@ +/* +* 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. +*/ +/* headers to use the BSD sockets */ +#ifndef ANDROID_SOCKET_H +#define ANDROID_SOCKET_H + +#include <stddef.h> +#include <stdint.h> +#include <errno.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* we're going to hide the implementation details of sockets behind + * a simple wrapper interface declared here. + * + * all socket operations set the global 'errno' variable on error. + * this is unlike Winsock which instead modifies another internal + * variable accessed through WSAGetLastError() and WSASetLastError() + */ + +/* the wrapper will convert any Winsock error message into an errno + * code for you. There are however a few standard Unix error codes + * that are not defined by the MS C library headers, so we add them + * here. We use the official Winsock error codes, which are documented + * even though we don't want to include the Winsock headers + */ +#ifdef _WIN32 +# ifndef EINTR +# define EINTR 10004 +# endif +# ifndef EAGAIN +# define EAGAIN 10035 +# endif +# ifndef EWOULDBLOCK +# define EWOULDBLOCK EAGAIN +# endif +# ifndef EINPROGRESS +# define EINPROGRESS 10036 +# endif +# ifndef EALREADY +# define EALREADY 10037 +# endif +# ifndef EDESTADDRREQ +# define EDESTADDRREQ 10039 +# endif +# ifndef EMSGSIZE +# define EMSGSIZE 10040 +# endif +# ifndef EPROTOTYPE +# define EPROTOTYPE 10041 +# endif +# ifndef ENOPROTOOPT +# define ENOPROTOOPT 10042 +# endif +# ifndef EAFNOSUPPORT +# define EAFNOSUPPORT 10047 +# endif +# ifndef EADDRINUSE +# define EADDRINUSE 10048 +# endif +# ifndef EADDRNOTAVAIL +# define EADDRNOTAVAIL 10049 +# endif +# ifndef ENETDOWN +# define ENETDOWN 10050 +# endif +# ifndef ENETUNREACH +# define ENETUNREACH 10051 +# endif +# ifndef ENETRESET +# define ENETRESET 10052 +# endif +# ifndef ECONNABORTED +# define ECONNABORTED 10053 +# endif +# ifndef ECONNRESET +# define ECONNRESET 10054 +# endif +# ifndef ENOBUFS +# define ENOBUFS 10055 +# endif +# ifndef EISCONN +# define EISCONN 10056 +# endif +# ifndef ENOTCONN +# define ENOTCONN 10057 +# endif +# ifndef ESHUTDOWN +# define ESHUTDOWN 10058 +# endif +# ifndef ETOOMANYREFS +# define ETOOMANYREFS 10059 +# endif +# ifndef ETIMEDOUT +# define ETIMEDOUT 10060 +# endif +# ifndef ECONNREFUSED +# define ECONNREFUSED 10061 +# endif +# ifndef ELOOP +# define ELOOP 10062 +# endif +# ifndef EHOSTDOWN +# define EHOSTDOWN 10064 +# endif +# ifndef EHOSTUNREACH +# define EHOSTUNREACH 10065 +# endif +#endif /* _WIN32 */ + +/* Define 'errno_str' as a handy macro to return the string + * corresponding to a given errno code. On Unix, this is + * equivalent to strerror(errno), but on Windows, this will + * take care of Winsock-originated errors as well. + */ +#ifdef _WIN32 + extern const char* _errno_str(void); +# define errno_str _errno_str() +#else +# define errno_str strerror(errno) +#endif + +/* always enable IPv6 sockets for now. + * the QEMU internal router is not capable of + * supporting them, but we plan to replace it + * with something better in the future. + */ +#define HAVE_IN6_SOCKETS 1 + +/* Unix sockets are not available on Win32 */ +#ifndef _WIN32 +# define HAVE_UNIX_SOCKETS 1 +#endif + +/* initialize the socket sub-system. this must be called before + * using any of the declarations below. + */ +int socket_init( void ); + +/* return the name of the current host */ +char* host_name( void ); + +/* supported socket types */ +typedef enum { + SOCKET_DGRAM = 0, + SOCKET_STREAM +} SocketType; + +/* supported socket families */ +typedef enum { + SOCKET_UNSPEC, + SOCKET_INET, + SOCKET_IN6, + SOCKET_UNIX +} SocketFamily; + +/* Generic socket address structure. Note that for Unix + * sockets, the path is stored in a heap-allocated block, + * unless the 'owner' field is cleared. If this is the case, + */ +typedef struct { + SocketFamily family; + union { + struct { + uint16_t port; + uint32_t address; + } inet; + struct { + uint16_t port; + uint8_t address[16]; + } in6; + struct { + int owner; + const char* path; + } _unix; + } u; +} SockAddress; + +#define SOCK_ADDRESS_INET_ANY 0x00000000 +#define SOCK_ADDRESS_INET_LOOPBACK 0x7f000001 + +/* initialize a new IPv4 socket address, the IP address and port are + * in host endianess. + */ +void sock_address_init_inet( SockAddress* a, uint32_t ip, uint16_t port ); + +/* Initialize an IPv6 socket address, the address is in network order + * and the port in host endianess. + */ +#if HAVE_IN6_SOCKETS +void sock_address_init_in6 ( SockAddress* a, const uint8_t* ip6[16], uint16_t port ); +#endif + +/* Intialize a Unix socket address, this will copy the 'path' string into the + * heap. You need to call sock_address_done() to release the copy + */ +#if HAVE_UNIX_SOCKETS +void sock_address_init_unix( SockAddress* a, const char* path ); +#endif + +/* Finalize a socket address, only needed for now for Unix addresses */ +void sock_address_done( SockAddress* a ); + +int sock_address_equal( const SockAddress* a, const SockAddress* b ); + +/* return a static string describing the address */ +const char* sock_address_to_string( const SockAddress* a ); + +static __inline__ +SocketFamily sock_address_get_family( const SockAddress* a ) +{ + return a->family; +} + +/* return the port number of a given socket address, or -1 if it's a Unix one */ +int sock_address_get_port( const SockAddress* a ); + +/* set the port number of a given socket address, don't do anything for Unix ones */ +void sock_address_set_port( SockAddress* a, uint16_t port ); + +/* return the path of a given Unix socket, returns NULL for non-Unix ones */ +const char* sock_address_get_path( const SockAddress* a ); + +/* return the inet address, or -1 if it's not SOCKET_INET */ +int sock_address_get_ip( const SockAddress* a ); + +/* bufprint a socket address into a human-readable string */ +char* bufprint_sock_address( char* p, char* end, const SockAddress* a ); + +/* resolve a hostname or decimal IPv4/IPv6 address into a socket address. + * returns 0 on success, or -1 on failure. Note that the values or errno + * set by this function are the following: + * + * EINVAL : invalid argument + * EHOSTDOWN : could not reach DNS server + * ENOENT : no host with this name, or host doesn't have any IP address + * ENOMEM : not enough memory to perform request + */ +int sock_address_init_resolve( SockAddress* a, + const char* hostname, + uint16_t port, + int preferIn6 ); + +int sock_address_get_numeric_info( SockAddress* a, + char* host, + size_t hostlen, + char* serv, + size_t servlen ); + +/* Support for listing all socket addresses of a given host */ +enum { + SOCKET_LIST_PASSIVE = (1 << 0), + SOCKET_LIST_FORCE_INET = (1 << 1), + SOCKET_LIST_FORCE_IN6 = (1 << 2), + SOCKET_LIST_DGRAM = (1 << 3), +}; + +/* resolve a host and service/port name into a list of SockAddress objects. + * returns a NULL-terminated array of SockAddress pointers on success, + * or NULL in case of failure, with the value of errno set to one of the + * following: + * + * EINVAL : invalid argument + * EHOSTDOWN : could not reach DNS server + * ENOENT : no host with this name, or host doesn't have IP address + * ENOMEM : not enough memory to perform request + * + * other system-level errors can also be set depending on the host sockets + * implementation. + * + * This function loops on EINTR so the caller shouldn't have to check for it. + */ +SockAddress** sock_address_list_create( const char* hostname, + const char* port, + unsigned flags ); + +/* resolve a string containing host and port name into a list of SockAddress + * objects. Parameter host_and_port should be in format [host:]port, where + * 'host' addresses the machine and must be resolvable into an IP address, and + * 'port' is a decimal numeric value for the port. 'host' is optional, and if + * ommited, localhost will be used. + * returns a NULL-terminated array of SockAddress pointers on success, + * or NULL in case of failure, with the value of errno set to one of the + * following: + * + * EINVAL : invalid argument + * EHOSTDOWN : could not reach DNS server + * ENOENT : no host with this name, or host doesn't have IP address + * ENOMEM : not enough memory to perform request + * + * other system-level errors can also be set depending on the host sockets + * implementation. + * + * This function loops on EINTR so the caller shouldn't have to check for it. + */ +SockAddress** sock_address_list_create2(const char* host_and_port, + unsigned flags ); + +void sock_address_list_free( SockAddress** list ); + +/* create a new socket, return the socket number of -1 on failure */ +int socket_create( SocketFamily family, SocketType type ); + +/* create a new socket intended for IPv4 communication. returns the socket number, + * or -1 on failure. + */ +int socket_create_inet( SocketType type ); + +/* create a new socket intended for IPv6 communication. returns the socket number, + * or -1 on failure. + */ +#if HAVE_IN6_SOCKETS +int socket_create_in6 ( SocketType type ); +#endif + +/* create a unix/local domain socket. returns the socket number, + * or -1 on failure. + */ +#if HAVE_UNIX_SOCKETS +int socket_create_unix( SocketType type ); +#endif + +/* return the type of a given socket */ +SocketType socket_get_type(int fd); + +/* set SO_REUSEADDR on Unix, SO_EXCLUSIVEADDR on Windows */ +int socket_set_xreuseaddr(int fd); + +/* set socket in non-blocking mode */ +int socket_set_nonblock(int fd); + +/* set socket in blocking mode */ +int socket_set_blocking(int fd); + +/* disable the TCP Nagle algorithm for lower latency */ +int socket_set_nodelay(int fd); + +/* send OOB data inline for this socket */ +int socket_set_oobinline(int fd); + +/* force listening to IPv6 interfaces only */ +int socket_set_ipv6only(int fd); + +/* retrieve last socket error code */ +int socket_get_error(int fd); + +/* close an opened socket. Note that this is unlike the Unix 'close' because: + * - it will properly shutdown the socket in the background + * - it does not modify errno + */ +void socket_close( int fd ); + +/* the following functions are equivalent to the BSD sockets ones + */ +int socket_recv ( int fd, void* buf, int buflen ); +int socket_recvfrom( int fd, void* buf, int buflen, SockAddress* from ); + +int socket_send ( int fd, const void* buf, int buflen ); +int socket_send_oob( int fd, const void* buf, int buflen ); +int socket_sendto( int fd, const void* buf, int buflen, const SockAddress* to ); + +int socket_connect( int fd, const SockAddress* address ); +int socket_bind( int fd, const SockAddress* address ); +int socket_get_address( int fd, SockAddress* address ); +int socket_get_peer_address( int fd, SockAddress* address ); +int socket_listen( int fd, int backlog ); +int socket_accept( int fd, SockAddress* address ); + +/* returns the number of bytes that can be read from a socket */ +int socket_can_read( int fd ); + +/* this call creates a pair of non-blocking sockets connected + * to each other. this is equivalent to calling the Unix function: + * socketpair(AF_LOCAL,SOCK_STREAM,0,&fds) + * + * on Windows, this will use a pair of TCP loopback sockets instead + * returns 0 on success, -1 on error. + */ +int socket_pair(int *fd1, int *fd2); + +/* create a server socket listening on the host's loopback interface */ +int socket_loopback_server( int port, SocketType type ); + +/* connect to a port on the host's loopback interface */ +int socket_loopback_client( int port, SocketType type ); + +/* create a server socket listening to a Unix domain path */ +#if HAVE_UNIX_SOCKETS +int socket_unix_server( const char* name, SocketType type ); +#endif + +/* create a Unix sockets and connects it to a Unix server */ +#if HAVE_UNIX_SOCKETS +int socket_unix_client( const char* name, SocketType type ); +#endif + +/* create an IPv4 client socket and connect it to a given host */ +int socket_network_client( const char* host, int port, SocketType type ); + +/* create an IPv4 socket and binds it to a given port of the host's interface */ +int socket_anyaddr_server( int port, SocketType type ); + +/* accept a connection from the host's any interface, return the new socket + * descriptor or -1 */ +int socket_accept_any( int server_fd ); + + +int socket_mcast_inet_add_membership( int s, uint32_t ip ); +int socket_mcast_inet_drop_membership( int s, uint32_t ip ); +int socket_mcast_inet_set_loop( int s, int enabled ); +int socket_mcast_inet_set_ttl( int s, int ttl ); + +#ifdef __cplusplus +} +#endif + +#endif /* ANDROID_SOCKET_H */ diff --git a/emulator/opengl/tests/gles_android_wrapper/Android.mk b/emulator/opengl/tests/gles_android_wrapper/Android.mk new file mode 100644 index 0000000..f7c8fed --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/Android.mk @@ -0,0 +1,80 @@ +LOCAL_PATH := $(call my-dir) + +#### libGLESv1_CM_emul.so +$(call emugl-begin-shared-library,libGLESv1_CM_emul) +$(call emugl-import,libGLESv1_enc) +$(call emugl-gen-wrapper,$(EMUGL_PATH)/system/GLESv1_enc,gl) +$(call emugl-set-shared-library-subpath,egl) + +LOCAL_SRC_FILES += glesv1_emul_ifc.cpp + +$(call emugl-end-module) + +emulatorOpengl := $(LOCAL_PATH)/../.. +logTag := -DLOG_TAG=\"eglWrapper\" +EMUGEN = $(BUILD_OUT_EXECUTABLES)/emugen +## comment for no debug +#debugFlags = -g -O0 + +#### libGLESv2_CM_emul.so +$(call emugl-begin-shared-library, libGLESv2_emul) +$(call emugl-import,libGLESv2_enc) +$(call emugl-gen-wrapper,$(EMUGL_PATH)/system/GLESv2_enc,gl2) +LOCAL_SRC_FILES += glesv2_emul_ifc.cpp +$(call emugl-set-shared-library-subpath,egl) +$(call emugl-end-module) + +##### libEGL_emul.so ########### + +# THE FOLLOWING DOESN'T WORK YET +# +$(call emugl-begin-shared-library,libEGL_emul) +$(call emugl-import,libut_rendercontrol_enc libGLESv1_CM_emul libGLESv2_emul libOpenglSystemCommon) + +$(call emugl-set-shared-library-subpath,egl) +LOCAL_CFLAGS += $(logTag) + +LOCAL_SRC_FILES := \ + egl.cpp \ + egl_dispatch.cpp \ + ServerConnection.cpp \ + ThreadInfo.cpp + +$(call emugl-end-module) + +#### egl.cfg #### + +# Ensure that this file is only copied to emulator-specific builds. +# Other builds are device-specific and will provide their own +# version of this file to point to the appropriate HW EGL libraries. +# +ifneq (,$(filter full full_x86 sdk sdk_x86,$(TARGET_PRODUCT))) +ifeq (,$(BUILD_EMULATOR_OPENGL_DRIVER)) +include $(CLEAR_VARS) + +LOCAL_MODULE := egl.cfg +LOCAL_SRC_FILES := $(LOCAL_MODULE) + +LOCAL_MODULE_PATH := $(TARGET_OUT)/lib/egl +LOCAL_MODULE_TAGS := debug +LOCAL_MODULE_CLASS := ETC + +include $(BUILD_PREBUILT) +endif # building 'real' driver BUILD_EMULATOR_OPENGL_DRIVER +endif # TARGET_PRODUCT in 'full sdk full_x86 sdk_x86' + +#### gles_emul.cfg #### +include $(CLEAR_VARS) + +LOCAL_MODULE := gles_emul.cfg +LOCAL_SRC_FILES := $(LOCAL_MODULE) + +LOCAL_MODULE_PATH := $(TARGET_OUT)/etc +LOCAL_MODULE_TAGS := debug +LOCAL_MODULE_CLASS := ETC + +include $(BUILD_PREBUILT) + + + + diff --git a/emulator/opengl/tests/gles_android_wrapper/ApiInitializer.h b/emulator/opengl/tests/gles_android_wrapper/ApiInitializer.h new file mode 100644 index 0000000..793c735 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/ApiInitializer.h @@ -0,0 +1,42 @@ +/* +* 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 _API_INITIALIZER_H_ +#define _API_INITIALIZER_H_ +#include <stdlib.h> +#include <dlfcn.h> + +class ApiInitializer { +public: + ApiInitializer(void *dso) : + m_dso(dso) { + } + static void *s_getProc(const char *name, void *userData) { + ApiInitializer *self = (ApiInitializer *)userData; + return self->getProc(name); + } +private: + void *m_dso; + void *getProc(const char *name) { + void *symbol = NULL; + if (m_dso) { + symbol = dlsym(m_dso, name); + } + return symbol; + } +}; + +#endif diff --git a/emulator/opengl/tests/gles_android_wrapper/CleanSpec.mk b/emulator/opengl/tests/gles_android_wrapper/CleanSpec.mk new file mode 100644 index 0000000..f56383a --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/CleanSpec.mk @@ -0,0 +1,50 @@ +# Copyright (C) 2007 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. +# + +# If you don't need to do a full clean build but would like to touch +# a file or delete some intermediate files, add a clean step to the end +# of the list. These steps will only be run once, if they haven't been +# run before. +# +# E.g.: +# $(call add-clean-step, touch -c external/sqlite/sqlite3.h) +# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates) +# +# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with +# files that are missing or have been moved. +# +# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory. +# Use $(OUT_DIR) to refer to the "out" directory. +# +# If you need to re-do something that's already mentioned, just copy +# the command and add it to the bottom of the list. E.g., if a change +# that you made last week required touching a file and a change you +# made today requires touching the same file, just copy the old +# touch step and add it to the end of the list. +# +# ************************************************ +# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST +# ************************************************ + +# For example: +#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates) +#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates) +#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f) +#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*) + +# ************************************************ +# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST +# ************************************************ +$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/SHARED_LIBRARIES/libGLES_emul_intermediates) diff --git a/emulator/opengl/tests/gles_android_wrapper/ServerConnection.cpp b/emulator/opengl/tests/gles_android_wrapper/ServerConnection.cpp new file mode 100644 index 0000000..ff4e390 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/ServerConnection.cpp @@ -0,0 +1,125 @@ +/* +* 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 "ServerConnection.h" +#include "TcpStream.h" +#include "QemuPipeStream.h" +#include <cutils/log.h> +#include "ThreadInfo.h" + +gl_client_context_t *ServerConnection::s_getGlContext() +{ + EGLThreadInfo *ti = getEGLThreadInfo(); + if (ti->serverConn) { + return ti->serverConn->m_glEnc; + } + return NULL; +} + +gl2_client_context_t *ServerConnection::s_getGl2Context() +{ + EGLThreadInfo *ti = getEGLThreadInfo(); + if (ti->serverConn) { + return ti->serverConn->m_gl2Enc; + } + return NULL; +} + +ServerConnection *ServerConnection::s_getServerConnection() +{ + EGLThreadInfo *ti = getEGLThreadInfo(); + if (!ti->serverConn) + { + ti->serverConn = new ServerConnection(); + if (ti->serverConn->create() < 0) { + delete ti->serverConn; + ti->serverConn = NULL; + } + } + + return ti->serverConn; +} + + +ServerConnection::ServerConnection() : + m_stream(NULL), + m_glEnc(NULL), + m_ut_enc(NULL) +{ +} + +ServerConnection::~ServerConnection() +{ + delete m_ut_enc; + delete m_glEnc; + delete m_stream; +} + + + +int ServerConnection::create(size_t bufsize, + const char *defaultServer) +{ + /* XXX: Make configurable through system property */ + int useQemuPipe = 1; + + if (m_stream != NULL) delete(m_stream); + + if (useQemuPipe) { + QemuPipeStream* pipeStream = new QemuPipeStream(bufsize); + + if (pipeStream->connect() < 0) { + ALOGE("couldn't connect to host server\n"); + delete pipeStream; + return -1; + } + m_stream = pipeStream; + } + else /* !useQemuPipe */ + { + TcpStream* tcpStream = new TcpStream(bufsize); + + char *s = getenv(ENV_RGL_SERVER); + char *hostname; + if (s == NULL) { + hostname = strdup(defaultServer); + } else { + hostname = strdup(s); + } + + if (tcpStream->connect(hostname, CODEC_SERVER_PORT) < 0) { + ALOGE("couldn't connect to %s\n", hostname); + free(hostname); + delete tcpStream; + return -1; + } + LOGI("connecting to server %s\n", hostname); + free(hostname); + + m_stream = tcpStream; + } + + m_glEnc = new GLEncoder(m_stream); + m_glEnc->setContextAccessor(s_getGlContext); + + m_gl2Enc = new GL2Encoder(m_stream); + m_gl2Enc->setContextAccessor(s_getGl2Context); + + m_ut_enc = new ut_rendercontrol_encoder_context_t(m_stream); + return 0; +} + diff --git a/emulator/opengl/tests/gles_android_wrapper/ServerConnection.h b/emulator/opengl/tests/gles_android_wrapper/ServerConnection.h new file mode 100644 index 0000000..84f40d8 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/ServerConnection.h @@ -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. +*/ +#ifndef _SERVER_CONNECTION_H +#define _SERVER_CONNECTION_H + +#include "GLEncoder.h" +#include "GL2Encoder.h" +#include "IOStream.h" +#include "codec_defs.h" +#include "ut_rendercontrol_enc.h" +#include <pthread.h> + +#define ENV_RGL_SERVER "RGL_SERVER" +#define RGL_DEFAULT_SERVER "10.0.2.2" + +class ServerConnection { +public: + ~ServerConnection(); + int create(size_t buf_size = 4 * 1024 * 1024, const char *defaultServer = RGL_DEFAULT_SERVER); + static gl_client_context_t *s_getGlContext(); + static ServerConnection *s_getServerConnection(); + static gl2_client_context_t *s_getGl2Context(); + GLEncoder *glEncoder() { return m_glEnc; } + GL2Encoder *gl2Encoder() { return m_gl2Enc; } + ut_rendercontrol_encoder_context_t * utEnc() { return m_ut_enc; } + +private: + ServerConnection(); + +private: + static pthread_key_t s_glKey; + static pthread_key_t s_connectionKey; + static void s_initKeys(); + IOStream *m_stream; + GLEncoder *m_glEnc; + GL2Encoder *m_gl2Enc; + ut_rendercontrol_encoder_context_t *m_ut_enc; + +}; + + +#endif diff --git a/emulator/opengl/tests/gles_android_wrapper/ThreadInfo.cpp b/emulator/opengl/tests/gles_android_wrapper/ThreadInfo.cpp new file mode 100644 index 0000000..5bf6a7d --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/ThreadInfo.cpp @@ -0,0 +1,39 @@ +/* +* 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" +#include "cutils/threads.h" + +thread_store_t s_tls = THREAD_STORE_INITIALIZER; + +static void tlsDestruct(void *ptr) +{ + if (ptr) { + EGLThreadInfo *ti = (EGLThreadInfo *)ptr; + delete ti->serverConn; + delete ti; + } +} + +EGLThreadInfo *getEGLThreadInfo() +{ + EGLThreadInfo *ti = (EGLThreadInfo *)thread_store_get(&s_tls); + if (ti) return ti; + + ti = new EGLThreadInfo(); + thread_store_set(&s_tls, ti, tlsDestruct); + + return ti; +} diff --git a/emulator/opengl/tests/gles_android_wrapper/ThreadInfo.h b/emulator/opengl/tests/gles_android_wrapper/ThreadInfo.h new file mode 100644 index 0000000..f748a39 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/ThreadInfo.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 _THREAD_INFO_H +#define _THREAD_INFO_H + +#include "ServerConnection.h" +#include <EGL/egl.h> + +struct EGLWrapperContext +{ + EGLWrapperContext(EGLContext p_aglContext, int _version) { + aglContext = p_aglContext; + clientState = NULL; + version = _version; + } + + ~EGLWrapperContext() { + delete clientState; + } + + EGLContext aglContext; + GLClientState *clientState; + int version; +}; + +struct EGLThreadInfo +{ + EGLThreadInfo() : currentContext(NULL), serverConn(NULL) {} + + EGLWrapperContext *currentContext; + ServerConnection *serverConn; +}; + + +EGLThreadInfo *getEGLThreadInfo(); +#endif diff --git a/emulator/opengl/tests/gles_android_wrapper/egl.cfg b/emulator/opengl/tests/gles_android_wrapper/egl.cfg new file mode 100644 index 0000000..891b07d --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/egl.cfg @@ -0,0 +1 @@ +0 0 emul
\ No newline at end of file diff --git a/emulator/opengl/tests/gles_android_wrapper/egl.cpp b/emulator/opengl/tests/gles_android_wrapper/egl.cpp new file mode 100644 index 0000000..1e2e456 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/egl.cpp @@ -0,0 +1,663 @@ +/* +* 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. +*/ + +// +// WARNING -------------------------- WARNING +// This code meant to be used for testing purposes only. It is not production +// level quality. +// Use on your own risk !! +// + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <dlfcn.h> +#include "egl_dispatch.h" +#include "egl_ftable.h" +#include <cutils/process_name.h> +#include <cutils/log.h> +#include "ServerConnection.h" +#include "ThreadInfo.h" +#include <pthread.h> +#include "gl_wrapper_context.h" +#include "gl2_wrapper_context.h" + +#define GLES_EMUL_TARGETS_FILE "/system/etc/gles_emul.cfg" +// implementation libraries; +#define GLESv1_enc_LIB "/system/lib/libGLESv1_enc.so" +#define GLESv2_enc_LIB "/system/lib/libGLESv2_enc.so" +#define GLES_android_LIB "/system/lib/egl/libGLES_android.so" +// driver libraries; +#define GLESv1_DRIVER "/system/lib/egl/libGLESv1_CM_emul.so" +#define GLESv2_DRIVER "/system/lib/egl/libGLESv2_emul.so" + + +static struct egl_dispatch *s_dispatch = NULL; +pthread_once_t dispatchTablesInitialized = PTHREAD_ONCE_INIT; + +static bool s_needEncode = false; + +static gl_wrapper_context_t *g_gl_dispatch = NULL; +static gl2_wrapper_context_t *g_gl2_dispatch = NULL; + +template <class T> +int initApi(const char *driverLibName, const char *implLibName, T **dispatchTable, T *(*accessor)()) +{ + void *driverLib = dlopen(driverLibName, RTLD_NOW | RTLD_LOCAL); + if (driverLib == NULL) { + ALOGE("failed to load %s : %s\n", driverLibName, dlerror()); + return -1; + } + + typedef T *(*createFcn_t)(void *, T *(*accessor)()); + createFcn_t createFcn; + createFcn = (createFcn_t) dlsym(driverLib, "createFromLib"); + if (createFcn == NULL) { + ALOGE("failed to load createFromLib constructor function\n"); + return -1; + } + + void *implLib = dlopen(implLibName, RTLD_NOW | RTLD_LOCAL); + if (implLib == NULL) { + ALOGE("couldn't open %s", implLibName); + return -2; + } + *dispatchTable = createFcn(implLib, accessor); + if (*dispatchTable == NULL) { + return -3; + } + + // XXX - we do close the impl library since it doesn't have data, as far as we concern. + dlclose(implLib); + + // XXX - we do not dlclose the driver library, so its not initialized when + // later loaded by android - is this required? + ALOGD("loading %s into %s complete\n", implLibName, driverLibName); + return 0; + +} + +static gl_wrapper_context_t *getGLContext() +{ + return g_gl_dispatch; +} + +static gl2_wrapper_context_t *getGL2Context() +{ + return g_gl2_dispatch; +} + +const char *getProcName() +{ + static const char *procname = NULL; + + if (procname == NULL) { + const char *str = get_process_name(); + if (strcmp(str, "unknown") != 0) { + procname = str; + } else { + // we need to obtain our process name from the command line; + FILE *fp = fopen("/proc/self/cmdline", "rt"); + if (fp == NULL) { + ALOGE("couldn't open /proc/self/cmdline\n"); + return NULL; + } + + char line[1000]; + if (fgets(line, sizeof(line), fp) == NULL) { + ALOGE("couldn't read the self cmdline from \n"); + fclose(fp); + return NULL; + } + fclose(fp); + + if (line[0] == '\0') { + ALOGE("cmdline is empty\n"); + return NULL; + } + + //obtain the basename; + line[sizeof(line) - 1] = '\0'; + char *p = line; + while (*p != '\0' && + *p != '\t' && + *p != ' ' && + *p != '\n') { + p++; + } + + *p = '\0'; p--; + while (p > line && *p != '/') p--; + if (*p == '/') p++; + procname = strdup(p); + } + } + + return procname; +} + + + +bool isNeedEncode() +{ + const char *procname = getProcName(); + if (procname == NULL) return false; + ALOGD("isNeedEncode? for %s\n", procname); + // check on our whitelist + FILE *fp = fopen(GLES_EMUL_TARGETS_FILE, "rt"); + if (fp == NULL) { + ALOGE("couldn't open %s\n", GLES_EMUL_TARGETS_FILE); + return false; + } + + char line[100]; + bool found = false; + size_t procnameLen = strlen(procname); + + while (fgets(line, sizeof(line), fp) != NULL) { + if (strlen(line) >= procnameLen && + !strncmp(procname, line, procnameLen)) { + char c = line[procnameLen]; + if (c == '\0' || c == ' ' || c == '\t' || c == '\n') { + found = true; + ALOGD("should use encoder for %s\n", procname); + break; + } + } + } + fclose(fp); + return found; +} + +void initDispatchTables() +{ + // + // Load our back-end implementation of EGL/GLES + // + ALOGD("Loading egl dispatch for %s\n", getProcName()); + + void *gles_android = dlopen("/system/lib/egl/libGLES_android.so", RTLD_NOW | RTLD_LOCAL); + if (!gles_android) { + fprintf(stderr,"FATAL ERROR: Could not load libGLES_android lib\n"); + exit(-1); + } + + // + // Load back-end EGL implementation library + // + s_dispatch = create_egl_dispatch( gles_android ); + if (!s_dispatch) { + fprintf(stderr,"FATAL ERROR: Could not create egl dispatch\n"); + exit(-1); + } + + // + // initialize gles + // + s_needEncode = isNeedEncode(); + void *gles_encoder = NULL; + if (s_needEncode) { + // initialize a connection to the server, and the GLESv1/v2 encoders; + ServerConnection * connection = ServerConnection::s_getServerConnection(); + if (connection == NULL) { + ALOGE("couldn't create server connection\n"); + s_needEncode = false; + } + } + + // init dispatch tabels for GLESv1 & GLESv2 + if (s_needEncode) { + // XXX - we do not check the retrun value because there isn't much we can do here on failure. + + if (initApi<gl_wrapper_context_t>(GLESv1_DRIVER, GLESv1_enc_LIB, &g_gl_dispatch, getGLContext) < 0) { + // fallback to android on faluire + s_needEncode = false; + } else { + initApi<gl2_wrapper_context_t>(GLESv2_DRIVER, GLESv2_enc_LIB, &g_gl2_dispatch, getGL2Context); + } + } + + if (!s_needEncode) { + ALOGD("Initializing native opengl for %s\n", getProcName()); + initApi<gl_wrapper_context_t>(GLESv1_DRIVER, GLES_android_LIB, &g_gl_dispatch, getGLContext); + // try to initialize gl2 from GLES, though its probably going to fail + initApi<gl2_wrapper_context_t>(GLESv2_DRIVER, GLES_android_LIB, &g_gl2_dispatch, getGL2Context); + } +} + +static struct egl_dispatch *getDispatch() +{ + pthread_once(&dispatchTablesInitialized, initDispatchTables); + return s_dispatch; +} + +__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) +{ + + // search in EGL function table + for (int i=0; i<egl_num_funcs; i++) { + if (!strcmp(egl_funcs_by_name[i].name, procname)) { + return (__eglMustCastToProperFunctionPointerType)egl_funcs_by_name[i].proc; + } + } + + // we do not support eglGetProcAddress for GLESv1 & GLESv2. The loader + // should be able to find this function through dynamic loading. + return NULL; +} + +//////////////// Path through functions ////////// + +EGLint eglGetError() +{ + return getDispatch()->eglGetError(); +} + +EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id) +{ + return getDispatch()->eglGetDisplay(display_id); +} + +EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) +{ + return getDispatch()->eglInitialize(dpy, major, minor); +} + +EGLBoolean eglTerminate(EGLDisplay dpy) +{ + return getDispatch()->eglTerminate(dpy); +} + +const char* eglQueryString(EGLDisplay dpy, EGLint name) +{ + return getDispatch()->eglQueryString(dpy, name); +} + +EGLBoolean eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config) +{ + return getDispatch()->eglGetConfigs(dpy, configs, config_size, num_config); +} + +static EGLint * filter_es2_bit(const EGLint *attrib_list, bool *isES2) +{ + if (attrib_list == NULL) { + if (isES2 != NULL) *isES2 = false; + return NULL; + } + + EGLint *attribs = NULL; + int nAttribs = 0; + while(attrib_list[nAttribs] != EGL_NONE) nAttribs++; + nAttribs++; + + attribs = new EGLint[nAttribs]; + memcpy(attribs, attrib_list, nAttribs * sizeof(EGLint)); + if (isES2 != NULL) *isES2 = false; + + // scan the attribute list for ES2 request and replace with ES1. + for (int i = 0; i < nAttribs; i++) { + if (attribs[i] == EGL_RENDERABLE_TYPE) { + if (attribs[i + 1] & EGL_OPENGL_ES2_BIT) { + attribs[i + 1] &= ~EGL_OPENGL_ES2_BIT; + attribs[i + 1] |= EGL_OPENGL_ES_BIT; + ALOGD("removing ES2 bit 0x%x\n", attribs[i + 1]); + if (isES2 != NULL) *isES2 = true; + } + } + } + return attribs; +} + +EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config) +{ + EGLBoolean res; + if (s_needEncode) { + EGLint *attribs = filter_es2_bit(attrib_list, NULL); + res = getDispatch()->eglChooseConfig(dpy, + attribs, + configs, + config_size, + num_config); + ALOGD("eglChooseConfig: %d configs found\n", *num_config); + if (*num_config == 0 && attribs != NULL) { + ALOGD("requested attributes:\n"); + for (int i = 0; attribs[i] != EGL_NONE; i++) { + ALOGD("%d: 0x%x\n", i, attribs[i]); + } + } + + delete attribs; + } else { + res = getDispatch()->eglChooseConfig(dpy, attrib_list, configs, config_size, num_config); + } + return res; +} + +EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value) +{ + if (s_needEncode && attribute == EGL_RENDERABLE_TYPE) { + *value = EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT; + return EGL_TRUE; + } else { + return getDispatch()->eglGetConfigAttrib(dpy, config, attribute, value); + } +} + +EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list) +{ + EGLSurface surface = getDispatch()->eglCreateWindowSurface(dpy, config, win, attrib_list); + if (surface != EGL_NO_SURFACE) { + ServerConnection *server; + if (s_needEncode && (server = ServerConnection::s_getServerConnection()) != NULL) { + server->utEnc()->createSurface(server->utEnc(), getpid(), (uint32_t)surface); + } + } + return surface; +} + +EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list) +{ + EGLSurface surface = getDispatch()->eglCreatePbufferSurface(dpy, config, attrib_list); + if (surface != EGL_NO_SURFACE) { + ServerConnection *server; + if (s_needEncode && (server = ServerConnection::s_getServerConnection()) != NULL) { + server->utEnc()->createSurface(server->utEnc(), getpid(), (uint32_t)surface); + } + } + return surface; +} + +EGLSurface eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list) +{ + EGLSurface surface = getDispatch()->eglCreatePixmapSurface(dpy, config, pixmap, attrib_list); + if (surface != EGL_NO_SURFACE) { + ServerConnection *server; + if (s_needEncode && (server = ServerConnection::s_getServerConnection()) != NULL) { + server->utEnc()->createSurface(server->utEnc(), getpid(), (uint32_t)surface); + } + } + return surface; +} + +EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) +{ + EGLBoolean res = getDispatch()->eglDestroySurface(dpy, surface); + if (res && surface != EGL_NO_SURFACE) { + ServerConnection *server; + if (s_needEncode && (server = ServerConnection::s_getServerConnection()) != NULL) { + server->utEnc()->destroySurface(server->utEnc(), getpid(), (uint32_t)surface); + } + } + return res; +} + +EGLBoolean eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value) +{ + EGLBoolean res = getDispatch()->eglQuerySurface(dpy, surface, attribute, value); + if (res && attribute == EGL_RENDERABLE_TYPE) { + *value |= EGL_OPENGL_ES2_BIT; + } + return res; +} + +EGLBoolean eglBindAPI(EGLenum api) +{ + return getDispatch()->eglBindAPI(api); +} + +EGLenum eglQueryAPI() +{ + return getDispatch()->eglQueryAPI(); +} + +EGLBoolean eglWaitClient() +{ + return getDispatch()->eglWaitClient(); +} + +EGLBoolean eglReleaseThread() +{ + return getDispatch()->eglReleaseThread(); +} + +EGLSurface eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list) +{ + return getDispatch()->eglCreatePbufferFromClientBuffer(dpy, buftype, buffer, config, attrib_list); +} + +EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) +{ + return getDispatch()->eglSurfaceAttrib(dpy, surface, attribute, value); +} + +EGLBoolean eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) +{ + return getDispatch()->eglBindTexImage(dpy, surface, buffer); +} + +EGLBoolean eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) +{ + return getDispatch()->eglReleaseTexImage(dpy, surface, buffer); +} + +EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) +{ + return getDispatch()->eglSwapInterval(dpy, interval); +} + +EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list) +{ + + EGLContext share = share_context; + if (share) share = ((EGLWrapperContext *)share_context)->aglContext; + + // check if are ES2, and convert it to ES1. + int nAttribs = 0; + if (attrib_list != NULL) { + while(attrib_list[nAttribs] != EGL_NONE) { + nAttribs++; + } + nAttribs++; + } + + EGLint *attrib = NULL; + if (nAttribs > 0) { + attrib = new EGLint[nAttribs]; + memcpy(attrib, attrib_list, nAttribs * sizeof(EGLint)); + } + + int version = 1; + for (int i = 0; i < nAttribs; i++) { + if (attrib[i] == EGL_CONTEXT_CLIENT_VERSION && + attrib[i + 1] == 2) { + version = 2; + attrib[i + 1] = 1; // replace to version 1 + } + } + + EGLContext ctx = getDispatch()->eglCreateContext(dpy, config, share, attrib); + delete attrib; + EGLWrapperContext *wctx = new EGLWrapperContext(ctx, version); + if (ctx != EGL_NO_CONTEXT) { + ServerConnection *server; + if (s_needEncode && (server = ServerConnection::s_getServerConnection()) != NULL) { + wctx->clientState = new GLClientState(); + server->utEnc()->createContext(server->utEnc(), getpid(), + (uint32_t)wctx, + (uint32_t)(share_context == EGL_NO_CONTEXT ? 0 : share_context), wctx->version); + } + } + return (EGLContext)wctx; +} + +EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) +{ + EGLWrapperContext *wctx = (EGLWrapperContext *)ctx; + EGLBoolean res = EGL_FALSE; + + if (ctx && ctx != EGL_NO_CONTEXT) { + res = getDispatch()->eglDestroyContext(dpy, wctx->aglContext); + if (res) { + EGLThreadInfo *ti = getEGLThreadInfo(); + ServerConnection *server; + if (s_needEncode && (server = ServerConnection::s_getServerConnection())) { + server->utEnc()->destroyContext(ti->serverConn->utEnc(), getpid(), (uint32_t)ctx); + } + if (ti->currentContext == wctx) ti->currentContext = NULL; + delete wctx; + } + } + + return res; +} + +EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) +{ + EGLWrapperContext *wctx = (EGLWrapperContext *)ctx; + EGLContext aglContext = (ctx == EGL_NO_CONTEXT ? EGL_NO_CONTEXT : wctx->aglContext); + EGLThreadInfo *ti = getEGLThreadInfo(); + EGLBoolean res = getDispatch()->eglMakeCurrent(dpy, draw, read, aglContext); + if (res ) { + // NOTE - we do get a pointer to the server connection, (rather then using ti->serverConn) + // for cases that this is the first egl call of the current thread. + + ServerConnection *server; + if (s_needEncode && (server = ServerConnection::s_getServerConnection())) { + server->utEnc()->makeCurrentContext(server->utEnc(), getpid(), + (uint32_t) (draw == EGL_NO_SURFACE ? 0 : draw), + (uint32_t) (read == EGL_NO_SURFACE ? 0 : read), + (uint32_t) (ctx == EGL_NO_CONTEXT ? 0 : ctx)); + server->glEncoder()->setClientState( wctx ? wctx->clientState : NULL ); + server->gl2Encoder()->setClientState( wctx ? wctx->clientState : NULL ); + } + + // set current context in our thread info + ti->currentContext = wctx; + } + return res; + +} + +EGLContext eglGetCurrentContext() +{ + EGLThreadInfo *ti = getEGLThreadInfo(); + return (ti->currentContext ? ti->currentContext : EGL_NO_CONTEXT); +} + +EGLSurface eglGetCurrentSurface(EGLint readdraw) +{ + return getDispatch()->eglGetCurrentSurface(readdraw); +} + +EGLDisplay eglGetCurrentDisplay() +{ + return getDispatch()->eglGetCurrentDisplay(); +} + +EGLBoolean eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value) +{ + EGLWrapperContext *wctx = (EGLWrapperContext *)ctx; + if (wctx) { + if (attribute == EGL_CONTEXT_CLIENT_VERSION) { + *value = wctx->version; + return EGL_TRUE; + } else { + return getDispatch()->eglQueryContext(dpy, wctx->aglContext, attribute, value); + } + } + else { + return EGL_BAD_CONTEXT; + } +} + +EGLBoolean eglWaitGL() +{ + return getDispatch()->eglWaitGL(); +} + +EGLBoolean eglWaitNative(EGLint engine) +{ + return getDispatch()->eglWaitNative(engine); +} + +EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) +{ + ServerConnection *server; + if (s_needEncode && (server = ServerConnection::s_getServerConnection()) != NULL) { + server->utEnc()->swapBuffers(server->utEnc(), getpid(), (uint32_t)surface); + server->glEncoder()->flush(); + server->gl2Encoder()->flush(); + return 1; + } + return getDispatch()->eglSwapBuffers(dpy, surface); +} + +EGLBoolean eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target) +{ + return getDispatch()->eglCopyBuffers(dpy, surface, target); +} + +EGLBoolean eglLockSurfaceKHR(EGLDisplay display, EGLSurface surface, const EGLint *attrib_list) +{ + return getDispatch()->eglLockSurfaceKHR(display, surface, attrib_list); +} + +EGLBoolean eglUnlockSurfaceKHR(EGLDisplay display, EGLSurface surface) +{ + return getDispatch()->eglUnlockSurfaceKHR(display, surface); +} + +EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list) +{ + EGLWrapperContext *wctx = (EGLWrapperContext *)ctx; + EGLContext aglContext = (wctx ? wctx->aglContext : EGL_NO_CONTEXT); + return getDispatch()->eglCreateImageKHR(dpy, aglContext, target, buffer, attrib_list); +} + +EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image) +{ + return getDispatch()->eglDestroyImageKHR(dpy, image); +} + +EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) +{ + return getDispatch()->eglCreateSyncKHR(dpy, type, attrib_list); +} + +EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) +{ + return getDispatch()->eglDestroySyncKHR(dpy, sync); +} + +EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout) +{ + return getDispatch()->eglClientWaitSyncKHR(dpy, sync, flags, timeout); +} + +EGLBoolean eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) +{ + return getDispatch()->eglSignalSyncKHR(dpy, sync, mode); +} + +EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value) +{ + return getDispatch()->eglGetSyncAttribKHR(dpy, sync, attribute, value); +} + +EGLBoolean eglSetSwapRectangleANDROID(EGLDisplay dpy, EGLSurface draw, EGLint left, EGLint top, EGLint width, EGLint height) +{ + return getDispatch()->eglSetSwapRectangleANDROID(dpy, draw, left, top, width, height); +} diff --git a/emulator/opengl/tests/gles_android_wrapper/egl_dispatch.cpp b/emulator/opengl/tests/gles_android_wrapper/egl_dispatch.cpp new file mode 100644 index 0000000..f69ca61 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/egl_dispatch.cpp @@ -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. +*/ +#include <stdio.h> +#include "egl_dispatch.h" +#include <dlfcn.h> + +egl_dispatch *create_egl_dispatch(void *gles_android) +{ + egl_dispatch *disp = new egl_dispatch; + + void *ptr; + ptr = dlsym(gles_android,"eglGetError"); disp->set_eglGetError((eglGetError_t)ptr); + ptr = dlsym(gles_android,"eglGetDisplay"); disp->set_eglGetDisplay((eglGetDisplay_t)ptr); + ptr = dlsym(gles_android,"eglInitialize"); disp->set_eglInitialize((eglInitialize_t)ptr); + ptr = dlsym(gles_android,"eglTerminate"); disp->set_eglTerminate((eglTerminate_t)ptr); + ptr = dlsym(gles_android,"eglQueryString"); disp->set_eglQueryString((eglQueryString_t)ptr); + ptr = dlsym(gles_android,"eglGetConfigs"); disp->set_eglGetConfigs((eglGetConfigs_t)ptr); + ptr = dlsym(gles_android,"eglChooseConfig"); disp->set_eglChooseConfig((eglChooseConfig_t)ptr); + ptr = dlsym(gles_android,"eglGetConfigAttrib"); disp->set_eglGetConfigAttrib((eglGetConfigAttrib_t)ptr); + ptr = dlsym(gles_android,"eglCreateWindowSurface"); disp->set_eglCreateWindowSurface((eglCreateWindowSurface_t)ptr); + ptr = dlsym(gles_android,"eglCreatePbufferSurface"); disp->set_eglCreatePbufferSurface((eglCreatePbufferSurface_t)ptr); + ptr = dlsym(gles_android,"eglCreatePixmapSurface"); disp->set_eglCreatePixmapSurface((eglCreatePixmapSurface_t)ptr); + ptr = dlsym(gles_android,"eglDestroySurface"); disp->set_eglDestroySurface((eglDestroySurface_t)ptr); + ptr = dlsym(gles_android,"eglQuerySurface"); disp->set_eglQuerySurface((eglQuerySurface_t)ptr); + ptr = dlsym(gles_android,"eglBindAPI"); disp->set_eglBindAPI((eglBindAPI_t)ptr); + ptr = dlsym(gles_android,"eglQueryAPI"); disp->set_eglQueryAPI((eglQueryAPI_t)ptr); + ptr = dlsym(gles_android,"eglWaitClient"); disp->set_eglWaitClient((eglWaitClient_t)ptr); + ptr = dlsym(gles_android,"eglReleaseThread"); disp->set_eglReleaseThread((eglReleaseThread_t)ptr); + ptr = dlsym(gles_android,"eglCreatePbufferFromClientBuffer"); disp->set_eglCreatePbufferFromClientBuffer((eglCreatePbufferFromClientBuffer_t)ptr); + ptr = dlsym(gles_android,"eglSurfaceAttrib"); disp->set_eglSurfaceAttrib((eglSurfaceAttrib_t)ptr); + ptr = dlsym(gles_android,"eglBindTexImage"); disp->set_eglBindTexImage((eglBindTexImage_t)ptr); + ptr = dlsym(gles_android,"eglReleaseTexImage"); disp->set_eglReleaseTexImage((eglReleaseTexImage_t)ptr); + ptr = dlsym(gles_android,"eglSwapInterval"); disp->set_eglSwapInterval((eglSwapInterval_t)ptr); + ptr = dlsym(gles_android,"eglCreateContext"); disp->set_eglCreateContext((eglCreateContext_t)ptr); + ptr = dlsym(gles_android,"eglDestroyContext"); disp->set_eglDestroyContext((eglDestroyContext_t)ptr); + ptr = dlsym(gles_android,"eglMakeCurrent"); disp->set_eglMakeCurrent((eglMakeCurrent_t)ptr); + ptr = dlsym(gles_android,"eglGetCurrentContext"); disp->set_eglGetCurrentContext((eglGetCurrentContext_t)ptr); + ptr = dlsym(gles_android,"eglGetCurrentSurface"); disp->set_eglGetCurrentSurface((eglGetCurrentSurface_t)ptr); + ptr = dlsym(gles_android,"eglGetCurrentDisplay"); disp->set_eglGetCurrentDisplay((eglGetCurrentDisplay_t)ptr); + ptr = dlsym(gles_android,"eglQueryContext"); disp->set_eglQueryContext((eglQueryContext_t)ptr); + ptr = dlsym(gles_android,"eglWaitGL"); disp->set_eglWaitGL((eglWaitGL_t)ptr); + ptr = dlsym(gles_android,"eglWaitNative"); disp->set_eglWaitNative((eglWaitNative_t)ptr); + ptr = dlsym(gles_android,"eglSwapBuffers"); disp->set_eglSwapBuffers((eglSwapBuffers_t)ptr); + ptr = dlsym(gles_android,"eglCopyBuffers"); disp->set_eglCopyBuffers((eglCopyBuffers_t)ptr); + ptr = dlsym(gles_android,"eglGetProcAddress"); disp->set_eglGetProcAddress((eglGetProcAddress_t)ptr); + ptr = dlsym(gles_android,"eglLockSurfaceKHR"); disp->set_eglLockSurfaceKHR((eglLockSurfaceKHR_t)ptr); + ptr = dlsym(gles_android,"eglUnlockSurfaceKHR"); disp->set_eglUnlockSurfaceKHR((eglUnlockSurfaceKHR_t)ptr); + ptr = dlsym(gles_android,"eglCreateImageKHR"); disp->set_eglCreateImageKHR((eglCreateImageKHR_t)ptr); + ptr = dlsym(gles_android,"eglDestroyImageKHR"); disp->set_eglDestroyImageKHR((eglDestroyImageKHR_t)ptr); + ptr = dlsym(gles_android,"eglCreateSyncKHR"); disp->set_eglCreateSyncKHR((eglCreateSyncKHR_t)ptr); + ptr = dlsym(gles_android,"eglDestroySyncKHR"); disp->set_eglDestroySyncKHR((eglDestroySyncKHR_t)ptr); + ptr = dlsym(gles_android,"eglClientWaitSyncKHR"); disp->set_eglClientWaitSyncKHR((eglClientWaitSyncKHR_t)ptr); + ptr = dlsym(gles_android,"eglSignalSyncKHR"); disp->set_eglSignalSyncKHR((eglSignalSyncKHR_t)ptr); + ptr = dlsym(gles_android,"eglGetSyncAttribKHR"); disp->set_eglGetSyncAttribKHR((eglGetSyncAttribKHR_t)ptr); + ptr = dlsym(gles_android,"eglSetSwapRectangleANDROID"); disp->set_eglSetSwapRectangleANDROID((eglSetSwapRectangleANDROID_t)ptr); + + return disp; +} diff --git a/emulator/opengl/tests/gles_android_wrapper/egl_dispatch.h b/emulator/opengl/tests/gles_android_wrapper/egl_dispatch.h new file mode 100644 index 0000000..1b8de0d --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/egl_dispatch.h @@ -0,0 +1,115 @@ +/* +* 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 egl_dispatch { + 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; + //Accessors + eglGetError_t set_eglGetError(eglGetError_t f) { eglGetError_t retval = eglGetError; eglGetError = f; return retval;} + eglGetDisplay_t set_eglGetDisplay(eglGetDisplay_t f) { eglGetDisplay_t retval = eglGetDisplay; eglGetDisplay = f; return retval;} + eglInitialize_t set_eglInitialize(eglInitialize_t f) { eglInitialize_t retval = eglInitialize; eglInitialize = f; return retval;} + eglTerminate_t set_eglTerminate(eglTerminate_t f) { eglTerminate_t retval = eglTerminate; eglTerminate = f; return retval;} + eglQueryString_t set_eglQueryString(eglQueryString_t f) { eglQueryString_t retval = eglQueryString; eglQueryString = f; return retval;} + eglGetConfigs_t set_eglGetConfigs(eglGetConfigs_t f) { eglGetConfigs_t retval = eglGetConfigs; eglGetConfigs = f; return retval;} + eglChooseConfig_t set_eglChooseConfig(eglChooseConfig_t f) { eglChooseConfig_t retval = eglChooseConfig; eglChooseConfig = f; return retval;} + eglGetConfigAttrib_t set_eglGetConfigAttrib(eglGetConfigAttrib_t f) { eglGetConfigAttrib_t retval = eglGetConfigAttrib; eglGetConfigAttrib = f; return retval;} + eglCreateWindowSurface_t set_eglCreateWindowSurface(eglCreateWindowSurface_t f) { eglCreateWindowSurface_t retval = eglCreateWindowSurface; eglCreateWindowSurface = f; return retval;} + eglCreatePbufferSurface_t set_eglCreatePbufferSurface(eglCreatePbufferSurface_t f) { eglCreatePbufferSurface_t retval = eglCreatePbufferSurface; eglCreatePbufferSurface = f; return retval;} + eglCreatePixmapSurface_t set_eglCreatePixmapSurface(eglCreatePixmapSurface_t f) { eglCreatePixmapSurface_t retval = eglCreatePixmapSurface; eglCreatePixmapSurface = f; return retval;} + eglDestroySurface_t set_eglDestroySurface(eglDestroySurface_t f) { eglDestroySurface_t retval = eglDestroySurface; eglDestroySurface = f; return retval;} + eglQuerySurface_t set_eglQuerySurface(eglQuerySurface_t f) { eglQuerySurface_t retval = eglQuerySurface; eglQuerySurface = f; return retval;} + eglBindAPI_t set_eglBindAPI(eglBindAPI_t f) { eglBindAPI_t retval = eglBindAPI; eglBindAPI = f; return retval;} + eglQueryAPI_t set_eglQueryAPI(eglQueryAPI_t f) { eglQueryAPI_t retval = eglQueryAPI; eglQueryAPI = f; return retval;} + eglWaitClient_t set_eglWaitClient(eglWaitClient_t f) { eglWaitClient_t retval = eglWaitClient; eglWaitClient = f; return retval;} + eglReleaseThread_t set_eglReleaseThread(eglReleaseThread_t f) { eglReleaseThread_t retval = eglReleaseThread; eglReleaseThread = f; return retval;} + eglCreatePbufferFromClientBuffer_t set_eglCreatePbufferFromClientBuffer(eglCreatePbufferFromClientBuffer_t f) { eglCreatePbufferFromClientBuffer_t retval = eglCreatePbufferFromClientBuffer; eglCreatePbufferFromClientBuffer = f; return retval;} + eglSurfaceAttrib_t set_eglSurfaceAttrib(eglSurfaceAttrib_t f) { eglSurfaceAttrib_t retval = eglSurfaceAttrib; eglSurfaceAttrib = f; return retval;} + eglBindTexImage_t set_eglBindTexImage(eglBindTexImage_t f) { eglBindTexImage_t retval = eglBindTexImage; eglBindTexImage = f; return retval;} + eglReleaseTexImage_t set_eglReleaseTexImage(eglReleaseTexImage_t f) { eglReleaseTexImage_t retval = eglReleaseTexImage; eglReleaseTexImage = f; return retval;} + eglSwapInterval_t set_eglSwapInterval(eglSwapInterval_t f) { eglSwapInterval_t retval = eglSwapInterval; eglSwapInterval = f; return retval;} + eglCreateContext_t set_eglCreateContext(eglCreateContext_t f) { eglCreateContext_t retval = eglCreateContext; eglCreateContext = f; return retval;} + eglDestroyContext_t set_eglDestroyContext(eglDestroyContext_t f) { eglDestroyContext_t retval = eglDestroyContext; eglDestroyContext = f; return retval;} + eglMakeCurrent_t set_eglMakeCurrent(eglMakeCurrent_t f) { eglMakeCurrent_t retval = eglMakeCurrent; eglMakeCurrent = f; return retval;} + eglGetCurrentContext_t set_eglGetCurrentContext(eglGetCurrentContext_t f) { eglGetCurrentContext_t retval = eglGetCurrentContext; eglGetCurrentContext = f; return retval;} + eglGetCurrentSurface_t set_eglGetCurrentSurface(eglGetCurrentSurface_t f) { eglGetCurrentSurface_t retval = eglGetCurrentSurface; eglGetCurrentSurface = f; return retval;} + eglGetCurrentDisplay_t set_eglGetCurrentDisplay(eglGetCurrentDisplay_t f) { eglGetCurrentDisplay_t retval = eglGetCurrentDisplay; eglGetCurrentDisplay = f; return retval;} + eglQueryContext_t set_eglQueryContext(eglQueryContext_t f) { eglQueryContext_t retval = eglQueryContext; eglQueryContext = f; return retval;} + eglWaitGL_t set_eglWaitGL(eglWaitGL_t f) { eglWaitGL_t retval = eglWaitGL; eglWaitGL = f; return retval;} + eglWaitNative_t set_eglWaitNative(eglWaitNative_t f) { eglWaitNative_t retval = eglWaitNative; eglWaitNative = f; return retval;} + eglSwapBuffers_t set_eglSwapBuffers(eglSwapBuffers_t f) { eglSwapBuffers_t retval = eglSwapBuffers; eglSwapBuffers = f; return retval;} + eglCopyBuffers_t set_eglCopyBuffers(eglCopyBuffers_t f) { eglCopyBuffers_t retval = eglCopyBuffers; eglCopyBuffers = f; return retval;} + eglGetProcAddress_t set_eglGetProcAddress(eglGetProcAddress_t f) { eglGetProcAddress_t retval = eglGetProcAddress; eglGetProcAddress = f; return retval;} + eglLockSurfaceKHR_t set_eglLockSurfaceKHR(eglLockSurfaceKHR_t f) { eglLockSurfaceKHR_t retval = eglLockSurfaceKHR; eglLockSurfaceKHR = f; return retval;} + eglUnlockSurfaceKHR_t set_eglUnlockSurfaceKHR(eglUnlockSurfaceKHR_t f) { eglUnlockSurfaceKHR_t retval = eglUnlockSurfaceKHR; eglUnlockSurfaceKHR = f; return retval;} + eglCreateImageKHR_t set_eglCreateImageKHR(eglCreateImageKHR_t f) { eglCreateImageKHR_t retval = eglCreateImageKHR; eglCreateImageKHR = f; return retval;} + eglDestroyImageKHR_t set_eglDestroyImageKHR(eglDestroyImageKHR_t f) { eglDestroyImageKHR_t retval = eglDestroyImageKHR; eglDestroyImageKHR = f; return retval;} + eglCreateSyncKHR_t set_eglCreateSyncKHR(eglCreateSyncKHR_t f) { eglCreateSyncKHR_t retval = eglCreateSyncKHR; eglCreateSyncKHR = f; return retval;} + eglDestroySyncKHR_t set_eglDestroySyncKHR(eglDestroySyncKHR_t f) { eglDestroySyncKHR_t retval = eglDestroySyncKHR; eglDestroySyncKHR = f; return retval;} + eglClientWaitSyncKHR_t set_eglClientWaitSyncKHR(eglClientWaitSyncKHR_t f) { eglClientWaitSyncKHR_t retval = eglClientWaitSyncKHR; eglClientWaitSyncKHR = f; return retval;} + eglSignalSyncKHR_t set_eglSignalSyncKHR(eglSignalSyncKHR_t f) { eglSignalSyncKHR_t retval = eglSignalSyncKHR; eglSignalSyncKHR = f; return retval;} + eglGetSyncAttribKHR_t set_eglGetSyncAttribKHR(eglGetSyncAttribKHR_t f) { eglGetSyncAttribKHR_t retval = eglGetSyncAttribKHR; eglGetSyncAttribKHR = f; return retval;} + eglSetSwapRectangleANDROID_t set_eglSetSwapRectangleANDROID(eglSetSwapRectangleANDROID_t f) { eglSetSwapRectangleANDROID_t retval = eglSetSwapRectangleANDROID; eglSetSwapRectangleANDROID = f; return retval;} +}; + +egl_dispatch *create_egl_dispatch(void *gles_andorid); + +#endif diff --git a/emulator/opengl/tests/gles_android_wrapper/egl_ftable.h b/emulator/opengl/tests/gles_android_wrapper/egl_ftable.h new file mode 100644 index 0000000..ee40585 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/egl_ftable.h @@ -0,0 +1,66 @@ +/* +* 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. +*/ +static struct _egl_funcs_by_name { + const char *name; + void *proc; +} egl_funcs_by_name[] = { + {"eglGetError", (void *)eglGetError}, + {"eglGetDisplay", (void *)eglGetDisplay}, + {"eglInitialize", (void *)eglInitialize}, + {"eglTerminate", (void *)eglTerminate}, + {"eglQueryString", (void *)eglQueryString}, + {"eglGetConfigs", (void *)eglGetConfigs}, + {"eglChooseConfig", (void *)eglChooseConfig}, + {"eglGetConfigAttrib", (void *)eglGetConfigAttrib}, + {"eglCreateWindowSurface", (void *)eglCreateWindowSurface}, + {"eglCreatePbufferSurface", (void *)eglCreatePbufferSurface}, + {"eglCreatePixmapSurface", (void *)eglCreatePixmapSurface}, + {"eglDestroySurface", (void *)eglDestroySurface}, + {"eglQuerySurface", (void *)eglQuerySurface}, + {"eglBindAPI", (void *)eglBindAPI}, + {"eglQueryAPI", (void *)eglQueryAPI}, + {"eglWaitClient", (void *)eglWaitClient}, + {"eglReleaseThread", (void *)eglReleaseThread}, + {"eglCreatePbufferFromClientBuffer", (void *)eglCreatePbufferFromClientBuffer}, + {"eglSurfaceAttrib", (void *)eglSurfaceAttrib}, + {"eglBindTexImage", (void *)eglBindTexImage}, + {"eglReleaseTexImage", (void *)eglReleaseTexImage}, + {"eglSwapInterval", (void *)eglSwapInterval}, + {"eglCreateContext", (void *)eglCreateContext}, + {"eglDestroyContext", (void *)eglDestroyContext}, + {"eglMakeCurrent", (void *)eglMakeCurrent}, + {"eglGetCurrentContext", (void *)eglGetCurrentContext}, + {"eglGetCurrentSurface", (void *)eglGetCurrentSurface}, + {"eglGetCurrentDisplay", (void *)eglGetCurrentDisplay}, + {"eglQueryContext", (void *)eglQueryContext}, + {"eglWaitGL", (void *)eglWaitGL}, + {"eglWaitNative", (void *)eglWaitNative}, + {"eglSwapBuffers", (void *)eglSwapBuffers}, + {"eglCopyBuffers", (void *)eglCopyBuffers}, + {"eglGetProcAddress", (void *)eglGetProcAddress}, + {"eglLockSurfaceKHR", (void *)eglLockSurfaceKHR}, + {"eglUnlockSurfaceKHR", (void *)eglUnlockSurfaceKHR}, + {"eglCreateImageKHR", (void *)eglCreateImageKHR}, + {"eglDestroyImageKHR", (void *)eglDestroyImageKHR}, + {"eglCreateSyncKHR", (void *)eglCreateSyncKHR}, + {"eglDestroySyncKHR", (void *)eglDestroySyncKHR}, + {"eglClientWaitSyncKHR", (void *)eglClientWaitSyncKHR}, + {"eglSignalSyncKHR", (void *)eglSignalSyncKHR}, + {"eglGetSyncAttribKHR", (void *)eglGetSyncAttribKHR}, + {"eglSetSwapRectangleANDROID", (void *)eglSetSwapRectangleANDROID} +}; + +static int egl_num_funcs = sizeof(egl_funcs_by_name) / sizeof(struct _egl_funcs_by_name); diff --git a/emulator/opengl/tests/gles_android_wrapper/egl_proc.h b/emulator/opengl/tests/gles_android_wrapper/egl_proc.h new file mode 100644 index 0000000..140c030 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/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 (* eglGetError_t) (); +typedef EGLDisplay (* eglGetDisplay_t) (EGLNativeDisplayType); +typedef EGLBoolean (* eglInitialize_t) (EGLDisplay, EGLint*, EGLint*); +typedef EGLBoolean (* eglTerminate_t) (EGLDisplay); +typedef char* (* eglQueryString_t) (EGLDisplay, EGLint); +typedef EGLBoolean (* eglGetConfigs_t) (EGLDisplay, EGLConfig*, EGLint, EGLint*); +typedef EGLBoolean (* eglChooseConfig_t) (EGLDisplay, const EGLint*, EGLConfig*, EGLint, EGLint*); +typedef EGLBoolean (* eglGetConfigAttrib_t) (EGLDisplay, EGLConfig, EGLint, EGLint*); +typedef EGLSurface (* eglCreateWindowSurface_t) (EGLDisplay, EGLConfig, EGLNativeWindowType, const EGLint*); +typedef EGLSurface (* eglCreatePbufferSurface_t) (EGLDisplay, EGLConfig, const EGLint*); +typedef EGLSurface (* eglCreatePixmapSurface_t) (EGLDisplay, EGLConfig, EGLNativePixmapType, const EGLint*); +typedef EGLBoolean (* eglDestroySurface_t) (EGLDisplay, EGLSurface); +typedef EGLBoolean (* eglQuerySurface_t) (EGLDisplay, EGLSurface, EGLint, EGLint*); +typedef EGLBoolean (* eglBindAPI_t) (EGLenum); +typedef EGLenum (* eglQueryAPI_t) (); +typedef EGLBoolean (* eglWaitClient_t) (); +typedef EGLBoolean (* eglReleaseThread_t) (); +typedef EGLSurface (* eglCreatePbufferFromClientBuffer_t) (EGLDisplay, EGLenum, EGLClientBuffer, EGLConfig, const EGLint*); +typedef EGLBoolean (* eglSurfaceAttrib_t) (EGLDisplay, EGLSurface, EGLint, EGLint); +typedef EGLBoolean (* eglBindTexImage_t) (EGLDisplay, EGLSurface, EGLint); +typedef EGLBoolean (* eglReleaseTexImage_t) (EGLDisplay, EGLSurface, EGLint); +typedef EGLBoolean (* eglSwapInterval_t) (EGLDisplay, EGLint); +typedef EGLContext (* eglCreateContext_t) (EGLDisplay, EGLConfig, EGLContext, const EGLint*); +typedef EGLBoolean (* eglDestroyContext_t) (EGLDisplay, EGLContext); +typedef EGLBoolean (* eglMakeCurrent_t) (EGLDisplay, EGLSurface, EGLSurface, EGLContext); +typedef EGLContext (* eglGetCurrentContext_t) (); +typedef EGLSurface (* eglGetCurrentSurface_t) (EGLint); +typedef EGLDisplay (* eglGetCurrentDisplay_t) (); +typedef EGLBoolean (* eglQueryContext_t) (EGLDisplay, EGLContext, EGLint, EGLint*); +typedef EGLBoolean (* eglWaitGL_t) (); +typedef EGLBoolean (* eglWaitNative_t) (EGLint); +typedef EGLBoolean (* eglSwapBuffers_t) (EGLDisplay, EGLSurface); +typedef EGLBoolean (* eglCopyBuffers_t) (EGLDisplay, EGLSurface, EGLNativePixmapType); +typedef __eglMustCastToProperFunctionPointerType (* eglGetProcAddress_t) (const char*); +typedef EGLBoolean (* eglLockSurfaceKHR_t) (EGLDisplay, EGLSurface, const EGLint*); +typedef EGLBoolean (* eglUnlockSurfaceKHR_t) (EGLDisplay, EGLSurface); +typedef EGLImageKHR (* eglCreateImageKHR_t) (EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const EGLint*); +typedef EGLBoolean (* eglDestroyImageKHR_t) (EGLDisplay, EGLImageKHR image); +typedef EGLSyncKHR (* eglCreateSyncKHR_t) (EGLDisplay, EGLenum, const EGLint*); +typedef EGLBoolean (* eglDestroySyncKHR_t) (EGLDisplay, EGLSyncKHR sync); +typedef EGLint (* eglClientWaitSyncKHR_t) (EGLDisplay, EGLSyncKHR, EGLint, EGLTimeKHR timeout); +typedef EGLBoolean (* eglSignalSyncKHR_t) (EGLDisplay, EGLSyncKHR, EGLenum); +typedef EGLBoolean (* eglGetSyncAttribKHR_t) (EGLDisplay, EGLSyncKHR, EGLint, EGLint*); +typedef EGLBoolean (* eglSetSwapRectangleANDROID_t) (EGLDisplay, EGLSurface, EGLint, EGLint, EGLint, EGLint); + +#endif // of _EGL_PROC_H diff --git a/emulator/opengl/tests/gles_android_wrapper/gles.cpp b/emulator/opengl/tests/gles_android_wrapper/gles.cpp new file mode 100644 index 0000000..c0949c8 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/gles.cpp @@ -0,0 +1,1410 @@ +/* +* 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 <string.h> +#include "gles_dispatch.h" +#include "gles_ftable.h" +#include <EGL/egl.h> +#include <cutils/log.h> + +static struct gles_dispatch *s_dispatch = NULL; + +void init_gles(void *gles_android) +{ + s_dispatch = create_gles_dispatch(gles_android); + if (s_dispatch == NULL) { + ALOGE("failed to create gles dispatch\n"); + } +} + +static struct gles_dispatch *getDispatch() +{ + if (!s_dispatch) { + fprintf(stderr,"FATAL ERROR: GLES has not been initialized\n"); + exit(-1); + } + + return s_dispatch; +} + +__eglMustCastToProperFunctionPointerType gles_getProcAddress(const char *procname) +{ + for (int i=0; i<gles_num_funcs; i++) { + if (!strcmp(gles_funcs_by_name[i].name, procname)) { + return (__eglMustCastToProperFunctionPointerType)gles_funcs_by_name[i].proc; + } + } + + return NULL; +} + +///////////// Path-through functions /////////////// +void glAlphaFunc(GLenum func, GLclampf ref) +{ + getDispatch()->glAlphaFunc(func, ref); +} + +void glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) +{ + getDispatch()->glClearColor(red, green, blue, alpha); +} + +void glClearDepthf(GLclampf depth) +{ + getDispatch()->glClearDepthf(depth); +} + +void glClipPlanef(GLenum plane, const GLfloat *equation) +{ + getDispatch()->glClipPlanef(plane, equation); +} + +void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) +{ + getDispatch()->glColor4f(red, green, blue, alpha); +} + +void glDepthRangef(GLclampf zNear, GLclampf zFar) +{ + getDispatch()->glDepthRangef(zNear, zFar); +} + +void glFogf(GLenum pname, GLfloat param) +{ + getDispatch()->glFogf(pname, param); +} + +void glFogfv(GLenum pname, const GLfloat *params) +{ + getDispatch()->glFogfv(pname, params); +} + +void glFrustumf(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) +{ + getDispatch()->glFrustumf(left, right, bottom, top, zNear, zFar); +} + +void glGetClipPlanef(GLenum pname, GLfloat eqn[4]) +{ + getDispatch()->glGetClipPlanef(pname, eqn); +} + +void glGetFloatv(GLenum pname, GLfloat *params) +{ + getDispatch()->glGetFloatv(pname, params); +} + +void glGetLightfv(GLenum light, GLenum pname, GLfloat *params) +{ + getDispatch()->glGetLightfv(light, pname, params); +} + +void glGetMaterialfv(GLenum face, GLenum pname, GLfloat *params) +{ + getDispatch()->glGetMaterialfv(face, pname, params); +} + +void glGetTexEnvfv(GLenum env, GLenum pname, GLfloat *params) +{ + getDispatch()->glGetTexEnvfv(env, pname, params); +} + +void glGetTexParameterfv(GLenum target, GLenum pname, GLfloat *params) +{ + getDispatch()->glGetTexParameterfv(target, pname, params); +} + +void glLightModelf(GLenum pname, GLfloat param) +{ + getDispatch()->glLightModelf(pname, param); +} + +void glLightModelfv(GLenum pname, const GLfloat *params) +{ + getDispatch()->glLightModelfv(pname, params); +} + +void glLightf(GLenum light, GLenum pname, GLfloat param) +{ + getDispatch()->glLightf(light, pname, param); +} + +void glLightfv(GLenum light, GLenum pname, const GLfloat *params) +{ + getDispatch()->glLightfv(light, pname, params); +} + +void glLineWidth(GLfloat width) +{ + getDispatch()->glLineWidth(width); +} + +void glLoadMatrixf(const GLfloat *m) +{ + getDispatch()->glLoadMatrixf(m); +} + +void glMaterialf(GLenum face, GLenum pname, GLfloat param) +{ + getDispatch()->glMaterialf(face, pname, param); +} + +void glMaterialfv(GLenum face, GLenum pname, const GLfloat *params) +{ + getDispatch()->glMaterialfv(face, pname, params); +} + +void glMultMatrixf(const GLfloat *m) +{ + getDispatch()->glMultMatrixf(m); +} + +void glMultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) +{ + getDispatch()->glMultiTexCoord4f(target, s, t, r, q); +} + +void glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz) +{ + getDispatch()->glNormal3f(nx, ny, nz); +} + +void glOrthof(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) +{ + getDispatch()->glOrthof(left, right, bottom, top, zNear, zFar); +} + +void glPointParameterf(GLenum pname, GLfloat param) +{ + getDispatch()->glPointParameterf(pname, param); +} + +void glPointParameterfv(GLenum pname, const GLfloat *params) +{ + getDispatch()->glPointParameterfv(pname, params); +} + +void glPointSize(GLfloat size) +{ + getDispatch()->glPointSize(size); +} + +void glPolygonOffset(GLfloat factor, GLfloat units) +{ + getDispatch()->glPolygonOffset(factor, units); +} + +void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) +{ + getDispatch()->glRotatef(angle, x, y, z); +} + +void glScalef(GLfloat x, GLfloat y, GLfloat z) +{ + getDispatch()->glScalef(x, y, z); +} + +void glTexEnvf(GLenum target, GLenum pname, GLfloat param) +{ + getDispatch()->glTexEnvf(target, pname, param); +} + +void glTexEnvfv(GLenum target, GLenum pname, const GLfloat *params) +{ + getDispatch()->glTexEnvfv(target, pname, params); +} + +void glTexParameterf(GLenum target, GLenum pname, GLfloat param) +{ + getDispatch()->glTexParameterf(target, pname, param); +} + +void glTexParameterfv(GLenum target, GLenum pname, const GLfloat *params) +{ + getDispatch()->glTexParameterfv(target, pname, params); +} + +void glTranslatef(GLfloat x, GLfloat y, GLfloat z) +{ + getDispatch()->glTranslatef(x, y, z); +} + +void glActiveTexture(GLenum texture) +{ + getDispatch()->glActiveTexture(texture); +} + +void glAlphaFuncx(GLenum func, GLclampx ref) +{ + getDispatch()->glAlphaFuncx(func, ref); +} + +void glBindBuffer(GLenum target, GLuint buffer) +{ + getDispatch()->glBindBuffer(target, buffer); +} + +void glBindTexture(GLenum target, GLuint texture) +{ + getDispatch()->glBindTexture(target, texture); +} + +void glBlendFunc(GLenum sfactor, GLenum dfactor) +{ + getDispatch()->glBlendFunc(sfactor, dfactor); +} + +void glBufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage) +{ + getDispatch()->glBufferData(target, size, data, usage); +} + +void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data) +{ + getDispatch()->glBufferSubData(target, offset, size, data); +} + +void glClear(GLbitfield mask) +{ + getDispatch()->glClear(mask); +} + +void glClearColorx(GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha) +{ + getDispatch()->glClearColorx(red, green, blue, alpha); +} + +void glClearDepthx(GLclampx depth) +{ + getDispatch()->glClearDepthx(depth); +} + +void glClearStencil(GLint s) +{ + getDispatch()->glClearStencil(s); +} + +void glClientActiveTexture(GLenum texture) +{ + getDispatch()->glClientActiveTexture(texture); +} + +void glClipPlanex(GLenum plane, const GLfixed *equation) +{ + getDispatch()->glClipPlanex(plane, equation); +} + +void glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) +{ + getDispatch()->glColor4ub(red, green, blue, alpha); +} + +void glColor4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha) +{ + getDispatch()->glColor4x(red, green, blue, alpha); +} + +void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) +{ + getDispatch()->glColorMask(red, green, blue, alpha); +} + +void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) +{ + getDispatch()->glColorPointer(size, type, stride, pointer); +} + +void glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) +{ + getDispatch()->glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data); +} + +void glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data) +{ + getDispatch()->glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data); +} + +void glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) +{ + getDispatch()->glCopyTexImage2D(target, level, internalformat, x, y, width, height, border); +} + +void glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) +{ + getDispatch()->glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); +} + +void glCullFace(GLenum mode) +{ + getDispatch()->glCullFace(mode); +} + +void glDeleteBuffers(GLsizei n, const GLuint *buffers) +{ + getDispatch()->glDeleteBuffers(n, buffers); +} + +void glDeleteTextures(GLsizei n, const GLuint *textures) +{ + getDispatch()->glDeleteTextures(n, textures); +} + +void glDepthFunc(GLenum func) +{ + getDispatch()->glDepthFunc(func); +} + +void glDepthMask(GLboolean flag) +{ + getDispatch()->glDepthMask(flag); +} + +void glDepthRangex(GLclampx zNear, GLclampx zFar) +{ + getDispatch()->glDepthRangex(zNear, zFar); +} + +void glDisable(GLenum cap) +{ + getDispatch()->glDisable(cap); +} + +void glDisableClientState(GLenum array) +{ + getDispatch()->glDisableClientState(array); +} + +void glDrawArrays(GLenum mode, GLint first, GLsizei count) +{ + getDispatch()->glDrawArrays(mode, first, count); +} + +void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) +{ + getDispatch()->glDrawElements(mode, count, type, indices); +} + +void glEnable(GLenum cap) +{ + getDispatch()->glEnable(cap); +} + +void glEnableClientState(GLenum array) +{ + getDispatch()->glEnableClientState(array); +} + +void glFinish() +{ + getDispatch()->glFinish(); +} + +void glFlush() +{ + getDispatch()->glFlush(); +} + +void glFogx(GLenum pname, GLfixed param) +{ + getDispatch()->glFogx(pname, param); +} + +void glFogxv(GLenum pname, const GLfixed *params) +{ + getDispatch()->glFogxv(pname, params); +} + +void glFrontFace(GLenum mode) +{ + getDispatch()->glFrontFace(mode); +} + +void glFrustumx(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) +{ + getDispatch()->glFrustumx(left, right, bottom, top, zNear, zFar); +} + +void glGetBooleanv(GLenum pname, GLboolean *params) +{ + getDispatch()->glGetBooleanv(pname, params); +} + +void glGetBufferParameteriv(GLenum target, GLenum pname, GLint *params) +{ + getDispatch()->glGetBufferParameteriv(target, pname, params); +} + +void glGetClipPlanex(GLenum pname, GLfixed eqn[4]) +{ + getDispatch()->glGetClipPlanex(pname, eqn); +} + +void glGenBuffers(GLsizei n, GLuint *buffers) +{ + getDispatch()->glGenBuffers(n, buffers); +} + +void glGenTextures(GLsizei n, GLuint *textures) +{ + getDispatch()->glGenTextures(n, textures); +} + +GLenum glGetError() +{ + return getDispatch()->glGetError(); +} + +void glGetFixedv(GLenum pname, GLfixed *params) +{ + getDispatch()->glGetFixedv(pname, params); +} + +void glGetIntegerv(GLenum pname, GLint *params) +{ + getDispatch()->glGetIntegerv(pname, params); +} + +void glGetLightxv(GLenum light, GLenum pname, GLfixed *params) +{ + getDispatch()->glGetLightxv(light, pname, params); +} + +void glGetMaterialxv(GLenum face, GLenum pname, GLfixed *params) +{ + getDispatch()->glGetMaterialxv(face, pname, params); +} + +void glGetPointerv(GLenum pname, GLvoid **params) +{ + getDispatch()->glGetPointerv(pname, params); +} + +const GLubyte* glGetString(GLenum name) +{ + return getDispatch()->glGetString(name); +} + +void glGetTexEnviv(GLenum env, GLenum pname, GLint *params) +{ + getDispatch()->glGetTexEnviv(env, pname, params); +} + +void glGetTexEnvxv(GLenum env, GLenum pname, GLfixed *params) +{ + getDispatch()->glGetTexEnvxv(env, pname, params); +} + +void glGetTexParameteriv(GLenum target, GLenum pname, GLint *params) +{ + getDispatch()->glGetTexParameteriv(target, pname, params); +} + +void glGetTexParameterxv(GLenum target, GLenum pname, GLfixed *params) +{ + getDispatch()->glGetTexParameterxv(target, pname, params); +} + +void glHint(GLenum target, GLenum mode) +{ + getDispatch()->glHint(target, mode); +} + +GLboolean glIsBuffer(GLuint buffer) +{ + return getDispatch()->glIsBuffer(buffer); +} + +GLboolean glIsEnabled(GLenum cap) +{ + return getDispatch()->glIsEnabled(cap); +} + +GLboolean glIsTexture(GLuint texture) +{ + return getDispatch()->glIsTexture(texture); +} + +void glLightModelx(GLenum pname, GLfixed param) +{ + getDispatch()->glLightModelx(pname, param); +} + +void glLightModelxv(GLenum pname, const GLfixed *params) +{ + getDispatch()->glLightModelxv(pname, params); +} + +void glLightx(GLenum light, GLenum pname, GLfixed param) +{ + getDispatch()->glLightx(light, pname, param); +} + +void glLightxv(GLenum light, GLenum pname, const GLfixed *params) +{ + getDispatch()->glLightxv(light, pname, params); +} + +void glLineWidthx(GLfixed width) +{ + getDispatch()->glLineWidthx(width); +} + +void glLoadIdentity() +{ + getDispatch()->glLoadIdentity(); +} + +void glLoadMatrixx(const GLfixed *m) +{ + getDispatch()->glLoadMatrixx(m); +} + +void glLogicOp(GLenum opcode) +{ + getDispatch()->glLogicOp(opcode); +} + +void glMaterialx(GLenum face, GLenum pname, GLfixed param) +{ + getDispatch()->glMaterialx(face, pname, param); +} + +void glMaterialxv(GLenum face, GLenum pname, const GLfixed *params) +{ + getDispatch()->glMaterialxv(face, pname, params); +} + +void glMatrixMode(GLenum mode) +{ + getDispatch()->glMatrixMode(mode); +} + +void glMultMatrixx(const GLfixed *m) +{ + getDispatch()->glMultMatrixx(m); +} + +void glMultiTexCoord4x(GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q) +{ + getDispatch()->glMultiTexCoord4x(target, s, t, r, q); +} + +void glNormal3x(GLfixed nx, GLfixed ny, GLfixed nz) +{ + getDispatch()->glNormal3x(nx, ny, nz); +} + +void glNormalPointer(GLenum type, GLsizei stride, const GLvoid *pointer) +{ + getDispatch()->glNormalPointer(type, stride, pointer); +} + +void glOrthox(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) +{ + getDispatch()->glOrthox(left, right, bottom, top, zNear, zFar); +} + +void glPixelStorei(GLenum pname, GLint param) +{ + getDispatch()->glPixelStorei(pname, param); +} + +void glPointParameterx(GLenum pname, GLfixed param) +{ + getDispatch()->glPointParameterx(pname, param); +} + +void glPointParameterxv(GLenum pname, const GLfixed *params) +{ + getDispatch()->glPointParameterxv(pname, params); +} + +void glPointSizex(GLfixed size) +{ + getDispatch()->glPointSizex(size); +} + +void glPolygonOffsetx(GLfixed factor, GLfixed units) +{ + getDispatch()->glPolygonOffsetx(factor, units); +} + +void glPopMatrix() +{ + getDispatch()->glPopMatrix(); +} + +void glPushMatrix() +{ + getDispatch()->glPushMatrix(); +} + +void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) +{ + getDispatch()->glReadPixels(x, y, width, height, format, type, pixels); +} + +void glRotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z) +{ + getDispatch()->glRotatex(angle, x, y, z); +} + +void glSampleCoverage(GLclampf value, GLboolean invert) +{ + getDispatch()->glSampleCoverage(value, invert); +} + +void glSampleCoveragex(GLclampx value, GLboolean invert) +{ + getDispatch()->glSampleCoveragex(value, invert); +} + +void glScalex(GLfixed x, GLfixed y, GLfixed z) +{ + getDispatch()->glScalex(x, y, z); +} + +void glScissor(GLint x, GLint y, GLsizei width, GLsizei height) +{ + getDispatch()->glScissor(x, y, width, height); +} + +void glShadeModel(GLenum mode) +{ + getDispatch()->glShadeModel(mode); +} + +void glStencilFunc(GLenum func, GLint ref, GLuint mask) +{ + getDispatch()->glStencilFunc(func, ref, mask); +} + +void glStencilMask(GLuint mask) +{ + getDispatch()->glStencilMask(mask); +} + +void glStencilOp(GLenum fail, GLenum zfail, GLenum zpass) +{ + getDispatch()->glStencilOp(fail, zfail, zpass); +} + +void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) +{ + getDispatch()->glTexCoordPointer(size, type, stride, pointer); +} + +void glTexEnvi(GLenum target, GLenum pname, GLint param) +{ + getDispatch()->glTexEnvi(target, pname, param); +} + +void glTexEnvx(GLenum target, GLenum pname, GLfixed param) +{ + getDispatch()->glTexEnvx(target, pname, param); +} + +void glTexEnviv(GLenum target, GLenum pname, const GLint *params) +{ + getDispatch()->glTexEnviv(target, pname, params); +} + +void glTexEnvxv(GLenum target, GLenum pname, const GLfixed *params) +{ + getDispatch()->glTexEnvxv(target, pname, params); +} + +void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels) +{ + getDispatch()->glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels); +} + +void glTexParameteri(GLenum target, GLenum pname, GLint param) +{ + getDispatch()->glTexParameteri(target, pname, param); +} + +void glTexParameterx(GLenum target, GLenum pname, GLfixed param) +{ + getDispatch()->glTexParameterx(target, pname, param); +} + +void glTexParameteriv(GLenum target, GLenum pname, const GLint *params) +{ + getDispatch()->glTexParameteriv(target, pname, params); +} + +void glTexParameterxv(GLenum target, GLenum pname, const GLfixed *params) +{ + getDispatch()->glTexParameterxv(target, pname, params); +} + +void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels) +{ + getDispatch()->glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); +} + +void glTranslatex(GLfixed x, GLfixed y, GLfixed z) +{ + getDispatch()->glTranslatex(x, y, z); +} + +void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) +{ + getDispatch()->glVertexPointer(size, type, stride, pointer); +} + +void glViewport(GLint x, GLint y, GLsizei width, GLsizei height) +{ + getDispatch()->glViewport(x, y, width, height); +} + +void glPointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *pointer) +{ + getDispatch()->glPointSizePointerOES(type, stride, pointer); +} + +void glBlendEquationSeparateOES(GLenum modeRGB, GLenum modeAlpha) +{ + getDispatch()->glBlendEquationSeparateOES(modeRGB, modeAlpha); +} + +void glBlendFuncSeparateOES(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) +{ + getDispatch()->glBlendFuncSeparateOES(srcRGB, dstRGB, srcAlpha, dstAlpha); +} + +void glBlendEquationOES(GLenum mode) +{ + getDispatch()->glBlendEquationOES(mode); +} + +void glDrawTexsOES(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height) +{ + getDispatch()->glDrawTexsOES(x, y, z, width, height); +} + +void glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height) +{ + getDispatch()->glDrawTexiOES(x, y, z, width, height); +} + +void glDrawTexxOES(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height) +{ + getDispatch()->glDrawTexxOES(x, y, z, width, height); +} + +void glDrawTexsvOES(const GLshort *coords) +{ + getDispatch()->glDrawTexsvOES(coords); +} + +void glDrawTexivOES(const GLint *coords) +{ + getDispatch()->glDrawTexivOES(coords); +} + +void glDrawTexxvOES(const GLfixed *coords) +{ + getDispatch()->glDrawTexxvOES(coords); +} + +void glDrawTexfOES(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height) +{ + getDispatch()->glDrawTexfOES(x, y, z, width, height); +} + +void glDrawTexfvOES(const GLfloat *coords) +{ + getDispatch()->glDrawTexfvOES(coords); +} + +void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) +{ + getDispatch()->glEGLImageTargetTexture2DOES(target, image); +} + +void glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image) +{ + getDispatch()->glEGLImageTargetRenderbufferStorageOES(target, image); +} + +void glAlphaFuncxOES(GLenum func, GLclampx ref) +{ + getDispatch()->glAlphaFuncxOES(func, ref); +} + +void glClearColorxOES(GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha) +{ + getDispatch()->glClearColorxOES(red, green, blue, alpha); +} + +void glClearDepthxOES(GLclampx depth) +{ + getDispatch()->glClearDepthxOES(depth); +} + +void glClipPlanexOES(GLenum plane, const GLfixed *equation) +{ + getDispatch()->glClipPlanexOES(plane, equation); +} + +void glColor4xOES(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha) +{ + getDispatch()->glColor4xOES(red, green, blue, alpha); +} + +void glDepthRangexOES(GLclampx zNear, GLclampx zFar) +{ + getDispatch()->glDepthRangexOES(zNear, zFar); +} + +void glFogxOES(GLenum pname, GLfixed param) +{ + getDispatch()->glFogxOES(pname, param); +} + +void glFogxvOES(GLenum pname, const GLfixed *params) +{ + getDispatch()->glFogxvOES(pname, params); +} + +void glFrustumxOES(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) +{ + getDispatch()->glFrustumxOES(left, right, bottom, top, zNear, zFar); +} + +void glGetClipPlanexOES(GLenum pname, GLfixed eqn[4]) +{ + getDispatch()->glGetClipPlanexOES(pname, eqn); +} + +void glGetFixedvOES(GLenum pname, GLfixed *params) +{ + getDispatch()->glGetFixedvOES(pname, params); +} + +void glGetLightxvOES(GLenum light, GLenum pname, GLfixed *params) +{ + getDispatch()->glGetLightxvOES(light, pname, params); +} + +void glGetMaterialxvOES(GLenum face, GLenum pname, GLfixed *params) +{ + getDispatch()->glGetMaterialxvOES(face, pname, params); +} + +void glGetTexEnvxvOES(GLenum env, GLenum pname, GLfixed *params) +{ + getDispatch()->glGetTexEnvxvOES(env, pname, params); +} + +void glGetTexParameterxvOES(GLenum target, GLenum pname, GLfixed *params) +{ + getDispatch()->glGetTexParameterxvOES(target, pname, params); +} + +void glLightModelxOES(GLenum pname, GLfixed param) +{ + getDispatch()->glLightModelxOES(pname, param); +} + +void glLightModelxvOES(GLenum pname, const GLfixed *params) +{ + getDispatch()->glLightModelxvOES(pname, params); +} + +void glLightxOES(GLenum light, GLenum pname, GLfixed param) +{ + getDispatch()->glLightxOES(light, pname, param); +} + +void glLightxvOES(GLenum light, GLenum pname, const GLfixed *params) +{ + getDispatch()->glLightxvOES(light, pname, params); +} + +void glLineWidthxOES(GLfixed width) +{ + getDispatch()->glLineWidthxOES(width); +} + +void glLoadMatrixxOES(const GLfixed *m) +{ + getDispatch()->glLoadMatrixxOES(m); +} + +void glMaterialxOES(GLenum face, GLenum pname, GLfixed param) +{ + getDispatch()->glMaterialxOES(face, pname, param); +} + +void glMaterialxvOES(GLenum face, GLenum pname, const GLfixed *params) +{ + getDispatch()->glMaterialxvOES(face, pname, params); +} + +void glMultMatrixxOES(const GLfixed *m) +{ + getDispatch()->glMultMatrixxOES(m); +} + +void glMultiTexCoord4xOES(GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q) +{ + getDispatch()->glMultiTexCoord4xOES(target, s, t, r, q); +} + +void glNormal3xOES(GLfixed nx, GLfixed ny, GLfixed nz) +{ + getDispatch()->glNormal3xOES(nx, ny, nz); +} + +void glOrthoxOES(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar) +{ + getDispatch()->glOrthoxOES(left, right, bottom, top, zNear, zFar); +} + +void glPointParameterxOES(GLenum pname, GLfixed param) +{ + getDispatch()->glPointParameterxOES(pname, param); +} + +void glPointParameterxvOES(GLenum pname, const GLfixed *params) +{ + getDispatch()->glPointParameterxvOES(pname, params); +} + +void glPointSizexOES(GLfixed size) +{ + getDispatch()->glPointSizexOES(size); +} + +void glPolygonOffsetxOES(GLfixed factor, GLfixed units) +{ + getDispatch()->glPolygonOffsetxOES(factor, units); +} + +void glRotatexOES(GLfixed angle, GLfixed x, GLfixed y, GLfixed z) +{ + getDispatch()->glRotatexOES(angle, x, y, z); +} + +void glSampleCoveragexOES(GLclampx value, GLboolean invert) +{ + getDispatch()->glSampleCoveragexOES(value, invert); +} + +void glScalexOES(GLfixed x, GLfixed y, GLfixed z) +{ + getDispatch()->glScalexOES(x, y, z); +} + +void glTexEnvxOES(GLenum target, GLenum pname, GLfixed param) +{ + getDispatch()->glTexEnvxOES(target, pname, param); +} + +void glTexEnvxvOES(GLenum target, GLenum pname, const GLfixed *params) +{ + getDispatch()->glTexEnvxvOES(target, pname, params); +} + +void glTexParameterxOES(GLenum target, GLenum pname, GLfixed param) +{ + getDispatch()->glTexParameterxOES(target, pname, param); +} + +void glTexParameterxvOES(GLenum target, GLenum pname, const GLfixed *params) +{ + getDispatch()->glTexParameterxvOES(target, pname, params); +} + +void glTranslatexOES(GLfixed x, GLfixed y, GLfixed z) +{ + getDispatch()->glTranslatexOES(x, y, z); +} + +GLboolean glIsRenderbufferOES(GLuint renderbuffer) +{ + return getDispatch()->glIsRenderbufferOES(renderbuffer); +} + +void glBindRenderbufferOES(GLenum target, GLuint renderbuffer) +{ + getDispatch()->glBindRenderbufferOES(target, renderbuffer); +} + +void glDeleteRenderbuffersOES(GLsizei n, const GLuint *renderbuffers) +{ + getDispatch()->glDeleteRenderbuffersOES(n, renderbuffers); +} + +void glGenRenderbuffersOES(GLsizei n, GLuint *renderbuffers) +{ + getDispatch()->glGenRenderbuffersOES(n, renderbuffers); +} + +void glRenderbufferStorageOES(GLenum target, GLenum internalformat, GLsizei width, GLsizei height) +{ + getDispatch()->glRenderbufferStorageOES(target, internalformat, width, height); +} + +void glGetRenderbufferParameterivOES(GLenum target, GLenum pname, GLint *params) +{ + getDispatch()->glGetRenderbufferParameterivOES(target, pname, params); +} + +GLboolean glIsFramebufferOES(GLuint framebuffer) +{ + return getDispatch()->glIsFramebufferOES(framebuffer); +} + +void glBindFramebufferOES(GLenum target, GLuint framebuffer) +{ + getDispatch()->glBindFramebufferOES(target, framebuffer); +} + +void glDeleteFramebuffersOES(GLsizei n, const GLuint *framebuffers) +{ + getDispatch()->glDeleteFramebuffersOES(n, framebuffers); +} + +void glGenFramebuffersOES(GLsizei n, GLuint *framebuffers) +{ + getDispatch()->glGenFramebuffersOES(n, framebuffers); +} + +GLenum glCheckFramebufferStatusOES(GLenum target) +{ + return getDispatch()->glCheckFramebufferStatusOES(target); +} + +void glFramebufferRenderbufferOES(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) +{ + getDispatch()->glFramebufferRenderbufferOES(target, attachment, renderbuffertarget, renderbuffer); +} + +void glFramebufferTexture2DOES(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) +{ + getDispatch()->glFramebufferTexture2DOES(target, attachment, textarget, texture, level); +} + +void glGetFramebufferAttachmentParameterivOES(GLenum target, GLenum attachment, GLenum pname, GLint *params) +{ + getDispatch()->glGetFramebufferAttachmentParameterivOES(target, attachment, pname, params); +} + +void glGenerateMipmapOES(GLenum target) +{ + getDispatch()->glGenerateMipmapOES(target); +} + +void* glMapBufferOES(GLenum target, GLenum access) +{ + return getDispatch()->glMapBufferOES(target, access); +} + +GLboolean glUnmapBufferOES(GLenum target) +{ + return getDispatch()->glUnmapBufferOES(target); +} + +void glGetBufferPointervOES(GLenum target, GLenum pname, GLvoid **ptr) +{ + getDispatch()->glGetBufferPointervOES(target, pname, ptr); +} + +void glCurrentPaletteMatrixOES(GLuint matrixpaletteindex) +{ + getDispatch()->glCurrentPaletteMatrixOES(matrixpaletteindex); +} + +void glLoadPaletteFromModelViewMatrixOES() +{ + getDispatch()->glLoadPaletteFromModelViewMatrixOES(); +} + +void glMatrixIndexPointerOES(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) +{ + getDispatch()->glMatrixIndexPointerOES(size, type, stride, pointer); +} + +void glWeightPointerOES(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) +{ + getDispatch()->glWeightPointerOES(size, type, stride, pointer); +} + +GLbitfield glQueryMatrixxOES(GLfixed mantissa[16], GLint exponent[16]) +{ + return getDispatch()->glQueryMatrixxOES(mantissa, exponent); +} + +void glDepthRangefOES(GLclampf zNear, GLclampf zFar) +{ + getDispatch()->glDepthRangefOES(zNear, zFar); +} + +void glFrustumfOES(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) +{ + getDispatch()->glFrustumfOES(left, right, bottom, top, zNear, zFar); +} + +void glOrthofOES(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) +{ + getDispatch()->glOrthofOES(left, right, bottom, top, zNear, zFar); +} + +void glClipPlanefOES(GLenum plane, const GLfloat *equation) +{ + getDispatch()->glClipPlanefOES(plane, equation); +} + +void glGetClipPlanefOES(GLenum pname, GLfloat eqn[4]) +{ + getDispatch()->glGetClipPlanefOES(pname, eqn); +} + +void glClearDepthfOES(GLclampf depth) +{ + getDispatch()->glClearDepthfOES(depth); +} + +void glTexGenfOES(GLenum coord, GLenum pname, GLfloat param) +{ + getDispatch()->glTexGenfOES(coord, pname, param); +} + +void glTexGenfvOES(GLenum coord, GLenum pname, const GLfloat *params) +{ + getDispatch()->glTexGenfvOES(coord, pname, params); +} + +void glTexGeniOES(GLenum coord, GLenum pname, GLint param) +{ + getDispatch()->glTexGeniOES(coord, pname, param); +} + +void glTexGenivOES(GLenum coord, GLenum pname, const GLint *params) +{ + getDispatch()->glTexGenivOES(coord, pname, params); +} + +void glTexGenxOES(GLenum coord, GLenum pname, GLfixed param) +{ + getDispatch()->glTexGenxOES(coord, pname, param); +} + +void glTexGenxvOES(GLenum coord, GLenum pname, const GLfixed *params) +{ + getDispatch()->glTexGenxvOES(coord, pname, params); +} + +void glGetTexGenfvOES(GLenum coord, GLenum pname, GLfloat *params) +{ + getDispatch()->glGetTexGenfvOES(coord, pname, params); +} + +void glGetTexGenivOES(GLenum coord, GLenum pname, GLint *params) +{ + getDispatch()->glGetTexGenivOES(coord, pname, params); +} + +void glGetTexGenxvOES(GLenum coord, GLenum pname, GLfixed *params) +{ + getDispatch()->glGetTexGenxvOES(coord, pname, params); +} + +void glBindVertexArrayOES(GLuint array) +{ + getDispatch()->glBindVertexArrayOES(array); +} + +void glDeleteVertexArraysOES(GLsizei n, const GLuint *arrays) +{ + getDispatch()->glDeleteVertexArraysOES(n, arrays); +} + +void glGenVertexArraysOES(GLsizei n, GLuint *arrays) +{ + getDispatch()->glGenVertexArraysOES(n, arrays); +} + +GLboolean glIsVertexArrayOES(GLuint array) +{ + return getDispatch()->glIsVertexArrayOES(array); +} + +void glDiscardFramebufferEXT(GLenum target, GLsizei numAttachments, const GLenum *attachments) +{ + getDispatch()->glDiscardFramebufferEXT(target, numAttachments, attachments); +} + +void glMultiDrawArraysEXT(GLenum mode, GLint *first, GLsizei *count, GLsizei primcount) +{ + getDispatch()->glMultiDrawArraysEXT(mode, first, count, primcount); +} + +void glMultiDrawElementsEXT(GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount) +{ + getDispatch()->glMultiDrawElementsEXT(mode, count, type, indices, primcount); +} + +void glClipPlanefIMG(GLenum p, const GLfloat *eqn) +{ + getDispatch()->glClipPlanefIMG(p, eqn); +} + +void glClipPlanexIMG(GLenum p, const GLfixed *eqn) +{ + getDispatch()->glClipPlanexIMG(p, eqn); +} + +void glRenderbufferStorageMultisampleIMG(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height) +{ + getDispatch()->glRenderbufferStorageMultisampleIMG(target, samples, internalformat, width, height); +} + +void glFramebufferTexture2DMultisampleIMG(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples) +{ + getDispatch()->glFramebufferTexture2DMultisampleIMG(target, attachment, textarget, texture, level, samples); +} + +void glDeleteFencesNV(GLsizei n, const GLuint *fences) +{ + getDispatch()->glDeleteFencesNV(n, fences); +} + +void glGenFencesNV(GLsizei n, GLuint *fences) +{ + getDispatch()->glGenFencesNV(n, fences); +} + +GLboolean glIsFenceNV(GLuint fence) +{ + return getDispatch()->glIsFenceNV(fence); +} + +GLboolean glTestFenceNV(GLuint fence) +{ + return getDispatch()->glTestFenceNV(fence); +} + +void glGetFenceivNV(GLuint fence, GLenum pname, GLint *params) +{ + getDispatch()->glGetFenceivNV(fence, pname, params); +} + +void glFinishFenceNV(GLuint fence) +{ + getDispatch()->glFinishFenceNV(fence); +} + +void glSetFenceNV(GLuint fence, GLenum condition) +{ + getDispatch()->glSetFenceNV(fence, condition); +} + +void glGetDriverControlsQCOM(GLint *num, GLsizei size, GLuint *driverControls) +{ + getDispatch()->glGetDriverControlsQCOM(num, size, driverControls); +} + +void glGetDriverControlStringQCOM(GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString) +{ + getDispatch()->glGetDriverControlStringQCOM(driverControl, bufSize, length, driverControlString); +} + +void glEnableDriverControlQCOM(GLuint driverControl) +{ + getDispatch()->glEnableDriverControlQCOM(driverControl); +} + +void glDisableDriverControlQCOM(GLuint driverControl) +{ + getDispatch()->glDisableDriverControlQCOM(driverControl); +} + +void glExtGetTexturesQCOM(GLuint *textures, GLint maxTextures, GLint *numTextures) +{ + getDispatch()->glExtGetTexturesQCOM(textures, maxTextures, numTextures); +} + +void glExtGetBuffersQCOM(GLuint *buffers, GLint maxBuffers, GLint *numBuffers) +{ + getDispatch()->glExtGetBuffersQCOM(buffers, maxBuffers, numBuffers); +} + +void glExtGetRenderbuffersQCOM(GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers) +{ + getDispatch()->glExtGetRenderbuffersQCOM(renderbuffers, maxRenderbuffers, numRenderbuffers); +} + +void glExtGetFramebuffersQCOM(GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers) +{ + getDispatch()->glExtGetFramebuffersQCOM(framebuffers, maxFramebuffers, numFramebuffers); +} + +void glExtGetTexLevelParameterivQCOM(GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params) +{ + getDispatch()->glExtGetTexLevelParameterivQCOM(texture, face, level, pname, params); +} + +void glExtTexObjectStateOverrideiQCOM(GLenum target, GLenum pname, GLint param) +{ + getDispatch()->glExtTexObjectStateOverrideiQCOM(target, pname, param); +} + +void glExtGetTexSubImageQCOM(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels) +{ + getDispatch()->glExtGetTexSubImageQCOM(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, texels); +} + +void glExtGetBufferPointervQCOM(GLenum target, GLvoid **params) +{ + getDispatch()->glExtGetBufferPointervQCOM(target, params); +} + +void glExtGetShadersQCOM(GLuint *shaders, GLint maxShaders, GLint *numShaders) +{ + getDispatch()->glExtGetShadersQCOM(shaders, maxShaders, numShaders); +} + +void glExtGetProgramsQCOM(GLuint *programs, GLint maxPrograms, GLint *numPrograms) +{ + getDispatch()->glExtGetProgramsQCOM(programs, maxPrograms, numPrograms); +} + +GLboolean glExtIsProgramBinaryQCOM(GLuint program) +{ + return getDispatch()->glExtIsProgramBinaryQCOM(program); +} + +void glExtGetProgramBinarySourceQCOM(GLuint program, GLenum shadertype, GLchar *source, GLint *length) +{ + getDispatch()->glExtGetProgramBinarySourceQCOM(program, shadertype, source, length); +} + +void glStartTilingQCOM(GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask) +{ + getDispatch()->glStartTilingQCOM(x, y, width, height, preserveMask); +} + +void glEndTilingQCOM(GLbitfield preserveMask) +{ + getDispatch()->glEndTilingQCOM(preserveMask); +} + diff --git a/emulator/opengl/tests/gles_android_wrapper/gles_dispatch.cpp b/emulator/opengl/tests/gles_android_wrapper/gles_dispatch.cpp new file mode 100644 index 0000000..0a17624 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/gles_dispatch.cpp @@ -0,0 +1,298 @@ +/* +* 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_dispatch.h" +#include <stdio.h> +#include <dlfcn.h> + +gles_dispatch *create_gles_dispatch(void *gles_android) +{ + gles_dispatch *disp = new gles_dispatch; + + void *ptr; + ptr = dlsym(gles_android,"glAlphaFunc"); disp->set_glAlphaFunc((glAlphaFunc_t)ptr); + ptr = dlsym(gles_android,"glClearColor"); disp->set_glClearColor((glClearColor_t)ptr); + ptr = dlsym(gles_android,"glClearDepthf"); disp->set_glClearDepthf((glClearDepthf_t)ptr); + ptr = dlsym(gles_android,"glClipPlanef"); disp->set_glClipPlanef((glClipPlanef_t)ptr); + ptr = dlsym(gles_android,"glColor4f"); disp->set_glColor4f((glColor4f_t)ptr); + ptr = dlsym(gles_android,"glDepthRangef"); disp->set_glDepthRangef((glDepthRangef_t)ptr); + ptr = dlsym(gles_android,"glFogf"); disp->set_glFogf((glFogf_t)ptr); + ptr = dlsym(gles_android,"glFogfv"); disp->set_glFogfv((glFogfv_t)ptr); + ptr = dlsym(gles_android,"glFrustumf"); disp->set_glFrustumf((glFrustumf_t)ptr); + ptr = dlsym(gles_android,"glGetClipPlanef"); disp->set_glGetClipPlanef((glGetClipPlanef_t)ptr); + ptr = dlsym(gles_android,"glGetFloatv"); disp->set_glGetFloatv((glGetFloatv_t)ptr); + ptr = dlsym(gles_android,"glGetLightfv"); disp->set_glGetLightfv((glGetLightfv_t)ptr); + ptr = dlsym(gles_android,"glGetMaterialfv"); disp->set_glGetMaterialfv((glGetMaterialfv_t)ptr); + ptr = dlsym(gles_android,"glGetTexEnvfv"); disp->set_glGetTexEnvfv((glGetTexEnvfv_t)ptr); + ptr = dlsym(gles_android,"glGetTexParameterfv"); disp->set_glGetTexParameterfv((glGetTexParameterfv_t)ptr); + ptr = dlsym(gles_android,"glLightModelf"); disp->set_glLightModelf((glLightModelf_t)ptr); + ptr = dlsym(gles_android,"glLightModelfv"); disp->set_glLightModelfv((glLightModelfv_t)ptr); + ptr = dlsym(gles_android,"glLightf"); disp->set_glLightf((glLightf_t)ptr); + ptr = dlsym(gles_android,"glLightfv"); disp->set_glLightfv((glLightfv_t)ptr); + ptr = dlsym(gles_android,"glLineWidth"); disp->set_glLineWidth((glLineWidth_t)ptr); + ptr = dlsym(gles_android,"glLoadMatrixf"); disp->set_glLoadMatrixf((glLoadMatrixf_t)ptr); + ptr = dlsym(gles_android,"glMaterialf"); disp->set_glMaterialf((glMaterialf_t)ptr); + ptr = dlsym(gles_android,"glMaterialfv"); disp->set_glMaterialfv((glMaterialfv_t)ptr); + ptr = dlsym(gles_android,"glMultMatrixf"); disp->set_glMultMatrixf((glMultMatrixf_t)ptr); + ptr = dlsym(gles_android,"glMultiTexCoord4f"); disp->set_glMultiTexCoord4f((glMultiTexCoord4f_t)ptr); + ptr = dlsym(gles_android,"glNormal3f"); disp->set_glNormal3f((glNormal3f_t)ptr); + ptr = dlsym(gles_android,"glOrthof"); disp->set_glOrthof((glOrthof_t)ptr); + ptr = dlsym(gles_android,"glPointParameterf"); disp->set_glPointParameterf((glPointParameterf_t)ptr); + ptr = dlsym(gles_android,"glPointParameterfv"); disp->set_glPointParameterfv((glPointParameterfv_t)ptr); + ptr = dlsym(gles_android,"glPointSize"); disp->set_glPointSize((glPointSize_t)ptr); + ptr = dlsym(gles_android,"glPolygonOffset"); disp->set_glPolygonOffset((glPolygonOffset_t)ptr); + ptr = dlsym(gles_android,"glRotatef"); disp->set_glRotatef((glRotatef_t)ptr); + ptr = dlsym(gles_android,"glScalef"); disp->set_glScalef((glScalef_t)ptr); + ptr = dlsym(gles_android,"glTexEnvf"); disp->set_glTexEnvf((glTexEnvf_t)ptr); + ptr = dlsym(gles_android,"glTexEnvfv"); disp->set_glTexEnvfv((glTexEnvfv_t)ptr); + ptr = dlsym(gles_android,"glTexParameterf"); disp->set_glTexParameterf((glTexParameterf_t)ptr); + ptr = dlsym(gles_android,"glTexParameterfv"); disp->set_glTexParameterfv((glTexParameterfv_t)ptr); + ptr = dlsym(gles_android,"glTranslatef"); disp->set_glTranslatef((glTranslatef_t)ptr); + ptr = dlsym(gles_android,"glActiveTexture"); disp->set_glActiveTexture((glActiveTexture_t)ptr); + ptr = dlsym(gles_android,"glAlphaFuncx"); disp->set_glAlphaFuncx((glAlphaFuncx_t)ptr); + ptr = dlsym(gles_android,"glBindBuffer"); disp->set_glBindBuffer((glBindBuffer_t)ptr); + ptr = dlsym(gles_android,"glBindTexture"); disp->set_glBindTexture((glBindTexture_t)ptr); + ptr = dlsym(gles_android,"glBlendFunc"); disp->set_glBlendFunc((glBlendFunc_t)ptr); + ptr = dlsym(gles_android,"glBufferData"); disp->set_glBufferData((glBufferData_t)ptr); + ptr = dlsym(gles_android,"glBufferSubData"); disp->set_glBufferSubData((glBufferSubData_t)ptr); + ptr = dlsym(gles_android,"glClear"); disp->set_glClear((glClear_t)ptr); + ptr = dlsym(gles_android,"glClearColorx"); disp->set_glClearColorx((glClearColorx_t)ptr); + ptr = dlsym(gles_android,"glClearDepthx"); disp->set_glClearDepthx((glClearDepthx_t)ptr); + ptr = dlsym(gles_android,"glClearStencil"); disp->set_glClearStencil((glClearStencil_t)ptr); + ptr = dlsym(gles_android,"glClientActiveTexture"); disp->set_glClientActiveTexture((glClientActiveTexture_t)ptr); + ptr = dlsym(gles_android,"glClipPlanex"); disp->set_glClipPlanex((glClipPlanex_t)ptr); + ptr = dlsym(gles_android,"glColor4ub"); disp->set_glColor4ub((glColor4ub_t)ptr); + ptr = dlsym(gles_android,"glColor4x"); disp->set_glColor4x((glColor4x_t)ptr); + ptr = dlsym(gles_android,"glColorMask"); disp->set_glColorMask((glColorMask_t)ptr); + ptr = dlsym(gles_android,"glColorPointer"); disp->set_glColorPointer((glColorPointer_t)ptr); + ptr = dlsym(gles_android,"glCompressedTexImage2D"); disp->set_glCompressedTexImage2D((glCompressedTexImage2D_t)ptr); + ptr = dlsym(gles_android,"glCompressedTexSubImage2D"); disp->set_glCompressedTexSubImage2D((glCompressedTexSubImage2D_t)ptr); + ptr = dlsym(gles_android,"glCopyTexImage2D"); disp->set_glCopyTexImage2D((glCopyTexImage2D_t)ptr); + ptr = dlsym(gles_android,"glCopyTexSubImage2D"); disp->set_glCopyTexSubImage2D((glCopyTexSubImage2D_t)ptr); + ptr = dlsym(gles_android,"glCullFace"); disp->set_glCullFace((glCullFace_t)ptr); + ptr = dlsym(gles_android,"glDeleteBuffers"); disp->set_glDeleteBuffers((glDeleteBuffers_t)ptr); + ptr = dlsym(gles_android,"glDeleteTextures"); disp->set_glDeleteTextures((glDeleteTextures_t)ptr); + ptr = dlsym(gles_android,"glDepthFunc"); disp->set_glDepthFunc((glDepthFunc_t)ptr); + ptr = dlsym(gles_android,"glDepthMask"); disp->set_glDepthMask((glDepthMask_t)ptr); + ptr = dlsym(gles_android,"glDepthRangex"); disp->set_glDepthRangex((glDepthRangex_t)ptr); + ptr = dlsym(gles_android,"glDisable"); disp->set_glDisable((glDisable_t)ptr); + ptr = dlsym(gles_android,"glDisableClientState"); disp->set_glDisableClientState((glDisableClientState_t)ptr); + ptr = dlsym(gles_android,"glDrawArrays"); disp->set_glDrawArrays((glDrawArrays_t)ptr); + ptr = dlsym(gles_android,"glDrawElements"); disp->set_glDrawElements((glDrawElements_t)ptr); + ptr = dlsym(gles_android,"glEnable"); disp->set_glEnable((glEnable_t)ptr); + ptr = dlsym(gles_android,"glEnableClientState"); disp->set_glEnableClientState((glEnableClientState_t)ptr); + ptr = dlsym(gles_android,"glFinish"); disp->set_glFinish((glFinish_t)ptr); + ptr = dlsym(gles_android,"glFlush"); disp->set_glFlush((glFlush_t)ptr); + ptr = dlsym(gles_android,"glFogx"); disp->set_glFogx((glFogx_t)ptr); + ptr = dlsym(gles_android,"glFogxv"); disp->set_glFogxv((glFogxv_t)ptr); + ptr = dlsym(gles_android,"glFrontFace"); disp->set_glFrontFace((glFrontFace_t)ptr); + ptr = dlsym(gles_android,"glFrustumx"); disp->set_glFrustumx((glFrustumx_t)ptr); + ptr = dlsym(gles_android,"glGetBooleanv"); disp->set_glGetBooleanv((glGetBooleanv_t)ptr); + ptr = dlsym(gles_android,"glGetBufferParameteriv"); disp->set_glGetBufferParameteriv((glGetBufferParameteriv_t)ptr); + ptr = dlsym(gles_android,"glGetClipPlanex"); disp->set_glGetClipPlanex((glGetClipPlanex_t)ptr); + ptr = dlsym(gles_android,"glGenBuffers"); disp->set_glGenBuffers((glGenBuffers_t)ptr); + ptr = dlsym(gles_android,"glGenTextures"); disp->set_glGenTextures((glGenTextures_t)ptr); + ptr = dlsym(gles_android,"glGetError"); disp->set_glGetError((glGetError_t)ptr); + ptr = dlsym(gles_android,"glGetFixedv"); disp->set_glGetFixedv((glGetFixedv_t)ptr); + ptr = dlsym(gles_android,"glGetIntegerv"); disp->set_glGetIntegerv((glGetIntegerv_t)ptr); + ptr = dlsym(gles_android,"glGetLightxv"); disp->set_glGetLightxv((glGetLightxv_t)ptr); + ptr = dlsym(gles_android,"glGetMaterialxv"); disp->set_glGetMaterialxv((glGetMaterialxv_t)ptr); + ptr = dlsym(gles_android,"glGetPointerv"); disp->set_glGetPointerv((glGetPointerv_t)ptr); + ptr = dlsym(gles_android,"glGetString"); disp->set_glGetString((glGetString_t)ptr); + ptr = dlsym(gles_android,"glGetTexEnviv"); disp->set_glGetTexEnviv((glGetTexEnviv_t)ptr); + ptr = dlsym(gles_android,"glGetTexEnvxv"); disp->set_glGetTexEnvxv((glGetTexEnvxv_t)ptr); + ptr = dlsym(gles_android,"glGetTexParameteriv"); disp->set_glGetTexParameteriv((glGetTexParameteriv_t)ptr); + ptr = dlsym(gles_android,"glGetTexParameterxv"); disp->set_glGetTexParameterxv((glGetTexParameterxv_t)ptr); + ptr = dlsym(gles_android,"glHint"); disp->set_glHint((glHint_t)ptr); + ptr = dlsym(gles_android,"glIsBuffer"); disp->set_glIsBuffer((glIsBuffer_t)ptr); + ptr = dlsym(gles_android,"glIsEnabled"); disp->set_glIsEnabled((glIsEnabled_t)ptr); + ptr = dlsym(gles_android,"glIsTexture"); disp->set_glIsTexture((glIsTexture_t)ptr); + ptr = dlsym(gles_android,"glLightModelx"); disp->set_glLightModelx((glLightModelx_t)ptr); + ptr = dlsym(gles_android,"glLightModelxv"); disp->set_glLightModelxv((glLightModelxv_t)ptr); + ptr = dlsym(gles_android,"glLightx"); disp->set_glLightx((glLightx_t)ptr); + ptr = dlsym(gles_android,"glLightxv"); disp->set_glLightxv((glLightxv_t)ptr); + ptr = dlsym(gles_android,"glLineWidthx"); disp->set_glLineWidthx((glLineWidthx_t)ptr); + ptr = dlsym(gles_android,"glLoadIdentity"); disp->set_glLoadIdentity((glLoadIdentity_t)ptr); + ptr = dlsym(gles_android,"glLoadMatrixx"); disp->set_glLoadMatrixx((glLoadMatrixx_t)ptr); + ptr = dlsym(gles_android,"glLogicOp"); disp->set_glLogicOp((glLogicOp_t)ptr); + ptr = dlsym(gles_android,"glMaterialx"); disp->set_glMaterialx((glMaterialx_t)ptr); + ptr = dlsym(gles_android,"glMaterialxv"); disp->set_glMaterialxv((glMaterialxv_t)ptr); + ptr = dlsym(gles_android,"glMatrixMode"); disp->set_glMatrixMode((glMatrixMode_t)ptr); + ptr = dlsym(gles_android,"glMultMatrixx"); disp->set_glMultMatrixx((glMultMatrixx_t)ptr); + ptr = dlsym(gles_android,"glMultiTexCoord4x"); disp->set_glMultiTexCoord4x((glMultiTexCoord4x_t)ptr); + ptr = dlsym(gles_android,"glNormal3x"); disp->set_glNormal3x((glNormal3x_t)ptr); + ptr = dlsym(gles_android,"glNormalPointer"); disp->set_glNormalPointer((glNormalPointer_t)ptr); + ptr = dlsym(gles_android,"glOrthox"); disp->set_glOrthox((glOrthox_t)ptr); + ptr = dlsym(gles_android,"glPixelStorei"); disp->set_glPixelStorei((glPixelStorei_t)ptr); + ptr = dlsym(gles_android,"glPointParameterx"); disp->set_glPointParameterx((glPointParameterx_t)ptr); + ptr = dlsym(gles_android,"glPointParameterxv"); disp->set_glPointParameterxv((glPointParameterxv_t)ptr); + ptr = dlsym(gles_android,"glPointSizex"); disp->set_glPointSizex((glPointSizex_t)ptr); + ptr = dlsym(gles_android,"glPolygonOffsetx"); disp->set_glPolygonOffsetx((glPolygonOffsetx_t)ptr); + ptr = dlsym(gles_android,"glPopMatrix"); disp->set_glPopMatrix((glPopMatrix_t)ptr); + ptr = dlsym(gles_android,"glPushMatrix"); disp->set_glPushMatrix((glPushMatrix_t)ptr); + ptr = dlsym(gles_android,"glReadPixels"); disp->set_glReadPixels((glReadPixels_t)ptr); + ptr = dlsym(gles_android,"glRotatex"); disp->set_glRotatex((glRotatex_t)ptr); + ptr = dlsym(gles_android,"glSampleCoverage"); disp->set_glSampleCoverage((glSampleCoverage_t)ptr); + ptr = dlsym(gles_android,"glSampleCoveragex"); disp->set_glSampleCoveragex((glSampleCoveragex_t)ptr); + ptr = dlsym(gles_android,"glScalex"); disp->set_glScalex((glScalex_t)ptr); + ptr = dlsym(gles_android,"glScissor"); disp->set_glScissor((glScissor_t)ptr); + ptr = dlsym(gles_android,"glShadeModel"); disp->set_glShadeModel((glShadeModel_t)ptr); + ptr = dlsym(gles_android,"glStencilFunc"); disp->set_glStencilFunc((glStencilFunc_t)ptr); + ptr = dlsym(gles_android,"glStencilMask"); disp->set_glStencilMask((glStencilMask_t)ptr); + ptr = dlsym(gles_android,"glStencilOp"); disp->set_glStencilOp((glStencilOp_t)ptr); + ptr = dlsym(gles_android,"glTexCoordPointer"); disp->set_glTexCoordPointer((glTexCoordPointer_t)ptr); + ptr = dlsym(gles_android,"glTexEnvi"); disp->set_glTexEnvi((glTexEnvi_t)ptr); + ptr = dlsym(gles_android,"glTexEnvx"); disp->set_glTexEnvx((glTexEnvx_t)ptr); + ptr = dlsym(gles_android,"glTexEnviv"); disp->set_glTexEnviv((glTexEnviv_t)ptr); + ptr = dlsym(gles_android,"glTexEnvxv"); disp->set_glTexEnvxv((glTexEnvxv_t)ptr); + ptr = dlsym(gles_android,"glTexImage2D"); disp->set_glTexImage2D((glTexImage2D_t)ptr); + ptr = dlsym(gles_android,"glTexParameteri"); disp->set_glTexParameteri((glTexParameteri_t)ptr); + ptr = dlsym(gles_android,"glTexParameterx"); disp->set_glTexParameterx((glTexParameterx_t)ptr); + ptr = dlsym(gles_android,"glTexParameteriv"); disp->set_glTexParameteriv((glTexParameteriv_t)ptr); + ptr = dlsym(gles_android,"glTexParameterxv"); disp->set_glTexParameterxv((glTexParameterxv_t)ptr); + ptr = dlsym(gles_android,"glTexSubImage2D"); disp->set_glTexSubImage2D((glTexSubImage2D_t)ptr); + ptr = dlsym(gles_android,"glTranslatex"); disp->set_glTranslatex((glTranslatex_t)ptr); + ptr = dlsym(gles_android,"glVertexPointer"); disp->set_glVertexPointer((glVertexPointer_t)ptr); + ptr = dlsym(gles_android,"glViewport"); disp->set_glViewport((glViewport_t)ptr); + ptr = dlsym(gles_android,"glPointSizePointerOES"); disp->set_glPointSizePointerOES((glPointSizePointerOES_t)ptr); + ptr = dlsym(gles_android,"glBlendEquationSeparateOES"); disp->set_glBlendEquationSeparateOES((glBlendEquationSeparateOES_t)ptr); + ptr = dlsym(gles_android,"glBlendFuncSeparateOES"); disp->set_glBlendFuncSeparateOES((glBlendFuncSeparateOES_t)ptr); + ptr = dlsym(gles_android,"glBlendEquationOES"); disp->set_glBlendEquationOES((glBlendEquationOES_t)ptr); + ptr = dlsym(gles_android,"glDrawTexsOES"); disp->set_glDrawTexsOES((glDrawTexsOES_t)ptr); + ptr = dlsym(gles_android,"glDrawTexiOES"); disp->set_glDrawTexiOES((glDrawTexiOES_t)ptr); + ptr = dlsym(gles_android,"glDrawTexxOES"); disp->set_glDrawTexxOES((glDrawTexxOES_t)ptr); + ptr = dlsym(gles_android,"glDrawTexsvOES"); disp->set_glDrawTexsvOES((glDrawTexsvOES_t)ptr); + ptr = dlsym(gles_android,"glDrawTexivOES"); disp->set_glDrawTexivOES((glDrawTexivOES_t)ptr); + ptr = dlsym(gles_android,"glDrawTexxvOES"); disp->set_glDrawTexxvOES((glDrawTexxvOES_t)ptr); + ptr = dlsym(gles_android,"glDrawTexfOES"); disp->set_glDrawTexfOES((glDrawTexfOES_t)ptr); + ptr = dlsym(gles_android,"glDrawTexfvOES"); disp->set_glDrawTexfvOES((glDrawTexfvOES_t)ptr); + ptr = dlsym(gles_android,"glEGLImageTargetTexture2DOES"); disp->set_glEGLImageTargetTexture2DOES((glEGLImageTargetTexture2DOES_t)ptr); + ptr = dlsym(gles_android,"glEGLImageTargetRenderbufferStorageOES"); disp->set_glEGLImageTargetRenderbufferStorageOES((glEGLImageTargetRenderbufferStorageOES_t)ptr); + ptr = dlsym(gles_android,"glAlphaFuncxOES"); disp->set_glAlphaFuncxOES((glAlphaFuncxOES_t)ptr); + ptr = dlsym(gles_android,"glClearColorxOES"); disp->set_glClearColorxOES((glClearColorxOES_t)ptr); + ptr = dlsym(gles_android,"glClearDepthxOES"); disp->set_glClearDepthxOES((glClearDepthxOES_t)ptr); + ptr = dlsym(gles_android,"glClipPlanexOES"); disp->set_glClipPlanexOES((glClipPlanexOES_t)ptr); + ptr = dlsym(gles_android,"glColor4xOES"); disp->set_glColor4xOES((glColor4xOES_t)ptr); + ptr = dlsym(gles_android,"glDepthRangexOES"); disp->set_glDepthRangexOES((glDepthRangexOES_t)ptr); + ptr = dlsym(gles_android,"glFogxOES"); disp->set_glFogxOES((glFogxOES_t)ptr); + ptr = dlsym(gles_android,"glFogxvOES"); disp->set_glFogxvOES((glFogxvOES_t)ptr); + ptr = dlsym(gles_android,"glFrustumxOES"); disp->set_glFrustumxOES((glFrustumxOES_t)ptr); + ptr = dlsym(gles_android,"glGetClipPlanexOES"); disp->set_glGetClipPlanexOES((glGetClipPlanexOES_t)ptr); + ptr = dlsym(gles_android,"glGetFixedvOES"); disp->set_glGetFixedvOES((glGetFixedvOES_t)ptr); + ptr = dlsym(gles_android,"glGetLightxvOES"); disp->set_glGetLightxvOES((glGetLightxvOES_t)ptr); + ptr = dlsym(gles_android,"glGetMaterialxvOES"); disp->set_glGetMaterialxvOES((glGetMaterialxvOES_t)ptr); + ptr = dlsym(gles_android,"glGetTexEnvxvOES"); disp->set_glGetTexEnvxvOES((glGetTexEnvxvOES_t)ptr); + ptr = dlsym(gles_android,"glGetTexParameterxvOES"); disp->set_glGetTexParameterxvOES((glGetTexParameterxvOES_t)ptr); + ptr = dlsym(gles_android,"glLightModelxOES"); disp->set_glLightModelxOES((glLightModelxOES_t)ptr); + ptr = dlsym(gles_android,"glLightModelxvOES"); disp->set_glLightModelxvOES((glLightModelxvOES_t)ptr); + ptr = dlsym(gles_android,"glLightxOES"); disp->set_glLightxOES((glLightxOES_t)ptr); + ptr = dlsym(gles_android,"glLightxvOES"); disp->set_glLightxvOES((glLightxvOES_t)ptr); + ptr = dlsym(gles_android,"glLineWidthxOES"); disp->set_glLineWidthxOES((glLineWidthxOES_t)ptr); + ptr = dlsym(gles_android,"glLoadMatrixxOES"); disp->set_glLoadMatrixxOES((glLoadMatrixxOES_t)ptr); + ptr = dlsym(gles_android,"glMaterialxOES"); disp->set_glMaterialxOES((glMaterialxOES_t)ptr); + ptr = dlsym(gles_android,"glMaterialxvOES"); disp->set_glMaterialxvOES((glMaterialxvOES_t)ptr); + ptr = dlsym(gles_android,"glMultMatrixxOES"); disp->set_glMultMatrixxOES((glMultMatrixxOES_t)ptr); + ptr = dlsym(gles_android,"glMultiTexCoord4xOES"); disp->set_glMultiTexCoord4xOES((glMultiTexCoord4xOES_t)ptr); + ptr = dlsym(gles_android,"glNormal3xOES"); disp->set_glNormal3xOES((glNormal3xOES_t)ptr); + ptr = dlsym(gles_android,"glOrthoxOES"); disp->set_glOrthoxOES((glOrthoxOES_t)ptr); + ptr = dlsym(gles_android,"glPointParameterxOES"); disp->set_glPointParameterxOES((glPointParameterxOES_t)ptr); + ptr = dlsym(gles_android,"glPointParameterxvOES"); disp->set_glPointParameterxvOES((glPointParameterxvOES_t)ptr); + ptr = dlsym(gles_android,"glPointSizexOES"); disp->set_glPointSizexOES((glPointSizexOES_t)ptr); + ptr = dlsym(gles_android,"glPolygonOffsetxOES"); disp->set_glPolygonOffsetxOES((glPolygonOffsetxOES_t)ptr); + ptr = dlsym(gles_android,"glRotatexOES"); disp->set_glRotatexOES((glRotatexOES_t)ptr); + ptr = dlsym(gles_android,"glSampleCoveragexOES"); disp->set_glSampleCoveragexOES((glSampleCoveragexOES_t)ptr); + ptr = dlsym(gles_android,"glScalexOES"); disp->set_glScalexOES((glScalexOES_t)ptr); + ptr = dlsym(gles_android,"glTexEnvxOES"); disp->set_glTexEnvxOES((glTexEnvxOES_t)ptr); + ptr = dlsym(gles_android,"glTexEnvxvOES"); disp->set_glTexEnvxvOES((glTexEnvxvOES_t)ptr); + ptr = dlsym(gles_android,"glTexParameterxOES"); disp->set_glTexParameterxOES((glTexParameterxOES_t)ptr); + ptr = dlsym(gles_android,"glTexParameterxvOES"); disp->set_glTexParameterxvOES((glTexParameterxvOES_t)ptr); + ptr = dlsym(gles_android,"glTranslatexOES"); disp->set_glTranslatexOES((glTranslatexOES_t)ptr); + ptr = dlsym(gles_android,"glIsRenderbufferOES"); disp->set_glIsRenderbufferOES((glIsRenderbufferOES_t)ptr); + ptr = dlsym(gles_android,"glBindRenderbufferOES"); disp->set_glBindRenderbufferOES((glBindRenderbufferOES_t)ptr); + ptr = dlsym(gles_android,"glDeleteRenderbuffersOES"); disp->set_glDeleteRenderbuffersOES((glDeleteRenderbuffersOES_t)ptr); + ptr = dlsym(gles_android,"glGenRenderbuffersOES"); disp->set_glGenRenderbuffersOES((glGenRenderbuffersOES_t)ptr); + ptr = dlsym(gles_android,"glRenderbufferStorageOES"); disp->set_glRenderbufferStorageOES((glRenderbufferStorageOES_t)ptr); + ptr = dlsym(gles_android,"glGetRenderbufferParameterivOES"); disp->set_glGetRenderbufferParameterivOES((glGetRenderbufferParameterivOES_t)ptr); + ptr = dlsym(gles_android,"glIsFramebufferOES"); disp->set_glIsFramebufferOES((glIsFramebufferOES_t)ptr); + ptr = dlsym(gles_android,"glBindFramebufferOES"); disp->set_glBindFramebufferOES((glBindFramebufferOES_t)ptr); + ptr = dlsym(gles_android,"glDeleteFramebuffersOES"); disp->set_glDeleteFramebuffersOES((glDeleteFramebuffersOES_t)ptr); + ptr = dlsym(gles_android,"glGenFramebuffersOES"); disp->set_glGenFramebuffersOES((glGenFramebuffersOES_t)ptr); + ptr = dlsym(gles_android,"glCheckFramebufferStatusOES"); disp->set_glCheckFramebufferStatusOES((glCheckFramebufferStatusOES_t)ptr); + ptr = dlsym(gles_android,"glFramebufferRenderbufferOES"); disp->set_glFramebufferRenderbufferOES((glFramebufferRenderbufferOES_t)ptr); + ptr = dlsym(gles_android,"glFramebufferTexture2DOES"); disp->set_glFramebufferTexture2DOES((glFramebufferTexture2DOES_t)ptr); + ptr = dlsym(gles_android,"glGetFramebufferAttachmentParameterivOES"); disp->set_glGetFramebufferAttachmentParameterivOES((glGetFramebufferAttachmentParameterivOES_t)ptr); + ptr = dlsym(gles_android,"glGenerateMipmapOES"); disp->set_glGenerateMipmapOES((glGenerateMipmapOES_t)ptr); + ptr = dlsym(gles_android,"glMapBufferOES"); disp->set_glMapBufferOES((glMapBufferOES_t)ptr); + ptr = dlsym(gles_android,"glUnmapBufferOES"); disp->set_glUnmapBufferOES((glUnmapBufferOES_t)ptr); + ptr = dlsym(gles_android,"glGetBufferPointervOES"); disp->set_glGetBufferPointervOES((glGetBufferPointervOES_t)ptr); + ptr = dlsym(gles_android,"glCurrentPaletteMatrixOES"); disp->set_glCurrentPaletteMatrixOES((glCurrentPaletteMatrixOES_t)ptr); + ptr = dlsym(gles_android,"glLoadPaletteFromModelViewMatrixOES"); disp->set_glLoadPaletteFromModelViewMatrixOES((glLoadPaletteFromModelViewMatrixOES_t)ptr); + ptr = dlsym(gles_android,"glMatrixIndexPointerOES"); disp->set_glMatrixIndexPointerOES((glMatrixIndexPointerOES_t)ptr); + ptr = dlsym(gles_android,"glWeightPointerOES"); disp->set_glWeightPointerOES((glWeightPointerOES_t)ptr); + ptr = dlsym(gles_android,"glQueryMatrixxOES"); disp->set_glQueryMatrixxOES((glQueryMatrixxOES_t)ptr); + ptr = dlsym(gles_android,"glDepthRangefOES"); disp->set_glDepthRangefOES((glDepthRangefOES_t)ptr); + ptr = dlsym(gles_android,"glFrustumfOES"); disp->set_glFrustumfOES((glFrustumfOES_t)ptr); + ptr = dlsym(gles_android,"glOrthofOES"); disp->set_glOrthofOES((glOrthofOES_t)ptr); + ptr = dlsym(gles_android,"glClipPlanefOES"); disp->set_glClipPlanefOES((glClipPlanefOES_t)ptr); + ptr = dlsym(gles_android,"glGetClipPlanefOES"); disp->set_glGetClipPlanefOES((glGetClipPlanefOES_t)ptr); + ptr = dlsym(gles_android,"glClearDepthfOES"); disp->set_glClearDepthfOES((glClearDepthfOES_t)ptr); + ptr = dlsym(gles_android,"glTexGenfOES"); disp->set_glTexGenfOES((glTexGenfOES_t)ptr); + ptr = dlsym(gles_android,"glTexGenfvOES"); disp->set_glTexGenfvOES((glTexGenfvOES_t)ptr); + ptr = dlsym(gles_android,"glTexGeniOES"); disp->set_glTexGeniOES((glTexGeniOES_t)ptr); + ptr = dlsym(gles_android,"glTexGenivOES"); disp->set_glTexGenivOES((glTexGenivOES_t)ptr); + ptr = dlsym(gles_android,"glTexGenxOES"); disp->set_glTexGenxOES((glTexGenxOES_t)ptr); + ptr = dlsym(gles_android,"glTexGenxvOES"); disp->set_glTexGenxvOES((glTexGenxvOES_t)ptr); + ptr = dlsym(gles_android,"glGetTexGenfvOES"); disp->set_glGetTexGenfvOES((glGetTexGenfvOES_t)ptr); + ptr = dlsym(gles_android,"glGetTexGenivOES"); disp->set_glGetTexGenivOES((glGetTexGenivOES_t)ptr); + ptr = dlsym(gles_android,"glGetTexGenxvOES"); disp->set_glGetTexGenxvOES((glGetTexGenxvOES_t)ptr); + ptr = dlsym(gles_android,"glBindVertexArrayOES"); disp->set_glBindVertexArrayOES((glBindVertexArrayOES_t)ptr); + ptr = dlsym(gles_android,"glDeleteVertexArraysOES"); disp->set_glDeleteVertexArraysOES((glDeleteVertexArraysOES_t)ptr); + ptr = dlsym(gles_android,"glGenVertexArraysOES"); disp->set_glGenVertexArraysOES((glGenVertexArraysOES_t)ptr); + ptr = dlsym(gles_android,"glIsVertexArrayOES"); disp->set_glIsVertexArrayOES((glIsVertexArrayOES_t)ptr); + ptr = dlsym(gles_android,"glDiscardFramebufferEXT"); disp->set_glDiscardFramebufferEXT((glDiscardFramebufferEXT_t)ptr); + ptr = dlsym(gles_android,"glMultiDrawArraysEXT"); disp->set_glMultiDrawArraysEXT((glMultiDrawArraysEXT_t)ptr); + ptr = dlsym(gles_android,"glMultiDrawElementsEXT"); disp->set_glMultiDrawElementsEXT((glMultiDrawElementsEXT_t)ptr); + ptr = dlsym(gles_android,"glClipPlanefIMG"); disp->set_glClipPlanefIMG((glClipPlanefIMG_t)ptr); + ptr = dlsym(gles_android,"glClipPlanexIMG"); disp->set_glClipPlanexIMG((glClipPlanexIMG_t)ptr); + ptr = dlsym(gles_android,"glRenderbufferStorageMultisampleIMG"); disp->set_glRenderbufferStorageMultisampleIMG((glRenderbufferStorageMultisampleIMG_t)ptr); + ptr = dlsym(gles_android,"glFramebufferTexture2DMultisampleIMG"); disp->set_glFramebufferTexture2DMultisampleIMG((glFramebufferTexture2DMultisampleIMG_t)ptr); + ptr = dlsym(gles_android,"glDeleteFencesNV"); disp->set_glDeleteFencesNV((glDeleteFencesNV_t)ptr); + ptr = dlsym(gles_android,"glGenFencesNV"); disp->set_glGenFencesNV((glGenFencesNV_t)ptr); + ptr = dlsym(gles_android,"glIsFenceNV"); disp->set_glIsFenceNV((glIsFenceNV_t)ptr); + ptr = dlsym(gles_android,"glTestFenceNV"); disp->set_glTestFenceNV((glTestFenceNV_t)ptr); + ptr = dlsym(gles_android,"glGetFenceivNV"); disp->set_glGetFenceivNV((glGetFenceivNV_t)ptr); + ptr = dlsym(gles_android,"glFinishFenceNV"); disp->set_glFinishFenceNV((glFinishFenceNV_t)ptr); + ptr = dlsym(gles_android,"glSetFenceNV"); disp->set_glSetFenceNV((glSetFenceNV_t)ptr); + ptr = dlsym(gles_android,"glGetDriverControlsQCOM"); disp->set_glGetDriverControlsQCOM((glGetDriverControlsQCOM_t)ptr); + ptr = dlsym(gles_android,"glGetDriverControlStringQCOM"); disp->set_glGetDriverControlStringQCOM((glGetDriverControlStringQCOM_t)ptr); + ptr = dlsym(gles_android,"glEnableDriverControlQCOM"); disp->set_glEnableDriverControlQCOM((glEnableDriverControlQCOM_t)ptr); + ptr = dlsym(gles_android,"glDisableDriverControlQCOM"); disp->set_glDisableDriverControlQCOM((glDisableDriverControlQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtGetTexturesQCOM"); disp->set_glExtGetTexturesQCOM((glExtGetTexturesQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtGetBuffersQCOM"); disp->set_glExtGetBuffersQCOM((glExtGetBuffersQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtGetRenderbuffersQCOM"); disp->set_glExtGetRenderbuffersQCOM((glExtGetRenderbuffersQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtGetFramebuffersQCOM"); disp->set_glExtGetFramebuffersQCOM((glExtGetFramebuffersQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtGetTexLevelParameterivQCOM"); disp->set_glExtGetTexLevelParameterivQCOM((glExtGetTexLevelParameterivQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtTexObjectStateOverrideiQCOM"); disp->set_glExtTexObjectStateOverrideiQCOM((glExtTexObjectStateOverrideiQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtGetTexSubImageQCOM"); disp->set_glExtGetTexSubImageQCOM((glExtGetTexSubImageQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtGetBufferPointervQCOM"); disp->set_glExtGetBufferPointervQCOM((glExtGetBufferPointervQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtGetShadersQCOM"); disp->set_glExtGetShadersQCOM((glExtGetShadersQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtGetProgramsQCOM"); disp->set_glExtGetProgramsQCOM((glExtGetProgramsQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtIsProgramBinaryQCOM"); disp->set_glExtIsProgramBinaryQCOM((glExtIsProgramBinaryQCOM_t)ptr); + ptr = dlsym(gles_android,"glExtGetProgramBinarySourceQCOM"); disp->set_glExtGetProgramBinarySourceQCOM((glExtGetProgramBinarySourceQCOM_t)ptr); + ptr = dlsym(gles_android,"glStartTilingQCOM"); disp->set_glStartTilingQCOM((glStartTilingQCOM_t)ptr); + ptr = dlsym(gles_android,"glEndTilingQCOM"); disp->set_glEndTilingQCOM((glEndTilingQCOM_t)ptr); + + return disp; +} diff --git a/emulator/opengl/tests/gles_android_wrapper/gles_dispatch.h b/emulator/opengl/tests/gles_android_wrapper/gles_dispatch.h new file mode 100644 index 0000000..98a4fca --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/gles_dispatch.h @@ -0,0 +1,570 @@ +/* +* 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 "gles_proc.h" + + +struct gles_dispatch { + 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; + //Accessors + glAlphaFunc_t set_glAlphaFunc(glAlphaFunc_t f) { glAlphaFunc_t retval = glAlphaFunc; glAlphaFunc = f; return retval;} + glClearColor_t set_glClearColor(glClearColor_t f) { glClearColor_t retval = glClearColor; glClearColor = f; return retval;} + glClearDepthf_t set_glClearDepthf(glClearDepthf_t f) { glClearDepthf_t retval = glClearDepthf; glClearDepthf = f; return retval;} + glClipPlanef_t set_glClipPlanef(glClipPlanef_t f) { glClipPlanef_t retval = glClipPlanef; glClipPlanef = f; return retval;} + glColor4f_t set_glColor4f(glColor4f_t f) { glColor4f_t retval = glColor4f; glColor4f = f; return retval;} + glDepthRangef_t set_glDepthRangef(glDepthRangef_t f) { glDepthRangef_t retval = glDepthRangef; glDepthRangef = f; return retval;} + glFogf_t set_glFogf(glFogf_t f) { glFogf_t retval = glFogf; glFogf = f; return retval;} + glFogfv_t set_glFogfv(glFogfv_t f) { glFogfv_t retval = glFogfv; glFogfv = f; return retval;} + glFrustumf_t set_glFrustumf(glFrustumf_t f) { glFrustumf_t retval = glFrustumf; glFrustumf = f; return retval;} + glGetClipPlanef_t set_glGetClipPlanef(glGetClipPlanef_t f) { glGetClipPlanef_t retval = glGetClipPlanef; glGetClipPlanef = f; return retval;} + glGetFloatv_t set_glGetFloatv(glGetFloatv_t f) { glGetFloatv_t retval = glGetFloatv; glGetFloatv = f; return retval;} + glGetLightfv_t set_glGetLightfv(glGetLightfv_t f) { glGetLightfv_t retval = glGetLightfv; glGetLightfv = f; return retval;} + glGetMaterialfv_t set_glGetMaterialfv(glGetMaterialfv_t f) { glGetMaterialfv_t retval = glGetMaterialfv; glGetMaterialfv = f; return retval;} + glGetTexEnvfv_t set_glGetTexEnvfv(glGetTexEnvfv_t f) { glGetTexEnvfv_t retval = glGetTexEnvfv; glGetTexEnvfv = f; return retval;} + glGetTexParameterfv_t set_glGetTexParameterfv(glGetTexParameterfv_t f) { glGetTexParameterfv_t retval = glGetTexParameterfv; glGetTexParameterfv = f; return retval;} + glLightModelf_t set_glLightModelf(glLightModelf_t f) { glLightModelf_t retval = glLightModelf; glLightModelf = f; return retval;} + glLightModelfv_t set_glLightModelfv(glLightModelfv_t f) { glLightModelfv_t retval = glLightModelfv; glLightModelfv = f; return retval;} + glLightf_t set_glLightf(glLightf_t f) { glLightf_t retval = glLightf; glLightf = f; return retval;} + glLightfv_t set_glLightfv(glLightfv_t f) { glLightfv_t retval = glLightfv; glLightfv = f; return retval;} + glLineWidth_t set_glLineWidth(glLineWidth_t f) { glLineWidth_t retval = glLineWidth; glLineWidth = f; return retval;} + glLoadMatrixf_t set_glLoadMatrixf(glLoadMatrixf_t f) { glLoadMatrixf_t retval = glLoadMatrixf; glLoadMatrixf = f; return retval;} + glMaterialf_t set_glMaterialf(glMaterialf_t f) { glMaterialf_t retval = glMaterialf; glMaterialf = f; return retval;} + glMaterialfv_t set_glMaterialfv(glMaterialfv_t f) { glMaterialfv_t retval = glMaterialfv; glMaterialfv = f; return retval;} + glMultMatrixf_t set_glMultMatrixf(glMultMatrixf_t f) { glMultMatrixf_t retval = glMultMatrixf; glMultMatrixf = f; return retval;} + glMultiTexCoord4f_t set_glMultiTexCoord4f(glMultiTexCoord4f_t f) { glMultiTexCoord4f_t retval = glMultiTexCoord4f; glMultiTexCoord4f = f; return retval;} + glNormal3f_t set_glNormal3f(glNormal3f_t f) { glNormal3f_t retval = glNormal3f; glNormal3f = f; return retval;} + glOrthof_t set_glOrthof(glOrthof_t f) { glOrthof_t retval = glOrthof; glOrthof = f; return retval;} + glPointParameterf_t set_glPointParameterf(glPointParameterf_t f) { glPointParameterf_t retval = glPointParameterf; glPointParameterf = f; return retval;} + glPointParameterfv_t set_glPointParameterfv(glPointParameterfv_t f) { glPointParameterfv_t retval = glPointParameterfv; glPointParameterfv = f; return retval;} + glPointSize_t set_glPointSize(glPointSize_t f) { glPointSize_t retval = glPointSize; glPointSize = f; return retval;} + glPolygonOffset_t set_glPolygonOffset(glPolygonOffset_t f) { glPolygonOffset_t retval = glPolygonOffset; glPolygonOffset = f; return retval;} + glRotatef_t set_glRotatef(glRotatef_t f) { glRotatef_t retval = glRotatef; glRotatef = f; return retval;} + glScalef_t set_glScalef(glScalef_t f) { glScalef_t retval = glScalef; glScalef = f; return retval;} + glTexEnvf_t set_glTexEnvf(glTexEnvf_t f) { glTexEnvf_t retval = glTexEnvf; glTexEnvf = f; return retval;} + glTexEnvfv_t set_glTexEnvfv(glTexEnvfv_t f) { glTexEnvfv_t retval = glTexEnvfv; glTexEnvfv = f; return retval;} + glTexParameterf_t set_glTexParameterf(glTexParameterf_t f) { glTexParameterf_t retval = glTexParameterf; glTexParameterf = f; return retval;} + glTexParameterfv_t set_glTexParameterfv(glTexParameterfv_t f) { glTexParameterfv_t retval = glTexParameterfv; glTexParameterfv = f; return retval;} + glTranslatef_t set_glTranslatef(glTranslatef_t f) { glTranslatef_t retval = glTranslatef; glTranslatef = f; return retval;} + glActiveTexture_t set_glActiveTexture(glActiveTexture_t f) { glActiveTexture_t retval = glActiveTexture; glActiveTexture = f; return retval;} + glAlphaFuncx_t set_glAlphaFuncx(glAlphaFuncx_t f) { glAlphaFuncx_t retval = glAlphaFuncx; glAlphaFuncx = f; return retval;} + glBindBuffer_t set_glBindBuffer(glBindBuffer_t f) { glBindBuffer_t retval = glBindBuffer; glBindBuffer = f; return retval;} + glBindTexture_t set_glBindTexture(glBindTexture_t f) { glBindTexture_t retval = glBindTexture; glBindTexture = f; return retval;} + glBlendFunc_t set_glBlendFunc(glBlendFunc_t f) { glBlendFunc_t retval = glBlendFunc; glBlendFunc = f; return retval;} + glBufferData_t set_glBufferData(glBufferData_t f) { glBufferData_t retval = glBufferData; glBufferData = f; return retval;} + glBufferSubData_t set_glBufferSubData(glBufferSubData_t f) { glBufferSubData_t retval = glBufferSubData; glBufferSubData = f; return retval;} + glClear_t set_glClear(glClear_t f) { glClear_t retval = glClear; glClear = f; return retval;} + glClearColorx_t set_glClearColorx(glClearColorx_t f) { glClearColorx_t retval = glClearColorx; glClearColorx = f; return retval;} + glClearDepthx_t set_glClearDepthx(glClearDepthx_t f) { glClearDepthx_t retval = glClearDepthx; glClearDepthx = f; return retval;} + glClearStencil_t set_glClearStencil(glClearStencil_t f) { glClearStencil_t retval = glClearStencil; glClearStencil = f; return retval;} + glClientActiveTexture_t set_glClientActiveTexture(glClientActiveTexture_t f) { glClientActiveTexture_t retval = glClientActiveTexture; glClientActiveTexture = f; return retval;} + glClipPlanex_t set_glClipPlanex(glClipPlanex_t f) { glClipPlanex_t retval = glClipPlanex; glClipPlanex = f; return retval;} + glColor4ub_t set_glColor4ub(glColor4ub_t f) { glColor4ub_t retval = glColor4ub; glColor4ub = f; return retval;} + glColor4x_t set_glColor4x(glColor4x_t f) { glColor4x_t retval = glColor4x; glColor4x = f; return retval;} + glColorMask_t set_glColorMask(glColorMask_t f) { glColorMask_t retval = glColorMask; glColorMask = f; return retval;} + glColorPointer_t set_glColorPointer(glColorPointer_t f) { glColorPointer_t retval = glColorPointer; glColorPointer = f; return retval;} + glCompressedTexImage2D_t set_glCompressedTexImage2D(glCompressedTexImage2D_t f) { glCompressedTexImage2D_t retval = glCompressedTexImage2D; glCompressedTexImage2D = f; return retval;} + glCompressedTexSubImage2D_t set_glCompressedTexSubImage2D(glCompressedTexSubImage2D_t f) { glCompressedTexSubImage2D_t retval = glCompressedTexSubImage2D; glCompressedTexSubImage2D = f; return retval;} + glCopyTexImage2D_t set_glCopyTexImage2D(glCopyTexImage2D_t f) { glCopyTexImage2D_t retval = glCopyTexImage2D; glCopyTexImage2D = f; return retval;} + glCopyTexSubImage2D_t set_glCopyTexSubImage2D(glCopyTexSubImage2D_t f) { glCopyTexSubImage2D_t retval = glCopyTexSubImage2D; glCopyTexSubImage2D = f; return retval;} + glCullFace_t set_glCullFace(glCullFace_t f) { glCullFace_t retval = glCullFace; glCullFace = f; return retval;} + glDeleteBuffers_t set_glDeleteBuffers(glDeleteBuffers_t f) { glDeleteBuffers_t retval = glDeleteBuffers; glDeleteBuffers = f; return retval;} + glDeleteTextures_t set_glDeleteTextures(glDeleteTextures_t f) { glDeleteTextures_t retval = glDeleteTextures; glDeleteTextures = f; return retval;} + glDepthFunc_t set_glDepthFunc(glDepthFunc_t f) { glDepthFunc_t retval = glDepthFunc; glDepthFunc = f; return retval;} + glDepthMask_t set_glDepthMask(glDepthMask_t f) { glDepthMask_t retval = glDepthMask; glDepthMask = f; return retval;} + glDepthRangex_t set_glDepthRangex(glDepthRangex_t f) { glDepthRangex_t retval = glDepthRangex; glDepthRangex = f; return retval;} + glDisable_t set_glDisable(glDisable_t f) { glDisable_t retval = glDisable; glDisable = f; return retval;} + glDisableClientState_t set_glDisableClientState(glDisableClientState_t f) { glDisableClientState_t retval = glDisableClientState; glDisableClientState = f; return retval;} + glDrawArrays_t set_glDrawArrays(glDrawArrays_t f) { glDrawArrays_t retval = glDrawArrays; glDrawArrays = f; return retval;} + glDrawElements_t set_glDrawElements(glDrawElements_t f) { glDrawElements_t retval = glDrawElements; glDrawElements = f; return retval;} + glEnable_t set_glEnable(glEnable_t f) { glEnable_t retval = glEnable; glEnable = f; return retval;} + glEnableClientState_t set_glEnableClientState(glEnableClientState_t f) { glEnableClientState_t retval = glEnableClientState; glEnableClientState = f; return retval;} + glFinish_t set_glFinish(glFinish_t f) { glFinish_t retval = glFinish; glFinish = f; return retval;} + glFlush_t set_glFlush(glFlush_t f) { glFlush_t retval = glFlush; glFlush = f; return retval;} + glFogx_t set_glFogx(glFogx_t f) { glFogx_t retval = glFogx; glFogx = f; return retval;} + glFogxv_t set_glFogxv(glFogxv_t f) { glFogxv_t retval = glFogxv; glFogxv = f; return retval;} + glFrontFace_t set_glFrontFace(glFrontFace_t f) { glFrontFace_t retval = glFrontFace; glFrontFace = f; return retval;} + glFrustumx_t set_glFrustumx(glFrustumx_t f) { glFrustumx_t retval = glFrustumx; glFrustumx = f; return retval;} + glGetBooleanv_t set_glGetBooleanv(glGetBooleanv_t f) { glGetBooleanv_t retval = glGetBooleanv; glGetBooleanv = f; return retval;} + glGetBufferParameteriv_t set_glGetBufferParameteriv(glGetBufferParameteriv_t f) { glGetBufferParameteriv_t retval = glGetBufferParameteriv; glGetBufferParameteriv = f; return retval;} + glGetClipPlanex_t set_glGetClipPlanex(glGetClipPlanex_t f) { glGetClipPlanex_t retval = glGetClipPlanex; glGetClipPlanex = f; return retval;} + glGenBuffers_t set_glGenBuffers(glGenBuffers_t f) { glGenBuffers_t retval = glGenBuffers; glGenBuffers = f; return retval;} + glGenTextures_t set_glGenTextures(glGenTextures_t f) { glGenTextures_t retval = glGenTextures; glGenTextures = f; return retval;} + glGetError_t set_glGetError(glGetError_t f) { glGetError_t retval = glGetError; glGetError = f; return retval;} + glGetFixedv_t set_glGetFixedv(glGetFixedv_t f) { glGetFixedv_t retval = glGetFixedv; glGetFixedv = f; return retval;} + glGetIntegerv_t set_glGetIntegerv(glGetIntegerv_t f) { glGetIntegerv_t retval = glGetIntegerv; glGetIntegerv = f; return retval;} + glGetLightxv_t set_glGetLightxv(glGetLightxv_t f) { glGetLightxv_t retval = glGetLightxv; glGetLightxv = f; return retval;} + glGetMaterialxv_t set_glGetMaterialxv(glGetMaterialxv_t f) { glGetMaterialxv_t retval = glGetMaterialxv; glGetMaterialxv = f; return retval;} + glGetPointerv_t set_glGetPointerv(glGetPointerv_t f) { glGetPointerv_t retval = glGetPointerv; glGetPointerv = f; return retval;} + glGetString_t set_glGetString(glGetString_t f) { glGetString_t retval = glGetString; glGetString = f; return retval;} + glGetTexEnviv_t set_glGetTexEnviv(glGetTexEnviv_t f) { glGetTexEnviv_t retval = glGetTexEnviv; glGetTexEnviv = f; return retval;} + glGetTexEnvxv_t set_glGetTexEnvxv(glGetTexEnvxv_t f) { glGetTexEnvxv_t retval = glGetTexEnvxv; glGetTexEnvxv = f; return retval;} + glGetTexParameteriv_t set_glGetTexParameteriv(glGetTexParameteriv_t f) { glGetTexParameteriv_t retval = glGetTexParameteriv; glGetTexParameteriv = f; return retval;} + glGetTexParameterxv_t set_glGetTexParameterxv(glGetTexParameterxv_t f) { glGetTexParameterxv_t retval = glGetTexParameterxv; glGetTexParameterxv = f; return retval;} + glHint_t set_glHint(glHint_t f) { glHint_t retval = glHint; glHint = f; return retval;} + glIsBuffer_t set_glIsBuffer(glIsBuffer_t f) { glIsBuffer_t retval = glIsBuffer; glIsBuffer = f; return retval;} + glIsEnabled_t set_glIsEnabled(glIsEnabled_t f) { glIsEnabled_t retval = glIsEnabled; glIsEnabled = f; return retval;} + glIsTexture_t set_glIsTexture(glIsTexture_t f) { glIsTexture_t retval = glIsTexture; glIsTexture = f; return retval;} + glLightModelx_t set_glLightModelx(glLightModelx_t f) { glLightModelx_t retval = glLightModelx; glLightModelx = f; return retval;} + glLightModelxv_t set_glLightModelxv(glLightModelxv_t f) { glLightModelxv_t retval = glLightModelxv; glLightModelxv = f; return retval;} + glLightx_t set_glLightx(glLightx_t f) { glLightx_t retval = glLightx; glLightx = f; return retval;} + glLightxv_t set_glLightxv(glLightxv_t f) { glLightxv_t retval = glLightxv; glLightxv = f; return retval;} + glLineWidthx_t set_glLineWidthx(glLineWidthx_t f) { glLineWidthx_t retval = glLineWidthx; glLineWidthx = f; return retval;} + glLoadIdentity_t set_glLoadIdentity(glLoadIdentity_t f) { glLoadIdentity_t retval = glLoadIdentity; glLoadIdentity = f; return retval;} + glLoadMatrixx_t set_glLoadMatrixx(glLoadMatrixx_t f) { glLoadMatrixx_t retval = glLoadMatrixx; glLoadMatrixx = f; return retval;} + glLogicOp_t set_glLogicOp(glLogicOp_t f) { glLogicOp_t retval = glLogicOp; glLogicOp = f; return retval;} + glMaterialx_t set_glMaterialx(glMaterialx_t f) { glMaterialx_t retval = glMaterialx; glMaterialx = f; return retval;} + glMaterialxv_t set_glMaterialxv(glMaterialxv_t f) { glMaterialxv_t retval = glMaterialxv; glMaterialxv = f; return retval;} + glMatrixMode_t set_glMatrixMode(glMatrixMode_t f) { glMatrixMode_t retval = glMatrixMode; glMatrixMode = f; return retval;} + glMultMatrixx_t set_glMultMatrixx(glMultMatrixx_t f) { glMultMatrixx_t retval = glMultMatrixx; glMultMatrixx = f; return retval;} + glMultiTexCoord4x_t set_glMultiTexCoord4x(glMultiTexCoord4x_t f) { glMultiTexCoord4x_t retval = glMultiTexCoord4x; glMultiTexCoord4x = f; return retval;} + glNormal3x_t set_glNormal3x(glNormal3x_t f) { glNormal3x_t retval = glNormal3x; glNormal3x = f; return retval;} + glNormalPointer_t set_glNormalPointer(glNormalPointer_t f) { glNormalPointer_t retval = glNormalPointer; glNormalPointer = f; return retval;} + glOrthox_t set_glOrthox(glOrthox_t f) { glOrthox_t retval = glOrthox; glOrthox = f; return retval;} + glPixelStorei_t set_glPixelStorei(glPixelStorei_t f) { glPixelStorei_t retval = glPixelStorei; glPixelStorei = f; return retval;} + glPointParameterx_t set_glPointParameterx(glPointParameterx_t f) { glPointParameterx_t retval = glPointParameterx; glPointParameterx = f; return retval;} + glPointParameterxv_t set_glPointParameterxv(glPointParameterxv_t f) { glPointParameterxv_t retval = glPointParameterxv; glPointParameterxv = f; return retval;} + glPointSizex_t set_glPointSizex(glPointSizex_t f) { glPointSizex_t retval = glPointSizex; glPointSizex = f; return retval;} + glPolygonOffsetx_t set_glPolygonOffsetx(glPolygonOffsetx_t f) { glPolygonOffsetx_t retval = glPolygonOffsetx; glPolygonOffsetx = f; return retval;} + glPopMatrix_t set_glPopMatrix(glPopMatrix_t f) { glPopMatrix_t retval = glPopMatrix; glPopMatrix = f; return retval;} + glPushMatrix_t set_glPushMatrix(glPushMatrix_t f) { glPushMatrix_t retval = glPushMatrix; glPushMatrix = f; return retval;} + glReadPixels_t set_glReadPixels(glReadPixels_t f) { glReadPixels_t retval = glReadPixels; glReadPixels = f; return retval;} + glRotatex_t set_glRotatex(glRotatex_t f) { glRotatex_t retval = glRotatex; glRotatex = f; return retval;} + glSampleCoverage_t set_glSampleCoverage(glSampleCoverage_t f) { glSampleCoverage_t retval = glSampleCoverage; glSampleCoverage = f; return retval;} + glSampleCoveragex_t set_glSampleCoveragex(glSampleCoveragex_t f) { glSampleCoveragex_t retval = glSampleCoveragex; glSampleCoveragex = f; return retval;} + glScalex_t set_glScalex(glScalex_t f) { glScalex_t retval = glScalex; glScalex = f; return retval;} + glScissor_t set_glScissor(glScissor_t f) { glScissor_t retval = glScissor; glScissor = f; return retval;} + glShadeModel_t set_glShadeModel(glShadeModel_t f) { glShadeModel_t retval = glShadeModel; glShadeModel = f; return retval;} + glStencilFunc_t set_glStencilFunc(glStencilFunc_t f) { glStencilFunc_t retval = glStencilFunc; glStencilFunc = f; return retval;} + glStencilMask_t set_glStencilMask(glStencilMask_t f) { glStencilMask_t retval = glStencilMask; glStencilMask = f; return retval;} + glStencilOp_t set_glStencilOp(glStencilOp_t f) { glStencilOp_t retval = glStencilOp; glStencilOp = f; return retval;} + glTexCoordPointer_t set_glTexCoordPointer(glTexCoordPointer_t f) { glTexCoordPointer_t retval = glTexCoordPointer; glTexCoordPointer = f; return retval;} + glTexEnvi_t set_glTexEnvi(glTexEnvi_t f) { glTexEnvi_t retval = glTexEnvi; glTexEnvi = f; return retval;} + glTexEnvx_t set_glTexEnvx(glTexEnvx_t f) { glTexEnvx_t retval = glTexEnvx; glTexEnvx = f; return retval;} + glTexEnviv_t set_glTexEnviv(glTexEnviv_t f) { glTexEnviv_t retval = glTexEnviv; glTexEnviv = f; return retval;} + glTexEnvxv_t set_glTexEnvxv(glTexEnvxv_t f) { glTexEnvxv_t retval = glTexEnvxv; glTexEnvxv = f; return retval;} + glTexImage2D_t set_glTexImage2D(glTexImage2D_t f) { glTexImage2D_t retval = glTexImage2D; glTexImage2D = f; return retval;} + glTexParameteri_t set_glTexParameteri(glTexParameteri_t f) { glTexParameteri_t retval = glTexParameteri; glTexParameteri = f; return retval;} + glTexParameterx_t set_glTexParameterx(glTexParameterx_t f) { glTexParameterx_t retval = glTexParameterx; glTexParameterx = f; return retval;} + glTexParameteriv_t set_glTexParameteriv(glTexParameteriv_t f) { glTexParameteriv_t retval = glTexParameteriv; glTexParameteriv = f; return retval;} + glTexParameterxv_t set_glTexParameterxv(glTexParameterxv_t f) { glTexParameterxv_t retval = glTexParameterxv; glTexParameterxv = f; return retval;} + glTexSubImage2D_t set_glTexSubImage2D(glTexSubImage2D_t f) { glTexSubImage2D_t retval = glTexSubImage2D; glTexSubImage2D = f; return retval;} + glTranslatex_t set_glTranslatex(glTranslatex_t f) { glTranslatex_t retval = glTranslatex; glTranslatex = f; return retval;} + glVertexPointer_t set_glVertexPointer(glVertexPointer_t f) { glVertexPointer_t retval = glVertexPointer; glVertexPointer = f; return retval;} + glViewport_t set_glViewport(glViewport_t f) { glViewport_t retval = glViewport; glViewport = f; return retval;} + glPointSizePointerOES_t set_glPointSizePointerOES(glPointSizePointerOES_t f) { glPointSizePointerOES_t retval = glPointSizePointerOES; glPointSizePointerOES = f; return retval;} + glBlendEquationSeparateOES_t set_glBlendEquationSeparateOES(glBlendEquationSeparateOES_t f) { glBlendEquationSeparateOES_t retval = glBlendEquationSeparateOES; glBlendEquationSeparateOES = f; return retval;} + glBlendFuncSeparateOES_t set_glBlendFuncSeparateOES(glBlendFuncSeparateOES_t f) { glBlendFuncSeparateOES_t retval = glBlendFuncSeparateOES; glBlendFuncSeparateOES = f; return retval;} + glBlendEquationOES_t set_glBlendEquationOES(glBlendEquationOES_t f) { glBlendEquationOES_t retval = glBlendEquationOES; glBlendEquationOES = f; return retval;} + glDrawTexsOES_t set_glDrawTexsOES(glDrawTexsOES_t f) { glDrawTexsOES_t retval = glDrawTexsOES; glDrawTexsOES = f; return retval;} + glDrawTexiOES_t set_glDrawTexiOES(glDrawTexiOES_t f) { glDrawTexiOES_t retval = glDrawTexiOES; glDrawTexiOES = f; return retval;} + glDrawTexxOES_t set_glDrawTexxOES(glDrawTexxOES_t f) { glDrawTexxOES_t retval = glDrawTexxOES; glDrawTexxOES = f; return retval;} + glDrawTexsvOES_t set_glDrawTexsvOES(glDrawTexsvOES_t f) { glDrawTexsvOES_t retval = glDrawTexsvOES; glDrawTexsvOES = f; return retval;} + glDrawTexivOES_t set_glDrawTexivOES(glDrawTexivOES_t f) { glDrawTexivOES_t retval = glDrawTexivOES; glDrawTexivOES = f; return retval;} + glDrawTexxvOES_t set_glDrawTexxvOES(glDrawTexxvOES_t f) { glDrawTexxvOES_t retval = glDrawTexxvOES; glDrawTexxvOES = f; return retval;} + glDrawTexfOES_t set_glDrawTexfOES(glDrawTexfOES_t f) { glDrawTexfOES_t retval = glDrawTexfOES; glDrawTexfOES = f; return retval;} + glDrawTexfvOES_t set_glDrawTexfvOES(glDrawTexfvOES_t f) { glDrawTexfvOES_t retval = glDrawTexfvOES; glDrawTexfvOES = f; return retval;} + glEGLImageTargetTexture2DOES_t set_glEGLImageTargetTexture2DOES(glEGLImageTargetTexture2DOES_t f) { glEGLImageTargetTexture2DOES_t retval = glEGLImageTargetTexture2DOES; glEGLImageTargetTexture2DOES = f; return retval;} + glEGLImageTargetRenderbufferStorageOES_t set_glEGLImageTargetRenderbufferStorageOES(glEGLImageTargetRenderbufferStorageOES_t f) { glEGLImageTargetRenderbufferStorageOES_t retval = glEGLImageTargetRenderbufferStorageOES; glEGLImageTargetRenderbufferStorageOES = f; return retval;} + glAlphaFuncxOES_t set_glAlphaFuncxOES(glAlphaFuncxOES_t f) { glAlphaFuncxOES_t retval = glAlphaFuncxOES; glAlphaFuncxOES = f; return retval;} + glClearColorxOES_t set_glClearColorxOES(glClearColorxOES_t f) { glClearColorxOES_t retval = glClearColorxOES; glClearColorxOES = f; return retval;} + glClearDepthxOES_t set_glClearDepthxOES(glClearDepthxOES_t f) { glClearDepthxOES_t retval = glClearDepthxOES; glClearDepthxOES = f; return retval;} + glClipPlanexOES_t set_glClipPlanexOES(glClipPlanexOES_t f) { glClipPlanexOES_t retval = glClipPlanexOES; glClipPlanexOES = f; return retval;} + glColor4xOES_t set_glColor4xOES(glColor4xOES_t f) { glColor4xOES_t retval = glColor4xOES; glColor4xOES = f; return retval;} + glDepthRangexOES_t set_glDepthRangexOES(glDepthRangexOES_t f) { glDepthRangexOES_t retval = glDepthRangexOES; glDepthRangexOES = f; return retval;} + glFogxOES_t set_glFogxOES(glFogxOES_t f) { glFogxOES_t retval = glFogxOES; glFogxOES = f; return retval;} + glFogxvOES_t set_glFogxvOES(glFogxvOES_t f) { glFogxvOES_t retval = glFogxvOES; glFogxvOES = f; return retval;} + glFrustumxOES_t set_glFrustumxOES(glFrustumxOES_t f) { glFrustumxOES_t retval = glFrustumxOES; glFrustumxOES = f; return retval;} + glGetClipPlanexOES_t set_glGetClipPlanexOES(glGetClipPlanexOES_t f) { glGetClipPlanexOES_t retval = glGetClipPlanexOES; glGetClipPlanexOES = f; return retval;} + glGetFixedvOES_t set_glGetFixedvOES(glGetFixedvOES_t f) { glGetFixedvOES_t retval = glGetFixedvOES; glGetFixedvOES = f; return retval;} + glGetLightxvOES_t set_glGetLightxvOES(glGetLightxvOES_t f) { glGetLightxvOES_t retval = glGetLightxvOES; glGetLightxvOES = f; return retval;} + glGetMaterialxvOES_t set_glGetMaterialxvOES(glGetMaterialxvOES_t f) { glGetMaterialxvOES_t retval = glGetMaterialxvOES; glGetMaterialxvOES = f; return retval;} + glGetTexEnvxvOES_t set_glGetTexEnvxvOES(glGetTexEnvxvOES_t f) { glGetTexEnvxvOES_t retval = glGetTexEnvxvOES; glGetTexEnvxvOES = f; return retval;} + glGetTexParameterxvOES_t set_glGetTexParameterxvOES(glGetTexParameterxvOES_t f) { glGetTexParameterxvOES_t retval = glGetTexParameterxvOES; glGetTexParameterxvOES = f; return retval;} + glLightModelxOES_t set_glLightModelxOES(glLightModelxOES_t f) { glLightModelxOES_t retval = glLightModelxOES; glLightModelxOES = f; return retval;} + glLightModelxvOES_t set_glLightModelxvOES(glLightModelxvOES_t f) { glLightModelxvOES_t retval = glLightModelxvOES; glLightModelxvOES = f; return retval;} + glLightxOES_t set_glLightxOES(glLightxOES_t f) { glLightxOES_t retval = glLightxOES; glLightxOES = f; return retval;} + glLightxvOES_t set_glLightxvOES(glLightxvOES_t f) { glLightxvOES_t retval = glLightxvOES; glLightxvOES = f; return retval;} + glLineWidthxOES_t set_glLineWidthxOES(glLineWidthxOES_t f) { glLineWidthxOES_t retval = glLineWidthxOES; glLineWidthxOES = f; return retval;} + glLoadMatrixxOES_t set_glLoadMatrixxOES(glLoadMatrixxOES_t f) { glLoadMatrixxOES_t retval = glLoadMatrixxOES; glLoadMatrixxOES = f; return retval;} + glMaterialxOES_t set_glMaterialxOES(glMaterialxOES_t f) { glMaterialxOES_t retval = glMaterialxOES; glMaterialxOES = f; return retval;} + glMaterialxvOES_t set_glMaterialxvOES(glMaterialxvOES_t f) { glMaterialxvOES_t retval = glMaterialxvOES; glMaterialxvOES = f; return retval;} + glMultMatrixxOES_t set_glMultMatrixxOES(glMultMatrixxOES_t f) { glMultMatrixxOES_t retval = glMultMatrixxOES; glMultMatrixxOES = f; return retval;} + glMultiTexCoord4xOES_t set_glMultiTexCoord4xOES(glMultiTexCoord4xOES_t f) { glMultiTexCoord4xOES_t retval = glMultiTexCoord4xOES; glMultiTexCoord4xOES = f; return retval;} + glNormal3xOES_t set_glNormal3xOES(glNormal3xOES_t f) { glNormal3xOES_t retval = glNormal3xOES; glNormal3xOES = f; return retval;} + glOrthoxOES_t set_glOrthoxOES(glOrthoxOES_t f) { glOrthoxOES_t retval = glOrthoxOES; glOrthoxOES = f; return retval;} + glPointParameterxOES_t set_glPointParameterxOES(glPointParameterxOES_t f) { glPointParameterxOES_t retval = glPointParameterxOES; glPointParameterxOES = f; return retval;} + glPointParameterxvOES_t set_glPointParameterxvOES(glPointParameterxvOES_t f) { glPointParameterxvOES_t retval = glPointParameterxvOES; glPointParameterxvOES = f; return retval;} + glPointSizexOES_t set_glPointSizexOES(glPointSizexOES_t f) { glPointSizexOES_t retval = glPointSizexOES; glPointSizexOES = f; return retval;} + glPolygonOffsetxOES_t set_glPolygonOffsetxOES(glPolygonOffsetxOES_t f) { glPolygonOffsetxOES_t retval = glPolygonOffsetxOES; glPolygonOffsetxOES = f; return retval;} + glRotatexOES_t set_glRotatexOES(glRotatexOES_t f) { glRotatexOES_t retval = glRotatexOES; glRotatexOES = f; return retval;} + glSampleCoveragexOES_t set_glSampleCoveragexOES(glSampleCoveragexOES_t f) { glSampleCoveragexOES_t retval = glSampleCoveragexOES; glSampleCoveragexOES = f; return retval;} + glScalexOES_t set_glScalexOES(glScalexOES_t f) { glScalexOES_t retval = glScalexOES; glScalexOES = f; return retval;} + glTexEnvxOES_t set_glTexEnvxOES(glTexEnvxOES_t f) { glTexEnvxOES_t retval = glTexEnvxOES; glTexEnvxOES = f; return retval;} + glTexEnvxvOES_t set_glTexEnvxvOES(glTexEnvxvOES_t f) { glTexEnvxvOES_t retval = glTexEnvxvOES; glTexEnvxvOES = f; return retval;} + glTexParameterxOES_t set_glTexParameterxOES(glTexParameterxOES_t f) { glTexParameterxOES_t retval = glTexParameterxOES; glTexParameterxOES = f; return retval;} + glTexParameterxvOES_t set_glTexParameterxvOES(glTexParameterxvOES_t f) { glTexParameterxvOES_t retval = glTexParameterxvOES; glTexParameterxvOES = f; return retval;} + glTranslatexOES_t set_glTranslatexOES(glTranslatexOES_t f) { glTranslatexOES_t retval = glTranslatexOES; glTranslatexOES = f; return retval;} + glIsRenderbufferOES_t set_glIsRenderbufferOES(glIsRenderbufferOES_t f) { glIsRenderbufferOES_t retval = glIsRenderbufferOES; glIsRenderbufferOES = f; return retval;} + glBindRenderbufferOES_t set_glBindRenderbufferOES(glBindRenderbufferOES_t f) { glBindRenderbufferOES_t retval = glBindRenderbufferOES; glBindRenderbufferOES = f; return retval;} + glDeleteRenderbuffersOES_t set_glDeleteRenderbuffersOES(glDeleteRenderbuffersOES_t f) { glDeleteRenderbuffersOES_t retval = glDeleteRenderbuffersOES; glDeleteRenderbuffersOES = f; return retval;} + glGenRenderbuffersOES_t set_glGenRenderbuffersOES(glGenRenderbuffersOES_t f) { glGenRenderbuffersOES_t retval = glGenRenderbuffersOES; glGenRenderbuffersOES = f; return retval;} + glRenderbufferStorageOES_t set_glRenderbufferStorageOES(glRenderbufferStorageOES_t f) { glRenderbufferStorageOES_t retval = glRenderbufferStorageOES; glRenderbufferStorageOES = f; return retval;} + glGetRenderbufferParameterivOES_t set_glGetRenderbufferParameterivOES(glGetRenderbufferParameterivOES_t f) { glGetRenderbufferParameterivOES_t retval = glGetRenderbufferParameterivOES; glGetRenderbufferParameterivOES = f; return retval;} + glIsFramebufferOES_t set_glIsFramebufferOES(glIsFramebufferOES_t f) { glIsFramebufferOES_t retval = glIsFramebufferOES; glIsFramebufferOES = f; return retval;} + glBindFramebufferOES_t set_glBindFramebufferOES(glBindFramebufferOES_t f) { glBindFramebufferOES_t retval = glBindFramebufferOES; glBindFramebufferOES = f; return retval;} + glDeleteFramebuffersOES_t set_glDeleteFramebuffersOES(glDeleteFramebuffersOES_t f) { glDeleteFramebuffersOES_t retval = glDeleteFramebuffersOES; glDeleteFramebuffersOES = f; return retval;} + glGenFramebuffersOES_t set_glGenFramebuffersOES(glGenFramebuffersOES_t f) { glGenFramebuffersOES_t retval = glGenFramebuffersOES; glGenFramebuffersOES = f; return retval;} + glCheckFramebufferStatusOES_t set_glCheckFramebufferStatusOES(glCheckFramebufferStatusOES_t f) { glCheckFramebufferStatusOES_t retval = glCheckFramebufferStatusOES; glCheckFramebufferStatusOES = f; return retval;} + glFramebufferRenderbufferOES_t set_glFramebufferRenderbufferOES(glFramebufferRenderbufferOES_t f) { glFramebufferRenderbufferOES_t retval = glFramebufferRenderbufferOES; glFramebufferRenderbufferOES = f; return retval;} + glFramebufferTexture2DOES_t set_glFramebufferTexture2DOES(glFramebufferTexture2DOES_t f) { glFramebufferTexture2DOES_t retval = glFramebufferTexture2DOES; glFramebufferTexture2DOES = f; return retval;} + glGetFramebufferAttachmentParameterivOES_t set_glGetFramebufferAttachmentParameterivOES(glGetFramebufferAttachmentParameterivOES_t f) { glGetFramebufferAttachmentParameterivOES_t retval = glGetFramebufferAttachmentParameterivOES; glGetFramebufferAttachmentParameterivOES = f; return retval;} + glGenerateMipmapOES_t set_glGenerateMipmapOES(glGenerateMipmapOES_t f) { glGenerateMipmapOES_t retval = glGenerateMipmapOES; glGenerateMipmapOES = f; return retval;} + glMapBufferOES_t set_glMapBufferOES(glMapBufferOES_t f) { glMapBufferOES_t retval = glMapBufferOES; glMapBufferOES = f; return retval;} + glUnmapBufferOES_t set_glUnmapBufferOES(glUnmapBufferOES_t f) { glUnmapBufferOES_t retval = glUnmapBufferOES; glUnmapBufferOES = f; return retval;} + glGetBufferPointervOES_t set_glGetBufferPointervOES(glGetBufferPointervOES_t f) { glGetBufferPointervOES_t retval = glGetBufferPointervOES; glGetBufferPointervOES = f; return retval;} + glCurrentPaletteMatrixOES_t set_glCurrentPaletteMatrixOES(glCurrentPaletteMatrixOES_t f) { glCurrentPaletteMatrixOES_t retval = glCurrentPaletteMatrixOES; glCurrentPaletteMatrixOES = f; return retval;} + glLoadPaletteFromModelViewMatrixOES_t set_glLoadPaletteFromModelViewMatrixOES(glLoadPaletteFromModelViewMatrixOES_t f) { glLoadPaletteFromModelViewMatrixOES_t retval = glLoadPaletteFromModelViewMatrixOES; glLoadPaletteFromModelViewMatrixOES = f; return retval;} + glMatrixIndexPointerOES_t set_glMatrixIndexPointerOES(glMatrixIndexPointerOES_t f) { glMatrixIndexPointerOES_t retval = glMatrixIndexPointerOES; glMatrixIndexPointerOES = f; return retval;} + glWeightPointerOES_t set_glWeightPointerOES(glWeightPointerOES_t f) { glWeightPointerOES_t retval = glWeightPointerOES; glWeightPointerOES = f; return retval;} + glQueryMatrixxOES_t set_glQueryMatrixxOES(glQueryMatrixxOES_t f) { glQueryMatrixxOES_t retval = glQueryMatrixxOES; glQueryMatrixxOES = f; return retval;} + glDepthRangefOES_t set_glDepthRangefOES(glDepthRangefOES_t f) { glDepthRangefOES_t retval = glDepthRangefOES; glDepthRangefOES = f; return retval;} + glFrustumfOES_t set_glFrustumfOES(glFrustumfOES_t f) { glFrustumfOES_t retval = glFrustumfOES; glFrustumfOES = f; return retval;} + glOrthofOES_t set_glOrthofOES(glOrthofOES_t f) { glOrthofOES_t retval = glOrthofOES; glOrthofOES = f; return retval;} + glClipPlanefOES_t set_glClipPlanefOES(glClipPlanefOES_t f) { glClipPlanefOES_t retval = glClipPlanefOES; glClipPlanefOES = f; return retval;} + glGetClipPlanefOES_t set_glGetClipPlanefOES(glGetClipPlanefOES_t f) { glGetClipPlanefOES_t retval = glGetClipPlanefOES; glGetClipPlanefOES = f; return retval;} + glClearDepthfOES_t set_glClearDepthfOES(glClearDepthfOES_t f) { glClearDepthfOES_t retval = glClearDepthfOES; glClearDepthfOES = f; return retval;} + glTexGenfOES_t set_glTexGenfOES(glTexGenfOES_t f) { glTexGenfOES_t retval = glTexGenfOES; glTexGenfOES = f; return retval;} + glTexGenfvOES_t set_glTexGenfvOES(glTexGenfvOES_t f) { glTexGenfvOES_t retval = glTexGenfvOES; glTexGenfvOES = f; return retval;} + glTexGeniOES_t set_glTexGeniOES(glTexGeniOES_t f) { glTexGeniOES_t retval = glTexGeniOES; glTexGeniOES = f; return retval;} + glTexGenivOES_t set_glTexGenivOES(glTexGenivOES_t f) { glTexGenivOES_t retval = glTexGenivOES; glTexGenivOES = f; return retval;} + glTexGenxOES_t set_glTexGenxOES(glTexGenxOES_t f) { glTexGenxOES_t retval = glTexGenxOES; glTexGenxOES = f; return retval;} + glTexGenxvOES_t set_glTexGenxvOES(glTexGenxvOES_t f) { glTexGenxvOES_t retval = glTexGenxvOES; glTexGenxvOES = f; return retval;} + glGetTexGenfvOES_t set_glGetTexGenfvOES(glGetTexGenfvOES_t f) { glGetTexGenfvOES_t retval = glGetTexGenfvOES; glGetTexGenfvOES = f; return retval;} + glGetTexGenivOES_t set_glGetTexGenivOES(glGetTexGenivOES_t f) { glGetTexGenivOES_t retval = glGetTexGenivOES; glGetTexGenivOES = f; return retval;} + glGetTexGenxvOES_t set_glGetTexGenxvOES(glGetTexGenxvOES_t f) { glGetTexGenxvOES_t retval = glGetTexGenxvOES; glGetTexGenxvOES = f; return retval;} + glBindVertexArrayOES_t set_glBindVertexArrayOES(glBindVertexArrayOES_t f) { glBindVertexArrayOES_t retval = glBindVertexArrayOES; glBindVertexArrayOES = f; return retval;} + glDeleteVertexArraysOES_t set_glDeleteVertexArraysOES(glDeleteVertexArraysOES_t f) { glDeleteVertexArraysOES_t retval = glDeleteVertexArraysOES; glDeleteVertexArraysOES = f; return retval;} + glGenVertexArraysOES_t set_glGenVertexArraysOES(glGenVertexArraysOES_t f) { glGenVertexArraysOES_t retval = glGenVertexArraysOES; glGenVertexArraysOES = f; return retval;} + glIsVertexArrayOES_t set_glIsVertexArrayOES(glIsVertexArrayOES_t f) { glIsVertexArrayOES_t retval = glIsVertexArrayOES; glIsVertexArrayOES = f; return retval;} + glDiscardFramebufferEXT_t set_glDiscardFramebufferEXT(glDiscardFramebufferEXT_t f) { glDiscardFramebufferEXT_t retval = glDiscardFramebufferEXT; glDiscardFramebufferEXT = f; return retval;} + glMultiDrawArraysEXT_t set_glMultiDrawArraysEXT(glMultiDrawArraysEXT_t f) { glMultiDrawArraysEXT_t retval = glMultiDrawArraysEXT; glMultiDrawArraysEXT = f; return retval;} + glMultiDrawElementsEXT_t set_glMultiDrawElementsEXT(glMultiDrawElementsEXT_t f) { glMultiDrawElementsEXT_t retval = glMultiDrawElementsEXT; glMultiDrawElementsEXT = f; return retval;} + glClipPlanefIMG_t set_glClipPlanefIMG(glClipPlanefIMG_t f) { glClipPlanefIMG_t retval = glClipPlanefIMG; glClipPlanefIMG = f; return retval;} + glClipPlanexIMG_t set_glClipPlanexIMG(glClipPlanexIMG_t f) { glClipPlanexIMG_t retval = glClipPlanexIMG; glClipPlanexIMG = f; return retval;} + glRenderbufferStorageMultisampleIMG_t set_glRenderbufferStorageMultisampleIMG(glRenderbufferStorageMultisampleIMG_t f) { glRenderbufferStorageMultisampleIMG_t retval = glRenderbufferStorageMultisampleIMG; glRenderbufferStorageMultisampleIMG = f; return retval;} + glFramebufferTexture2DMultisampleIMG_t set_glFramebufferTexture2DMultisampleIMG(glFramebufferTexture2DMultisampleIMG_t f) { glFramebufferTexture2DMultisampleIMG_t retval = glFramebufferTexture2DMultisampleIMG; glFramebufferTexture2DMultisampleIMG = f; return retval;} + glDeleteFencesNV_t set_glDeleteFencesNV(glDeleteFencesNV_t f) { glDeleteFencesNV_t retval = glDeleteFencesNV; glDeleteFencesNV = f; return retval;} + glGenFencesNV_t set_glGenFencesNV(glGenFencesNV_t f) { glGenFencesNV_t retval = glGenFencesNV; glGenFencesNV = f; return retval;} + glIsFenceNV_t set_glIsFenceNV(glIsFenceNV_t f) { glIsFenceNV_t retval = glIsFenceNV; glIsFenceNV = f; return retval;} + glTestFenceNV_t set_glTestFenceNV(glTestFenceNV_t f) { glTestFenceNV_t retval = glTestFenceNV; glTestFenceNV = f; return retval;} + glGetFenceivNV_t set_glGetFenceivNV(glGetFenceivNV_t f) { glGetFenceivNV_t retval = glGetFenceivNV; glGetFenceivNV = f; return retval;} + glFinishFenceNV_t set_glFinishFenceNV(glFinishFenceNV_t f) { glFinishFenceNV_t retval = glFinishFenceNV; glFinishFenceNV = f; return retval;} + glSetFenceNV_t set_glSetFenceNV(glSetFenceNV_t f) { glSetFenceNV_t retval = glSetFenceNV; glSetFenceNV = f; return retval;} + glGetDriverControlsQCOM_t set_glGetDriverControlsQCOM(glGetDriverControlsQCOM_t f) { glGetDriverControlsQCOM_t retval = glGetDriverControlsQCOM; glGetDriverControlsQCOM = f; return retval;} + glGetDriverControlStringQCOM_t set_glGetDriverControlStringQCOM(glGetDriverControlStringQCOM_t f) { glGetDriverControlStringQCOM_t retval = glGetDriverControlStringQCOM; glGetDriverControlStringQCOM = f; return retval;} + glEnableDriverControlQCOM_t set_glEnableDriverControlQCOM(glEnableDriverControlQCOM_t f) { glEnableDriverControlQCOM_t retval = glEnableDriverControlQCOM; glEnableDriverControlQCOM = f; return retval;} + glDisableDriverControlQCOM_t set_glDisableDriverControlQCOM(glDisableDriverControlQCOM_t f) { glDisableDriverControlQCOM_t retval = glDisableDriverControlQCOM; glDisableDriverControlQCOM = f; return retval;} + glExtGetTexturesQCOM_t set_glExtGetTexturesQCOM(glExtGetTexturesQCOM_t f) { glExtGetTexturesQCOM_t retval = glExtGetTexturesQCOM; glExtGetTexturesQCOM = f; return retval;} + glExtGetBuffersQCOM_t set_glExtGetBuffersQCOM(glExtGetBuffersQCOM_t f) { glExtGetBuffersQCOM_t retval = glExtGetBuffersQCOM; glExtGetBuffersQCOM = f; return retval;} + glExtGetRenderbuffersQCOM_t set_glExtGetRenderbuffersQCOM(glExtGetRenderbuffersQCOM_t f) { glExtGetRenderbuffersQCOM_t retval = glExtGetRenderbuffersQCOM; glExtGetRenderbuffersQCOM = f; return retval;} + glExtGetFramebuffersQCOM_t set_glExtGetFramebuffersQCOM(glExtGetFramebuffersQCOM_t f) { glExtGetFramebuffersQCOM_t retval = glExtGetFramebuffersQCOM; glExtGetFramebuffersQCOM = f; return retval;} + glExtGetTexLevelParameterivQCOM_t set_glExtGetTexLevelParameterivQCOM(glExtGetTexLevelParameterivQCOM_t f) { glExtGetTexLevelParameterivQCOM_t retval = glExtGetTexLevelParameterivQCOM; glExtGetTexLevelParameterivQCOM = f; return retval;} + glExtTexObjectStateOverrideiQCOM_t set_glExtTexObjectStateOverrideiQCOM(glExtTexObjectStateOverrideiQCOM_t f) { glExtTexObjectStateOverrideiQCOM_t retval = glExtTexObjectStateOverrideiQCOM; glExtTexObjectStateOverrideiQCOM = f; return retval;} + glExtGetTexSubImageQCOM_t set_glExtGetTexSubImageQCOM(glExtGetTexSubImageQCOM_t f) { glExtGetTexSubImageQCOM_t retval = glExtGetTexSubImageQCOM; glExtGetTexSubImageQCOM = f; return retval;} + glExtGetBufferPointervQCOM_t set_glExtGetBufferPointervQCOM(glExtGetBufferPointervQCOM_t f) { glExtGetBufferPointervQCOM_t retval = glExtGetBufferPointervQCOM; glExtGetBufferPointervQCOM = f; return retval;} + glExtGetShadersQCOM_t set_glExtGetShadersQCOM(glExtGetShadersQCOM_t f) { glExtGetShadersQCOM_t retval = glExtGetShadersQCOM; glExtGetShadersQCOM = f; return retval;} + glExtGetProgramsQCOM_t set_glExtGetProgramsQCOM(glExtGetProgramsQCOM_t f) { glExtGetProgramsQCOM_t retval = glExtGetProgramsQCOM; glExtGetProgramsQCOM = f; return retval;} + glExtIsProgramBinaryQCOM_t set_glExtIsProgramBinaryQCOM(glExtIsProgramBinaryQCOM_t f) { glExtIsProgramBinaryQCOM_t retval = glExtIsProgramBinaryQCOM; glExtIsProgramBinaryQCOM = f; return retval;} + glExtGetProgramBinarySourceQCOM_t set_glExtGetProgramBinarySourceQCOM(glExtGetProgramBinarySourceQCOM_t f) { glExtGetProgramBinarySourceQCOM_t retval = glExtGetProgramBinarySourceQCOM; glExtGetProgramBinarySourceQCOM = f; return retval;} + glStartTilingQCOM_t set_glStartTilingQCOM(glStartTilingQCOM_t f) { glStartTilingQCOM_t retval = glStartTilingQCOM; glStartTilingQCOM = f; return retval;} + glEndTilingQCOM_t set_glEndTilingQCOM(glEndTilingQCOM_t f) { glEndTilingQCOM_t retval = glEndTilingQCOM; glEndTilingQCOM = f; return retval;} +}; + +gles_dispatch *create_gles_dispatch(void *gles_andorid); + +#endif diff --git a/emulator/opengl/tests/gles_android_wrapper/gles_emul.cfg b/emulator/opengl/tests/gles_android_wrapper/gles_emul.cfg new file mode 100644 index 0000000..a837807 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/gles_emul.cfg @@ -0,0 +1,7 @@ +angeles +my-tritex +org.zeroxlab.benchmark +com.cooliris.media +com.polarbit.waveblazerlite +test-opengl-gl2_basic +com.trendy.ddapp diff --git a/emulator/opengl/tests/gles_android_wrapper/gles_ftable.h b/emulator/opengl/tests/gles_android_wrapper/gles_ftable.h new file mode 100644 index 0000000..1895b18 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/gles_ftable.h @@ -0,0 +1,292 @@ +/* +* 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. +*/ +static struct _gles_funcs_by_name { + const char *name; + void *proc; +} gles_funcs_by_name[] = { + {"glAlphaFunc", (void *)glAlphaFunc}, + {"glClearColor", (void *)glClearColor}, + {"glClearDepthf", (void *)glClearDepthf}, + {"glClipPlanef", (void *)glClipPlanef}, + {"glColor4f", (void *)glColor4f}, + {"glDepthRangef", (void *)glDepthRangef}, + {"glFogf", (void *)glFogf}, + {"glFogfv", (void *)glFogfv}, + {"glFrustumf", (void *)glFrustumf}, + {"glGetClipPlanef", (void *)glGetClipPlanef}, + {"glGetFloatv", (void *)glGetFloatv}, + {"glGetLightfv", (void *)glGetLightfv}, + {"glGetMaterialfv", (void *)glGetMaterialfv}, + {"glGetTexEnvfv", (void *)glGetTexEnvfv}, + {"glGetTexParameterfv", (void *)glGetTexParameterfv}, + {"glLightModelf", (void *)glLightModelf}, + {"glLightModelfv", (void *)glLightModelfv}, + {"glLightf", (void *)glLightf}, + {"glLightfv", (void *)glLightfv}, + {"glLineWidth", (void *)glLineWidth}, + {"glLoadMatrixf", (void *)glLoadMatrixf}, + {"glMaterialf", (void *)glMaterialf}, + {"glMaterialfv", (void *)glMaterialfv}, + {"glMultMatrixf", (void *)glMultMatrixf}, + {"glMultiTexCoord4f", (void *)glMultiTexCoord4f}, + {"glNormal3f", (void *)glNormal3f}, + {"glOrthof", (void *)glOrthof}, + {"glPointParameterf", (void *)glPointParameterf}, + {"glPointParameterfv", (void *)glPointParameterfv}, + {"glPointSize", (void *)glPointSize}, + {"glPolygonOffset", (void *)glPolygonOffset}, + {"glRotatef", (void *)glRotatef}, + {"glScalef", (void *)glScalef}, + {"glTexEnvf", (void *)glTexEnvf}, + {"glTexEnvfv", (void *)glTexEnvfv}, + {"glTexParameterf", (void *)glTexParameterf}, + {"glTexParameterfv", (void *)glTexParameterfv}, + {"glTranslatef", (void *)glTranslatef}, + {"glActiveTexture", (void *)glActiveTexture}, + {"glAlphaFuncx", (void *)glAlphaFuncx}, + {"glBindBuffer", (void *)glBindBuffer}, + {"glBindTexture", (void *)glBindTexture}, + {"glBlendFunc", (void *)glBlendFunc}, + {"glBufferData", (void *)glBufferData}, + {"glBufferSubData", (void *)glBufferSubData}, + {"glClear", (void *)glClear}, + {"glClearColorx", (void *)glClearColorx}, + {"glClearDepthx", (void *)glClearDepthx}, + {"glClearStencil", (void *)glClearStencil}, + {"glClientActiveTexture", (void *)glClientActiveTexture}, + {"glClipPlanex", (void *)glClipPlanex}, + {"glColor4ub", (void *)glColor4ub}, + {"glColor4x", (void *)glColor4x}, + {"glColorMask", (void *)glColorMask}, + {"glColorPointer", (void *)glColorPointer}, + {"glCompressedTexImage2D", (void *)glCompressedTexImage2D}, + {"glCompressedTexSubImage2D", (void *)glCompressedTexSubImage2D}, + {"glCopyTexImage2D", (void *)glCopyTexImage2D}, + {"glCopyTexSubImage2D", (void *)glCopyTexSubImage2D}, + {"glCullFace", (void *)glCullFace}, + {"glDeleteBuffers", (void *)glDeleteBuffers}, + {"glDeleteTextures", (void *)glDeleteTextures}, + {"glDepthFunc", (void *)glDepthFunc}, + {"glDepthMask", (void *)glDepthMask}, + {"glDepthRangex", (void *)glDepthRangex}, + {"glDisable", (void *)glDisable}, + {"glDisableClientState", (void *)glDisableClientState}, + {"glDrawArrays", (void *)glDrawArrays}, + {"glDrawElements", (void *)glDrawElements}, + {"glEnable", (void *)glEnable}, + {"glEnableClientState", (void *)glEnableClientState}, + {"glFinish", (void *)glFinish}, + {"glFlush", (void *)glFlush}, + {"glFogx", (void *)glFogx}, + {"glFogxv", (void *)glFogxv}, + {"glFrontFace", (void *)glFrontFace}, + {"glFrustumx", (void *)glFrustumx}, + {"glGetBooleanv", (void *)glGetBooleanv}, + {"glGetBufferParameteriv", (void *)glGetBufferParameteriv}, + {"glGetClipPlanex", (void *)glGetClipPlanex}, + {"glGenBuffers", (void *)glGenBuffers}, + {"glGenTextures", (void *)glGenTextures}, + {"glGetError", (void *)glGetError}, + {"glGetFixedv", (void *)glGetFixedv}, + {"glGetIntegerv", (void *)glGetIntegerv}, + {"glGetLightxv", (void *)glGetLightxv}, + {"glGetMaterialxv", (void *)glGetMaterialxv}, + {"glGetPointerv", (void *)glGetPointerv}, + {"glGetString", (void *)glGetString}, + {"glGetTexEnviv", (void *)glGetTexEnviv}, + {"glGetTexEnvxv", (void *)glGetTexEnvxv}, + {"glGetTexParameteriv", (void *)glGetTexParameteriv}, + {"glGetTexParameterxv", (void *)glGetTexParameterxv}, + {"glHint", (void *)glHint}, + {"glIsBuffer", (void *)glIsBuffer}, + {"glIsEnabled", (void *)glIsEnabled}, + {"glIsTexture", (void *)glIsTexture}, + {"glLightModelx", (void *)glLightModelx}, + {"glLightModelxv", (void *)glLightModelxv}, + {"glLightx", (void *)glLightx}, + {"glLightxv", (void *)glLightxv}, + {"glLineWidthx", (void *)glLineWidthx}, + {"glLoadIdentity", (void *)glLoadIdentity}, + {"glLoadMatrixx", (void *)glLoadMatrixx}, + {"glLogicOp", (void *)glLogicOp}, + {"glMaterialx", (void *)glMaterialx}, + {"glMaterialxv", (void *)glMaterialxv}, + {"glMatrixMode", (void *)glMatrixMode}, + {"glMultMatrixx", (void *)glMultMatrixx}, + {"glMultiTexCoord4x", (void *)glMultiTexCoord4x}, + {"glNormal3x", (void *)glNormal3x}, + {"glNormalPointer", (void *)glNormalPointer}, + {"glOrthox", (void *)glOrthox}, + {"glPixelStorei", (void *)glPixelStorei}, + {"glPointParameterx", (void *)glPointParameterx}, + {"glPointParameterxv", (void *)glPointParameterxv}, + {"glPointSizex", (void *)glPointSizex}, + {"glPolygonOffsetx", (void *)glPolygonOffsetx}, + {"glPopMatrix", (void *)glPopMatrix}, + {"glPushMatrix", (void *)glPushMatrix}, + {"glReadPixels", (void *)glReadPixels}, + {"glRotatex", (void *)glRotatex}, + {"glSampleCoverage", (void *)glSampleCoverage}, + {"glSampleCoveragex", (void *)glSampleCoveragex}, + {"glScalex", (void *)glScalex}, + {"glScissor", (void *)glScissor}, + {"glShadeModel", (void *)glShadeModel}, + {"glStencilFunc", (void *)glStencilFunc}, + {"glStencilMask", (void *)glStencilMask}, + {"glStencilOp", (void *)glStencilOp}, + {"glTexCoordPointer", (void *)glTexCoordPointer}, + {"glTexEnvi", (void *)glTexEnvi}, + {"glTexEnvx", (void *)glTexEnvx}, + {"glTexEnviv", (void *)glTexEnviv}, + {"glTexEnvxv", (void *)glTexEnvxv}, + {"glTexImage2D", (void *)glTexImage2D}, + {"glTexParameteri", (void *)glTexParameteri}, + {"glTexParameterx", (void *)glTexParameterx}, + {"glTexParameteriv", (void *)glTexParameteriv}, + {"glTexParameterxv", (void *)glTexParameterxv}, + {"glTexSubImage2D", (void *)glTexSubImage2D}, + {"glTranslatex", (void *)glTranslatex}, + {"glVertexPointer", (void *)glVertexPointer}, + {"glViewport", (void *)glViewport}, + {"glPointSizePointerOES", (void *)glPointSizePointerOES}, + {"glBlendEquationSeparateOES", (void *)glBlendEquationSeparateOES}, + {"glBlendFuncSeparateOES", (void *)glBlendFuncSeparateOES}, + {"glBlendEquationOES", (void *)glBlendEquationOES}, + {"glDrawTexsOES", (void *)glDrawTexsOES}, + {"glDrawTexiOES", (void *)glDrawTexiOES}, + {"glDrawTexxOES", (void *)glDrawTexxOES}, + {"glDrawTexsvOES", (void *)glDrawTexsvOES}, + {"glDrawTexivOES", (void *)glDrawTexivOES}, + {"glDrawTexxvOES", (void *)glDrawTexxvOES}, + {"glDrawTexfOES", (void *)glDrawTexfOES}, + {"glDrawTexfvOES", (void *)glDrawTexfvOES}, + {"glEGLImageTargetTexture2DOES", (void *)glEGLImageTargetTexture2DOES}, + {"glEGLImageTargetRenderbufferStorageOES", (void *)glEGLImageTargetRenderbufferStorageOES}, + {"glAlphaFuncxOES", (void *)glAlphaFuncxOES}, + {"glClearColorxOES", (void *)glClearColorxOES}, + {"glClearDepthxOES", (void *)glClearDepthxOES}, + {"glClipPlanexOES", (void *)glClipPlanexOES}, + {"glColor4xOES", (void *)glColor4xOES}, + {"glDepthRangexOES", (void *)glDepthRangexOES}, + {"glFogxOES", (void *)glFogxOES}, + {"glFogxvOES", (void *)glFogxvOES}, + {"glFrustumxOES", (void *)glFrustumxOES}, + {"glGetClipPlanexOES", (void *)glGetClipPlanexOES}, + {"glGetFixedvOES", (void *)glGetFixedvOES}, + {"glGetLightxvOES", (void *)glGetLightxvOES}, + {"glGetMaterialxvOES", (void *)glGetMaterialxvOES}, + {"glGetTexEnvxvOES", (void *)glGetTexEnvxvOES}, + {"glGetTexParameterxvOES", (void *)glGetTexParameterxvOES}, + {"glLightModelxOES", (void *)glLightModelxOES}, + {"glLightModelxvOES", (void *)glLightModelxvOES}, + {"glLightxOES", (void *)glLightxOES}, + {"glLightxvOES", (void *)glLightxvOES}, + {"glLineWidthxOES", (void *)glLineWidthxOES}, + {"glLoadMatrixxOES", (void *)glLoadMatrixxOES}, + {"glMaterialxOES", (void *)glMaterialxOES}, + {"glMaterialxvOES", (void *)glMaterialxvOES}, + {"glMultMatrixxOES", (void *)glMultMatrixxOES}, + {"glMultiTexCoord4xOES", (void *)glMultiTexCoord4xOES}, + {"glNormal3xOES", (void *)glNormal3xOES}, + {"glOrthoxOES", (void *)glOrthoxOES}, + {"glPointParameterxOES", (void *)glPointParameterxOES}, + {"glPointParameterxvOES", (void *)glPointParameterxvOES}, + {"glPointSizexOES", (void *)glPointSizexOES}, + {"glPolygonOffsetxOES", (void *)glPolygonOffsetxOES}, + {"glRotatexOES", (void *)glRotatexOES}, + {"glSampleCoveragexOES", (void *)glSampleCoveragexOES}, + {"glScalexOES", (void *)glScalexOES}, + {"glTexEnvxOES", (void *)glTexEnvxOES}, + {"glTexEnvxvOES", (void *)glTexEnvxvOES}, + {"glTexParameterxOES", (void *)glTexParameterxOES}, + {"glTexParameterxvOES", (void *)glTexParameterxvOES}, + {"glTranslatexOES", (void *)glTranslatexOES}, + {"glIsRenderbufferOES", (void *)glIsRenderbufferOES}, + {"glBindRenderbufferOES", (void *)glBindRenderbufferOES}, + {"glDeleteRenderbuffersOES", (void *)glDeleteRenderbuffersOES}, + {"glGenRenderbuffersOES", (void *)glGenRenderbuffersOES}, + {"glRenderbufferStorageOES", (void *)glRenderbufferStorageOES}, + {"glGetRenderbufferParameterivOES", (void *)glGetRenderbufferParameterivOES}, + {"glIsFramebufferOES", (void *)glIsFramebufferOES}, + {"glBindFramebufferOES", (void *)glBindFramebufferOES}, + {"glDeleteFramebuffersOES", (void *)glDeleteFramebuffersOES}, + {"glGenFramebuffersOES", (void *)glGenFramebuffersOES}, + {"glCheckFramebufferStatusOES", (void *)glCheckFramebufferStatusOES}, + {"glFramebufferRenderbufferOES", (void *)glFramebufferRenderbufferOES}, + {"glFramebufferTexture2DOES", (void *)glFramebufferTexture2DOES}, + {"glGetFramebufferAttachmentParameterivOES", (void *)glGetFramebufferAttachmentParameterivOES}, + {"glGenerateMipmapOES", (void *)glGenerateMipmapOES}, + {"glMapBufferOES", (void *)glMapBufferOES}, + {"glUnmapBufferOES", (void *)glUnmapBufferOES}, + {"glGetBufferPointervOES", (void *)glGetBufferPointervOES}, + {"glCurrentPaletteMatrixOES", (void *)glCurrentPaletteMatrixOES}, + {"glLoadPaletteFromModelViewMatrixOES", (void *)glLoadPaletteFromModelViewMatrixOES}, + {"glMatrixIndexPointerOES", (void *)glMatrixIndexPointerOES}, + {"glWeightPointerOES", (void *)glWeightPointerOES}, + {"glQueryMatrixxOES", (void *)glQueryMatrixxOES}, + {"glDepthRangefOES", (void *)glDepthRangefOES}, + {"glFrustumfOES", (void *)glFrustumfOES}, + {"glOrthofOES", (void *)glOrthofOES}, + {"glClipPlanefOES", (void *)glClipPlanefOES}, + {"glGetClipPlanefOES", (void *)glGetClipPlanefOES}, + {"glClearDepthfOES", (void *)glClearDepthfOES}, + {"glTexGenfOES", (void *)glTexGenfOES}, + {"glTexGenfvOES", (void *)glTexGenfvOES}, + {"glTexGeniOES", (void *)glTexGeniOES}, + {"glTexGenivOES", (void *)glTexGenivOES}, + {"glTexGenxOES", (void *)glTexGenxOES}, + {"glTexGenxvOES", (void *)glTexGenxvOES}, + {"glGetTexGenfvOES", (void *)glGetTexGenfvOES}, + {"glGetTexGenivOES", (void *)glGetTexGenivOES}, + {"glGetTexGenxvOES", (void *)glGetTexGenxvOES}, + {"glBindVertexArrayOES", (void *)glBindVertexArrayOES}, + {"glDeleteVertexArraysOES", (void *)glDeleteVertexArraysOES}, + {"glGenVertexArraysOES", (void *)glGenVertexArraysOES}, + {"glIsVertexArrayOES", (void *)glIsVertexArrayOES}, + {"glDiscardFramebufferEXT", (void *)glDiscardFramebufferEXT}, + {"glMultiDrawArraysEXT", (void *)glMultiDrawArraysEXT}, + {"glMultiDrawElementsEXT", (void *)glMultiDrawElementsEXT}, + {"glClipPlanefIMG", (void *)glClipPlanefIMG}, + {"glClipPlanexIMG", (void *)glClipPlanexIMG}, + {"glRenderbufferStorageMultisampleIMG", (void *)glRenderbufferStorageMultisampleIMG}, + {"glFramebufferTexture2DMultisampleIMG", (void *)glFramebufferTexture2DMultisampleIMG}, + {"glDeleteFencesNV", (void *)glDeleteFencesNV}, + {"glGenFencesNV", (void *)glGenFencesNV}, + {"glIsFenceNV", (void *)glIsFenceNV}, + {"glTestFenceNV", (void *)glTestFenceNV}, + {"glGetFenceivNV", (void *)glGetFenceivNV}, + {"glFinishFenceNV", (void *)glFinishFenceNV}, + {"glSetFenceNV", (void *)glSetFenceNV}, + {"glGetDriverControlsQCOM", (void *)glGetDriverControlsQCOM}, + {"glGetDriverControlStringQCOM", (void *)glGetDriverControlStringQCOM}, + {"glEnableDriverControlQCOM", (void *)glEnableDriverControlQCOM}, + {"glDisableDriverControlQCOM", (void *)glDisableDriverControlQCOM}, + {"glExtGetTexturesQCOM", (void *)glExtGetTexturesQCOM}, + {"glExtGetBuffersQCOM", (void *)glExtGetBuffersQCOM}, + {"glExtGetRenderbuffersQCOM", (void *)glExtGetRenderbuffersQCOM}, + {"glExtGetFramebuffersQCOM", (void *)glExtGetFramebuffersQCOM}, + {"glExtGetTexLevelParameterivQCOM", (void *)glExtGetTexLevelParameterivQCOM}, + {"glExtTexObjectStateOverrideiQCOM", (void *)glExtTexObjectStateOverrideiQCOM}, + {"glExtGetTexSubImageQCOM", (void *)glExtGetTexSubImageQCOM}, + {"glExtGetBufferPointervQCOM", (void *)glExtGetBufferPointervQCOM}, + {"glExtGetShadersQCOM", (void *)glExtGetShadersQCOM}, + {"glExtGetProgramsQCOM", (void *)glExtGetProgramsQCOM}, + {"glExtIsProgramBinaryQCOM", (void *)glExtIsProgramBinaryQCOM}, + {"glExtGetProgramBinarySourceQCOM", (void *)glExtGetProgramBinarySourceQCOM}, + {"glStartTilingQCOM", (void *)glStartTilingQCOM}, + {"glEndTilingQCOM", (void *)glEndTilingQCOM} +}; +static int gles_num_funcs = sizeof(gles_funcs_by_name) / sizeof(struct _gles_funcs_by_name); diff --git a/emulator/opengl/tests/gles_android_wrapper/gles_proc.h b/emulator/opengl/tests/gles_android_wrapper/gles_proc.h new file mode 100644 index 0000000..afd94b9 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/gles_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 (* glAlphaFunc_t) (GLenum, GLclampf); +typedef void (* glClearColor_t) (GLclampf, GLclampf, GLclampf, GLclampf); +typedef void (* glClearDepthf_t) (GLclampf); +typedef void (* glClipPlanef_t) (GLenum, const GLfloat*); +typedef void (* glColor4f_t) (GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (* glDepthRangef_t) (GLclampf, GLclampf); +typedef void (* glFogf_t) (GLenum, GLfloat); +typedef void (* glFogfv_t) (GLenum, const GLfloat*); +typedef void (* glFrustumf_t) (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (* glGetClipPlanef_t) (GLenum, GLfloat*); +typedef void (* glGetFloatv_t) (GLenum, GLfloat*); +typedef void (* glGetLightfv_t) (GLenum, GLenum, GLfloat*); +typedef void (* glGetMaterialfv_t) (GLenum, GLenum, GLfloat*); +typedef void (* glGetTexEnvfv_t) (GLenum, GLenum, GLfloat*); +typedef void (* glGetTexParameterfv_t) (GLenum, GLenum, GLfloat*); +typedef void (* glLightModelf_t) (GLenum, GLfloat); +typedef void (* glLightModelfv_t) (GLenum, const GLfloat*); +typedef void (* glLightf_t) (GLenum, GLenum, GLfloat); +typedef void (* glLightfv_t) (GLenum, GLenum, const GLfloat*); +typedef void (* glLineWidth_t) (GLfloat); +typedef void (* glLoadMatrixf_t) (const GLfloat*); +typedef void (* glMaterialf_t) (GLenum, GLenum, GLfloat); +typedef void (* glMaterialfv_t) (GLenum, GLenum, const GLfloat*); +typedef void (* glMultMatrixf_t) (const GLfloat*); +typedef void (* glMultiTexCoord4f_t) (GLenum, GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (* glNormal3f_t) (GLfloat, GLfloat, GLfloat); +typedef void (* glOrthof_t) (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (* glPointParameterf_t) (GLenum, GLfloat); +typedef void (* glPointParameterfv_t) (GLenum, const GLfloat*); +typedef void (* glPointSize_t) (GLfloat); +typedef void (* glPolygonOffset_t) (GLfloat, GLfloat); +typedef void (* glRotatef_t) (GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (* glScalef_t) (GLfloat, GLfloat, GLfloat); +typedef void (* glTexEnvf_t) (GLenum, GLenum, GLfloat); +typedef void (* glTexEnvfv_t) (GLenum, GLenum, const GLfloat*); +typedef void (* glTexParameterf_t) (GLenum, GLenum, GLfloat); +typedef void (* glTexParameterfv_t) (GLenum, GLenum, const GLfloat*); +typedef void (* glTranslatef_t) (GLfloat, GLfloat, GLfloat); +typedef void (* glActiveTexture_t) (GLenum); +typedef void (* glAlphaFuncx_t) (GLenum, GLclampx); +typedef void (* glBindBuffer_t) (GLenum, GLuint); +typedef void (* glBindTexture_t) (GLenum, GLuint); +typedef void (* glBlendFunc_t) (GLenum, GLenum); +typedef void (* glBufferData_t) (GLenum, GLsizeiptr, const GLvoid*, GLenum); +typedef void (* glBufferSubData_t) (GLenum, GLintptr, GLsizeiptr, const GLvoid*); +typedef void (* glClear_t) (GLbitfield); +typedef void (* glClearColorx_t) (GLclampx, GLclampx, GLclampx, GLclampx); +typedef void (* glClearDepthx_t) (GLclampx); +typedef void (* glClearStencil_t) (GLint); +typedef void (* glClientActiveTexture_t) (GLenum); +typedef void (* glClipPlanex_t) (GLenum, const GLfixed*); +typedef void (* glColor4ub_t) (GLubyte, GLubyte, GLubyte, GLubyte); +typedef void (* glColor4x_t) (GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glColorMask_t) (GLboolean, GLboolean, GLboolean, GLboolean); +typedef void (* glColorPointer_t) (GLint, GLenum, GLsizei, const GLvoid*); +typedef void (* glCompressedTexImage2D_t) (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid*); +typedef void (* glCompressedTexSubImage2D_t) (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid*); +typedef void (* glCopyTexImage2D_t) (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLsizei, GLint); +typedef void (* glCopyTexSubImage2D_t) (GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei); +typedef void (* glCullFace_t) (GLenum); +typedef void (* glDeleteBuffers_t) (GLsizei, const GLuint*); +typedef void (* glDeleteTextures_t) (GLsizei, const GLuint*); +typedef void (* glDepthFunc_t) (GLenum); +typedef void (* glDepthMask_t) (GLboolean); +typedef void (* glDepthRangex_t) (GLclampx, GLclampx); +typedef void (* glDisable_t) (GLenum); +typedef void (* glDisableClientState_t) (GLenum); +typedef void (* glDrawArrays_t) (GLenum, GLint, GLsizei); +typedef void (* glDrawElements_t) (GLenum, GLsizei, GLenum, const GLvoid*); +typedef void (* glEnable_t) (GLenum); +typedef void (* glEnableClientState_t) (GLenum); +typedef void (* glFinish_t) (); +typedef void (* glFlush_t) (); +typedef void (* glFogx_t) (GLenum, GLfixed); +typedef void (* glFogxv_t) (GLenum, const GLfixed*); +typedef void (* glFrontFace_t) (GLenum); +typedef void (* glFrustumx_t) (GLfixed, GLfixed, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glGetBooleanv_t) (GLenum, GLboolean*); +typedef void (* glGetBufferParameteriv_t) (GLenum, GLenum, GLint*); +typedef void (* glGetClipPlanex_t) (GLenum, GLfixed*); +typedef void (* glGenBuffers_t) (GLsizei, GLuint*); +typedef void (* glGenTextures_t) (GLsizei, GLuint*); +typedef GLenum (* glGetError_t) (); +typedef void (* glGetFixedv_t) (GLenum, GLfixed*); +typedef void (* glGetIntegerv_t) (GLenum, GLint*); +typedef void (* glGetLightxv_t) (GLenum, GLenum, GLfixed*); +typedef void (* glGetMaterialxv_t) (GLenum, GLenum, GLfixed*); +typedef void (* glGetPointerv_t) (GLenum, GLvoid**); +typedef const GLubyte* (* glGetString_t) (GLenum); +typedef void (* glGetTexEnviv_t) (GLenum, GLenum, GLint*); +typedef void (* glGetTexEnvxv_t) (GLenum, GLenum, GLfixed*); +typedef void (* glGetTexParameteriv_t) (GLenum, GLenum, GLint*); +typedef void (* glGetTexParameterxv_t) (GLenum, GLenum, GLfixed*); +typedef void (* glHint_t) (GLenum, GLenum); +typedef GLboolean (* glIsBuffer_t) (GLuint); +typedef GLboolean (* glIsEnabled_t) (GLenum); +typedef GLboolean (* glIsTexture_t) (GLuint); +typedef void (* glLightModelx_t) (GLenum, GLfixed); +typedef void (* glLightModelxv_t) (GLenum, const GLfixed*); +typedef void (* glLightx_t) (GLenum, GLenum, GLfixed); +typedef void (* glLightxv_t) (GLenum, GLenum, const GLfixed*); +typedef void (* glLineWidthx_t) (GLfixed); +typedef void (* glLoadIdentity_t) (); +typedef void (* glLoadMatrixx_t) (const GLfixed*); +typedef void (* glLogicOp_t) (GLenum); +typedef void (* glMaterialx_t) (GLenum, GLenum, GLfixed); +typedef void (* glMaterialxv_t) (GLenum, GLenum, const GLfixed*); +typedef void (* glMatrixMode_t) (GLenum); +typedef void (* glMultMatrixx_t) (const GLfixed*); +typedef void (* glMultiTexCoord4x_t) (GLenum, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glNormal3x_t) (GLfixed, GLfixed, GLfixed); +typedef void (* glNormalPointer_t) (GLenum, GLsizei, const GLvoid*); +typedef void (* glOrthox_t) (GLfixed, GLfixed, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glPixelStorei_t) (GLenum, GLint); +typedef void (* glPointParameterx_t) (GLenum, GLfixed); +typedef void (* glPointParameterxv_t) (GLenum, const GLfixed*); +typedef void (* glPointSizex_t) (GLfixed); +typedef void (* glPolygonOffsetx_t) (GLfixed, GLfixed); +typedef void (* glPopMatrix_t) (); +typedef void (* glPushMatrix_t) (); +typedef void (* glReadPixels_t) (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid*); +typedef void (* glRotatex_t) (GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glSampleCoverage_t) (GLclampf, GLboolean); +typedef void (* glSampleCoveragex_t) (GLclampx, GLboolean); +typedef void (* glScalex_t) (GLfixed, GLfixed, GLfixed); +typedef void (* glScissor_t) (GLint, GLint, GLsizei, GLsizei); +typedef void (* glShadeModel_t) (GLenum); +typedef void (* glStencilFunc_t) (GLenum, GLint, GLuint); +typedef void (* glStencilMask_t) (GLuint); +typedef void (* glStencilOp_t) (GLenum, GLenum, GLenum); +typedef void (* glTexCoordPointer_t) (GLint, GLenum, GLsizei, const GLvoid*); +typedef void (* glTexEnvi_t) (GLenum, GLenum, GLint); +typedef void (* glTexEnvx_t) (GLenum, GLenum, GLfixed); +typedef void (* glTexEnviv_t) (GLenum, GLenum, const GLint*); +typedef void (* glTexEnvxv_t) (GLenum, GLenum, const GLfixed*); +typedef void (* glTexImage2D_t) (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid*); +typedef void (* glTexParameteri_t) (GLenum, GLenum, GLint); +typedef void (* glTexParameterx_t) (GLenum, GLenum, GLfixed); +typedef void (* glTexParameteriv_t) (GLenum, GLenum, const GLint*); +typedef void (* glTexParameterxv_t) (GLenum, GLenum, const GLfixed*); +typedef void (* glTexSubImage2D_t) (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid*); +typedef void (* glTranslatex_t) (GLfixed, GLfixed, GLfixed); +typedef void (* glVertexPointer_t) (GLint, GLenum, GLsizei, const GLvoid*); +typedef void (* glViewport_t) (GLint, GLint, GLsizei, GLsizei); +typedef void (* glPointSizePointerOES_t) (GLenum, GLsizei, const GLvoid*); +typedef void (* glBlendEquationSeparateOES_t) (GLenum, GLenum); +typedef void (* glBlendFuncSeparateOES_t) (GLenum, GLenum, GLenum, GLenum); +typedef void (* glBlendEquationOES_t) (GLenum); +typedef void (* glDrawTexsOES_t) (GLshort, GLshort, GLshort, GLshort, GLshort); +typedef void (* glDrawTexiOES_t) (GLint, GLint, GLint, GLint, GLint); +typedef void (* glDrawTexxOES_t) (GLfixed, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glDrawTexsvOES_t) (const GLshort*); +typedef void (* glDrawTexivOES_t) (const GLint*); +typedef void (* glDrawTexxvOES_t) (const GLfixed*); +typedef void (* glDrawTexfOES_t) (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (* glDrawTexfvOES_t) (const GLfloat*); +typedef void (* glEGLImageTargetTexture2DOES_t) (GLenum, GLeglImageOES); +typedef void (* glEGLImageTargetRenderbufferStorageOES_t) (GLenum, GLeglImageOES); +typedef void (* glAlphaFuncxOES_t) (GLenum, GLclampx); +typedef void (* glClearColorxOES_t) (GLclampx, GLclampx, GLclampx, GLclampx); +typedef void (* glClearDepthxOES_t) (GLclampx); +typedef void (* glClipPlanexOES_t) (GLenum, const GLfixed*); +typedef void (* glColor4xOES_t) (GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glDepthRangexOES_t) (GLclampx, GLclampx); +typedef void (* glFogxOES_t) (GLenum, GLfixed); +typedef void (* glFogxvOES_t) (GLenum, const GLfixed*); +typedef void (* glFrustumxOES_t) (GLfixed, GLfixed, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glGetClipPlanexOES_t) (GLenum, GLfixed*); +typedef void (* glGetFixedvOES_t) (GLenum, GLfixed*); +typedef void (* glGetLightxvOES_t) (GLenum, GLenum, GLfixed*); +typedef void (* glGetMaterialxvOES_t) (GLenum, GLenum, GLfixed*); +typedef void (* glGetTexEnvxvOES_t) (GLenum, GLenum, GLfixed*); +typedef void (* glGetTexParameterxvOES_t) (GLenum, GLenum, GLfixed*); +typedef void (* glLightModelxOES_t) (GLenum, GLfixed); +typedef void (* glLightModelxvOES_t) (GLenum, const GLfixed*); +typedef void (* glLightxOES_t) (GLenum, GLenum, GLfixed); +typedef void (* glLightxvOES_t) (GLenum, GLenum, const GLfixed*); +typedef void (* glLineWidthxOES_t) (GLfixed); +typedef void (* glLoadMatrixxOES_t) (const GLfixed*); +typedef void (* glMaterialxOES_t) (GLenum, GLenum, GLfixed); +typedef void (* glMaterialxvOES_t) (GLenum, GLenum, const GLfixed*); +typedef void (* glMultMatrixxOES_t) (const GLfixed*); +typedef void (* glMultiTexCoord4xOES_t) (GLenum, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glNormal3xOES_t) (GLfixed, GLfixed, GLfixed); +typedef void (* glOrthoxOES_t) (GLfixed, GLfixed, GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glPointParameterxOES_t) (GLenum, GLfixed); +typedef void (* glPointParameterxvOES_t) (GLenum, const GLfixed*); +typedef void (* glPointSizexOES_t) (GLfixed); +typedef void (* glPolygonOffsetxOES_t) (GLfixed, GLfixed); +typedef void (* glRotatexOES_t) (GLfixed, GLfixed, GLfixed, GLfixed); +typedef void (* glSampleCoveragexOES_t) (GLclampx, GLboolean); +typedef void (* glScalexOES_t) (GLfixed, GLfixed, GLfixed); +typedef void (* glTexEnvxOES_t) (GLenum, GLenum, GLfixed); +typedef void (* glTexEnvxvOES_t) (GLenum, GLenum, const GLfixed*); +typedef void (* glTexParameterxOES_t) (GLenum, GLenum, GLfixed); +typedef void (* glTexParameterxvOES_t) (GLenum, GLenum, const GLfixed*); +typedef void (* glTranslatexOES_t) (GLfixed, GLfixed, GLfixed); +typedef GLboolean (* glIsRenderbufferOES_t) (GLuint); +typedef void (* glBindRenderbufferOES_t) (GLenum, GLuint); +typedef void (* glDeleteRenderbuffersOES_t) (GLsizei, const GLuint*); +typedef void (* glGenRenderbuffersOES_t) (GLsizei, GLuint*); +typedef void (* glRenderbufferStorageOES_t) (GLenum, GLenum, GLsizei, GLsizei); +typedef void (* glGetRenderbufferParameterivOES_t) (GLenum, GLenum, GLint*); +typedef GLboolean (* glIsFramebufferOES_t) (GLuint); +typedef void (* glBindFramebufferOES_t) (GLenum, GLuint); +typedef void (* glDeleteFramebuffersOES_t) (GLsizei, const GLuint*); +typedef void (* glGenFramebuffersOES_t) (GLsizei, GLuint*); +typedef GLenum (* glCheckFramebufferStatusOES_t) (GLenum); +typedef void (* glFramebufferRenderbufferOES_t) (GLenum, GLenum, GLenum, GLuint); +typedef void (* glFramebufferTexture2DOES_t) (GLenum, GLenum, GLenum, GLuint, GLint); +typedef void (* glGetFramebufferAttachmentParameterivOES_t) (GLenum, GLenum, GLenum, GLint*); +typedef void (* glGenerateMipmapOES_t) (GLenum); +typedef void* (* glMapBufferOES_t) (GLenum, GLenum); +typedef GLboolean (* glUnmapBufferOES_t) (GLenum); +typedef void (* glGetBufferPointervOES_t) (GLenum, GLenum, GLvoid*); +typedef void (* glCurrentPaletteMatrixOES_t) (GLuint); +typedef void (* glLoadPaletteFromModelViewMatrixOES_t) (); +typedef void (* glMatrixIndexPointerOES_t) (GLint, GLenum, GLsizei, const GLvoid*); +typedef void (* glWeightPointerOES_t) (GLint, GLenum, GLsizei, const GLvoid*); +typedef GLbitfield (* glQueryMatrixxOES_t) (GLfixed*, GLint*); +typedef void (* glDepthRangefOES_t) (GLclampf, GLclampf); +typedef void (* glFrustumfOES_t) (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (* glOrthofOES_t) (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (* glClipPlanefOES_t) (GLenum, const GLfloat*); +typedef void (* glGetClipPlanefOES_t) (GLenum, GLfloat*); +typedef void (* glClearDepthfOES_t) (GLclampf); +typedef void (* glTexGenfOES_t) (GLenum, GLenum, GLfloat); +typedef void (* glTexGenfvOES_t) (GLenum, GLenum, const GLfloat*); +typedef void (* glTexGeniOES_t) (GLenum, GLenum, GLint); +typedef void (* glTexGenivOES_t) (GLenum, GLenum, const GLint*); +typedef void (* glTexGenxOES_t) (GLenum, GLenum, GLfixed); +typedef void (* glTexGenxvOES_t) (GLenum, GLenum, const GLfixed*); +typedef void (* glGetTexGenfvOES_t) (GLenum, GLenum, GLfloat*); +typedef void (* glGetTexGenivOES_t) (GLenum, GLenum, GLint*); +typedef void (* glGetTexGenxvOES_t) (GLenum, GLenum, GLfixed*); +typedef void (* glBindVertexArrayOES_t) (GLuint); +typedef void (* glDeleteVertexArraysOES_t) (GLsizei, const GLuint*); +typedef void (* glGenVertexArraysOES_t) (GLsizei, GLuint*); +typedef GLboolean (* glIsVertexArrayOES_t) (GLuint); +typedef void (* glDiscardFramebufferEXT_t) (GLenum, GLsizei, const GLenum*); +typedef void (* glMultiDrawArraysEXT_t) (GLenum, GLint*, GLsizei*, GLsizei); +typedef void (* glMultiDrawElementsEXT_t) (GLenum, const GLsizei*, GLenum, const GLvoid**, GLsizei); +typedef void (* glClipPlanefIMG_t) (GLenum, const GLfloat*); +typedef void (* glClipPlanexIMG_t) (GLenum, const GLfixed*); +typedef void (* glRenderbufferStorageMultisampleIMG_t) (GLenum, GLsizei, GLenum, GLsizei, GLsizei); +typedef void (* glFramebufferTexture2DMultisampleIMG_t) (GLenum, GLenum, GLenum, GLuint, GLint, GLsizei); +typedef void (* glDeleteFencesNV_t) (GLsizei, const GLuint*); +typedef void (* glGenFencesNV_t) (GLsizei, GLuint*); +typedef GLboolean (* glIsFenceNV_t) (GLuint); +typedef GLboolean (* glTestFenceNV_t) (GLuint); +typedef void (* glGetFenceivNV_t) (GLuint, GLenum, GLint*); +typedef void (* glFinishFenceNV_t) (GLuint); +typedef void (* glSetFenceNV_t) (GLuint, GLenum); +typedef void (* glGetDriverControlsQCOM_t) (GLint*, GLsizei, GLuint*); +typedef void (* glGetDriverControlStringQCOM_t) (GLuint, GLsizei, GLsizei*, GLchar*); +typedef void (* glEnableDriverControlQCOM_t) (GLuint); +typedef void (* glDisableDriverControlQCOM_t) (GLuint); +typedef void (* glExtGetTexturesQCOM_t) (GLuint*, GLint, GLint*); +typedef void (* glExtGetBuffersQCOM_t) (GLuint*, GLint, GLint*); +typedef void (* glExtGetRenderbuffersQCOM_t) (GLuint*, GLint, GLint*); +typedef void (* glExtGetFramebuffersQCOM_t) (GLuint*, GLint, GLint*); +typedef void (* glExtGetTexLevelParameterivQCOM_t) (GLuint, GLenum, GLint, GLenum, GLint*); +typedef void (* glExtTexObjectStateOverrideiQCOM_t) (GLenum, GLenum, GLint); +typedef void (* glExtGetTexSubImageQCOM_t) (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, GLvoid*); +typedef void (* glExtGetBufferPointervQCOM_t) (GLenum, GLvoid**); +typedef void (* glExtGetShadersQCOM_t) (GLuint*, GLint, GLint*); +typedef void (* glExtGetProgramsQCOM_t) (GLuint*, GLint, GLint*); +typedef GLboolean (* glExtIsProgramBinaryQCOM_t) (GLuint); +typedef void (* glExtGetProgramBinarySourceQCOM_t) (GLuint, GLenum, GLchar*, GLint*); +typedef void (* glStartTilingQCOM_t) (GLuint, GLuint, GLuint, GLuint, GLbitfield); +typedef void (* glEndTilingQCOM_t) (GLbitfield); + + +#endif diff --git a/emulator/opengl/tests/gles_android_wrapper/glesv1_emul_ifc.cpp b/emulator/opengl/tests/gles_android_wrapper/glesv1_emul_ifc.cpp new file mode 100644 index 0000000..26c98a8 --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/glesv1_emul_ifc.cpp @@ -0,0 +1,39 @@ +/* +* 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 <stdlib.h> +#include "ApiInitializer.h" +#include <dlfcn.h> +#include "gl_wrapper_context.h" + +extern "C" { + gl_wrapper_context_t *createFromLib(void *solib, gl_wrapper_context_t *(*accessor)()); +} + +gl_wrapper_context_t * createFromLib(void *solib, gl_wrapper_context_t *(accessor)()) +{ + gl_wrapper_context_t *ctx = new gl_wrapper_context_t; + if (ctx == NULL) { + return NULL; + } + ApiInitializer *initializer = new ApiInitializer(solib); + ctx->initDispatchByName(ApiInitializer::s_getProc, initializer); + gl_wrapper_context_t::setContextAccessor(accessor); + delete initializer; + return ctx; +} + + diff --git a/emulator/opengl/tests/gles_android_wrapper/glesv2_emul_ifc.cpp b/emulator/opengl/tests/gles_android_wrapper/glesv2_emul_ifc.cpp new file mode 100644 index 0000000..4ae13dd --- /dev/null +++ b/emulator/opengl/tests/gles_android_wrapper/glesv2_emul_ifc.cpp @@ -0,0 +1,40 @@ +/* +* 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 <stdlib.h> +#include "ApiInitializer.h" +#include <dlfcn.h> +#include "gl2_wrapper_context.h" + +extern "C" { + gl2_wrapper_context_t *createFromLib(void *solib, gl2_wrapper_context_t *(*accessor)()); +} + +gl2_wrapper_context_t * createFromLib(void *solib, gl2_wrapper_context_t *(*accessor)()) +{ + gl2_wrapper_context_t *ctx = new gl2_wrapper_context_t; + if (ctx == NULL) { + return NULL; + } + ApiInitializer *initializer = new ApiInitializer(solib); + ctx->initDispatchByName(ApiInitializer::s_getProc, initializer); + gl2_wrapper_context_t::setContextAccessor(accessor); + delete initializer; + return ctx; +} + + + diff --git a/emulator/opengl/tests/translator_tests/GLES_CM/Android.mk b/emulator/opengl/tests/translator_tests/GLES_CM/Android.mk new file mode 100644 index 0000000..77cd272 --- /dev/null +++ b/emulator/opengl/tests/translator_tests/GLES_CM/Android.mk @@ -0,0 +1,32 @@ +LOCAL_PATH:= $(call my-dir) + +$(call emugl-begin-host-executable,triangleCM) +$(call emugl-import,libEGL_translator libGLES_CM_translator) + +PREBUILT := $(HOST_PREBUILT_TAG) +LOCAL_SDL_CONFIG ?= prebuilts/tools/$(PREBUILT)/sdl/bin/sdl-config +LOCAL_SDL_CFLAGS := $(shell $(LOCAL_SDL_CONFIG) --cflags) +LOCAL_SDL_LDLIBS := $(filter-out %.a %.lib,$(shell $(LOCAL_SDL_CONFIG) --static-libs)) + +ifeq ($(HOST_OS),darwin) + DARWIN_VERSION := $(strip $(shell sw_vers -productVersion)) + ifneq ($(filter 10.7 10.7.%,$(DARWIN_VERSION)),) + # Lion needs to be forced to link dylib to avoid problems + # with the dynamic function lookups in SDL 1.2 + LOCAL_SDL_LDLIBS += /usr/lib/dylib1.o + endif +endif + +LOCAL_SRC_FILES:= \ + triangleCM.cpp + +LOCAL_CFLAGS += $(LOCAL_SDL_CFLAGS) -g -O0 +LOCAL_LDLIBS += $(LOCAL_SDL_LDLIBS) + +LOCAL_STATIC_LIBRARIES += libSDL libSDLmain + +ifeq ($(HOST_OS),darwin) +$(call emugl-import,libMac_view) +endif + +$(call emugl-end-module) diff --git a/emulator/opengl/tests/translator_tests/GLES_CM/triangleCM.cpp b/emulator/opengl/tests/translator_tests/GLES_CM/triangleCM.cpp new file mode 100644 index 0000000..7547cd0 --- /dev/null +++ b/emulator/opengl/tests/translator_tests/GLES_CM/triangleCM.cpp @@ -0,0 +1,463 @@ +/* +* 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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> + +//#define GL_API +//#define GL_APIENTRY + +#undef ANDROID +#include <EGL/egl.h> +#include <GLES/gl.h> + +#ifdef __APPLE__ +extern "C" void * createGLView(void *nsWindowPtr, int x, int y, int width, int height); +#endif + +#undef HAVE_MALLOC_H +#include <SDL.h> +#include <SDL_syswm.h> + + +#define WINDOW_WIDTH 500 +#define WINDOW_HEIGHT 500 + +#define TEX_WIDTH 256 +#define TEX_HEIGHT 256 + + +#define F_to_X(d) ((d) > 32767.65535 ? 32767 * 65536 + 65535 : \ + (d) < -32768.65535 ? -32768 * 65536 + 65535 : \ + ((GLfixed) ((d) * 65536))) +#define X_to_F(x) ((float)(x))/65536.0f + +static EGLint const attribute_list[] = { + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_NONE +}; + +unsigned char *genTexture(int width, int height, int comp) +{ + unsigned char *img = new unsigned char[width * height * comp]; + unsigned char *ptr = img; + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + unsigned char col = ((i / 8 + j / 8) % 2) * 255 ; + if (j>(width/2)) col/=2; + for (int c = 0; c < comp; c++) { + *ptr = col; ptr++; + } + } + } + return img; +} + +unsigned char *genRedTexture(int width, int height, int comp) +{ + unsigned char *img = new unsigned char[width * height * comp]; + memset(img,0,width*height*comp); + unsigned char *ptr = img; + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + unsigned char col = ((i / 8 + j / 8) % 2) * 255 ; + *ptr = col; + ptr+=comp; + } + } + return img; +} + +//mip 0; +unsigned char *genPalette4_rgb8(int width, int height,int color) +{ + int size = width*height/2 + 16*3/*palette size*/; + unsigned char *img = new unsigned char[size]; + + memset(img,0,size); + img[0] = 255; img[1] = 0; img[2] = 0; // red + img[3] = 0; img[4] = 0; img[5] = 255; //blue + img[7] = 128; img[8] = 0; img[9] = 128; //fucsia + //rest of the palette is empty + + unsigned char *ptr = img+(16*3); + for (int i = 0; i < (height*width/2); i++) { + ptr[i] = (i%2)?0x0|color:0x11|color; + } + return img; +} + +void usage(const char *progname) +{ + fprintf(stderr, "usage: %s [-n <nframes> -i -h]\n", progname); + fprintf(stderr, "\t-h: this message\n"); + fprintf(stderr, "\t-i: immidate mode\n"); + fprintf(stderr, "\t-n nframes: generate nframes\n"); + fprintf(stderr, "\t-e: use index arrays\n"); + fprintf(stderr, "\t-t: use texture\n"); + fprintf(stderr, "\t-f: use fixed points\n"); + fprintf(stderr, "\t-p: use point size OES extention\n"); +} + +#define SWITCH_SOURCE(add)\ + if(useConvertedType){ \ + if(useFixed){ \ + data = (GLvoid*)(fixedVertices+(add)); \ + } else { \ + data = (GLvoid*)(byteVertices +(add)); \ + } \ + } else { \ + data = (GLvoid*)(afVertices+(add)); \ + } \ + +#ifdef _WIN32 +int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) +#else +int main(int argc, char **argv) +#endif +{ + GLuint ui32Vbo = 0; // Vertex buffer object handle + GLuint ui32IndexVbo; + GLuint ui32Texture; + + int nframes = 100; + bool immidateMode = false; + bool useIndices = true; + bool useTexture = false; + bool useCompTexture = false; + bool useConvertedType = true; + bool useFixed = false; + bool usePoints = false; + bool useCopy = false; + bool useSubCopy = false; + + int c; + extern char *optarg; + + #ifdef _WIN32 + HWND windowId = NULL; + #elif __linux__ + Window windowId = NULL; + #elif __APPLE__ + void* windowId = NULL; + #endif + + // // Inialize SDL window + // + if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_VIDEO)) { + fprintf(stderr,"SDL init failed: %s\n", SDL_GetError()); + return -1; + } + + SDL_Surface *surface = SDL_SetVideoMode(WINDOW_WIDTH,WINDOW_HEIGHT, 32, SDL_HWSURFACE); + if (surface == NULL) { + fprintf(stderr,"Failed to set video mode: %s\n", SDL_GetError()); + return -1; + } + + SDL_SysWMinfo wminfo; + memset(&wminfo, 0, sizeof(wminfo)); + SDL_GetWMInfo(&wminfo); + #ifdef _WIN32 + windowId = wminfo.window; + #elif __linux__ + windowId = wminfo.info.x11.window; + #elif __APPLE__ + windowId = createGLView(wminfo.nsWindowPtr,0,0,WINDOW_WIDTH,WINDOW_HEIGHT); + + #endif + + int major,minor,num_config; + EGLConfig configs[150]; + EGLSurface egl_surface; + EGLContext ctx; + EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); + eglInitialize(d,&major,&minor); + printf("DISPLAY == %p major =%d minor = %d\n",d,major,minor); + eglChooseConfig(d, attribute_list, configs, 150, &num_config); + printf("config returned %d\n",num_config); + egl_surface = eglCreateWindowSurface(d,configs[0],windowId,NULL); + printf("before creating context..\n"); + ctx = eglCreateContext(d,configs[0],EGL_NO_CONTEXT,NULL); + printf("SURFACE == %p CONTEXT == %p\n",egl_surface,ctx); + if(eglMakeCurrent(d,egl_surface,egl_surface,ctx)!= EGL_TRUE){ + printf("make current failed\n"); + return false; + } + printf("after make current\n"); + + GLenum err = glGetError(); + if(err != GL_NO_ERROR) { + printf("error before drawing ->>> %d \n",err); + } else { + printf("no error before drawing\n"); + } + + if (useTexture) { + + glEnable(GL_TEXTURE_2D); + ui32Texture = 1; + glBindTexture(GL_TEXTURE_2D, ui32Texture); + GLenum err = glGetError(); + + unsigned char *pixels = NULL; + if(useCompTexture) { + pixels = genPalette4_rgb8(TEX_WIDTH,TEX_HEIGHT,3); + glCompressedTexImage2D(GL_TEXTURE_2D,0,GL_PALETTE4_RGB8_OES,TEX_WIDTH,TEX_HEIGHT,0,3*16+TEX_WIDTH*TEX_HEIGHT/2,pixels); + + } else { + pixels = genTexture(TEX_WIDTH, TEX_HEIGHT, 4); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_WIDTH, TEX_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + } + + delete pixels; + + err = glGetError(); + if(err != GL_NO_ERROR) + printf("error %d after image \n",err); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + err = glGetError(); + if(err != GL_NO_ERROR) + printf("error after min filter \n"); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + err = glGetError(); + if(err != GL_NO_ERROR) + printf("error after mag filter \n"); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + err = glGetError(); + if(err != GL_NO_ERROR) + printf("error after env mode \n"); + + if(useCompTexture) { + pixels = genPalette4_rgb8(TEX_WIDTH,TEX_HEIGHT,1); + glCompressedTexSubImage2D(GL_TEXTURE_2D,0,TEX_WIDTH/4,TEX_HEIGHT/4,TEX_WIDTH/8,TEX_HEIGHT/8,GL_PALETTE4_RGB8_OES,3*16+(TEX_WIDTH*TEX_HEIGHT/128),pixels); + } else { + pixels = genRedTexture(TEX_WIDTH/8, TEX_HEIGHT/8, 4); + glTexSubImage2D(GL_TEXTURE_2D,0,TEX_WIDTH/4,TEX_HEIGHT/4,TEX_WIDTH/8,TEX_HEIGHT/8,GL_RGBA,GL_UNSIGNED_BYTE,pixels); + } + err = glGetError(); + if(err != GL_NO_ERROR) + printf("error %d after subimage \n",err); + delete pixels; + + } + + glClearColor(0.6f, 0.8f, 1.0f, 1.0f); // clear blue + + float afVertices[] = { -0.4f,-0.4f,0.0f, // Position + 1.0f,0.0f,0.0f,1.0f, // Color + 0.0f, 0.0f, // texture + 12.f, //point size + + 0.4f,-0.4f,0.0f, + 0.0f,1.0f,0.0f,1.0f, + 1.0f, 0.0f, + 47.0f, + + 0.0f,0.4f,0.0f, + 0.0f,0.0f,1.0f,1.0f, + 0.5f, 1.0f, + 14.0f + }; + +#define MAX_T 1 +#define MID_T 0 +#define MIN_T 0 + + GLbyte byteVertices[] = { -1,-1,0, // Position + 255,0,0,255, // Color + MIN_T, MIN_T, // texture + 12, //point size + + 1,-1,0, + 0,255,0,255, + MAX_T,MIN_T, + 47, + + 0,1,0, + 0,0,255,255, + MID_T, MAX_T, + 14 + }; + + GLfixed fixedVertices[] = { F_to_X(-0.4f),F_to_X(-0.4f),F_to_X(0.0f), // Position + F_to_X(1.0f),F_to_X(0.0f),F_to_X(0.0f),F_to_X(1.0f), // Color + F_to_X(0.0f),F_to_X(0.0f), // texture + F_to_X(12.0f),//points size + + F_to_X(0.4f),F_to_X(-0.4f),F_to_X(0.0f), + F_to_X(0.0f),F_to_X(1.0f),F_to_X(0.0f),F_to_X(1.0f), + F_to_X(1.0f),F_to_X( 0.0f), + F_to_X(30.0f), + + F_to_X(0.0f),F_to_X(0.4f),F_to_X(0.0f), + F_to_X(0.0f),F_to_X(0.0f),F_to_X(1.0f),F_to_X(1.0f), + F_to_X(0.5f), F_to_X(1.0f), + F_to_X(30.0) + }; + + unsigned short indices[] = { 2, 1, 0 }; + + if (!immidateMode) { + glGenBuffers(1, &ui32Vbo); + ui32Vbo = 1; + printf("ui32Vbo = %d\n", ui32Vbo); + + glBindBuffer(GL_ARRAY_BUFFER, ui32Vbo); + void* data = (void*)afVertices; + unsigned int uiSize = 3*(sizeof(float)*10); + if(useConvertedType){ + if(useFixed){ + data = (void*)fixedVertices; + } else { + data = (void*)byteVertices; + uiSize = 3*(sizeof(GLbyte)*10); + } + } + glBufferData(GL_ARRAY_BUFFER, uiSize,data, GL_STATIC_DRAW); + + ui32IndexVbo = 2; + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ui32IndexVbo); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); + } + + // Draws a triangle for 800 frames + float angle = 0.0; + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + GLvoid* arr = NULL; + GLenum type; + GLenum drawType; + GLenum colorType; + int size_of; + + if(useConvertedType){ + if(useFixed) + { + arr = fixedVertices; + colorType = type = GL_FIXED; + size_of = sizeof(GLfixed); + } else { + arr = byteVertices; + colorType = GL_UNSIGNED_BYTE; + type = GL_BYTE; + size_of = sizeof(GLbyte); + } + }else { + arr = afVertices; + colorType = type = GL_FLOAT; + size_of = sizeof(float); + } + + if(usePoints) + { + drawType = GL_POINTS; + } + else + drawType = GL_TRIANGLES; + + GLvoid* data = NULL; + for (int i = 0; i < 100; i++) { + + glClear(GL_COLOR_BUFFER_BIT); + glPushMatrix(); + glRotatef(angle, 0.0, 0.0, 1.0); + angle += 360.0 / nframes; + // Enable vertex arrays + glEnableClientState(GL_VERTEX_ARRAY); + if (immidateMode) { + glVertexPointer(3,type, size_of * 10, arr); + } else { + glVertexPointer(3,type, size_of * 10, 0); + } + + // Set color data in the same way + glEnableClientState(GL_COLOR_ARRAY); + if (immidateMode) { + SWITCH_SOURCE(3) + glColorPointer(4, colorType, size_of * 10, data); + } else { + glColorPointer(4,colorType,size_of * 10, (GLvoid*) (size_of * 3) ); + } + if (useTexture) { + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + if (immidateMode) { + SWITCH_SOURCE(7) + glTexCoordPointer(2, type, size_of * 10,data); + } else { + glTexCoordPointer(2, type, size_of * 10, (GLvoid*)(size_of * 7)); + } + } + if(usePoints) + { + glEnableClientState(GL_POINT_SIZE_ARRAY_OES); + if (immidateMode) { + SWITCH_SOURCE(9) + glPointSizePointerOES(type,size_of * 10,data); + } else { + glPointSizePointerOES(type,size_of * 10,(GLvoid*)(size_of * 9)); + } + } + + if (useIndices) { + if (immidateMode) { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glDrawElements(drawType, 3, GL_UNSIGNED_SHORT, indices); + } else { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ui32IndexVbo); + glDrawElements(drawType, 3, GL_UNSIGNED_SHORT, 0); + } + } else { + glDrawArrays(drawType, 0, 3); + } + + GLenum err = glGetError(); + if(err != GL_NO_ERROR) + printf(" error %d has occured while drawing\n",err); + + + glPopMatrix(); + eglSwapBuffers(d,egl_surface); + + if(useTexture && useCopy) + glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,0,0,256,256,0); + else if(useTexture && useSubCopy) + glCopyTexSubImage2D(GL_TEXTURE_2D,0,100,100,WINDOW_WIDTH/2,WINDOW_HEIGHT/2,50,50); + } + err = glGetError(); + if(err != GL_NO_ERROR) + printf("error ->>> %d \n",err); + eglDestroySurface(d,egl_surface); + eglDestroyContext(d,ctx); + +// Just wait until the window is closed + SDL_Event ev; + while( SDL_WaitEvent(&ev) ) { + if (ev.type == SDL_QUIT) { + break; + } + } + return 0; +} + + diff --git a/emulator/opengl/tests/translator_tests/GLES_V2/Android.mk b/emulator/opengl/tests/translator_tests/GLES_V2/Android.mk new file mode 100644 index 0000000..53f774c --- /dev/null +++ b/emulator/opengl/tests/translator_tests/GLES_V2/Android.mk @@ -0,0 +1,30 @@ +LOCAL_PATH:= $(call my-dir) + +$(call emugl-begin-host-executable,triangleV2) +$(call emugl-import,libEGL_translator libGLES_V2_translator) + +PREBUILT := $(HOST_PREBUILT_TAG) +LOCAL_SDL_CONFIG ?= prebuilts/tools/$(PREBUILT)/sdl/bin/sdl-config +LOCAL_SDL_CFLAGS := $(shell $(LOCAL_SDL_CONFIG) --cflags) +LOCAL_SDL_LDLIBS := $(filter-out %.a %.lib,$(shell $(LOCAL_SDL_CONFIG) --static-libs)) + +LOCAL_SRC_FILES:= \ + triangleV2.cpp + +LOCAL_CFLAGS += $(LOCAL_SDL_CFLAGS) -g -O0 +LOCAL_LDLIBS += $(LOCAL_SDL_LDLIBS) + +LOCAL_STATIC_LIBRARIES += libSDL libSDLmain + +ifeq ($(HOST_OS),darwin) +DARWIN_VERSION := $(strip $(shell sw_vers -productVersion)) +ifneq ($(filter 10.7 10.7.%,$(DARWIN_VERSION)),) + # Lion needs to be forced to link dylib to avoid problems + # with the dynamic function lookups in SDL 1.2 + LOCAL_LDLIBS += /usr/lib/dylib1.o +endif +$(call emugl-import,libMac_view) +endif + +$(call emugl-end-module) + diff --git a/emulator/opengl/tests/translator_tests/GLES_V2/triangleV2.cpp b/emulator/opengl/tests/translator_tests/GLES_V2/triangleV2.cpp new file mode 100644 index 0000000..59535c5 --- /dev/null +++ b/emulator/opengl/tests/translator_tests/GLES_V2/triangleV2.cpp @@ -0,0 +1,457 @@ +/* +* 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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> + +//#define GL_API +//#define GL_APIENTRY + +#undef ANDROID +#include <EGL/egl.h> +#include <GLES2/gl2.h> + +#ifdef __APPLE__ +extern "C" void * createGLView(void *nsWindowPtr, int x, int y, int width, int height); +#endif + +#undef HAVE_MALLOC_H +#include <SDL.h> +#include <SDL_syswm.h> + + +#define WINDOW_WIDTH 500 +#define WINDOW_HEIGHT 500 + +#define TEX_WIDTH 256 +#define TEX_HEIGHT 256 + + +#define F_to_X(d) ((d) > 32767.65535 ? 32767 * 65536 + 65535 : \ + (d) < -32768.65535 ? -32768 * 65536 + 65535 : \ + ((GLfixed) ((d) * 65536))) +#define X_to_F(x) ((float)(x))/65536.0f + +//#define __FIXED__ + +const char *def_vShaderStr = + "attribute vec4 vPosition; \n" + "void main() \n" + "{ \n" + " gl_Position = vPosition; \n" + "} \n"; + +const char *def_fShaderStr = + "precision mediump float; \n" + "void main() \n" + "{ \n" +#ifndef __FIXED__ + " gl_FragColor = vec4(0.2, 0.5, 0.1, 1.0); \n" +#else + " gl_FragColor = vec4(0.4, 0.3, 0.7, 1.0); \n" +#endif + "} \n"; + +static EGLint const attribute_list[] = { + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_NONE +}; + +unsigned char *genTexture(int width, int height, int comp) +{ + unsigned char *img = new unsigned char[width * height * comp]; + unsigned char *ptr = img; + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + unsigned char col = ((i / 8 + j / 8) % 2) * 255 ; + for (int c = 0; c < comp; c++) { + *ptr = col; ptr++; + } + } + } + return img; +} + +unsigned char *genRedTexture(int width, int height, int comp) +{ + unsigned char *img = new unsigned char[width * height * comp]; + memset(img,0,width*height*comp); + unsigned char *ptr = img; + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + unsigned char col = ((i / 8 + j / 8) % 2) * 255 ; + *ptr = col; + ptr+=comp; + } + } + return img; +} + + +void printUsage(const char *progname) +{ + fprintf(stderr, "usage: %s [options]\n", progname); + fprintf(stderr, "\t-vs <filename> - vertex shader to use\n"); + fprintf(stderr, "\t-fs <filename> - fragment shader to use\n"); +} + + + +GLuint LoadShader(GLenum type,const char *shaderSrc) +{ + GLuint shader; + GLint compiled; + // Create the shader object + shader = glCreateShader(type); + if(shader == 0) + return 0; + // Load the shader source + glShaderSource(shader, 1, &shaderSrc, NULL); + // Compile the shader + glCompileShader(shader); + // Check the compile status + glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); + if(!compiled) + { + GLint infoLen = 0; + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen); + if(infoLen > 1) + { + char* infoLog = (char*)malloc(sizeof(char) * infoLen); + glGetShaderInfoLog(shader, infoLen, NULL, infoLog); + printf("Error compiling shader:\n%s\n", infoLog); + free(infoLog); + } + glDeleteShader(shader); + return 0; + } + return shader; +} + +const char *readShader(const char *fileName) +{ + FILE *fp = fopen(fileName, "rb"); + if (!fp) return NULL; + + int bSize = 1024; + int nBufs = 1; + char *buf = (char *)malloc(bSize); + int n; + int len = 0; + n = fread(&buf[0], 1, bSize, fp); + while( n == bSize ) { + len += n; + nBufs++; + buf = (char *)realloc(buf, bSize * nBufs); + n = fread(&buf[len], 1, bSize, fp); + } + len += n; + + buf[len] = '\0'; + return (const char *)buf; +} + +void dumpUniforms(GLuint program) +{ + GLint numU; + glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &numU); + printf("==== Program %d has %d active uniforms ===\n", program, numU); + char name[512]; + GLsizei len; + GLint size; + GLenum type; + for (int i=0; i<numU; i++) { + glGetActiveUniform(program, i, + 512, &len, &size, &type, name); + printf("\t%s : type=0x%x size=%d\n", name, type, size); + } +} + +/// +// Initialize the shader and program object +// +int Init(const char *vShaderStr, const char *fShaderStr) +{ + GLuint vertexShader; + GLuint fragmentShader; + GLuint programObject; + GLint linked; + // Load the vertex/fragment shaders + vertexShader = LoadShader(GL_VERTEX_SHADER, vShaderStr); + fragmentShader = LoadShader(GL_FRAGMENT_SHADER, fShaderStr); + // Create the program object + programObject = glCreateProgram(); + if(programObject == 0) + return -1; + glAttachShader(programObject, vertexShader); + glAttachShader(programObject, fragmentShader); + // Bind vPosition to attribute 0 + glBindAttribLocation(programObject, 0, "vPosition"); + // Link the program + glLinkProgram(programObject); + // Check the link status + glGetProgramiv(programObject, GL_LINK_STATUS, &linked); + if(!linked) + { + GLint infoLen = 0; + glGetProgramiv(programObject, GL_INFO_LOG_LENGTH, &infoLen); + if(infoLen > 1) + { + char* infoLog = (char*)malloc(sizeof(char) * infoLen); + glGetProgramInfoLog(programObject, infoLen, NULL, infoLog); + printf("Error linking program:\n%s\n", infoLog); + free(infoLog); + } + glDeleteProgram(programObject); + return -1; + } + + // dump active uniforms + dumpUniforms(programObject); + + // Store the program object +#ifndef __FIXED__ + glClearColor(0.0f, 0.0f, 1.0f, 1.0f); +#else + glClearColor(1.0f, 0.0f, 0.0f, 1.0f); +#endif + return programObject; +} + + +/// +// Draw a triangle using the shader pair created in Init() +// +void Draw(EGLDisplay display,EGLSurface surface,int width,int height,GLuint program) +{ +#ifndef __FIXED__ + GLfloat vVertices[] = {0.0f, 0.5f, 0.0f, + -0.5f, -0.5f, 0.0f, + 0.5f, -0.5f, 0.0f}; +#else + + GLfixed vVertices[] = {F_to_X(0.0f), F_to_X(0.5f),F_to_X(0.0f), + F_to_X(-0.5f),F_to_X(-0.5f), F_to_X(0.0f), + F_to_X(0.5f),F_to_X(-0.5f),F_to_X(0.0f)}; +#endif + + // Set the viewport + glViewport(0, 0,width,height); + // Clear the color buffer + glClear(GL_COLOR_BUFFER_BIT); + // Use the program object + glUseProgram(program); + // Load the vertex data +#ifndef __FIXED__ + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices); +#else + glVertexAttribPointer(0, 3, GL_FIXED, GL_FALSE, 0, vVertices); +#endif + glEnableVertexAttribArray(0); + glDrawArrays(GL_TRIANGLES, 0, 3); + eglSwapBuffers(display,surface); +} + +#ifdef _WIN32 +char **parseCmdLine(char *cmdLine, int *argc) +{ + int argvSize = 10; + char **argv = (char **)malloc(argvSize * sizeof(char *)); + *argc = 0; + int i=0; + bool prevIsSpace = true; + int argStart = 0; + + argv[(*argc)++] = strdup("playdump"); + + while(cmdLine[i] != '\0') { + bool isSpace = (cmdLine[i] == ' ' || cmdLine[i] == '\t'); + if ( !isSpace && prevIsSpace ) { + argStart = i; + } + else if (isSpace && !prevIsSpace) { + cmdLine[i] = '\0'; + if (*argc >= argvSize) { + argvSize *= 2; + argv = (char **)realloc(argv, argvSize * sizeof(char *)); + } + argv[(*argc)++] = &cmdLine[argStart]; + argStart = i+1; + } + + prevIsSpace = isSpace; + i++; + } + + if (i > argStart) { + argv[(*argc)++] = &cmdLine[argStart]; + } + return argv; +} +#endif + +#ifdef _WIN32 +int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) +#else +int main(int argc, char **argv) +#endif +{ + GLuint ui32Vbo = 0; // Vertex buffer object handle + GLuint ui32IndexVbo; + GLuint ui32Texture; + + int nframes = 100; + bool immidateMode = false; + bool useIndices = false; + bool useTexture = true; + bool useCompTexture = false; + bool useFixed = true; + bool usePoints = false; + bool useCopy = false; + bool useSubCopy = false; + +#ifdef _WIN32 + int argc; + char **argv = parseCmdLine(lpCmdLine, &argc); +#endif + const char *vShader = def_vShaderStr; + const char *fShader = def_fShaderStr; + + for (int i=1; i<argc; i++) { + if (!strcmp(argv[i],"-vs")) { + if (++i >= argc) { + printUsage(argv[0]); + return -1; + } + vShader = readShader(argv[i]); + if (!vShader) { + vShader = def_vShaderStr; + printf("Failed to load vshader %s, using defualt\n", argv[i]); + } + else { + printf("Using vshader %s\n", argv[i]); + } + } + else if (!strcmp(argv[i],"-fs")) { + if (++i >= argc) { + printUsage(argv[0]); + return -1; + } + fShader = readShader(argv[i]); + if (!fShader) { + fShader = def_fShaderStr; + printf("Failed to load fshader %s, using defualt\n", argv[i]); + } + else { + printf("Using fshader %s\n", argv[i]); + } + } + else { + printUsage(argv[0]); + return -1; + } + } + + #ifdef _WIN32 + HWND windowId = NULL; + #elif __linux__ + Window windowId = NULL; + #elif __APPLE__ + void* windowId = NULL; + #endif + + // // Inialize SDL window + // + if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_VIDEO)) { + fprintf(stderr,"SDL init failed: %s\n", SDL_GetError()); + return -1; + } + + SDL_Surface *surface = SDL_SetVideoMode(WINDOW_WIDTH,WINDOW_HEIGHT, 32, SDL_HWSURFACE); + if (surface == NULL) { + fprintf(stderr,"Failed to set video mode: %s\n", SDL_GetError()); + return -1; + } + + SDL_SysWMinfo wminfo; + memset(&wminfo, 0, sizeof(wminfo)); + SDL_GetWMInfo(&wminfo); + #ifdef _WIN32 + windowId = wminfo.window; + #elif __linux__ + windowId = wminfo.info.x11.window; + #elif __APPLE__ + windowId = createGLView(wminfo.nsWindowPtr,0,0,WINDOW_WIDTH,WINDOW_HEIGHT); + #endif + + int major,minor,num_config; + int attrib_list[] ={ + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; + EGLConfig configs[150]; + EGLSurface egl_surface; + EGLContext ctx; + EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); + eglInitialize(d,&major,&minor); + printf("DISPLAY == %p major =%d minor = %d\n",d,major,minor); + eglChooseConfig(d, attribute_list, configs, 150, &num_config); + printf("config returned %d\n",num_config); + egl_surface = eglCreateWindowSurface(d,configs[0],windowId,NULL); + ctx = eglCreateContext(d,configs[0],EGL_NO_CONTEXT,attrib_list); + printf("SURFACE == %p CONTEXT == %p\n",egl_surface,ctx); + if(eglMakeCurrent(d,egl_surface,egl_surface,ctx)!= EGL_TRUE){ + printf("make current failed\n"); + return false; + } + printf("after make current\n"); + + GLenum err = glGetError(); + if(err != GL_NO_ERROR) { + printf("error before drawing ->>> %d \n",err); + } else { + printf("no error before drawing\n"); + } + + int program = Init(vShader, fShader); + if(program < 0){ + printf("failed init shaders\n"); + return false; + } + + Draw(d,egl_surface,WINDOW_WIDTH,WINDOW_HEIGHT,program); + + err = glGetError(); + if(err != GL_NO_ERROR) + printf("error ->>> %d \n",err); + eglDestroySurface(d,egl_surface); + eglDestroyContext(d,ctx); + +// Just wait until the window is closed + SDL_Event ev; + while( SDL_WaitEvent(&ev) ) { + if (ev.type == SDL_QUIT) { + break; + } + } + return 0; +} + + diff --git a/emulator/opengl/tests/translator_tests/MacCommon/Android.mk b/emulator/opengl/tests/translator_tests/MacCommon/Android.mk new file mode 100644 index 0000000..4c4ae6b --- /dev/null +++ b/emulator/opengl/tests/translator_tests/MacCommon/Android.mk @@ -0,0 +1,13 @@ +LOCAL_PATH := $(call my-dir) + +ifeq ($(HOST_OS),darwin) +$(call emugl-begin-host-static-library,libMac_view) + +LIBMACVIEW_FRAMEWORKS := AppKit AudioToolbox AudioUnit +LIBMACVIEW_PREFIX := -Wl,-framework, + +$(call emugl-export,LDLIBS,$(foreach _framework,$(LIBMACVIEW_FRAMEWORKS),$(LIBMACVIEW_PREFIX)$(_framework))) +LOCAL_SRC_FILES := setup_gl.m +LOCAL_CFLAGS += -g -O0 +$(call emugl-end-module) +endif # HOST_OS == darwin diff --git a/emulator/opengl/tests/translator_tests/MacCommon/setup_gl.m b/emulator/opengl/tests/translator_tests/MacCommon/setup_gl.m new file mode 100644 index 0000000..a300943 --- /dev/null +++ b/emulator/opengl/tests/translator_tests/MacCommon/setup_gl.m @@ -0,0 +1,35 @@ +/* +* 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 <stdio.h> +#include <Cocoa/Cocoa.h> + + void * createGLView(void *nsWindowPtr, int x, int y, int width, int height) +{ + NSRect contentRect = NSMakeRect(x, y, width, height); + NSView *glView = [[NSView alloc] initWithFrame:contentRect]; + if (glView == nil) { + printf("couldn't create opengl view\n"); + return nil; + } + [glView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; + NSWindow *win = (NSWindow *)nsWindowPtr; + [[win contentView] addSubview:glView]; + [win makeKeyAndOrderFront:nil]; + return (void *)glView; +} + + diff --git a/emulator/opengl/tests/ut_rendercontrol_dec/Android.mk b/emulator/opengl/tests/ut_rendercontrol_dec/Android.mk new file mode 100644 index 0000000..a5a01e8 --- /dev/null +++ b/emulator/opengl/tests/ut_rendercontrol_dec/Android.mk @@ -0,0 +1,7 @@ +LOCAL_PATH := $(call my-dir) + +$(call emugl-begin-host-shared-library,libut_rendercontrol_dec) +$(call emugl-import, libOpenglCodecCommon) +$(call emugl-gen-decoder,$(EMUGL_PATH)/tests/ut_rendercontrol_enc,ut_rendercontrol) +$(call emugl-export,C_INCLUDES,$(EMUGL_PATH)/tests/ut_rendercontrol_enc) +$(call emugl-end-module) diff --git a/emulator/opengl/tests/ut_rendercontrol_enc/Android.mk b/emulator/opengl/tests/ut_rendercontrol_enc/Android.mk new file mode 100644 index 0000000..ae234b2 --- /dev/null +++ b/emulator/opengl/tests/ut_rendercontrol_enc/Android.mk @@ -0,0 +1,8 @@ +LOCAL_PATH := $(call my-dir) + +$(call emugl-begin-shared-library,libut_rendercontrol_enc) +$(call emugl-import,libOpenglCodecCommon) +$(call emugl-gen-encoder,$(LOCAL_PATH),ut_rendercontrol) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) +$(call emugl-end-module) + diff --git a/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol.attrib b/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol.attrib new file mode 100644 index 0000000..c47a9f9 --- /dev/null +++ b/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol.attrib @@ -0,0 +1,4 @@ +GLOBAL + base_opcode 10000 + encoder_headers <stdint.h> + diff --git a/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol.in b/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol.in new file mode 100644 index 0000000..0d5942f --- /dev/null +++ b/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol.in @@ -0,0 +1,11 @@ +GL_ENTRY(int, createContext, uint32_t pid, uint32_t handle, uint32_t shareCtx, int version) +GL_ENTRY(int, createSurface, uint32_t pid, uint32_t handle) +GL_ENTRY(int, makeCurrentContext, uint32_t pid, uint32_t drawSurface, uint32_t readSurface, uint32_t ctxHandle) +GL_ENTRY(void, swapBuffers, uint32_t pid, uint32_t surface) +GL_ENTRY(int, destroyContext, uint32_t pid, uint32_t handle) +GL_ENTRY(int, destroySurface, uint32_t pid, uint32_t handle) + + + + + diff --git a/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol.types b/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol.types new file mode 100644 index 0000000..9d945ab --- /dev/null +++ b/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol.types @@ -0,0 +1,2 @@ +uint32_t 32 0x%08x false + diff --git a/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol_types.h b/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol_types.h new file mode 100644 index 0000000..9b7864d --- /dev/null +++ b/emulator/opengl/tests/ut_rendercontrol_enc/ut_rendercontrol_types.h @@ -0,0 +1,17 @@ +/* +* 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 <stdint.h> diff --git a/emulator/opengl/tests/ut_renderer/Android.mk b/emulator/opengl/tests/ut_renderer/Android.mk new file mode 100644 index 0000000..fe8e7ac --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/Android.mk @@ -0,0 +1,30 @@ +LOCAL_PATH:=$(call my-dir) + +ifeq ($(HOST_OS), linux) + +$(call emugl-begin-host-executable,ut_renderer) +$(call emugl-import,libut_rendercontrol_dec libGLESv1_dec libGLESv2_dec libEGL_host_wrapper) + +LOCAL_SRC_FILES := ut_renderer.cpp \ + RenderingThread.cpp \ + ReadBuffer.cpp \ + Renderer.cpp \ + RendererContext.cpp \ + RendererSurface.cpp \ + X11Windowing.cpp + +# define PVR_WAR to support imgtec PVR opengl-ES implementation +# +# specifically this MACRO enables code that work arounds a bug +# in the implementation where glTextureParameter(...,GL_TEXTURE_RECT,...) +# is called would cause a crash if the texture dimensions have not been +# defined yet. + +LOCAL_CFLAGS += -DPVR_WAR +#LOCAL_CFLAGS += -g -O0 + +LOCAL_LDLIBS += -lpthread -lX11 -lrt + +$(call emugl-end-module) + +endif # HOST_OS == linux diff --git a/emulator/opengl/tests/ut_renderer/NativeWindowing.h b/emulator/opengl/tests/ut_renderer/NativeWindowing.h new file mode 100644 index 0000000..9468066 --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/NativeWindowing.h @@ -0,0 +1,28 @@ +/* +* 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_WINDOWING_H +#define _NATIVE_WINDOWING_H + +#include <EGL/egl.h> + +class NativeWindowing { +public: + virtual NativeDisplayType getNativeDisplay() = 0; + virtual NativeWindowType createNativeWindow(NativeDisplayType dpy, int width, int height) = 0; + virtual int destroyNativeWindow(NativeDisplayType dpy, NativeWindowType win) = 0; +}; + +#endif diff --git a/emulator/opengl/tests/ut_renderer/ReadBuffer.cpp b/emulator/opengl/tests/ut_renderer/ReadBuffer.cpp new file mode 100644 index 0000000..e0073c0 --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/ReadBuffer.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 "ReadBuffer.h" +#include <string.h> +#include <assert.h> + +ReadBuffer::ReadBuffer(SocketStream *stream, size_t bufsize) +{ + m_size = bufsize; + m_stream = stream; + m_buf = new unsigned char[m_size]; + m_validData = 0; + m_readPtr = m_buf; +} + +ReadBuffer::~ReadBuffer() +{ + delete m_buf; +} + +int ReadBuffer::getData() +{ + if (m_validData > 0) { + memcpy(m_buf, m_readPtr, m_validData); + } + m_readPtr = m_buf; + // get fresh data into the buffer; + int stat = m_stream->recv(m_buf + m_validData, m_size - m_validData); + if (stat > 0) { + m_validData += (size_t) stat; + } + return stat; +} + +void ReadBuffer::consume(size_t amount) +{ + assert(amount <= m_validData); + m_validData -= amount; + m_readPtr += amount; +} diff --git a/emulator/opengl/tests/ut_renderer/ReadBuffer.h b/emulator/opengl/tests/ut_renderer/ReadBuffer.h new file mode 100644 index 0000000..b039b19 --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/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 "SocketStream.h" + +class ReadBuffer { +public: + ReadBuffer(SocketStream *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; + SocketStream *m_stream; +}; +#endif diff --git a/emulator/opengl/tests/ut_renderer/Renderer.cpp b/emulator/opengl/tests/ut_renderer/Renderer.cpp new file mode 100644 index 0000000..22afadb --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/Renderer.cpp @@ -0,0 +1,183 @@ +/* +* 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 <assert.h> +#include "RenderingThread.h" +#include "Renderer.h" + +// include operating-system dependent windowing system impelemntation +#ifdef _WIN32 +# error "WINDOWS IS NOT SUPPORTED AT THE MOMENT" +#elif defined __APPLE__ +# error "Apple OS-X IS NOT SUPPORTED" +#elif defined (__unix__) +# include "X11Windowing.h" +#endif + + + + + +Renderer * Renderer::m_instance = NULL; + +Renderer * Renderer::instance() +{ + if (m_instance == NULL) m_instance = new Renderer; + return m_instance; +} + +Renderer::Renderer() +{ + // Unix specific, use your platform specific windowing implementation +#ifdef __unix__ + m_nw = new X11Windowing; +#endif + + m_dpy = eglGetDisplay(m_nw->getNativeDisplay()); + EGLint major, minor; + eglInitialize(m_dpy, &major, &minor); + fprintf(stderr, "egl initialized : %d.%d\n", major, minor); +} + +int Renderer::createSurface(RenderingThread *thread, const ClientHandle & handle) +{ + android::Mutex::Autolock(this->m_mutex); + + assert(m_surfaces.find(handle) == m_surfaces.end()); + if (handle.handle == 0) { + fprintf(stderr, "trying to create surface for EGL_NO_SURFACE !!!\n"); + return -1; + } else { + RendererSurface *surface = RendererSurface::create(m_dpy, RendererSurface::CONFIG_DEPTH, m_nw); + if (surface == NULL) { + printf("failed to create surface !!\n"); + return -1; + } + m_surfaces.insert(SurfaceMap::value_type(handle, surface)); + } + return 0; +} + +int Renderer::destroySurface(RenderingThread *thread, const ClientHandle &handle) +{ + android::Mutex::Autolock(this->m_mutex); + + SurfaceMap::iterator i = m_surfaces.find(handle); + if (i == m_surfaces.end()) { + printf("removing surface that doesn't exists\n"); + return -1; + } + if (i->second->destroy(m_nw)) { + m_surfaces.erase(handle); + } + return 0; +} + +int Renderer::createContext(RenderingThread *thread, const ClientHandle &handle, ClientHandle shareCtx, int version) +{ + android::Mutex::Autolock(this->m_mutex); + + assert(m_ctxs.find(handle) == m_ctxs.end()); + RendererContext *shared = NULL; + if (shareCtx.handle != 0) { + ContextMap::iterator sctx = m_ctxs.find(shareCtx); + if (sctx != m_ctxs.end()) { + shared = sctx->second; + } + } + + RendererContext *ctx = + RendererContext::create(m_dpy, + RendererSurface::getEglConfig(m_dpy, RendererSurface::CONFIG_DEPTH), + shared, version); + if (ctx == NULL) { + fprintf(stderr, "failed to create context\n"); + return -1; + } + m_ctxs.insert(ContextMap::value_type(handle, ctx)); + return 0; +} + +int Renderer::destroyContext(RenderingThread *thread, const ClientHandle &handle) +{ + android::Mutex::Autolock(this->m_mutex); + + ContextMap::iterator i = m_ctxs.find(handle); + if (i == m_ctxs.end()) { + printf("removing context that doesn't exists\n"); + return -1; + } + if (i->second->destroy()) { + m_ctxs.erase(handle); + } + return 0; +} + +int Renderer::makeCurrent(RenderingThread *thread, + const ClientHandle &drawSurface, + const ClientHandle &readSurface, + const ClientHandle & ctx) +{ + android::Mutex::Autolock(this->m_mutex); + + RendererContext *currentContext = thread->currentContext(); + + ContextMap::iterator c = m_ctxs.find(ctx); + EGLContext eglContext; + if (ctx.handle != 0 && c != m_ctxs.end()) { + if (c->second != currentContext) { + // new context is set + if (currentContext != NULL) currentContext->unref(); + c->second->ref(); + eglContext = c->second->eglContext(); + thread->setCurrentContext(c->second); + thread->glDecoder().setContextData(&c->second->decoderContextData()); + thread->gl2Decoder().setContextData(&c->second->decoderContextData()); + } else { + // same context is already set + eglContext = c->second->eglContext(); + } + } else { + eglContext = EGL_NO_CONTEXT; + if (currentContext != NULL) currentContext->unref(); + thread->setCurrentContext(NULL); + thread->glDecoder().setContextData(NULL); + thread->gl2Decoder().setContextData(NULL); + } + + EGLSurface draw = EGL_NO_SURFACE; + EGLSurface read = EGL_NO_SURFACE; + SurfaceMap::iterator i; + i = m_surfaces.find(drawSurface); if (i != m_surfaces.end()) draw = i->second->eglSurface(); + i = m_surfaces.find(readSurface); if (i != m_surfaces.end()) read = i->second->eglSurface(); + + return eglMakeCurrent(m_dpy, draw, read, eglContext); +} + +int Renderer::swapBuffers(RenderingThread *thread, + const ClientHandle &surface) +{ + android::Mutex::Autolock(this->m_mutex); + + SurfaceMap::iterator s = m_surfaces.find(surface); + if (s == m_surfaces.end()) { + fprintf(stderr, "swapping buffers for non existing surface\n"); + return -1; + } + return eglSwapBuffers(m_dpy, s->second->eglSurface()); +} diff --git a/emulator/opengl/tests/ut_renderer/Renderer.h b/emulator/opengl/tests/ut_renderer/Renderer.h new file mode 100644 index 0000000..cdf10b6 --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/Renderer.h @@ -0,0 +1,62 @@ +/* +* 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 _RENDERER_H_ +#define _RENDERER_H_ +#include <map> +#include "RendererSurface.h" +#include "RendererContext.h" +#include "NativeWindowing.h" +#include <utils/threads.h> + +class RenderingThread; + +class Renderer { +public: + + class ClientHandle { + public: + unsigned int pid; + unsigned int handle; + ClientHandle(unsigned int _pid, unsigned int _handle) : pid(_pid), handle(_handle) {} + + bool operator< (const ClientHandle & p) const { + bool val = (pid == p.pid) ? handle < p.handle : pid < p.pid; + return val; + } + }; + + static Renderer *instance(); + int createSurface(RenderingThread *thread, const ClientHandle & handle); + int destroySurface(RenderingThread *thread, const ClientHandle &handle); + int createContext(RenderingThread *thread, const ClientHandle & ctx, const ClientHandle shareCtx, int version); + int destroyContext(RenderingThread *thread,const ClientHandle & ctx); + int makeCurrent(RenderingThread *thread, + const ClientHandle & drawSurface, const ClientHandle & readSurface, const ClientHandle & ctx); + int swapBuffers(RenderingThread *thread, const ClientHandle & surface); + +private: + typedef std::map<ClientHandle, RendererSurface *> SurfaceMap; + typedef std::map<ClientHandle, RendererContext *> ContextMap; + static Renderer *m_instance; + Renderer(); + SurfaceMap m_surfaces; + ContextMap m_ctxs; + NativeWindowing *m_nw; + EGLDisplay m_dpy; + + android::Mutex m_mutex; // single global mutex for the renderer class; +}; +#endif diff --git a/emulator/opengl/tests/ut_renderer/RendererContext.cpp b/emulator/opengl/tests/ut_renderer/RendererContext.cpp new file mode 100644 index 0000000..0f93acd --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/RendererContext.cpp @@ -0,0 +1,66 @@ +/* +* 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 "RendererContext.h" +#include <stdio.h> +#include <stdlib.h> + +RendererContext * RendererContext::create(EGLDisplay dpy, EGLConfig config, RendererContext *shareCtx, int version) +{ + EGLContext ctx; + EGLContext shared = shareCtx == NULL ? EGL_NO_CONTEXT : shareCtx->eglContext(); + + EGLint context_attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE }; + context_attributes[1] = version; + + ctx = eglCreateContext(dpy, config, shared, context_attributes); + if (eglGetError() != EGL_SUCCESS) return NULL; + + return new RendererContext(dpy, ctx, version); +} + +int RendererContext::destroy() +{ + if (count() <= 0) { + eglDestroyContext(m_dpy, m_ctx); + return 1; + } + return 0; +} + +#ifdef PVR_WAR +void RendererContext::setActiveTexture(GLenum texture) +{ + m_activeTexture = texture - GL_TEXTURE0; +} + +void RendererContext::setTex2DBind(GLuint texture) +{ + m_tex2DBind[m_activeTexture] = texture; +} + +GLuint RendererContext::getTex2DBind() +{ + return m_tex2DBind[m_activeTexture]; +} + +void RendererContext::addPendingCropRect(const int *rect) +{ + PendingCropRect *r = new PendingCropRect; + r->texture = m_tex2DBind[m_activeTexture]; + memcpy(r->rect, rect, 4*sizeof(int)); + m_pendingCropRects.insert(r); +} +#endif diff --git a/emulator/opengl/tests/ut_renderer/RendererContext.h b/emulator/opengl/tests/ut_renderer/RendererContext.h new file mode 100644 index 0000000..bb24a2e --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/RendererContext.h @@ -0,0 +1,127 @@ +/* +* 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 _RENDERER_CONTEXT_H_ +#define _RENDERER_CONTEXT_H_ + +#include "RendererObject.h" +#include "GLDecoderContextData.h" + +#include <EGL/egl.h> +#define GL_API +#define GL_APIENTRY +#include <GLES/gl.h> +#include <string.h> + +#ifdef PVR_WAR +#include <set> +struct PendingCropRect +{ + GLuint texture; + int rect[4]; +}; + +typedef std::set<PendingCropRect *> PendingCropRectSet; +#endif + +class RendererContext : public RendererObject { +public: + static RendererContext *create(EGLDisplay dpy, EGLConfig config, RendererContext *shareCtx, int version); + EGLContext eglContext() { return m_ctx; } + int destroy(); + GLDecoderContextData & decoderContextData() { return m_contextData; } +#ifdef PVR_WAR + void setActiveTexture(GLenum texture); + GLenum getActiveTexture() { return GL_TEXTURE0 + m_activeTexture; } + void setTex2DBind(GLuint texture); + void setTex2DEnable(bool enable) { + m_tex2DEnable[m_activeTexture] = enable; + } + bool isTex2DEnable(int texunit) { return m_tex2DEnable[texunit]; } + GLuint getTex2DBind(); + void addPendingCropRect(const int *rect); + PendingCropRectSet &getPendingCropRects() { return m_pendingCropRects; } + + void setClientActiveTexture(GLenum texture) { m_clientActiveTexture = texture - GL_TEXTURE0; } + GLenum getClientActiveTexture() { return m_clientActiveTexture + GL_TEXTURE0; } + void enableClientState(GLenum cap, bool enable) { + switch(cap) { + case GL_VERTEX_ARRAY: + m_clientStateEnable[0] = enable; + break; + case GL_NORMAL_ARRAY: + m_clientStateEnable[1] = enable; + break; + case GL_COLOR_ARRAY: + m_clientStateEnable[2] = enable; + break; + case GL_POINT_SIZE_ARRAY_OES: + m_clientStateEnable[3] = enable; + break; + case GL_TEXTURE_COORD_ARRAY: + m_clientStateEnable[4 + m_clientActiveTexture] = enable; + break; + } + } + + bool getClientState(GLenum cap, int texUnit) { + switch(cap) { + case GL_VERTEX_ARRAY: + return m_clientStateEnable[0]; + case GL_NORMAL_ARRAY: + return m_clientStateEnable[1]; + case GL_COLOR_ARRAY: + return m_clientStateEnable[2]; + case GL_POINT_SIZE_ARRAY_OES: + return m_clientStateEnable[3]; + break; + case GL_TEXTURE_COORD_ARRAY: + return m_clientStateEnable[4 + texUnit]; + break; + } + return false; + } +#endif + +private: + EGLDisplay m_dpy; + EGLContext m_ctx; + GLDecoderContextData m_contextData; + int m_version; + + RendererContext(EGLDisplay dpy, EGLContext ctx, int version) : + m_dpy(dpy), + m_ctx(ctx), + m_version(version) + { +#ifdef PVR_WAR + m_activeTexture = 0; + m_clientActiveTexture = 0; + memset(m_tex2DBind, 0, 8*sizeof(GLuint)); + memset(m_tex2DEnable, 0, 8*sizeof(bool)); + memset(m_clientStateEnable, 0, 16*sizeof(bool)); +#endif + } + +#ifdef PVR_WAR + int m_tex2DBind[8]; + bool m_tex2DEnable[8]; + int m_activeTexture; + int m_clientActiveTexture; + bool m_clientStateEnable[16]; + PendingCropRectSet m_pendingCropRects; +#endif +}; +#endif diff --git a/emulator/opengl/tests/ut_renderer/RendererObject.h b/emulator/opengl/tests/ut_renderer/RendererObject.h new file mode 100644 index 0000000..18c89be --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/RendererObject.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 _RENDERER_OBJECT_H_ +#define _RENDERER_OBJECT_H_ + +class RendererObject { +public: + RendererObject() { m_count = 0; } + + int count() { return m_count; } + void ref() { m_count++; } + void unref() { m_count--; } +private: + int m_count; +}; +#endif diff --git a/emulator/opengl/tests/ut_renderer/RendererSurface.cpp b/emulator/opengl/tests/ut_renderer/RendererSurface.cpp new file mode 100644 index 0000000..7d8d8c6 --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/RendererSurface.cpp @@ -0,0 +1,108 @@ +/* +* 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 "RendererSurface.h" +#include <stdio.h> +#include <stdlib.h> + +#include "NativeWindowing.h" + +#define MAX_ATTRIB 100 + + +EGLConfig RendererSurface::getEglConfig(EGLDisplay eglDisplay, SurfaceConfig config) +{ + EGLConfig eglConfig; + int nConfigs; + + EGLint attrib[MAX_ATTRIB]; + int pos =0; + + attrib[pos++] = EGL_SURFACE_TYPE; attrib[pos++] = EGL_WINDOW_BIT; + if (config & CONFIG_DEPTH) {attrib[pos++] = EGL_DEPTH_SIZE; attrib[pos++] = 1;} + attrib[pos++] = EGL_NONE; + + if (!eglChooseConfig(eglDisplay, attrib, &eglConfig, 1, &nConfigs)) { + return 0; + } + /***/ + int ibuf; + if (eglGetConfigAttrib(eglDisplay, eglConfig, EGL_BUFFER_SIZE, &ibuf)) { + fprintf(stderr, "EGL COLOR Buffer size: %d\n", ibuf); + } else { + fprintf(stderr, "eglGetConfigAttrib error: %d\n", eglGetError()); + } + if (eglGetConfigAttrib(eglDisplay, eglConfig, EGL_DEPTH_SIZE, &ibuf)) { + fprintf(stderr, "EGL DEPTH Buffer size: %d\n", ibuf); + } else { + fprintf(stderr, "eglGetConfigAttrib error: %d\n", eglGetError()); + } + /***/ + + + if (nConfigs != 1) { + return 0; + } + return eglConfig; +} + +RendererSurface * RendererSurface::create(EGLDisplay eglDisplay, SurfaceConfig config, NativeWindowing *nw) +{ + int width = 0, height = 0; + const char* env; + + env = getenv("ANDROID_WINDOW_WIDTH"); + if (env && *env) { + width = atoi(env); + } + env = getenv("ANDROID_WINDOW_HEIGHT"); + if (env && *env) { + height = atoi(env); + } + if (width <= 160) + width = DEFAULT_WIDTH; + if (height <= 160) + height = DEFAULT_HEIGHT; + + printf("%s: Using width=%d height=%d\n", __FUNCTION__, width, height); + + EGLConfig eglConfig = getEglConfig(eglDisplay, config); + if (eglConfig == 0) { + return NULL; + } + + NativeWindowType window = nw->createNativeWindow(nw->getNativeDisplay(), width, height); + if (window == 0) { + return NULL; + } + + EGLSurface eglSurface = eglCreateWindowSurface(eglDisplay, + eglConfig, + window, NULL); + + if (eglGetError() != EGL_SUCCESS) { + return NULL; + } + + return new RendererSurface(eglDisplay, window, eglSurface, eglConfig); +} + +int RendererSurface::destroy(NativeWindowing *nw) +{ + eglDestroySurface(m_eglDisplay, m_eglSurface); + nw->destroyNativeWindow(nw->getNativeDisplay(), m_window); + return 1; +} + diff --git a/emulator/opengl/tests/ut_renderer/RendererSurface.h b/emulator/opengl/tests/ut_renderer/RendererSurface.h new file mode 100644 index 0000000..4f6709c --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/RendererSurface.h @@ -0,0 +1,52 @@ +/* +* 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 _RENDERER_SURFACE_H_ +#define _RENDERER_SURFACE_H_ + +#include <EGL/egl.h> +#include "NativeWindowing.h" +#include "RendererObject.h" + +#define DEFAULT_HEIGHT 480 +#define DEFAULT_WIDTH 320 + +class RendererSurface : public RendererObject { +public: + typedef enum { CONFIG_DEPTH = 1 << 0 } SurfaceConfig; + + EGLSurface eglSurface() { return m_eglSurface; } + EGLConfig eglConfig() { return m_config; } + EGLDisplay eglDisplay() { return m_eglDisplay; } + + static RendererSurface * create(EGLDisplay eglDisplay, SurfaceConfig config, NativeWindowing *nw); + static EGLConfig getEglConfig(EGLDisplay eglDisplay, SurfaceConfig config); + + int destroy(NativeWindowing *nw); + +private: + RendererSurface(EGLDisplay display, NativeWindowType window, EGLSurface surface, EGLConfig config) : + m_eglDisplay(display), + m_config(config), + m_window(window), + m_eglSurface(surface) + {} + + EGLDisplay m_eglDisplay; + EGLConfig m_config; + NativeWindowType m_window; + EGLSurface m_eglSurface; +}; +#endif diff --git a/emulator/opengl/tests/ut_renderer/RenderingThread.cpp b/emulator/opengl/tests/ut_renderer/RenderingThread.cpp new file mode 100644 index 0000000..70eee20 --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/RenderingThread.cpp @@ -0,0 +1,387 @@ +/* +* 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 "RenderingThread.h" +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <pthread.h> +#include "ReadBuffer.h" +#include "Renderer.h" +#include "TimeUtils.h" + +#include <GLES/glext.h> + +__thread RenderingThread * RenderingThread::m_tls; + +#ifdef PVR_WAR +void RenderingThread::s_glTexParameteriv(GLenum target, GLenum param, const int *p) +{ + if (target == GL_TEXTURE_2D && param == GL_TEXTURE_CROP_RECT_OES) { + m_tls->m_currentContext->addPendingCropRect(p); + } else { + m_tls->m_glTexParameteriv(target, param, p); + } +} + +void RenderingThread::s_glDrawTexfOES(GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLfloat h) +{ + m_tls->applyPendingCropRects(); + m_tls->m_glDrawTexfOES(x, y, z, w, h); + m_tls->fixTextureEnable(); +} + +void RenderingThread::s_glDrawTexsOES(GLshort x, GLshort y, GLshort z, GLshort w, GLshort h) +{ + m_tls->applyPendingCropRects(); + m_tls->m_glDrawTexsOES(x, y, z, w, h); + m_tls->fixTextureEnable(); +} + +void RenderingThread::s_glDrawTexiOES(GLint x, GLint y, GLint z, GLint w, GLint h) +{ + m_tls->applyPendingCropRects(); + m_tls->m_glDrawTexiOES(x, y, z, w, h); + m_tls->fixTextureEnable(); +} + +void RenderingThread::s_glDrawTexxOES(GLfixed x, GLfixed y, GLfixed z, GLfixed w, GLfixed h) +{ + m_tls->applyPendingCropRects(); + m_tls->m_glDrawTexxOES(x, y, z, w, h); + m_tls->fixTextureEnable(); +} + +void RenderingThread::s_glDrawTexfvOES(const GLfloat *coords) +{ + m_tls->applyPendingCropRects(); + m_tls->m_glDrawTexfvOES(coords); + m_tls->fixTextureEnable(); +} + +void RenderingThread::s_glDrawTexsvOES(const GLshort *coords) +{ + m_tls->applyPendingCropRects(); + m_tls->m_glDrawTexsvOES(coords); + m_tls->fixTextureEnable(); +} + +void RenderingThread::s_glDrawTexivOES(const GLint *coords) +{ + m_tls->applyPendingCropRects(); + m_tls->m_glDrawTexivOES(coords); + m_tls->fixTextureEnable(); +} + +void RenderingThread::s_glDrawTexxvOES(const GLfixed *coords) +{ + m_tls->applyPendingCropRects(); + m_tls->m_glDrawTexxvOES(coords); + m_tls->fixTextureEnable(); +} + + +void RenderingThread::s_glActiveTexture(GLenum texture) +{ + if (texture - GL_TEXTURE0 >= m_tls->m_backendCaps.maxTextureUnits) return; + + m_tls->m_currentContext->setActiveTexture(texture); + m_tls->m_glActiveTexture(texture); +} + +void RenderingThread::s_glBindTexture(GLenum target, GLuint texture) +{ + if (target == GL_TEXTURE_2D) m_tls->m_currentContext->setTex2DBind(texture); + m_tls->m_glBindTexture(target, texture); +} + +void RenderingThread::s_glEnable(GLenum cap) +{ + if (cap == GL_TEXTURE_2D) m_tls->m_currentContext->setTex2DEnable(true); + m_tls->m_glEnable(cap); +} + +void RenderingThread::s_glDisable(GLenum cap) +{ + if (cap == GL_TEXTURE_2D) m_tls->m_currentContext->setTex2DEnable(false); + m_tls->m_glDisable(cap); +} + +void RenderingThread::s_glClientActiveTexture(GLenum texture) +{ + if (texture - GL_TEXTURE0 >= m_tls->m_backendCaps.maxTextureUnits) return; + m_tls->m_currentContext->setClientActiveTexture(texture); + m_tls->m_glClientActiveTexture(texture); +} + +void RenderingThread::s_glEnableClientState(GLenum cap) +{ + m_tls->m_currentContext->enableClientState(cap, true); + m_tls->m_glEnableClientState(cap); +} + +void RenderingThread::s_glDisableClientState(GLenum cap) +{ + m_tls->m_currentContext->enableClientState(cap, false); + m_tls->m_glDisableClientState(cap); +} + +void RenderingThread::applyPendingCropRects() +{ + PendingCropRectSet &rset = m_currentContext->getPendingCropRects(); + if (rset.size() > 0) { + GLuint currBindedTex = m_currentContext->getTex2DBind(); + for (PendingCropRectSet::iterator i = rset.begin(); + i != rset.end(); + i++) { + m_glBindTexture(GL_TEXTURE_2D, (*i)->texture); + m_glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, (int *)(*i)->rect); + delete (*i); + } + m_glBindTexture(GL_TEXTURE_2D, currBindedTex); + rset.clear(); + } +} + +void RenderingThread::fixTextureEnable() +{ + // restore texture units enable state + for (unsigned int i=0; i<m_backendCaps.maxTextureUnits; i++) { + m_glActiveTexture(GL_TEXTURE0 + i); + if (m_currentContext->isTex2DEnable(i)) { + m_glEnable(GL_TEXTURE_2D); + } + else { + m_glDisable(GL_TEXTURE_2D); + } + m_glClientActiveTexture(GL_TEXTURE0 + i); + if (m_currentContext->getClientState(GL_TEXTURE_COORD_ARRAY, i)) { + m_glEnableClientState(GL_TEXTURE_COORD_ARRAY); + } + else { + m_glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } + } + // restore current active texture + m_glActiveTexture(m_currentContext->getActiveTexture()); + m_glClientActiveTexture(m_currentContext->getClientActiveTexture()); + + // restore other client state enable bits + if (m_currentContext->getClientState(GL_VERTEX_ARRAY, 0)) { + m_glEnableClientState(GL_VERTEX_ARRAY); + } + else { + m_glDisableClientState(GL_VERTEX_ARRAY); + } + + if (m_currentContext->getClientState(GL_NORMAL_ARRAY, 0)) { + m_glEnableClientState(GL_NORMAL_ARRAY); + } + else { + m_glDisableClientState(GL_NORMAL_ARRAY); + } + + if (m_currentContext->getClientState(GL_COLOR_ARRAY, 0)) { + m_glEnableClientState(GL_COLOR_ARRAY); + } + else { + m_glDisableClientState(GL_COLOR_ARRAY); + } + + if (m_currentContext->getClientState(GL_POINT_SIZE_ARRAY_OES, 0)) { + m_glEnableClientState(GL_POINT_SIZE_ARRAY_OES); + } + else { + m_glDisableClientState(GL_POINT_SIZE_ARRAY_OES); + } +} +#endif + + +int RenderingThread::s_createContext(uint32_t pid, uint32_t handle, uint32_t shareCtx, int version) +{ + return Renderer::instance()->createContext(m_tls, Renderer::ClientHandle(pid, handle), + Renderer::ClientHandle(pid, shareCtx), + version); + +} + + +int RenderingThread::s_createSurface(uint32_t pid, uint32_t handle) +{ + return Renderer::instance()->createSurface(m_tls, Renderer::ClientHandle(pid, handle)); +} + +int RenderingThread::s_destroySurface(uint32_t pid, uint32_t handle) +{ + return Renderer::instance()->destroySurface(m_tls, Renderer::ClientHandle(pid, handle)); +} + +int RenderingThread::s_destroyContext(uint32_t pid, uint32_t handle) +{ + return Renderer::instance()->destroyContext(m_tls, Renderer::ClientHandle(pid, handle)); +} + + +int RenderingThread::s_makeCurrent(uint32_t pid, uint32_t drawSurface, uint32_t readSurface, uint32_t ctx) +{ + int ret = Renderer::instance()->makeCurrent(m_tls, + Renderer::ClientHandle(pid, drawSurface), + Renderer::ClientHandle(pid, readSurface), + Renderer::ClientHandle(pid, ctx)); + + if (ret && ctx) { + m_tls->initBackendCaps(); + } + + return ret; +} + +void RenderingThread::s_swapBuffers(uint32_t pid, uint32_t surface) +{ + Renderer::instance()->swapBuffers(m_tls, Renderer::ClientHandle(pid, surface)); +} + + +RenderingThread::RenderingThread(SocketStream *stream) : + m_stream(stream), + m_currentContext(NULL) +{ + m_backendCaps.initialized = false; +} + +int RenderingThread::start(void) +{ + if (pthread_create(&m_thread, NULL, s_thread, this) < 0) { + perror("pthread_create"); + return -1; + } + return 0; +} + + +void * RenderingThread::s_thread(void *data) +{ + RenderingThread *self = (RenderingThread *)data; + m_tls = self; + return self->thread(); +} + +void RenderingThread::initBackendCaps() +{ + if (m_backendCaps.initialized) return; + + m_glDec.glGetIntegerv(GL_MAX_TEXTURE_UNITS, (GLint *)&m_backendCaps.maxTextureUnits); + m_backendCaps.initialized = true; +} + +void *RenderingThread::thread() +{ + + // initialize our decoders; + m_glDec.initGL(); + +#ifdef PVR_WAR + m_glTexParameteriv = m_glDec.set_glTexParameteriv(s_glTexParameteriv); + m_glDrawTexfOES = m_glDec.set_glDrawTexfOES(s_glDrawTexfOES); + m_glDrawTexsOES = m_glDec.set_glDrawTexsOES(s_glDrawTexsOES); + m_glDrawTexiOES = m_glDec.set_glDrawTexiOES(s_glDrawTexiOES); + m_glDrawTexxOES = m_glDec.set_glDrawTexxOES(s_glDrawTexxOES); + m_glDrawTexfvOES = m_glDec.set_glDrawTexfvOES(s_glDrawTexfvOES); + m_glDrawTexsvOES = m_glDec.set_glDrawTexsvOES(s_glDrawTexsvOES); + m_glDrawTexivOES = m_glDec.set_glDrawTexivOES(s_glDrawTexivOES); + m_glDrawTexxvOES = m_glDec.set_glDrawTexxvOES(s_glDrawTexxvOES); + m_glActiveTexture = m_glDec.set_glActiveTexture(s_glActiveTexture); + m_glBindTexture = m_glDec.set_glBindTexture(s_glBindTexture); + m_glEnable = m_glDec.set_glEnable(s_glEnable); + m_glDisable = m_glDec.set_glDisable(s_glDisable); + m_glClientActiveTexture = m_glDec.set_glClientActiveTexture(s_glClientActiveTexture); + m_glEnableClientState = m_glDec.set_glEnableClientState(s_glEnableClientState); + m_glDisableClientState = m_glDec.set_glDisableClientState(s_glDisableClientState); +#endif + + m_gl2Dec.initGL(); + + m_utDec.set_swapBuffers(s_swapBuffers); + m_utDec.set_createContext(s_createContext); + m_utDec.set_destroyContext(s_destroyContext); + m_utDec.set_createSurface(s_createSurface); + m_utDec.set_destroySurface(s_destroySurface); + m_utDec.set_makeCurrentContext(s_makeCurrent); + + ReadBuffer readBuf(m_stream, DECODER_BUF_SIZE); + + int stats_totalBytes = 0; + long long stats_t0 = GetCurrentTimeMS(); + + while (1) { + + int stat = readBuf.getData(); + if (stat == 0) { + fprintf(stderr, "client shutdown\n"); + break; + } else if (stat < 0) { + perror("getData"); + 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(); + } + + bool progress = true; + while (progress) { + progress = false; + // we need at least one header (8 bytes) in our buffer + if (readBuf.validData() >= 8) { + size_t last = m_glDec.decode(readBuf.buf(), readBuf.validData(), m_stream); + if (last > 0) { + progress = true; + readBuf.consume(last); + } + } + + if (readBuf.validData() >= 8) { + size_t last = m_gl2Dec.decode(readBuf.buf(), readBuf.validData(), m_stream); + if (last > 0) { + readBuf.consume(last); + progress = true; + } + } + + if (readBuf.validData() >= 8) { + size_t last = m_utDec.decode(readBuf.buf(), readBuf.validData(), m_stream); + if (last > 0) { + readBuf.consume(last); + progress = true; + } + } + } + } + // shutdown + if (m_currentContext != NULL) { + m_currentContext->unref(); + } + + return NULL; +} diff --git a/emulator/opengl/tests/ut_renderer/RenderingThread.h b/emulator/opengl/tests/ut_renderer/RenderingThread.h new file mode 100644 index 0000000..0b4ebe6 --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/RenderingThread.h @@ -0,0 +1,117 @@ +/* +* 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 _RENDERING_THREAD_H_ +#define _RENDERING_THREAD_H_ + +#include "SocketStream.h" +#include "GLDecoder.h" +#include "GL2Decoder.h" +#include "ut_rendercontrol_dec.h" +#include <pthread.h> + +#define GL_API +#define GL_APIENTRY + +#include <GLES/egl.h> +#include <GLES/gl.h> + + +#define WINDOW_WIDTH 320 +#define WINDOW_HEIGHT 480 + +#define DECODER_BUF_SIZE (4 * 1024 * 1024) + +class RendererContext; + +class RenderingThread { +public: + RenderingThread(SocketStream *stream); + int start(); + void *thread(); + RendererContext *currentContext() { return m_currentContext; } + void setCurrentContext(RendererContext *ctx) { m_currentContext = ctx; } + GLDecoder & glDecoder() { return m_glDec; } + GL2Decoder & gl2Decoder() { return m_gl2Dec; } + +private: + void initBackendCaps(); + +private: + GLDecoder m_glDec; + ut_rendercontrol_decoder_context_t m_utDec; + GL2Decoder m_gl2Dec; + + SocketStream *m_stream; + pthread_t m_thread; + RendererContext * m_currentContext; + + struct BackendCaps { + bool initialized; + GLuint maxTextureUnits; + } m_backendCaps; + + static void * s_thread(void *data); + static __thread RenderingThread *m_tls; + + static int s_createContext(uint32_t pid, uint32_t handle, uint32_t shareCtx, int version); + static int s_createSurface(uint32_t pid, uint32_t handle); + static int s_destroySurface(uint32_t pid, uint32_t handle); + static int s_destroyContext(uint32_t pid, uint32_t handle); + static int s_makeCurrent(uint32_t pid, uint32_t drawSurface, uint32_t readSurface, uint32_t ctx); + static void s_swapBuffers(uint32_t pid, uint32_t surface); +#ifdef PVR_WAR + static void s_glTexParameteriv(GLenum target, GLenum param, const int *p); + static void s_glDrawTexfOES(GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLfloat h); + static void s_glDrawTexsOES(GLshort x, GLshort y, GLshort z, GLshort w, GLshort h); + static void s_glDrawTexiOES(GLint x, GLint y, GLint z, GLint w, GLint h); + static void s_glDrawTexxOES(GLfixed x, GLfixed y, GLfixed z, GLfixed w, GLfixed h); + static void s_glDrawTexfvOES(const GLfloat *coords); + static void s_glDrawTexsvOES(const GLshort *coords); + static void s_glDrawTexivOES(const GLint *coords); + static void s_glDrawTexxvOES(const GLfixed *coords); + + static void s_glActiveTexture(GLenum texture); + static void s_glBindTexture(GLenum target, GLuint texture); + static void s_glEnable(GLenum cap); + static void s_glDisable(GLenum cap); + static void s_glClientActiveTexture(GLenum texture); + static void s_glEnableClientState(GLenum cap); + static void s_glDisableClientState(GLenum cap); + + void applyPendingCropRects(); + void fixTextureEnable(); + + glTexParameteriv_server_proc_t m_glTexParameteriv; + glDrawTexfOES_server_proc_t m_glDrawTexfOES; + glDrawTexiOES_server_proc_t m_glDrawTexiOES; + glDrawTexsOES_server_proc_t m_glDrawTexsOES; + glDrawTexxOES_server_proc_t m_glDrawTexxOES; + glDrawTexfvOES_server_proc_t m_glDrawTexfvOES; + glDrawTexivOES_server_proc_t m_glDrawTexivOES; + glDrawTexsvOES_server_proc_t m_glDrawTexsvOES; + glDrawTexxvOES_server_proc_t m_glDrawTexxvOES; + glActiveTexture_server_proc_t m_glActiveTexture; + glBindTexture_server_proc_t m_glBindTexture; + glEnable_server_proc_t m_glEnable; + glDisable_server_proc_t m_glDisable; + glClientActiveTexture_server_proc_t m_glClientActiveTexture; + glEnableClientState_server_proc_t m_glEnableClientState; + glDisableClientState_server_proc_t m_glDisableClientState; +#endif + +}; + +#endif diff --git a/emulator/opengl/tests/ut_renderer/X11RendererSurface.cpp b/emulator/opengl/tests/ut_renderer/X11RendererSurface.cpp new file mode 100644 index 0000000..121ee87 --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/X11RendererSurface.cpp @@ -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. +*/ +#include "X11RendererSurface.h" + +NativeDisplayType X11RendererSurface::getNativeDisplay() +{ + if (m_display == NULL) { + m_display = XOpenDisplay(NULL); + } + return NativeDisplayType(m_display); +} + +int X11RendererSurface::destoryNativeWindow(NativeWindowType win) +{ + if (m_display == NULL) return -1; + + Window x11Window = (Window)(win); + return XDestroyWindow(m_display, x11Window); +} + +NativeWindowType GlesX11Win::createNativeWindow() +{ + + getNativeDisplay(); + if (m_display == NULL) { + return -1; + } + + long defaultScreen = DefaultScreen( dpy ); + Window rootWindow = RootWindow(dpy, defaultScreen); + int depth = DefaultDepth(dpy, defaultScreen); + XVisualInfo *visualInfo = new XVisualInfo; + + XMatchVisualInfo(m_display, defaultScreen, , dpeth, TrueColor, visualInfo); + if (visualInfo == NULL) { + fprintf(stderr, "couldn't find matching visual\n"); + return -1; + } + + Colormap x11Colormap = XCreateColormap(m_display, rootWindow, visualInfo->visual, AllocNone); + XSetWindowAttributes sWA; + sWA.Colormap = x11Colormap; + sWA.event_mask = StructureNotifyMask | ExposureMask; + unsigned int eventMask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap; + + Window win = XCreateWindow( m_display, + rootWindow, + 0, 0, width, height, + 0, CopyFromParent, InputOutput, + CopyFromParent, eventMask, &sWA); + + XMapWindow(m_display, win); + XFlush(m_display); + return NativeWindowType(win); +} + diff --git a/emulator/opengl/tests/ut_renderer/X11RendererSurface.h b/emulator/opengl/tests/ut_renderer/X11RendererSurface.h new file mode 100644 index 0000000..be9bcec --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/X11RendererSurface.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 _X11_RENDERER_SURFACE_H_ +#define _X11_RENDERER_SURFACE_H_ + +#include <X11/Xutil.h> +#include <X11/Xlib.h> +#include <EGL/egl.h> + +include "RendererSurface.h" + +class X11RendererSurface : public RendererSurface +{ +public: + X11RendererSurface() : RendererSurface() { + m_display = NULL; + } + NativeDisplayType getNativeDisplay(); + NativeWindowType createNativeWindow(); + int destroyNativeWindow(NativeWindowType win); +private: + Display m_display; +}; +#endif diff --git a/emulator/opengl/tests/ut_renderer/X11Windowing.cpp b/emulator/opengl/tests/ut_renderer/X11Windowing.cpp new file mode 100644 index 0000000..cc94fdd --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/X11Windowing.cpp @@ -0,0 +1,131 @@ +/* +* 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 "X11Windowing.h" + +#include <stdio.h> +#include <stdlib.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> + +#define DEBUG 0 +#if DEBUG +# define D(...) printf(__VA_ARGS__), printf("\n") +#else +# define D(...) ((void)0) +#endif + +/* Try to remember the window position between creates/destroys */ +static int X11_wmXPos = 100; +static int X11_wmYPos = 100; + +static int X11_wmXAdjust = 0; +static int X11_wmYAdjust = 0; + +static void +get_window_pos( Display *disp, Window win, int *px, int *py ) +{ + Window child; + + XTranslateCoordinates( disp, win, DefaultRootWindow(disp), 0, 0, px, py, &child ); +} + + +static void +set_window_pos(Display *disp, Window win, int x, int y) +{ + int xNew, yNew; + int xAdjust = X11_wmXAdjust; + int yAdjust = X11_wmYAdjust; + + /* this code is tricky because some window managers, but not all, + * will translate the final window position by a given offset + * corresponding to the frame decoration. + * + * so we first try to move the window, get the position that the + * window manager has set, and if they are different, re-position the + * window again with an adjustment. + * + * this causes a slight flicker since the window 'jumps' very + * quickly from one position to the other. + */ + + D("%s: move to [%d,%d] adjusted to [%d,%d]", __FUNCTION__, + x, y, x+xAdjust, y+yAdjust); + XMoveWindow(disp, win, x + xAdjust, y + yAdjust); + XSync(disp, True); + get_window_pos(disp, win, &xNew, &yNew); + if (xNew != x || yNew != y) { + X11_wmXAdjust = xAdjust = x - xNew; + X11_wmYAdjust = yAdjust = y - yNew; + D("%s: read pos [%d,%d], recomputing adjust=[%d,%d] moving to [%d,%d]\n", + __FUNCTION__, xNew, yNew, xAdjust, yAdjust, x+xAdjust, y+yAdjust); + XMoveWindow(disp, win, x + xAdjust, y + yAdjust ); + } + XSync(disp, False); +} + + +NativeDisplayType X11Windowing::getNativeDisplay() +{ + Display *dpy = XOpenDisplay(NULL); + return (NativeDisplayType)dpy; +} + +NativeWindowType X11Windowing::createNativeWindow(NativeDisplayType _dpy, int width, int height) +{ + Display *dpy = (Display *) _dpy; + + long defaultScreen = DefaultScreen( dpy ); + Window rootWindow = RootWindow(dpy, defaultScreen); + int depth = DefaultDepth(dpy, defaultScreen); + XVisualInfo *visualInfo = new XVisualInfo; + + XMatchVisualInfo(dpy, defaultScreen, depth, TrueColor, visualInfo); + if (visualInfo == NULL) { + fprintf(stderr, "couldn't find matching visual\n"); + return NULL; + } + + Colormap x11Colormap = XCreateColormap(dpy, rootWindow, visualInfo->visual, AllocNone); + XSetWindowAttributes sWA; + sWA.colormap = x11Colormap; + sWA.event_mask = StructureNotifyMask | ExposureMask; + sWA.background_pixel = 0; + sWA.border_pixel = 0; + unsigned int attributes_mask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap; + + Window win = XCreateWindow( dpy, + rootWindow, + X11_wmXPos, X11_wmYPos, width, height, + 0, CopyFromParent, InputOutput, + CopyFromParent, attributes_mask, &sWA); + + XMapWindow(dpy, win); + XFlush(dpy); + set_window_pos(dpy, win, X11_wmXPos, X11_wmYPos); + return NativeWindowType(win); +} + +int X11Windowing::destroyNativeWindow(NativeDisplayType _dpy, NativeWindowType _win) +{ + Display *dpy = (Display *)_dpy; + Window win = (Window)_win; + get_window_pos(dpy, win, &X11_wmXPos, &X11_wmYPos); + D("%s: Saved window position [%d, %d]\n", __FUNCTION__, X11_wmXPos, X11_wmYPos); + XDestroyWindow(dpy, win); + XFlush(dpy); + return 0; +} diff --git a/emulator/opengl/tests/ut_renderer/X11Windowing.h b/emulator/opengl/tests/ut_renderer/X11Windowing.h new file mode 100644 index 0000000..0f0c76b --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/X11Windowing.h @@ -0,0 +1,27 @@ +/* +* 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 _X11WINDOWING_H_ +#define _X11WINDOWING_H_ + +#include "NativeWindowing.h" + +class X11Windowing : public NativeWindowing { + NativeDisplayType getNativeDisplay(); + NativeWindowType createNativeWindow(NativeDisplayType _dpy, int width, int height); + int destroyNativeWindow(NativeDisplayType dpy, NativeWindowType win); +}; + +#endif diff --git a/emulator/opengl/tests/ut_renderer/ut_renderer.cpp b/emulator/opengl/tests/ut_renderer/ut_renderer.cpp new file mode 100644 index 0000000..f2b2bc3 --- /dev/null +++ b/emulator/opengl/tests/ut_renderer/ut_renderer.cpp @@ -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. +*/ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include "codec_defs.h" +#include "RenderingThread.h" +#include "TcpStream.h" +#ifndef _WIN32 +#include "UnixStream.h" +#endif + + +int main(int argc, char **argv) +{ +#ifdef _WIN32 + TcpStream *socket = new TcpStream(); + + if (socket->listen(CODEC_SERVER_PORT) < 0) { + perror("listen"); + exit(1); + } +#else + UnixStream *socket = new UnixStream(); + + if (socket->listen(CODEC_SERVER_PORT) < 0) { + perror("listen"); + exit(1); + } +#endif + + printf("waiting for client connection on port: %d\n", CODEC_SERVER_PORT); + while (1) { + // wait for client connection + SocketStream *glStream = socket->accept(); + if (glStream == NULL) { + printf("failed to get client.. aborting\n"); + exit(3); + } + printf("Got client connection, creating a rendering thread;\n"); + // create a thread to handle this connection + RenderingThread *rt = new RenderingThread(glStream); + rt->start(); + } + + return 0; +} + + |