1# ANGLE Development 2 3ANGLE provides OpenGL ES 3.1 and EGL 1.5 libraries and tests. You can use these to build and run OpenGL ES applications on Windows, Linux, Mac and Android. 4 5## Development setup 6 7### Version Control 8ANGLE uses git for version control. Helpful documentation can be found at [http://git-scm.com/documentation](http://git-scm.com/documentation). 9 10### Required Tools 11On all platforms: 12 13 * [depot_tools](https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up) 14 * Required to download dependencies (with gclient), generate build files (with GN), and compile ANGLE (with ninja). 15 * Ensure `depot_tools` is in your path as it provides ninja for compilation. 16 * For Googlers, run `download_from_google_storage --config` to login to Google Storage. 17 18On Windows: 19 20 * ***IMPORTANT: Set `DEPOT_TOOLS_WIN_TOOLCHAIN=0` in your environment if you are not a Googler.*** 21 * Install [Visual Studio Community 2019](https://visualstudio.microsoft.com/vs/) 22 * Install the [Windows 10 SDK, latest version](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk). 23 * You can install it through Visual Studio Installer if available. 24 * Required for GN-generated Visual Studio projects, the Debug runtime for D3D11, and the D3D Compiler DLL. 25 * (optional) See the [Chromium Windows build instructions](https://chromium.googlesource.com/chromium/src/+/main/docs/windows_build_instructions.md) for more info. 26 27On Linux: 28 29 * Dependencies will be handled later (see `install-build-deps.sh` below). 30 31On MacOS: 32 33 * [XCode](https://developer.apple.com/xcode/) for Clang and development files. 34 35### Getting the source 36 37``` 38git clone https://chromium.googlesource.com/angle/angle 39cd angle 40python scripts/bootstrap.py 41gclient sync 42git checkout main 43``` 44 45On Linux only, you need to install all the necessary dependencies before going further by running this command: 46``` 47./build/install-build-deps.sh 48``` 49 50After this completes successfully, you are ready to generate the ninja files: 51``` 52gn gen out/Debug 53``` 54 55On Windows only, ensure you **set `DEPOT_TOOLS_WIN_TOOLCHAIN=0` in your environment** (if you are not a Googler). 56 57GN will generate ninja files. To change the default build options run `gn args out/Debug`. Some commonly used options are: 58``` 59target_cpu = "x86" (default is "x64") 60is_clang = false (to use system default compiler instead of clang) 61is_debug = false (for release builds. is_debug = true is the default) 62angle_assert_always_on = true (enable release asserts and debug layers) 63``` 64 65For a release build run `gn args out/Release` and set `is_debug = false`. 66 67On Windows, you can build for the Universal Windows Platform (UWP) by setting `target_os = "winuwp"` in the args. 68 69For more information on GN run `gn help`. 70 71Ninja can be used to compile on all platforms with one of the following commands: 72``` 73autoninja -C out/Debug 74autoninja -C out/Release 75``` 76Ninja automatically calls GN to regenerate the build files on any configuration change. 77 78Ensure `depot_tools` is in your path as it provides ninja. 79 80### Building with Goma (Google employees only) 81 82In addition, Google employees should use goma, a distributed compilation 83system. Detailed information is available internally but the relevant gn arg 84is: 85 86``` 87use_goma = true 88``` 89 90To get any benefit from goma it is important to pass a large -j value to 91ninja. A good default is 10*numCores to 20*numCores. If you run autoninja then 92it will automatically pass an appropriate -j value to ninja for goma or not. 93 94``` 95$ autoninja -C out\Debug 96``` 97 98### Building and Debugging with Visual Studio 99 100To generate the Visual Studio solution in `out/Debug/angle-debug.sln`: 101``` 102gn gen out/Debug --sln=angle-debug --ide=vs2019 103``` 104 105In Visual Studio: 106 1. Open the ANGLE solution file `out/Debug/angle-debug.sln`. 107 2. It is recommended you still use `autoninja` from the command line to build. 108 3. If you do want to build in the solution, "Build Solution" is not functional with GN. Build one target at a time. 109 110Once the build completes all ANGLE libraries, tests, and samples will be located in `out/Debug`. 111 112### Building ANGLE for Android 113 114See the Android specific [documentation](DevSetupAndroid.md#ANGLE-for-Android). 115 116## Application Development with ANGLE 117This sections describes how to use ANGLE to build an OpenGL ES application. 118 119### Choosing a Backend 120ANGLE can use a variety of backing renderers based on platform. On Windows, it defaults to D3D11 where it's available, 121or D3D9 otherwise. On other desktop platforms, it defaults to GL. On mobile, it defaults to GLES. 122 123ANGLE provides an EGL extension called `EGL_ANGLE_platform_angle` which allows uers to select 124which renderer to use at EGL initialization time by calling eglGetPlatformDisplayEXT with special 125enums. Details of the extension can be found in its specification in 126`extensions/EGL_ANGLE_platform_angle.txt` and `extensions/EGL_ANGLE_platform_angle_*.txt` and 127examples of its use can be seen in the ANGLE samples and tests, particularly `util/EGLWindow.cpp`. 128 129To change the default D3D backend: 130 131 1. Open `src/libANGLE/renderer/d3d/DisplayD3D.cpp` 132 2. Locate the definition of `ANGLE_DEFAULT_D3D11` near the head of the file, and set it to your preference. 133 134To remove any backend entirely: 135 136 1. Run `gn args <path/to/build/dir>` 137 2. Set the appropriate variable to `false`. Options are: 138 - `angle_enable_d3d9` 139 - `angle_enable_d3d11` 140 - `angle_enable_gl` 141 - `angle_enable_metal` 142 - `angle_enable_null` 143 - `angle_enable_vulkan` 144 - `angle_enable_essl` 145 - `angle_enable_glsl` 146 147### To Use ANGLE in Your Application 148On Windows: 149 150 1. Configure your build environment to have access to the `include` folder to provide access to the standard Khronos EGL and GLES2 header files. 151 * For Visual C++ 152 * Right-click your project in the _Solution Explorer_, and select _Properties_. 153 * Under the _Configuration Properties_ branch, click _C/C++_. 154 * Add the relative path to the Khronos EGL and GLES2 header files to _Additional Include Directories_. 155 2. Configure your build environment to have access to `libEGL.lib` and `libGLESv2.lib` found in the build output directory (see [Building ANGLE](#building-with-visual-studio)). 156 * For Visual C++ 157 * Right-click your project in the _Solution Explorer_, and select _Properties_. 158 * Under the _Configuration Properties_ branch, open the _Linker_ branch and click _Input_. 159 * Add the relative paths to both the `libEGL.lib` file and `libGLESv2.lib` file to _Additional Dependencies_, separated by a semicolon. 160 3. Copy `libEGL.dll` and `libGLESv2.dll` from the build output directory (see [Building ANGLE](#building-with-visual-studio)) into your application folder. 161 4. Code your application to the Khronos [OpenGL ES 2.0](http://www.khronos.org/registry/gles/) and [EGL 1.4](http://www.khronos.org/registry/egl/) APIs. 162 163On Linux and MacOS, either: 164 165 - Link you application against `libGLESv2` and `libEGL` 166 - Use `dlopen` to load the OpenGL ES and EGL entry points at runtime. 167 168## GLSL ES to GLSL Translator 169In addition to OpenGL ES 2.0 and EGL 1.4 libraries, ANGLE also provides a GLSL ES to GLSL translator. This is useful for implementing OpenGL ES emulators on top of desktop OpenGL. 170 171### Source and Building 172The translator code is included with ANGLE but fully independent; it resides in `src/compiler`. 173Follow the steps above for [getting and building ANGLE](#getting-the-source) to build the translator on the platform of your choice. 174 175### Usage 176The basic usage is shown in `essl_to_glsl` sample under `samples/translator`. To translate a GLSL ES shader, following functions need to be called in the same order: 177 178 * `ShInitialize()` initializes the translator library and must be called only once from each process using the translator. 179 * `ShContructCompiler()` creates a translator object for vertex or fragment shader. 180 * `ShCompile()` translates the given shader. 181 * `ShDestruct()` destroys the given translator. 182 * `ShFinalize()` shuts down the translator library and must be called only once from each process using the translator. 183