├── .github └── FUNDING.yml ├── .gitignore ├── .travis.yml ├── Android.mk ├── CHANGELOG.md ├── CMakeLists.txt ├── COMPILE.md ├── LICENSE ├── MEDIA.md ├── README.md ├── USAGE.md ├── _config.yml ├── bc_cat.h ├── gl4es.png ├── include ├── EGL │ ├── egl.h │ ├── eglext.h │ └── eglplatform.h ├── GL │ ├── gl.h │ ├── gl_mangle.h │ ├── glext.h │ ├── glu.h │ ├── glu_mangle.h │ ├── glx.h │ ├── glx_mangle.h │ ├── glxext.h │ └── internal │ │ └── dri_interface.h ├── GLES │ ├── egl.h │ ├── gl.h │ ├── gl2.h │ ├── gl2ext.h │ ├── gl2platform.h │ ├── gl3.h │ ├── gl3ext.h │ ├── gl3platform.h │ ├── glext.h │ └── glplatform.h ├── KHR │ └── khrplatform.h ├── android_debug.h ├── gl4eshint.h ├── gl4esinit.h └── khash.h ├── media ├── assaultcube.jpg └── minecraft.png ├── refs ├── descent3.0000284192.png ├── foobillardplus.0000014748.png ├── glsl_lighting.0000505393.png ├── glxgears.0000008203.png ├── neverball.0000078749.png ├── neverball.0000078750.png ├── openra.0000031249.png ├── pointsprite.0000248810.png └── stuntcarracer.0000118817.png ├── spec ├── build ├── gen.py ├── requirements.txt ├── template │ ├── base │ │ ├── base.j2 │ │ ├── copy_packed_call.j2 │ │ ├── fprint.j2 │ │ ├── header.j2 │ │ ├── headers.j2 │ │ ├── indexed_call.j2 │ │ ├── packed_call.j2 │ │ ├── wrap.c.j2 │ │ └── wrap.h.j2 │ ├── client.c.j2 │ ├── eglwrap.c.j2 │ ├── gleswrap.c.j2 │ ├── glextwrap.c.j2 │ ├── glwrap.h.j2 │ ├── glxfuncs.j2 │ ├── host.c.j2 │ └── proxy.h.j2 ├── xml │ ├── egl.xml │ ├── gles-2.0.xml │ ├── glx.xml │ ├── glxext.xml │ ├── opengl.xml │ ├── toyml.py │ └── wgl.xml └── yml │ ├── alsa.yml │ ├── egl.yml │ ├── gles-1.1.yml │ ├── gles-2.0.yml │ ├── glext-1.1.yml │ ├── glext-es2-1.1.yml │ ├── glx.yml │ ├── glxext.yml │ ├── my_glx.yml │ ├── opengl.yml │ └── wgl.yml ├── src ├── CMakeLists.txt ├── agl │ ├── agl.c │ ├── agl.h │ ├── amigaos.c │ ├── amigaos.h │ └── lookup.c ├── config.h ├── egl │ ├── egl.c │ ├── egl.h │ └── lookup.c ├── gl │ ├── arbconverter.c │ ├── arbconverter.h │ ├── arbgenerator.c │ ├── arbgenerator.h │ ├── arbhelper.c │ ├── arbhelper.h │ ├── arbparser.c │ ├── arbparser.h │ ├── array.c │ ├── array.h │ ├── attributes.h │ ├── blend.c │ ├── blend.h │ ├── blit.c │ ├── blit.h │ ├── buffers.c │ ├── buffers.h │ ├── build_info.c │ ├── build_info.h │ ├── const.h │ ├── debug.c │ ├── debug.h │ ├── decompress.c │ ├── decompress.h │ ├── depth.c │ ├── depth.h │ ├── directstate.c │ ├── directstate.h │ ├── drawing.c │ ├── enable.c │ ├── enum_info.h │ ├── envvars.c │ ├── envvars.h │ ├── eval.c │ ├── eval.h │ ├── face.c │ ├── face.h │ ├── fog.c │ ├── fog.h │ ├── fpe.c │ ├── fpe.h │ ├── fpe_cache.c │ ├── fpe_cache.h │ ├── fpe_shader.c │ ├── fpe_shader.h │ ├── framebuffers.c │ ├── framebuffers.h │ ├── getter.c │ ├── gl4es.c │ ├── gl4es.h │ ├── gl_lookup.c │ ├── gl_lookup.h │ ├── glcase.h │ ├── gles.h │ ├── glesfuncs.inc │ ├── glstate.c │ ├── glstate.h │ ├── hint.c │ ├── hint.h │ ├── init.c │ ├── init.h │ ├── light.c │ ├── light.h │ ├── line.c │ ├── line.h │ ├── list.c │ ├── list.h │ ├── listdraw.c │ ├── listrl.c │ ├── loader.c │ ├── loader.h │ ├── logs.c │ ├── logs.h │ ├── math │ │ ├── eval.h │ │ └── matheval.c │ ├── matrix.c │ ├── matrix.h │ ├── matvec.c │ ├── matvec.h │ ├── oldprogram.c │ ├── oldprogram.h │ ├── pixel.c │ ├── pixel.h │ ├── planes.c │ ├── planes.h │ ├── pointsprite.c │ ├── pointsprite.h │ ├── preproc.c │ ├── preproc.h │ ├── program.c │ ├── program.h │ ├── queries.c │ ├── queries.h │ ├── raster.c │ ├── raster.h │ ├── render.c │ ├── render.h │ ├── samplers.c │ ├── samplers.h │ ├── shader.c │ ├── shader.h │ ├── shader_hacks.c │ ├── shader_hacks.h │ ├── shaderconv.c │ ├── shaderconv.h │ ├── stack.c │ ├── stack.h │ ├── state.h │ ├── stb_dxt_104.h │ ├── stencil.c │ ├── stencil.h │ ├── string_utils.c │ ├── string_utils.h │ ├── stubs.c │ ├── texenv.c │ ├── texenv.h │ ├── texgen.c │ ├── texgen.h │ ├── texture.c │ ├── texture.h │ ├── texture_3d.c │ ├── texture_compressed.c │ ├── texture_params.c │ ├── texture_read.c │ ├── uniform.c │ ├── uniform.h │ ├── vertexattrib.c │ ├── vertexattrib.h │ └── wrap │ │ ├── gl4es.h │ │ ├── gl4eswraps.c │ │ ├── gles.c │ │ ├── gles.h │ │ ├── glstub.c │ │ ├── skips.h │ │ └── stub.h └── glx │ ├── drmfunc.h │ ├── gbm.c │ ├── gbmfunc.h │ ├── glx.c │ ├── glx.h │ ├── glx_gbm.h │ ├── hardext.c │ ├── hardext.h │ ├── lookup.c │ ├── rpi.c │ ├── rpi.h │ ├── streaming.c │ ├── streaming.h │ ├── utils.c │ └── utils.h ├── test.cmake ├── tests ├── test.sh └── tests.sh ├── traces ├── descent3.tgz ├── foobillardplus.tgz ├── glsl_lighting.tgz ├── glxgears.tgz ├── neverball.tgz ├── openra.tgz ├── pointsprite.tgz └── stuntcarracer.tgz └── version.h /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: ptitSeb 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: paypal.me/0ptitSeb 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gdb_history 2 | .vscode/ 3 | CMakeFiles/ 4 | lib/ 5 | Makefile 6 | CMakeCache.txt 7 | CTestTestfile.cmake 8 | cmake_install.cmake 9 | spec/yml/gles-1.1-full.yml 10 | /build/ 11 | /tests/*.png 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | sudo: false 3 | dist: buster 4 | 5 | compiler: 6 | - gcc 7 | 8 | #Build steps 9 | before_script: 10 | - mkdir build 11 | - cd build 12 | - cmake .. -DODROID=1 13 | 14 | script: 15 | - make 16 | 17 | #after_script: 18 | # - sudo apt-get install apitrace-gl-frontend=5\* imagemagick xvfb -y 19 | # - cd ../tests 20 | # - xvfb-run ./tests.sh ../lib 21 | -------------------------------------------------------------------------------- /Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | ########################### 4 | # 5 | # GL static library 6 | # 7 | ########################### 8 | 9 | include $(CLEAR_VARS) 10 | 11 | LOCAL_MODULE := GL 12 | 13 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include 14 | 15 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES) -DBCMHOST 16 | 17 | LOCAL_SRC_FILES := \ 18 | src/gl/arbconverter.c \ 19 | src/gl/arbgenerator.c \ 20 | src/gl/arbhelper.c \ 21 | src/gl/arbparser.c \ 22 | src/gl/array.c \ 23 | src/gl/blend.c \ 24 | src/gl/blit.c \ 25 | src/gl/buffers.c \ 26 | src/gl/build_info.c \ 27 | src/gl/debug.c \ 28 | src/gl/decompress.c \ 29 | src/gl/depth.c \ 30 | src/gl/directstate.c \ 31 | src/gl/drawing.c \ 32 | src/gl/enable.c \ 33 | src/gl/envvars.c \ 34 | src/gl/eval.c \ 35 | src/gl/face.c \ 36 | src/gl/fog.c \ 37 | src/gl/fpe.c \ 38 | src/gl/fpe_cache.c \ 39 | src/gl/fpe_shader.c \ 40 | src/gl/framebuffers.c \ 41 | src/gl/gl_lookup.c \ 42 | src/gl/getter.c \ 43 | src/gl/gl4es.c \ 44 | src/gl/glstate.c \ 45 | src/gl/hint.c \ 46 | src/gl/init.c \ 47 | src/gl/light.c \ 48 | src/gl/line.c \ 49 | src/gl/list.c \ 50 | src/gl/listdraw.c \ 51 | src/gl/listrl.c \ 52 | src/gl/loader.c \ 53 | src/gl/logs.c \ 54 | src/gl/matrix.c \ 55 | src/gl/matvec.c \ 56 | src/gl/oldprogram.c \ 57 | src/gl/pixel.c \ 58 | src/gl/planes.c \ 59 | src/gl/pointsprite.c \ 60 | src/gl/preproc.c \ 61 | src/gl/program.c \ 62 | src/gl/queries.c \ 63 | src/gl/raster.c \ 64 | src/gl/render.c \ 65 | src/gl/samplers.c \ 66 | src/gl/shader.c \ 67 | src/gl/shaderconv.c \ 68 | src/gl/shader_hacks.c \ 69 | src/gl/stack.c \ 70 | src/gl/stencil.c \ 71 | src/gl/string_utils.c \ 72 | src/gl/stubs.c \ 73 | src/gl/texenv.c \ 74 | src/gl/texgen.c \ 75 | src/gl/texture.c \ 76 | src/gl/texture_compressed.c \ 77 | src/gl/texture_params.c \ 78 | src/gl/texture_read.c \ 79 | src/gl/texture_3d.c \ 80 | src/gl/uniform.c \ 81 | src/gl/vertexattrib.c \ 82 | src/gl/wrap/gl4eswraps.c \ 83 | src/gl/wrap/gles.c \ 84 | src/gl/wrap/glstub.c \ 85 | src/gl/math/matheval.c \ 86 | src/glx/hardext.c \ 87 | src/glx/glx.c \ 88 | src/glx/lookup.c \ 89 | src/glx/gbm.c \ 90 | src/glx/streaming.c \ 91 | 92 | LOCAL_CFLAGS += -g -std=gnu99 -funwind-tables -O3 -fvisibility=hidden -include include/android_debug.h 93 | LOCAL_CFLAGS += -DNOX11 94 | LOCAL_CFLAGS += -DNO_GBM 95 | #LOCAL_CFLAGS += -DNO_INIT_CONSTRUCTOR 96 | LOCAL_CFLAGS += -DDEFAULT_ES=2 97 | 98 | LOCAL_LDLIBS := -llog 99 | #building as a static lib 100 | 101 | LOCAL_CFLAGS += -DSTATICLIB 102 | include $(BUILD_STATIC_LIBRARY) 103 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016-2018 Sebastien Chevalier 2 | Copyright (c) 2013-2016 Ryan Hileman 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /MEDIA.md: -------------------------------------------------------------------------------- 1 | GL4ES - OpenGL for GLES Hardware 2 | ==== 3 | 4 | Many OpenGL software already works with GL4ES. 5 | 6 | ![foobillards++](refs/foobillardplus.0000014748.png) 7 | 8 | Complex OpenGL 1.5 games, like Foobillard++, that uses cascaded display list, line stipple and TexGen works fine. Here running on the OpenPandora. It will work with both GLES1.1 and GLES2.0 backend. Most OpenGL 1.x games will runs. 9 | 10 | 11 | [![Play on Youtube](https://img.youtube.com/vi/75FYb60L7zw/0.jpg)](https://www.youtube.com/watch?v=75FYb60L7zw) 12 | 13 | The limit is an hardware one: GLES1.1 and GLES2.0 hardware do not allow reading Depth buffer, so some games that use it (like AssaultCube) for game play wont run correctly. Some FPS are using it just for cosmetics (Lens flare) and run fine without, like Serious Sam (both First and Second Encounter), here on the OpenPandora again. 14 | 15 | ![AssaultCube on Android](media/assaultcube.jpg) 16 | AssaultCube an Android also use gl4es for the rendering 17 | 18 | 19 | [![Play on Youtube](https://img.youtube.com/vi/kJPb2jYiBoM/0.jpg)](https://www.youtube.com/watch?v=kJPb2jYiBoM) 20 | 21 | More complex program, like Blender, can also run. 22 | 23 | 24 | ![MineCraft](media/minecraft.png) 25 | 26 | But also Minecraft, here on an ODroid in this old video. 27 | 28 | 29 | ![OpenRA](refs/openra.0000031249.png) 30 | 31 | On the OpenGL 2.0, side using GLES2.0 backend, OpenRA can run on the Pandora. 32 | 33 | 34 | And OpenGL 2.x opens a lot of doors. Many commercial games run just fine on gl4es. 35 | 36 | [![Play on Youtube](https://img.youtube.com/vi/VUoeHWuwlMU/0.jpg)](https://www.youtube.com/watch?v=VUoeHWuwlMU) 37 | 38 | Here some FNA games, running on an ODroid XU4 (using method described [there](https://magazine.odroid.com/article/playing-modern-fna-games-on-the-odroid-platform/)). That video show just a few, and even more can be make to run. 39 | 40 | 41 | 42 | [![Play on Youtube](https://img.youtube.com/vi/B4YN37z3-ws/0.jpg)](https://www.youtube.com/watch?v=B4YN37z3-ws) 43 | 44 | And with [Box86](https://github.com/ptitSeb/box86), even more commercial games can run, like here NeverWinter Night on an ODroid XU4 45 | 46 | GL4ES also now works on some other platform, like AmigaOS4 (so BigEndian platform) 47 | [![Play on Youtube](https://img.youtube.com/vi/hQVabA_ReoQ/0.jpg)](https://www.youtube.com/watch?v=hQVabA_ReoQ) 48 | 49 | Here running Foobillard++ 50 | 51 | Or even in a web browser (that support WebGL): try it with Stunt Car Remake [here](http://ptitseb.github.io/stuntcarremake/) 52 | 53 | Another web browser example: Serious Sam Engine, try it [here](https://martinmullins.github.io/ssam/) (initial 80MB game files download). 54 | [source repo](https://github.com/martinmullins/Serious-Engine) 55 | [![Gif of Serious Engine](https://github.com/martinmullins/ssam/blob/main/ssam.gif?raw=true)](https://martinmullins.github.io/ssam/) 56 | 57 | Neverball in a browser also use gl4es for rendering: [neverball in a browser](https://neverball.github.io/) 58 | 59 | About performances: while gl4es is a wrapper, there are many caching and works done in gl4es to avoid slowdown and bottleneck. While those optimization are useless in highly optimized engine, like the Quake3 engine, on other engine and games, gl4es can be (much) faster than straight GLES conversion (especially if there are a lot of `glBegin(...)`/`glEnd()` drawing commands). On an x86 VM, gl4es running on GLES can be faster than direct OpenGL use on some games! 60 | Now GL4ES can also use VBO, either when the software use it, or automatically when using glList, giving sometimes a nice boost (the boost depend on the Platform and game) 61 | 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![logo](gl4es.png "gl4es logo") 2 | 3 | GL4ES - OpenGL for GLES Hardware 4 | ==== 5 | 6 | ![gl4es build status](https://api.travis-ci.org/ptitSeb/gl4es.png "gl4es build status") 7 | 8 | This is a library provide OpenGL 2.x functionality for GLES2.0 accelerated Hardware (and of course also support OpenGL 1.5 function, sometimes better than when using GLES 1.1 backend) 9 | There is also support for GLES 1.1 Hardware, emulating OpenGL 1.5, and some OpenGL 2.x+ extensions. 10 | 11 | GL4ES is known to work on many platform: OpenPandora, ODroid, RaspberryPI (2 and 3 at least), PocketCHIP, "otherfruit"PI (like the OrangePI), Android, iOS, x86 and x86_64 Linux (tested using mesa-egl). There is also some WIP support for AmigaOS4, using experimental GLES2 driver for Warp3D. 12 | 13 | This library is based on glshim (https://github.com/lunixbochs/glshim) but as now evolved far from it, with different feature set and objectives. Go check this lib if you need things like RemoteGL or TinyGLES (for software rendering). 14 | 15 | The focus is on compatibility and speed with a wide selection of game and software. 16 | 17 | It has been tested successfully of a large selection of games and software, including: Minecraft, OpenMW, SeriousSam (both First and Second Encounters), RVGL (ReVolt GL), TSMC (The Secret Maryo Chronicles), TORCS, SpeedDreams, GL-117, Foobillard(plus), half life 1&2, Blender 2.68 to name just a few. I have also some success with Linux port of XNA games, using either MonoGame or FNA. 18 | 19 | Most function of OpenGL up to 1.5 are supported, with some notable exceptions: 20 | * Reading of Depth or Stencil buffer will not work 21 | * GL_FEEDBACK mode is not implemented 22 | * No Accum emulation 23 | 24 | Some known general limitations: 25 | * GL_SELECT as some limitation in its implementation (for example, current Depth buffer or bounded texture are not taken into account, also custom vertex shader will not work here) 26 | * NPOT texture are supported, but not with GL_REPEAT / GL_MIRRORED, only GL_CLAMP will work properly (unless the GLES Hardware support NPOT) 27 | * Multiple Color attachment on Framebuffer are not supported 28 | * OcclusionQuery is implemented, but with a 0 bits precision 29 | * Probably many other things 30 | 31 | Status of the GLES2 backend 32 | * The FPE (Fixed Pipeline Emulator) has most OpenGL 1.5 drawing call implemented 33 | * The Shader Conversion is really crude, so only simple shaders will work (especially, the implicit conversion float <-> int is not handled) 34 | * ARB_program are supported (converted on-the-fly to glsl shaders) 35 | * Lighting support double-side and color separation 36 | * FogCoord are supported, along with secondary color 37 | * An ES2 context should be usable (useful for SDL2) 38 | * OpenGL 2.x games that have been tested include: OpenRA, GZDoom, Danger from the Deep, SuperTuxKart 0.8.1, Hammerwatch, OpenMW, half life 2, many FNA & MonoGames games (FEZ, Towerfall Ascension, Stardew Valley, Dust, Owlboy, and many other), even some Unity3D games (Teslagrad, Colin McRea Rally remake and other)... 39 | * glxgears works, but FlatShade is not implemented (and will probably never be), so it's slightly different than using GLES1.1 or actual GL hardware 40 | * GL_TEXTURE_1D, GL_TEXTURE_3D and GL_TEXTURE_RECTANGLE_ARB are not yet supported in shaders (they are supported in fixed pipeline functions), and texture 3D are just a single 2D layer for now. 41 | * Program that link only a GL_FRAGMENT or GL_VERTEX shader are not supported yet. 42 | * Some VBO are used. 43 | 44 | Status of the GLES1.1 backend 45 | * Framebuffer use FRAMEBUFFER_OES extension (that must be present in the GLES 1.1 stack) 46 | * Lighting doesn't support double-side or color separation 47 | * FogCoord or Secondary colors are not supported 48 | * GL_TEXTURE_3D are just a single 2D layer (the 1st layer). 49 | * VBO are supported, but they are emulated, even if VBO if supported in GLES1.1 driver 50 | 51 | If you use gl4es in your project (as a static or dynamic link), please mention gl4es in you readme / about / whatever. 52 | 53 | ---- 54 | 55 | Compiling 56 | ---- 57 | How to compile and per-platform specific comment can be found [here](COMPILE.md) 58 | 59 | ---- 60 | 61 | GLU 62 | ---- 63 | 64 | Standard GLU do works without any issues. You can find a version [here](https://github.com/ptitSeb/GLU) if you need one. 65 | 66 | ---- 67 | 68 | Installation 69 | ---- 70 | 71 | Put lib/libGL.so.1 in your `LD_LIBRARY_PATH`. 72 | Beware that GL4ES is meant to replace any libGL you can have on your system (like Mesa for example) 73 | 74 | ---- 75 | 76 | Usage 77 | ---- 78 | 79 | There are many environment variable to control gl4es behavior, also usable at runtime using `glHint(...)`. 80 | 81 | See [here](USAGE.md) for all variables and what they do. 82 | 83 | ---- 84 | 85 | Media (what is working already) 86 | ---- 87 | 88 | Some screenshot and youtube links of stuffs that works [here](MEDIA.md) 89 | 90 | ---- 91 | 92 | Version history 93 | ---- 94 | 95 | The change log is [here](CHANGELOG.md) 96 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-hacker 2 | title: GL4ES - The OpenGL driver for GLES Hardware 3 | -------------------------------------------------------------------------------- /bc_cat.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * 3 | * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 4 | * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved. 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful but, except 11 | * as otherwise stated in writing, without any warranty; without even the 12 | * implied warranty of merchantability or fitness for a particular purpose. 13 | * See the GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 18 | * 19 | * The full GNU General Public License is included in this distribution in 20 | * the file called "COPYING". 21 | * 22 | * Contact Information: 23 | * Imagination Technologies Ltd. 24 | * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 25 | * 26 | ******************************************************************************/ 27 | 28 | #ifndef __BC_CAT_H__ 29 | #define __BC_CAT_H__ 30 | 31 | #include 32 | 33 | #define BC_FOURCC(a,b,c,d) \ 34 | ((unsigned long) ((a) | (b)<<8 | (c)<<16 | (d)<<24)) 35 | 36 | #define BC_PIX_FMT_NV12 BC_FOURCC('N', 'V', '1', '2') /*YUV 4:2:0*/ 37 | #define BC_PIX_FMT_UYVY BC_FOURCC('U', 'Y', 'V', 'Y') /*YUV 4:2:2*/ 38 | #define BC_PIX_FMT_YUYV BC_FOURCC('Y', 'U', 'Y', 'V') /*YUV 4:2:2*/ 39 | #define BC_PIX_FMT_RGB565 BC_FOURCC('R', 'G', 'B', 'P') /*RGB 5:6:5*/ 40 | 41 | enum BC_memory { 42 | BC_MEMORY_MMAP = 1, 43 | BC_MEMORY_USERPTR = 2, 44 | }; 45 | 46 | typedef struct BCIO_package_TAG { 47 | int input; 48 | int output; 49 | }BCIO_package; 50 | 51 | /* 52 | * the following types are tested for fourcc in struct bc_buf_params_t 53 | * NV12 54 | * UYVY 55 | * RGB565 - not tested yet 56 | * YUYV 57 | */ 58 | typedef struct bc_buf_params { 59 | int count; /*number of buffers, [in/out]*/ 60 | int width; /*buffer width in pixel, multiple of 8 or 32*/ 61 | int height; /*buffer height in pixel*/ 62 | unsigned int fourcc; /*buffer pixel format*/ 63 | enum BC_memory type; 64 | } bc_buf_params_t; 65 | 66 | typedef struct bc_buf_ptr { 67 | unsigned int index; 68 | int size; 69 | unsigned long pa; 70 | } bc_buf_ptr_t; 71 | 72 | #define BCIO_GID 'g' 73 | #define BC_IOWR(INDEX) _IOWR(BCIO_GID, INDEX, BCIO_package) 74 | 75 | #define BCIOGET_BUFFERCOUNT BC_IOWR(0) /*obsolete, since BCIOREQ_BUFFERS 76 | return the number of buffers*/ 77 | #define BCIOGET_BUFFERPHYADDR BC_IOWR(1) /*get physical address by index*/ 78 | #define BCIOGET_BUFFERIDX BC_IOWR(2) /*get index by physical address*/ 79 | 80 | #define BCIOREQ_BUFFERS BC_IOWR(3) 81 | #define BCIOSET_BUFFERPHYADDR BC_IOWR(4) 82 | 83 | #endif 84 | 85 | -------------------------------------------------------------------------------- /gl4es.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RandomCoderOrg/gl4es-port/6145025f2ba262484d01165359fa0768aa5d52c0/gl4es.png -------------------------------------------------------------------------------- /include/GL/glu_mangle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Mesa 3-D graphics library 3 | * Version: 3.0 4 | * Copyright (C) 1995-1998 Brian Paul 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the Free 18 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | */ 20 | 21 | 22 | #ifndef GLU_MANGLE_H 23 | #define GLU_MANGLE_H 24 | 25 | 26 | #define gluLookAt mgluLookAt 27 | #define gluOrtho2D mgluOrtho2D 28 | #define gluPerspective mgluPerspective 29 | #define gluPickMatrix mgluPickMatrix 30 | #define gluProject mgluProject 31 | #define gluUnProject mgluUnProject 32 | #define gluErrorString mgluErrorString 33 | #define gluScaleImage mgluScaleImage 34 | #define gluBuild1DMipmaps mgluBuild1DMipmaps 35 | #define gluBuild2DMipmaps mgluBuild2DMipmaps 36 | #define gluNewQuadric mgluNewQuadric 37 | #define gluDeleteQuadric mgluDeleteQuadric 38 | #define gluQuadricDrawStyle mgluQuadricDrawStyle 39 | #define gluQuadricOrientation mgluQuadricOrientation 40 | #define gluQuadricNormals mgluQuadricNormals 41 | #define gluQuadricTexture mgluQuadricTexture 42 | #define gluQuadricCallback mgluQuadricCallback 43 | #define gluCylinder mgluCylinder 44 | #define gluSphere mgluSphere 45 | #define gluDisk mgluDisk 46 | #define gluPartialDisk mgluPartialDisk 47 | #define gluNewNurbsRenderer mgluNewNurbsRenderer 48 | #define gluDeleteNurbsRenderer mgluDeleteNurbsRenderer 49 | #define gluLoadSamplingMatrices mgluLoadSamplingMatrices 50 | #define gluNurbsProperty mgluNurbsProperty 51 | #define gluGetNurbsProperty mgluGetNurbsProperty 52 | #define gluBeginCurve mgluBeginCurve 53 | #define gluEndCurve mgluEndCurve 54 | #define gluNurbsCurve mgluNurbsCurve 55 | #define gluBeginSurface mgluBeginSurface 56 | #define gluEndSurface mgluEndSurface 57 | #define gluNurbsSurface mgluNurbsSurface 58 | #define gluBeginTrim mgluBeginTrim 59 | #define gluEndTrim mgluEndTrim 60 | #define gluPwlCurve mgluPwlCurve 61 | #define gluNurbsCallback mgluNurbsCallback 62 | #define gluNewTess mgluNewTess 63 | #define gluDeleteTess mgluDeleteTess 64 | #define gluTessBeginPolygon mgluTessBeginPolygon 65 | #define gluTessBeginContour mgluTessBeginContour 66 | #define gluTessVertex mgluTessVertex 67 | #define gluTessEndPolygon mgluTessEndPolygon 68 | #define gluTessEndContour mgluTessEndContour 69 | #define gluTessProperty mgluTessProperty 70 | #define gluTessNormal mgluTessNormal 71 | #define gluTessCallback mgluTessCallback 72 | #define gluGetTessProperty mgluGetTessProperty 73 | #define gluBeginPolygon mgluBeginPolygon 74 | #define gluNextContour mgluNextContour 75 | #define gluEndPolygon mgluEndPolygon 76 | #define gluGetString mgluGetString 77 | #define gluBuild1DMipmapLevels mgluBuild1DMipmapLevels 78 | #define gluBuild2DMipmapLevels mgluBuild2DMipmapLevels 79 | #define gluBuild3DMipmapLevels mgluBuild3DMipmapLevels 80 | #define gluBuild3DMipmaps mgluBuild3DMipmaps 81 | #define gluCheckExtension mgluCheckExtension 82 | #define gluUnProject4 mgluUnProject4 83 | #define gluNurbsCallbackData mgluNurbsCallbackData 84 | #define gluNurbsCallbackDataEXT mgluNurbsCallbackDataEXT 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /include/GL/glx_mangle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Mesa 3-D graphics library 3 | * Version: 6.5 4 | * 5 | * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 21 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | 26 | #ifndef GLX_MANGLE_H 27 | #define GLX_MANGLE_H 28 | 29 | #define glXChooseVisual mglXChooseVisual 30 | #define glXCreateContext mglXCreateContext 31 | #define glXDestroyContext mglXDestroyContext 32 | #define glXMakeCurrent mglXMakeCurrent 33 | #define glXCopyContext mglXCopyContext 34 | #define glXSwapBuffers mglXSwapBuffers 35 | #define glXCreateGLXPixmap mglXCreateGLXPixmap 36 | #define glXDestroyGLXPixmap mglXDestroyGLXPixmap 37 | #define glXQueryExtension mglXQueryExtension 38 | #define glXQueryVersion mglXQueryVersion 39 | #define glXIsDirect mglXIsDirect 40 | #define glXGetConfig mglXGetConfig 41 | #define glXGetCurrentContext mglXGetCurrentContext 42 | #define glXGetCurrentDrawable mglXGetCurrentDrawable 43 | #define glXWaitGL mglXWaitGL 44 | #define glXWaitX mglXWaitX 45 | #define glXUseXFont mglXUseXFont 46 | #define glXQueryExtensionsString mglXQueryExtensionsString 47 | #define glXQueryServerString mglXQueryServerString 48 | #define glXGetClientString mglXGetClientString 49 | #define glXCreateGLXPixmapMESA mglXCreateGLXPixmapMESA 50 | #define glXReleaseBuffersMESA mglXReleaseBuffersMESA 51 | #define glXCopySubBufferMESA mglXCopySubBufferMESA 52 | #define glXGetVideoSyncSGI mglXGetVideoSyncSGI 53 | #define glXWaitVideoSyncSGI mglXWaitVideoSyncSGI 54 | 55 | /* GLX 1.2 */ 56 | #define glXGetCurrentDisplay mglXGetCurrentDisplay 57 | 58 | /* GLX 1.3 */ 59 | #define glXChooseFBConfig mglXChooseFBConfig 60 | #define glXGetFBConfigAttrib mglXGetFBConfigAttrib 61 | #define glXGetFBConfigs mglXGetFBConfigs 62 | #define glXGetVisualFromFBConfig mglXGetVisualFromFBConfig 63 | #define glXCreateWindow mglXCreateWindow 64 | #define glXDestroyWindow mglXDestroyWindow 65 | #define glXCreatePixmap mglXCreatePixmap 66 | #define glXDestroyPixmap mglXDestroyPixmap 67 | #define glXCreatePbuffer mglXCreatePbuffer 68 | #define glXDestroyPbuffer mglXDestroyPbuffer 69 | #define glXQueryDrawable mglXQueryDrawable 70 | #define glXCreateNewContext mglXCreateNewContext 71 | #define glXMakeContextCurrent mglXMakeContextCurrent 72 | #define glXGetCurrentReadDrawable mglXGetCurrentReadDrawable 73 | #define glXQueryContext mglXQueryContext 74 | #define glXSelectEvent mglXSelectEvent 75 | #define glXGetSelectedEvent mglXGetSelectedEvent 76 | 77 | /* GLX 1.4 */ 78 | #define glXGetProcAddress mglXGetProcAddress 79 | #define glXGetProcAddressARB mglXGetProcAddressARB 80 | 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /include/GLES/egl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Skeleton egl.h to provide compatibility for early GLES 1.0 3 | * applications. Several early implementations included gl.h 4 | * in egl.h leading applications to include only egl.h 5 | * 6 | * $Revision: 6252 $ on $Date:: 2008-08-06 16:35:08 -0700 #$ 7 | */ 8 | 9 | #ifndef __legacy_egl_h_ 10 | #define __legacy_egl_h_ 11 | 12 | #include 13 | #include 14 | 15 | #endif /* __legacy_egl_h_ */ 16 | -------------------------------------------------------------------------------- /include/GLES/gl2platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __gl2platform_h_ 2 | #define __gl2platform_h_ 3 | 4 | /* $Revision: 10602 $ on $Date:: 2010-03-04 22:35:34 -0800 #$ */ 5 | 6 | /* 7 | * This document is licensed under the SGI Free Software B License Version 8 | * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . 9 | */ 10 | 11 | /* Platform-specific types and definitions for OpenGL ES 2.X gl2.h 12 | * 13 | * Adopters may modify khrplatform.h and this file to suit their platform. 14 | * You are encouraged to submit all modifications to the Khronos group so that 15 | * they can be included in future versions of this file. Please submit changes 16 | * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) 17 | * by filing a bug against product "OpenGL-ES" component "Registry". 18 | */ 19 | 20 | #include 21 | 22 | #ifndef GL_APICALL 23 | #define GL_APICALL KHRONOS_APICALL 24 | #endif 25 | 26 | #ifndef GL_APIENTRY 27 | #define GL_APIENTRY KHRONOS_APIENTRY 28 | #endif 29 | 30 | #endif /* __gl2platform_h_ */ 31 | -------------------------------------------------------------------------------- /include/GLES/gl3ext.h: -------------------------------------------------------------------------------- 1 | #ifndef __gl3ext_h_ 2 | #define __gl3ext_h_ 3 | 4 | /* $Revision: 17809 $ on $Date:: 2012-05-14 08:03:36 -0700 #$ */ 5 | 6 | /* 7 | * This document is licensed under the SGI Free Software B License Version 8 | * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . 9 | */ 10 | 11 | /* OpenGL ES 3 Extensions 12 | * 13 | * After an OES extension's interactions with OpenGl ES 3.0 have been documented, 14 | * its tokens and function definitions should be added to this file in a manner 15 | * that does not conflict with gl2ext.h or gl3.h. 16 | * 17 | * Tokens and function definitions for extensions that have become standard 18 | * features in OpenGL ES 3.0 will not be added to this file. 19 | * 20 | * Applications using OpenGL-ES-2-only extensions should include gl2ext.h 21 | */ 22 | 23 | #endif /* __gl3ext_h_ */ 24 | 25 | -------------------------------------------------------------------------------- /include/GLES/gl3platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __gl3platform_h_ 2 | #define __gl3platform_h_ 3 | 4 | /* $Revision: 18437 $ on $Date:: 2012-07-08 23:31:39 -0700 #$ */ 5 | 6 | /* 7 | * This document is licensed under the SGI Free Software B License Version 8 | * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . 9 | */ 10 | 11 | /* Platform-specific types and definitions for OpenGL ES 3.X gl3.h 12 | * 13 | * Adopters may modify khrplatform.h and this file to suit their platform. 14 | * You are encouraged to submit all modifications to the Khronos group so that 15 | * they can be included in future versions of this file. Please submit changes 16 | * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) 17 | * by filing a bug against product "OpenGL-ES" component "Registry". 18 | */ 19 | 20 | #include 21 | 22 | #ifndef GL_APICALL 23 | #define GL_APICALL KHRONOS_APICALL 24 | #endif 25 | 26 | #ifndef GL_APIENTRY 27 | #define GL_APIENTRY KHRONOS_APIENTRY 28 | #endif 29 | 30 | #endif /* __gl3platform_h_ */ 31 | -------------------------------------------------------------------------------- /include/GLES/glplatform.h: -------------------------------------------------------------------------------- 1 | #ifndef __glplatform_h_ 2 | #define __glplatform_h_ 3 | 4 | /* $Revision: 10601 $ on $Date:: 2010-03-04 22:15:27 -0800 #$ */ 5 | 6 | /* 7 | * This document is licensed under the SGI Free Software B License Version 8 | * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . 9 | */ 10 | 11 | /* Platform-specific types and definitions for OpenGL ES 1.X gl.h 12 | * 13 | * Adopters may modify khrplatform.h and this file to suit their platform. 14 | * You are encouraged to submit all modifications to the Khronos group so that 15 | * they can be included in future versions of this file. Please submit changes 16 | * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) 17 | * by filing a bug against product "OpenGL-ES" component "Registry". 18 | */ 19 | 20 | #include 21 | 22 | #ifndef GL_API 23 | #define GL_API KHRONOS_APICALL 24 | #endif 25 | 26 | #ifndef GL_APIENTRY 27 | #define GL_APIENTRY KHRONOS_APIENTRY 28 | #endif 29 | 30 | #endif /* __glplatform_h_ */ 31 | -------------------------------------------------------------------------------- /include/android_debug.h: -------------------------------------------------------------------------------- 1 | #ifndef __ANDROID_DEBUG_H__ 2 | #define __ANDROID_DEBUG_H__ 3 | 4 | // Redirect printf() to Android log 5 | // Put this file into CFLAGS: "-include ../android_debug.h" 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #define printf(...) __android_log_print(ANDROID_LOG_INFO, "LIBGL", __VA_ARGS__) 12 | 13 | #endif 14 | 15 | -------------------------------------------------------------------------------- /include/gl4eshint.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ESINCLUDE_HINT_H_ 2 | #define _GL4ESINCLUDE_HINT_H_ 3 | 4 | // Custom hints to handles some specifics gl4es options 5 | 6 | // same as using LIBGL_SHRINK=x 7 | #define GL_SHRINK_HINT_GL4ES 0xA101 8 | // same as using LIBGL_ALPHAHACK=x 9 | #define GL_ALPHAHACK_HINT_GL4ES 0xA102 10 | // same as using LIBGL_RECYCLEFBO=x 11 | #define GL_RECYCLEFBO_HINT_GL4ES 0xA103 12 | // same as using LIBGL_MIPMAP=x 13 | #define GL_MIPMAP_HINT_GL4ES 0xA104 14 | // same as using LIBGL_TEXDUMP=x 15 | #define GL_TEXDUMP_HINT_GL4ES 0xA105 16 | // same as using LIBGL_COPY=x 17 | #define GL_COPY_HINT_GL4ES 0xA106 18 | // same as using LIBGL_NOLUMALPHA=x 19 | #define GL_NOLUMAPHA_HINT_GL4ES 0xA107 20 | // same as using LIBGL_BLENDHACK=x 21 | #define GL_BLENDHACK_HINT_GL4ES 0xA108 22 | // REMOVED same as using LIBGL_BATCH=x 23 | #define GL_BATCH_HINT_GL4ES 0xA109 24 | // same as using LIBGL_NOERROR=x 25 | #define GL_NOERROR_HINT_GL4ES 0xA10A 26 | // same as using LIBGL_NODOWNSAMPLING=x 27 | #define GL_NODOWNSAMPLING_HINT_GL4ES 0xA10B 28 | // same as using LIBGL_NOVAOCACHE=x 29 | #define GL_NOVAOCACHE_HINT_GL4ES 0xA10C 30 | // same as using LIBGL_BEGINEND=x 31 | #define GL_BEGINEND_HINT_GL4ES 0xA10D 32 | // same as using LIBGL_AVOID16BITS=x 33 | #define GL_AVOID16BITS_HINT_GL4ES 0xA10E 34 | // same as using LIBGL_GAMMA=xx (PANDORA only) 35 | #define GL_GAMMA_HINT_GL4ES 0xA10F 36 | 37 | // special value to query underlying Hardware value using glGetString 38 | #define GL_VENDOR_GL4ES (GL_VENDOR | 0x10000) 39 | #define GL_EXTENSIONS_GL4ES (GL_ENXTENSIONS | 0x10000) 40 | #endif // _GL4ESINCLUDE_HINT_H_ 41 | -------------------------------------------------------------------------------- /include/gl4esinit.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _GL4ESINCLUDE_INIT_H_ 3 | #define _GL4ESINCLUDE_INIT_H_ 4 | 5 | #ifndef APIENTRY_GL4ES 6 | # if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__) 7 | # define APIENTRY_GL4ES __stdcall 8 | # else 9 | # define APIENTRY_GL4ES 10 | # endif 11 | #endif 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | // set driver GetProcAddress implementation. required for hardext detection with NOEGL or when loader is disabled 18 | void set_getprocaddress(void *(APIENTRY_GL4ES *new_proc_address)(const char *)); 19 | // reguired with NOEGL 20 | void set_getmainfbsize(void (APIENTRY_GL4ES *new_getMainFBSize)(int* width, int* height)); 21 | // do this before any GL calls if init constructors are disabled. 22 | void initialize_gl4es(void); 23 | // do this to uninitialize GL4ES if init constructors are disabled. 24 | void close_gl4es(void); 25 | // wrapped GetProcAddress 26 | void* APIENTRY_GL4ES gl4es_GetProcAddress(const char *name); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /media/assaultcube.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RandomCoderOrg/gl4es-port/6145025f2ba262484d01165359fa0768aa5d52c0/media/assaultcube.jpg -------------------------------------------------------------------------------- /media/minecraft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RandomCoderOrg/gl4es-port/6145025f2ba262484d01165359fa0768aa5d52c0/media/minecraft.png -------------------------------------------------------------------------------- /refs/descent3.0000284192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RandomCoderOrg/gl4es-port/6145025f2ba262484d01165359fa0768aa5d52c0/refs/descent3.0000284192.png -------------------------------------------------------------------------------- /refs/foobillardplus.0000014748.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RandomCoderOrg/gl4es-port/6145025f2ba262484d01165359fa0768aa5d52c0/refs/foobillardplus.0000014748.png -------------------------------------------------------------------------------- /refs/glsl_lighting.0000505393.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RandomCoderOrg/gl4es-port/6145025f2ba262484d01165359fa0768aa5d52c0/refs/glsl_lighting.0000505393.png -------------------------------------------------------------------------------- /refs/glxgears.0000008203.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RandomCoderOrg/gl4es-port/6145025f2ba262484d01165359fa0768aa5d52c0/refs/glxgears.0000008203.png -------------------------------------------------------------------------------- /refs/neverball.0000078749.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RandomCoderOrg/gl4es-port/6145025f2ba262484d01165359fa0768aa5d52c0/refs/neverball.0000078749.png -------------------------------------------------------------------------------- /refs/neverball.0000078750.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RandomCoderOrg/gl4es-port/6145025f2ba262484d01165359fa0768aa5d52c0/refs/neverball.0000078750.png -------------------------------------------------------------------------------- /refs/openra.0000031249.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RandomCoderOrg/gl4es-port/6145025f2ba262484d01165359fa0768aa5d52c0/refs/openra.0000031249.png -------------------------------------------------------------------------------- /refs/pointsprite.0000248810.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RandomCoderOrg/gl4es-port/6145025f2ba262484d01165359fa0768aa5d52c0/refs/pointsprite.0000248810.png -------------------------------------------------------------------------------- /refs/stuntcarracer.0000118817.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RandomCoderOrg/gl4es-port/6145025f2ba262484d01165359fa0768aa5d52c0/refs/stuntcarracer.0000118817.png -------------------------------------------------------------------------------- /spec/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash -ux 2 | cd "$(dirname "$0")" 3 | 4 | base=../src/ 5 | if [ -e yml/gles-1.1-full.yml ]; then rm yml/gles-1.1-full.yml ;fi 6 | touch yml/gles-1.1-full.yml 7 | cat yml/*-1.1.yml >> yml/gles-1.1-full.yml 8 | #gles1=$(ls -1 yml/*-1.1-full.yml | tr '\n' ',' | sed -e 's/,$//') 9 | #gles=$(ls -1 yml/*es-1.1.yml | tr '\n' ',' | sed -e 's/,$//') 10 | #glext=$(ls -1 yml/*ext-1.1.yml | tr '\n' ',' | sed -e 's/,$//') 11 | gles1="yml/gles-1.1-full.yml" 12 | 13 | #./gen.py "$gles" gleswrap.c.j2 gleswrap.c gles.h > "$base/gl/wrap/gles.c" 14 | #./gen.py "$glext" glextwrap.c.j2 glextwrap.c gles.h > "$base/gl/wrap/glesext.c" 15 | ./gen.py "$gles1" gleswrap.c.j2 gleswrap.c gles.h ../gl4es.h ../loader.h skips.h > "$base/gl/wrap/gles.c" 16 | ./gen.py "$gles1" glwrap.h.j2 gleswrap.h ../gles.h > "$base/gl/wrap/gles.h" 17 | ./gen.py "$gles1" glxfuncs.j2 glxfuncs.inc ../gl/gl4es.h > "$base/glx/glesfuncs.inc" 18 | 19 | -------------------------------------------------------------------------------- /spec/gen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import argparse 4 | import jinja2 5 | import re 6 | from yaml import safe_load 7 | 8 | split_re = re.compile(r'^(?P.*?)\s*(?P\w+)$') 9 | env = jinja2.Environment( 10 | trim_blocks=True, 11 | lstrip_blocks=True, 12 | loader=jinja2.FileSystemLoader('template'), 13 | ) 14 | 15 | def args(args, add_type=True): 16 | return ', '.join( 17 | '{} {}'.format(arg['type'], arg['name']) if add_type else arg['name'] 18 | for arg in args 19 | ) 20 | 21 | f = '0.2f' 22 | printf_lookup = { 23 | 'GLbitfield': 'd', 24 | 'GLboolean': 'd', 25 | 'GLbyte': 'c', 26 | 'GLubyte': 'c', 27 | 'GLchar': 'c', 28 | 'GLdouble': '0.2f', 29 | 'GLenum': 'u', 30 | 'GLfloat': '0.2f', 31 | 'GLint': 'd', 32 | 'GLintptr': 'd', 33 | 'GLintptrARB': 'd', 34 | 'GLshort': 'd', 35 | 'GLsizei': 'd', 36 | 'GLsizeiptr': 'd', 37 | 'GLsizeiptrARB': 'd', 38 | 'GLuint': 'u', 39 | 'GLushort': 'u', 40 | 'GLvoid': 'p', 41 | } 42 | 43 | def printf(args): 44 | types = [] 45 | for arg in args: 46 | typ = arg['type'] 47 | if '*' in typ: 48 | t = 'p' 49 | else: 50 | t = printf_lookup.get(typ, 'p') 51 | 52 | types.append(t) 53 | 54 | return ', '.join('%' + t for t in types) 55 | 56 | def unconst(s): 57 | split = s.split(' ') 58 | while 'const' in split: 59 | split.remove('const') 60 | return ' '.join(split) 61 | 62 | env.filters['args'] = args 63 | env.filters['printf'] = printf 64 | env.filters['unconst'] = unconst 65 | 66 | def split_arg(arg): 67 | match = split_re.match(arg) 68 | if match: 69 | return match.groupdict() 70 | else: 71 | return {'type': 'unknown', 'name': arg} 72 | 73 | def gen(files, template, guard_name, headers, 74 | deep=False, cats=(), ifdef=None, ifndef=None): 75 | funcs = {} 76 | formats = [] 77 | unique_formats = set() 78 | for data in files: 79 | if deep and not isinstance(data.values()[0], list): 80 | functions = [] 81 | for cat, f in data.items(): 82 | if not cats or cat in cats: 83 | functions.extend(f.items()) 84 | else: 85 | functions = data.items() 86 | 87 | for name, args in sorted(functions): 88 | props = {} 89 | if args: 90 | ret = args.pop(0) 91 | else: 92 | ret = 'void' 93 | 94 | loadlib = 'LOAD_GLES' 95 | if name.endswith('_OES_'): 96 | loadlib = 'LOAD_GLES_OES' 97 | name = name[:-5] 98 | elif name.endswith('_EXT_'): 99 | loadlib = 'LOAD_GLES_EXT' 100 | name = name[:-5] 101 | 102 | args = [split_arg(arg) for arg in args if not arg == 'void'] 103 | if any(arg.get('type') == 'unknown' for arg in args): 104 | continue 105 | 106 | if args: 107 | args[0]['first'] = True 108 | args[-1]['last'] = True 109 | 110 | for i, arg in enumerate(args): 111 | arg['index'] = i 112 | 113 | types = '_'.join( 114 | arg['type'].replace(' ', '_').replace('*', '__GENPT__') 115 | for arg in [{'type': ret}] + args) 116 | 117 | props.update({ 118 | 'return': ret, 119 | 'name': name, 120 | 'args': args, 121 | 'types': types, 122 | 'void': ret == 'void', 123 | 'loadlib': loadlib, 124 | }) 125 | if not types in unique_formats: 126 | unique_formats.add(types) 127 | formats.append(props) 128 | 129 | funcs[name] = props 130 | 131 | context = { 132 | 'functions': [i[1] for i in sorted(funcs.items())], 133 | 'formats': formats, 134 | 'headers': headers, 135 | 'name': guard_name, 136 | 'ifdef': ifdef, 137 | 'ifndef': ifndef, 138 | } 139 | 140 | t = env.get_template(template) 141 | return t.render(**context).rstrip('\n') 142 | 143 | if __name__ == '__main__': 144 | parser = argparse.ArgumentParser(description='Generate code with yml/jinja.') 145 | parser.add_argument('yaml', help='spec files') 146 | parser.add_argument('template', help='jinja template to load') 147 | parser.add_argument('name', help='header guard name') 148 | parser.add_argument('headers', nargs='*', help='headers to include') 149 | parser.add_argument('--deep', help='nested definitions', action='store_true') 150 | parser.add_argument('--cats', help='deep category filter') 151 | parser.add_argument('--ifdef', help='wrap with ifdef') 152 | parser.add_argument('--ifndef', help='wrap with ifndef') 153 | 154 | args = parser.parse_args() 155 | 156 | files = [] 157 | for name in args.yaml.split(','): 158 | with open(name) as f: 159 | data = safe_load(f) 160 | if data: 161 | files.append(data) 162 | 163 | if args.cats: 164 | cats = args.cats.split(',') 165 | else: 166 | cats = None 167 | print(gen(files, args.template, args.name, 168 | args.headers, args.deep, cats, 169 | args.ifdef, args.ifndef)) 170 | -------------------------------------------------------------------------------- /spec/requirements.txt: -------------------------------------------------------------------------------- 1 | jinja2 2 | pyyaml 3 | -------------------------------------------------------------------------------- /spec/template/base/base.j2: -------------------------------------------------------------------------------- 1 | {% if ifdef %}#ifdef {{ ifdef }} 2 | {% endif %} 3 | {% if ifndef %}#ifndef {{ ifndef }} 4 | {% endif %} 5 | {% block main %}{% endblock %} 6 | {% if ifdef %}#endif{% endif %} 7 | {% if ifndef %}#endif{% endif %} 8 | -------------------------------------------------------------------------------- /spec/template/base/copy_packed_call.j2: -------------------------------------------------------------------------------- 1 | packed_call_t* glCopyPackedCall(const packed_call_t *packed) { 2 | switch (packed->format) { 3 | {% for f in formats %} 4 | case FORMAT_{{ f.types }}: { 5 | int sizeofpacked = sizeof(PACKED_{{ f.types }}); 6 | PACKED_{{ f.types }} *newpacked = (PACKED_{{ f.types }}*)malloc(sizeofpacked); 7 | memcpy(newpacked, packed, sizeofpacked); 8 | return (packed_call_t*)newpacked; 9 | break; 10 | } 11 | {% endfor %} 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /spec/template/base/fprint.j2: -------------------------------------------------------------------------------- 1 | {% if func.args %} 2 | printf("{{ func.name }}({{ func.args|printf }});\n", {{ func.args|args(0) }}); 3 | {% else %} 4 | printf("{{ func.name }}();\n"); 5 | {% endif %} 6 | -------------------------------------------------------------------------------- /spec/template/base/header.j2: -------------------------------------------------------------------------------- 1 | {% extends "base/base.j2" %} 2 | {% block main %} 3 | {% include "base/headers.j2" %} 4 | 5 | {% set guard = name.upper().replace('.', '_') -%} 6 | #ifndef {{ guard }} 7 | #define {{ guard }} 8 | {% block content %}{% endblock %} 9 | #endif 10 | {% endblock %} 11 | -------------------------------------------------------------------------------- /spec/template/base/headers.j2: -------------------------------------------------------------------------------- 1 | {% block headers %} 2 | {% for header in headers %} 3 | {% if "<" in header %} 4 | #include {{ header }} 5 | {% else %} 6 | #include "{{ header }}" 7 | {% endif %} 8 | {% endfor %} 9 | {% endblock %} 10 | -------------------------------------------------------------------------------- /spec/template/base/indexed_call.j2: -------------------------------------------------------------------------------- 1 | void glIndexedCall(const indexed_call_t *packed, void *ret_v) { 2 | switch (packed->func) { 3 | {% for f in functions %} 4 | #ifndef skip_index_{{ f.name }} 5 | case {{ f.name }}_INDEX: { 6 | INDEXED_{{ f.types }} *unpacked = (INDEXED_{{ f.types }} *)packed; 7 | {% if f.args %} 8 | ARGS_{{ f.types }} args = unpacked->args; 9 | {% endif %} 10 | {% if not f.void %} 11 | {{ f.return }} *ret = ({{ f.return }} *)ret_v; 12 | *ret = 13 | {% endif %} 14 | {{ f.name }}({% for arg in f.args -%} 15 | args.a{{ loop.index }}{% if not arg.last %}, {% endif %} 16 | {% endfor %}); 17 | break; 18 | } 19 | #endif 20 | {% endfor %} 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /spec/template/base/packed_call.j2: -------------------------------------------------------------------------------- 1 | void glPackedCall(const packed_call_t *packed) { 2 | switch (packed->format) { 3 | {% for f in formats %} 4 | case FORMAT_{{ f.types }}: { 5 | PACKED_{{ f.types }} *unpacked = (PACKED_{{ f.types }} *)packed; 6 | {% if f.args %} 7 | ARGS_{{ f.types }} args = unpacked->args; 8 | {% endif %} 9 | unpacked->func({% for arg in f.args -%} 10 | args.a{{ loop.index }}{% if not arg.last %}, {% endif %} 11 | {% endfor %}); 12 | break; 13 | } 14 | {% endfor %} 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spec/template/base/wrap.c.j2: -------------------------------------------------------------------------------- 1 | {% extends "base/base.j2" %} 2 | {% block main %} 3 | {% include "base/headers.j2" %} 4 | {% for func in functions %} 5 | {% block definition scoped %} 6 | {{ func.return }} gl4es_{{ func.name }}({{ func.args|args }}) { 7 | {% block load scoped %}{% endblock %} 8 | {% block call scoped %} 9 | {% if not func.void %}return {% endif %}{% block prefix %}wrap{% endblock %}_{{ func.name }}({{ func.args|args(0) }}); 10 | {%- endblock %} 11 | } 12 | {{ func.return }} {{ func.name }}({{ func.args|args }}) AliasExport("gl4es_{{ func.name }}"); 13 | {% endblock %} 14 | {% endfor %} 15 | {% block content %}{% endblock %} 16 | {% endblock %} 17 | -------------------------------------------------------------------------------- /spec/template/base/wrap.h.j2: -------------------------------------------------------------------------------- 1 | {% extends "base/header.j2" %} 2 | {% block content %} 3 | 4 | typedef struct { 5 | int format; 6 | void *func; 7 | void *args; 8 | } packed_call_t; 9 | 10 | typedef struct { 11 | int func; 12 | void *args; 13 | } indexed_call_t; 14 | 15 | enum FORMAT { 16 | {% for f in formats %} 17 | FORMAT_{{ f.types }}, 18 | {% endfor %} 19 | }; 20 | 21 | {% for f in formats %} 22 | typedef {{ f.return }} (*FUNC_{{ f.types }})({{ f.args|args }}); 23 | {% if f.args %} 24 | typedef struct { 25 | {% for arg in f.args %} 26 | {{ arg.type|unconst }} a{{ loop.index }}{% if arg.type == 'GLdouble' %} __attribute__ ((aligned(8))){% endif %}; 27 | {% endfor %} 28 | } ARGS_{{ f.types }}; 29 | {% endif %} 30 | typedef struct { 31 | int format; 32 | FUNC_{{ f.types }} func; 33 | {% if f.args %} 34 | ARGS_{{ f.types }} args; 35 | {% endif %} 36 | } PACKED_{{ f.types }}; 37 | typedef struct { 38 | int func; 39 | {% if f.args %} 40 | ARGS_{{ f.types }} args; 41 | {% endif %} 42 | } INDEXED_{{ f.types }}; 43 | {% endfor %} 44 | 45 | extern void glPushCall(void *data); 46 | void glPackedCall(const packed_call_t *packed); 47 | void glIndexedCall(const indexed_call_t *packed, void *ret_v); 48 | packed_call_t* glCopyPackedCall(const packed_call_t *packed); 49 | 50 | {% for func in functions %} 51 | #define {{ func.name }}_INDEX {{ loop.index }} 52 | #define {{ func.name }}_RETURN {{ func.return }} 53 | #define {{ func.name }}_ARG_NAMES {{ func.args|args(0) }} 54 | #define {{ func.name }}_ARG_EXPAND {{ func.args|args }} 55 | #define {{ func.name }}_PACKED PACKED_{{ func.types }} 56 | #define {{ func.name }}_INDEXED INDEXED_{{ func.types }} 57 | #define {{ func.name }}_FORMAT FORMAT_{{ func.types }} 58 | {% endfor %} 59 | 60 | {% for func in functions %} 61 | {{ func.return }} APIENTRY_GL4ES gl4es_{{ func.name }}({{ func.name }}_ARG_EXPAND); 62 | typedef {{ func.return }} (* APIENTRY_GLES {{ func.name }}_PTR)({{ func.name }}_ARG_EXPAND); 63 | {% endfor %} 64 | 65 | {% endblock %} 66 | -------------------------------------------------------------------------------- /spec/template/client.c.j2: -------------------------------------------------------------------------------- 1 | {% extends "base/wrap.c.j2" %} 2 | {% block headers %} 3 | #include 4 | #include 5 | #include 6 | #include 7 | {{ super() }} 8 | 9 | {% endblock %} 10 | 11 | {% block main %} 12 | {{ super() }} 13 | 14 | snd_config_t *snd_config = NULL; 15 | 16 | __GLXextFuncPtr glXGetProcAddressARB(const GLubyte *name) { 17 | {% for func in functions %} 18 | {% if not func.name.startswith('snd_') %} 19 | if (strcmp(name, "{{ func.name }}") == 0) { 20 | return (void *){{ func.name }}; 21 | } 22 | {% endif %} 23 | {% endfor %} 24 | printf("glXGetProcAddress(%s) not found\n", name); 25 | return NULL; 26 | } 27 | 28 | __GLXextFuncPtr glXGetProcAddress(const GLubyte *name) { 29 | return glXGetProcAddressARB(name); 30 | } 31 | {% endblock %} 32 | 33 | {% block definition %} 34 | #if !defined(skip_client_{{ func.name }}) && !defined(skip_index_{{ func.name }}) 35 | {{ super() -}} 36 | #endif 37 | {% endblock %} 38 | 39 | {% block call %} 40 | {{ func.name }}_INDEXED packed_data; 41 | packed_data.func = {{ func.name }}_INDEX; 42 | {% for arg in func.args %} 43 | packed_data.args.a{{ loop.index }} = ({{ arg.type|unconst }}){{ arg.name }}; 44 | {% endfor %} 45 | {% if not func.void %} 46 | {{ func.return }} ret; 47 | syscall(SYS_proxy, (void *)&packed_data, &ret); 48 | return ret; 49 | {% else %} 50 | syscall(SYS_proxy, (void *)&packed_data, NULL); 51 | {% endif %} 52 | {% endblock %} 53 | -------------------------------------------------------------------------------- /spec/template/eglwrap.c.j2: -------------------------------------------------------------------------------- 1 | {% extends "base/wrap.c.j2" %} 2 | {% block headers %} 3 | {{ super() }} 4 | void *egl_lib; 5 | #define WARN_NULL(name) if (name == NULL) printf("LIBGL: warning, " #name " is NULL\n"); 6 | #define LOAD_EGL(type, name, args...) \ 7 | typedef type (*eglptr_##name)(args); \ 8 | static eglptr_##name egl_##name; \ 9 | if (egl##name == NULL) { \ 10 | if (egl_lib == NULL) { \ 11 | egl_lib = dlopen("libEGL.so", RTLD_LOCAL | RTLD_LAZY); \ 12 | WARN_NULL(egl_lib); \ 13 | } \ 14 | egl_##name = (eglptr_##name)dlsym(egl_lib, #name); \ 15 | WARN_NULL(egl_lib_##name); \ 16 | } \ 17 | {% endblock %} 18 | 19 | {% block load %} 20 | LOAD_EGL({{ func.return }}, {{ func.name }} 21 | {%- if func.args %}, {{ func.args|args }}{% endif %}); 22 | {% endblock %} 23 | {% block prefix %}egl{% endblock %} 24 | -------------------------------------------------------------------------------- /spec/template/gleswrap.c.j2: -------------------------------------------------------------------------------- 1 | {% extends "base/wrap.c.j2" %} 2 | {% block headers %} 3 | {{ super() }} 4 | 5 | {% endblock %} 6 | {% block content %} 7 | {% include "base/packed_call.j2" %} 8 | 9 | /* 10 | {% include "base/copy_packed_call.j2" %} 11 | */ 12 | 13 | {% endblock %} 14 | 15 | {% block definition %} 16 | #ifndef skip_{{ func.name }} 17 | {{ super() -}} 18 | #endif 19 | {% endblock %} 20 | {% block load %} 21 | {{ func.loadlib }}({{ func.name }}); 22 | {% endblock %} 23 | {% block call %} 24 | #ifndef direct_{{ func.name }} 25 | PUSH_IF_COMPILING({{ func.name }}) 26 | #endif 27 | {{ super() }} 28 | {% endblock %} 29 | {% block prefix %}gles{% endblock %} 30 | -------------------------------------------------------------------------------- /spec/template/glextwrap.c.j2: -------------------------------------------------------------------------------- 1 | {% extends "base/wrap.c.j2" %} 2 | {% block headers %} 3 | {{ super() }} 4 | 5 | {% endblock %} 6 | {% block definition %} 7 | #ifndef skip_{{ func.name }} 8 | {{ super() -}} 9 | #endif 10 | {% endblock %} 11 | {% block load %} 12 | {{ func.loadlib }}({{ func.name }}); 13 | {% endblock %} 14 | {% block call %} 15 | #ifndef direct_{{ func.name }} 16 | PUSH_IF_COMPILING({{ func.name }}) 17 | #endif 18 | {{ super() }} 19 | {% endblock %} 20 | {% block prefix %}gles{% endblock %} 21 | -------------------------------------------------------------------------------- /spec/template/glwrap.h.j2: -------------------------------------------------------------------------------- 1 | {% extends "base/wrap.h.j2" %} 2 | {% block content %} 3 | {{ super() }} 4 | 5 | {% for func in functions %} 6 | #ifndef direct_{{ func.name }} 7 | #define push_{{ func.name }}({{ func.args|args(0) }}) { \ 8 | {{ func.name }}_PACKED *packed_data = malloc(sizeof({{ func.name }}_PACKED)); \ 9 | packed_data->format = {{ func.name }}_FORMAT; \ 10 | packed_data->func = gl4es_{{ func.name }}; \ 11 | {% if func.args %} 12 | {% for arg in func.args %} 13 | packed_data->args.a{{ loop.index }} = ({{ arg.type|unconst }}){{ arg.name }}; \ 14 | {% endfor %} 15 | {% endif %} 16 | glPushCall((void *)packed_data); \ 17 | } 18 | #endif 19 | {% endfor %} 20 | {% endblock %} -------------------------------------------------------------------------------- /spec/template/glxfuncs.j2: -------------------------------------------------------------------------------- 1 | {% for func in functions %} 2 | _EX({{ func.name }}); 3 | {% endfor %} 4 | -------------------------------------------------------------------------------- /spec/template/host.c.j2: -------------------------------------------------------------------------------- 1 | {% extends "base/header.j2" %} 2 | 3 | {% block content %} 4 | {% include "base/indexed_call.j2" %} 5 | 6 | {% endblock %} 7 | -------------------------------------------------------------------------------- /spec/template/proxy.h.j2: -------------------------------------------------------------------------------- 1 | {% extends "base/wrap.h.j2" %} 2 | -------------------------------------------------------------------------------- /spec/xml/toyml.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from collections import defaultdict 3 | import re 4 | import xml.etree.ElementTree as ET 5 | import yaml 6 | 7 | 8 | def etna_to_yml(xml): 9 | defs = xml.find('functions') 10 | functions = defaultdict(dict) 11 | for f in defs.findall('function'): 12 | name = f.get('name') 13 | ret = f.find('return') 14 | if ret is not None: 15 | ret = ret.get('type') 16 | if ret is None: 17 | ret = 'void' 18 | 19 | params = [] 20 | for p in f.findall('param'): 21 | params.append('{} {}'.format(p.get('type'), p.get('name'))) 22 | 23 | functions[name] = [ret] + params 24 | 25 | return functions 26 | 27 | 28 | def lua_to_yml(xml): 29 | typemap = xml.find('typemap') 30 | types = {} 31 | for t in typemap: 32 | name = t.get('typename') 33 | types[name] = t.get('C-lang', name) 34 | 35 | defs = xml.find('functions').find('function-defs') 36 | functions = defaultdict(dict) 37 | for f in defs.findall('function'): 38 | cat = f.get('category') 39 | ret = f.get('return') 40 | ret = types.get(ret, ret) 41 | func = f.get('name') 42 | 43 | params = [] 44 | for param in f.findall('param'): 45 | typ = param.get('type') 46 | typ = types.get(typ, typ) 47 | name = param.get('name') 48 | kind = param.get('kind') 49 | if kind in ('array', 'reference', 'array[size]'): 50 | typ = typ.rstrip() 51 | if not typ.endswith('*') or kind == 'reference': 52 | typ += ' *' 53 | if not 'const' in typ and param.get('input', 'false') == 'true': 54 | typ = 'const ' + typ 55 | p = '{} {}'.format(typ, name) 56 | p = p.replace('* ', '*') 57 | params.append(p) 58 | 59 | args = [ret] 60 | args.extend(params) 61 | functions[cat][func] = args 62 | return functions 63 | 64 | 65 | def khronos_to_yml(xml): 66 | def extract(node): 67 | return node.findtext('ptype') or node.text, node.findtext('name') 68 | 69 | def clean(s): 70 | return re.sub('\s+', ' ', s).strip() 71 | 72 | defs = xml.find('commands') 73 | functions = defaultdict(dict) 74 | for f in defs.findall('command'): 75 | proto = f.find('proto') 76 | ret, name = extract(proto) 77 | params = [] 78 | for param in f.findall('param'): 79 | params.append(clean(' '.join((param.itertext())))) 80 | 81 | functions[name] = [ret] + params 82 | return functions 83 | 84 | 85 | def to_yml(filename): 86 | with open(filename, 'r') as f: 87 | data = f.read() 88 | 89 | data = re.sub(' xmlns="[^"]+"', '', data, count=1) 90 | xml = ET.fromstring(data) 91 | 92 | if xml.tag == 'root': 93 | functions = etna_to_yml(xml) 94 | elif xml.tag == 'specification': 95 | functions = lua_to_yml(xml) 96 | elif xml.tag == 'registry': 97 | functions = khronos_to_yml(xml) 98 | else: 99 | print 'unrecognized root tag:', xml.tag 100 | 101 | yml = yaml.dump(dict(functions)) 102 | with open(filename.replace('xml', 'yml'), 'w') as o: 103 | o.write(yml) 104 | 105 | if __name__ == '__main__': 106 | import sys 107 | if len(sys.argv) < 2: 108 | print 'Usage: {} [file.xml...]'.format(sys.argv[0]) 109 | sys.exit(1) 110 | 111 | for name in sys.argv[1:]: 112 | to_yml(name) 113 | -------------------------------------------------------------------------------- /spec/yml/glext-1.1.yml: -------------------------------------------------------------------------------- 1 | #GLES 1.1 Extensions (might be GLES 2.0 Core) 2 | glBlendColor_OES_: [void, GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha] 3 | glBlendEquation_OES_: [void, GLenum mode] 4 | glBlendEquationSeparate_OES_: [void, GLenum modeRGB, GLenum modeA] 5 | glBlendFuncSeparate_OES_: [void, GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha] 6 | # glTexGenfOES_OES_: [void, GLenum coord, GLenum pname, GLfloat param] 7 | glTexGenfv_OES_: [void, GLenum coord, GLenum pname, "const GLfloat *params"] 8 | glTexGeni_OES_: [void, GLenum coord, GLenum pname, GLint param] 9 | # glTexGenivOES_OES_: [void, GLenum coord, GLenum pname, "const GLint *params"] 10 | 11 | glGenFramebuffers_OES_: [void, GLsizei n, "GLuint *ids"] 12 | glDeleteFramebuffers_OES_: [void, GLsizei n, "GLuint *framebuffers"] 13 | glIsFramebuffer_OES_: [GLboolean, GLuint framebuffer] 14 | glCheckFramebufferStatus_OES_: [GLenum, GLenum target] 15 | glBindFramebuffer_OES_: [void, GLenum target, GLuint framebuffer] 16 | glFramebufferTexture2D_OES_: [void, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level] 17 | glGenRenderbuffers_OES_: [void, GLsizei n, "GLuint *renderbuffers"] 18 | glFramebufferRenderbuffer_OES_: [void, GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer] 19 | glDeleteRenderbuffers_OES_: [void, GLsizei n, "GLuint *renderbuffers"] 20 | glRenderbufferStorage_OES_: [void, GLenum target, GLenum internalformat, GLsizei width, GLsizei height] 21 | glBindRenderbuffer_OES_: [void, GLenum target, GLuint renderbuffer] 22 | glIsRenderbuffer_OES_: [GLboolean, GLuint renderbuffer] 23 | glGenerateMipmap_OES_: [void, GLenum target] 24 | glGetFramebufferAttachmentParameteriv_OES_: [void, GLenum target, GLenum attachment, GLenum pname, "GLint *params"] 25 | glGetRenderbufferParameteriv_OES_: [void, GLenum target, GLenum pname, "GLint * params"] 26 | 27 | glDrawTexi_OES_: [void, GLint x, GLint y, GLint z, GLint width, GLint height] 28 | glDrawTexf_OES_: [void, GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height] 29 | 30 | glMultiDrawArrays_OES_: [void, GLenum mode, "const GLint *first", "const GLsizei *count", GLsizei primcount] 31 | glMultiDrawElements_OES_: [void, GLenum mode, "GLsizei *count", GLenum type, "const void * const *indices", GLsizei primcount] 32 | 33 | glGetProgramBinary_OES_ : [void, GLuint program, GLsizei bufSize, "GLsizei *length", "GLenum *binaryFormat", "GLvoid *binary"] 34 | glProgramBinary_OES_ : [void, GLuint program, GLenum binaryFormat, "const GLvoid *binary", GLint length] 35 | 36 | glDrawBuffers_EXT_ : [void, GLsizei n, "const GLenum *bufs"] -------------------------------------------------------------------------------- /spec/yml/glx.yml: -------------------------------------------------------------------------------- 1 | glx: 2 | glXBindHyperpipeSGIX: [int, Display *dpy, int hpId] 3 | glXBindSwapBarrierSGIX: [void, uint32_t window, uint32_t barrier] 4 | glXChangeDrawableAttributes: [void, uint32_t drawable] 5 | glXChangeDrawableAttributesSGIX: [void, uint32_t drawable] 6 | glXClientInfo: [void] 7 | glXCopyContext: [void, uint32_t source, uint32_t dest, uint32_t mask] 8 | glXCreateContext: [void, uint32_t gc_id, uint32_t screen, uint32_t visual, uint32_t 9 | share_list] 10 | glXCreateContextWithConfigSGIX: [void, uint32_t gc_id, uint32_t screen, uint32_t 11 | config, uint32_t share_list] 12 | glXCreateGLXPbufferSGIX: [void, uint32_t config, uint32_t pbuffer] 13 | glXCreateGLXPixmap: [void, uint32_t visual, uint32_t pixmap, uint32_t glxpixmap] 14 | glXCreateGLXPixmapWithConfigSGIX: [void, uint32_t config, uint32_t pixmap, uint32_t 15 | glxpixmap] 16 | glXCreateGLXVideoSourceSGIX: [void, uint32_t dpy, uint32_t screen, uint32_t server, 17 | uint32_t path, uint32_t class, uint32_t node] 18 | glXCreateNewContext: [void, uint32_t config, uint32_t render_type, uint32_t share_list, 19 | uint32_t direct] 20 | glXCreatePbuffer: [void, uint32_t config, uint32_t pbuffer] 21 | glXCreatePixmap: [void, uint32_t config, uint32_t pixmap, uint32_t glxpixmap] 22 | glXCreateWindow: [void, uint32_t config, uint32_t window, uint32_t glxwindow] 23 | glXDestroyContext: [void, uint32_t context] 24 | glXDestroyGLXPbufferSGIX: [void, uint32_t pbuffer] 25 | glXDestroyGLXPixmap: [void, uint32_t pixmap] 26 | glXDestroyGLXVideoSourceSGIX: [void, uint32_t dpy, uint32_t glxvideosource] 27 | glXDestroyHyperpipeConfigSGIX: [int, Display *dpy, int hpId] 28 | glXDestroyPbuffer: [void, uint32_t pbuffer] 29 | glXDestroyPixmap: [void, uint32_t glxpixmap] 30 | glXDestroyWindow: [void, uint32_t glxwindow] 31 | glXGetDrawableAttributes: [void, uint32_t drawable] 32 | glXGetDrawableAttributesSGIX: [void, uint32_t drawable] 33 | glXGetFBConfigs: [void] 34 | glXGetFBConfigsSGIX: [void] 35 | glXGetVisualConfigs: [void] 36 | glXHyperpipeAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, int size, 37 | const void *attribList] 38 | glXHyperpipeConfigSGIX: [int, Display *dpy, int networkId, int npipes, GLXHyperpipeConfigSGIX 39 | cfg, int *hpId] 40 | glXIsDirect: [void, uint32_t dpy, uint32_t context] 41 | glXJoinSwapGroupSGIX: [void, uint32_t window, uint32_t group] 42 | glXMakeContextCurrent: [void, uint32_t drawable, uint32_t readdrawable, uint32_t 43 | context] 44 | glXMakeCurrent: [void, uint32_t drawable, uint32_t context] 45 | glXMakeCurrentReadSGI: [void, uint32_t drawable, uint32_t readdrawable, uint32_t 46 | context] 47 | glXQueryContext: [void] 48 | glXQueryContextInfoEXT: [void] 49 | glXQueryExtensionsString: [void, uint32_t screen] 50 | glXQueryHyperpipeAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, int 51 | size, const void *returnAttribList] 52 | glXQueryHyperpipeBestAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, 53 | int size, const void *attribList, void *returnAttribList] 54 | glXQueryHyperpipeConfigSGIX: [GLXHyperpipeConfigSGIX *, Display *dpy, int hpId, 55 | int *npipes] 56 | glXQueryHyperpipeNetworkSGIX: [GLXHyperpipeNetworkSGIX *, Display *dpy, int *npipes] 57 | glXQueryMaxSwapBarriersSGIX: [void] 58 | glXQueryServerString: [void, uint32_t screen, uint32_t name] 59 | glXQueryVersion: [void, uint32_t *major, uint32_t *minor] 60 | glXRender: [void] 61 | glXRenderLarge: [void] 62 | glXSwapBuffers: [void, uint32_t drawable] 63 | glXSwapIntervalSGI: [void] 64 | glXUseXFont: [void, uint32_t font, uint32_t first, uint32_t count, uint32_t list_base] 65 | glXVendorPrivate: [void] 66 | glXVendorPrivateWithReply: [void] 67 | glXWaitGL: [void, uint32_t context] 68 | glXWaitX: [void] 69 | -------------------------------------------------------------------------------- /spec/yml/my_glx.yml: -------------------------------------------------------------------------------- 1 | glx: 2 | glXChooseVisual: [XVisualInfo *, Display *dpy, int screen, int *attribList] 3 | glXBindHyperpipeSGIX: [int, Display *dpy, int hpId] 4 | glXBindSwapBarrierSGIX: [void, uint32_t window, uint32_t barrier] 5 | glXChangeDrawableAttributes: [void, uint32_t drawable] 6 | glXChangeDrawableAttributesSGIX: [void, uint32_t drawable] 7 | glXClientInfo: [void] 8 | glXCopyContext: [void, Display *dpy, GLXContext src, GLXContext dst, unsigned long mask] 9 | glXCreateContext: [GLXContext, Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct] 10 | glXCreateContextAttribsARB: [GLXContext, Display *display, void *config, GLXContext share_context, Bool direct, const int *attrib_list] 11 | glXCreateContextWithConfigSGIX: [void, uint32_t gc_id, uint32_t screen, uint32_t 12 | config, uint32_t share_list] 13 | glXCreateGLXPbufferSGIX: [void, uint32_t config, uint32_t pbuffer] 14 | glXCreateGLXPixmap: [GLXPixmap, Display *dpy, XVisualInfo *visual, Pixmap pixmap] 15 | glXCreateGLXPixmapWithConfigSGIX: [void, uint32_t config, uint32_t pixmap, uint32_t 16 | glxpixmap] 17 | glXCreateGLXVideoSourceSGIX: [void, Display *dpy, uint32_t screen, uint32_t server, 18 | uint32_t path, uint32_t class, uint32_t node] 19 | glXCreateNewContext: [void, uint32_t config, uint32_t render_type, uint32_t share_list, 20 | uint32_t direct] 21 | glXCreatePbuffer: [void, uint32_t config, uint32_t pbuffer] 22 | glXCreatePixmap: [void, uint32_t config, uint32_t pixmap, uint32_t glxpixmap] 23 | glXCreateWindow: [void, uint32_t config, uint32_t window, uint32_t glxwindow] 24 | glXDestroyContext: [void, Display *dpy, GLXContext ctx] 25 | glXDestroyGLXPbufferSGIX: [void, uint32_t pbuffer] 26 | glXDestroyGLXPixmap: [void, Display *dpy, GLXPixmap pixmap] 27 | glXDestroyGLXVideoSourceSGIX: [void, Display *dpy, uint32_t glxvideosource] 28 | glXDestroyHyperpipeConfigSGIX: [int, Display *dpy, int hpId] 29 | glXDestroyPbuffer: [void, uint32_t pbuffer] 30 | glXDestroyPixmap: [void, uint32_t glxpixmap] 31 | glXDestroyWindow: [void, uint32_t glxwindow] 32 | glXGetDrawableAttributes: [void, uint32_t drawable] 33 | glXGetDrawableAttributesSGIX: [void, uint32_t drawable] 34 | glXGetClientString: [const char *, Display *display, int name] 35 | glXGetCurrentContext: [GLXContext] 36 | glXGetCurrentDrawable: [GLXDrawable] 37 | glXGetConfig: [int, Display *display, XVisualInfo *visual, int attribute, int *value] 38 | glXGetFBConfigs: [void] 39 | glXGetFBConfigsSGIX: [void] 40 | glXGetVisualConfigs: [void] 41 | glXHyperpipeAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, int size, 42 | const void *attribList] 43 | glXHyperpipeConfigSGIX: [int, Display *dpy, int networkId, int npipes, GLXHyperpipeConfigSGIX 44 | cfg, int *hpId] 45 | glXIsDirect: [Bool, Display *dpy, GLXContext ctx] 46 | glXJoinSwapGroupSGIX: [void, uint32_t window, uint32_t group] 47 | glXMakeContextCurrent: [void, uint32_t drawable, uint32_t readdrawable, uint32_t 48 | context] 49 | glXMakeCurrent: [Bool, Display *dpy, GLXDrawable drawable, GLXContext ctx] 50 | glXMakeCurrentReadSGI: [void, uint32_t drawable, uint32_t readdrawable, uint32_t 51 | context] 52 | glXQueryContext: [void] 53 | glXQueryContextInfoEXT: [void] 54 | glXQueryExtension: [Bool, Display *display, int *errorBase, int *eventBase] 55 | glXQueryExtensionsString: [const char *, Display *dpy, int screen] 56 | glXQueryHyperpipeAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, int 57 | size, const void *returnAttribList] 58 | glXQueryHyperpipeBestAttribSGIX: [int, Display *dpy, int timeSlice, int attrib, 59 | int size, const void *attribList, void *returnAttribList] 60 | glXQueryHyperpipeConfigSGIX: [GLXHyperpipeConfigSGIX *, Display *dpy, int hpId, 61 | int *npipes] 62 | glXQueryHyperpipeNetworkSGIX: [GLXHyperpipeNetworkSGIX *, Display *dpy, int *npipes] 63 | glXQueryMaxSwapBarriersSGIX: [void] 64 | glXQueryServerString: [const char *, Display *dpy, int screen, int name] 65 | glXQueryVersion: [Bool, Display *dpy, int *maj, int *min] 66 | glXReleaseBuffersMESA: [Bool, Display *dpy, GLXDrawable drawable] 67 | glXRender: [void] 68 | glXRenderLarge: [void] 69 | glXSwapBuffers: [void, Display *dpy, GLXDrawable drawable] 70 | glXSwapIntervalSGI: [void, unsigned int interval] 71 | glXSwapIntervalMESA: [int, unsigned int interval] 72 | glXUseXFont: [void, Font font, int first, int count, int list] 73 | glXVendorPrivate: [void] 74 | glXVendorPrivateWithReply: [void] 75 | glXWaitGL: [void] 76 | glXWaitX: [void] 77 | -------------------------------------------------------------------------------- /src/agl/agl.c: -------------------------------------------------------------------------------- 1 | #include "agl.h" 2 | 3 | #include 4 | #include 5 | #include 6 | //#include 7 | #undef __USE_INLINE__ 8 | #include 9 | #include 10 | 11 | extern struct OGLES2IFace *IOGLES2; 12 | 13 | void* NewGLState(void* shared_glstate, int es2only); 14 | void DeleteGLState(void* oldstate); 15 | void ActivateGLState(void* new_glstate); 16 | void GetHardwareExtensions(int notest); 17 | 18 | typedef struct _agl_ctx_glstate { 19 | void* context; 20 | void* glstate; 21 | } agl_ctx_glstate; 22 | 23 | static agl_ctx_glstate *agl_context = NULL; 24 | static int agl_context_len = 0; 25 | static int agl_context_cap = 0; 26 | static void* agl_current_ctx = NULL; 27 | 28 | // find (or add if not found) a context in the list, and activate glstate... 29 | void agl_context_find(void* ctx) { 30 | if(!ctx) 31 | return; 32 | if(!agl_context) { 33 | agl_context_cap = 10; 34 | agl_context = (agl_ctx_glstate*)malloc(sizeof(agl_ctx_glstate)*agl_context_cap); 35 | memset(agl_context, 0, sizeof(agl_ctx_glstate)*agl_context_cap); 36 | } 37 | int idx = 0; 38 | while (idxaglCreateContext2(errcode, tags); 85 | return NULL; 86 | } 87 | void* aglCreateContext2(ULONG * errcode, struct TagItem * tags) { 88 | return aglCreateContext(errcode, tags); 89 | } 90 | /* 91 | void* VARARGS68K aglCreateContextTags(ULONG * errcode, ...) { 92 | void* ret = NULL; 93 | if(IOGLES2) { 94 | struct TagItem tags[100]; 95 | VA_LIST args; 96 | VA_START(args, errcode); 97 | int i = 0; 98 | do { 99 | struct Tagitem tag = VA_ARG(args, struct TagItem); 100 | tags[i++] = tag; 101 | } while (tag!=TAG_DONE); 102 | VA_END(args); 103 | ret = IOGLES2->aglCreateContext2(errcode, tags); 104 | } 105 | return ret; 106 | } 107 | */ 108 | void aglDestroyContext(void* context) { 109 | if(IOGLES2) { 110 | //bind the context before deleting stuffs. 111 | if(context!=agl_current_ctx) 112 | IOGLES2->aglMakeCurrent(context); 113 | 114 | agl_context_remove(context); // remove the associated glstate 115 | 116 | if(context!=agl_current_ctx) // rebind old context if needed 117 | IOGLES2->aglMakeCurrent(agl_current_ctx); 118 | IOGLES2->aglDestroyContext(context); 119 | 120 | } 121 | } 122 | 123 | void aglMakeCurrent(void* context) { 124 | agl_current_ctx = context; 125 | if(IOGLES2) { 126 | IOGLES2->aglMakeCurrent(context); 127 | 128 | if (context) 129 | agl_context_find(context); // activate (and create if needed) the correct glstate 130 | } 131 | } 132 | 133 | void aglSetParams2(struct TagItem * tags) { 134 | if(IOGLES2) { 135 | return IOGLES2->aglSetParams2(tags); 136 | } 137 | } 138 | 139 | void amiga_pre_swap(); 140 | void amiga_post_swap(); 141 | void aglSwapBuffers() { 142 | amiga_pre_swap(); 143 | // Swap the Buffers! 144 | if(IOGLES2) { 145 | IOGLES2->aglSwapBuffers(); 146 | } 147 | amiga_post_swap(); 148 | } 149 | 150 | // what is the use of this function? 151 | void aglSetBitmap(struct BitMap *bitmap) { 152 | if(IOGLES2) { 153 | IOGLES2->aglSetBitmap(bitmap); 154 | } 155 | } 156 | 157 | //void* aglGetProcAddress(const char* name); //-> declared in agl/lookup.c 158 | 159 | #ifdef GL4ES_COMPILE_FOR_USE_IN_SHARED_LIB 160 | void agl_reset_internals() { 161 | if(agl_context) { 162 | free(agl_context); 163 | agl_context=NULL; 164 | } 165 | agl_context_len=0; 166 | agl_context_cap=0; 167 | agl_current_ctx=NULL; 168 | } 169 | #endif -------------------------------------------------------------------------------- /src/agl/agl.h: -------------------------------------------------------------------------------- 1 | #ifndef _AGL_H_ 2 | #define _AGL_H_ 3 | 4 | #ifndef EXEC_TYPES_H 5 | #include 6 | #endif 7 | #ifndef EXEC_EXEC_H 8 | #include 9 | #endif 10 | #ifndef EXEC_INTERFACES_H 11 | #include 12 | #endif 13 | 14 | #ifndef GRAPHICS_GFX_H 15 | #include 16 | #endif 17 | 18 | #ifndef OGLES2_OGLES2_DEFS_H 19 | // it would be better to have an include with only the CreateContextTags enum difed, to avoid conflict 20 | // of other typedef with full OpenGL header file... 21 | //#include 22 | #endif 23 | 24 | void* aglCreateContext(ULONG * errcode, struct TagItem * tags); 25 | void* aglCreateContext2(ULONG * errcode, struct TagItem * tags); 26 | //void* aglCreateContextTags(ULONG * errcode, ...); 27 | void aglDestroyContext(void* context); 28 | void aglMakeCurrent(void* context); 29 | void aglSwapBuffers(); 30 | void aglSetParams2(struct TagItem * tags); 31 | void aglSetBitmap(struct BitMap *bitmap); 32 | void* aglGetProcAddress(const char* name); 33 | 34 | #endif //_AGL_H_ -------------------------------------------------------------------------------- /src/agl/amigaos.h: -------------------------------------------------------------------------------- 1 | #ifndef _AMIGAOS_H_ 2 | #define _AMIGAOS_H_ 3 | 4 | void* os4GetProcAddress(const char* name); 5 | 6 | void os4OpenLib(void** lib); 7 | void os4CloseLib(); 8 | 9 | #endif //_AMIGAOS_H_ -------------------------------------------------------------------------------- /src/agl/lookup.c: -------------------------------------------------------------------------------- 1 | #include "../gl/attributes.h" 2 | #include "../gl/init.h" 3 | #include "../gl/logs.h" 4 | #define STUB_FCT aglStub 5 | #include "../gl/gl_lookup.h" 6 | 7 | #include "../glx/glx.h" 8 | #include "../glx/hardext.h" 9 | 10 | void aglStub(void *x, ...) { 11 | return; 12 | } 13 | 14 | // Copy/ Paste of agl specifics function, but simplified whithout the Amiga speicifc types 15 | void* aglCreateContext(void * errcode, void * tags); 16 | void* aglCreateContext2(void * errcode, void * tags); 17 | void aglDestroyContext(void* context); 18 | void aglMakeCurrent(void* context); 19 | void aglSwapBuffers(); 20 | void aglSetParams2(void * tags); 21 | void aglSetBitmap(void * bitmap); 22 | void* aglGetProcAddress(const char* name); 23 | // TODO: something less error prone, but agl.h cannot be included here, as some Amiga header conflict with some GLES ones 24 | 25 | void *gl4es_aglGetProcAddress(const char *name) { 26 | 27 | MAP("glXSwapIntervalMESA", gl4es_glXSwapInterval); 28 | MAP("glXSwapIntervalSGI", gl4es_glXSwapInterval); 29 | _EX(aglGetProcAddress); 30 | MAP("glXGetProcAddress", gl4es_aglGetProcAddress); 31 | MAP("glXGetProcAddressARB", gl4es_aglGetProcAddress); 32 | // direct mapping 33 | MAP("aglCreateContext", aglCreateContext); 34 | MAP("aglCreateContext2", aglCreateContext2); 35 | MAP("aglDestroyContext", aglDestroyContext); 36 | MAP("aglMakeCurrent", aglMakeCurrent); 37 | MAP("aglSwapBuffers", aglSwapBuffers); 38 | MAP("aglSetParams2", aglSetParams2); 39 | MAP("aglSetBitmap", aglSetBitmap); 40 | 41 | return gl4es_GetProcAddress(name); 42 | } 43 | void* aglGetProcAddress(const char* name) AliasExport("gl4es_aglGetProcAddress"); 44 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_MAIN_CONFIG_H 2 | #define _GL4ES_MAIN_CONFIG_H 3 | 4 | #define SYS_proxy 9999 5 | #define MAX_EVAL_ORDER 30 6 | #define MAX_TEX 16 7 | #define MAX_LIGHT 8 8 | #define MAX_STACK_PROJECTION 16 9 | #define MAX_STACK_TEXTURE 16 10 | #define MAX_STACK_MODELVIEW 64 11 | #define MAX_STACK_COLOR 16 12 | #define MAX_STACK_ARB_MATRIX 8 13 | #define MAX_CLIP_PLANES 6 14 | #define MAX_VATTRIB 32 15 | #define MAX_MAP_SIZE 256 16 | #define MAX_ARB_MATRIX 8 17 | #define MAX_VTX_PROG_ENV_PARAMS 96 18 | #define MAX_VTX_PROG_LOC_PARAMS 96 19 | #define MAX_FRG_PROG_ENV_PARAMS 24 20 | #define MAX_FRG_PROG_LOC_PARAMS 24 21 | #define MAX_DRAW_BUFFERS 16 22 | 23 | #endif // _GL4ES_MAIN_CONFIG_H 24 | -------------------------------------------------------------------------------- /src/egl/egl.h: -------------------------------------------------------------------------------- 1 | #ifndef _EGL_EGL_H_ 2 | #define _EGL_EGL_H_ 3 | 4 | #ifdef NOEGL 5 | # error Building EGL wrapper without EGL 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | EGLint gl4es_eglGetError(void); 13 | EGLDisplay gl4es_eglGetDisplay(EGLNativeDisplayType display_id); 14 | EGLBoolean gl4es_eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor); 15 | EGLBoolean gl4es_eglTerminate(EGLDisplay dpy); 16 | const char * gl4es_eglQueryString(EGLDisplay dpy, EGLint name); 17 | EGLBoolean gl4es_eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config); 18 | EGLBoolean gl4es_eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config); 19 | EGLBoolean gl4es_eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value); 20 | 21 | EGLSurface gl4es_eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list); 22 | EGLSurface gl4es_eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list); 23 | EGLSurface gl4es_eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list); 24 | EGLBoolean gl4es_eglDestroySurface(EGLDisplay dpy, EGLSurface surface); 25 | EGLBoolean gl4es_eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value); 26 | EGLBoolean gl4es_eglBindAPI(EGLenum api); 27 | EGLenum gl4es_eglQueryAPI(void); 28 | 29 | EGLBoolean gl4es_eglWaitClient(void); 30 | EGLBoolean gl4es_eglReleaseThread(void); 31 | EGLSurface gl4es_eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list); 32 | EGLBoolean gl4es_eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value); 33 | EGLBoolean gl4es_eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer); 34 | EGLBoolean gl4es_eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer); 35 | EGLBoolean gl4es_eglSwapInterval(EGLDisplay dpy, EGLint interval); 36 | EGLContext gl4es_eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list); 37 | EGLBoolean gl4es_eglDestroyContext(EGLDisplay dpy, EGLContext ctx); 38 | EGLBoolean gl4es_eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx); 39 | EGLContext gl4es_eglGetCurrentContext(void); 40 | EGLSurface gl4es_eglGetCurrentSurface(EGLint readdraw); 41 | EGLDisplay gl4es_eglGetCurrentDisplay(void); 42 | EGLBoolean gl4es_eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value); 43 | EGLBoolean gl4es_eglWaitGL(void); 44 | EGLBoolean gl4es_eglWaitNative(EGLint engine); 45 | EGLBoolean gl4es_eglSwapBuffers(EGLDisplay dpy, EGLSurface surface); 46 | EGLBoolean gl4es_eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target); 47 | void* gl4es_eglGetProcAddress(const char *name); 48 | 49 | #endif // _EGL_EGL_H 50 | 51 | -------------------------------------------------------------------------------- /src/egl/lookup.c: -------------------------------------------------------------------------------- 1 | #include "../gl/attributes.h" 2 | #include "../gl/init.h" 3 | #include "../gl/logs.h" 4 | 5 | #define STUB_FCT eglStub 6 | #include "../gl/gl_lookup.h" 7 | 8 | #include "egl.h" 9 | #include "../glx/hardext.h" 10 | 11 | extern void *gl4es_glXGetProcAddress(const char *name); 12 | 13 | void glXStub(void *x, ...) { 14 | return; 15 | } 16 | 17 | void* gl4es_eglGetProcAddress(const char *name) { 18 | _EX(eglGetError); 19 | _EX(eglGetDisplay); 20 | _EX(eglInitialize); 21 | _EX(eglTerminate); 22 | _EX(eglQueryString); 23 | _EX(eglGetConfigs); 24 | _EX(eglChooseConfig); 25 | _EX(eglGetConfigAttrib); 26 | 27 | _EX(eglCreateWindowSurface); 28 | _EX(eglCreatePbufferSurface); 29 | _EX(eglCreatePixmapSurface); 30 | _EX(eglDestroySurface); 31 | _EX(eglQuerySurface); 32 | _EX(eglBindAPI); 33 | _EX(eglQueryAPI); 34 | 35 | _EX(eglWaitClient); 36 | _EX(eglReleaseThread); 37 | _EX(eglCreatePbufferFromClientBuffer); 38 | _EX(eglSurfaceAttrib); 39 | _EX(eglBindTexImage); 40 | _EX(eglReleaseTexImage); 41 | _EX(eglSwapInterval); 42 | _EX(eglCreateContext); 43 | _EX(eglDestroyContext); 44 | _EX(eglMakeCurrent); 45 | _EX(eglGetCurrentContext); 46 | _EX(eglGetCurrentSurface); 47 | _EX(eglGetCurrentDisplay); 48 | _EX(eglQueryContext); 49 | _EX(eglWaitGL); 50 | _EX(eglWaitNative); 51 | _EX(eglSwapBuffers); 52 | _EX(eglCopyBuffers); 53 | 54 | _EX(glXGetProcAddress); 55 | _ARB(glXGetProcAddress); 56 | _EX(eglGetProcAddress); 57 | 58 | return gl4es_GetProcAddress(name); 59 | } 60 | 61 | __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *name) AliasExport("gl4es_eglGetProcAddress"); 62 | 63 | -------------------------------------------------------------------------------- /src/gl/arbconverter.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_ARBCONVERTER_H_ 2 | #define _GL4ES_ARBCONVERTER_H_ 3 | 4 | #include 5 | 6 | char* gl4es_convertARB(const char* const code, int vertex, char **error_msg, int *error_ptr); 7 | 8 | #endif // _GL4ES_ARBCONVERTER_H_ 9 | -------------------------------------------------------------------------------- /src/gl/arbgenerator.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_ARBGENERATOR_H_ 2 | #define _GL4ES_ARBGENERATOR_H_ 3 | 4 | #include 5 | 6 | #include "arbhelper.h" 7 | 8 | #define APPEND_OUTPUT(str, len) \ 9 | if (appendString(curStatusPtr, str, len)) { \ 10 | FAIL("Unknown error (not enough memory?"); \ 11 | } 12 | #define APPEND_OUTPUT2(str) APPEND_OUTPUT(str, (size_t)-1) 13 | 14 | void generateVariablePre(sCurStatus *curStatusPtr, int vertex, char **error_msg, sVariable *varPtr); 15 | void generateInstruction(sCurStatus *curStatusPtr, int vertex, char **error_msg, sInstruction *instPtr); 16 | void generateVariablePst(sCurStatus *curStatusPtr, int vertex, char **error_msg, sVariable *varPtr); 17 | 18 | #endif // _GL4ES_ARBGENERATOR_H_ 19 | -------------------------------------------------------------------------------- /src/gl/arbparser.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_ARBPARSER_H_ 2 | #define _GL4ES_ARBPARSER_H_ 3 | 4 | #include 5 | 6 | #include "arbhelper.h" 7 | 8 | struct sSpecialCases { 9 | int hasFogFragCoord; 10 | int isDepthReplacing; 11 | }; 12 | 13 | eToken readNextToken(sCurStatus* curStatus); 14 | void parseToken(sCurStatus *curStatus, int vertex, char **error_msg, struct sSpecialCases *hasFogFragCoord); 15 | 16 | #endif // _GL4ES_ARBPARSER_H_ 17 | -------------------------------------------------------------------------------- /src/gl/array.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_ARRAY_H_ 2 | #define _GL4ES_ARRAY_H_ 3 | 4 | #include "buffers.h" 5 | #include "gles.h" 6 | 7 | GLvoid *copy_gl_array(const GLvoid *src, 8 | GLenum from, GLsizei width, GLsizei stride, 9 | GLenum to, GLsizei to_width, GLsizei skip, GLsizei count, void* dst); 10 | 11 | GLvoid *copy_gl_array_convert(const GLvoid *src, 12 | GLenum from, GLsizei width, GLsizei stride, 13 | GLenum to, GLsizei to_width, GLsizei skip, GLsizei count, GLvoid* filler, void* dst); 14 | 15 | GLvoid *copy_gl_pointer(vertexattrib_t *ptr, GLsizei width, GLsizei skip, GLsizei count); 16 | GLvoid *copy_gl_pointer_color(vertexattrib_t *ptr, GLsizei width, GLsizei skip, GLsizei count); 17 | GLvoid *copy_gl_pointer_color_bgra(const void *ptr, GLint stride, GLsizei width, GLsizei skip, GLsizei count); 18 | GLvoid *copy_gl_pointer_bytecolor(vertexattrib_t *ptr, GLsizei width, GLsizei skip, GLsizei count); 19 | GLvoid *copy_gl_pointer_raw(vertexattrib_t *ptr, GLsizei width, GLsizei skip, GLsizei count); 20 | GLvoid *copy_gl_pointer_tex(vertexattrib_t *ptr, GLsizei width, GLsizei skip, GLsizei count); 21 | void copy_gl_pointer_noalloc(void* dest, vertexattrib_t *ptr, GLsizei width, GLsizei skip, GLsizei count); 22 | void copy_gl_pointer_color_noalloc(void* dest, vertexattrib_t *ptr, GLsizei width, GLsizei skip, GLsizei count); 23 | void copy_gl_pointer_color_bgra_noalloc(void* dest, const void *ptr, GLint stride, GLsizei width, GLsizei skip, GLsizei count); 24 | void copy_gl_pointer_bytecolor_noalloc(void* dest, vertexattrib_t *ptr, GLsizei width, GLsizei skip, GLsizei count); 25 | void copy_gl_pointer_raw_noalloc(void* dest, vertexattrib_t *ptr, GLsizei width, GLsizei skip, GLsizei count); 26 | void copy_gl_pointer_tex_noalloc(void* dest, vertexattrib_t *ptr, GLsizei width, GLsizei skip, GLsizei count); 27 | GLfloat *gl_pointer_index(vertexattrib_t *ptr, GLint index); 28 | void normalize_indices_us(GLushort *indices, GLsizei *max, GLsizei *min, GLsizei count); 29 | void getminmax_indices_us(const GLushort *indices, GLsizei *max, GLsizei *min, GLsizei count); 30 | void normalize_indices_ui(GLuint *indices, GLsizei *max, GLsizei *min, GLsizei count); 31 | void getminmax_indices_ui(const GLuint *indices, GLsizei *max, GLsizei *min, GLsizei count); 32 | 33 | GLfloat *copy_eval_double1(GLenum target, GLint ustride, GLint uorder, const GLdouble *points); 34 | GLfloat *copy_eval_float1(GLenum target, GLint ustride, GLint uorder, const GLfloat *points); 35 | GLfloat *copy_eval_double2(GLenum target, GLint ustride, GLint uorder, GLint vstride, GLint vorder, const GLdouble *points); 36 | GLfloat *copy_eval_float2(GLenum target, GLint ustride, GLint uorder, GLint vstride, GLint vorder, const GLfloat *points); 37 | 38 | #endif // _GL4ES_ARRAY_H_ 39 | -------------------------------------------------------------------------------- /src/gl/blend.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_BLEND_H_ 2 | #define _GL4ES_BLEND_H_ 3 | 4 | #include "gles.h" 5 | 6 | void APIENTRY_GL4ES gl4es_glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); 7 | void APIENTRY_GL4ES gl4es_glBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); 8 | void APIENTRY_GL4ES gl4es_glBlendEquationSeparate(GLenum modeRGB, GLenum modeA); 9 | void APIENTRY_GL4ES gl4es_glBlendFunc(GLenum sfactor, GLenum dfactor); 10 | void APIENTRY_GL4ES gl4es_glBlendEquation(GLenum mode); 11 | 12 | #endif //_GL4ES_BLEND_H_ 13 | -------------------------------------------------------------------------------- /src/gl/blit.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_BLIT_H_ 2 | #define _GL4ES_BLIT_H_ 3 | 4 | #include "gles.h" 5 | 6 | #define BLIT_ALPHA 0 7 | #define BLIT_OPAQUE 1 8 | #define BLIT_COLOR 2 9 | 10 | void gl4es_blitTexture(GLuint texture, 11 | GLfloat sx, GLfloat sy, 12 | GLfloat width, GLfloat height, 13 | GLfloat nwidth, GLfloat nheight, 14 | GLfloat zoomx, GLfloat zoomy, 15 | GLfloat vpwidth, GLfloat vpheight, 16 | GLfloat x, GLfloat y, GLint mode); 17 | 18 | #endif // _GL4ES_BLIT_H_ 19 | -------------------------------------------------------------------------------- /src/gl/build_info.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "build_info.h" 3 | #include "logs.h" 4 | #include "../../version.h" 5 | 6 | void print_build_infos() 7 | { 8 | SHUT_LOGD("v%d.%d.%d built on %s %s\n", MAJOR, MINOR, REVISION, __DATE__, __TIME__); 9 | } 10 | -------------------------------------------------------------------------------- /src/gl/build_info.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_BUILD_INFO_H_ 2 | #define _GL4ES_BUILD_INFO_H_ 3 | 4 | void print_build_infos(); 5 | 6 | #endif // _GL4ES_BUILD_INFO_H_ 7 | -------------------------------------------------------------------------------- /src/gl/debug.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_DEBUG_H_ 2 | #define _GL4ES_DEBUG_H_ 3 | 4 | #include "gles.h" 5 | 6 | const char* PrintEnum(GLenum what); 7 | 8 | const char* PrintEGLError(int onlyerror); 9 | 10 | void CheckGLError(int fwd); 11 | 12 | #endif // _GL4ES_DEBUG_H_ 13 | -------------------------------------------------------------------------------- /src/gl/decompress.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_DECOMPRESS_H_ 2 | #define _GL4ES_DECOMPRESS_H_ 3 | 4 | #include 5 | 6 | void DecompressBlockDXT1(uint32_t x, uint32_t y, uint32_t width, 7 | const uint8_t* blockStorage, 8 | int transparent0, int* simpleAlpha, int *complexAlpha, 9 | uint32_t* image); 10 | 11 | void DecompressBlockDXT3(uint32_t x, uint32_t y, uint32_t width, 12 | const uint8_t* blockStorage, 13 | int transparent0, int* simpleAlpha, int *complexAlpha, 14 | uint32_t* image); 15 | 16 | void DecompressBlockDXT5(uint32_t x, uint32_t y, uint32_t width, 17 | const uint8_t* blockStorage, 18 | int transparent0, int* simpleAlpha, int *complexAlpha, 19 | uint32_t* image); 20 | 21 | #endif // _GL4ES_DECOMPRESS_H_ 22 | -------------------------------------------------------------------------------- /src/gl/depth.c: -------------------------------------------------------------------------------- 1 | #include "depth.h" 2 | 3 | #include "gl4es.h" 4 | #include "glstate.h" 5 | #include "loader.h" 6 | 7 | void APIENTRY_GL4ES gl4es_glDepthFunc(GLenum func) { 8 | if(glstate->list.compiling) { 9 | PUSH_IF_COMPILING(glDepthFunc); 10 | } 11 | noerrorShim(); 12 | if (glstate->depth.func == func) 13 | return; 14 | FLUSH_BEGINEND; 15 | glstate->depth.func = func; 16 | LOAD_GLES(glDepthFunc); 17 | errorGL(); 18 | gles_glDepthFunc(func); 19 | } 20 | 21 | void APIENTRY_GL4ES gl4es_glDepthMask(GLboolean flag) { 22 | if(glstate->list.compiling) { 23 | PUSH_IF_COMPILING(glDepthMask); 24 | } 25 | noerrorShim(); 26 | if (glstate->depth.mask == flag) 27 | return; 28 | FLUSH_BEGINEND; 29 | glstate->depth.mask = flag; 30 | LOAD_GLES(glDepthMask); 31 | errorGL(); 32 | gles_glDepthMask(flag); 33 | } 34 | 35 | GLfloat clamp(GLfloat a) { 36 | return (a<0.f)?0.f:((a>1.f)?1.f:a); 37 | } 38 | 39 | void APIENTRY_GL4ES gl4es_glDepthRangef(GLclampf Near, GLclampf Far) { 40 | Near = clamp(Near); 41 | Far = clamp(Far); 42 | if(glstate->list.compiling) { 43 | PUSH_IF_COMPILING(glDepthRangef); 44 | } 45 | noerrorShim(); 46 | if ((glstate->depth.Near == Near) && (glstate->depth.Far == Far)) 47 | return; 48 | FLUSH_BEGINEND; 49 | glstate->depth.Near = Near; 50 | glstate->depth.Far = Far; 51 | LOAD_GLES(glDepthRangef); 52 | errorGL(); 53 | gles_glDepthRangef(Near, Far); 54 | } 55 | 56 | void APIENTRY_GL4ES gl4es_glClearDepthf(GLclampf depth) { 57 | depth = clamp(depth); 58 | if(glstate->list.compiling) { 59 | PUSH_IF_COMPILING(glClearDepthf); 60 | } 61 | noerrorShim(); 62 | glstate->depth.clear = depth; 63 | LOAD_GLES(glClearDepthf); 64 | errorGL(); 65 | gles_glClearDepthf(depth); 66 | } 67 | 68 | AliasExport(void,glDepthFunc,,(GLenum func)); 69 | AliasExport(void,glDepthMask,,(GLboolean flag)); 70 | AliasExport(void,glDepthRangef,,(GLclampf nearVal, GLclampf farVal)); 71 | 72 | -------------------------------------------------------------------------------- /src/gl/depth.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_DEPTH_H_ 2 | #define _GL4ES_DEPTH_H_ 3 | 4 | #include "gles.h" 5 | 6 | void APIENTRY_GL4ES gl4es_glDepthFunc(GLenum func); 7 | void APIENTRY_GL4ES gl4es_glDepthMask(GLboolean flag); 8 | void APIENTRY_GL4ES gl4es_glDepthRangef(GLclampf nearVal, GLclampf farVal); 9 | void APIENTRY_GL4ES gl4es_glClearDepthf(GLclampf depth); 10 | 11 | #endif // _GL4ES_DEPTH_H_ 12 | -------------------------------------------------------------------------------- /src/gl/enum_info.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_ENUM_INFO_H 2 | #define _GL4ES_ENUM_INFO_H 3 | 4 | #include 5 | 6 | #include "const.h" 7 | #include "debug.h" 8 | #include "logs.h" 9 | 10 | static const GLsizei gl_sizeof(GLenum type) { 11 | // types 12 | switch (type) { 13 | case GL_DOUBLE: 14 | return 8; 15 | case GL_FLOAT: 16 | case GL_INT: 17 | case GL_UNSIGNED_INT: 18 | case GL_UNSIGNED_INT_10_10_10_2: 19 | case GL_UNSIGNED_INT_2_10_10_10_REV: 20 | case GL_UNSIGNED_INT_8_8_8_8: 21 | case GL_UNSIGNED_INT_8_8_8_8_REV: 22 | case GL_UNSIGNED_INT_24_8: 23 | case GL_4_BYTES: 24 | return 4; 25 | case GL_3_BYTES: 26 | return 3; 27 | case GL_LUMINANCE_ALPHA: 28 | case GL_SHORT: 29 | case GL_HALF_FLOAT: 30 | case GL_HALF_FLOAT_OES: 31 | case GL_UNSIGNED_SHORT: 32 | case GL_UNSIGNED_SHORT_1_5_5_5_REV: 33 | case GL_UNSIGNED_SHORT_4_4_4_4: 34 | case GL_UNSIGNED_SHORT_4_4_4_4_REV: 35 | case GL_UNSIGNED_SHORT_5_5_5_1: 36 | case GL_UNSIGNED_SHORT_5_6_5: 37 | case GL_UNSIGNED_SHORT_5_6_5_REV: 38 | case GL_2_BYTES: 39 | return 2; 40 | case GL_ALPHA: 41 | case GL_LUMINANCE: 42 | case GL_BYTE: 43 | case GL_UNSIGNED_BYTE: 44 | case GL_UNSIGNED_BYTE_2_3_3_REV: 45 | case GL_UNSIGNED_BYTE_3_3_2: 46 | case GL_DEPTH_COMPONENT: 47 | case GL_COLOR_INDEX: 48 | return 1; 49 | } 50 | // formats 51 | LOGD("Unsupported pixel data type: %s\n", PrintEnum(type)); 52 | return 0; 53 | } 54 | 55 | static const GLuint gl_max_value(GLenum type) { 56 | switch (type) { 57 | // float/double only make sense on tex/color 58 | // be careful about using this 59 | case GL_DOUBLE: 60 | case GL_FLOAT: 61 | case GL_HALF_FLOAT: 62 | case GL_HALF_FLOAT_OES: 63 | return 1; 64 | case GL_BYTE: return 127; 65 | case GL_UNSIGNED_BYTE: return 255; 66 | case GL_SHORT: return 32767; 67 | case GL_UNSIGNED_SHORT: return 65535; 68 | case GL_INT: return 2147483647; 69 | case GL_UNSIGNED_INT: return 4294967295; 70 | } 71 | LOGD("unknown gl max value type: %s\n", PrintEnum(type)); 72 | return 0; 73 | } 74 | 75 | static const GLboolean is_type_packed(GLenum type) { 76 | switch (type) { 77 | case GL_4_BYTES: 78 | case GL_3_BYTES: 79 | case GL_2_BYTES: 80 | case GL_UNSIGNED_BYTE_2_3_3_REV: 81 | case GL_UNSIGNED_BYTE_3_3_2: 82 | case GL_UNSIGNED_INT_10_10_10_2: 83 | case GL_UNSIGNED_INT_2_10_10_10_REV: 84 | case GL_UNSIGNED_INT_8_8_8_8: 85 | case GL_UNSIGNED_INT_8_8_8_8_REV: 86 | case GL_UNSIGNED_SHORT_1_5_5_5_REV: 87 | case GL_UNSIGNED_SHORT_4_4_4_4: 88 | case GL_UNSIGNED_SHORT_4_4_4_4_REV: 89 | case GL_UNSIGNED_SHORT_5_5_5_1: 90 | case GL_UNSIGNED_SHORT_5_6_5: 91 | case GL_UNSIGNED_SHORT_5_6_5_REV: 92 | case GL_DEPTH_STENCIL: 93 | return true; 94 | } 95 | return false; 96 | } 97 | 98 | static const GLsizei pixel_sizeof(GLenum format, GLenum type) { 99 | GLsizei width = 0; 100 | switch (format) { 101 | case GL_RED: 102 | case GL_ALPHA: 103 | case GL_LUMINANCE: 104 | case GL_DEPTH_COMPONENT: 105 | case GL_DEPTH_STENCIL: 106 | case GL_COLOR_INDEX: 107 | width = 1; 108 | break; 109 | case GL_RG: 110 | case GL_LUMINANCE_ALPHA: 111 | width = 2; 112 | break; 113 | case GL_RGB: 114 | case GL_BGR: 115 | case GL_RGB8: 116 | width = 3; 117 | break; 118 | case GL_RGBA: 119 | case GL_BGRA: 120 | case GL_RGBA8: 121 | width = 4; 122 | break; 123 | default: 124 | LOGD("unsupported pixel format %s\n", PrintEnum(format)); 125 | return 0; 126 | } 127 | 128 | if (is_type_packed(type)) 129 | width = 1; 130 | 131 | return width * gl_sizeof(type); 132 | } 133 | 134 | static const GLboolean pixel_hasalpha(GLenum format) { 135 | switch (format) { 136 | case GL_ALPHA: 137 | case GL_LUMINANCE_ALPHA: 138 | case GL_RGBA: 139 | case GL_BGRA: 140 | case GL_RGBA8: 141 | case GL_COLOR_INDEX: 142 | return true; 143 | case GL_RED: 144 | case GL_LUMINANCE: 145 | case GL_RG: 146 | case GL_RGB: 147 | case GL_BGR: 148 | case GL_RGB8: 149 | case GL_DEPTH_COMPONENT: 150 | case GL_DEPTH_STENCIL: 151 | return false; 152 | default: 153 | return true; 154 | } 155 | } 156 | 157 | static inline const GLboolean valid_vertex_type(GLenum type) { 158 | switch (type) { 159 | case GL_UNSIGNED_BYTE: 160 | case GL_BYTE: 161 | case GL_FIXED: 162 | case GL_FLOAT: 163 | case GL_SHORT: 164 | return true; 165 | default: 166 | return false; 167 | } 168 | } 169 | 170 | #endif // _GL4ES_ENUM_INFO_H -------------------------------------------------------------------------------- /src/gl/envvars.c: -------------------------------------------------------------------------------- 1 | #include "envvars.h" 2 | #include 3 | #include 4 | #include 5 | //---------------------------------------------------------------------------- 6 | const char* GetEnvVar(const char *name) 7 | { 8 | return getenv(name); 9 | } 10 | //---------------------------------------------------------------------------- 11 | int HasEnvVar(const char *name) 12 | { 13 | return GetEnvVar(name)!=NULL; 14 | } 15 | //---------------------------------------------------------------------------- 16 | int ReturnEnvVarInt(const char *name) 17 | { 18 | const char *s=GetEnvVar(name); 19 | return s ? atoi(s) : 0; 20 | } 21 | //---------------------------------------------------------------------------- 22 | int ReturnEnvVarIntDef(const char *name,int def) 23 | { 24 | const char *s=GetEnvVar(name); 25 | return s ? atoi(s) : def; 26 | } 27 | //---------------------------------------------------------------------------- 28 | int IsEnvVarTrue(const char *name) 29 | { 30 | const char *s=GetEnvVar(name); 31 | return s && atoi(s)!=0; 32 | } 33 | //---------------------------------------------------------------------------- 34 | int IsEnvVarFalse(const char *name) 35 | { 36 | const char *s=GetEnvVar(name); 37 | return s && *s=='0'; 38 | } 39 | //---------------------------------------------------------------------------- 40 | int IsEnvVarInt(const char *name,int i) 41 | { 42 | const char *s=GetEnvVar(name); 43 | return s && atoi(s)==i; 44 | } 45 | //---------------------------------------------------------------------------- 46 | int GetEnvVarInt(const char *name,int *i,int def) 47 | { 48 | const char *s=GetEnvVar(name); 49 | *i=s ? atoi(s) : def; 50 | return s!=NULL; 51 | } 52 | //---------------------------------------------------------------------------- 53 | int GetEnvVarBool(const char *name,int *b,int def) 54 | { 55 | const char *s=GetEnvVar(name); 56 | *b=s ? atoi(s) : def; 57 | if(*b) *b=1; 58 | return s!=NULL; 59 | } 60 | //---------------------------------------------------------------------------- 61 | int GetEnvVarFloat(const char *name,float *f,float def) 62 | { 63 | const char *s=GetEnvVar(name); 64 | *f=s ? atof(s) : def; 65 | return s!=NULL; 66 | } 67 | //---------------------------------------------------------------------------- 68 | int GetEnvVarFmt(const char *name,const char *fmt,...) 69 | { 70 | int cnt=0; 71 | const char *s=GetEnvVar(name); 72 | if(s) { 73 | va_list args; 74 | va_start(args,fmt); 75 | cnt=vsscanf(s,fmt,args); 76 | va_end(args); 77 | } 78 | return cnt; 79 | } 80 | //---------------------------------------------------------------------------- 81 | -------------------------------------------------------------------------------- /src/gl/envvars.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_ENVVARS_H_ 2 | #define _GL4ES_ENVVARS_H_ 3 | //---------------------------------------------------------------------------- 4 | const char* GetEnvVar(const char *name); 5 | //---------------------------------------------------------------------------- 6 | int HasEnvVar(const char *name); 7 | int ReturnEnvVarInt(const char *name); 8 | int ReturnEnvVarIntDef(const char *name,int def); 9 | //---------------------------------------------------------------------------- 10 | int IsEnvVarTrue(const char *name); 11 | int IsEnvVarFalse(const char *name); 12 | int IsEnvVarInt(const char *name,int i); 13 | //---------------------------------------------------------------------------- 14 | int GetEnvVarInt(const char *name,int *i,int def); 15 | int GetEnvVarBool(const char *name,int *b,int def); 16 | int GetEnvVarFloat(const char *name,float *f,float def); 17 | //---------------------------------------------------------------------------- 18 | int GetEnvVarFmt(const char *name,const char *fmt,...); 19 | //---------------------------------------------------------------------------- 20 | #endif 21 | -------------------------------------------------------------------------------- /src/gl/eval.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_EVAL_H_ 2 | #define _GL4ES_EVAL_H_ 3 | 4 | #include "const.h" 5 | #include "gles.h" 6 | 7 | void APIENTRY_GL4ES gl4es_glMap1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points); 8 | void APIENTRY_GL4ES gl4es_glMap1f(GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points); 9 | void APIENTRY_GL4ES gl4es_glMap2d(GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points); 10 | void APIENTRY_GL4ES gl4es_glMap2f(GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points); 11 | 12 | void APIENTRY_GL4ES gl4es_glEvalCoord1d(GLdouble u); 13 | void APIENTRY_GL4ES gl4es_glEvalCoord1f(GLfloat u); 14 | void APIENTRY_GL4ES gl4es_glEvalCoord2d(GLdouble u, GLdouble v); 15 | void APIENTRY_GL4ES gl4es_glEvalCoord2f(GLfloat u, GLfloat v); 16 | 17 | void APIENTRY_GL4ES gl4es_glEvalMesh1(GLenum mode, GLint i1, GLint i2); 18 | void APIENTRY_GL4ES gl4es_glEvalMesh2(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2); 19 | void APIENTRY_GL4ES gl4es_glEvalPoint1(GLint i); 20 | void APIENTRY_GL4ES gl4es_glEvalPoint2(GLint i, GLint j); 21 | void APIENTRY_GL4ES gl4es_glMapGrid1d(GLint un, GLdouble u1, GLdouble u2); 22 | void APIENTRY_GL4ES gl4es_glMapGrid1f(GLint un, GLfloat u1, GLfloat u2); 23 | void APIENTRY_GL4ES gl4es_glMapGrid2d(GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2); 24 | void APIENTRY_GL4ES gl4es_glMapGrid2f(GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2); 25 | void APIENTRY_GL4ES gl4es_glGetMapdv(GLenum target, GLenum query, GLdouble *v); 26 | void APIENTRY_GL4ES gl4es_glGetMapfv(GLenum target, GLenum query, GLfloat *v); 27 | void APIENTRY_GL4ES gl4es_glGetMapiv(GLenum target, GLenum query, GLint *v); 28 | 29 | typedef struct { 30 | GLenum type; 31 | } map_state_t; 32 | 33 | typedef struct { 34 | GLdouble _1, _2, d; 35 | GLint order; 36 | } mapcoordd_t; 37 | 38 | typedef struct { 39 | GLfloat _1, _2, d; 40 | GLint order; 41 | } mapcoordf_t; 42 | 43 | typedef struct { 44 | GLenum type; 45 | GLint dims, width; 46 | mapcoordd_t u, v; 47 | const GLdouble *points; 48 | } map_stated_t; 49 | 50 | typedef struct { 51 | GLenum type; 52 | GLint dims, width; 53 | mapcoordf_t u, v; 54 | const GLfloat *points; 55 | } map_statef_t; 56 | 57 | typedef struct { 58 | GLfloat _1, _2; 59 | GLfloat d; 60 | GLint n; 61 | } map_grid_t; 62 | 63 | static const GLsizei get_map_width(GLenum target) { 64 | switch (target) { 65 | case GL_MAP1_COLOR_4: return 4; 66 | case GL_MAP1_INDEX: return 3; 67 | case GL_MAP1_NORMAL: return 3; 68 | case GL_MAP1_TEXTURE_COORD_1: return 1; 69 | case GL_MAP1_TEXTURE_COORD_2: return 2; 70 | case GL_MAP1_TEXTURE_COORD_3: return 3; 71 | case GL_MAP1_TEXTURE_COORD_4: return 4; 72 | case GL_MAP1_VERTEX_3: return 3; 73 | case GL_MAP1_VERTEX_4: return 4; 74 | case GL_MAP2_COLOR_4: return 4; 75 | case GL_MAP2_INDEX: return 3; 76 | case GL_MAP2_NORMAL: return 3; 77 | case GL_MAP2_TEXTURE_COORD_1: return 1; 78 | case GL_MAP2_TEXTURE_COORD_2: return 2; 79 | case GL_MAP2_TEXTURE_COORD_3: return 3; 80 | case GL_MAP2_TEXTURE_COORD_4: return 4; 81 | case GL_MAP2_VERTEX_3: return 3; 82 | case GL_MAP2_VERTEX_4: return 4; 83 | } 84 | return 0; 85 | } 86 | 87 | #endif // _GL4ES_EVAL_H_ 88 | -------------------------------------------------------------------------------- /src/gl/face.c: -------------------------------------------------------------------------------- 1 | #include "face.h" 2 | 3 | #include "loader.h" 4 | #include "gl4es.h" 5 | #include "glstate.h" 6 | 7 | void APIENTRY_GL4ES gl4es_glCullFace(GLenum mode) { 8 | if(!glstate->list.pending) 9 | PUSH_IF_COMPILING(glCullFace); 10 | if(mode!=GL_FRONT && mode!=GL_BACK && mode!=GL_FRONT_AND_BACK) { 11 | errorShim(GL_INVALID_ENUM); 12 | return; 13 | } 14 | if(glstate->face.cull == mode) { 15 | noerrorShim(); 16 | return; 17 | } 18 | FLUSH_BEGINEND; 19 | 20 | glstate->face.cull = mode; 21 | LOAD_GLES(glCullFace); 22 | gles_glCullFace(mode); 23 | } 24 | 25 | void APIENTRY_GL4ES gl4es_glFrontFace(GLenum mode) { 26 | if(!glstate->list.pending) 27 | PUSH_IF_COMPILING(glFrontFace); 28 | if(mode!=GL_CW && mode!=GL_CCW) { 29 | errorShim(GL_INVALID_ENUM); 30 | return; 31 | } 32 | if(glstate->face.front == mode) { 33 | noerrorShim(); 34 | return; 35 | } 36 | FLUSH_BEGINEND; 37 | 38 | glstate->face.front = mode; 39 | LOAD_GLES(glFrontFace); 40 | gles_glFrontFace(mode); 41 | } 42 | 43 | 44 | AliasExport(void,glCullFace,,(GLenum mode)); 45 | AliasExport(void,glFrontFace,,(GLenum mode)); 46 | -------------------------------------------------------------------------------- /src/gl/face.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_FACE_H_ 2 | #define _GL4ES_FACE_H_ 3 | 4 | #include "gles.h" 5 | 6 | void APIENTRY_GL4ES gl4es_glCullFace(GLenum mode); 7 | void APIENTRY_GL4ES gl4es_glFrontFace(GLenum mode); 8 | 9 | #endif // _GL4ES_FACE_H_ 10 | -------------------------------------------------------------------------------- /src/gl/fog.c: -------------------------------------------------------------------------------- 1 | #include "fog.h" 2 | 3 | #include "../glx/hardext.h" 4 | #include "fpe.h" 5 | #include "gl4es.h" 6 | #include "glstate.h" 7 | #include "loader.h" 8 | #include "matrix.h" 9 | #include "matvec.h" 10 | 11 | void APIENTRY_GL4ES gl4es_glFogfv(GLenum pname, const GLfloat* params) { 12 | 13 | if (glstate->list.active) 14 | if (glstate->list.compiling) { 15 | NewStage(glstate->list.active, STAGE_FOG); 16 | rlFogOp(glstate->list.active, pname, params); 17 | return; 18 | } 19 | else gl4es_flush(); 20 | noerrorShim(); 21 | #define GO(A,name, size) if(memcmp(A glstate->fog.name, params, size)==0) return; else memcpy(A glstate->fog.name, params, size); 22 | switch (pname) { 23 | case GL_FOG_MODE: 24 | GO(&, mode, sizeof(GLfloat)) 25 | break; 26 | case GL_FOG_DENSITY: 27 | if(*params<0.f) { 28 | errorShim(GL_INVALID_VALUE); 29 | return; 30 | } 31 | GO(&, density, sizeof(GLfloat)) 32 | break; 33 | case GL_FOG_START: 34 | GO(&, start, sizeof(GLfloat)) 35 | break; 36 | case GL_FOG_END: 37 | GO(&, end, sizeof(GLfloat)) 38 | break; 39 | case GL_FOG_INDEX: 40 | GO(&, index, sizeof(GLfloat)) 41 | return; // unsupported for now 42 | case GL_FOG_COLOR: 43 | #if defined(__GNUC__) && (__GNUC__ > 7) 44 | #pragma GCC diagnostic push 45 | #pragma GCC diagnostic ignored "-Wstringop-overflow" 46 | #endif 47 | // GCC 8.1 warn about reading 16 bytes from a 4 bytes value, but params is not (in that case) a 4 bytes value 48 | GO(, color, 4*sizeof(GLfloat)) 49 | #if defined(__GNUC__) && (__GNUC__ > 7) 50 | #pragma GCC diagnostic pop 51 | #endif 52 | break; 53 | case GL_FOG_COORD_SRC: 54 | GO(&, coord_src, sizeof(GLfloat)) 55 | if(hardext.esversion==1) 56 | return; // unsupported on GLES1.1 57 | break; 58 | case GL_FOG_DISTANCE_MODE_NV: 59 | GO(&, distance, sizeof(GLfloat)) 60 | if(hardext.esversion==1) 61 | return; // unsupported on GLES1.1 62 | break; 63 | default: 64 | errorShim(GL_INVALID_ENUM); 65 | return; 66 | } 67 | #undef GO 68 | LOAD_GLES_FPE(glFogfv); 69 | gles_glFogfv(pname, params); 70 | errorGL(); 71 | } 72 | 73 | void APIENTRY_GL4ES gl4es_glFogf(GLenum pname, GLfloat param) { 74 | gl4es_glFogfv(pname, ¶m); 75 | } 76 | 77 | void APIENTRY_GL4ES gl4es_glFogCoordd(GLdouble coord) { 78 | gl4es_glFogCoordf(coord); 79 | } 80 | void APIENTRY_GL4ES gl4es_glFogCoorddv(const GLdouble *coord) { 81 | gl4es_glFogCoordf(*coord); 82 | } 83 | void APIENTRY_GL4ES gl4es_glFogCoordfv(const GLfloat *coord) { 84 | gl4es_glFogCoordf(*coord); 85 | } 86 | void APIENTRY_GL4ES gl4es_glFogCoordf(GLfloat coord) { 87 | if (glstate->list.active) { 88 | if(glstate->list.pending) 89 | gl4es_flush(); 90 | else 91 | { 92 | rlFogCoordf(glstate->list.active, coord); 93 | glstate->list.active->lastFogCoord = coord; 94 | } 95 | noerrorShim(); 96 | } else { 97 | noerrorShim(); 98 | } 99 | // change the state last thing 100 | glstate->fogcoord[0] = coord; 101 | } 102 | 103 | 104 | AliasExport(void,glFogfv,,(GLenum pname, const GLfloat* params)); 105 | AliasExport(void,glFogf,,(GLenum pname, GLfloat param)); 106 | AliasExport_D(void,glFogCoordd,,(GLdouble coord)); 107 | AliasExport(void,glFogCoorddv,,(const GLdouble *coord)); 108 | AliasExport(void,glFogCoordf,,(GLfloat coord)); 109 | AliasExport(void,glFogCoordfv,,(const GLfloat *coord)); 110 | 111 | AliasExport(void,glFogfv,EXT,(GLenum pname, const GLfloat* params)); 112 | AliasExport(void,glFogf,EXT,(GLenum pname, GLfloat param)); 113 | AliasExport_D(void,glFogCoordd,EXT,(GLdouble coord)); 114 | AliasExport(void,glFogCoorddv,EXT,(const GLdouble *coord)); 115 | AliasExport(void,glFogCoordf,EXT,(GLfloat coord)); 116 | AliasExport(void,glFogCoordfv,EXT,(const GLfloat *coord)); -------------------------------------------------------------------------------- /src/gl/fog.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_FOG_H_ 2 | #define _GL4ES_FOG_H_ 3 | 4 | #include "gles.h" 5 | 6 | typedef struct { 7 | GLenum mode; 8 | GLfloat density; 9 | GLenum distance; 10 | GLfloat start; 11 | GLfloat end; 12 | GLfloat index; 13 | GLfloat color[4]; 14 | GLenum coord_src; 15 | } fog_t; 16 | 17 | void APIENTRY_GL4ES gl4es_glFogfv(GLenum pname, const GLfloat* params); 18 | void APIENTRY_GL4ES gl4es_glFogf(GLenum pname, GLfloat param); 19 | 20 | void APIENTRY_GL4ES gl4es_glFogCoordf(GLfloat coord); 21 | void APIENTRY_GL4ES gl4es_glFogCoordfv(const GLfloat *coord); 22 | 23 | #endif // _GL4ES_FOG_H_ 24 | -------------------------------------------------------------------------------- /src/gl/fpe_cache.h: -------------------------------------------------------------------------------- 1 | #ifndef __FPE_CACHE_H__ 2 | #define __FPE_CACHE_H__ 3 | 4 | typedef struct fpe_state_s fpe_state_t; 5 | typedef fpe_state_t *kh_fpe_t; 6 | typedef struct fpe_fpe_s fpe_fpe_t; 7 | typedef struct kh_fpecachelist_s kh_fpecachelist_t; 8 | #ifndef fpe_cache_t 9 | #define fpe_cache_t kh_fpecachelist_t 10 | #endif 11 | 12 | fpe_cache_t* fpe_NewCache(); 13 | void fpe_disposeCache(fpe_cache_t* cache, int freeprog); 14 | fpe_fpe_t *fpe_GetCache(fpe_cache_t *cur, fpe_state_t *state, int fixed); 15 | 16 | void fpe_InitPSA(const char* name); 17 | void fpe_FreePSA(); 18 | void fpe_readPSA(); 19 | void fpe_writePSA(); 20 | int fpe_GetProgramPSA(GLuint program, fpe_state_t* state); 21 | void fpe_AddProgramPSA(GLuint program, fpe_state_t* state); 22 | 23 | #endif //__FPE_CACHE_H__ -------------------------------------------------------------------------------- /src/gl/fpe_shader.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_FPE_SHADER_H_ 2 | #define _GL4ES_FPE_SHADER_H_ 3 | 4 | #include "fpe.h" 5 | 6 | extern const char* fpeshader_signature; 7 | 8 | const char* const* fpe_VertexShader(shaderconv_need_t* need, fpe_state_t *state); 9 | const char* const* fpe_FragmentShader(shaderconv_need_t* need, fpe_state_t *state); 10 | 11 | const char* const* fpe_CustomVertexShader(const char* initial, fpe_state_t* state); 12 | const char* const* fpe_CustomFragmentShader(const char* initial, fpe_state_t* state); 13 | 14 | #endif // _GL4ES_FPE_SHADER_H_ 15 | -------------------------------------------------------------------------------- /src/gl/framebuffers.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_FRAMEBUFFERS_H_ 2 | #define _GL4ES_FRAMEBUFFERS_H_ 3 | 4 | #include "gles.h" 5 | 6 | void APIENTRY_GL4ES gl4es_glGenerateMipmap(GLenum target); 7 | void APIENTRY_GL4ES gl4es_glGenFramebuffers(GLsizei n, GLuint *ids); 8 | void APIENTRY_GL4ES gl4es_glDeleteFramebuffers(GLsizei n, GLuint *framebuffers); 9 | GLboolean APIENTRY_GL4ES gl4es_glIsFramebuffer(GLuint framebuffer); 10 | GLenum APIENTRY_GL4ES gl4es_glCheckFramebufferStatus(GLenum target); 11 | void APIENTRY_GL4ES gl4es_glBindFramebuffer(GLenum target, GLuint framebuffer); 12 | void APIENTRY_GL4ES gl4es_glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); 13 | void APIENTRY_GL4ES gl4es_glGenRenderbuffers(GLsizei n, GLuint *renderbuffers); 14 | void APIENTRY_GL4ES gl4es_glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); 15 | void APIENTRY_GL4ES gl4es_glDeleteRenderbuffers(GLsizei n, GLuint *renderbuffers); 16 | void APIENTRY_GL4ES gl4es_glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height); 17 | void APIENTRY_GL4ES gl4es_glBindRenderbuffer(GLenum target, GLuint renderbuffer); 18 | GLboolean APIENTRY_GL4ES gl4es_glIsRenderbuffer(GLuint renderbuffer); 19 | void APIENTRY_GL4ES gl4es_glGenerateMipmap(GLenum target); 20 | void APIENTRY_GL4ES gl4es_glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint *params); 21 | void APIENTRY_GL4ES gl4es_glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint * params); 22 | 23 | void APIENTRY_GL4ES gl4es_glFramebufferTexture1D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); // naive Wrap 24 | void APIENTRY_GL4ES gl4es_glFramebufferTexture3D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint layer); // naive Wrap 25 | void APIENTRY_GL4ES gl4es_glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); //STUB 26 | void APIENTRY_GL4ES gl4es_glFramebufferTextureLayer( GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); // naive Wrap 27 | void APIENTRY_GL4ES gl4es_glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); 28 | 29 | void APIENTRY_GL4ES gl4es_glDrawBuffers(GLsizei n, const GLenum *bufs); 30 | void APIENTRY_GL4ES gl4es_glNamedFramebufferDrawBuffers(GLuint framebuffer, GLsizei n, const GLenum *bufs); 31 | 32 | void APIENTRY_GL4ES gl4es_glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint * value); 33 | void APIENTRY_GL4ES gl4es_glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint * value); 34 | void APIENTRY_GL4ES gl4es_glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat * value); 35 | void APIENTRY_GL4ES gl4es_glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); 36 | 37 | void APIENTRY_GL4ES gl4es_glClearNamedFramebufferiv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLint *value); 38 | void APIENTRY_GL4ES gl4es_glClearNamedFramebufferuiv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLuint *value); 39 | void APIENTRY_GL4ES gl4es_glClearNamedFramebufferfv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLfloat *value); 40 | void APIENTRY_GL4ES gl4es_glClearNamedFramebufferfi(GLuint framebuffer, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); 41 | 42 | void APIENTRY_GL4ES gl4es_glColorMaskIndexed(GLuint framebuffer, GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); 43 | 44 | // In case of LIBGL_FB=2, let's create an FBO for everything, that is then blitted just before the SwapBuffer 45 | void createMainFBO(int width, int height); 46 | void blitMainFBO(int x, int y, int width, int height); 47 | void deleteMainFBO(void* state); 48 | void bindMainFBO(); 49 | void unbindMainFBO(); 50 | 51 | void readfboBegin(); 52 | void readfboEnd(); 53 | 54 | GLuint gl4es_getCurrentFBO(); 55 | void gl4es_setCurrentFBO(); 56 | 57 | void gl4es_saveCurrentFBO(); 58 | void gl4es_restoreCurrentFBO(); 59 | 60 | #endif // _GL4ES_FRAMEBUFFERS_H_ 61 | -------------------------------------------------------------------------------- /src/gl/gl_lookup.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL_LOOKUP_H_ 2 | #define _GL_LOOKUP_H_ 3 | 4 | #include "attributes.h" 5 | 6 | #ifdef DEBUG 7 | #define MAP(func_name, func) \ 8 | if (strcmp(name, func_name) == 0) {printf("%p (%s)\n", (void*)func, #func) ;return (void *)func;} 9 | #else 10 | #define MAP(func_name, func) \ 11 | if (strcmp(name, func_name) == 0) return (void *)func; 12 | #endif 13 | 14 | #define EX(func_name) MAP(#func_name, func_name) 15 | 16 | #define ARB(func_name) MAP(#func_name "ARB", func_name) 17 | 18 | #define EXT(func_name) MAP(#func_name "EXT", func_name) 19 | 20 | #define _EX(func_name) MAP(#func_name, gl4es_ ## func_name) 21 | 22 | #define _ARB(func_name) MAP(#func_name "ARB", gl4es_ ## func_name) 23 | 24 | #define _EXT(func_name) MAP(#func_name "EXT", gl4es_ ## func_name) 25 | 26 | #ifndef STUB_FCT 27 | #error STUB_FCT is not defined 28 | #endif 29 | 30 | #ifdef DEBUG 31 | #define STUB(func_name) \ 32 | if (strcmp(name, #func_name) == 0) { \ 33 | printf("=> STUB\n"); \ 34 | if(!globals4es.silentstub) LOGD("GL4ES stub: %s\n", #func_name); \ 35 | return (void *)STUB_FCT; \ 36 | } 37 | #else 38 | #define STUB(func_name) \ 39 | if (strcmp(name, #func_name) == 0) { \ 40 | if(!globals4es.silentstub) LOGD("GL4ES stub: %s\n", #func_name); \ 41 | return (void *)STUB_FCT; \ 42 | } 43 | #endif 44 | 45 | NonAliasExportDecl(void*,gl4es_GetProcAddress,(const char *name)); 46 | 47 | #endif //_GL_LOOKUP_H_ -------------------------------------------------------------------------------- /src/gl/glcase.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_GLCASE_H_ 2 | #define _GL4ES_GLCASE_H_ 3 | 4 | #define GL_TYPE_CASE(name, var, magic, vtype, code)\ 5 | case magic: { \ 6 | vtype *name = (vtype *)var; \ 7 | code \ 8 | break; \ 9 | } 10 | 11 | #define GL_TYPE_CASE_ALT(name, var, name2, var2, magic, vtype, code) \ 12 | case magic: { \ 13 | vtype *name = (vtype *)var; \ 14 | vtype *name2= (vtype *)var2; \ 15 | code \ 16 | break; \ 17 | } 18 | 19 | #define GL_TYPE_CASE2(name, var, magic, vtype, code2, code) \ 20 | case magic: { \ 21 | code2 { \ 22 | vtype *name = (vtype *)var; \ 23 | code \ 24 | } \ 25 | break; \ 26 | } 27 | 28 | #define GL_TYPE_CASE_MAX(name, var, magic, vtype, code, max) \ 29 | case magic: { \ 30 | vtype *name = (vtype *)var; \ 31 | vtype maxv = max; \ 32 | code \ 33 | break; \ 34 | } 35 | 36 | #define GL_TYPE_SWITCH(name, var, type, code, extra) \ 37 | switch (type) { \ 38 | GL_TYPE_CASE(name, var, GL_DOUBLE, GLdouble, code) \ 39 | GL_TYPE_CASE(name, var, GL_FLOAT, GLfloat, code) \ 40 | GL_TYPE_CASE(name, var, GL_INT, GLint, code) \ 41 | GL_TYPE_CASE(name, var, GL_SHORT, GLshort, code) \ 42 | GL_TYPE_CASE(name, var, GL_BYTE, GLbyte, code) \ 43 | GL_TYPE_CASE(name, var, GL_UNSIGNED_BYTE, GLubyte, code) \ 44 | GL_TYPE_CASE(name, var, GL_UNSIGNED_INT, GLuint, code) \ 45 | GL_TYPE_CASE(name, var, GL_UNSIGNED_SHORT, GLushort, code) \ 46 | extra \ 47 | } 48 | 49 | #define GL_TYPE_SWITCH_ALT(name, var, name2, var2, type, code, extra) \ 50 | switch (type) { \ 51 | GL_TYPE_CASE_ALT(name, var, name2, var2, GL_DOUBLE, GLdouble, code) \ 52 | GL_TYPE_CASE_ALT(name, var, name2, var2, GL_FLOAT, GLfloat, code) \ 53 | GL_TYPE_CASE_ALT(name, var, name2, var2, GL_INT, GLint, code) \ 54 | GL_TYPE_CASE_ALT(name, var, name2, var2, GL_SHORT, GLshort, code) \ 55 | GL_TYPE_CASE_ALT(name, var, name2, var2, GL_BYTE, GLbyte, code) \ 56 | GL_TYPE_CASE_ALT(name, var, name2, var2, GL_UNSIGNED_BYTE, GLubyte, code) \ 57 | GL_TYPE_CASE_ALT(name, var, name2, var2, GL_UNSIGNED_INT, GLuint, code) \ 58 | GL_TYPE_CASE_ALT(name, var, name2, var2, GL_UNSIGNED_SHORT, GLushort, code) \ 59 | extra \ 60 | } 61 | 62 | #define GL_TYPE_SWITCH2(name, var, type, code2, code, extra) \ 63 | switch (type) { \ 64 | GL_TYPE_CASE2(name, var, GL_DOUBLE, GLdouble, code2, code) \ 65 | GL_TYPE_CASE2(name, var, GL_FLOAT, GLfloat, code2, code) \ 66 | GL_TYPE_CASE2(name, var, GL_INT, GLint, code2, code) \ 67 | GL_TYPE_CASE2(name, var, GL_SHORT, GLshort, code2, code) \ 68 | GL_TYPE_CASE2(name, var, GL_BYTE, GLbyte, code2, code) \ 69 | GL_TYPE_CASE2(name, var, GL_UNSIGNED_BYTE, GLubyte, code2, code) \ 70 | GL_TYPE_CASE2(name, var, GL_UNSIGNED_INT, GLuint, code2, code) \ 71 | GL_TYPE_CASE2(name, var, GL_UNSIGNED_SHORT, GLushort, code2, code) \ 72 | extra \ 73 | } 74 | 75 | #define GL_TYPE_SWITCH_MAX(name, var, type, code, extra) \ 76 | switch (type) { \ 77 | GL_TYPE_CASE_MAX(name, var, GL_DOUBLE, GLdouble, code, 1.0) \ 78 | GL_TYPE_CASE_MAX(name, var, GL_FLOAT, GLfloat, code, 1.0f) \ 79 | GL_TYPE_CASE_MAX(name, var, GL_INT, GLint, code, 2147483647l) \ 80 | GL_TYPE_CASE_MAX(name, var, GL_SHORT, GLshort, code, 32767) \ 81 | GL_TYPE_CASE_MAX(name, var, GL_BYTE, GLbyte, code, 127) \ 82 | GL_TYPE_CASE_MAX(name, var, GL_UNSIGNED_BYTE, GLubyte, code, 255) \ 83 | GL_TYPE_CASE_MAX(name, var, GL_UNSIGNED_INT, GLuint, code, 4294967295l) \ 84 | GL_TYPE_CASE_MAX(name, var, GL_UNSIGNED_SHORT, GLushort, code, 65535) \ 85 | extra \ 86 | } 87 | 88 | #endif // _GL4ES_GLCASE_H_ -------------------------------------------------------------------------------- /src/gl/hint.c: -------------------------------------------------------------------------------- 1 | #include "hint.h" 2 | 3 | #include 4 | #include "init.h" 5 | #include "loader.h" 6 | #include "gl4es.h" 7 | #include "glstate.h" 8 | 9 | #ifdef PANDORA 10 | void pandora_set_gamma(); 11 | #endif 12 | 13 | void APIENTRY_GL4ES gl4es_glHint(GLenum pname, GLenum mode) { 14 | 15 | FLUSH_BEGINEND; 16 | 17 | LOAD_GLES(glHint); 18 | noerrorShim(); 19 | switch(pname) { 20 | // some Hint are not supported in GLES2, so just ignoring them 21 | case GL_FOG_HINT: 22 | if(hardext.esversion>1) 23 | return; 24 | gles_glHint(pname, mode); 25 | break; 26 | case GL_PERSPECTIVE_CORRECTION_HINT: 27 | if(hardext.esversion>1) 28 | return; 29 | gles_glHint(pname, mode); 30 | break; 31 | case GL_LINE_SMOOTH_HINT: 32 | if(hardext.esversion>1) 33 | return; 34 | gles_glHint(pname, mode); 35 | break; 36 | case GL_POINT_SMOOTH_HINT: 37 | if(hardext.esversion>1) 38 | return; 39 | gles_glHint(pname, mode); 40 | break; 41 | case GL_TEXTURE_COMPRESSION_HINT: // ignore this one 42 | // TODO: track setted value 43 | return; 44 | // specifics GL4ES Hints 45 | case GL_SHRINK_HINT_GL4ES: 46 | if (mode<=11) 47 | globals4es.texshrink = mode; 48 | else 49 | errorShim(GL_INVALID_ENUM); 50 | break; 51 | case GL_ALPHAHACK_HINT_GL4ES: 52 | if (mode<=1) 53 | globals4es.alphahack = mode; 54 | else 55 | errorShim(GL_INVALID_ENUM); 56 | break; 57 | case GL_RECYCLEFBO_HINT_GL4ES: 58 | if (mode<=1) 59 | globals4es.recyclefbo = mode; 60 | else 61 | errorShim(GL_INVALID_ENUM); 62 | break; 63 | case GL_MIPMAP_HINT_GL4ES: 64 | if (mode<=4) 65 | globals4es.automipmap = mode; 66 | else 67 | errorShim(GL_INVALID_ENUM); 68 | break; 69 | case GL_TEXDUMP_HINT_GL4ES: 70 | if (mode<=1) 71 | globals4es.texdump = mode; 72 | else 73 | errorShim(GL_INVALID_ENUM); 74 | break; 75 | case GL_COPY_HINT_GL4ES: 76 | if (mode>1) //removed 77 | errorShim(GL_INVALID_ENUM); 78 | break; 79 | case GL_NOLUMAPHA_HINT_GL4ES: 80 | if (mode<=1) 81 | globals4es.nolumalpha = mode; 82 | else 83 | errorShim(GL_INVALID_ENUM); 84 | break; 85 | case GL_BLENDHACK_HINT_GL4ES: 86 | if (mode<=1) 87 | globals4es.blendhack = mode; 88 | else 89 | errorShim(GL_INVALID_ENUM); 90 | break; 91 | case GL_BATCH_HINT_GL4ES: 92 | globals4es.minbatch = 0; 93 | globals4es.maxbatch = mode*100; 94 | break; 95 | case GL_NOERROR_HINT_GL4ES: 96 | if (mode<=1) 97 | globals4es.noerror = mode; 98 | else 99 | errorShim(GL_INVALID_ENUM); 100 | break; 101 | case GL_NODOWNSAMPLING_HINT_GL4ES: 102 | if (mode<=1) 103 | globals4es.nodownsampling = mode; 104 | else 105 | errorShim(GL_INVALID_ENUM); 106 | break; 107 | case GL_NOVAOCACHE_HINT_GL4ES: 108 | if (mode<=1) 109 | globals4es.novaocache = mode; 110 | else 111 | errorShim(GL_INVALID_ENUM); 112 | break; 113 | case GL_BEGINEND_HINT_GL4ES: 114 | if(mode<=2) 115 | globals4es.beginend = mode; 116 | else 117 | errorShim(GL_INVALID_ENUM); 118 | case GL_AVOID16BITS_HINT_GL4ES: 119 | if (mode<=1) 120 | globals4es.avoid16bits = mode; 121 | else 122 | errorShim(GL_INVALID_ENUM); 123 | break; 124 | case GL_GAMMA_HINT_GL4ES: 125 | globals4es.gamma = ((float)mode)/10.f; 126 | #ifdef PANDORA 127 | pandora_set_gamma(); 128 | #endif 129 | break; 130 | default: 131 | errorGL(); 132 | gles_glHint(pname, mode); 133 | } 134 | } 135 | AliasExport(void,glHint,,(GLenum pname, GLenum mode)); -------------------------------------------------------------------------------- /src/gl/hint.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_HINT_H_ 2 | #define _GL4ES_HINT_H_ 3 | 4 | #include "gles.h" 5 | 6 | void APIENTRY_GL4ES gl4es_glHint(GLenum pname, GLenum mode); 7 | 8 | #endif // _GL4ES_HINT_H_ 9 | -------------------------------------------------------------------------------- /src/gl/init.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_INIT_H_ 2 | #define _GL4ES_INIT_H_ 3 | 4 | #if defined(PANDORA) 5 | #define USE_FBIO 1 6 | #endif 7 | 8 | typedef struct _globals4es { 9 | int nobanner; 10 | int mergelist; 11 | int xrefresh; 12 | int stacktrace; 13 | int usefb; 14 | int usegbm; 15 | int usefbo; 16 | int recyclefbo; 17 | int usepbuffer; 18 | int showfps; 19 | int vsync; 20 | int automipmap; 21 | int texcopydata; 22 | int tested_env; 23 | int texshrink; 24 | int texdump; 25 | int alphahack; 26 | int texstream; 27 | int nolumalpha; 28 | int blendhack; 29 | int blendcolor; 30 | int noerror; 31 | int npot; 32 | int defaultwrap; 33 | int notexrect; 34 | int queries; 35 | int silentstub; 36 | int glx_surface_srgb; 37 | int nodownsampling; 38 | int vabgra; 39 | int nobgra; 40 | int potframebuffer; 41 | float gamma; 42 | int texmat; 43 | int novaocache; 44 | int beginend; 45 | int avoid16bits; 46 | int avoid24bits; 47 | int force16bits; 48 | int nohighp; 49 | int minbatch; 50 | int maxbatch; 51 | int es; 52 | int gl; 53 | int usevbo; 54 | int comments; 55 | int forcenpot; 56 | int fbomakecurrent; // hack to bind/unbind FBO when doing glXMakeCurrent 57 | int fbounbind; // hack to bind/unbind fbo if a bind texture is used for drawing 58 | int fboforcetex; // force texture attachment for Color0 59 | int blitfullscreen; // a "fullscreen" blit to FB0 means SwapBuffers 60 | int notexarray; 61 | int nodepthtex; 62 | int logshader; 63 | int shadernogles; 64 | int floattex; 65 | int glxrecycle; 66 | int noclean; 67 | int dbgshaderconv; 68 | int nopsa; 69 | int noes2; 70 | int nointovlhack; 71 | int noshaderlod; 72 | int fbo_noalpha; 73 | int noarbprogram; // to disable ARB Program 74 | int glxnative; 75 | int normalize; // force normal normalization (workaround a bug) 76 | int blitfb0; 77 | #ifndef NO_GBM 78 | char drmcard[50]; 79 | #endif 80 | char version[50]; 81 | } globals4es_t; 82 | 83 | extern globals4es_t globals4es; 84 | 85 | #endif // _GL4ES_INIT_H_ 86 | -------------------------------------------------------------------------------- /src/gl/light.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_LIGHT_H_ 2 | #define _GL4ES_LIGHT_H_ 3 | 4 | #include "gles.h" 5 | #include "../config.h" 6 | 7 | typedef struct { 8 | GLfloat ambient[4]; 9 | GLfloat diffuse[4]; 10 | GLfloat specular[4]; 11 | GLfloat constantAttenuation, linearAttenuation, quadraticAttenuation; 12 | GLfloat position[4]; 13 | GLfloat spotDirection[3]; // It's only 3 in fact, because it's a direction 14 | GLfloat spotExponent; 15 | GLfloat spotCutoff; 16 | } light_t; 17 | 18 | typedef struct { 19 | light_t lights[MAX_LIGHT]; 20 | GLfloat ambient[4]; 21 | GLboolean two_side; 22 | GLboolean separate_specular; 23 | GLboolean local_viewer; 24 | } light_state_t; 25 | 26 | typedef struct { 27 | GLfloat ambient[4]; 28 | GLfloat diffuse[4]; 29 | GLfloat specular[4]; 30 | GLfloat emission[4]; 31 | GLfloat shininess; 32 | int indexes[3]; 33 | GLenum colormat; 34 | } material_t; 35 | 36 | typedef struct { 37 | material_t front; 38 | material_t back; 39 | } material_state_t; 40 | 41 | void APIENTRY_GL4ES gl4es_glLightModelf(GLenum pname, GLfloat param); 42 | void APIENTRY_GL4ES gl4es_glLightModelfv(GLenum pname, const GLfloat* params); 43 | void APIENTRY_GL4ES gl4es_glLightfv(GLenum light, GLenum pname, const GLfloat* params); 44 | void APIENTRY_GL4ES gl4es_glLightf(GLenum light, GLenum pname, GLfloat params); 45 | 46 | void APIENTRY_GL4ES gl4es_glGetLightfv(GLenum light, GLenum pname, GLfloat * params); 47 | void APIENTRY_GL4ES gl4es_glGetLightiv(GLenum light, GLenum pname, GLint * params); 48 | 49 | void APIENTRY_GL4ES gl4es_glMaterialfv(GLenum face, GLenum pname, const GLfloat *params) ; 50 | void APIENTRY_GL4ES gl4es_glMaterialf(GLenum face, GLenum pname, GLfloat param); 51 | void APIENTRY_GL4ES gl4es_glColorMaterial(GLenum face, GLenum mode); 52 | 53 | #endif // _GL4ES_LIGHT_H_ 54 | -------------------------------------------------------------------------------- /src/gl/line.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_LINE_H 2 | #define _GL4ES_LINE_H 3 | 4 | #include "gles.h" 5 | #include "list.h" 6 | 7 | void APIENTRY_GL4ES gl4es_glLineStipple(GLuint factor, GLushort pattern); 8 | GLfloat *gen_stipple_tex_coords(GLfloat *vert, GLushort *sindices, modeinit_t *modes, int stride, int length, GLfloat* noalloctex); 9 | void bind_stipple_tex(); 10 | 11 | #endif // _GL4ES_LINE_H 12 | -------------------------------------------------------------------------------- /src/gl/logs.c: -------------------------------------------------------------------------------- 1 | #include "logs.h" 2 | #include "init.h" 3 | #include 4 | #if defined(ANDROID) && defined(USE_ANDROID_LOG) 5 | #include 6 | #endif 7 | //---------------------------------------------------------------------------- 8 | static const char * const log_prefix="LIBGL: "; 9 | //---------------------------------------------------------------------------- 10 | void LogPrintf_NoPrefix(const char *fmt,...) 11 | { 12 | va_list args; 13 | va_start(args,fmt); 14 | #if defined(ANDROID) && defined(USE_ANDROID_LOG) 15 | __android_log_vprint(ANDROID_LOG_INFO, "LIBGL", fmt, args); 16 | #else 17 | vprintf(fmt,args); 18 | #endif 19 | va_end(args); 20 | } 21 | //---------------------------------------------------------------------------- 22 | void LogFPrintf(FILE *fp,const char *fmt,...) 23 | { 24 | #ifndef ANDROID 25 | fprintf(fp,log_prefix); 26 | #endif 27 | va_list args; 28 | va_start(args,fmt); 29 | #if defined(ANDROID) && defined(USE_ANDROID_LOG) 30 | // also on logcat 31 | __android_log_vprint(ANDROID_LOG_INFO, "LIBGL", fmt, args); 32 | #endif 33 | vfprintf(fp,fmt,args); 34 | va_end(args); 35 | } 36 | //---------------------------------------------------------------------------- 37 | void LogPrintf(const char *fmt,...) 38 | { 39 | #ifndef ANDROID 40 | printf(log_prefix); 41 | #endif 42 | va_list args; 43 | va_start(args,fmt); 44 | #if defined(ANDROID) && defined(USE_ANDROID_LOG) 45 | __android_log_vprint(ANDROID_LOG_INFO, "LIBGL", fmt, args); 46 | #else 47 | vprintf(fmt,args); 48 | #endif 49 | va_end(args); 50 | } 51 | //---------------------------------------------------------------------------- 52 | -------------------------------------------------------------------------------- /src/gl/logs.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_LOGS_H_ 2 | #define _GL4ES_LOGS_H_ 3 | //---------------------------------------------------------------------------- 4 | #include 5 | #include "init.h" 6 | #include "attributes.h" 7 | //---------------------------------------------------------------------------- 8 | void LogPrintf_NoPrefix(const char *fmt,...); 9 | void LogFPrintf(FILE *fp,const char *fmt,...); 10 | EXPORT void LogPrintf(const char *fmt,...); 11 | //---------------------------------------------------------------------------- 12 | #ifdef GL4ES_SILENCE_MESSAGES 13 | #define SHUT_LOGD(...) 14 | #define SHUT_LOGD_NOPREFIX(...) 15 | #define SHUT_LOGE(...) 16 | #else 17 | #define SHUT_LOGD(...) if(!globals4es.nobanner) LogPrintf(__VA_ARGS__) 18 | #define SHUT_LOGD_NOPREFIX(...) if(!globals4es.nobanner) LogPrintf_NoPrefix(__VA_ARGS__) 19 | #define SHUT_LOGE(...) if(!globals4es.nobanner) LogFPrintf(stderr,__VA_ARGS__) 20 | #endif 21 | //---------------------------------------------------------------------------- 22 | #define LOGD(...) LogPrintf(__VA_ARGS__) 23 | #define LOGE(...) LogFPrintf(stderr,__VA_ARGS__) 24 | //---------------------------------------------------------------------------- 25 | #endif // _GL4ES_LOGS_H_ 26 | -------------------------------------------------------------------------------- /src/gl/math/eval.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Mesa 3-D graphics library 4 | * Version: 3.5 5 | * 6 | * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a 9 | * copy of this software and associated documentation files (the "Software"), 10 | * to deal in the Software without restriction, including without limitation 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 | * and/or sell copies of the Software, and to permit persons to whom the 13 | * Software is furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included 16 | * in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef _M_EVAL_H 27 | #define _M_EVAL_H 28 | 29 | #include "../gl4es.h" 30 | 31 | void _math_init_eval( void ); 32 | 33 | 34 | /* 35 | * Horner scheme for Bezier curves 36 | * 37 | * Bezier curves can be computed via a Horner scheme. 38 | * Horner is numerically less stable than the de Casteljau 39 | * algorithm, but it is faster. For curves of degree n 40 | * the complexity of Horner is O(n) and de Casteljau is O(n^2). 41 | * Since stability is not important for displaying curve 42 | * points I decided to use the Horner scheme. 43 | * 44 | * A cubic Bezier curve with control points b0, b1, b2, b3 can be 45 | * written as 46 | * 47 | * (([3] [3] ) [3] ) [3] 48 | * c(t) = (([0]*s*b0 + [1]*t*b1)*s + [2]*t^2*b2)*s + [3]*t^2*b3 49 | * 50 | * [n] 51 | * where s=1-t and the binomial coefficients [i]. These can 52 | * be computed iteratively using the identity: 53 | * 54 | * [n] [n ] [n] 55 | * [i] = (n-i+1)/i * [i-1] and [0] = 1 56 | */ 57 | 58 | 59 | void 60 | _math_horner_bezier_curve(const GLfloat *cp, GLfloat *out, GLfloat t, 61 | GLuint dim, GLuint order); 62 | 63 | 64 | /* 65 | * Tensor product Bezier surfaces 66 | * 67 | * Again the Horner scheme is used to compute a point on a 68 | * TP Bezier surface. First a control polygon for a curve 69 | * on the surface in one parameter direction is computed, 70 | * then the point on the curve for the other parameter 71 | * direction is evaluated. 72 | * 73 | * To store the curve control polygon additional storage 74 | * for max(uorder,vorder) points is needed in the 75 | * control net cn. 76 | */ 77 | 78 | void 79 | _math_horner_bezier_surf(GLfloat *cn, GLfloat *out, GLfloat u, GLfloat v, 80 | GLuint dim, GLuint uorder, GLuint vorder); 81 | 82 | 83 | /* 84 | * The direct de Casteljau algorithm is used when a point on the 85 | * surface and the tangent directions spanning the tangent plane 86 | * should be computed (this is needed to compute normals to the 87 | * surface). In this case the de Casteljau algorithm approach is 88 | * nicer because a point and the partial derivatives can be computed 89 | * at the same time. To get the correct tangent length du and dv 90 | * must be multiplied with the (u2-u1)/uorder-1 and (v2-v1)/vorder-1. 91 | * Since only the directions are needed, this scaling step is omitted. 92 | * 93 | * De Casteljau needs additional storage for uorder*vorder 94 | * values in the control net cn. 95 | */ 96 | 97 | void 98 | _math_de_casteljau_surf(GLfloat *cn, GLfloat *out, GLfloat *du, GLfloat *dv, 99 | GLfloat u, GLfloat v, GLuint dim, 100 | GLuint uorder, GLuint vorder); 101 | 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /src/gl/matrix.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_MATRIX_H_ 2 | #define _GL4ES_MATRIX_H_ 3 | 4 | #include "gl4es.h" 5 | #include "gles.h" 6 | #include "glstate.h" 7 | #include "list.h" 8 | #include "matvec.h" 9 | 10 | void APIENTRY_GL4ES gl4es_glMatrixMode(GLenum mode); 11 | void APIENTRY_GL4ES gl4es_glPushMatrix(void); 12 | void APIENTRY_GL4ES gl4es_glPopMatrix(void); 13 | void APIENTRY_GL4ES gl4es_glLoadMatrixf(const GLfloat * m); 14 | void APIENTRY_GL4ES gl4es_glMultMatrixf(const GLfloat * m); 15 | void APIENTRY_GL4ES gl4es_glLoadIdentity(void); 16 | void APIENTRY_GL4ES gl4es_glTranslatef(GLfloat x, GLfloat y, GLfloat z); 17 | void APIENTRY_GL4ES gl4es_glScalef(GLfloat x, GLfloat y, GLfloat z); 18 | void APIENTRY_GL4ES gl4es_glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z); 19 | void APIENTRY_GL4ES gl4es_glOrthof(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal); 20 | void APIENTRY_GL4ES gl4es_glFrustumf(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal); 21 | 22 | static inline GLfloat* getTexMat(int tmu) { 23 | return glstate->texture_matrix[tmu]->stack+glstate->texture_matrix[tmu]->top*16; 24 | } 25 | 26 | static inline GLfloat* getMVMat() { 27 | return glstate->modelview_matrix->stack+glstate->modelview_matrix->top*16; 28 | } 29 | 30 | static inline GLfloat* getInvMVMat() { 31 | if(glstate->inv_mv_matrix_dirty) { 32 | matrix_inverse(glstate->modelview_matrix->stack+glstate->modelview_matrix->top*16, glstate->inv_mv_matrix); 33 | glstate->inv_mv_matrix_dirty = 0; 34 | } 35 | return glstate->inv_mv_matrix; 36 | } 37 | static inline GLfloat* getNormalMat() { 38 | if(glstate->normal_matrix_dirty) { 39 | matrix_inverse3_transpose(glstate->modelview_matrix->stack+glstate->modelview_matrix->top*16, glstate->normal_matrix); 40 | glstate->normal_matrix_dirty = 0; 41 | } 42 | return glstate->normal_matrix; 43 | } 44 | 45 | static inline GLfloat* getPMat() { 46 | return glstate->projection_matrix->stack+glstate->projection_matrix->top*16; 47 | } 48 | 49 | static inline GLfloat* getMVPMat() 50 | { 51 | if(glstate->mvp_matrix_dirty) { 52 | matrix_mul(getPMat(), getMVMat(), glstate->mvp_matrix); 53 | glstate->mvp_matrix_dirty = 0; 54 | } 55 | return glstate->mvp_matrix; 56 | } 57 | 58 | 59 | #endif // _GL4ES_MATRIX_H_ 60 | -------------------------------------------------------------------------------- /src/gl/matvec.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_MATVEC_H_ 2 | #define _GL4ES_MATVEC_H_ 3 | 4 | #include 5 | #include "attributes.h" 6 | 7 | float dot(const float *a, const float *b) FASTMATH; 8 | float dot4(const float *a, const float *b) FASTMATH; 9 | void cross3(const float *a, const float *b, float* c) FASTMATH; 10 | void matrix_vector(const float *a, const float *b, float *c); 11 | void vector_matrix(const float *a, const float *b, float *c); 12 | void vector3_matrix(const float *a, const float *b, float *c); 13 | void vector3_matrix3(const float *a, const float *b, float *c); 14 | void vector3_matrix4(const float *a, const float *b, float *c); 15 | void vector_normalize(float *a); 16 | void vector4_normalize(float *a); 17 | void vector4_mult(const float *a, const float *b, float *c); 18 | void vector4_add(const float *a, const float *b, float *c); 19 | void matrix_transpose(const float *a, float *b); 20 | void matrix_inverse(const float *m, float *r); 21 | void matrix_inverse3_transpose(const float *m, float *r); // upper3x3 of matrix4 -> inverse -> transposed mat3 22 | void matrix_mul(const float *a, const float *b, float *c); 23 | void set_identity(float* mat); 24 | int is_identity(const float* mat); 25 | 26 | #endif // _GL4ES_MATVEC_H_ 27 | -------------------------------------------------------------------------------- /src/gl/oldprogram.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_OLD_PROGRAM_H_ 2 | #define _GL4ES_OLD_PROGRAM_H_ 3 | 4 | #include "gles.h" 5 | #include "buffers.h" 6 | #include "shader.h" 7 | #include "uniform.h" 8 | #include "program.h" 9 | 10 | typedef struct kh_oldprograms_s kh_oldprograms_t; 11 | typedef struct glstate_s glstate_t; 12 | typedef struct shader_s shader_t; 13 | 14 | typedef struct oldprogram_s { 15 | GLuint id; 16 | GLenum type; 17 | char* string; 18 | shader_t* shader; 19 | int max_local_params; 20 | float* prog_local_params; 21 | int max_env_params; 22 | float* prog_env_params; // link to global array 23 | // tracking of the shader uniforms 24 | int min_loc; 25 | int max_loc; 26 | int* locals; 27 | int min_env; 28 | int max_env; 29 | int* envs; 30 | } oldprogram_t; 31 | 32 | void InitOldProgramMap(glstate_t* glstate); 33 | void FreeOldProgramMap(glstate_t* glstate); 34 | 35 | oldprogram_t* getOldProgram(GLuint id); 36 | 37 | // ARB_vertex_program 38 | // VertexAttrib are the same as ARB_vertex_shader 39 | 40 | void APIENTRY_GL4ES gl4es_glProgramStringARB(GLenum target, GLenum format, GLsizei len, const GLvoid *string); 41 | 42 | void APIENTRY_GL4ES gl4es_glBindProgramARB(GLenum target, GLuint program); 43 | 44 | void APIENTRY_GL4ES gl4es_glDeleteProgramsARB(GLsizei n, const GLuint *programs); 45 | 46 | void APIENTRY_GL4ES gl4es_glGenProgramsARB(GLsizei n, GLuint *programs); 47 | 48 | void APIENTRY_GL4ES gl4es_glProgramEnvParameter4dARB(GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); 49 | void APIENTRY_GL4ES gl4es_glProgramEnvParameter4dvARB(GLenum target, GLuint index, const GLdouble *params); 50 | void APIENTRY_GL4ES gl4es_glProgramEnvParameter4fARB(GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); 51 | void APIENTRY_GL4ES gl4es_glProgramEnvParameter4fvARB(GLenum target, GLuint index, const GLfloat *params); 52 | 53 | void APIENTRY_GL4ES gl4es_glProgramLocalParameter4dARB(GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); 54 | void APIENTRY_GL4ES gl4es_glProgramLocalParameter4dvARB(GLenum target, GLuint index, const GLdouble *params); 55 | void APIENTRY_GL4ES gl4es_glProgramLocalParameter4fARB(GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); 56 | void APIENTRY_GL4ES gl4es_glProgramLocalParameter4fvARB(GLenum target, GLuint index, const GLfloat *params); 57 | 58 | void APIENTRY_GL4ES gl4es_glGetProgramEnvParameterdvARB(GLenum target, GLuint index, GLdouble *params); 59 | void APIENTRY_GL4ES gl4es_glGetProgramEnvParameterfvARB(GLenum target, GLuint index, GLfloat *params); 60 | 61 | void APIENTRY_GL4ES gl4es_glGetProgramLocalParameterdvARB(GLenum target, GLuint index, GLdouble *params); 62 | void APIENTRY_GL4ES gl4es_glGetProgramLocalParameterfvARB(GLenum target, GLuint index, GLfloat *params); 63 | 64 | void APIENTRY_GL4ES gl4es_glGetProgramivARB(GLenum target, GLenum pname, GLint *params); 65 | 66 | void APIENTRY_GL4ES gl4es_glGetProgramStringARB(GLenum target, GLenum pname, GLvoid *string); 67 | 68 | void APIENTRY_GL4ES gl4es_glGetVertexAttribdvARB(GLuint index, GLenum pname, GLdouble *params); 69 | void APIENTRY_GL4ES gl4es_glGetVertexAttribfvARB(GLuint index, GLenum pname, GLfloat *params); 70 | void APIENTRY_GL4ES gl4es_glGetVertexAttribivARB(GLuint index, GLenum pname, GLint *params); 71 | 72 | void APIENTRY_GL4ES gl4es_glGetVertexAttribPointervARB(GLuint index, GLenum pname, GLvoid **pointer); 73 | 74 | GLboolean APIENTRY_GL4ES gl4es_glIsProgramARB(GLuint program); 75 | 76 | void APIENTRY_GL4ES gl4es_glProgramEnvParameters4fvEXT(GLenum target, GLuint index, GLsizei count, const GLfloat *params); 77 | void APIENTRY_GL4ES gl4es_glProgramLocalParameters4fvEXT(GLenum target, GLuint index, GLsizei count, const GLfloat *params); 78 | 79 | #endif //_GL4ES_OLD_PROGRAM_H_ -------------------------------------------------------------------------------- /src/gl/pixel.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_PIXEL_H_ 2 | #define _GL4ES_PIXEL_H_ 3 | 4 | #include 5 | #include "gles.h" 6 | 7 | typedef struct { 8 | GLenum type; 9 | GLint red, green, blue, alpha; 10 | int maxv; 11 | } colorlayout_t; 12 | 13 | typedef struct { 14 | GLfloat r, g, b, a; 15 | } pixel_t; 16 | 17 | #define widthalign(width, align) ((((uintptr_t)(width))+((uintptr_t)(align)-1))&(~((uintptr_t)(align)-1))) 18 | 19 | bool pixel_convert(const GLvoid *src, GLvoid **dst, 20 | GLuint width, GLuint height, 21 | GLenum src_format, GLenum src_type, 22 | GLenum dst_format, GLenum dst_type, GLuint stride, GLuint align); 23 | 24 | bool pixel_transform(const GLvoid *src, GLvoid **dst, 25 | GLuint width, GLuint height, 26 | GLenum src_format, GLenum src_type, 27 | const GLfloat *scale, const GLfloat *bias); 28 | 29 | bool pixel_scale(const GLvoid *src, GLvoid **dst, 30 | GLuint width, GLuint height, 31 | GLuint new_width, GLuint new_height, 32 | GLenum format, GLenum type); 33 | 34 | bool pixel_halfscale(const GLvoid *src, GLvoid **dst, 35 | GLuint width, GLuint height, 36 | GLenum format, GLenum type); 37 | 38 | bool pixel_thirdscale(const GLvoid *src, GLvoid **dst, 39 | GLuint width, GLuint height, 40 | GLenum format, GLenum type); 41 | 42 | bool pixel_quarterscale(const GLvoid *src, GLvoid **dst, 43 | GLuint width, GLuint height, 44 | GLenum format, GLenum type); 45 | 46 | bool pixel_doublescale(const GLvoid *src, GLvoid **dst, 47 | GLuint width, GLuint height, 48 | GLenum format, GLenum type); 49 | 50 | bool pixel_to_ppm(const GLvoid *pixels, 51 | GLuint width, GLuint height, 52 | GLenum format, GLenum type, GLuint name, GLuint align); 53 | 54 | // sRGB ->RGB colorspace conversion, for RGBA data... 55 | void pixel_srgb_inplace(GLvoid* pixels, GLuint width, GLuint height); 56 | 57 | #endif // _GL4ES_PIXEL_H_ 58 | -------------------------------------------------------------------------------- /src/gl/planes.c: -------------------------------------------------------------------------------- 1 | #include "planes.h" 2 | 3 | #include "../glx/hardext.h" 4 | #include "loader.h" 5 | #include "matrix.h" 6 | #include "matvec.h" 7 | 8 | void APIENTRY_GL4ES gl4es_glClipPlanef(GLenum plane, const GLfloat *equation) 9 | { 10 | /* 11 | When glClipPlane is called, 12 | equation is transformed by the inverse of the modelview matrix and stored in the resulting eye coordinates. 13 | Subsequent changes to the modelview matrix have no effect on the stored plane-equation components. 14 | If the dot product of the eye coordinates of a vertex with the stored plane equation components is positive or zero, 15 | the vertex is in with respect to that clipping plane. Otherwise, it is out. 16 | */ 17 | PUSH_IF_COMPILING(glClipPlanef); //TODO: fix that, equation is an array and should be copied before beeing put in the stack 18 | if((plane=GL_CLIP_PLANE0+hardext.maxplanes)) { 19 | errorShim(GL_INVALID_ENUM); 20 | return; 21 | } 22 | if(hardext.esversion==1) { 23 | LOAD_GLES2(glClipPlanef); 24 | errorGL(); 25 | gles_glClipPlanef(plane, equation); 26 | } else { // TODO: should fist compute the clipplane and compare to stored one before sending to hardware 27 | int p = plane-GL_CLIP_PLANE0; 28 | matrix_vector(getInvMVMat(), equation, glstate->planes[p]); //Tested, seems ok 29 | noerrorShim(); 30 | } 31 | } 32 | 33 | AliasExport(void,glClipPlanef,,(GLenum pname, const GLfloat* params)); -------------------------------------------------------------------------------- /src/gl/planes.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_PLANES_H_ 2 | #define _GL4ES_PLANES_H_ 3 | 4 | #include "gles.h" 5 | 6 | void APIENTRY_GL4ES gl4es_glClipPlanef(GLenum plane, const GLfloat *equation); 7 | 8 | #endif // _GL4ES_PLANES_H_ 9 | -------------------------------------------------------------------------------- /src/gl/pointsprite.c: -------------------------------------------------------------------------------- 1 | #include "pointsprite.h" 2 | 3 | #include "../glx/hardext.h" 4 | #include "debug.h" 5 | #include "fpe.h" 6 | #include "gl4es.h" 7 | #include "glstate.h" 8 | #include "loader.h" 9 | 10 | void APIENTRY_GL4ES gl4es_glPointParameteri(GLenum pname, GLint param) 11 | { 12 | gl4es_glPointParameterf(pname, param); 13 | } 14 | AliasExport(void,glPointParameteri,,(GLenum pname, GLint param)); 15 | 16 | void APIENTRY_GL4ES gl4es_glPointParameteriv(GLenum pname, const GLint * params) 17 | { 18 | GLfloat tmp[3]; 19 | int v=(pname==GL_POINT_DISTANCE_ATTENUATION)?3:1; 20 | for (int i=0; ilist.active) 36 | if (glstate->list.compiling) { 37 | if (pname == GL_POINT_DISTANCE_ATTENUATION) { 38 | NewStage(glstate->list.active, STAGE_POINTPARAM); 39 | rlPointParamOp(glstate->list.active, 1, params); 40 | return; 41 | } else { 42 | gl4es_glPointParameterf(pname, params[0]); 43 | return; 44 | } 45 | } else gl4es_flush(); 46 | 47 | switch(pname) { 48 | case GL_POINT_SIZE_MIN: 49 | if(*params<0.0f) { 50 | errorShim(GL_INVALID_VALUE); 51 | return; 52 | } 53 | if(glstate->pointsprite.sizeMin == *params) { 54 | noerrorShim(); 55 | return; 56 | } 57 | glstate->pointsprite.sizeMin = *params; 58 | break; 59 | case GL_POINT_SIZE_MAX: 60 | if(*params<0.0f) { 61 | errorShim(GL_INVALID_VALUE); 62 | return; 63 | } 64 | if(glstate->pointsprite.sizeMax == *params) { 65 | noerrorShim(); 66 | return; 67 | } 68 | glstate->pointsprite.sizeMax = *params; 69 | break; 70 | case GL_POINT_FADE_THRESHOLD_SIZE: 71 | if(*params<0.0f) { 72 | errorShim(GL_INVALID_VALUE); 73 | return; 74 | } 75 | if(glstate->pointsprite.fadeThresholdSize == *params) { 76 | noerrorShim(); 77 | return; 78 | } 79 | glstate->pointsprite.fadeThresholdSize = *params; 80 | break; 81 | case GL_POINT_DISTANCE_ATTENUATION: 82 | if(*params<0.0f) { 83 | errorShim(GL_INVALID_VALUE); 84 | return; 85 | } 86 | if(memcmp(glstate->pointsprite.distance, params, 3*sizeof(GLfloat))==0) { 87 | noerrorShim(); 88 | return; 89 | } 90 | memcpy(glstate->pointsprite.distance, params, 3*sizeof(GLfloat)); 91 | break; 92 | case GL_POINT_SPRITE_COORD_ORIGIN: 93 | if(*params!=GL_UPPER_LEFT && *params!=GL_LOWER_LEFT) { 94 | errorShim(GL_INVALID_VALUE); 95 | return; 96 | } 97 | if(glstate->pointsprite.coordOrigin == *params) { 98 | noerrorShim(); 99 | return; 100 | } 101 | if(glstate->fpe_state) { 102 | if(*params==GL_LOWER_LEFT) 103 | glstate->fpe_state->pointsprite_upper = 0; 104 | else 105 | glstate->fpe_state->pointsprite_upper = 1; 106 | } 107 | glstate->pointsprite.coordOrigin = *params; 108 | break; 109 | } 110 | 111 | LOAD_GLES_FPE(glPointParameterfv); 112 | errorGL(); 113 | gles_glPointParameterfv(pname, params); 114 | } 115 | AliasExport(void,glPointParameterfv,,(GLenum pname, const GLfloat * params)); 116 | AliasExport(void,glPointParameterfv,ARB,(GLenum pname, const GLfloat * params)); 117 | AliasExport(void,glPointParameterfv,EXT,(GLenum pname, const GLfloat * params)); 118 | 119 | void APIENTRY_GL4ES gl4es_glPointSize(GLfloat size) { 120 | if(size<=0.0f) { 121 | errorShim(GL_INVALID_VALUE); 122 | return; 123 | } 124 | glstate->pointsprite.size = size; 125 | errorGL(); 126 | LOAD_GLES_FPE(glPointSize); 127 | gles_glPointSize(size); 128 | } 129 | AliasExport(void,glPointSize,,(GLfloat size)); 130 | -------------------------------------------------------------------------------- /src/gl/pointsprite.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_POINTSPRITE_H_ 2 | #define _GL4ES_POINTSPRITE_H_ 3 | 4 | #include "gles.h" 5 | 6 | typedef struct { 7 | GLfloat size; 8 | GLfloat sizeMin; 9 | GLfloat sizeMax; 10 | GLfloat fadeThresholdSize; 11 | GLfloat distance[3]; 12 | GLenum coordOrigin; 13 | } pointsprite_t; 14 | 15 | void APIENTRY_GL4ES gl4es_glPointParameteri(GLenum pname, GLint param); 16 | void APIENTRY_GL4ES gl4es_glPointParameteriv(GLenum pname, const GLint * params); 17 | void APIENTRY_GL4ES gl4es_glPointParameterf(GLenum pname, GLfloat param); 18 | void APIENTRY_GL4ES gl4es_glPointParameterfv(GLenum pname, const GLfloat * params); 19 | 20 | void APIENTRY_GL4ES gl4es_glPointSize(GLfloat size); 21 | 22 | #endif // _GL4ES_POINTSPRITE_H_ 23 | -------------------------------------------------------------------------------- /src/gl/preproc.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_PREPROC_H_ 2 | #define _GL4ES_PREPROC_H_ 3 | 4 | typedef struct { 5 | char name[50]; 6 | int state; //0:disable, 1:warn, 1:enable, 2:require 7 | } extension_t; 8 | 9 | typedef struct { 10 | extension_t *ext; 11 | int size; 12 | int cap; 13 | } extensions_t; 14 | 15 | char* preproc(const char* code, int keepcomments, int gl_es, extensions_t* exts, char** versionString); 16 | 17 | #endif // _GL4ES_PREPROC_H_ 18 | -------------------------------------------------------------------------------- /src/gl/queries.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_QUERIES_H_ 2 | #define _GL4ES_QUERIES_H_ 3 | 4 | #include "khash.h" 5 | #include "gles.h" 6 | 7 | void APIENTRY_GL4ES gl4es_glBeginQuery(GLenum target, GLuint id); 8 | void APIENTRY_GL4ES gl4es_glEndQuery(GLenum target); 9 | void APIENTRY_GL4ES gl4es_glGenQueries(GLsizei n, GLuint * ids); 10 | void APIENTRY_GL4ES gl4es_glDeleteQueries(GLsizei n, const GLuint* ids); 11 | GLboolean APIENTRY_GL4ES gl4es_glIsQuery(GLuint id); 12 | void APIENTRY_GL4ES gl4es_glGetQueryiv(GLenum target, GLenum pname, GLint* params); 13 | void APIENTRY_GL4ES gl4es_glGetQueryObjectiv(GLuint id, GLenum pname, GLint* params); 14 | void APIENTRY_GL4ES gl4es_glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params); 15 | void APIENTRY_GL4ES gl4es_glQueryCounter(GLuint id, GLenum target); 16 | void APIENTRY_GL4ES gl4es_glGetQueryObjecti64v(GLuint id, GLenum pname, GLint64 * params); 17 | void APIENTRY_GL4ES gl4es_glGetQueryObjectui64v(GLuint id, GLenum pname, GLuint64 * params); 18 | 19 | unsigned long long get_clock(); 20 | 21 | #endif // _GL4ES_QUERIES_H_ 22 | -------------------------------------------------------------------------------- /src/gl/raster.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_RASTER_H_ 2 | #define _GL4ES_RASTER_H_ 3 | 4 | #include "gles.h" 5 | #include "list.h" 6 | 7 | #ifndef GL_STENCIL_INDEX 8 | #define GL_STENCIL_INDEX 0x1901 9 | #endif // GL_STENCIL_INDEX 10 | #ifndef GL_DEPTH_COMPONENT 11 | #define GL_DEPTH_COMPONENT 0x1902 12 | #endif // GL_DEPTH_COMPONENT 13 | 14 | typedef struct { 15 | GLfloat x; 16 | GLfloat y; 17 | GLfloat z; 18 | } rasterpos_t; 19 | 20 | typedef struct { 21 | GLint x; 22 | GLint y; 23 | GLsizei width; 24 | GLsizei height; 25 | } viewport_t; 26 | 27 | int raster_need_transform(); 28 | 29 | void APIENTRY_GL4ES gl4es_glBitmap(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, 30 | GLfloat xmove, GLfloat ymove, const GLubyte *bitmap); 31 | void APIENTRY_GL4ES gl4es_glDrawPixels(GLsizei width, GLsizei height, GLenum format, 32 | GLenum type, const GLvoid *data); 33 | void APIENTRY_GL4ES gl4es_glRasterPos3f(GLfloat x, GLfloat y, GLfloat z); 34 | void APIENTRY_GL4ES gl4es_glWindowPos3f(GLfloat x, GLfloat y, GLfloat z); 35 | void APIENTRY_GL4ES gl4es_glViewport(GLint x, GLint y, GLsizei width, GLsizei height); 36 | void render_raster(); 37 | 38 | void APIENTRY_GL4ES gl4es_glPixelZoom(GLfloat xfactor, GLfloat yfactor); 39 | 40 | void APIENTRY_GL4ES gl4es_glPixelTransferf(GLenum pname, GLfloat param); 41 | 42 | void APIENTRY_GL4ES gl4es_glPixelMapfv(GLenum map, GLsizei mapsize, const GLfloat *values); 43 | void APIENTRY_GL4ES gl4es_glPixelMapuiv(GLenum map,GLsizei mapsize, const GLuint *values); 44 | void APIENTRY_GL4ES gl4es_glPixelMapusv(GLenum map,GLsizei mapsize, const GLushort *values); 45 | void APIENTRY_GL4ES gl4es_glGetPixelMapfv(GLenum map, GLfloat *data); 46 | void APIENTRY_GL4ES gl4es_glGetPixelMapuiv(GLenum map, GLuint *data); 47 | void APIENTRY_GL4ES gl4es_glGetPixelMapusv(GLenum map, GLushort *data); 48 | 49 | void render_raster_list(rasterlist_t* raster); 50 | 51 | void bitmap_flush(); 52 | 53 | #endif // _GL4ES_RASTER_H_ 54 | -------------------------------------------------------------------------------- /src/gl/render.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_RENDER_H_ 2 | #define _GL4ES_RENDER_H_ 3 | 4 | #include "buffers.h" 5 | #include "gles.h" 6 | 7 | GLint APIENTRY_GL4ES gl4es_glRenderMode(GLenum mode); 8 | void APIENTRY_GL4ES gl4es_glInitNames(void); 9 | void APIENTRY_GL4ES gl4es_glPopName(void); 10 | void APIENTRY_GL4ES gl4es_glPushName(GLuint name); 11 | void APIENTRY_GL4ES gl4es_glLoadName(GLuint name); 12 | void APIENTRY_GL4ES gl4es_glSelectBuffer(GLsizei size, GLuint *buffer); 13 | 14 | void select_glDrawElements(const vertexattrib_t* vtx, GLenum mode, GLuint count, GLenum type, GLvoid * indices); 15 | void select_glDrawArrays(const vertexattrib_t* vtx, GLenum mode, GLuint first, GLuint count); 16 | 17 | #endif // _GL4ES_RENDER_H_ 18 | -------------------------------------------------------------------------------- /src/gl/samplers.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_SAMPLERS_H_ 2 | #define _GL4ES_SAMPLERS_H_ 3 | 4 | #include "gles.h" 5 | 6 | void gl4es_glGenSamplers(GLsizei n, GLuint *ids); 7 | void gl4es_glBindSampler(GLuint unit, GLuint sampler); 8 | void gl4es_glDeleteSamplers(GLsizei n, const GLuint* samplers); 9 | GLboolean gl4es_glIsSampler(GLuint id); 10 | void gl4es_glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param); 11 | void gl4es_glSamplerParameteri(GLuint sampler, GLenum pname, GLint param); 12 | void gl4es_glSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params); 13 | void gl4es_glSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params); 14 | void gl4es_glSamplerParameterIiv(GLuint sampler, GLenum pname, GLint *params); 15 | void gl4es_glSamplerParameterIuiv(GLuint sampler, GLenum pname, GLuint *params); 16 | void gl4es_glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat * params); 17 | void gl4es_glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLfloat * params); 18 | void gl4es_glGetSamplerParameterIiv(GLuint sampler, GLenum pname, GLint * params); 19 | void gl4es_glGetSamplerParameterIuiv(GLuint sampler, GLenum pname, GLuint * params); 20 | 21 | #endif //_GL4ES_SAMPLERS_H_ -------------------------------------------------------------------------------- /src/gl/shader.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_SHADER_H_ 2 | #define _GL4ES_SHADER_H_ 3 | 4 | #include "khash.h" 5 | #include "gles.h" 6 | #include "oldprogram.h" 7 | #include 8 | 9 | typedef struct shaderconv_need_s { 10 | int need_color; // front and back 11 | int need_secondary; // same 12 | int need_fogcoord; 13 | int need_texcoord; // max texcoord needed (-1 for none) 14 | int need_notexarray; // need to not use tex array 15 | int need_normalmatrix; // if normal matrix is needed (for highp / mediump choosing) 16 | int need_mvmatrix; 17 | int need_mvpmatrix; 18 | int need_clean; // this shader needs to stay "clean", no hack in here 19 | int need_clipvertex; 20 | uint32_t need_texs; // flags of what tex is needed 21 | } shaderconv_need_t; 22 | 23 | typedef struct shader_s { 24 | GLuint id; // internal id of the shader 25 | GLenum type; // type of the shader (GL_VERTEX or GL_FRAGMENT) 26 | int attached; // number of time the shader is attached 27 | int deleted;// flagged for deletion 28 | int compiled;// flag if compiled 29 | oldprogram_t *old; // in case the shader is an old ARB ASM-like program 30 | char* source; // original source of the shader (or converted if comming from "old") 31 | char* converted; // converted source (or null if nothing) 32 | // shaderconv 33 | shaderconv_need_t need; // the varying need / provide of the shader 34 | } shader_t; 35 | 36 | KHASH_MAP_DECLARE_INT(shaderlist, shader_t *); 37 | 38 | GLuint APIENTRY_GL4ES gl4es_glCreateShader(GLenum shaderType); 39 | void APIENTRY_GL4ES gl4es_glDeleteShader(GLuint shader); 40 | void APIENTRY_GL4ES gl4es_glCompileShader(GLuint shader); 41 | void APIENTRY_GL4ES gl4es_glShaderSource(GLuint shader, GLsizei count, const GLchar * const *string, const GLint *length); 42 | void APIENTRY_GL4ES gl4es_glGetShaderSource(GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); 43 | GLboolean APIENTRY_GL4ES gl4es_glIsShader(GLuint shader); 44 | void APIENTRY_GL4ES gl4es_glGetShaderInfoLog(GLuint shader, GLsizei maxLength, GLsizei *length, GLchar *infoLog); 45 | void APIENTRY_GL4ES gl4es_glGetShaderiv(GLuint shader, GLenum pname, GLint *params); 46 | void APIENTRY_GL4ES gl4es_glGetShaderPrecisionFormat(GLenum shaderType, GLenum precisionType, GLint *range, GLint *precision); 47 | void APIENTRY_GL4ES gl4es_glShaderBinary(GLsizei count, const GLuint *shaders, GLenum binaryFormat, const void *binary, GLsizei length); 48 | void APIENTRY_GL4ES gl4es_glReleaseShaderCompiler(void); 49 | 50 | void accumShaderNeeds(GLuint shader, shaderconv_need_t *need); 51 | int isShaderCompatible(GLuint shader, shaderconv_need_t *need); 52 | void redoShader(GLuint shader, shaderconv_need_t *need); 53 | shader_t *getShader(GLuint shader); 54 | 55 | #define CHECK_SHADER(type, shader) \ 56 | if(!shader) { \ 57 | noerrorShim(); \ 58 | return (type)0; \ 59 | } \ 60 | shader_t *glshader = NULL; \ 61 | khint_t k_##shader; \ 62 | { \ 63 | khash_t(shaderlist) *shaders = glstate->glsl->shaders; \ 64 | k_##shader = kh_get(shaderlist, shaders, shader); \ 65 | if (k_##shader != kh_end(shaders)) \ 66 | glshader = kh_value(shaders, k_##shader); \ 67 | } \ 68 | if (!glshader) { \ 69 | errorShim(GL_INVALID_OPERATION); \ 70 | return (type)0; \ 71 | } 72 | 73 | // ========== GL_ARB_shader_objects ============== 74 | 75 | GLhandleARB APIENTRY_GL4ES gl4es_glCreateShaderObject(GLenum shaderType); 76 | 77 | #endif // _GL4ES_SHADER_H_ 78 | -------------------------------------------------------------------------------- /src/gl/shader_hacks.h: -------------------------------------------------------------------------------- 1 | #ifndef __SHADER_HACKS_H__ 2 | #define __SHADER_HACKS_H__ 3 | 4 | char* ShaderHacks(char* shader); 5 | 6 | #endif //__SHADER_HACKS_H__ -------------------------------------------------------------------------------- /src/gl/shaderconv.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_SHADERCONV_H_ 2 | #define _GL4ES_SHADERCONV_H_ 3 | 4 | #include "gles.h" 5 | #include "program.h" 6 | 7 | char* ConvertShader(const char* pBuffer, int isVertex, shaderconv_need_t *need); 8 | 9 | int isBuiltinAttrib(const char* name); 10 | int isBuiltinMatrix(const char* name); 11 | 12 | const char* hasBuiltinAttrib(const char* vertexShader, int Att); 13 | const char* builtinAttribGLName(const char* name); 14 | const char* builtinAttribInternalName(const char* name); 15 | 16 | #endif // _GL4ES_SHADERCONV_H_ 17 | -------------------------------------------------------------------------------- /src/gl/stack.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_STACK_H_ 2 | #define _GL4ES_STACK_H_ 3 | 4 | #include "gles.h" 5 | #include "state.h" 6 | #include "texture.h" 7 | #include 8 | 9 | #define STACK_SIZE 16 10 | 11 | #define GL4ES_HINT_FIRST GL_SHRINK_HINT_GL4ES 12 | #define GL4ES_HINT_LAST (GL_NOERROR_HINT_GL4ES + 1) 13 | 14 | 15 | typedef struct _glstack_t { 16 | GLbitfield mask; 17 | 18 | // GL_COLOR_BUFFER_BIT 19 | GLboolean alpha_test; 20 | GLint alpha_test_func; 21 | GLclampf alpha_test_ref; 22 | 23 | GLboolean blend; 24 | GLint blend_src_func; 25 | GLint blend_dst_func; 26 | 27 | GLboolean dither; 28 | 29 | // point sprite 30 | GLboolean pointsprite; 31 | GLint pscoordreplace[MAX_TEX]; 32 | 33 | GLboolean color_logic_op; 34 | GLint logic_op; 35 | 36 | GLfloat clear_color[4]; 37 | GLfloat color_mask[4]; 38 | 39 | // GL_CURRENT_BIT 40 | GLfloat color[4]; 41 | GLfloat normal[4]; 42 | GLfloat tex[4]; 43 | GLfloat secondary[4]; 44 | 45 | // TODO: can only fill this via raster.c 46 | GLfloat raster_pos[3]; 47 | GLboolean raster_valid; 48 | GLfloat pixel_scale_bias[4+4]; 49 | GLfloat pixel_zoomx; 50 | GLfloat pixel_zoomy; 51 | 52 | // GL_DEPTH_BUFFER_BIT 53 | GLboolean depth_test; 54 | GLint depth_func; 55 | GLfloat clear_depth; 56 | GLint depth_mask; 57 | 58 | // GL_ENABLE_BIT 59 | GLboolean cull_face; 60 | GLboolean normalize; 61 | GLboolean polygon_offset_fill; 62 | GLboolean stencil_test; 63 | GLuint tex_enabled[MAX_TEX]; 64 | GLboolean texgen_s[MAX_TEX]; 65 | GLboolean texgen_r[MAX_TEX]; 66 | GLboolean texgen_t[MAX_TEX]; 67 | GLboolean texgen_q[MAX_TEX]; 68 | GLboolean colormaterial; 69 | GLboolean autonormal; 70 | 71 | // GL_FOG_BIT 72 | GLboolean fog; 73 | GLfloat fog_color[4]; 74 | GLfloat fog_density; 75 | GLfloat fog_start; 76 | GLfloat fog_end; 77 | GLint fog_mode; 78 | 79 | // GL_HINT_BIT 80 | GLint perspective_hint; 81 | GLint point_smooth_hint; 82 | GLint line_smooth_hint; 83 | GLint fog_hint; 84 | GLint mipmap_hint; 85 | GLint gles4_hint[GL4ES_HINT_LAST-GL4ES_HINT_FIRST]; 86 | 87 | // GL_LIGHTING_BIT 88 | GLboolean lighting; 89 | GLboolean *lights_enabled; 90 | GLfloat *lights; 91 | GLfloat light_model_ambient[4]; 92 | GLint light_model_two_side; 93 | GLfloat *materials; 94 | GLint shade_model; 95 | 96 | // GL_LINE_BIT 97 | GLboolean line_smooth; 98 | GLboolean line_stipple; // TODO: needs to be hooked locally? 99 | GLfloat line_width; 100 | 101 | // GL_LIST_BIT 102 | GLint list_base; 103 | 104 | // GL_MULTISAMPLE_BIT 105 | GLboolean multisample; 106 | GLboolean sample_alpha_to_coverage; 107 | GLboolean sample_alpha_to_one; 108 | GLboolean sample_coverage; 109 | 110 | // GL_POINT_BIT 111 | GLboolean point_smooth; 112 | GLfloat point_size; 113 | 114 | // TODO: GL_POLYGON_BIT 115 | // TODO: GL_POLYGON_STIPPLE_BIT 116 | 117 | // GL_SCISSOR_BIT 118 | GLboolean scissor_test; 119 | GLfloat scissor_box[4]; 120 | 121 | // GL_STENCIL_BUFFER_BIT 122 | GLenum stencil_func; 123 | GLint stencil_ref; 124 | GLuint stencil_mask; 125 | GLint stencil_clearvalue; 126 | GLenum stencil_sfail; 127 | GLenum stencil_dpfail; 128 | GLenum stencil_dppass; 129 | 130 | // GL_TEXTURE_BIT 131 | GLint texture[MAX_TEX][ENABLED_TEXTURE_LAST]; 132 | texgen_state_t texgen[MAX_TEX]; 133 | GLint active; 134 | 135 | // GL_TRANSFORM_BIT 136 | // with Clip Planes... 137 | GLenum matrix_mode; 138 | GLboolean normalize_flag; 139 | GLboolean rescale_normal_flag; 140 | // GL_VIEWPORT_BIT 141 | GLint viewport_size[4]; 142 | GLfloat depth_range[2]; 143 | 144 | // dynamically-sized shenanigans 145 | GLboolean *clip_planes_enabled; 146 | GLfloat *clip_planes; 147 | 148 | // misc 149 | unsigned int len; 150 | unsigned int cap; 151 | } glstack_t; 152 | 153 | typedef struct _glclientstack_t { 154 | GLbitfield mask; 155 | 156 | // GL_CLIENT_PIXEL_STORE_BIT 157 | GLint pack_align; 158 | GLint unpack_align; 159 | GLuint unpack_row_length; 160 | GLuint unpack_skip_pixels; 161 | GLuint unpack_skip_rows; 162 | GLuint pack_row_length; 163 | GLuint pack_skip_pixels; 164 | GLuint pack_skip_rows; 165 | 166 | // GL_CLIENT_VERTEX_ARRAY_BIT 167 | GLuint client; 168 | vertexattrib_t vertexattrib[MAX_VATTRIB]; 169 | unsigned int len; 170 | unsigned int cap; 171 | } glclientstack_t; 172 | 173 | void APIENTRY_GL4ES gl4es_glPushClientAttrib(GLbitfield mask); 174 | void APIENTRY_GL4ES gl4es_glPopClientAttrib(void); 175 | void APIENTRY_GL4ES gl4es_glPushAttrib(GLbitfield mask); 176 | void APIENTRY_GL4ES gl4es_glPopAttrib(void); 177 | 178 | #endif // _GL4ES_STACK_H_ 179 | -------------------------------------------------------------------------------- /src/gl/stencil.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_STENCIL_H_ 2 | #define _GL4ES_STENCIL_H_ 3 | 4 | #include "gles.h" 5 | 6 | typedef struct { 7 | GLenum func[2]; 8 | GLint f_ref[2]; 9 | GLuint f_mask[2]; 10 | GLuint mask[2]; 11 | GLenum sfail[2]; 12 | GLenum dpfail[2]; 13 | GLenum dppass[2]; 14 | GLint clear; 15 | } stencil_t; 16 | 17 | #endif // _GL4ES_STENCIL_H_ 18 | -------------------------------------------------------------------------------- /src/gl/string_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_STRING_UTILS_H_ 2 | #define _GL4ES_STRING_UTILS_H_ 3 | 4 | extern const char* AllSeparators; 5 | 6 | const char* FindString(const char* pBuffer, const char* S); 7 | char* FindStringNC(char* pBuffer, const char* S); 8 | int CountString(const char* pBuffer, const char* S); 9 | char* ResizeIfNeeded(char* pBuffer, int *size, int addsize); 10 | char* InplaceReplace(char* pBuffer, int* size, const char* S, const char* D); 11 | char* Append(char* pBuffer, int* size, const char* S); 12 | char* InplaceInsert(char* pBuffer, const char* S, char* master, int* size); 13 | char* GetLine(char* pBuffer, int num); 14 | int CountLine(const char* pBuffer); 15 | int GetLineFor(const char* pBuffer, const char* S); // get the line number for 1st occurent of S in pBuffer 16 | char* StrNext(char *pBuffer, const char* S); // mostly as strstr, but go after the substring if found 17 | //"blank" (space, tab, cr, lf,":", ",", ";", ".", "/") 18 | char* NextStr(char* pBuffer); // go to next non "blank" 19 | char* NextBlank(char* pBuffer); // go to next "blank" 20 | char* NextLine(char* pBuffer); // go to next new line (crlf not included) 21 | 22 | const char* GetNextStr(char* pBuffer); // get a (static) copy of next str (until next separator), can be a simple number or separator also 23 | 24 | // those function don't try to be smart with separators... 25 | int CountStringSimple(char* pBuffer, const char* S); 26 | char* InplaceReplaceSimple(char* pBuffer, int* size, const char* S, const char* D); 27 | 28 | 29 | #endif // _GL4ES_STRING_UTILS_H_ 30 | -------------------------------------------------------------------------------- /src/gl/texenv.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_TEXENV_H_ 2 | #define _GL4ES_TEXENV_H_ 3 | 4 | #include "gles.h" 5 | 6 | typedef struct { 7 | GLenum mode; 8 | GLfloat color[4]; 9 | GLenum combine_rgb; 10 | GLenum combine_alpha; 11 | GLfloat rgb_scale; 12 | GLfloat alpha_scale; 13 | GLenum src0_rgb; 14 | GLenum src1_rgb; 15 | GLenum src2_rgb; 16 | GLenum src3_rgb; 17 | GLenum src0_alpha; 18 | GLenum src1_alpha; 19 | GLenum src2_alpha; 20 | GLenum src3_alpha; 21 | GLenum op0_rgb; 22 | GLenum op1_rgb; 23 | GLenum op2_rgb; 24 | GLenum op3_rgb; 25 | GLenum op0_alpha; 26 | GLenum op1_alpha; 27 | GLenum op2_alpha; 28 | GLenum op3_alpha; 29 | } texenv_t; 30 | 31 | typedef struct { 32 | GLenum lod_bias; 33 | } texfilter_t; 34 | 35 | void APIENTRY_GL4ES gl4es_glTexEnvf(GLenum target, GLenum pname, GLfloat param); 36 | void APIENTRY_GL4ES gl4es_glTexEnvi(GLenum target, GLenum pname, GLint param); 37 | void APIENTRY_GL4ES gl4es_glTexEnvfv(GLenum target, GLenum pname, const GLfloat *param); 38 | void APIENTRY_GL4ES gl4es_glTexEnviv(GLenum target, GLenum pname, const GLint *param); 39 | void APIENTRY_GL4ES gl4es_glGetTexEnvfv(GLenum target, GLenum pname, GLfloat * params); 40 | void APIENTRY_GL4ES gl4es_glGetTexEnviv(GLenum target, GLenum pname, GLint * params); 41 | 42 | #endif // _GL4ES_TEXENV_H_ 43 | -------------------------------------------------------------------------------- /src/gl/texgen.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_TEXGEN_H_ 2 | #define _GL4ES_TEXGEN_H_ 3 | 4 | #include "gles.h" 5 | 6 | void APIENTRY_GL4ES gl4es_glTexGenfv(GLenum coord, GLenum pname, const GLfloat *params); 7 | void APIENTRY_GL4ES gl4es_glTexGeni(GLenum coord, GLenum pname, GLint param); 8 | void gen_tex_coords(GLfloat *verts, GLfloat *norm, GLfloat **coords, GLint count, GLint *needclean, int texture, GLushort* indices, GLuint ilen); 9 | void gen_tex_clean(GLint cleancode, int texture); 10 | void APIENTRY_GL4ES gl4es_glGetTexGenfv(GLenum coord,GLenum pname,GLfloat *params); 11 | 12 | void APIENTRY_GL4ES gl4es_glLoadTransposeMatrixf(const GLfloat *m); 13 | void APIENTRY_GL4ES gl4es_glLoadTransposeMatrixd(const GLdouble *m); 14 | void APIENTRY_GL4ES gl4es_glMultTransposeMatrixd(const GLdouble *m); 15 | void APIENTRY_GL4ES gl4es_glMultTransposeMatrixf(const GLfloat *m); 16 | 17 | #endif // _GL4ES_TEXGEN_H_ 18 | -------------------------------------------------------------------------------- /src/gl/texture_3d.c: -------------------------------------------------------------------------------- 1 | #include "texture.h" 2 | 3 | #include "../glx/hardext.h" 4 | #include "../glx/streaming.h" 5 | #include "array.h" 6 | #include "blit.h" 7 | #include "decompress.h" 8 | #include "debug.h" 9 | #include "enum_info.h" 10 | #include "fpe.h" 11 | #include "framebuffers.h" 12 | #include "gles.h" 13 | #include "init.h" 14 | #include "loader.h" 15 | #include "matrix.h" 16 | #include "pixel.h" 17 | #include "raster.h" 18 | 19 | //#define DEBUG 20 | #ifdef DEBUG 21 | #define DBG(a) a 22 | #else 23 | #define DBG(a) 24 | #endif 25 | 26 | // 3d stubs 27 | void APIENTRY_GL4ES gl4es_glTexImage3D(GLenum target, GLint level, GLint internalFormat, 28 | GLsizei width, GLsizei height, GLsizei depth, GLint border, 29 | GLenum format, GLenum type, const GLvoid *data) { 30 | 31 | // TODO: maybe too naive to force GL_TEXTURE_2D here? 32 | gl4es_glTexImage2D(GL_TEXTURE_3D, level, internalFormat, width, height, 33 | border, format, type, data); 34 | } 35 | void APIENTRY_GL4ES gl4es_glTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, 36 | GLsizei width, GLsizei height, GLsizei depth, GLenum format, 37 | GLenum type, const GLvoid *data) { 38 | 39 | gl4es_glTexSubImage2D(GL_TEXTURE_3D, level, xoffset, yoffset, 40 | width, height, format, type, data); 41 | } 42 | 43 | void APIENTRY_GL4ES gl4es_glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth) 44 | { 45 | DBG(printf("glTexStorage3D(%s, %d, %s, %d, %d, %d)\n", PrintEnum(target), levels, PrintEnum(internalformat), width, height, depth);) 46 | gl4es_glTexImage3D(target, 0, internalformat, width, height, depth, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 47 | } 48 | 49 | void APIENTRY_GL4ES gl4es_glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, 50 | GLint x, GLint y, GLsizei width, GLsizei height) { 51 | gl4es_glCopyTexSubImage2D(GL_TEXTURE_3D, level, xoffset, yoffset, x, y, width, height); 52 | } 53 | 54 | 55 | //Direct wrapper 56 | AliasExport(void,glTexImage3D,,(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *data)); 57 | AliasExport(void,glTexImage3D,EXT,(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *data)); 58 | AliasExport(void,glTexSubImage3D,,(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *data)); 59 | AliasExport(void,glCopyTexSubImage3D,,(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)); 60 | 61 | //EXT mapper 62 | AliasExport(void,glTexSubImage3D,EXT,(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *data)); 63 | AliasExport(void,glCopyTexSubImage3D,EXT,(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)); 64 | 65 | //ARB mapper 66 | AliasExport(void,glTexSubImage3D,ARB,(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *data)); 67 | AliasExport(void,glCopyTexSubImage3D,ARB,(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)); 68 | 69 | // TexStorage 70 | AliasExport(void,glTexStorage3D,,(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)); 71 | -------------------------------------------------------------------------------- /src/gl/vertexattrib.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_VERTEXATTRIB_H_ 2 | #define _GL4ES_VERTEXATTRIB_H_ 3 | 4 | #include "gles.h" 5 | 6 | // actual definition of vertexattrib_t is in buffer.h, as they are part of VAO... 7 | 8 | void APIENTRY_GL4ES gl4es_glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer); 9 | void APIENTRY_GL4ES gl4es_glEnableVertexAttribArray(GLuint index); 10 | void APIENTRY_GL4ES gl4es_glDisableVertexAttribArray(GLuint index); 11 | 12 | // other variant are defined in wrap... 13 | void APIENTRY_GL4ES gl4es_glVertexAttrib4f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); 14 | void APIENTRY_GL4ES gl4es_glVertexAttrib4fv(GLuint index, const GLfloat *v); 15 | 16 | 17 | void APIENTRY_GL4ES gl4es_glGetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params); 18 | void APIENTRY_GL4ES gl4es_glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params); 19 | void APIENTRY_GL4ES gl4es_glGetVertexAttribiv(GLuint index, GLenum pname, GLint *params); 20 | void APIENTRY_GL4ES gl4es_glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer); 21 | 22 | // GL_ARB_instanced_arrays 23 | void APIENTRY_GL4ES gl4es_glVertexAttribDivisor(GLuint index, GLuint divisor); 24 | 25 | #endif // _GL4ES_VERTEXATTRIB_H_ 26 | -------------------------------------------------------------------------------- /src/gl/wrap/glstub.c: -------------------------------------------------------------------------------- 1 | #include "stub.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include "../envvars.h" 7 | #include "../attributes.h" 8 | 9 | #define STUB(ret, def, args)\ 10 | ret APIENTRY_GL4ES gl4es_ ## def args {\ 11 | if(IsEnvVarTrue("LIBGL_DEBUG"))\ 12 | printf("stub: %s;\n", #def);\ 13 | } \ 14 | AliasExport(ret,def,,args); 15 | 16 | /*STUB(void,glFogCoordd,(GLdouble coord)); 17 | STUB(void,glFogCoordf,(GLfloat coord)); 18 | STUB(void,glFogCoorddv,(const GLdouble *coord)); 19 | STUB(void,glFogCoordfv,(const GLfloat *coord));*/ 20 | #ifdef BCMHOST 21 | STUB(void,glDiscardFramebufferEXT,(GLenum target, GLsizei numAttachments, const GLenum *attachments)); 22 | #endif 23 | 24 | /* 25 | STUB(void glBlendEquationSeparatei(GLuint buf, GLenum modeRGB, GLenum modeAlpha)) 26 | STUB(void glBlendFuncSeparatei(GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)) 27 | */ 28 | STUB(void,glClearAccum,(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)); 29 | //STUB(void,glColorMaterial,(GLenum face, GLenum mode)); 30 | STUB(void,glCopyPixels,(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type)); 31 | STUB(void,glDrawBuffer,(GLenum mode)); 32 | STUB(void,glEdgeFlag,(GLboolean flag)); 33 | STUB(void,glIndexf,(GLfloat c)); 34 | STUB(void,glPolygonStipple,(const GLubyte *mask)); 35 | STUB(void,glReadBuffer,(GLenum mode)); 36 | //STUB(void glSecondaryColor3f(GLfloat r, GLfloat g, GLfloat b)); 37 | STUB(void,glColorTable,(GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table)); 38 | 39 | STUB(void,glAccum,(GLenum op, GLfloat value)); 40 | STUB(void,glPrioritizeTextures,(GLsizei n, const GLuint *textures, const GLclampf *priorities)); 41 | //STUB(void,glPixelMapfv,(GLenum map, GLsizei mapsize, const GLfloat *values)); 42 | //STUB(void,glPixelMapuiv,(GLenum map,GLsizei mapsize, const GLuint *values)); 43 | //STUB(void,glPixelMapusv,(GLenum map,GLsizei mapsize, const GLushort *values)); 44 | STUB(void,glPassThrough,(GLfloat token)); 45 | STUB(void,glIndexMask,(GLuint mask)); 46 | //STUB(void,glGetPixelMapfv,(GLenum map, GLfloat *data)); 47 | //STUB(void,glGetPixelMapuiv,(GLenum map, GLuint *data)); 48 | //STUB(void,glGetPixelMapusv,(GLenum map, GLushort *data)); 49 | STUB(void,glClearIndex,(GLfloat c)); 50 | STUB(void,glGetPolygonStipple,(GLubyte *pattern)); 51 | STUB(void,glFeedbackBuffer,(GLsizei size, GLenum type, GLfloat *buffer)); 52 | STUB(void,glEdgeFlagv,(GLboolean *flag)); 53 | //STUB(void glIndexPointer(GLenum type, GLsizei stride, const GLvoid * pointer)); 54 | #undef STUB 55 | -------------------------------------------------------------------------------- /src/gl/wrap/stub.h: -------------------------------------------------------------------------------- 1 | #include "../gles.h" 2 | 3 | //GLint APIENTRY_GL4ES gl4es_glRenderMode(GLenum mode); 4 | //void APIENTRY_GL4ES gl4es_glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha); 5 | void APIENTRY_GL4ES gl4es_glBlendEquationSeparatei(GLuint buf, GLenum modeRGB, GLenum modeAlpha); 6 | //void APIENTRY_GL4ES gl4es_glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); 7 | void APIENTRY_GL4ES gl4es_glBlendFuncSeparatei(GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); 8 | //void APIENTRY_GL4ES gl4es_glColorMaterial(GLenum face, GLenum mode); 9 | void APIENTRY_GL4ES gl4es_glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type); 10 | void APIENTRY_GL4ES gl4es_glDrawBuffer(GLenum mode); 11 | void APIENTRY_GL4ES gl4es_glEdgeFlag(GLboolean flag); 12 | //void APIENTRY_GL4ES gl4es_glFogCoordd(GLdouble coord); 13 | //void APIENTRY_GL4ES gl4es_glFogCoorddv(const GLdouble *coord); 14 | //void APIENTRY_GL4ES gl4es_glFogCoordf(GLfloat coord); 15 | //void APIENTRY_GL4ES gl4es_glFogCoordfv(const GLfloat *coord); 16 | //void APIENTRY_GL4ES gl4es_glGetTexImage(GLenum target, GLint level, GLenum format, GLenum type, GLvoid * img); 17 | //void APIENTRY_GL4ES gl4es_glGetTexLevelParameterfv(GLenum target, GLint level, GLenum pname, GLfloat *params); 18 | //void APIENTRY_GL4ES gl4es_glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params); 19 | void APIENTRY_GL4ES gl4es_glIndexf(GLfloat c); 20 | void APIENTRY_GL4ES gl4es_glLightModeli(GLenum pname, GLint param); 21 | void APIENTRY_GL4ES gl4es_glPolygonStipple(const GLubyte *mask); 22 | void APIENTRY_GL4ES gl4es_glReadBuffer(GLenum mode); 23 | void APIENTRY_GL4ES gl4es_glSecondaryColor3f(GLfloat r, GLfloat g, GLfloat b); 24 | void APIENTRY_GL4ES gl4es_glColorTable (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); 25 | //void APIENTRY_GL4ES gl4es_glIndexPointer(GLenum type, GLsizei stride, const GLvoid * pointer); 26 | 27 | void APIENTRY_GL4ES gl4es_glAccum(GLenum op, GLfloat value); 28 | void APIENTRY_GL4ES gl4es_glPrioritizeTextures(GLsizei n, const GLuint *textures, const GLclampf *priorities); 29 | void APIENTRY_GL4ES gl4es_glPixelMapfv(GLenum map, GLsizei mapsize, const GLfloat *values); 30 | void APIENTRY_GL4ES gl4es_glPixelMapuiv(GLenum map,GLsizei mapsize, const GLuint *values); 31 | void APIENTRY_GL4ES gl4es_glPixelMapusv(GLenum map,GLsizei mapsize, const GLushort *values); 32 | void APIENTRY_GL4ES gl4es_glPassThrough(GLfloat token); 33 | void APIENTRY_GL4ES gl4es_glIndexMask(GLuint mask); 34 | void APIENTRY_GL4ES gl4es_glGetPixelMapfv(GLenum map, GLfloat *data); 35 | void APIENTRY_GL4ES gl4es_glGetPixelMapuiv(GLenum map, GLuint *data); 36 | void APIENTRY_GL4ES gl4es_glGetPixelMapusv(GLenum map, GLushort *data); 37 | void APIENTRY_GL4ES gl4es_glClearIndex(GLfloat c); 38 | void APIENTRY_GL4ES gl4es_glGetPolygonStipple(GLubyte *pattern); 39 | void APIENTRY_GL4ES gl4es_glFeedbackBuffer(GLsizei size, GLenum type, GLfloat *buffer); 40 | void APIENTRY_GL4ES gl4es_glEdgeFlagv(GLboolean *flag); 41 | -------------------------------------------------------------------------------- /src/glx/drmfunc.h: -------------------------------------------------------------------------------- 1 | #ifdef DRMFUNC 2 | 3 | DRMFUNC(drmModeResPtr,drmModeGetResources,(int fd)) 4 | DRMFUNC(drmModeConnectorPtr,drmModeGetConnector,(int fd, uint32_t connectorId)) 5 | DRMFUNC(void, drmModeFreeConnector,(drmModeConnectorPtr ptr)) 6 | DRMFUNC(drmModeEncoderPtr,drmModeGetEncoder,(int fd, uint32_t encoder_id)) 7 | DRMFUNC(void,drmModeFreeEncoder,(drmModeEncoderPtr ptr)) 8 | DRMFUNC(int,drmModeRmFB,(int fd, uint32_t bufferId)) 9 | DRMFUNC(int,drmModeAddFB,(int fd, uint32_t width, uint32_t height, uint8_t depth, uint8_t bpp, uint32_t pitch, uint32_t bo_handle, uint32_t *buf_id)) 10 | DRMFUNC(int,drmModeSetCrtc,(int fd, uint32_t crtcId, uint32_t bufferId, uint32_t x, uint32_t y, uint32_t *connectors, int count, drmModeModeInfoPtr mode)) 11 | 12 | #endif -------------------------------------------------------------------------------- /src/glx/gbmfunc.h: -------------------------------------------------------------------------------- 1 | #ifdef GBMFUNC 2 | 3 | GBMFUNC(int,gbm_device_get_fd,(struct gbm_device *gbm)) 4 | GBMFUNC(int,gbm_device_is_format_supported,(struct gbm_device *gbm, 5 | uint32_t format, uint32_t usage)) 6 | GBMFUNC(void,gbm_device_destroy,(struct gbm_device *gbm)) 7 | GBMFUNC(struct gbm_device *,gbm_create_device,(int fd)) 8 | GBMFUNC(unsigned int,gbm_bo_get_width,(struct gbm_bo *bo)) 9 | GBMFUNC(unsigned int,gbm_bo_get_height,(struct gbm_bo *bo)) 10 | GBMFUNC(uint32_t,gbm_bo_get_stride,(struct gbm_bo *bo)) 11 | GBMFUNC(union gbm_bo_handle,gbm_bo_get_handle,(struct gbm_bo *bo)) 12 | GBMFUNC(int,gbm_bo_write,(struct gbm_bo *bo, const void *buf, size_t count)) 13 | GBMFUNC(struct gbm_device *,gbm_bo_get_device,(struct gbm_bo *bo)) 14 | GBMFUNC(void,gbm_bo_set_user_data,(struct gbm_bo *bo, void *data, 15 | void (*destroy_user_data)(struct gbm_bo *, void *))) 16 | GBMFUNC(void *,gbm_bo_get_user_data,(struct gbm_bo *bo)) 17 | GBMFUNC(void,gbm_bo_destroy,(struct gbm_bo *bo)) 18 | GBMFUNC(struct gbm_bo *,gbm_bo_create,(struct gbm_device *gbm, 19 | uint32_t width, uint32_t height, 20 | uint32_t format, uint32_t usage)) 21 | GBMFUNC(struct gbm_surface *,gbm_surface_create,(struct gbm_device *gbm, 22 | uint32_t width, uint32_t height, 23 | uint32_t format, uint32_t flags)) 24 | GBMFUNC(void,gbm_surface_destroy,(struct gbm_surface *surf)) 25 | GBMFUNC(struct gbm_bo *,gbm_surface_lock_front_buffer,(struct gbm_surface *surf)) 26 | GBMFUNC(void,gbm_surface_release_buffer,(struct gbm_surface *surf, struct gbm_bo *bo)) 27 | 28 | #endif -------------------------------------------------------------------------------- /src/glx/glx_gbm.h: -------------------------------------------------------------------------------- 1 | #ifndef _GLX_GBM_H_ 2 | #define _GLX_GBM_H_ 3 | 4 | #ifndef NOEGL 5 | #include 6 | #endif 7 | 8 | void LoadGBMFunctions(); 9 | void CloseGBMFunctions(); 10 | 11 | void* OpenGBMDisplay(void* display); 12 | 13 | void* CreateGBMWindow(int w, int h); 14 | void DeleteGBMWindow(void* win); 15 | 16 | #if !defined(NOEGL) && !defined(ANDROID) 17 | int FindGBMConfig(EGLDisplay eglDisp, EGLConfig *configs, int numFounds); 18 | EGLBoolean GBMMakeCurrent(EGLDisplay eglDisp, EGLSurface draw, EGLSurface read, EGLContext ctx); 19 | #endif 20 | 21 | #endif // _GLX_GBM_H_ 22 | -------------------------------------------------------------------------------- /src/glx/hardext.h: -------------------------------------------------------------------------------- 1 | #ifndef _GLX_HARDEXT_H_ 2 | #define _GLX_HARDEXT_H_ 3 | 4 | #include "../gl/attributes.h" 5 | 6 | #define VEND_IMGTEC 0x0100 7 | #define VEND_ARM 0x0200 8 | 9 | #define MAX_PRGBIN 10 10 | 11 | typedef struct _hardext { 12 | int npot; // 0 = no npot capability, 1 = limited npot, 2 = full npot 13 | int maxtex; // maximum number of texture 14 | int maxlights; // maximum number of light 15 | int maxsize; // maximum texture size 16 | int maxplanes; // maximum clip planes 17 | int blendsub; // GL_OES_blend_subtract 18 | int blendfunc; // GL_OES_blend_func_separate 19 | int blendeq; // GL_OES_blend_equation_separate 20 | int blendminmax; // GL_EXT_blend_minmax 21 | int blendcolor; // GL_EXT_blend_color 22 | int pointsprite; // GL_OES_point_sprite 23 | int pointsize; // GL_OES_point_size_array 24 | int elementuint; // GL_OES_element_index_uint 25 | int fbo; // GL_OES_framebuffer_object 26 | int depthstencil; // GL_OES_packed_depth_stencil 27 | int depth24; // GL_OES_depth24 28 | int rgba8; // GL_OES_rgb8_rgba8 29 | int multidraw; // GL_EXT_multi_draw_arrays 30 | int bgra8888; // GL_EXT_texture_format_BGRA8888 31 | int depthtex; // GL_OES_depth_texture 32 | int stenciltex; // GL_OES_texture_stencil8 33 | int cubemap; // GL_OES_texture_cube_map 34 | int drawtex; // GL_OES_draw_texture 35 | int rgtex; // GL_EXT_texture_rg 36 | int floattex; // GL_OES_texture_float 37 | int halffloattex; // GL_OES_texture_half_float 38 | int floatfbo; // GL_EXT_color_buffer_float 39 | int halffloatfbo; // GL_EXT_color_buffer_half_float 40 | int rgb332; // GL_AOS4_texture_format_RGB332 41 | int rgb332rev; // GL_AOS4_texture_format_RGB332REV 42 | int rgba1555rev; // GL_AOS4_texture_format_RGBA1555REV 43 | int rgba8888; // GL_AOS4_texture_format_RGBA8888 44 | int rgba8888rev; // GL_AOS4_texture_format_RGBA8888REV 45 | int mirrored; // GL_OES_texture_mirrored_repeat 46 | int aniso; // Max ANISOTROPIC filter available (0 if not) 47 | int srgb; // EGL_KHR_gl_colorspace 48 | int mapbuffer; // GL_OES_mapbuffer 49 | int drawbuffers; // GL_EXT_draw_buffers 50 | // es2 stuffs 51 | int esversion; // 1 is ES1.1 backend, 2 is ES2 52 | int maxvattrib; // GL_MAX_VERTEX_ATTRIBS (or 0 if not using es2) 53 | int maxteximage; // GL_MAX_TEXTURE_IMAGE_UNITS for es2 54 | int maxvarying; // GL_MAX_VARYING_VECTORS for es2 55 | int maxcolorattach; // GL_MAX_COLOR_ATTACHMENTS_EXT or 1 if GL_EXT_draw_buffers not supported 56 | int maxdrawbuffers; // GL_MAX_DRAW_BUFFERS_EXT or 1 if GL_EXT_draw_buffers not supported 57 | int highp; // GL_OES_fragment_precision_high 58 | int fragdepth; // GL_EXT_frag_depth 59 | int derivatives; // GL_OES_standard_derivatives 60 | int shaderlod; // GL_EXT_shader_texture_lod 61 | int cubelod; // textureCubeLod doesn't need "EXT" even with GL_EXT_shader_texture_lod 62 | int gbm; // EGL_KHR_platform_gbm 63 | int khr_pixmap; // EGL_KHR_image_pixmap 64 | int khr_texture_2d; // EGL_KHR_gl_texture_2D_image 65 | int khr_renderbuffer; // EGL_KHR_gl_renderbuffer_image 66 | int vendor; // which vendor (to apply workaround) 67 | int eglnoalpha; // EGL surface doesn't seems to have any alpha channel (auto detect) 68 | int prgbinary; // GL_OES_get_program extension 69 | int prgbin_n; // number of program binary format support 70 | int glsl120; // does version 120 glsl shader are supported ? 71 | int glsl300es; // does version 300es glsl shader are supported ? 72 | int glsl310es; // does version 300es glsl shader are supported ? 73 | } hardext_t; 74 | 75 | EXPORT extern hardext_t hardext; 76 | 77 | EXPORT void GetHardwareExtensions(int test); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /src/glx/lookup.c: -------------------------------------------------------------------------------- 1 | #include "../gl/attributes.h" 2 | #include "../gl/init.h" 3 | #include "../gl/logs.h" 4 | 5 | #define STUB_FCT glXStub 6 | #include "../gl/gl_lookup.h" 7 | 8 | #include "glx.h" 9 | #include "hardext.h" 10 | 11 | 12 | void glXStub(void *x, ...) { 13 | return; 14 | } 15 | void *gl4es_glXGetProcAddress(const char *name) __attribute__((visibility("default"))); 16 | void *gl4es_glXGetProcAddress(const char *name) { 17 | 18 | #ifndef NOX11 19 | // glX calls 20 | _EX(glXChooseVisual); 21 | _EX(glXCopyContext); 22 | _EX(glXCreateContext); 23 | _EX(glXCreateNewContext); 24 | _EX(glXCreateContextAttribsARB); 25 | _EX(glXDestroyContext); 26 | _EX(glXGetConfig); 27 | _EX(glXGetCurrentDisplay); 28 | _EX(glXGetCurrentDrawable); 29 | _EX(glXIsDirect); 30 | _EX(glXMakeCurrent); 31 | _EX(glXMakeContextCurrent); 32 | _EX(glXQueryExtensionsString); 33 | _EX(glXQueryServerString); 34 | _EX(glXSwapBuffers); 35 | _EX(glXSwapIntervalEXT); 36 | #endif //NOX11 37 | MAP("glXSwapIntervalMESA", gl4es_glXSwapInterval); 38 | MAP("glXSwapIntervalSGI", gl4es_glXSwapInterval); 39 | #ifndef NOX11 40 | _EX(glXUseXFont); 41 | _EX(glXWaitGL); 42 | _EX(glXWaitX); 43 | _EX(glXGetCurrentContext); 44 | _EX(glXQueryExtension); 45 | _EX(glXQueryDrawable); 46 | _EX(glXQueryVersion); 47 | _EX(glXGetClientString); 48 | _EX(glXGetFBConfigs); 49 | _EX(glXChooseFBConfig); 50 | MAP("glXChooseFBConfigSGIX", gl4es_glXChooseFBConfig); 51 | _EX(glXGetFBConfigAttrib); 52 | _EX(glXQueryContext); 53 | _EX(glXGetVisualFromFBConfig); 54 | _EX(glXCreateWindow); 55 | _EX(glXDestroyWindow); 56 | 57 | _EX(glXCreatePbuffer); 58 | _EX(glXDestroyPbuffer); 59 | _EX(glXCreatePixmap); 60 | _EX(glXDestroyPixmap); 61 | _EX(glXCreateGLXPixmap); 62 | _EX(glXDestroyGLXPixmap); 63 | STUB(glXGetCurrentReadDrawable); 64 | STUB(glXGetSelectedEvent); 65 | STUB(glXSelectEvent); 66 | 67 | _EX(glXCreateContextAttribs); 68 | _ARB(glXCreateContextAttribs); 69 | #endif //NOX11 70 | _EX(glXGetProcAddress); 71 | _ARB(glXGetProcAddress); 72 | 73 | return gl4es_GetProcAddress(name); 74 | } 75 | #ifdef AMIGAOS4 76 | //AliasExport(void*,aglGetProcAddress,,(const char* name)); 77 | #else 78 | AliasExport(void*,glXGetProcAddress,,(const char* name)); 79 | AliasExport(void*,glXGetProcAddress,ARB,(const char* name)); 80 | #endif -------------------------------------------------------------------------------- /src/glx/rpi.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "rpi.h" 8 | 9 | // Code specific to RPI 10 | // everything is dynamicaly linked, so this can be saffely compiled everywhere 11 | extern void* bcm_host; 12 | extern void* vcos; 13 | 14 | extern void (*bcm_host_init)(); 15 | extern void (*bcm_host_deinit)(); 16 | 17 | typedef uint32_t DISPMANX_DISPLAY_HANDLE_T; 18 | typedef uint32_t DISPMANX_UPDATE_HANDLE_T; 19 | typedef uint32_t DISPMANX_ELEMENT_HANDLE_T; 20 | typedef uint32_t DISPMANX_RESOURCE_HANDLE_T; 21 | typedef uint32_t DISPMANX_PROTECTION_T; 22 | typedef uint32_t DISPMANX_FLAGS_ALPHA_T; 23 | typedef struct tag_VC_RECT_T { 24 | int32_t x; 25 | int32_t y; 26 | int32_t width; 27 | int32_t height; 28 | } VC_RECT_T; 29 | typedef struct { 30 | DISPMANX_ELEMENT_HANDLE_T element; 31 | int width; 32 | int height; 33 | } EGL_DISPMANX_WINDOW_T; 34 | typedef struct { 35 | DISPMANX_FLAGS_ALPHA_T flags; 36 | uint32_t opacity; 37 | DISPMANX_RESOURCE_HANDLE_T mask; 38 | } VC_DISPMANX_ALPHA_T; 39 | int32_t (*graphics_get_display_size)(const uint16_t, uint32_t *, uint32_t*); 40 | DISPMANX_DISPLAY_HANDLE_T (*vc_dispmanx_display_open)(uint32_t); 41 | DISPMANX_UPDATE_HANDLE_T (*vc_dispmanx_update_start)(int32_t); 42 | DISPMANX_ELEMENT_HANDLE_T (*vc_dispmanx_element_add)( 43 | DISPMANX_UPDATE_HANDLE_T, DISPMANX_DISPLAY_HANDLE_T, int32_t, 44 | VC_RECT_T *, DISPMANX_RESOURCE_HANDLE_T, 45 | VC_RECT_T *, DISPMANX_PROTECTION_T, 46 | /*VC_DISPMANX_ALPHA_T*/void*, /*DISPMANX_CLAMP_T*/void*, 47 | /*DISPMANX_TRANSFORM_T*/ int32_t); 48 | int (*vc_dispmanx_update_submit_sync)(DISPMANX_RESOURCE_HANDLE_T); 49 | int (*vc_dispmanx_element_remove)(DISPMANX_UPDATE_HANDLE_T update, DISPMANX_ELEMENT_HANDLE_T element); 50 | static DISPMANX_UPDATE_HANDLE_T dispman_update; 51 | static DISPMANX_DISPLAY_HANDLE_T dispman_display; 52 | static VC_RECT_T dst_rect; 53 | static VC_RECT_T src_rect; 54 | 55 | static int rpi_inited = 0; 56 | void rpi_init() { 57 | if(!bcm_host || rpi_inited) 58 | return; 59 | rpi_inited++; 60 | bcm_host_init = dlsym(bcm_host, "bcm_host_init"); 61 | bcm_host_deinit = dlsym(bcm_host, "bcm_host_deinit"); 62 | if(!bcm_host_init || !bcm_host_deinit) { 63 | printf("LIBGL: Warning, bcm_host function missing (init=%p, deinit=%p)\n", bcm_host_init, bcm_host_deinit); 64 | return; 65 | } 66 | bcm_host_init(); 67 | 68 | #define GO(A) A=dlsym(bcm_host, #A); if(A==NULL) A=dlsym(vcos, #A); if(A==NULL) printf("LIBGL: Warning, " #A " is null") 69 | GO(graphics_get_display_size); 70 | GO(vc_dispmanx_display_open); 71 | GO(vc_dispmanx_update_start); 72 | GO(vc_dispmanx_element_add); 73 | GO(vc_dispmanx_update_submit_sync); 74 | GO(vc_dispmanx_element_remove); 75 | #undef GO 76 | } 77 | 78 | void rpi_fini() { 79 | if(!bcm_host || !rpi_inited) 80 | return; 81 | --rpi_inited; 82 | if(!bcm_host_init || !bcm_host_deinit) 83 | return; 84 | bcm_host_deinit(); 85 | } 86 | 87 | void* create_rpi_window(int w, int h) { 88 | EGL_DISPMANX_WINDOW_T *nativewindow = (EGL_DISPMANX_WINDOW_T*)calloc(1, sizeof(EGL_DISPMANX_WINDOW_T)); 89 | if(!bcm_host) return NULL; 90 | // create a simple RPI nativewindow of size w*h, on output 0 (i.e. LCD)... 91 | // code heavily inspired from Allegro 5.2 92 | uint32_t screenwidth, screenheight; 93 | graphics_get_display_size(/*LCD*/ 0, &screenwidth, & screenheight); 94 | if(w==0) w=screenwidth; 95 | if(h==0) h=screenheight; 96 | DISPMANX_ELEMENT_HANDLE_T dispman_element; 97 | VC_RECT_T dst_rect, src_rect; 98 | dst_rect.x = 0; dst_rect.y = 0; 99 | dst_rect.width = screenwidth; 100 | dst_rect.height = screenheight; 101 | src_rect.x = 0; src_rect.y = 0; 102 | src_rect.width = w << 16; 103 | src_rect.height = h << 16; 104 | dispman_display = vc_dispmanx_display_open(/*LCD*/ 0); 105 | dispman_update = vc_dispmanx_update_start(0); 106 | VC_DISPMANX_ALPHA_T alpha = { /*DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS*/ 1, 255, 0 }; 107 | dispman_element = vc_dispmanx_element_add( 108 | dispman_update,dispman_display, 0, &dst_rect, 109 | 0, &src_rect, /*DISPMANX_PROTECTION_NONE*/ 0, &alpha, 0, 110 | /*DISPMAN_NO_ROTATE*/ 0); 111 | nativewindow->element = dispman_element; 112 | nativewindow->width = w; 113 | nativewindow->height = h; 114 | vc_dispmanx_update_submit_sync(dispman_update); 115 | 116 | return nativewindow; 117 | } 118 | 119 | void delete_rpi_window(void* win) { 120 | EGL_DISPMANX_WINDOW_T* nativewindow = (EGL_DISPMANX_WINDOW_T*)win; 121 | 122 | vc_dispmanx_element_remove(dispman_update, nativewindow->element); 123 | vc_dispmanx_update_submit_sync(dispman_update); 124 | 125 | free(win); 126 | } 127 | -------------------------------------------------------------------------------- /src/glx/rpi.h: -------------------------------------------------------------------------------- 1 | #ifndef _GLX_RPI_H_ 2 | #define _GLX_RPI_H_ 3 | 4 | // Code specific to RPI 5 | 6 | void rpi_init(); 7 | void rpi_fini(); 8 | void* create_rpi_window(int w, int h); 9 | void delete_rpi_window(void* win); 10 | 11 | #endif // _GLX_RPI_H_ 12 | -------------------------------------------------------------------------------- /src/glx/streaming.h: -------------------------------------------------------------------------------- 1 | #ifndef _GLX_STREAMING_H_ 2 | #define _GLX_STREAMING_H_ 3 | 4 | #ifdef TEXSTREAM 5 | #include "../gl/gl4es.h" 6 | 7 | #ifndef GL_APIENTRYP 8 | #define GL_APIENTRYP 9 | #endif 10 | #ifndef GL_IMG_texture_stream 11 | #define GL_TEXTURE_STREAM_IMG 0x8C0D 12 | #define GL_TEXTURE_NUM_STREAM_DEVICES_IMG 0x8C0E 13 | #define GL_TEXTURE_STREAM_DEVICE_WIDTH_IMG 0x8C0F 14 | #define GL_TEXTURE_STREAM_DEVICE_HEIGHT_IMG 0x8EA0 15 | #define GL_TEXTURE_STREAM_DEVICE_FORMAT_IMG 0x8EA1 16 | #define GL_TEXTURE_STREAM_DEVICE_NUM_BUFFERS_IMG 0x8EA2 17 | typedef void (GL_APIENTRYP PFNGLTEXBINDSTREAMIMGPROC) (GLint device, GLint deviceoffset); 18 | typedef const GLubyte *(GL_APIENTRYP PFNGLGETTEXSTREAMDEVICENAMEIMGPROC) (GLenum target); 19 | typedef void (GL_APIENTRYP PFNGLGETTEXSTREAMDEVICEATTRIBUTEIVIMGPROC) (GLenum target, GLenum pname, GLint *params); 20 | #define GL_IMG_texture_stream 1 21 | #endif 22 | 23 | extern PFNGLTEXBINDSTREAMIMGPROC *glTexBindStreamIMG; 24 | extern PFNGLGETTEXSTREAMDEVICEATTRIBUTEIVIMGPROC *glGetTexAttrIMG; 25 | extern PFNGLGETTEXSTREAMDEVICENAMEIMGPROC *glGetTexDeviceIMG; 26 | 27 | extern int gl_stream; //0 if no streaming not 0 if streaming available 28 | 29 | // Function to start the Streaming texture Cache. Return 0 if failed, non-0 if OK. 30 | int InitStreamingCache(); 31 | // Function to get a Streaming buffer address 32 | void* GetStreamingBuffer(int buff); 33 | // Function to add a new texture of size Width*Height, with fake Texture ID "ID". Return the StreamingID or -1 if failed. 34 | int AddStreamed(int width, int height, unsigned int ID); 35 | // Function to free a streamed texture ID 36 | void FreeStreamed(int ID); 37 | // Function to find a StreamingID with a TextureID. G-1 if not found 38 | int FindTexID(unsigned int ID); 39 | // Function to apply Min& Mag filter to Streaming texture 40 | void ApplyFilterID(int ID, GLenum min_filter, GLenum mag_filter); 41 | // Function to activate the Steaming texture ID on current tex... 42 | void ActivateStreaming(int ID); 43 | // Function to deactivate the Streaming texture on current tex... 44 | void DeactivateStreaming(); 45 | #endif // TEXSTREAM 46 | #endif // _GLX_STREAMING_H_ 47 | -------------------------------------------------------------------------------- /src/glx/utils.c: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | /* 3 | * Generate OpenGL-compatible bitmap. 4 | * From Mesa-9.0.1 5 | */ 6 | #ifndef NOX11 7 | 8 | void 9 | fill_bitmap(Display * dpy, Window win, GC gc, 10 | unsigned int width, unsigned int height, 11 | int x0, int y0, unsigned int c, GLubyte * bitmap) 12 | { 13 | XImage *image; 14 | unsigned int x, y; 15 | Pixmap pixmap; 16 | XChar2b char2b; 17 | 18 | pixmap = XCreatePixmap(dpy, win, 8 * width, height, 1); 19 | XSetForeground(dpy, gc, 0); 20 | XFillRectangle(dpy, pixmap, gc, 0, 0, 8 * width, height); 21 | XSetForeground(dpy, gc, 1); 22 | 23 | char2b.byte1 = (c >> 8) & 0xff; 24 | char2b.byte2 = (c & 0xff); 25 | 26 | XDrawString16(dpy, pixmap, gc, x0, y0, &char2b, 1); 27 | 28 | image = XGetImage(dpy, pixmap, 0, 0, 8 * width, height, 1, XYPixmap); 29 | if (image) { 30 | /* Fill the bitmap (X11 and OpenGL are upside down wrt each other). */ 31 | for (y = 0; y < height; y++) 32 | for (x = 0; x < 8 * width; x++) 33 | if (XGetPixel(image, x, y)) 34 | bitmap[width * (height - y - 1) + x / 8] |= 35 | (1 << (7 - (x % 8))); 36 | XDestroyImage(image); 37 | } 38 | 39 | XFreePixmap(dpy, pixmap); 40 | } 41 | /* 42 | * determine if a given glyph is valid and return the 43 | * corresponding XCharStruct. 44 | * From MesaGL-9.0.1 45 | */ 46 | XCharStruct * 47 | isvalid(XFontStruct * fs, int which) 48 | { 49 | unsigned int rows, pages; 50 | int byte1 = 0, byte2 = 0; 51 | int i, valid = 1; 52 | 53 | rows = fs->max_byte1 - fs->min_byte1 + 1; 54 | pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1; 55 | 56 | if (rows == 1) { 57 | /* "linear" fonts */ 58 | if ((fs->min_char_or_byte2 > which) || (fs->max_char_or_byte2 < which)) 59 | valid = 0; 60 | } 61 | else { 62 | /* "matrix" fonts */ 63 | byte2 = which & 0xff; 64 | byte1 = which >> 8; 65 | if ((fs->min_char_or_byte2 > byte2) || 66 | (fs->max_char_or_byte2 < byte2) || 67 | (fs->min_byte1 > byte1) || (fs->max_byte1 < byte1)) 68 | valid = 0; 69 | } 70 | 71 | if (valid) { 72 | if (fs->per_char) { 73 | if (rows == 1) { 74 | /* "linear" fonts */ 75 | return (fs->per_char + (which - fs->min_char_or_byte2)); 76 | } 77 | else { 78 | /* "matrix" fonts */ 79 | i = ((byte1 - fs->min_byte1) * pages) + 80 | (byte2 - fs->min_char_or_byte2); 81 | return (fs->per_char + i); 82 | } 83 | } 84 | else { 85 | return (&fs->min_bounds); 86 | } 87 | } 88 | return (NULL); 89 | } 90 | 91 | #endif //NOX11 -------------------------------------------------------------------------------- /src/glx/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _GLX_UTILS_H_ 2 | #define _GLX_UTILS_H_ 3 | 4 | #ifndef NOX11 5 | #include 6 | #include 7 | #endif // NOX11 8 | #include 9 | #include 10 | 11 | #include "../gl/gl4es.h" 12 | #ifndef NOX11 13 | void 14 | fill_bitmap(Display * dpy, Window win, GC gc, 15 | unsigned int width, unsigned int height, 16 | int x0, int y0, unsigned int c, GLubyte * bitmap); 17 | 18 | XCharStruct * 19 | isvalid(XFontStruct * fs, int which); 20 | #endif // NOX11 21 | #endif // _GLX_UTILS_H_ 22 | -------------------------------------------------------------------------------- /test.cmake: -------------------------------------------------------------------------------- 1 | # Check if all required arguments are provided 2 | macro(argument_required argument failstring) 3 | if (NOT ${argument}) 4 | message(FATAL_ERROR ${failstring}) 5 | endif (NOT ${argument}) 6 | endmacro(argument_required) 7 | 8 | argument_required(LIBRARY_FOLDER "All tests require to have a library output folder.") 9 | argument_required(TESTS_DIRECTORY "All tests require to have a test folder.") 10 | argument_required(TEST_FILENAME "All tests require a trace filename to be reprinted.") 11 | argument_required(CALLS "All tests require a call count.") 12 | 13 | # Enable different GLES version tests 14 | if (GLES_FORCED) 15 | set(GLES${GLES_FORCED}_ENABLED ON) 16 | else (GLES_FORCED) 17 | set(GLES1_ENABLED ON) 18 | set(GLES2_ENABLED ON) 19 | endif (GLES_FORCED) 20 | 21 | # Special case fo pixels tolerance 22 | if (TOLERANCE) 23 | set(TOLERANCE_GLES1 ${TOLERANCE}) 24 | set(TOLERANCE_GLES2 ${TOLERANCE}) 25 | endif (TOLERANCE) 26 | 27 | # Use the built library 28 | set(ENV{LD_LIBRARY_PATH} ${LIBRARY_FOLDER}:$ENV{LD_LIBRARY_PATH}) 29 | 30 | macro(run_test GLES) 31 | if (GLES${GLES}_ENABLED) 32 | argument_required(TOLERANCE_GLES${GLES} "All tests require a pixel tolerance for GLES ${GLES}.") 33 | 34 | set(ENV{LIBGL_ES} ${GLES}) 35 | 36 | message(STATUS "Starting test in GLES ${GLES}...") 37 | execute_process( 38 | COMMAND ${TESTS_DIRECTORY}/test.sh 39 | ${TEST_FILENAME} 40 | ${CALLS} 41 | ${TOLERANCE_GLES${GLES}} 42 | ${EXTRACT_RANGE} 43 | ERROR_VARIABLE TEST_ERROR 44 | OUTPUT_VARIABLE TEST_OUTPUT 45 | WORKING_DIRECTORY ${TESTS_DIRECTORY} 46 | ) 47 | message(STATUS "Ran test.\nError: ${TEST_ERROR}\nOutput: ${TEST_OUTPUT}") 48 | 49 | if (TEST_OUTPUT) 50 | set(ERROR ${ERROR} ${GLES}) 51 | endif (TEST_OUTPUT) 52 | endif (GLES${GLES}_ENABLED) 53 | endmacro(run_test) 54 | 55 | run_test(1) 56 | run_test(2) 57 | 58 | if (ERROR) 59 | message(FATAL_ERROR "Test(s) failed while using GLES ${ERROR}") 60 | endif (ERROR) 61 | 62 | message(STATUS "Success.") 63 | -------------------------------------------------------------------------------- /tests/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # WARNING: do not execute this file unless you are aware of what you're doing. 4 | # This file is meant to be executed by ctest. 5 | 6 | export LIBGL_FB=3 7 | export LIBGL_SILENTSTUB=1 8 | export LIBGL_NOBANNER=1 9 | export LIBGL_NOERROR=1 10 | 11 | tar xf ../traces/$1.tgz 12 | apitrace dump-images --calls="$2" $1.trace >/dev/null 13 | exit_status=$? 14 | test $exit_status -ne 0 && echo "Test returned a non-zero status $exit_status (segmentation fault?)" 15 | rm $1.trace 16 | 17 | if [[ -f $1.$2.png ]] 18 | then 19 | mv $1.$2.png $1.$2.$LIBGL_ES.png 20 | 21 | EXTRACT="" 22 | if [[ ! -z "$4" ]] 23 | then 24 | EXTRACT="-extract $4" 25 | fi 26 | result=$(compare -metric AE -fuzz 20% $EXTRACT ../refs/$1.$2.png $1.$2.$LIBGL_ES.png diff_$1_GLES$LIBGL_ES.png 2>&1) 27 | 28 | if [[ ! "$result" -lt "$3" ]] 29 | then 30 | echo -n "$result pixels of difference" 31 | exit 1 32 | fi 33 | 34 | [[ -e diff_$1_GLES$LIBGL_ES.png ]] && rm diff_$1_GLES$LIBGL_ES.png 35 | [[ -e $1.$2.$LIBGL_ES.png ]] && rm $1.$2.$LIBGL_ES.png 36 | else 37 | echo -n "Failed to get snapshot" 38 | exit 1 39 | fi 40 | 41 | exit 0 42 | -------------------------------------------------------------------------------- /tests/tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function clean_tests { 4 | #glxgears 5 | if [ -e glxgears.0000008203.png ];then 6 | rm glxgears.0000008203.png 7 | fi 8 | if [ -e glxgears.trace ];then 9 | rm glxgears.trace 10 | fi 11 | #stunt car racer 12 | if [ -e stuntcarracer.0000118817.png ];then 13 | rm stuntcarracer.0000118817.png 14 | fi 15 | if [ -e stuntcarracer.trace ];then 16 | rm stuntcarracer.trace 17 | fi 18 | #neverball 19 | if [ -e neverball.0000078750.png ];then 20 | rm neverball.0000078750.png 21 | fi 22 | if [ -e neverball.trace ];then 23 | rm neverball.trace 24 | fi 25 | #foobillardplus 26 | if [ -e foobillardplus.0000014748.png ];then 27 | rm foobillardplus.0000014748.png 28 | fi 29 | if [ -e foobillardplus.trace ];then 30 | rm foobillardplus.trace 31 | fi 32 | #openra 33 | if [ -e openra.0000031249.png ];then 34 | rm openra.0000031249.png 35 | fi 36 | if [ -e openra.trace ];then 37 | rm openra.trace 38 | fi 39 | #glsl_lighting 40 | if [ -e glsl_lighting.0000505393.png ];then 41 | rm glsl_lighting.0000505393.png 42 | fi 43 | if [ -e glsl_lighting.trace ];then 44 | rm glsl_lighting.trace 45 | fi 46 | #pointsprite 47 | if [ -e pointsprite.0000248810.png ];then 48 | rm pointsprite.0000248810.png 49 | fi 50 | if [ -e pointsprite.trace ];then 51 | rm pointsprite.trace 52 | fi 53 | #diff result 54 | if [ -e diff.png ];then 55 | rm diff.png 56 | fi 57 | } 58 | 59 | export OK=1 60 | function launch_test { 61 | tar xf ../traces/$1.tgz 62 | if [ "$BENCH" = "1" ];then 63 | glretrace -b $1.trace 64 | else 65 | apitrace dump-images --calls="$2" $1.trace 66 | EXTRACT="" 67 | if [ ! -z "$4" ];then 68 | EXTRACT="-extract $4" 69 | fi 70 | result=$(compare -metric AE -fuzz 20% $EXTRACT ../refs/$1.$2.png $1.$2.png diff.png 2>&1) 71 | if [ ! "$result" -lt "$3" ];then 72 | popd >/dev/null 73 | echo "error, $result pixels diff" 74 | export OK=0 75 | fi 76 | fi 77 | } 78 | 79 | function banner { 80 | echo 81 | echo " ******************* " 82 | if [ "$BENCH" = "1" ];then 83 | echo " Bench $1 " 84 | else 85 | echo " $1 " 86 | fi 87 | echo " ------------------- " 88 | } 89 | 90 | export BENCH=0 91 | if [ "$1" = "-b" ];then 92 | BENCH=1 93 | shift 94 | fi 95 | if [ "$2" = "-b" ];then 96 | BENCH=1 97 | fi 98 | 99 | if [ ! -z "$1" ];then 100 | export LD_LIBRARY_PATH=$1:$LD_LIBRARY_PATH 101 | fi 102 | 103 | if [ ! "$BENCH" = "1" ];then 104 | export LIBGL_FB=3 105 | fi 106 | export LIBGL_SILENTSTUB=1 107 | export LIBGL_NOBANNER=1 108 | 109 | TESTS=`dirname "$0"` 110 | 111 | pushd "$TESTS" >/dev/null 112 | 113 | clean_tests 114 | 115 | export LIBGL_ES=1 116 | 117 | banner "GLES1.1: glxgears" 118 | launch_test glxgears 0000008203 25 119 | if [ $OK = 0 ];then 120 | exit 1 121 | fi 122 | 123 | banner "GLES1.1: StuntCarRacer" 124 | launch_test stuntcarracer 0000118817 20 638x478+1+1 125 | if [ $OK = 0 ];then 126 | exit 1 127 | fi 128 | 129 | banner "GLES1.1: Neverball" 130 | launch_test neverball 0000078750 20 798x478+1+1 131 | if [ $OK = 0 ];then 132 | exit 1 133 | fi 134 | 135 | banner "GLES1.1: Foobillard Plus" 136 | launch_test foobillardplus 0000014748 20 798x478+1+1 137 | if [ $OK = 0 ];then 138 | exit 1 139 | fi 140 | 141 | banner "GLES1.1: Point Sprite" 142 | launch_test pointsprite 0000248810 20 143 | if [ $OK = 0 ];then 144 | exit 1 145 | fi 146 | 147 | export LIBGL_ES=2 148 | 149 | banner "GLES2.0: OpenRA" 150 | launch_test openra 0000031249 20 638x478+1+1 151 | if [ $OK = 0 ];then 152 | exit 1 153 | fi 154 | 155 | banner "GLES2.0: glsl_lighting" 156 | launch_test glsl_lighting 0000505393 20 157 | if [ $OK = 0 ];then 158 | exit 1 159 | fi 160 | 161 | banner "GLES2.0: glxgears" 162 | # Because FlatShaded mode is not supported, the image is more different. 163 | launch_test glxgears 0000008203 700 164 | if [ $OK = 0 ];then 165 | exit 1 166 | fi 167 | 168 | banner "GLES2.0: StuntCarRacer" 169 | launch_test stuntcarracer 0000118817 20 638x478+1+1 170 | if [ $OK = 0 ];then 171 | exit 1 172 | fi 173 | 174 | banner "GLES2.0: Neverball" 175 | launch_test neverball 0000078750 200 798x478+1+1 176 | if [ $OK = 0 ];then 177 | exit 1 178 | fi 179 | 180 | banner "GLES2.0: Foobillard Plus" 181 | launch_test foobillardplus 0000014748 50 798x478+1+1 182 | if [ $OK = 0 ];then 183 | exit 1 184 | fi 185 | 186 | banner "GLES2.0: Point Sprite" 187 | launch_test pointsprite 0000248810 20 188 | if [ $OK = 0 ];then 189 | exit 1 190 | fi 191 | 192 | # cleanup 193 | clean_tests 194 | 195 | popd >/dev/null 196 | echo " ================= " 197 | echo "All done" 198 | exit 0 199 | -------------------------------------------------------------------------------- /traces/descent3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RandomCoderOrg/gl4es-port/6145025f2ba262484d01165359fa0768aa5d52c0/traces/descent3.tgz -------------------------------------------------------------------------------- /traces/foobillardplus.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RandomCoderOrg/gl4es-port/6145025f2ba262484d01165359fa0768aa5d52c0/traces/foobillardplus.tgz -------------------------------------------------------------------------------- /traces/glsl_lighting.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RandomCoderOrg/gl4es-port/6145025f2ba262484d01165359fa0768aa5d52c0/traces/glsl_lighting.tgz -------------------------------------------------------------------------------- /traces/glxgears.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RandomCoderOrg/gl4es-port/6145025f2ba262484d01165359fa0768aa5d52c0/traces/glxgears.tgz -------------------------------------------------------------------------------- /traces/neverball.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RandomCoderOrg/gl4es-port/6145025f2ba262484d01165359fa0768aa5d52c0/traces/neverball.tgz -------------------------------------------------------------------------------- /traces/openra.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RandomCoderOrg/gl4es-port/6145025f2ba262484d01165359fa0768aa5d52c0/traces/openra.tgz -------------------------------------------------------------------------------- /traces/pointsprite.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RandomCoderOrg/gl4es-port/6145025f2ba262484d01165359fa0768aa5d52c0/traces/pointsprite.tgz -------------------------------------------------------------------------------- /traces/stuntcarracer.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RandomCoderOrg/gl4es-port/6145025f2ba262484d01165359fa0768aa5d52c0/traces/stuntcarracer.tgz -------------------------------------------------------------------------------- /version.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL4ES_VERSION_H 2 | #define _GL4ES_VERSION_H 3 | 4 | #define MAJOR 1 5 | #define MINOR 1 6 | #define REVISION 5 7 | 8 | #endif //_GL4ES_VERSION_H 9 | --------------------------------------------------------------------------------