├── .github └── workflows │ └── glad2.yaml ├── .gitignore ├── LICENSE ├── MANIFEST.in ├── README.md ├── cmake ├── CMakeLists.txt └── GladConfig.cmake ├── example ├── c++ │ ├── hellowindow2.cpp │ ├── hellowindow2_macro.cpp │ ├── hellowindow2_mx.cpp │ └── multiwin_mx │ │ ├── CMakeLists.txt │ │ └── multiwin_mx.cpp ├── c │ ├── egl_gles2_glfw_emscripten.c │ ├── egl_x11 │ │ ├── CMakeLists.txt │ │ └── egl_x11.c │ ├── gl_glfw.c │ ├── gl_glfw_on_demand.c │ ├── gl_sdl2.c │ ├── gles2_glfw_emscripten.c │ ├── glut.c │ ├── glx.c │ ├── glx_modern.c │ ├── vulkan_tri_glfw │ │ ├── CMakeLists.txt │ │ └── vulkan_tri_glfw.c │ └── wgl.c └── rust │ ├── gl-glfw-mx │ ├── Cargo.toml │ ├── README.md │ ├── init.sh │ └── src │ │ └── main.rs │ └── gl-glfw │ ├── Cargo.toml │ ├── README.md │ ├── init.sh │ └── src │ └── main.rs ├── glad ├── __init__.py ├── __main__.py ├── config.py ├── files │ ├── __init__.py │ ├── egl.xml │ ├── eglplatform.h │ ├── gl.xml │ ├── glx.xml │ ├── khrplatform.h │ ├── vk.xml │ ├── vk_platform.h │ ├── vulkan_video_codec_av1std.h │ ├── vulkan_video_codec_av1std_decode.h │ ├── vulkan_video_codec_h264std.h │ ├── vulkan_video_codec_h264std_decode.h │ ├── vulkan_video_codec_h264std_encode.h │ ├── vulkan_video_codec_h265std.h │ ├── vulkan_video_codec_h265std_decode.h │ ├── vulkan_video_codec_h265std_encode.h │ ├── vulkan_video_codecs_common.h │ └── wgl.xml ├── generator │ ├── __init__.py │ ├── c │ │ ├── __init__.py │ │ └── templates │ │ │ ├── base_template.c │ │ │ ├── base_template.h │ │ │ ├── egl.c │ │ │ ├── egl.h │ │ │ ├── gl.c │ │ │ ├── gl.h │ │ │ ├── glx.c │ │ │ ├── glx.h │ │ │ ├── header_only.h │ │ │ ├── impl_util.c │ │ │ ├── loader │ │ │ ├── egl.c │ │ │ ├── egl.h │ │ │ ├── gl.c │ │ │ ├── gl.h │ │ │ ├── gles1.c │ │ │ ├── gles1.h │ │ │ ├── gles2.c │ │ │ ├── gles2.h │ │ │ ├── glsc2.c │ │ │ ├── glsc2.h │ │ │ ├── glx.c │ │ │ ├── glx.h │ │ │ ├── library.c │ │ │ ├── vulkan.c │ │ │ ├── vulkan.h │ │ │ ├── wgl.c │ │ │ └── wgl.h │ │ │ ├── platform.h │ │ │ ├── template_utils.h │ │ │ ├── vk.c │ │ │ ├── vk.h │ │ │ ├── wgl.c │ │ │ └── wgl.h │ ├── rust │ │ ├── __init__.py │ │ └── templates │ │ │ ├── Cargo.toml │ │ │ ├── impl.rs │ │ │ ├── lib.rs │ │ │ ├── template_utils.rs │ │ │ └── types │ │ │ ├── egl.rs │ │ │ ├── gl.rs │ │ │ ├── glx.rs │ │ │ ├── khrplatform.rs │ │ │ ├── vk.rs │ │ │ └── wgl.rs │ └── util.py ├── opener.py ├── parse.py ├── plugin.py ├── sink.py ├── specification.py └── util.py ├── long_description.md ├── pyproject.toml ├── requirements.txt ├── test ├── README.md ├── c │ ├── cmake │ │ ├── CMakeLists.txt │ │ └── test_disabled.sh │ ├── compile │ │ ├── egl │ │ │ ├── alias │ │ │ │ └── 001 │ │ │ │ │ └── test.c │ │ │ ├── default │ │ │ │ ├── 001 │ │ │ │ │ └── test.c │ │ │ │ └── 002 │ │ │ │ │ └── test.c │ │ │ ├── header-only │ │ │ │ └── 001 │ │ │ │ │ └── test.c │ │ │ └── on-demand │ │ │ │ ├── 001 │ │ │ │ └── test.c │ │ │ │ └── 002 │ │ │ │ └── test.c │ │ ├── gl │ │ │ ├── alias │ │ │ │ ├── 001 │ │ │ │ │ └── test.c │ │ │ │ ├── 002 │ │ │ │ │ └── test.c │ │ │ │ ├── 003 │ │ │ │ │ └── test.c │ │ │ │ ├── 004 │ │ │ │ │ └── test.c │ │ │ │ ├── 005 │ │ │ │ │ └── test.c │ │ │ │ ├── 006 │ │ │ │ │ └── test.c │ │ │ │ └── 007 │ │ │ │ │ └── test.c │ │ │ ├── debug │ │ │ │ ├── 001 │ │ │ │ │ └── test.c │ │ │ │ ├── 002 │ │ │ │ │ └── test.c │ │ │ │ ├── 003 │ │ │ │ │ └── test.c │ │ │ │ ├── 004 │ │ │ │ │ └── test.c │ │ │ │ ├── 005 │ │ │ │ │ └── test.c │ │ │ │ └── 006 │ │ │ │ │ └── test.c │ │ │ ├── default │ │ │ │ ├── 001 │ │ │ │ │ └── test.c │ │ │ │ ├── 002 │ │ │ │ │ └── test.c │ │ │ │ ├── 003 │ │ │ │ │ └── test.c │ │ │ │ ├── 004 │ │ │ │ │ └── test.c │ │ │ │ ├── 005 │ │ │ │ │ └── test.c │ │ │ │ ├── 006 │ │ │ │ │ └── test.c │ │ │ │ └── 007 │ │ │ │ │ └── test.c │ │ │ ├── header-only+mx │ │ │ │ ├── 001 │ │ │ │ │ └── test.c │ │ │ │ ├── 002 │ │ │ │ │ └── test.c │ │ │ │ ├── 003 │ │ │ │ │ └── test.c │ │ │ │ ├── 004 │ │ │ │ │ └── test.c │ │ │ │ ├── 005 │ │ │ │ │ └── test.c │ │ │ │ ├── 006 │ │ │ │ │ └── test.c │ │ │ │ └── 007 │ │ │ │ │ └── test.c │ │ │ ├── header-only │ │ │ │ ├── 001 │ │ │ │ │ └── test.c │ │ │ │ ├── 002 │ │ │ │ │ └── test.c │ │ │ │ ├── 003 │ │ │ │ │ └── test.c │ │ │ │ ├── 004 │ │ │ │ │ └── test.c │ │ │ │ ├── 005 │ │ │ │ │ └── test.c │ │ │ │ └── 006 │ │ │ │ │ └── test.c │ │ │ ├── mx+mx-global │ │ │ │ ├── 001 │ │ │ │ │ └── test_disabled.c │ │ │ │ ├── 002 │ │ │ │ │ └── test_disabled.c │ │ │ │ ├── 003 │ │ │ │ │ └── test_disabled.c │ │ │ │ ├── 004 │ │ │ │ │ └── test_disabled.c │ │ │ │ ├── 005 │ │ │ │ │ └── test_disabled.c │ │ │ │ ├── 006 │ │ │ │ │ └── test_disabled.c │ │ │ │ ├── 007 │ │ │ │ │ └── test_disabled.c │ │ │ │ └── 008 │ │ │ │ │ └── test_disabled.c │ │ │ └── on-demand │ │ │ │ ├── 001 │ │ │ │ └── test.c │ │ │ │ └── 002 │ │ │ │ └── test.c │ │ ├── gles1 │ │ │ ├── default │ │ │ │ ├── 001 │ │ │ │ │ └── test.c │ │ │ │ └── 002 │ │ │ │ │ └── test.c │ │ │ └── on-demand │ │ │ │ ├── 001 │ │ │ │ └── test.c │ │ │ │ └── 002 │ │ │ │ └── test.c │ │ ├── gles2 │ │ │ ├── alias │ │ │ │ └── 001 │ │ │ │ │ └── test.c │ │ │ ├── default │ │ │ │ ├── 001 │ │ │ │ │ └── test.c │ │ │ │ ├── 002 │ │ │ │ │ └── test.c │ │ │ │ ├── 003 │ │ │ │ │ └── test.c │ │ │ │ ├── 004 │ │ │ │ │ └── test.c │ │ │ │ └── 005 │ │ │ │ │ └── test.c │ │ │ └── on-demand │ │ │ │ ├── 001 │ │ │ │ └── test.c │ │ │ │ └── 002 │ │ │ │ └── test.c │ │ ├── glx │ │ │ ├── alias │ │ │ │ └── 001 │ │ │ │ │ └── test.c │ │ │ ├── default │ │ │ │ ├── 001 │ │ │ │ │ └── test.c │ │ │ │ ├── 002 │ │ │ │ │ └── test.c │ │ │ │ └── 003 │ │ │ │ │ └── test.c │ │ │ ├── header-only │ │ │ │ ├── 001 │ │ │ │ │ └── test.c │ │ │ │ └── 002 │ │ │ │ │ └── test.c │ │ │ └── on-demand │ │ │ │ ├── 001 │ │ │ │ └── test.c │ │ │ │ └── 002 │ │ │ │ └── test.c │ │ └── vulkan │ │ │ ├── alias │ │ │ ├── 001 │ │ │ │ └── test.c │ │ │ └── 002 │ │ │ │ └── test.c │ │ │ ├── debug │ │ │ └── 001 │ │ │ │ └── test.c │ │ │ ├── default │ │ │ ├── 001 │ │ │ │ └── test.c │ │ │ ├── 002 │ │ │ │ └── test.c │ │ │ ├── 003 │ │ │ │ └── test.c │ │ │ ├── 004 │ │ │ │ └── test.c │ │ │ ├── 005 │ │ │ │ └── test.c │ │ │ └── 006 │ │ │ │ └── test.c │ │ │ ├── header-only+mx │ │ │ ├── 001 │ │ │ │ └── test.c │ │ │ └── 002 │ │ │ │ └── test.c │ │ │ ├── header-only │ │ │ ├── 001 │ │ │ │ └── test.c │ │ │ └── 002 │ │ │ │ └── test.c │ │ │ ├── mx+mx-global │ │ │ ├── 001 │ │ │ │ └── test_disabled.c │ │ │ └── 002 │ │ │ │ └── test_disabled.c │ │ │ └── on-demand │ │ │ ├── 001 │ │ │ └── test.c │ │ │ └── 002 │ │ │ └── test.c │ ├── parse │ │ ├── 001 │ │ │ └── test.c │ │ ├── 002 │ │ │ └── test.c │ │ ├── 003 │ │ │ └── test.c │ │ └── 004 │ │ │ └── test.c │ └── run │ │ ├── gl │ │ ├── debug │ │ │ └── 001 │ │ │ │ └── test.c │ │ ├── default │ │ │ ├── 001 │ │ │ │ └── test.c │ │ │ ├── 002 │ │ │ │ └── test.c │ │ │ └── 003 │ │ │ │ └── test.c │ │ ├── mx │ │ │ ├── 001 │ │ │ │ └── test.c │ │ │ ├── 002 │ │ │ │ └── test.c │ │ │ ├── 003 │ │ │ │ └── test_disabled.c │ │ │ ├── 004 │ │ │ │ └── test_disabled.c │ │ │ ├── 005 │ │ │ │ └── test_disabled.c │ │ │ └── 006 │ │ │ │ └── test_disabled.c │ │ ├── on-demand+debug │ │ │ ├── 001 │ │ │ │ └── test.c │ │ │ └── 002 │ │ │ │ └── test.c │ │ └── on-demand │ │ │ ├── 001 │ │ │ └── test.c │ │ │ └── 002 │ │ │ └── test.c │ │ └── wgl │ │ └── default │ │ └── 001 │ │ └── test.c └── rust │ ├── compile │ ├── egl │ │ └── default │ │ │ └── 001 │ │ │ ├── Cargo.toml │ │ │ └── test.rs │ ├── gl │ │ └── default │ │ │ ├── 001 │ │ │ ├── Cargo.toml │ │ │ └── test.rs │ │ │ ├── 002 │ │ │ ├── Cargo.toml │ │ │ └── test.rs │ │ │ └── 003 │ │ │ ├── Cargo.toml │ │ │ └── test.rs │ ├── glx │ │ └── default │ │ │ └── 001 │ │ │ ├── Cargo.toml │ │ │ └── test.rs │ ├── vulkan │ │ └── default │ │ │ └── 001 │ │ │ ├── Cargo.toml │ │ │ └── test.rs │ └── wgl │ │ └── default │ │ └── 001 │ │ ├── Cargo.toml │ │ └── test.rs │ ├── gen │ └── mx │ │ └── 001 │ │ ├── Cargo.toml │ │ └── test.rs │ └── run │ └── gl │ └── default │ └── 001 │ ├── Cargo.toml │ └── test.rs └── utility ├── bump_version.sh ├── compiletest.sh ├── download.sh ├── examples.sh ├── generateall.sh ├── test.sh └── updatesub.sh /.github/workflows/glad2.yaml: -------------------------------------------------------------------------------- 1 | on: [push, pull_request] 2 | 3 | name: glad2 4 | 5 | jobs: 6 | test: 7 | name: Test 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v4 11 | - uses: actions/setup-python@v5 12 | with: 13 | python-version: '3.x' 14 | - name: Install Python dependencies 15 | run: | 16 | python -m pip install --upgrade pip 17 | pip install -r requirements.txt 18 | - name: Install dependencies 19 | run: | 20 | sudo apt-get update 21 | sudo apt-get install gcc g++ gcc-mingw-w64 g++-mingw-w64 rustc libglfw3-dev wine winetricks xvfb libxxf86vm-dev libxi-dev libxcursor-dev libxinerama-dev 22 | - name: Setup environment 23 | run: | 24 | mkdir .wine 25 | export WINEPREFIX="$(pwd)/.wine" 26 | export WINEDLLOVERRIDES="mscoree,mshtml=" 27 | 28 | winetricks nocrashdialog 29 | - name: Run Tests 30 | run: PRINT_MESSAGE=1 xvfb-run --auto-servernum ./utility/test.sh 31 | - name: Publish Test Results 32 | uses: EnricoMi/publish-unit-test-result-action@v2 33 | if: always() 34 | with: 35 | files: test-report.xml 36 | comment_mode: off 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | /*.xml 3 | *.kdev4 4 | build/ 5 | *.o 6 | *.a 7 | a.out 8 | *.kdev_include_paths 9 | main.c 10 | *.diff 11 | *.swp 12 | .idea 13 | dist/ 14 | *.egg-info 15 | /khrplatform.h 16 | /eglplatform.h 17 | /vk_platform.h 18 | /glad-rs/ 19 | /rust/ 20 | target/ 21 | Cargo.lock 22 | .vscode/ 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The glad source code: 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2013-2022 David Herberth 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | this software and associated documentation files (the "Software"), to deal in 9 | the Software without restriction, including without limitation the rights to 10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | the Software, and to permit persons to whom the Software is furnished to do so, 12 | subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | IN 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 | The Khronos Specifications: 26 | 27 | Copyright (c) 2013-2020 The Khronos Group Inc. 28 | 29 | Licensed under the Apache License, Version 2.0 (the "License"); 30 | you may not use this file except in compliance with the License. 31 | You may obtain a copy of the License at 32 | 33 | http://www.apache.org/licenses/LICENSE-2.0 34 | 35 | Unless required by applicable law or agreed to in writing, software 36 | distributed under the License is distributed on an "AS IS" BASIS, 37 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 38 | See the License for the specific language governing permissions and 39 | limitations under the License. 40 | 41 | 42 | The EGL Specification and various headers: 43 | 44 | Copyright (c) 2007-2016 The Khronos Group Inc. 45 | 46 | Permission is hereby granted, free of charge, to any person obtaining a 47 | copy of this software and/or associated documentation files (the 48 | "Materials"), to deal in the Materials without restriction, including 49 | without limitation the rights to use, copy, modify, merge, publish, 50 | distribute, sublicense, and/or sell copies of the Materials, and to 51 | permit persons to whom the Materials are furnished to do so, subject to 52 | the following conditions: 53 | 54 | The above copyright notice and this permission notice shall be included 55 | in all copies or substantial portions of the Materials. 56 | 57 | THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 58 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 59 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 60 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 61 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 62 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 63 | MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 64 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | recursive-include glad *.c *.h *.d *.volt *.rs *.toml *.xml 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | glad 2 | ==== 3 | 4 | Vulkan/GL/GLES/EGL/GLX/WGL Loader-Generator based on the official specifications 5 | for multiple languages. 6 | 7 | Check out the [webservice for glad2](https://glad.sh) to generate the files you need! 8 | 9 | 10 | **NOTE:** This is the 2.0 branch, which adds more functionality but changes the API. 11 | 12 | Some languages are only available in the [glad1 generator](https://glad.dav1d.de). 13 | 14 | ## Examples 15 | 16 | ```c 17 | #include 18 | // GLFW (include after glad) 19 | #include 20 | 21 | 22 | int main() { 23 | // -- snip -- 24 | 25 | GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", NULL, NULL); 26 | glfwMakeContextCurrent(window); 27 | 28 | int version = gladLoadGL(glfwGetProcAddress); 29 | if (version == 0) { 30 | printf("Failed to initialize OpenGL context\n"); 31 | return -1; 32 | } 33 | 34 | // Successfully loaded OpenGL 35 | printf("Loaded OpenGL %d.%d\n", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version)); 36 | 37 | // -- snip -- 38 | } 39 | ``` 40 | 41 | The full code: [hellowindow2.cpp](example/c++/hellowindow2.cpp) 42 | 43 | More examples in the [examples directory](example/) of this repository. 44 | 45 | ## Plugins 46 | 47 | Glad [plugins](https://github.com/Dav1dde/glad/wiki/Extending-Glad) 48 | maintained by the community to add support for more languages: 49 | 50 | - [Fortran](https://github.com/AarnoldGad/glad-fortran). 51 | 52 | ## Documentation 53 | 54 | The documentation can be found in the [wiki](https://github.com/Dav1dde/glad/wiki). 55 | 56 | 57 | Examples can be found [in the example directory](/example). Some examples: 58 | 59 | * C/C++ 60 | * [GL GLFW](example/c/gl_glfw.c) 61 | * [GL GLFW On-Demand loading](example/c/gl_glfw_on_demand.c) 62 | * [GL GLFW Multiple Windows/Contexts](example/c++/multiwin_mx/) 63 | * [GL SDL2](example/c/gl_sdl2.c) 64 | * [Vulkan GLFW](example/c/vulkan_tri_glfw/) 65 | * [GLX](example/c/glx.c) 66 | * [GLX Modern](example/c/glx_modern.c) 67 | * [WGL](example/c/wgl.c) 68 | * [EGL X11](example/c/egl_x11/) 69 | * Rust 70 | * [GL GLFW](example/rust/gl-glfw/) 71 | * [GL GLFW Multiple Windows/Contexts](example/rust/gl-glfw-mx/) 72 | 73 | 74 | 75 | ## License 76 | 77 | For the source code and various Khronos files see [LICENSE](/LICENSE). 78 | 79 | The generated code from glad is any of Public Domain, WTFPL or CC0. 80 | Now Khronos has some of their specifications under Apache Version 2.0 81 | license which may have an impact on the generated code, 82 | [see this clarifying comment](https://github.com/KhronosGroup/OpenGL-Registry/issues/376#issuecomment-596187053) 83 | on the Khronos / OpenGL-Specification issue tracker. 84 | -------------------------------------------------------------------------------- /cmake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # configuration variables: 2 | # GLAD_SOURCES_DIR: path to the sources of glad (=python module) 3 | 4 | cmake_minimum_required(VERSION 3.12) 5 | project(glad C) 6 | 7 | set( 8 | GLAD_CMAKE_DIR 9 | "${CMAKE_CURRENT_LIST_DIR}" 10 | CACHE STRING 11 | "Directory containing glad generator CMakeLists.txt. Must be absolute." 12 | ) 13 | set( 14 | GLAD_SOURCES_DIR 15 | "${GLAD_CMAKE_DIR}/../" 16 | CACHE STRING 17 | "Directory containing glad sources (python modules), used as working directory. Must be absolute." 18 | ) 19 | mark_as_advanced(GLAD_CMAKE_DIR) 20 | 21 | include(${GLAD_CMAKE_DIR}/GladConfig.cmake) 22 | -------------------------------------------------------------------------------- /example/c++/hellowindow2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // GLAD 4 | #include 5 | 6 | // GLFW (include after glad) 7 | #include 8 | 9 | 10 | // This example is taken from http://learnopengl.com/ 11 | // http://learnopengl.com/code_viewer.php?code=getting-started/hellowindow2 12 | // The code originally used GLEW, I replaced it with Glad 13 | 14 | // Compile: 15 | // g++ example/c++/hellowindow2.cpp -Ibuild/include build/src/gl.c -lglfw -ldl 16 | 17 | 18 | // Function prototypes 19 | void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode); 20 | 21 | // Window dimensions 22 | const GLuint WIDTH = 800, HEIGHT = 600; 23 | 24 | 25 | // The MAIN function, from here we start the application and run the game loop 26 | int main() 27 | { 28 | std::cout << "Starting GLFW context, OpenGL 3.3" << std::endl; 29 | // Init GLFW 30 | glfwInit(); 31 | // Set all the required options for GLFW 32 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 33 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 34 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 35 | glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); 36 | 37 | // Create a GLFWwindow object that we can use for GLFW's functions 38 | GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", NULL, NULL); 39 | glfwMakeContextCurrent(window); 40 | if (window == NULL) 41 | { 42 | std::cout << "Failed to create GLFW window" << std::endl; 43 | glfwTerminate(); 44 | return -1; 45 | } 46 | 47 | // Set the required callback functions 48 | glfwSetKeyCallback(window, key_callback); 49 | 50 | // Load OpenGL functions, gladLoadGL returns the loaded version, 0 on error. 51 | int version = gladLoadGL(glfwGetProcAddress); 52 | if (version == 0) 53 | { 54 | std::cout << "Failed to initialize OpenGL context" << std::endl; 55 | return -1; 56 | } 57 | 58 | // Successfully loaded OpenGL 59 | std::cout << "Loaded OpenGL " << GLAD_VERSION_MAJOR(version) << "." << GLAD_VERSION_MINOR(version) << std::endl; 60 | 61 | // Define the viewport dimensions 62 | glViewport(0, 0, WIDTH, HEIGHT); 63 | 64 | // Game loop 65 | while (!glfwWindowShouldClose(window)) 66 | { 67 | // Check if any events have been activated (key pressed, mouse moved etc.) and call corresponding response functions 68 | glfwPollEvents(); 69 | 70 | // Render 71 | // Clear the colorbuffer 72 | glClearColor(0.2f, 0.3f, 0.3f, 1.0f); 73 | glClear(GL_COLOR_BUFFER_BIT); 74 | 75 | // Swap the screen buffers 76 | glfwSwapBuffers(window); 77 | } 78 | 79 | // Terminates GLFW, clearing any resources allocated by GLFW. 80 | glfwTerminate(); 81 | return 0; 82 | } 83 | 84 | // Is called whenever a key is pressed/released via GLFW 85 | void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode) 86 | { 87 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 88 | glfwSetWindowShouldClose(window, GL_TRUE); 89 | } 90 | -------------------------------------------------------------------------------- /example/c++/hellowindow2_mx.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // GLAD 4 | #include 5 | 6 | // GLFW 7 | #include 8 | 9 | 10 | // This example is taken from http://learnopengl.com/ 11 | // http://learnopengl.com/code_viewer.php?code=getting-started/hellowindow2 12 | // The code originally used GLEW, I replaced it with Glad 13 | 14 | // Compile: 15 | // g++ example/c++/hellowindow2.cpp -Ibuild/include build/src/glad.c -lglfw -ldl 16 | 17 | 18 | // Function prototypes 19 | void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode); 20 | void draw(GLFWwindow *window, GladGLContext *context); 21 | 22 | // Window dimensions 23 | const GLuint WIDTH = 800, HEIGHT = 600; 24 | 25 | 26 | // The MAIN function, from here we start the application and run the game loop 27 | int main() 28 | { 29 | std::cout << "Starting GLFW context, OpenGL 3.3" << std::endl; 30 | // Init GLFW 31 | glfwInit(); 32 | // Set all the required options for GLFW 33 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 34 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 35 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 36 | glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); 37 | 38 | // Create a GLFWwindow object that we can use for GLFW's functions 39 | GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", NULL, NULL); 40 | glfwMakeContextCurrent(window); 41 | if (window == NULL) 42 | { 43 | std::cout << "Failed to create GLFW window" << std::endl; 44 | glfwTerminate(); 45 | return -1; 46 | } 47 | 48 | // Set the required callback functions 49 | glfwSetKeyCallback(window, key_callback); 50 | 51 | GladGLContext context = {}; 52 | int version = gladLoadGLContext(&context, glfwGetProcAddress); 53 | if (version == 0) 54 | { 55 | std::cout << "Failed to initialize OpenGL context" << std::endl; 56 | return -1; 57 | } 58 | 59 | draw(window, &context); 60 | 61 | return 0; 62 | } 63 | 64 | void draw(GLFWwindow *window, GladGLContext *gl) { 65 | // Define the viewport dimensions 66 | gl->Viewport(0, 0, WIDTH, HEIGHT); 67 | 68 | // Game loop 69 | while (!glfwWindowShouldClose(window)) 70 | { 71 | // Check if any events have been activated (key pressed, mouse moved etc.) and call corresponding response functions 72 | glfwPollEvents(); 73 | 74 | // Render 75 | // Clear the colorbuffer 76 | gl->ClearColor(0.2f, 0.3f, 0.3f, 1.0f); 77 | gl->Clear(GL_COLOR_BUFFER_BIT); 78 | 79 | // Swap the screen buffers 80 | glfwSwapBuffers(window); 81 | } 82 | 83 | // Terminates GLFW, clearing any resources allocated by GLFW. 84 | glfwTerminate(); 85 | } 86 | 87 | // Is called whenever a key is pressed/released via GLFW 88 | void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode) 89 | { 90 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 91 | glfwSetWindowShouldClose(window, GL_TRUE); 92 | } 93 | -------------------------------------------------------------------------------- /example/c++/multiwin_mx/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | project(glad_examples_c_multiwin_mx C CXX) 3 | 4 | find_package(glfw3 REQUIRED) 5 | 6 | set(GLAD_SOURCES_DIR "${PROJECT_SOURCE_DIR}/../../..") 7 | add_subdirectory("${GLAD_SOURCES_DIR}/cmake" glad_cmake) 8 | 9 | glad_add_library(glad_gl_core_mx_33 REPRODUCIBLE MX API gl:core=3.3) 10 | 11 | add_executable(multiwin_mx 12 | multiwin_mx.cpp 13 | ) 14 | target_link_libraries(multiwin_mx 15 | PUBLIC 16 | glad_gl_core_mx_33 17 | glfw 18 | ) 19 | -------------------------------------------------------------------------------- /example/c++/multiwin_mx/multiwin_mx.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | 7 | // Function prototypes 8 | GLFWwindow* create_window(const char *name, int major, int minor); 9 | GladGLContext* create_context(GLFWwindow *window); 10 | void free_context(GladGLContext *context); 11 | void draw(GLFWwindow *window, GladGLContext *context, float r, float g, float b); 12 | void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode); 13 | 14 | // Window dimensions 15 | const GLuint WIDTH = 400, HEIGHT = 300; 16 | 17 | 18 | int main() 19 | { 20 | glfwInit(); 21 | 22 | GLFWwindow *window1 = create_window("Window 1", 3, 3); 23 | GLFWwindow *window2 = create_window("Window 2", 3, 2); 24 | 25 | if (!window1 || !window2) { 26 | std::cout << "Failed to create GLFW window" << std::endl; 27 | glfwTerminate(); 28 | return -1; 29 | } 30 | 31 | glfwSetKeyCallback(window1, key_callback); 32 | glfwSetKeyCallback(window2, key_callback); 33 | 34 | GladGLContext *context1 = create_context(window1); 35 | GladGLContext *context2 = create_context(window2); 36 | 37 | if (!context1 || !context2) { 38 | std::cout << "Failed to initialize GL contexts" << std::endl; 39 | free_context(context1); 40 | free_context(context2); 41 | } 42 | 43 | glfwMakeContextCurrent(window1); 44 | context1->Viewport(0, 0, WIDTH, HEIGHT); 45 | 46 | glfwMakeContextCurrent(window2); 47 | context2->Viewport(0, 0, WIDTH, HEIGHT); 48 | 49 | 50 | while (!glfwWindowShouldClose(window1) && !glfwWindowShouldClose(window2)) 51 | { 52 | glfwPollEvents(); 53 | 54 | draw(window1, context1, 0.5, 0.2, 0.6); 55 | draw(window2, context2, 0.0, 0.1, 0.8); 56 | } 57 | 58 | free_context(context1); 59 | free_context(context2); 60 | 61 | glfwTerminate(); 62 | 63 | return 0; 64 | } 65 | 66 | GLFWwindow* create_window(const char *name, int major, int minor) { 67 | std::cout << "Creating Window, OpenGL " << major << "." << minor << ": " << name << std::endl; 68 | 69 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, major); 70 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor); 71 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 72 | glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); 73 | 74 | GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, name, NULL, NULL); 75 | return window; 76 | } 77 | 78 | GladGLContext* create_context(GLFWwindow *window) { 79 | glfwMakeContextCurrent(window); 80 | 81 | GladGLContext* context = (GladGLContext*) calloc(1, sizeof(GladGLContext)); 82 | if (!context) return NULL; 83 | 84 | int version = gladLoadGLContext(context, glfwGetProcAddress); 85 | std::cout << "Loaded OpenGL " << GLAD_VERSION_MAJOR(version) << "." << GLAD_VERSION_MINOR(version) << std::endl; 86 | 87 | return context; 88 | } 89 | 90 | void free_context(GladGLContext *context) { 91 | free(context); 92 | } 93 | 94 | 95 | void draw(GLFWwindow *window, GladGLContext *gl, float r, float g, float b) { 96 | glfwMakeContextCurrent(window); 97 | 98 | gl->ClearColor(r, g, b, 1.0f); 99 | gl->Clear(GL_COLOR_BUFFER_BIT); 100 | 101 | glfwSwapBuffers(window); 102 | } 103 | 104 | // Is called whenever a key is pressed/released via GLFW 105 | void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode) 106 | { 107 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 108 | glfwSetWindowShouldClose(window, GL_TRUE); 109 | } 110 | -------------------------------------------------------------------------------- /example/c/egl_gles2_glfw_emscripten.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #define GLFW_INCLUDE_NONE 1 9 | #include 10 | 11 | #ifdef __EMSCRIPTEN__ 12 | #include 13 | #else 14 | #define GLFW_EXPOSE_NATIVE_EGL 1 15 | #include 16 | #endif 17 | 18 | const GLuint WIDTH = 800, HEIGHT = 600; 19 | 20 | void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode) { 21 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 22 | glfwSetWindowShouldClose(window, GL_TRUE); 23 | } 24 | 25 | void render_frame(GLFWwindow *window) { 26 | glfwPollEvents(); 27 | 28 | glClearColor(0.7f, 0.9f, 0.1f, 1.0f); 29 | glClear(GL_COLOR_BUFFER_BIT); 30 | 31 | glfwSwapBuffers(window); 32 | } 33 | 34 | int main(int argc, char **argv) { 35 | glfwInit(); 36 | srand(time(NULL)); 37 | 38 | glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); 39 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); 40 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); 41 | glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API); 42 | glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); 43 | 44 | GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "[glad] EGL with GLFW", NULL, NULL); 45 | glfwMakeContextCurrent(window); 46 | 47 | glfwSetKeyCallback(window, key_callback); 48 | 49 | #ifndef __EMSCRIPTEN__ 50 | /* Load EGL */ 51 | EGLDisplay display = glfwGetEGLDisplay(); 52 | int egl_version = gladLoaderLoadEGL(display); 53 | printf("EGL %d.%d\n", GLAD_VERSION_MAJOR(egl_version), GLAD_VERSION_MINOR(egl_version)); 54 | #endif 55 | 56 | /* Load GLES */ 57 | int gles_version = 0; 58 | if (rand() % 100 < 50) { 59 | printf("-> using GLFW to load GLES2\n"); 60 | gles_version = gladLoadGLES2(glfwGetProcAddress); 61 | } else { 62 | printf("-> using GLAD loader to load GLES2\n"); 63 | gles_version = gladLoaderLoadGLES2(); 64 | } 65 | printf("GLES %d.%d\n", GLAD_VERSION_MAJOR(gles_version), GLAD_VERSION_MINOR(gles_version)); 66 | 67 | #ifdef __EMSCRIPTEN__ 68 | emscripten_set_main_loop_arg((em_arg_callback_func) render_frame, window, 60, 1); 69 | #else 70 | while (!glfwWindowShouldClose(window)) { render_frame(window); } 71 | #endif 72 | 73 | glfwTerminate(); 74 | 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /example/c/egl_x11/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | project(glad_examples_c_egl_x11 C) 3 | 4 | find_package(X11 REQUIRED) 5 | 6 | set(GLAD_SOURCES_DIR "${PROJECT_SOURCE_DIR}/../../..") 7 | add_subdirectory("${GLAD_SOURCES_DIR}/cmake" glad_cmake) 8 | 9 | glad_add_library(glad_egl_15_gles2_20 REPRODUCIBLE LOADER API egl=1.5 gles2=2.0) 10 | add_executable(egl_x11 11 | egl_x11.c 12 | ) 13 | target_include_directories(egl_x11 14 | PUBLIC 15 | ${X11_INCLUDE_DIR} 16 | ) 17 | target_link_libraries(egl_x11 18 | PUBLIC 19 | glad_egl_15_gles2_20 20 | ${X11_LIBRARIES} 21 | ) 22 | -------------------------------------------------------------------------------- /example/c/gl_glfw.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define GLAD_GL_IMPLEMENTATION // Necessary for headeronly version. 5 | #include 6 | 7 | #include 8 | 9 | 10 | const GLuint WIDTH = 800, HEIGHT = 600; 11 | 12 | void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode) { 13 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 14 | glfwSetWindowShouldClose(window, GL_TRUE); 15 | } 16 | 17 | int main(void) { 18 | glfwInit(); 19 | 20 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 21 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); 22 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 23 | 24 | GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "[glad] GL with GLFW", NULL, NULL); 25 | glfwMakeContextCurrent(window); 26 | 27 | glfwSetKeyCallback(window, key_callback); 28 | 29 | int version = gladLoadGL(glfwGetProcAddress); 30 | printf("GL %d.%d\n", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version)); 31 | 32 | while (!glfwWindowShouldClose(window)) { 33 | glfwPollEvents(); 34 | 35 | glClearColor(0.7f, 0.9f, 0.1f, 1.0f); 36 | glClear(GL_COLOR_BUFFER_BIT); 37 | 38 | glfwSwapBuffers(window); 39 | } 40 | 41 | glfwTerminate(); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /example/c/gl_glfw_on_demand.c: -------------------------------------------------------------------------------- 1 | // This example requires you to generate glad with the --on-demand option and optionally --loader and --debug. 2 | // gcc -o gl_glfw_on_demand example/c/gl_glfw_on_demand.c build/src/gl.c -Ibuild/include -ldl -lglfw 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | 11 | const GLuint WIDTH = 800, HEIGHT = 600; 12 | 13 | 14 | static void pre_call_gl_callback(const char *name, GLADapiproc apiproc, int len_args, ...) { 15 | printf("about to call gl func: %s\n", name); 16 | } 17 | 18 | void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode) { 19 | if (action != GLFW_PRESS) { 20 | return; 21 | } 22 | 23 | if (key == GLFW_KEY_ESCAPE) { 24 | glfwSetWindowShouldClose(window, GL_TRUE); 25 | #ifdef GLAD_OPTION_GL_DEBUG 26 | } else if (key == GLFW_KEY_H) { 27 | printf("Installing glad debug function pointers\n"); 28 | gladInstallGLDebug(); 29 | } else if (key == GLFW_KEY_J) { 30 | printf("Uninstalling glad debug function pointers\n"); 31 | gladUninstallGLDebug(); 32 | #endif 33 | } 34 | } 35 | 36 | int main(void) { 37 | glfwInit(); 38 | 39 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 40 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); 41 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 42 | 43 | GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "[glad] GL with GLFW", NULL, NULL); 44 | glfwMakeContextCurrent(window); 45 | 46 | glfwSetKeyCallback(window, key_callback); 47 | 48 | // If glad is generated with the --loader and --on-demand option 49 | // you don't have to call any glad function. 50 | // It is recommended to use the loader provided by your context creation library 51 | // instead of the glad loader. 52 | #ifndef GLAD_GL_LOADER 53 | gladSetGLOnDemandLoader(glfwGetProcAddress); 54 | #endif 55 | 56 | #ifdef GLAD_OPTION_GL_DEBUG 57 | gladUninstallGLDebug(); 58 | gladSetGLPreCallback(pre_call_gl_callback); 59 | #endif 60 | 61 | while (!glfwWindowShouldClose(window)) { 62 | glfwPollEvents(); 63 | 64 | glClearColor(0.7f, 0.9f, 0.1f, 1.0f); 65 | glClear(GL_COLOR_BUFFER_BIT); 66 | 67 | glfwSwapBuffers(window); 68 | } 69 | 70 | glfwTerminate(); 71 | 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /example/c/gl_sdl2.c: -------------------------------------------------------------------------------- 1 | // gcc example/c/gl_sdl2.c build/src/gl.c -Ibuild/include `sdl2-config --libs --cflags` -ldl 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | const GLuint WIDTH = 800, HEIGHT = 600; 11 | 12 | int main(void) { 13 | // code without checking for errors 14 | SDL_Init(SDL_INIT_VIDEO); 15 | 16 | SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 17 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); 18 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); 19 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); 20 | 21 | SDL_Window *window = SDL_CreateWindow( 22 | "[glad] GL with SDL", 23 | SDL_WINDOWPOS_CENTERED, 24 | SDL_WINDOWPOS_CENTERED, 25 | WIDTH, HEIGHT, 26 | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN 27 | ); 28 | 29 | SDL_GLContext context = SDL_GL_CreateContext(window); 30 | 31 | int version = gladLoadGL((GLADloadfunc) SDL_GL_GetProcAddress); 32 | printf("GL %d.%d\n", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version)); 33 | 34 | int exit = 0; 35 | while(!exit) { 36 | SDL_Event event; 37 | while (SDL_PollEvent(&event)) { 38 | switch(event.type) { 39 | case SDL_QUIT: 40 | exit = 1; 41 | break; 42 | case SDL_KEYUP: 43 | if (event.key.keysym.sym == SDLK_ESCAPE) { 44 | exit = 1; 45 | } 46 | break; 47 | default: 48 | break; 49 | } 50 | } 51 | 52 | glClearColor(0.7f, 0.9f, 0.1f, 1.0f); 53 | glClear(GL_COLOR_BUFFER_BIT); 54 | 55 | SDL_GL_SwapWindow(window); 56 | SDL_Delay(1); 57 | } 58 | 59 | SDL_GL_DeleteContext(context); 60 | SDL_DestroyWindow(window); 61 | SDL_Quit(); 62 | 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /example/c/gles2_glfw_emscripten.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | #define GLFW_INCLUDE_NONE 1 7 | #include 8 | 9 | #ifdef __EMSCRIPTEN__ 10 | #include 11 | #endif 12 | 13 | 14 | const GLuint WIDTH = 800, HEIGHT = 600; 15 | 16 | void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode) { 17 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 18 | glfwSetWindowShouldClose(window, GL_TRUE); 19 | } 20 | 21 | void render_frame(GLFWwindow *window) { 22 | glfwPollEvents(); 23 | 24 | glClearColor(0.7f, 0.9f, 0.1f, 1.0f); 25 | glClear(GL_COLOR_BUFFER_BIT); 26 | 27 | glfwSwapBuffers(window); 28 | } 29 | 30 | int main(void) { 31 | glfwInit(); 32 | 33 | glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); 34 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); 35 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); 36 | glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API); 37 | glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); 38 | 39 | GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "[glad] GLES2 with GLFW", NULL, NULL); 40 | glfwMakeContextCurrent(window); 41 | 42 | glfwSetKeyCallback(window, key_callback); 43 | 44 | /* Load GLES */ 45 | int gles_version = gladLoadGLES2(glfwGetProcAddress); 46 | printf("GLES %d.%d\n", GLAD_VERSION_MAJOR(gles_version), GLAD_VERSION_MINOR(gles_version)); 47 | 48 | #ifdef __EMSCRIPTEN__ 49 | emscripten_set_main_loop_arg((em_arg_callback_func) render_frame, window, 60, 1); 50 | #else 51 | while (!glfwWindowShouldClose(window)) { render_frame(window); } 52 | #endif 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /example/c/glut.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #ifdef __APPLE__ 5 | #include 6 | #else 7 | #include 8 | #endif 9 | 10 | // This file is a modified version of gl3w's test.c 11 | // https://github.com/skaslev/gl3w/blob/master/src/test.c 12 | 13 | // Compile: 14 | // gcc example/c/simple.c -Ibuild/include build/src/glad.c -lglut -ldl 15 | 16 | 17 | static int width = 600, height = 600; 18 | 19 | static void display(void) 20 | { 21 | glClearColor(1.0f, 0.2f, 0.7f, 1.0f); 22 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 23 | glutSwapBuffers(); 24 | glutPostRedisplay(); 25 | } 26 | 27 | static void reshape(int w, int h) 28 | { 29 | width = w > 1 ? w : 1; 30 | height = h > 1 ? h : 1; 31 | glViewport(0, 0, width, height); 32 | glClearDepth(1.0); 33 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 34 | glEnable(GL_DEPTH_TEST); 35 | } 36 | 37 | static void keyboard(unsigned char key, int x, int y) 38 | { 39 | switch (key) { 40 | case 27: // Escape key 41 | glutDestroyWindow(1); 42 | return; 43 | } 44 | glutPostRedisplay(); 45 | } 46 | 47 | int main(int argc, char **argv) 48 | { 49 | glutInit(&argc, argv); 50 | glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); 51 | glutInitWindowSize(width, height); 52 | glutCreateWindow("cookie"); 53 | 54 | glutReshapeFunc(reshape); 55 | glutDisplayFunc(display); 56 | glutKeyboardFunc(keyboard); 57 | 58 | // initialize glad after creating a context 59 | int version = gladLoaderLoadGL(); 60 | if(version == 0) { 61 | printf("Something went wrong!\n"); 62 | exit(-1); 63 | } 64 | 65 | printf("OpenGL %d.%d\n", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version)); 66 | if (!GLAD_GL_VERSION_2_0) { 67 | printf("Your system doesn't support OpenGL >= 2!\n"); 68 | return -1; 69 | } 70 | 71 | printf("OpenGL %s, GLSL %s\n", 72 | glGetString(GL_VERSION), 73 | glGetString(GL_SHADING_LANGUAGE_VERSION)); 74 | 75 | glutMainLoop(); 76 | 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /example/c/glx.c: -------------------------------------------------------------------------------- 1 | // gcc example/c/glx.c -o build/glx -Ibuild/include build/src/*.c -ldl -lX11 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | 14 | const int window_width = 800, window_height = 480; 15 | 16 | 17 | int main(void) { 18 | Display *display = XOpenDisplay(NULL); 19 | if (display == NULL) { 20 | printf("cannot connect to X server\n"); 21 | return 1; 22 | } 23 | 24 | int screen = DefaultScreen(display); 25 | 26 | int glx_version = gladLoaderLoadGLX(display, screen); 27 | if (!glx_version) { 28 | printf("Unable to load GLX.\n"); 29 | return 1; 30 | } 31 | printf("Loaded GLX %d.%d\n", GLAD_VERSION_MAJOR(glx_version), GLAD_VERSION_MINOR(glx_version)); 32 | 33 | Window root = RootWindow(display, screen); 34 | 35 | GLint visual_attributes[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None }; 36 | XVisualInfo *visual_info = glXChooseVisual(display, screen, visual_attributes); 37 | 38 | Colormap colormap = XCreateColormap(display, root, visual_info->visual, AllocNone); 39 | 40 | XSetWindowAttributes attributes; 41 | attributes.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask; 42 | attributes.colormap = colormap; 43 | 44 | Window window = 45 | XCreateWindow(display, root, 0, 0, window_width, window_height, 0, 46 | visual_info->depth, InputOutput, visual_info->visual, 47 | CWColormap | CWEventMask, &attributes); 48 | 49 | XMapWindow(display, window); 50 | XStoreName(display, window, "[glad] GLX with X11"); 51 | 52 | if (!window) { 53 | printf("Unable to create window.\n"); 54 | return 1; 55 | } 56 | 57 | GLXContext context = glXCreateContext(display, visual_info, NULL, GL_TRUE); 58 | glXMakeCurrent(display, window, context); 59 | 60 | int gl_version = gladLoaderLoadGL(); 61 | if (!gl_version) { 62 | printf("Unable to load GL.\n"); 63 | return 1; 64 | } 65 | printf("Loaded GL %d.%d\n", GLAD_VERSION_MAJOR(gl_version), GLAD_VERSION_MINOR(gl_version)); 66 | 67 | XWindowAttributes gwa; 68 | XGetWindowAttributes(display, window, &gwa); 69 | glViewport(0, 0, gwa.width, gwa.height); 70 | 71 | bool quit = false; 72 | while (!quit) { 73 | while (XPending(display)) { 74 | XEvent xev; 75 | XNextEvent(display, &xev); 76 | 77 | if (xev.type == KeyPress) { 78 | quit = true; 79 | } 80 | } 81 | 82 | glClearColor(0.8, 0.6, 0.7, 1.0); 83 | glClear(GL_COLOR_BUFFER_BIT); 84 | 85 | glXSwapBuffers(display, window); 86 | 87 | usleep(1000 * 10); 88 | } 89 | 90 | glXMakeCurrent(display, 0, 0); 91 | glXDestroyContext(display, context); 92 | 93 | XDestroyWindow(display, window); 94 | XFreeColormap(display, colormap); 95 | XCloseDisplay(display); 96 | 97 | gladLoaderUnloadGLX(); 98 | } 99 | -------------------------------------------------------------------------------- /example/c/glx_modern.c: -------------------------------------------------------------------------------- 1 | // gcc example/c/glx.c -o build/glx -Ibuild/include build/src/*.c -ldl -lX11 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | 14 | const int window_width = 800, window_height = 480; 15 | 16 | 17 | int main(void) { 18 | Display *display = XOpenDisplay(NULL); 19 | if (display == NULL) { 20 | printf("cannot connect to X server\n"); 21 | return 1; 22 | } 23 | 24 | int screen = DefaultScreen(display); 25 | Window root = RootWindow(display, screen); 26 | Visual *visual = DefaultVisual(display, screen); 27 | 28 | Colormap colormap = XCreateColormap(display, root, visual, AllocNone); 29 | 30 | XSetWindowAttributes attributes; 31 | attributes.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask; 32 | attributes.colormap = colormap; 33 | 34 | Window window = 35 | XCreateWindow(display, root, 0, 0, window_width, window_height, 0, 36 | DefaultDepth(display, screen), InputOutput, visual, 37 | CWColormap | CWEventMask, &attributes); 38 | 39 | XMapWindow(display, window); 40 | XStoreName(display, window, "[glad] Modern GLX with X11"); 41 | 42 | if (!window) { 43 | printf("Unable to create window.\n"); 44 | return 1; 45 | } 46 | 47 | int glx_version = gladLoaderLoadGLX(display, screen); 48 | if (!glx_version) { 49 | printf("Unable to load GLX.\n"); 50 | return 1; 51 | } 52 | printf("Loaded GLX %d.%d\n", GLAD_VERSION_MAJOR(glx_version), GLAD_VERSION_MINOR(glx_version)); 53 | 54 | GLint visual_attributes[] = { 55 | GLX_RENDER_TYPE, GLX_RGBA_BIT, 56 | GLX_DOUBLEBUFFER, 1, 57 | None 58 | }; 59 | 60 | int num_fbc = 0; 61 | GLXFBConfig *fbc = glXChooseFBConfig(display, screen, visual_attributes, &num_fbc); 62 | 63 | GLint context_attributes[] = { 64 | GLX_CONTEXT_MAJOR_VERSION_ARB, 3, 65 | GLX_CONTEXT_MINOR_VERSION_ARB, 3, 66 | GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, 67 | None 68 | }; 69 | 70 | GLXContext context = 71 | glXCreateContextAttribsARB(display, fbc[0], NULL, 1, context_attributes); 72 | if (!context) { 73 | printf("Unable to create OpenGL context.\n"); 74 | return 1; 75 | } 76 | 77 | glXMakeCurrent(display, window, context); 78 | 79 | int gl_version = gladLoaderLoadGL(); 80 | if (!gl_version) { 81 | printf("Unable to load GL.\n"); 82 | return 1; 83 | } 84 | printf("Loaded GL %d.%d\n", GLAD_VERSION_MAJOR(gl_version), GLAD_VERSION_MINOR(gl_version)); 85 | 86 | XWindowAttributes gwa; 87 | XGetWindowAttributes(display, window, &gwa); 88 | glViewport(0, 0, gwa.width, gwa.height); 89 | 90 | bool quit = false; 91 | while (!quit) { 92 | while (XPending(display)) { 93 | XEvent xev; 94 | XNextEvent(display, &xev); 95 | 96 | if (xev.type == KeyPress) { 97 | quit = true; 98 | } 99 | } 100 | 101 | glClearColor(0.8, 0.6, 0.7, 1.0); 102 | glClear(GL_COLOR_BUFFER_BIT); 103 | 104 | glXSwapBuffers(display, window); 105 | 106 | usleep(1000 * 10); 107 | } 108 | 109 | glXMakeCurrent(display, 0, 0); 110 | glXDestroyContext(display, context); 111 | 112 | XDestroyWindow(display, window); 113 | XFreeColormap(display, colormap); 114 | XCloseDisplay(display); 115 | 116 | gladLoaderUnloadGLX(); 117 | } 118 | -------------------------------------------------------------------------------- /example/c/vulkan_tri_glfw/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | project(glad_examples_c_vulkan_tri_glfw C) 3 | 4 | set(GLAD_SOURCES_DIR "${PROJECT_SOURCE_DIR}/../../..") 5 | add_subdirectory("${GLAD_SOURCES_DIR}/cmake" glad_cmake) 6 | 7 | find_package(glfw3 REQUIRED) 8 | 9 | glad_add_library(glad_vulkan_12 REPRODUCIBLE LOADER API vulkan=1.2) 10 | add_executable(vulkan_tri_glfw 11 | vulkan_tri_glfw.c 12 | ) 13 | target_link_libraries(vulkan_tri_glfw 14 | PUBLIC 15 | glad_vulkan_12 16 | glfw 17 | ) 18 | -------------------------------------------------------------------------------- /example/rust/gl-glfw-mx/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "gl-glfw" 3 | version = "0.1.0" 4 | 5 | [dependencies] 6 | glfw = "0.37.0" 7 | glad-gl = { path = "./build/glad-gl" } 8 | 9 | -------------------------------------------------------------------------------- /example/rust/gl-glfw-mx/README.md: -------------------------------------------------------------------------------- 1 | Example: gl-glfw-mx 2 | ================ 3 | 4 | 5 | This is basic example showcasing `glad-gl` in combination with 6 | [`glfw`](https://crates.io/crates/glfw). And multiple OpenGL contexts 7 | in different windows. 8 | 9 | To run the example use the following command: 10 | 11 | ```sh 12 | ./init.sh && cargo run 13 | ``` 14 | 15 | The `init.sh` script is just a small utility used to generate 16 | the `glad-gl` crate into the `build/` directory. The `Cargo.toml` 17 | references the dependency using: 18 | 19 | ```toml 20 | [dependencies] 21 | glad-gl = { path = "./build/glad-gl" } 22 | ``` 23 | 24 | This example is the basic example of the 25 | [glfw crate](https://crates.io/crates/glfw) with some 26 | OpenGL instructions added and just one additional line 27 | to initialize `glad`: 28 | 29 | ```rust 30 | gl::load(|e| glfw.get_proc_address_raw(e) as *const std::os::raw::c_void); 31 | ``` 32 | 33 | That's all that is needed to initialize and use OpenGL using `glad`! 34 | 35 | -------------------------------------------------------------------------------- /example/rust/gl-glfw-mx/init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | BASE_PATH="$(dirname $(realpath $0))" 4 | 5 | 6 | cd "${BASE_PATH}/../../../" 7 | 8 | python -m glad --out-path "${BASE_PATH}/build" --extensions="" --api="gl:core=3.3" rust --mx 9 | 10 | -------------------------------------------------------------------------------- /example/rust/gl-glfw-mx/src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate glfw; 2 | extern crate glad_gl; 3 | use std::sync::mpsc::Receiver; 4 | use glfw::{Action, Context, Key}; 5 | use glad_gl::gl; 6 | 7 | 8 | struct Window { 9 | source: glfw::Window, 10 | events: Receiver<(f64, glfw::WindowEvent)>, 11 | gl: gl::Gl 12 | } 13 | 14 | fn main() { 15 | let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap(); 16 | 17 | let mut w1 = create_window(&mut glfw); 18 | let mut w2 = create_window(&mut glfw); 19 | 20 | while !w1.source.should_close() && !w2.source.should_close() { 21 | glfw.poll_events(); 22 | 23 | draw(&mut w1); 24 | draw(&mut w2); 25 | } 26 | } 27 | 28 | fn create_window(glfw: &mut glfw::Glfw) -> Window { 29 | let (mut window, events) = glfw 30 | .create_window(300, 300, "[glad] Rust - OpenGL with GLFW", glfw::WindowMode::Windowed) 31 | .expect("Failed to create GLFW window."); 32 | 33 | window.set_key_polling(true); 34 | window.make_current(); 35 | 36 | let gl = gl::load(|e| glfw.get_proc_address_raw(e) as *const std::os::raw::c_void); 37 | 38 | Window { 39 | source: window, events, gl 40 | } 41 | } 42 | 43 | fn draw(window: &mut Window) { 44 | for (_, event) in glfw::flush_messages(&window.events) { 45 | handle_window_event(&mut window.source, event); 46 | } 47 | 48 | window.source.make_current(); 49 | unsafe { 50 | window.gl.ClearColor(0.7, 0.9, 0.1, 1.0); 51 | window.gl.Clear(gl::COLOR_BUFFER_BIT); 52 | } 53 | window.source.swap_buffers(); 54 | } 55 | 56 | fn handle_window_event(window: &mut glfw::Window, event: glfw::WindowEvent) { 57 | match event { 58 | glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) => { 59 | window.set_should_close(true) 60 | } 61 | _ => {} 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /example/rust/gl-glfw/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "gl-glfw" 3 | version = "0.1.0" 4 | 5 | [dependencies] 6 | glfw = "0.37.0" 7 | glad-gl = { path = "./build/glad-gl" } 8 | 9 | -------------------------------------------------------------------------------- /example/rust/gl-glfw/README.md: -------------------------------------------------------------------------------- 1 | Example: gl-glfw 2 | ================ 3 | 4 | 5 | This is basic example showcasing `glad-gl` in combination with 6 | [`glfw`](https://crates.io/crates/glfw). 7 | 8 | To run the example use the following command: 9 | 10 | ```sh 11 | ./init.sh && cargo run 12 | ``` 13 | 14 | The `init.sh` script is just a small utility used to generate 15 | the `glad-gl` crate into the `build/` directory. The `Cargo.toml` 16 | references the dependency using: 17 | 18 | ```toml 19 | [dependencies] 20 | glad-gl = { path = "./build/glad-gl" } 21 | ``` 22 | 23 | This example is the basic example of the 24 | [glfw crate](https://crates.io/crates/glfw) with some 25 | OpenGL instructions added and just one additional line 26 | to initialize `glad`: 27 | 28 | ```rust 29 | gl::load(|e| glfw.get_proc_address_raw(e) as *const std::os::raw::c_void); 30 | ``` 31 | 32 | That's all that is needed to initialize and use OpenGL using `glad`! 33 | 34 | -------------------------------------------------------------------------------- /example/rust/gl-glfw/init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | BASE_PATH="$(dirname $(realpath $0))" 4 | 5 | 6 | cd "${BASE_PATH}/../../../" 7 | 8 | python -m glad --out-path "${BASE_PATH}/build" --extensions="" --api="gl:core=3.3" rust 9 | 10 | -------------------------------------------------------------------------------- /example/rust/gl-glfw/src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate glfw; 2 | extern crate glad_gl; 3 | use glfw::{Action, Context, Key}; 4 | use glad_gl::gl; 5 | 6 | 7 | fn main() { 8 | let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap(); 9 | 10 | let (mut window, events) = glfw.create_window(300, 300, "[glad] Rust - OpenGL with GLFW", glfw::WindowMode::Windowed) 11 | .expect("Failed to create GLFW window."); 12 | 13 | window.set_key_polling(true); 14 | window.make_current(); 15 | 16 | gl::load(|e| glfw.get_proc_address_raw(e) as *const std::os::raw::c_void); 17 | 18 | while !window.should_close() { 19 | glfw.poll_events(); 20 | for (_, event) in glfw::flush_messages(&events) { 21 | handle_window_event(&mut window, event); 22 | } 23 | 24 | unsafe { 25 | gl::ClearColor(0.7, 0.9, 0.1, 1.0); 26 | gl::Clear(gl::COLOR_BUFFER_BIT); 27 | } 28 | 29 | window.swap_buffers(); 30 | } 31 | } 32 | 33 | fn handle_window_event(window: &mut glfw::Window, event: glfw::WindowEvent) { 34 | match event { 35 | glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) => { 36 | window.set_should_close(true) 37 | } 38 | _ => {} 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /glad/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | __version__ = '2.0.8' 3 | 4 | -------------------------------------------------------------------------------- /glad/files/__init__.py: -------------------------------------------------------------------------------- 1 | import os.path 2 | import logging 3 | import shutil 4 | 5 | try: 6 | from urlparse import urlparse 7 | except ImportError: 8 | from urllib.parse import urlparse 9 | 10 | try: 11 | from importlib.resources import files 12 | 13 | def resource_open(package, name, *args, **kwargs): 14 | return files(package).joinpath(name).open(*args, **kwargs) 15 | except ImportError: 16 | try: 17 | from pkg_resources import resource_stream 18 | 19 | def resource_open(package, name, *args, **kwargs): 20 | return resource_stream(package, name) 21 | except ImportError: 22 | def resource_open(package, name, *args, **kwargs): 23 | raise FileNotFoundError 24 | 25 | 26 | BASE_PATH = os.path.abspath(os.path.dirname(__file__)) 27 | 28 | logger = logging.getLogger('glad.files') 29 | 30 | 31 | class GladFileException(Exception): 32 | pass 33 | 34 | 35 | def open_local(name, *args, **kwargs): 36 | # use pkg_resources when available, makes it work in zipped modules 37 | # or other environments 38 | try: 39 | return resource_open(__name__, name, *args, **kwargs) 40 | except FileNotFoundError: 41 | pass 42 | 43 | # fallback to filesystem 44 | logger.info('falling back to packaged path: %r', name) 45 | local_path = os.path.normpath(os.path.join(BASE_PATH, os.path.join(name))) 46 | if not local_path.startswith(BASE_PATH): 47 | raise GladFileException('unsafe file path, won\'t open {!r}'.format(local_path)) 48 | return open(local_path, *args, **kwargs) 49 | 50 | 51 | class StaticFileOpener(object): 52 | def urlopen(self, url, data=None, *args, **kwargs): 53 | logger.debug('intercepted attempt to retrieve resource: %r', url) 54 | if data is not None: 55 | raise GladFileException('can not resolve requests with payload') 56 | 57 | filename = urlparse(url).path.rsplit('/', 1)[-1] 58 | return open_local(filename, 'rb') 59 | 60 | def urlretrieve(self, url, filename, *args, **kwargs): 61 | with self.urlopen(url) as src: 62 | with open(filename, 'wb') as dst: 63 | shutil.copyfileobj(src, dst) 64 | -------------------------------------------------------------------------------- /glad/files/vk_platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // File: vk_platform.h 3 | // 4 | /* 5 | ** Copyright 2014-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | 11 | #ifndef VK_PLATFORM_H_ 12 | #define VK_PLATFORM_H_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif // __cplusplus 18 | 19 | /* 20 | *************************************************************************************************** 21 | * Platform-specific directives and type declarations 22 | *************************************************************************************************** 23 | */ 24 | 25 | /* Platform-specific calling convention macros. 26 | * 27 | * Platforms should define these so that Vulkan clients call Vulkan commands 28 | * with the same calling conventions that the Vulkan implementation expects. 29 | * 30 | * VKAPI_ATTR - Placed before the return type in function declarations. 31 | * Useful for C++11 and GCC/Clang-style function attribute syntax. 32 | * VKAPI_CALL - Placed after the return type in function declarations. 33 | * Useful for MSVC-style calling convention syntax. 34 | * VKAPI_PTR - Placed between the '(' and '*' in function pointer types. 35 | * 36 | * Function declaration: VKAPI_ATTR void VKAPI_CALL vkCommand(void); 37 | * Function pointer type: typedef void (VKAPI_PTR *PFN_vkCommand)(void); 38 | */ 39 | #if defined(_WIN32) 40 | // On Windows, Vulkan commands use the stdcall convention 41 | #define VKAPI_ATTR 42 | #define VKAPI_CALL __stdcall 43 | #define VKAPI_PTR VKAPI_CALL 44 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH < 7 45 | #error "Vulkan is not supported for the 'armeabi' NDK ABI" 46 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH >= 7 && defined(__ARM_32BIT_STATE) 47 | // On Android 32-bit ARM targets, Vulkan functions use the "hardfloat" 48 | // calling convention, i.e. float parameters are passed in registers. This 49 | // is true even if the rest of the application passes floats on the stack, 50 | // as it does by default when compiling for the armeabi-v7a NDK ABI. 51 | #define VKAPI_ATTR __attribute__((pcs("aapcs-vfp"))) 52 | #define VKAPI_CALL 53 | #define VKAPI_PTR VKAPI_ATTR 54 | #else 55 | // On other platforms, use the default calling convention 56 | #define VKAPI_ATTR 57 | #define VKAPI_CALL 58 | #define VKAPI_PTR 59 | #endif 60 | 61 | #if !defined(VK_NO_STDDEF_H) 62 | #include 63 | #endif // !defined(VK_NO_STDDEF_H) 64 | 65 | #if !defined(VK_NO_STDINT_H) 66 | #if defined(_MSC_VER) && (_MSC_VER < 1600) 67 | typedef signed __int8 int8_t; 68 | typedef unsigned __int8 uint8_t; 69 | typedef signed __int16 int16_t; 70 | typedef unsigned __int16 uint16_t; 71 | typedef signed __int32 int32_t; 72 | typedef unsigned __int32 uint32_t; 73 | typedef signed __int64 int64_t; 74 | typedef unsigned __int64 uint64_t; 75 | #else 76 | #include 77 | #endif 78 | #endif // !defined(VK_NO_STDINT_H) 79 | 80 | #ifdef __cplusplus 81 | } // extern "C" 82 | #endif // __cplusplus 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /glad/files/vulkan_video_codec_h264std_decode.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_VIDEO_CODEC_H264STD_DECODE_H_ 2 | #define VULKAN_VIDEO_CODEC_H264STD_DECODE_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // vulkan_video_codec_h264std_decode is a preprocessor guard. Do not pass it to API calls. 23 | #define vulkan_video_codec_h264std_decode 1 24 | #include "vulkan_video_codec_h264std.h" 25 | 26 | #define VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_API_VERSION_1_0_0 VK_MAKE_VIDEO_STD_VERSION(1, 0, 0) 27 | 28 | #define VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_SPEC_VERSION VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_API_VERSION_1_0_0 29 | #define VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_EXTENSION_NAME "VK_STD_vulkan_video_codec_h264_decode" 30 | #define STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_LIST_SIZE 2 31 | 32 | typedef enum StdVideoDecodeH264FieldOrderCount { 33 | STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_TOP = 0, 34 | STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_BOTTOM = 1, 35 | STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_INVALID = 0x7FFFFFFF, 36 | STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_MAX_ENUM = 0x7FFFFFFF 37 | } StdVideoDecodeH264FieldOrderCount; 38 | typedef struct StdVideoDecodeH264PictureInfoFlags { 39 | uint32_t field_pic_flag : 1; 40 | uint32_t is_intra : 1; 41 | uint32_t IdrPicFlag : 1; 42 | uint32_t bottom_field_flag : 1; 43 | uint32_t is_reference : 1; 44 | uint32_t complementary_field_pair : 1; 45 | } StdVideoDecodeH264PictureInfoFlags; 46 | 47 | typedef struct StdVideoDecodeH264PictureInfo { 48 | StdVideoDecodeH264PictureInfoFlags flags; 49 | uint8_t seq_parameter_set_id; 50 | uint8_t pic_parameter_set_id; 51 | uint8_t reserved1; 52 | uint8_t reserved2; 53 | uint16_t frame_num; 54 | uint16_t idr_pic_id; 55 | int32_t PicOrderCnt[STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_LIST_SIZE]; 56 | } StdVideoDecodeH264PictureInfo; 57 | 58 | typedef struct StdVideoDecodeH264ReferenceInfoFlags { 59 | uint32_t top_field_flag : 1; 60 | uint32_t bottom_field_flag : 1; 61 | uint32_t used_for_long_term_reference : 1; 62 | uint32_t is_non_existing : 1; 63 | } StdVideoDecodeH264ReferenceInfoFlags; 64 | 65 | typedef struct StdVideoDecodeH264ReferenceInfo { 66 | StdVideoDecodeH264ReferenceInfoFlags flags; 67 | uint16_t FrameNum; 68 | uint16_t reserved; 69 | int32_t PicOrderCnt[STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_LIST_SIZE]; 70 | } StdVideoDecodeH264ReferenceInfo; 71 | 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /glad/files/vulkan_video_codec_h265std_decode.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_VIDEO_CODEC_H265STD_DECODE_H_ 2 | #define VULKAN_VIDEO_CODEC_H265STD_DECODE_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // vulkan_video_codec_h265std_decode is a preprocessor guard. Do not pass it to API calls. 23 | #define vulkan_video_codec_h265std_decode 1 24 | #include "vulkan_video_codec_h265std.h" 25 | 26 | #define VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_API_VERSION_1_0_0 VK_MAKE_VIDEO_STD_VERSION(1, 0, 0) 27 | 28 | #define VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_SPEC_VERSION VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_API_VERSION_1_0_0 29 | #define VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_EXTENSION_NAME "VK_STD_vulkan_video_codec_h265_decode" 30 | #define STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE 8 31 | typedef struct StdVideoDecodeH265PictureInfoFlags { 32 | uint32_t IrapPicFlag : 1; 33 | uint32_t IdrPicFlag : 1; 34 | uint32_t IsReference : 1; 35 | uint32_t short_term_ref_pic_set_sps_flag : 1; 36 | } StdVideoDecodeH265PictureInfoFlags; 37 | 38 | typedef struct StdVideoDecodeH265PictureInfo { 39 | StdVideoDecodeH265PictureInfoFlags flags; 40 | uint8_t sps_video_parameter_set_id; 41 | uint8_t pps_seq_parameter_set_id; 42 | uint8_t pps_pic_parameter_set_id; 43 | uint8_t NumDeltaPocsOfRefRpsIdx; 44 | int32_t PicOrderCntVal; 45 | uint16_t NumBitsForSTRefPicSetInSlice; 46 | uint16_t reserved; 47 | uint8_t RefPicSetStCurrBefore[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; 48 | uint8_t RefPicSetStCurrAfter[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; 49 | uint8_t RefPicSetLtCurr[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; 50 | } StdVideoDecodeH265PictureInfo; 51 | 52 | typedef struct StdVideoDecodeH265ReferenceInfoFlags { 53 | uint32_t used_for_long_term_reference : 1; 54 | uint32_t unused_for_reference : 1; 55 | } StdVideoDecodeH265ReferenceInfoFlags; 56 | 57 | typedef struct StdVideoDecodeH265ReferenceInfo { 58 | StdVideoDecodeH265ReferenceInfoFlags flags; 59 | int32_t PicOrderCntVal; 60 | } StdVideoDecodeH265ReferenceInfo; 61 | 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /glad/files/vulkan_video_codecs_common.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_VIDEO_CODECS_COMMON_H_ 2 | #define VULKAN_VIDEO_CODECS_COMMON_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // vulkan_video_codecs_common is a preprocessor guard. Do not pass it to API calls. 23 | #define vulkan_video_codecs_common 1 24 | #if !defined(VK_NO_STDINT_H) 25 | #include 26 | #endif 27 | 28 | #define VK_MAKE_VIDEO_STD_VERSION(major, minor, patch) \ 29 | ((((uint32_t)(major)) << 22) | (((uint32_t)(minor)) << 12) | ((uint32_t)(patch))) 30 | 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /glad/generator/c/templates/egl.h: -------------------------------------------------------------------------------- 1 | {% extends 'base_template.h' %} 2 | 3 | {% block custom_declarations %} 4 | {% for api in feature_set.info.apis %} 5 | GLAD_API_CALL int gladLoad{{ api|api }}UserPtr(EGLDisplay display, GLADuserptrloadfunc load, void *userptr); 6 | GLAD_API_CALL int gladLoad{{ api|api }}(EGLDisplay display, GLADloadfunc load); 7 | {% endfor %} 8 | {% endblock %} 9 | -------------------------------------------------------------------------------- /glad/generator/c/templates/gl.h: -------------------------------------------------------------------------------- 1 | {% extends 'base_template.h' %} 2 | 3 | {% block header %} 4 | #ifdef __clang__ 5 | #pragma clang diagnostic push 6 | #pragma clang diagnostic ignored "-Wreserved-id-macro" 7 | #endif 8 | {% set header_data = [ 9 | ('gl', '__gl_h_', 'OpenGL (gl.h)'), ('gl', '__gl3_h_', 'OpenGL (gl3.h)'), 10 | ('gl', '__glext_h_', 'OpenGL (glext.h)'), ('gl', '__gl3ext_h_', 'OpenGL (gl3ext.h)'), 11 | ('gles1', '__gl_h_', 'OpenGL ES 1'), ('gles1', '__gles1_gl_h_', 'OpenGL ES 1'), 12 | ('gles2', '__gl2_h_', 'OpenGL ES 2'), ('gles2', '__gles2_gl2_h_', 'OpenGL ES 2'), 13 | ('gles2', '__gl3_h_', 'OpenGL ES 3'), ('gles2', '__gles2_gl3_h_', 'OpenGL ES 3'), 14 | ] %} 15 | {% set written = [] %} 16 | {% for api, header_name, name in header_data %} 17 | {% if api in feature_set.info.apis and header_name not in written -%} 18 | {{ template_utils.header_error(api, header_name, name) }} 19 | {%- do written.append(header_name) -%} 20 | {%- endif -%} 21 | {%- endfor -%} 22 | #ifdef __clang__ 23 | #pragma clang diagnostic pop 24 | #endif 25 | {% endblock %} 26 | 27 | 28 | {% block custom_declarations %} 29 | {% for api in feature_set.info.apis %} 30 | GLAD_API_CALL int gladLoad{{ api|api }}{{ 'Context' if options.mx }}UserPtr({{ template_utils.context_arg(',') }} GLADuserptrloadfunc load, void *userptr); 31 | GLAD_API_CALL int gladLoad{{ api|api }}{{ 'Context' if options.mx }}({{ template_utils.context_arg(',') }} GLADloadfunc load); 32 | 33 | {% if options.mx_global %} 34 | GLAD_API_CALL int gladLoad{{ api|api }}UserPtr(GLADuserptrloadfunc load, void *userptr); 35 | GLAD_API_CALL int gladLoad{{ api|api }}(GLADloadfunc load); 36 | {% endif %} 37 | {% endfor %} 38 | {% endblock %} 39 | -------------------------------------------------------------------------------- /glad/generator/c/templates/glx.c: -------------------------------------------------------------------------------- 1 | {% extends 'base_template.c' %} 2 | 3 | {% block loader %} 4 | static int glad_glx_has_extension(Display *display, int screen, const char *ext) { 5 | #ifndef GLX_VERSION_1_1 6 | GLAD_UNUSED(display); 7 | GLAD_UNUSED(screen); 8 | GLAD_UNUSED(ext); 9 | #else 10 | const char *terminator; 11 | const char *loc; 12 | const char *extensions; 13 | 14 | if (glXQueryExtensionsString == NULL) { 15 | return 0; 16 | } 17 | 18 | extensions = glXQueryExtensionsString(display, screen); 19 | 20 | if(extensions == NULL || ext == NULL) { 21 | return 0; 22 | } 23 | 24 | while(1) { 25 | loc = strstr(extensions, ext); 26 | if(loc == NULL) 27 | break; 28 | 29 | terminator = loc + strlen(ext); 30 | if((loc == extensions || *(loc - 1) == ' ') && 31 | (*terminator == ' ' || *terminator == '\0')) { 32 | return 1; 33 | } 34 | extensions = terminator; 35 | } 36 | #endif 37 | 38 | return 0; 39 | } 40 | 41 | static GLADapiproc glad_glx_get_proc_from_userptr(void *userptr, const char* name) { 42 | return (GLAD_GNUC_EXTENSION (GLADapiproc (*)(const char *name)) userptr)(name); 43 | } 44 | 45 | {% for api in feature_set.info.apis %} 46 | static int glad_glx_find_extensions(Display *display, int screen) { 47 | {% for extension in feature_set.extensions %} 48 | GLAD_{{ extension.name }} = glad_glx_has_extension(display, screen, "{{ extension.name }}"); 49 | {% else %} 50 | GLAD_UNUSED(&glad_glx_has_extension); 51 | {% endfor %} 52 | return 1; 53 | } 54 | 55 | static int glad_glx_find_core_{{ api|lower }}(Display **display, int *screen) { 56 | int major = 0, minor = 0; 57 | if(*display == NULL) { 58 | #ifdef GLAD_GLX_NO_X11 59 | GLAD_UNUSED(screen); 60 | return 0; 61 | #else 62 | *display = XOpenDisplay(0); 63 | if (*display == NULL) { 64 | return 0; 65 | } 66 | *screen = XScreenNumberOfScreen(XDefaultScreenOfDisplay(*display)); 67 | #endif 68 | } 69 | glXQueryVersion(*display, &major, &minor); 70 | {% for feature in feature_set.features %} 71 | GLAD_{{ feature.name }} = (major == {{ feature.version.major }} && minor >= {{ feature.version.minor }}) || major > {{ feature.version.major }}; 72 | {% endfor %} 73 | return GLAD_MAKE_VERSION(major, minor); 74 | } 75 | 76 | int gladLoad{{ api|api }}UserPtr(Display *display, int screen, GLADuserptrloadfunc load, void *userptr) { 77 | int version; 78 | glXQueryVersion = (PFNGLXQUERYVERSIONPROC) load(userptr, "glXQueryVersion"); 79 | if(glXQueryVersion == NULL) return 0; 80 | version = glad_glx_find_core_{{ api|lower }}(&display, &screen); 81 | 82 | {% for feature, _ in loadable(feature_set.features) %} 83 | glad_glx_load_{{ feature.name }}(load, userptr); 84 | {% endfor %} 85 | 86 | if (!glad_glx_find_extensions(display, screen)) return 0; 87 | {% for extension, _ in loadable(feature_set.extensions) %} 88 | glad_glx_load_{{ extension.name }}(load, userptr); 89 | {% endfor %} 90 | 91 | {% if options.alias %} 92 | glad_glx_resolve_aliases(); 93 | {% endif %} 94 | 95 | return version; 96 | } 97 | 98 | int gladLoad{{ api|api }}(Display *display, int screen, GLADloadfunc load) { 99 | return gladLoad{{ api|api }}UserPtr(display, screen, glad_glx_get_proc_from_userptr, GLAD_GNUC_EXTENSION (void*) load); 100 | } 101 | {% endfor %} 102 | 103 | {% endblock %} 104 | -------------------------------------------------------------------------------- /glad/generator/c/templates/glx.h: -------------------------------------------------------------------------------- 1 | {% extends 'base_template.h' %} 2 | 3 | {% block header %} 4 | {{ template_utils.header_error(feature_set.name, feature_set.name|upper + '_H', feature_set.name|api) }} 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | {% endblock %} 12 | 13 | 14 | {% block custom_declarations %} 15 | {% for api in feature_set.info.apis %} 16 | GLAD_API_CALL int gladLoad{{ api|api }}UserPtr(Display *display, int screen, GLADuserptrloadfunc load, void *userptr); 17 | GLAD_API_CALL int gladLoad{{ api|api }}(Display *display, int screen, GLADloadfunc load); 18 | {% endfor %} 19 | {% endblock %} -------------------------------------------------------------------------------- /glad/generator/c/templates/header_only.h: -------------------------------------------------------------------------------- 1 | {% include spec.name + '.h' %} 2 | 3 | /* Source */ 4 | #ifdef GLAD_{{ feature_set.name|upper }}_IMPLEMENTATION 5 | {% include spec.name + '.c' %} 6 | 7 | #endif /* GLAD_{{ feature_set.name|upper }}_IMPLEMENTATION */ 8 | 9 | -------------------------------------------------------------------------------- /glad/generator/c/templates/impl_util.c: -------------------------------------------------------------------------------- 1 | #ifndef GLAD_IMPL_UTIL_C_ 2 | #define GLAD_IMPL_UTIL_C_ 3 | 4 | #ifdef _MSC_VER 5 | #define GLAD_IMPL_UTIL_SSCANF sscanf_s 6 | #else 7 | #define GLAD_IMPL_UTIL_SSCANF sscanf 8 | #endif 9 | 10 | #endif /* GLAD_IMPL_UTIL_C_ */ 11 | -------------------------------------------------------------------------------- /glad/generator/c/templates/loader/egl.c: -------------------------------------------------------------------------------- 1 | {% import "template_utils.h" as template_utils with context %} 2 | #ifdef GLAD_EGL 3 | 4 | {% include 'loader/library.c' %} 5 | 6 | struct _glad_egl_userptr { 7 | void *handle; 8 | PFNEGLGETPROCADDRESSPROC get_proc_address_ptr; 9 | }; 10 | 11 | static GLADapiproc glad_egl_get_proc(void *vuserptr, const char* name) { 12 | struct _glad_egl_userptr userptr = *(struct _glad_egl_userptr*) vuserptr; 13 | GLADapiproc result = NULL; 14 | 15 | result = glad_dlsym_handle(userptr.handle, name); 16 | if (result == NULL) { 17 | result = GLAD_GNUC_EXTENSION (GLADapiproc) userptr.get_proc_address_ptr(name); 18 | } 19 | 20 | return result; 21 | } 22 | 23 | static void* _egl_handle = NULL; 24 | 25 | static void* glad_egl_dlopen_handle(void) { 26 | #if GLAD_PLATFORM_APPLE 27 | static const char *NAMES[] = {"libEGL.dylib"}; 28 | #elif GLAD_PLATFORM_WIN32 29 | static const char *NAMES[] = {"libEGL.dll", "EGL.dll"}; 30 | #else 31 | static const char *NAMES[] = {"libEGL.so.1", "libEGL.so"}; 32 | #endif 33 | 34 | if (_egl_handle == NULL) { 35 | _egl_handle = glad_get_dlopen_handle(NAMES, sizeof(NAMES) / sizeof(NAMES[0])); 36 | } 37 | 38 | return _egl_handle; 39 | } 40 | 41 | static struct _glad_egl_userptr glad_egl_build_userptr(void *handle) { 42 | struct _glad_egl_userptr userptr; 43 | userptr.handle = handle; 44 | userptr.get_proc_address_ptr = (PFNEGLGETPROCADDRESSPROC) glad_dlsym_handle(handle, "eglGetProcAddress"); 45 | return userptr; 46 | } 47 | 48 | {% if not options.on_demand %} 49 | int gladLoaderLoadEGL(EGLDisplay display) { 50 | int version = 0; 51 | void *handle = NULL; 52 | int did_load = 0; 53 | struct _glad_egl_userptr userptr; 54 | 55 | did_load = _egl_handle == NULL; 56 | handle = glad_egl_dlopen_handle(); 57 | if (handle != NULL) { 58 | userptr = glad_egl_build_userptr(handle); 59 | 60 | if (userptr.get_proc_address_ptr != NULL) { 61 | version = gladLoadEGLUserPtr(display, glad_egl_get_proc, &userptr); 62 | } 63 | 64 | if (!version && did_load) { 65 | gladLoaderUnloadEGL(); 66 | } 67 | } 68 | 69 | return version; 70 | } 71 | {% endif %} 72 | 73 | {% if options.on_demand %} 74 | {% call template_utils.zero_initialized() %}static struct _glad_egl_userptr glad_egl_internal_loader_global_userptr{% endcall %} 75 | static GLADapiproc glad_egl_internal_loader_get_proc(const char *name) { 76 | if (glad_egl_internal_loader_global_userptr.handle == NULL) { 77 | glad_egl_internal_loader_global_userptr = glad_egl_build_userptr(glad_egl_dlopen_handle()); 78 | } 79 | 80 | return glad_egl_get_proc((void *) &glad_egl_internal_loader_global_userptr, name); 81 | } 82 | {% endif %} 83 | 84 | void gladLoaderUnloadEGL(void) { 85 | if (_egl_handle != NULL) { 86 | glad_close_dlopen_handle(_egl_handle); 87 | _egl_handle = NULL; 88 | {% if options.on_demand %} 89 | glad_egl_internal_loader_global_userptr.handle = NULL; 90 | {% endif %} 91 | } 92 | } 93 | 94 | #endif /* GLAD_EGL */ 95 | -------------------------------------------------------------------------------- /glad/generator/c/templates/loader/egl.h: -------------------------------------------------------------------------------- 1 | #ifdef GLAD_EGL 2 | 3 | {% if not options.on_demand %} 4 | GLAD_API_CALL int gladLoaderLoadEGL(EGLDisplay display); 5 | {% endif %} 6 | 7 | GLAD_API_CALL void gladLoaderUnloadEGL(void); 8 | 9 | #endif -------------------------------------------------------------------------------- /glad/generator/c/templates/loader/gl.h: -------------------------------------------------------------------------------- 1 | {% import "template_utils.h" as template_utils with context %} 2 | #ifdef GLAD_GL 3 | 4 | {% if not options.on_demand %} 5 | GLAD_API_CALL int gladLoaderLoadGL{{ 'Context' if options.mx }}({{ template_utils.context_arg(def='void') }}); 6 | {% endif %} 7 | {% if options.mx_global %} 8 | GLAD_API_CALL int gladLoaderLoadGL(void); 9 | {% endif %} 10 | GLAD_API_CALL void gladLoaderUnloadGL{{ 'Context' if options.mx }}({{ template_utils.context_arg(def='void') }}); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /glad/generator/c/templates/loader/gles1.c: -------------------------------------------------------------------------------- 1 | {% import "template_utils.h" as template_utils with context %} 2 | #ifdef GLAD_GLES1 3 | 4 | {% set loader_handle = template_utils.handle('gles1') %} 5 | {% include 'loader/library.c' %} 6 | 7 | #include 8 | 9 | struct _glad_gles1_userptr { 10 | void *handle; 11 | PFNEGLGETPROCADDRESSPROC get_proc_address_ptr; 12 | }; 13 | 14 | 15 | static GLADapiproc glad_gles1_get_proc(void *vuserptr, const char* name) { 16 | struct _glad_gles1_userptr userptr = *(struct _glad_gles1_userptr*) vuserptr; 17 | GLADapiproc result = NULL; 18 | 19 | {# /* dlsym first, since some implementations don't return function pointers for core functions */ #} 20 | result = glad_dlsym_handle(userptr.handle, name); 21 | if (result == NULL) { 22 | result = userptr.get_proc_address_ptr(name); 23 | } 24 | 25 | return result; 26 | } 27 | 28 | {% if not options.mx %} 29 | static void* {{ loader_handle }} = NULL; 30 | {% endif %} 31 | 32 | static void* glad_gles1_dlopen_handle({{ template_utils.context_arg(def='void') }}) { 33 | #if GLAD_PLATFORM_APPLE 34 | static const char *NAMES[] = {"libGLESv1_CM.dylib"}; 35 | #elif GLAD_PLATFORM_WIN32 36 | static const char *NAMES[] = {"GLESv1_CM.dll", "libGLESv1_CM", "libGLES_CM.dll"}; 37 | #else 38 | static const char *NAMES[] = {"libGLESv1_CM.so.1", "libGLESv1_CM.so", "libGLES_CM.so.1"}; 39 | #endif 40 | 41 | if ({{ loader_handle }} == NULL) { 42 | {{ loader_handle }} = glad_get_dlopen_handle(NAMES, sizeof(NAMES) / sizeof(NAMES[0])); 43 | } 44 | 45 | return {{ loader_handle }}; 46 | } 47 | 48 | static struct _glad_gles1_userptr glad_gles1_build_userptr(void *handle) { 49 | struct _glad_gles1_userptr userptr; 50 | userptr.handle = handle; 51 | userptr.get_proc_address_ptr = eglGetProcAddress; 52 | return userptr; 53 | } 54 | 55 | {% if not options.on_demand %} 56 | int gladLoaderLoadGLES1{{ 'Context' if options.mx }}({{ template_utils.context_arg(def='void') }}) { 57 | int version = 0; 58 | void *handle = NULL; 59 | int did_load = 0; 60 | struct _glad_gles1_userptr userptr; 61 | 62 | if (eglGetProcAddress == NULL) { 63 | return 0; 64 | } 65 | 66 | did_load = {{ loader_handle }} == NULL; 67 | handle = glad_gles1_dlopen_handle({{ 'context' if options.mx }}); 68 | if (handle != NULL) { 69 | userptr = glad_gles1_build_userptr(handle); 70 | 71 | version = gladLoadGLES1{{ 'Context' if options.mx }}UserPtr({{ 'context, ' if options.mx }}glad_gles1_get_proc, &userptr); 72 | 73 | if (!version && did_load) { 74 | gladLoaderUnloadGLES1{{ 'Context' if options.mx }}({{ 'context' if options.mx }}); 75 | } 76 | } 77 | 78 | return version; 79 | } 80 | {% endif %} 81 | 82 | {% if options.on_demand %} 83 | {% call template_utils.zero_initialized() %}static struct _glad_gles1_userptr glad_gles1_internal_loader_global_userptr{% endcall %} 84 | static GLADapiproc glad_gles1_internal_loader_get_proc(const char *name) { 85 | if (glad_gles1_internal_loader_global_userptr.handle == NULL) { 86 | glad_gles1_internal_loader_global_userptr = glad_gles1_build_userptr(glad_gles1_dlopen_handle()); 87 | } 88 | 89 | return glad_gles1_get_proc((void *) &glad_gles1_internal_loader_global_userptr, name); 90 | } 91 | {% endif %} 92 | 93 | {% if options.mx_global %} 94 | int gladLoaderLoadGLES1(void) { 95 | return gladLoaderLoadGLES1Context(gladGet{{ feature_set.name|api }}Context()); 96 | } 97 | {% endif %} 98 | 99 | void gladLoaderUnloadGLES1{{ 'Context' if options.mx }}({{ template_utils.context_arg(def='void') }}) { 100 | if ({{ loader_handle }} != NULL) { 101 | glad_close_dlopen_handle({{ loader_handle }}); 102 | {{ loader_handle }} = NULL; 103 | {% if options.on_demand %} 104 | glad_gles1_internal_loader_global_userptr.handle = NULL; 105 | {% endif %} 106 | } 107 | } 108 | 109 | #endif /* GLAD_GLES1 */ 110 | -------------------------------------------------------------------------------- /glad/generator/c/templates/loader/gles1.h: -------------------------------------------------------------------------------- 1 | {% import "template_utils.h" as template_utils with context %} 2 | #ifdef GLAD_GLES1 3 | {# 4 | #ifndef __egl_h_ 5 | #error "gles1 loader requires egl.h, include egl.h () before including the loader." 6 | #endif 7 | #} 8 | 9 | {% if not options.on_demand %} 10 | GLAD_API_CALL int gladLoaderLoadGLES1{{ 'Context' if options.mx }}({{ template_utils.context_arg(def='void') }}); 11 | {% endif %} 12 | {% if options.mx_global %} 13 | GLAD_API_CALL int gladLoaderLoadGLES1(void); 14 | {% endif %} 15 | GLAD_API_CALL void gladLoaderUnloadGLES1{{ 'Context' if options.mx }}({{ template_utils.context_arg(def='void') }}); 16 | 17 | #endif /* GLAD_GLES1 */ 18 | -------------------------------------------------------------------------------- /glad/generator/c/templates/loader/gles2.h: -------------------------------------------------------------------------------- 1 | {% import "template_utils.h" as template_utils with context %} 2 | #ifdef GLAD_GLES2 3 | {# 4 | #ifndef __egl_h_ 5 | #error "gles2 loader requires egl.h, include egl.h () before including the loader." 6 | #endif 7 | #} 8 | 9 | {% if not options.on_demand %} 10 | GLAD_API_CALL int gladLoaderLoadGLES2{{ 'Context' if options.mx }}({{ template_utils.context_arg(def='void') }}); 11 | {% endif %} 12 | {% if options.mx_global %} 13 | GLAD_API_CALL int gladLoaderLoadGLES2(void); 14 | {% endif %} 15 | GLAD_API_CALL void gladLoaderUnloadGLES2{{ 'Context' if options.mx }}({{ template_utils.context_arg(def='void') }}); 16 | 17 | #endif /* GLAD_GLES2 */ 18 | 19 | -------------------------------------------------------------------------------- /glad/generator/c/templates/loader/glsc2.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dav1dde/glad/431786d8126e4f383a81e36f47b61a5d52a1c20d/glad/generator/c/templates/loader/glsc2.c -------------------------------------------------------------------------------- /glad/generator/c/templates/loader/glsc2.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dav1dde/glad/431786d8126e4f383a81e36f47b61a5d52a1c20d/glad/generator/c/templates/loader/glsc2.h -------------------------------------------------------------------------------- /glad/generator/c/templates/loader/glx.c: -------------------------------------------------------------------------------- 1 | #ifdef GLAD_GLX 2 | 3 | {% include 'loader/library.c' %} 4 | 5 | typedef void* (GLAD_API_PTR *GLADglxprocaddrfunc)(const char*); 6 | 7 | static GLADapiproc glad_glx_get_proc(void *userptr, const char *name) { 8 | return GLAD_GNUC_EXTENSION ((GLADapiproc (*)(const char *name)) userptr)(name); 9 | } 10 | 11 | static void* _glx_handle; 12 | 13 | static void* glad_glx_dlopen_handle(void) { 14 | static const char *NAMES[] = { 15 | #if defined __CYGWIN__ 16 | "libGL-1.so", 17 | #endif 18 | "libGL.so.1", 19 | "libGL.so" 20 | }; 21 | 22 | if (_glx_handle == NULL) { 23 | _glx_handle = glad_get_dlopen_handle(NAMES, sizeof(NAMES) / sizeof(NAMES[0])); 24 | } 25 | 26 | return _glx_handle; 27 | } 28 | 29 | {% if not options.on_demand %} 30 | int gladLoaderLoadGLX(Display *display, int screen) { 31 | int version = 0; 32 | void *handle = NULL; 33 | int did_load = 0; 34 | GLADglxprocaddrfunc loader; 35 | 36 | did_load = _glx_handle == NULL; 37 | handle = glad_glx_dlopen_handle(); 38 | if (handle != NULL) { 39 | loader = (GLADglxprocaddrfunc) glad_dlsym_handle(handle, "glXGetProcAddressARB"); 40 | if (loader != NULL) { 41 | version = gladLoadGLXUserPtr(display, screen, glad_glx_get_proc, GLAD_GNUC_EXTENSION (void*) loader); 42 | } 43 | 44 | if (!version && did_load) { 45 | gladLoaderUnloadGLX(); 46 | } 47 | } 48 | 49 | return version; 50 | } 51 | {% endif %} 52 | 53 | {% if options.on_demand %} 54 | static GLADglxprocaddrfunc glad_glx_internal_loader_global_userptr = NULL; 55 | static GLADapiproc glad_glx_internal_loader_get_proc(const char *name) { 56 | if (glad_glx_internal_loader_global_userptr == NULL) { 57 | glad_glx_internal_loader_global_userptr = (GLADglxprocaddrfunc) glad_dlsym_handle(glad_glx_dlopen_handle(), "glXGetProcAddressARB"); 58 | } 59 | 60 | return glad_glx_get_proc(GLAD_GNUC_EXTENSION (void *) glad_glx_internal_loader_global_userptr, name); 61 | } 62 | {% endif %} 63 | 64 | void gladLoaderUnloadGLX() { 65 | if (_glx_handle != NULL) { 66 | glad_close_dlopen_handle(_glx_handle); 67 | _glx_handle = NULL; 68 | {% if options.on_demand %} 69 | glad_glx_internal_loader_global_userptr = NULL; 70 | {% endif %} 71 | } 72 | } 73 | 74 | #endif /* GLAD_GLX */ 75 | -------------------------------------------------------------------------------- /glad/generator/c/templates/loader/glx.h: -------------------------------------------------------------------------------- 1 | #ifdef GLAD_GLX 2 | 3 | {% if not options.on_demand %} 4 | GLAD_API_CALL int gladLoaderLoadGLX(Display *display, int screen); 5 | {% endif %} 6 | 7 | GLAD_API_CALL void gladLoaderUnloadGLX(void); 8 | 9 | #endif -------------------------------------------------------------------------------- /glad/generator/c/templates/loader/library.c: -------------------------------------------------------------------------------- 1 | #ifndef GLAD_LOADER_LIBRARY_C_ 2 | #define GLAD_LOADER_LIBRARY_C_ 3 | 4 | #include 5 | #include 6 | 7 | #if GLAD_PLATFORM_WIN32 8 | #include 9 | #else 10 | #include 11 | #endif 12 | 13 | 14 | static void* glad_get_dlopen_handle(const char *lib_names[], int length) { 15 | void *handle = NULL; 16 | int i; 17 | 18 | for (i = 0; i < length; ++i) { 19 | #if GLAD_PLATFORM_WIN32 20 | #if GLAD_PLATFORM_UWP 21 | size_t buffer_size = (strlen(lib_names[i]) + 1) * sizeof(WCHAR); 22 | LPWSTR buffer = (LPWSTR) malloc(buffer_size); 23 | if (buffer != NULL) { 24 | int ret = MultiByteToWideChar(CP_ACP, 0, lib_names[i], -1, buffer, buffer_size); 25 | if (ret != 0) { 26 | handle = (void*) LoadPackagedLibrary(buffer, 0); 27 | } 28 | free((void*) buffer); 29 | } 30 | #else 31 | handle = (void*) LoadLibraryA(lib_names[i]); 32 | #endif 33 | #else 34 | handle = dlopen(lib_names[i], RTLD_LAZY | RTLD_LOCAL); 35 | #endif 36 | if (handle != NULL) { 37 | return handle; 38 | } 39 | } 40 | 41 | return NULL; 42 | } 43 | 44 | static void glad_close_dlopen_handle(void* handle) { 45 | if (handle != NULL) { 46 | #if GLAD_PLATFORM_WIN32 47 | FreeLibrary((HMODULE) handle); 48 | #else 49 | dlclose(handle); 50 | #endif 51 | } 52 | } 53 | 54 | static GLADapiproc glad_dlsym_handle(void* handle, const char *name) { 55 | if (handle == NULL) { 56 | return NULL; 57 | } 58 | 59 | #if GLAD_PLATFORM_WIN32 60 | return (GLADapiproc) GetProcAddress((HMODULE) handle, name); 61 | #else 62 | return GLAD_GNUC_EXTENSION (GLADapiproc) dlsym(handle, name); 63 | #endif 64 | } 65 | 66 | #endif /* GLAD_LOADER_LIBRARY_C_ */ 67 | -------------------------------------------------------------------------------- /glad/generator/c/templates/loader/vulkan.h: -------------------------------------------------------------------------------- 1 | {% import "template_utils.h" as template_utils with context %} 2 | #ifdef GLAD_VULKAN 3 | 4 | {% if not options.on_demand %} 5 | GLAD_API_CALL int gladLoaderLoadVulkan{{ 'Context' if options.mx }}({{ template_utils.context_arg(',') }} VkInstance instance, VkPhysicalDevice physical_device, VkDevice device); 6 | {% endif %} 7 | {% if options.mx_global %} 8 | GLAD_API_CALL int gladLoaderLoadVulkan(VkInstance instance, VkPhysicalDevice physical_device, VkDevice device); 9 | {% endif %} 10 | GLAD_API_CALL void gladLoaderUnloadVulkan{{ 'Context' if options.mx }}({{ template_utils.context_arg(def='void') }}); 11 | 12 | {% if options.on_demand %} 13 | GLAD_API_CALL void gladLoaderSetVulkanInstance(VkInstance instance); 14 | GLAD_API_CALL void gladLoaderSetVulkanDevice(VkDevice device); 15 | {% endif %} 16 | 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /glad/generator/c/templates/loader/wgl.c: -------------------------------------------------------------------------------- 1 | #ifdef GLAD_WGL 2 | 3 | {% if not options.on_demand %} 4 | static GLADapiproc glad_wgl_get_proc(void *vuserptr, const char* name) { 5 | GLAD_UNUSED(vuserptr); 6 | return GLAD_GNUC_EXTENSION (GLADapiproc) wglGetProcAddress(name); 7 | } 8 | 9 | int gladLoaderLoadWGL(HDC hdc) { 10 | return gladLoadWGLUserPtr(hdc, glad_wgl_get_proc, NULL); 11 | } 12 | {% endif %} 13 | 14 | {% if options.on_demand %} 15 | static GLADapiproc glad_wgl_internal_loader_get_proc(const char *name) { 16 | return GLAD_GNUC_EXTENSION (GLADapiproc) wglGetProcAddress(name); 17 | } 18 | {% endif %} 19 | 20 | #endif /* GLAD_WGL */ 21 | -------------------------------------------------------------------------------- /glad/generator/c/templates/loader/wgl.h: -------------------------------------------------------------------------------- 1 | #ifdef GLAD_WGL 2 | 3 | {% if not options.on_demand %} 4 | GLAD_API_CALL int gladLoaderLoadWGL(HDC hdc); 5 | {% endif %} 6 | 7 | #endif -------------------------------------------------------------------------------- /glad/generator/c/templates/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef GLAD_PLATFORM_H_ 2 | #define GLAD_PLATFORM_H_ 3 | 4 | #ifndef GLAD_PLATFORM_WIN32 5 | #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__MINGW32__) 6 | #define GLAD_PLATFORM_WIN32 1 7 | #else 8 | #define GLAD_PLATFORM_WIN32 0 9 | #endif 10 | #endif 11 | 12 | #ifndef GLAD_PLATFORM_APPLE 13 | #ifdef __APPLE__ 14 | #define GLAD_PLATFORM_APPLE 1 15 | #else 16 | #define GLAD_PLATFORM_APPLE 0 17 | #endif 18 | #endif 19 | 20 | #ifndef GLAD_PLATFORM_EMSCRIPTEN 21 | #ifdef __EMSCRIPTEN__ 22 | #define GLAD_PLATFORM_EMSCRIPTEN 1 23 | #else 24 | #define GLAD_PLATFORM_EMSCRIPTEN 0 25 | #endif 26 | #endif 27 | 28 | #ifndef GLAD_PLATFORM_UWP 29 | #if defined(_MSC_VER) && !defined(GLAD_INTERNAL_HAVE_WINAPIFAMILY) 30 | #ifdef __has_include 31 | #if __has_include() 32 | #define GLAD_INTERNAL_HAVE_WINAPIFAMILY 1 33 | #endif 34 | #elif _MSC_VER >= 1700 && !_USING_V110_SDK71_ 35 | #define GLAD_INTERNAL_HAVE_WINAPIFAMILY 1 36 | #endif 37 | #endif 38 | 39 | #ifdef GLAD_INTERNAL_HAVE_WINAPIFAMILY 40 | #include 41 | #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) 42 | #define GLAD_PLATFORM_UWP 1 43 | #endif 44 | #endif 45 | 46 | #ifndef GLAD_PLATFORM_UWP 47 | #define GLAD_PLATFORM_UWP 0 48 | #endif 49 | #endif 50 | 51 | #ifdef __GNUC__ 52 | #define GLAD_GNUC_EXTENSION __extension__ 53 | #else 54 | #define GLAD_GNUC_EXTENSION 55 | #endif 56 | 57 | #define GLAD_UNUSED(x) (void)(x) 58 | 59 | #ifndef GLAD_API_CALL 60 | #if defined(GLAD_API_CALL_EXPORT) 61 | #if GLAD_PLATFORM_WIN32 || defined(__CYGWIN__) 62 | #if defined(GLAD_API_CALL_EXPORT_BUILD) 63 | #if defined(__GNUC__) 64 | #define GLAD_API_CALL __attribute__ ((dllexport)) extern 65 | #else 66 | #define GLAD_API_CALL __declspec(dllexport) extern 67 | #endif 68 | #else 69 | #if defined(__GNUC__) 70 | #define GLAD_API_CALL __attribute__ ((dllimport)) extern 71 | #else 72 | #define GLAD_API_CALL __declspec(dllimport) extern 73 | #endif 74 | #endif 75 | #elif defined(__GNUC__) && defined(GLAD_API_CALL_EXPORT_BUILD) 76 | #define GLAD_API_CALL __attribute__ ((visibility ("default"))) extern 77 | #else 78 | #define GLAD_API_CALL extern 79 | #endif 80 | #else 81 | #define GLAD_API_CALL extern 82 | #endif 83 | #endif 84 | 85 | #ifdef APIENTRY 86 | #define GLAD_API_PTR APIENTRY 87 | #elif GLAD_PLATFORM_WIN32 88 | #define GLAD_API_PTR __stdcall 89 | #else 90 | #define GLAD_API_PTR 91 | #endif 92 | 93 | #ifndef GLAPI 94 | #define GLAPI GLAD_API_CALL 95 | #endif 96 | 97 | #ifndef GLAPIENTRY 98 | #define GLAPIENTRY GLAD_API_PTR 99 | #endif 100 | 101 | #define GLAD_MAKE_VERSION(major, minor) (major * 10000 + minor) 102 | #define GLAD_VERSION_MAJOR(version) (version / 10000) 103 | #define GLAD_VERSION_MINOR(version) (version % 10000) 104 | 105 | #define GLAD_GENERATOR_VERSION "{{ gen_info.version }}" 106 | 107 | typedef void (*GLADapiproc)(void); 108 | 109 | typedef GLADapiproc (*GLADloadfunc)(const char *name); 110 | typedef GLADapiproc (*GLADuserptrloadfunc)(void *userptr, const char *name); 111 | 112 | typedef void (*GLADprecallback)(const char *name, GLADapiproc apiproc, int len_args, ...); 113 | typedef void (*GLADpostcallback)(void *ret, const char *name, GLADapiproc apiproc, int len_args, ...); 114 | 115 | #endif /* GLAD_PLATFORM_H_ */ 116 | -------------------------------------------------------------------------------- /glad/generator/c/templates/vk.h: -------------------------------------------------------------------------------- 1 | {% extends 'base_template.h' %} 2 | 3 | 4 | {% block header %} 5 | {{ template_utils.header_error(feature_set.name, feature_set.name.upper() + '_H_', name) }} 6 | {{ template_utils.header_error(feature_set.name, feature_set.name.upper() + '_CORE_H_', name) }} 7 | {% endblock %} 8 | 9 | 10 | {% block custom_declarations %} 11 | {% for api in feature_set.info.apis %} 12 | GLAD_API_CALL int gladLoad{{ api|api }}{{ 'Context' if options.mx }}UserPtr({{ template_utils.context_arg(',') }} VkPhysicalDevice physical_device, GLADuserptrloadfunc load, void *userptr); 13 | GLAD_API_CALL int gladLoad{{ api|api }}{{ 'Context' if options.mx }}({{ template_utils.context_arg(',') }} VkPhysicalDevice physical_device, GLADloadfunc load); 14 | {% endfor %} 15 | 16 | {% if options.mx_global %} 17 | GLAD_API_CALL int gladLoad{{ feature_set.name|api }}UserPtr(VkPhysicalDevice physical_device, GLADuserptrloadfunc load, void *userptr); 18 | GLAD_API_CALL int gladLoad{{ feature_set.name|api }}(VkPhysicalDevice physical_device, GLADloadfunc load); 19 | {% endif %} 20 | {% endblock %} 21 | -------------------------------------------------------------------------------- /glad/generator/c/templates/wgl.c: -------------------------------------------------------------------------------- 1 | {% extends 'base_template.c' %} 2 | 3 | {% block extension_loaders %} 4 | {% for extension, commands in loadable((feature_set.features[1:], feature_set.extensions)) %} 5 | static void glad_wgl_load_{{ extension.name }}(GLADuserptrloadfunc load, void *userptr) { 6 | if(!GLAD_{{ extension.name }}) return; 7 | {% for command in commands %} 8 | glad_{{ command.name }} = ({{ command.name|pfn }}) load(userptr, "{{ command.name }}"); 9 | {% endfor %} 10 | } 11 | {% endfor %} 12 | {% endblock %} 13 | 14 | {% block loader %} 15 | static int glad_wgl_has_extension(HDC hdc, const char *ext) { 16 | const char *terminator; 17 | const char *loc; 18 | const char *extensions; 19 | 20 | if(wglGetExtensionsStringEXT == NULL && wglGetExtensionsStringARB == NULL) 21 | return 0; 22 | 23 | if(wglGetExtensionsStringARB == NULL || hdc == INVALID_HANDLE_VALUE) 24 | extensions = wglGetExtensionsStringEXT(); 25 | else 26 | extensions = wglGetExtensionsStringARB(hdc); 27 | 28 | if(extensions == NULL || ext == NULL) 29 | return 0; 30 | 31 | while(1) { 32 | loc = strstr(extensions, ext); 33 | if(loc == NULL) 34 | break; 35 | 36 | terminator = loc + strlen(ext); 37 | if((loc == extensions || *(loc - 1) == ' ') && 38 | (*terminator == ' ' || *terminator == '\0')) 39 | { 40 | return 1; 41 | } 42 | extensions = terminator; 43 | } 44 | 45 | return 0; 46 | } 47 | 48 | static GLADapiproc glad_wgl_get_proc_from_userptr(void *userptr, const char* name) { 49 | return (GLAD_GNUC_EXTENSION (GLADapiproc (*)(const char *name)) userptr)(name); 50 | } 51 | 52 | {% for api in feature_set.info.apis %} 53 | static int glad_wgl_find_extensions_{{ api|lower }}(HDC hdc) { 54 | {% for extension in feature_set.extensions %} 55 | GLAD_{{ extension.name }} = glad_wgl_has_extension(hdc, "{{ extension.name }}"); 56 | {% else %} 57 | GLAD_UNUSED(&glad_wgl_has_extension); 58 | {% endfor %} 59 | return 1; 60 | } 61 | 62 | static int glad_wgl_find_core_{{ api|lower }}(void) { 63 | {% set hv = feature_set.features|select('supports', api)|list|last %} 64 | int major = {{ hv.version.major }}, minor = {{ hv.version.minor }}; 65 | {% for feature in feature_set.features|select('supports', api) %} 66 | GLAD_{{ feature.name }} = (major == {{ feature.version.major }} && minor >= {{ feature.version.minor }}) || major > {{ feature.version.major }}; 67 | {% endfor %} 68 | return GLAD_MAKE_VERSION(major, minor); 69 | } 70 | 71 | int gladLoad{{ api|api }}UserPtr(HDC hdc, GLADuserptrloadfunc load, void *userptr) { 72 | int version; 73 | wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC) load(userptr, "wglGetExtensionsStringARB"); 74 | wglGetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC) load(userptr, "wglGetExtensionsStringEXT"); 75 | if(wglGetExtensionsStringARB == NULL && wglGetExtensionsStringEXT == NULL) return 0; 76 | version = glad_wgl_find_core_{{ api|lower }}(); 77 | 78 | {% for feature, _ in loadable(feature_set.features[1:], api=api) %} 79 | glad_wgl_load_{{ feature.name }}(load, userptr); 80 | {% endfor %} 81 | 82 | if (!glad_wgl_find_extensions_{{ api|lower }}(hdc)) return 0; 83 | {% for extension, _ in loadable(feature_set.extensions, api=api) %} 84 | glad_wgl_load_{{ extension.name }}(load, userptr); 85 | {% endfor %} 86 | 87 | {% if options.alias %} 88 | glad_wgl_resolve_aliases(); 89 | {% endif %} 90 | 91 | return version; 92 | } 93 | 94 | int gladLoad{{ api|api }}(HDC hdc, GLADloadfunc load) { 95 | return gladLoad{{ api|api }}UserPtr(hdc, glad_wgl_get_proc_from_userptr, GLAD_GNUC_EXTENSION (void*) load); 96 | } 97 | {% endfor %} 98 | {% endblock %} 99 | -------------------------------------------------------------------------------- /glad/generator/c/templates/wgl.h: -------------------------------------------------------------------------------- 1 | {% extends 'base_template.h' %} 2 | 3 | {% block header %} 4 | #include 5 | #include 6 | {% endblock %} 7 | 8 | 9 | {% block commands %} 10 | {{ template_utils.write_function_typedefs(feature_set.commands) }} 11 | {# these are already defined in windows.h #} 12 | {% set blacklist = feature_set.features[0].get_requirements(spec, feature_set=feature_set).commands %} 13 | {{ template_utils.write_function_declarations(feature_set.commands|reject('existsin', blacklist)) }} 14 | {% endblock %} 15 | 16 | 17 | {% block custom_declarations %} 18 | {% for api in feature_set.info.apis %} 19 | GLAD_API_CALL int gladLoad{{ api|api }}UserPtr(HDC hdc, GLADuserptrloadfunc load, void *userptr); 20 | GLAD_API_CALL int gladLoad{{ api|api }}(HDC hdc, GLADloadfunc load); 21 | {% endfor %} 22 | {% endblock %} 23 | -------------------------------------------------------------------------------- /glad/generator/rust/templates/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "glad-{{ feature_set.name }}" 3 | version = "{{ version }}" 4 | authors = ["David Herberth "] 5 | license = "(WTFPL OR CC0-1.0) AND Apache-2.0" 6 | 7 | [features] 8 | {% for platform in spec.platforms.values() %} 9 | {{ platform.protect }} = [] 10 | {{ platform.name }} = ["{{ platform.protect }}"] 11 | {% endfor %} 12 | -------------------------------------------------------------------------------- /glad/generator/rust/templates/lib.rs: -------------------------------------------------------------------------------- 1 | #[allow(clippy::all)] 2 | pub mod {{ spec.name }}; -------------------------------------------------------------------------------- /glad/generator/rust/templates/template_utils.rs: -------------------------------------------------------------------------------- 1 | {% macro protect(symbol) %} 2 | {% set protections = spec.protections(symbol, feature_set=feature_set) %} 3 | {% if protections -%} 4 | #[cfg(any({{ protections|map('feature')|join(',') }}))] 5 | {%- endif -%} 6 | {%- endmacro %} 7 | -------------------------------------------------------------------------------- /glad/generator/rust/templates/types/egl.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code, non_camel_case_types, non_snake_case)] 2 | {% include 'types/khrplatform.rs' %} 3 | 4 | pub type EGLint = khronos_int32_t; 5 | 6 | // TODO replace based on platform, see eglplatform.h 7 | #[cfg(target_os = "macos")] pub type EGLNativeDisplayType = i32; 8 | #[cfg(not(target_os = "macos"))] pub type EGLNativeDisplayType = *mut std::os::raw::c_void; 9 | pub type EGLNativeWindowType = *mut std::os::raw::c_void; 10 | pub type EGLNativePixmapType = *mut std::os::raw::c_void; 11 | 12 | // EGL types 13 | pub type EGLBoolean = std::os::raw::c_uint; 14 | pub type EGLenum = std::os::raw::c_uint; 15 | 16 | pub type EGLClientBuffer = *mut std::os::raw::c_void; 17 | pub type EGLConfig = *mut std::os::raw::c_void; 18 | pub type EGLContext = *mut std::os::raw::c_void; 19 | pub type EGLDeviceEXT = *mut std::os::raw::c_void; 20 | pub type EGLDisplay = *mut std::os::raw::c_void; 21 | pub type EGLImage = *mut std::os::raw::c_void; 22 | pub type EGLImageKHR = *mut std::os::raw::c_void; 23 | pub type EGLLabelKHR = *mut std::os::raw::c_void; 24 | pub type EGLObjectKHR = *mut std::os::raw::c_void; 25 | pub type EGLOutputLayerEXT = *mut std::os::raw::c_void; 26 | pub type EGLOutputPortEXT = *mut std::os::raw::c_void; 27 | pub type EGLStreamKHR = *mut std::os::raw::c_void; 28 | pub type EGLSurface = *mut std::os::raw::c_void; 29 | pub type EGLSync = *mut std::os::raw::c_void; 30 | pub type EGLSyncKHR = *mut std::os::raw::c_void; 31 | pub type EGLSyncNV = *mut std::os::raw::c_void; 32 | 33 | pub type EGLAttrib = isize; 34 | pub type EGLAttribKHR = isize; 35 | pub enum __eglMustCastToProperFunctionPointerType_fn {} 36 | pub type __eglMustCastToProperFunctionPointerType = *mut __eglMustCastToProperFunctionPointerType_fn; 37 | pub type EGLNativeFileDescriptorKHR = std::os::raw::c_int; 38 | pub type EGLnsecsANDROID = khronos_stime_nanoseconds_t; 39 | pub type EGLsizeiANDROID = khronos_ssize_t; 40 | pub type EGLTimeKHR = khronos_utime_nanoseconds_t; 41 | pub type EGLTime = khronos_utime_nanoseconds_t; 42 | pub type EGLTimeNV = khronos_utime_nanoseconds_t; 43 | pub type EGLuint64KHR = khronos_uint64_t; 44 | pub type EGLuint64NV = khronos_utime_nanoseconds_t; 45 | pub struct AHardwareBuffer; 46 | 47 | pub type EGLSetBlobFuncANDROID = extern "system" fn ( 48 | *const std::os::raw::c_void, 49 | EGLsizeiANDROID, 50 | *const std::os::raw::c_void, 51 | EGLsizeiANDROID 52 | ) -> (); 53 | pub type EGLGetBlobFuncANDROID = extern "system" fn ( 54 | *const std::os::raw::c_void, 55 | EGLsizeiANDROID, 56 | *mut std::os::raw::c_void, 57 | EGLsizeiANDROID 58 | ) -> EGLsizeiANDROID; 59 | pub type EGLDEBUGPROCKHR = extern "system" fn ( 60 | error: EGLenum, 61 | command: *mut std::os::raw::c_char, 62 | messageType: EGLint, 63 | threadLabel: EGLLabelKHR, 64 | objectLabel: EGLLabelKHR, 65 | message: *mut std::os::raw::c_char 66 | ) -> (); 67 | 68 | 69 | #[repr(C)] 70 | #[derive(Copy, Clone)] 71 | pub struct EGLClientPixmapHI { 72 | pData: *const std::os::raw::c_void, 73 | iWidth: EGLint, 74 | iHeight: EGLint, 75 | iStride: EGLint, 76 | } 77 | 78 | pub type wl_display = std::os::raw::c_void; 79 | pub type wl_surface = std::os::raw::c_void; 80 | pub type wl_buffer = std::os::raw::c_void; 81 | pub type wl_resource = std::os::raw::c_void; 82 | 83 | -------------------------------------------------------------------------------- /glad/generator/rust/templates/types/gl.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code, non_snake_case, non_camel_case_types)] 2 | 3 | use std::os::raw; 4 | 5 | pub type GLvoid = raw::c_void; 6 | 7 | pub type GLbyte = raw::c_char; 8 | pub type GLubyte = raw::c_uchar; 9 | pub type GLchar = raw::c_char; 10 | pub type GLboolean = raw::c_uchar; 11 | 12 | pub type GLshort = raw::c_short; 13 | pub type GLushort = raw::c_ushort; 14 | 15 | pub type GLint = raw::c_int; 16 | pub type GLuint = raw::c_uint; 17 | pub type GLint64 = i64; 18 | pub type GLuint64 = u64; 19 | 20 | pub type GLintptr = isize; 21 | pub type GLsizeiptr = isize; 22 | pub type GLintptrARB = isize; 23 | pub type GLsizeiptrARB = isize; 24 | pub type GLint64EXT = i64; 25 | pub type GLuint64EXT = u64; 26 | 27 | pub type GLsizei = GLint; 28 | pub type GLclampx = raw::c_int; 29 | pub type GLfixed = GLint; 30 | pub type GLhalf = raw::c_ushort; 31 | pub type GLhalfNV = raw::c_ushort; 32 | pub type GLhalfARB = raw::c_ushort; 33 | 34 | pub type GLenum = raw::c_uint; 35 | pub type GLbitfield = raw::c_uint; 36 | 37 | pub type GLfloat = raw::c_float; 38 | pub type GLdouble = raw::c_double; 39 | pub type GLclampf = raw::c_float; 40 | pub type GLclampd = raw::c_double; 41 | 42 | pub type GLcharARB = raw::c_char; 43 | 44 | #[cfg(target_os = "macos")] 45 | pub type GLhandleARB = *const raw::c_void; 46 | #[cfg(not(target_os = "macos"))] 47 | pub type GLhandleARB = raw::c_uint; 48 | 49 | pub enum __GLsync {} 50 | 51 | pub type GLsync = *const __GLsync; 52 | 53 | pub enum _cl_context {} 54 | 55 | pub enum _cl_event {} 56 | 57 | pub type GLvdpauSurfaceNV = GLintptr; 58 | pub type GLeglClientBufferEXT = *const raw::c_void; 59 | pub type GLeglImageOES = *const raw::c_void; 60 | 61 | 62 | pub type GLDEBUGPROC = extern "system" fn ( 63 | source: GLenum, 64 | type_: GLenum, 65 | id: GLuint, 66 | severity: GLenum, 67 | length: GLsizei, 68 | message: *const GLchar, 69 | userParam: *mut raw::c_void, 70 | ); 71 | pub type GLDEBUGPROCARB = extern "system" fn ( 72 | source: GLenum, 73 | type_: GLenum, 74 | id: GLuint, 75 | severity: GLenum, 76 | length: GLsizei, 77 | message: *const GLchar, 78 | userParam: *mut raw::c_void, 79 | ); 80 | pub type GLDEBUGPROCKHR = extern "system" fn ( 81 | source: GLenum, 82 | type_: GLenum, 83 | id: GLuint, 84 | severity: GLenum, 85 | length: GLsizei, 86 | message: *const GLchar, 87 | userParam: *mut GLvoid, 88 | ); 89 | pub type GLDEBUGPROCAMD = extern "system" fn ( 90 | id: GLuint, 91 | category: GLenum, 92 | severity: GLenum, 93 | length: GLsizei, 94 | message: *const GLchar, 95 | userParam: *mut GLvoid, 96 | ); 97 | pub type GLVULKANPROCNV = extern "system" fn (); 98 | -------------------------------------------------------------------------------- /glad/generator/rust/templates/types/khrplatform.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_camel_case_types)] 2 | 3 | use std; 4 | 5 | // see khrplatform.h for these types 6 | pub type khronos_int8_t = i8; 7 | pub type khronos_uint8_t = u8; 8 | pub type khronos_int16_t = i16; 9 | pub type khronos_uint16_t = u16; 10 | pub type khronos_int32_t = i32; 11 | pub type khronos_uint32_t = u32; 12 | pub type khronos_int64_t = i64; 13 | pub type khronos_uint64_t = u64; 14 | pub type khronos_intptr_t = isize; 15 | pub type khronos_uintptr_t = usize; 16 | pub type khronos_ssize_t = isize; 17 | pub type khronos_usize_t = usize; 18 | pub type khronos_float_t = std::os::raw::c_float; 19 | pub type khronos_time_ns_t = u64; 20 | pub type khronos_stime_nanoseconds_t = i64; 21 | pub type khronos_utime_nanoseconds_t = u64; 22 | -------------------------------------------------------------------------------- /glad/generator/rust/templates/types/vk.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code, non_camel_case_types, non_snake_case)] 2 | 3 | {% import 'template_utils.rs' as template_utils with context %} 4 | 5 | use std; 6 | use std::os::raw::*; 7 | 8 | // types required for: xcb 9 | pub type xcb_connection_t = std::os::raw::c_void; 10 | pub type xcb_window_t = u32; 11 | pub type xcb_visualid_t = u32; 12 | // types required for: xlib(_xrandr) 13 | pub type Display = std::os::raw::c_void; 14 | pub type RROutput = std::os::raw::c_ulong; 15 | pub type Window = std::os::raw::c_ulong; 16 | pub type VisualID = std::os::raw::c_ulong; 17 | // types required for: win32 18 | pub type BOOL = std::os::raw::c_int; 19 | pub type DWORD = std::os::raw::c_ulong; 20 | pub type LPVOID = *mut std::os::raw::c_void; 21 | pub type HANDLE = *mut std::os::raw::c_void; 22 | pub type HMONITOR = *mut std::os::raw::c_void; 23 | pub type WCHAR = u16; 24 | pub type LPCWSTR = *const WCHAR; 25 | pub type HINSTANCE = *mut std::os::raw::c_void; 26 | pub type HWND = *mut std::os::raw::c_void; 27 | #[repr(C)] 28 | #[derive(Copy, Clone)] 29 | pub struct SECURITY_ATTRIBUTES { 30 | nLength: DWORD, 31 | lpSecurityDescriptor: LPVOID, 32 | bInheritHandle: BOOL, 33 | } 34 | // types required for: wayland 35 | pub type wl_display = std::os::raw::c_void; 36 | pub type wl_surface = std::os::raw::c_void; 37 | // types required for: mir 38 | pub type MirConnection = std::os::raw::c_void; 39 | pub type MirSurface = std::os::raw::c_void; 40 | 41 | 42 | #[macro_export] 43 | macro_rules! VK_MAKE_VERSION { 44 | ($major:expr, $minor:expr, $patch:expr) => ((($major) << 22) | (($minor) << 12) | ($patch)); 45 | } 46 | 47 | #[macro_export] 48 | macro_rules! VK_VERSION_MAJOR { ($version:expr) => ($version >> 22); } 49 | #[macro_export] 50 | macro_rules! VK_VERSION_MINOR { ($version:expr) => (($version >> 12) & 0x3ff); } 51 | #[macro_export] 52 | macro_rules! VK_VERSION_PATCH { ($version:expr) => ($version & 0xfff); } 53 | 54 | #[macro_export] 55 | macro_rules! VK_DEFINE_NON_DISPATCHABLE_HANDLE { 56 | ($name:ident) => ( 57 | #[repr(C)] 58 | #[derive(Copy, Clone)] 59 | pub struct $name(u64); 60 | ); 61 | } 62 | 63 | #[macro_export] 64 | macro_rules! VK_DEFINE_HANDLE { 65 | ($name:ident) => ( 66 | #[repr(C)] 67 | #[derive(Copy, Clone)] 68 | pub struct $name(*const std::os::raw::c_void); 69 | ); 70 | } 71 | 72 | {% for type in feature_set.types %} 73 | {% if type.alias %} 74 | pub type {{ type.name }} = {{ type.alias }}; 75 | {% elif type.category == 'basetype' %} 76 | pub type {{ type.name }} = {{ type.type|type }}; 77 | {% elif type.category == 'handle' %} 78 | {{ type.type }}!({{ type.name }}); 79 | {% elif type.category == 'enum' %} 80 | {% set members = type.enums_for(feature_set) %} 81 | {% if members %} 82 | {{ template_utils.protect(type) }} 83 | #[repr(i{{ type.bitwidth or '32' }})] 84 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] 85 | pub enum {{ type.name }} { 86 | {% for member in members %} 87 | {% if not member.alias %} {# Aliasing of enums is not allowed in Rust #} 88 | {{ member.name }} = {{ member.value }}, 89 | {% endif %} 90 | {% endfor %} 91 | } 92 | {% endif %} 93 | {% elif type.category in ('struct', 'union') %} 94 | {{ template_utils.protect(type) }} 95 | #[allow(non_snake_case)] 96 | #[repr(C)] 97 | #[derive(Copy, Clone)] 98 | pub {{ type.category }} {{ type.name }} { 99 | {% for member in type.members %} 100 | pub {{ member.name|identifier }}: {{ member.type|type }}, 101 | {% endfor %} 102 | } 103 | {% elif type.category == 'bitmask' %} 104 | pub type {{ type.name }} = {{ type.type }}; 105 | {% elif type.category == 'funcpointer' %} 106 | pub type {{ type.name }} = extern "system" fn( 107 | {% for parameter in type.parameters %} 108 | {{ parameter.name }}: {{ parameter.type|type }}, 109 | {% endfor %} 110 | ) -> {{ type.ret|type }}; 111 | {% endif %} 112 | {% endfor %} 113 | -------------------------------------------------------------------------------- /glad/opener.py: -------------------------------------------------------------------------------- 1 | from contextlib import closing 2 | import logging 3 | import sys 4 | 5 | if sys.version_info >= (3, 0): 6 | _is_py3 = True 7 | from urllib.request import build_opener, ContentTooShortError 8 | else: 9 | _is_py3 = False 10 | from urllib2 import build_opener 11 | from urllib import FancyURLopener 12 | 13 | 14 | logger = logging.getLogger('glad.opener') 15 | 16 | 17 | def build_urllib_opener(user_agent, *args, **kwargs): 18 | if _is_py3: 19 | return None 20 | 21 | class UrllibURLOpener(FancyURLopener): 22 | version = user_agent 23 | return UrllibURLOpener(*args, **kwargs) 24 | 25 | 26 | def _urlretrieve_with_opener(opener, url, filename, data=None): 27 | if not _is_py3: 28 | raise SyntaxError('Only call this in Python 3 code.') 29 | 30 | # borrowed from the original implementation at urllib.request.urlretrieve. 31 | with closing(opener.open(url, data=data)) as src: 32 | headers = src.info() 33 | 34 | with open(filename, 'wb') as dest: 35 | result = filename, headers 36 | bs = 1024*8 37 | size = -1 38 | read = 0 39 | blocknum = 0 40 | if "content-length" in headers: 41 | size = int(headers["Content-Length"]) 42 | 43 | while True: 44 | block = src.read(bs) 45 | if not block: 46 | break 47 | read += len(block) 48 | dest.write(block) 49 | blocknum += 1 50 | 51 | if size >= 0 and read < size: 52 | raise ContentTooShortError( 53 | 'retrieval incomplete: got only %i out of %i bytes' 54 | % (read, size), result) 55 | 56 | return result 57 | 58 | 59 | class URLOpener(object): 60 | """ 61 | Class to download/find Khronos related files, like 62 | the official specs and khrplatform.h. 63 | 64 | Can also be used to download files, exists mainly because of 65 | Python 2 and Python 3 incompatibilities. 66 | """ 67 | def __init__(self, user_agent='Mozilla/5.0'): 68 | # the urllib2/urllib.request opener 69 | self.opener = build_opener() 70 | self.opener.addheaders = [('User-agent', user_agent)] 71 | 72 | # the urllib opener (Python 2 only) 73 | self.opener2 = build_urllib_opener(user_agent) 74 | 75 | def urlopen(self, url, data=None, *args, **kwargs): 76 | """ 77 | Same as urllib2.urlopen or urllib.request.urlopen, 78 | the only difference is that it links to the internal opener. 79 | """ 80 | logger.info('opening: \'%s\'', url) 81 | 82 | if data is None: 83 | return self.opener.open(url) 84 | 85 | return self.opener.open(url, data) 86 | 87 | def urlretrieve(self, url, filename, data=None): 88 | """ 89 | Similar to urllib.urlretrieve or urllib.request.urlretrieve 90 | only that *filname* is required. 91 | 92 | :param url: URL to download. 93 | :param filename: Filename to save the content to. 94 | :param data: Valid URL-encoded data. 95 | :return: Tuple containing path and headers. 96 | """ 97 | logger.info('saving: \'%s\' to \'%s\'', url, filename) 98 | 99 | if _is_py3: 100 | return _urlretrieve_with_opener(self.opener, url, filename, data=data) 101 | 102 | return self.opener2.retrieve(url, filename, data=data) 103 | 104 | # just a singleton helper: 105 | _default = None 106 | 107 | @classmethod 108 | def default(cls): 109 | if cls._default is None: 110 | cls._default = cls() 111 | 112 | return cls._default 113 | -------------------------------------------------------------------------------- /glad/plugin.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import logging 3 | import inspect 4 | try: 5 | from importlib.metadata import entry_points 6 | 7 | if sys.version_info < (3, 10): 8 | _entry_points = entry_points 9 | 10 | def entry_points(group=None): 11 | return _entry_points().get(group, []) 12 | except ImportError: 13 | from pkg_resources import iter_entry_points as entry_points 14 | 15 | import glad.specification 16 | from glad.generator.c import CGenerator 17 | from glad.generator.rust import RustGenerator 18 | from glad.parse import Specification 19 | 20 | 21 | logger = logging.getLogger(__name__) 22 | 23 | 24 | GENERATOR_ENTRY_POINT = 'glad.generator' 25 | SPECIFICATION_ENTRY_POINT = 'glad.specification' 26 | 27 | 28 | DEFAULT_GENERATORS = dict( 29 | c=CGenerator, 30 | rust=RustGenerator 31 | ) 32 | DEFAULT_SPECIFICATIONS = dict() 33 | 34 | for name, cls in inspect.getmembers(glad.specification, inspect.isclass): 35 | if issubclass(cls, Specification) and cls is not Specification: 36 | DEFAULT_SPECIFICATIONS[cls.NAME] = cls 37 | 38 | 39 | def find_generators(default=None, entry_point=GENERATOR_ENTRY_POINT): 40 | generators = dict(DEFAULT_GENERATORS if default is None else default) 41 | 42 | for entry_point in entry_points(group=entry_point): 43 | generators[entry_point.name] = entry_point.load() 44 | logger.debug('loaded language %s: %s', entry_point.name, generators[entry_point.name]) 45 | 46 | return generators 47 | 48 | 49 | def find_specifications(default=None, entry_point=SPECIFICATION_ENTRY_POINT): 50 | specifications = dict(DEFAULT_SPECIFICATIONS if default is None else default) 51 | 52 | for entry_point in entry_points(group=entry_point): 53 | specifications[entry_point.name] = entry_point.load() 54 | logger.debug('loaded specification %s: %s', entry_point.name, specifications[entry_point.name]) 55 | 56 | return specifications 57 | -------------------------------------------------------------------------------- /glad/sink.py: -------------------------------------------------------------------------------- 1 | import collections 2 | import logging 3 | 4 | 5 | class Sink(object): 6 | def info(self, message, exc=None): 7 | raise NotImplementedError 8 | 9 | def warning(self, message, exc=None): 10 | raise NotImplementedError 11 | 12 | def error(self, message, exc=None): 13 | raise NotImplementedError 14 | 15 | 16 | class NullSink(Sink): 17 | def info(self, message, exc=None): 18 | pass 19 | 20 | def warning(self, message, exc=None): 21 | pass 22 | 23 | def error(self, message, exc=None): 24 | pass 25 | 26 | 27 | class LoggingSink(Sink): 28 | _DEFAULT_LOGGER = logging.getLogger(__name__) 29 | 30 | def __init__(self, name=None, logger=None): 31 | self.logger = logger 32 | if self.logger is None and name is not None: 33 | self.logger = logging.getLogger(name) 34 | if self.logger is None: 35 | self.logger = self._DEFAULT_LOGGER 36 | 37 | def info(self, message, exc=None): 38 | self.logger.info(message) 39 | 40 | def warning(self, message, exc=None): 41 | self.logger.warning(message) 42 | 43 | def error(self, message, exc=None): 44 | self.logger.error(message) 45 | 46 | 47 | Message = collections.namedtuple('Message', ['type', 'content', 'exc']) 48 | 49 | 50 | class CollectingSink(Sink): 51 | def __init__(self): 52 | self.messages = list() 53 | 54 | def info(self, message, exc=None): 55 | self.messages.append(Message('info', message, exc)) 56 | 57 | def warning(self, message, exc=None): 58 | self.messages.append(Message('warning', message, exc)) 59 | 60 | def error(self, message, exc=None): 61 | self.messages.append(Message('error', message, exc)) 62 | 63 | @property 64 | def infos(self): 65 | return [m for m in self.messages if m.type == 'info'] 66 | 67 | @property 68 | def warnings(self): 69 | return [m for m in self.messages if m.type == 'warning'] 70 | 71 | @property 72 | def errors(self): 73 | return [m for m in self.messages if m.type == 'error'] 74 | 75 | -------------------------------------------------------------------------------- /glad/specification.py: -------------------------------------------------------------------------------- 1 | from glad.parse import Specification, Require 2 | 3 | 4 | class EGL(Specification): 5 | DISPLAY_NAME = 'EGL' 6 | 7 | API = 'https://raw.githubusercontent.com/KhronosGroup/EGL-Registry/main/api/' 8 | NAME = 'egl' 9 | 10 | def protections(self, symbol, api=None, profile=None, feature_set=None): 11 | return list() 12 | 13 | 14 | class GL(Specification): 15 | DISPLAY_NAME = 'OpenGL' 16 | 17 | API = 'https://raw.githubusercontent.com/KhronosGroup/OpenGL-Registry/main/xml/' 18 | NAME = 'gl' 19 | 20 | def _magic_require(self, api, profile): 21 | require = Specification._magic_require(self, api, profile) 22 | 23 | magic_blacklist = ( 24 | 'stddef', 'khrplatform', 'inttypes', # gl.xml 25 | ) 26 | requirements = [r for r in require.requirements if r not in magic_blacklist] 27 | return Require(api, profile, requirements) 28 | 29 | def protections(self, symbol, api=None, profile=None, feature_set=None): 30 | return list() 31 | 32 | 33 | class GLX(Specification): 34 | DISPLAY_NAME = 'GLX' 35 | 36 | API = 'https://raw.githubusercontent.com/KhronosGroup/OpenGL-Registry/main/xml/' 37 | NAME = 'glx' 38 | 39 | def protections(self, symbol, api=None, profile=None, feature_set=None): 40 | return list() 41 | 42 | 43 | class WGL(Specification): 44 | DISPLAY_NAME = 'WGL' 45 | 46 | API = 'https://raw.githubusercontent.com/KhronosGroup/OpenGL-Registry/main/xml/' 47 | NAME = 'wgl' 48 | 49 | def protections(self, symbol, api=None, profile=None, feature_set=None): 50 | return list() 51 | 52 | 53 | class VK(Specification): 54 | DISPLAY_NAME = 'Vulkan' 55 | 56 | API = 'https://raw.githubusercontent.com/KhronosGroup/Vulkan-Docs/main/xml/' 57 | NAME = 'vk' 58 | 59 | def _magic_require(self, api, profile): 60 | # magic_categories = ( 61 | # 'define', 'basetype', 'handle' 62 | # ) 63 | # 64 | # requirements = [name for name, types in self.types.items() 65 | # if any(t.api in (None, api) and t.category in magic_categories for t in types)] 66 | # 67 | # return Require(api, profile, requirements) 68 | return None 69 | 70 | def _magic_are_enums_blacklisted(self, enums_element): 71 | # blacklist everything that has a type 72 | return enums_element.get('type') in ('enum', 'bitmask') 73 | -------------------------------------------------------------------------------- /long_description.md: -------------------------------------------------------------------------------- 1 | Glad 2 | ---- 3 | 4 | Glad uses the official Khronos-XML specs to generate a 5 | GL/GLES/EGL/GLX/VK/WGL Loader made for your needs. 6 | 7 | Checkout the GitHub repository: https://github.com/Dav1dde/glad 8 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=61.0"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "glad2" 7 | dynamic = ["version"] 8 | description = "Multi-Language GL/GLES/EGL/GLX/VK/WGL Loader-Generator based on the official specifications." 9 | readme = "long_description.md" 10 | license = { file = "LICENSE" } 11 | authors = [{ name = "David Herberth", email = "github@dav1d.de" }] 12 | maintainers = [{ name = "David Herberth", email = "github@dav1d.de" }] 13 | dependencies = ["Jinja2>=2.7,<4.0"] 14 | classifiers = [ 15 | 'Development Status :: 5 - Production/Stable', 16 | 'Environment :: Console', 17 | 'Intended Audience :: Developers', 18 | 'Intended Audience :: Education', 19 | 'Intended Audience :: Science/Research', 20 | 'License :: OSI Approved :: MIT License', 21 | 'Natural Language :: English', 22 | 'Operating System :: OS Independent', 23 | 'Programming Language :: Python :: 3', 24 | 'Programming Language :: Python :: 3.8', 25 | 'Programming Language :: Python :: 3.9', 26 | 'Programming Language :: Python :: 3.10', 27 | 'Programming Language :: Python :: 3.11', 28 | 'Programming Language :: Python :: 3.12', 29 | 'Topic :: Games/Entertainment', 30 | 'Topic :: Multimedia :: Graphics', 31 | 'Topic :: Multimedia :: Graphics :: 3D Rendering', 32 | 'Topic :: Software Development', 33 | 'Topic :: Software Development :: Build Tools', 34 | 'Topic :: Utilities' 35 | ] 36 | keywords = ["opengl", "glad", "generator", "gl", "wgl", "egl", "gles", "vulkan", "vk", "glx"] 37 | 38 | [project.urls] 39 | Source = "https://github.com/Dav1dde/glad" 40 | 41 | [project.scripts] 42 | glad = "glad.__main__:main" 43 | 44 | [project.entry-points."glad.generator"] 45 | c = "glad.generator.c.__init__:CGenerator" 46 | rust = "glad.generator.rust.__init__:RustGenerator" 47 | 48 | [project.entry-points."glad.specification"] 49 | egl = "glad.specification:EGL" 50 | gl = "glad.specification:GL" 51 | glx = "glad.specification:GLX" 52 | wgl = "glad.specification:WGL" 53 | vk = "glad.specification:VK" 54 | 55 | [project.optional-dependencies] 56 | fortran = ["glad2-fortran"] 57 | 58 | [tool.setuptools] 59 | platforms = ["any"] 60 | 61 | [tool.setuptools.dynamic] 62 | version = { attr = "glad.__version__" } 63 | 64 | [tool.setuptools.packages] 65 | find = {} 66 | 67 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Jinja2>=2.7,<4.0 2 | -------------------------------------------------------------------------------- /test/README.md: -------------------------------------------------------------------------------- 1 | Test 2 | ==== 3 | 4 | This directory contains integration tests ran by the [`/utility/test.sh`](../utility/test.sh) script. 5 | These tests are mainly for testing the generators. 6 | 7 | 8 | ## Execution 9 | 10 | There are a few requirements for actually running the test suite: 11 | 12 | * Linux 13 | * Python environment 14 | * GCC 15 | * glfw 16 | * mingw 17 | * wine 18 | 19 | Depending on future generators being added there may be more. 20 | -------------------------------------------------------------------------------- /test/c/cmake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8) 2 | 3 | project(glad_all_versions C) 4 | enable_testing() 5 | 6 | set(GLAD_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake") 7 | add_subdirectory("${GLAD_CMAKE_PATH}" "glad_cmake") 8 | 9 | set(egl_VERSIONS 1.0 1.1 1.2 1.3 1.4 1.5) 10 | set(gl_VERSIONS 1.0 1.1 1.2 1.3 1.4 1.5 2.0 2.1 3.0 3.1 3.2 3.3 4.0 4.1 4.2 4.3 4.4 4.5 4.6) 11 | set(gles1_VERSIONS 1.0) 12 | set(gles2_VERSIONS 2.0 3.0 3.1 3.2) 13 | set(glsc2_VERSIONS 2.0) 14 | set(glx_VERSIONS 1.0 1.1 1.2 1.3 1.4) 15 | set(vulkan_VERSIONS 1.0 1.1) 16 | set(wgl_VERSIONS 1.0) 17 | 18 | set(gl_PROFILES core compatibility) 19 | 20 | set(egl_SYSTEMS Linux Windows Darwin) 21 | set(gl_SYSTEMS Linux Windows Darwin) 22 | set(gles1_SYSTEMS Linux Windows Darwin) 23 | set(gles2_SYSTEMS Linux Windows Darwin) 24 | set(glsc2_SYSTEMS Linux Windows Darwin) 25 | set(glx_SYSTEMS Linux) 26 | set(vulkan_SYSTEMS Linux Windows Darwin) 27 | set(wgl_SYSTEMS Windows) 28 | 29 | set(APIS egl gl gles1 gles2 glsc2 glx vulkan wgl) 30 | 31 | macro(merge_version RESULT VERSION) 32 | string(REPLACE "." "" "${RESULT}" "${VERSION}") 33 | endmacro() 34 | 35 | foreach(API ${APIS}) 36 | set(PROFILES "${${API}_PROFILES}") 37 | if(NOT PROFILES) 38 | set(PROFILES "X") 39 | endif() 40 | foreach(PROFILE ${PROFILES}) 41 | if(PROFILE STREQUAL "X") 42 | set(PROFILE "") 43 | endif() 44 | foreach(VERSION ${${API}_VERSIONS}) 45 | set(APISTR "${API}") 46 | string(REPLACE "." "" NAME_SUFFIX "${VERSION}") 47 | if(PROFILE) 48 | string(APPEND APISTR ":${PROFILE}") 49 | string(APPEND NAME_SUFFIX "_${PROFILE}") 50 | endif() 51 | set(TARGET "glad_${API}_${NAME_SUFFIX}") 52 | glad_add_library("${TARGET}" EXCLUDE_FROM_ALL 53 | LOCATION "${PROJECT_BINARY_DIR}/external/glad_${API}_${NAME_SUFFIX}" 54 | API ${APISTR}=${VERSION} 55 | ) 56 | if(CMAKE_SYSTEM_NAME IN_LIST "${API}_SYSTEMS") 57 | add_test( 58 | NAME "${TARGET}" 59 | COMMAND "${CMAKE_MAKE_PROGRAM}" "${TARGET}" VERBOSE=ON 60 | WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" 61 | ) 62 | endif() 63 | endforeach() 64 | endforeach() 65 | endforeach() 66 | 67 | foreach(glx_VERSION ${glx_VERSIONS}) 68 | string(REPLACE "." "" NAME_SUFFIX "${glx_VERSION}") 69 | target_link_libraries(glad_glx_${NAME_SUFFIX} 70 | PUBLIC 71 | glad_gl_10_core 72 | ) 73 | endforeach() 74 | 75 | foreach(wgl_VERSION ${wgl_VERSIONS}) 76 | string(REPLACE "." "" NAME_SUFFIX "${wgl_VERSION}") 77 | target_link_libraries(glad_wgl_${NAME_SUFFIX} 78 | PUBLIC 79 | glad_gl_10_core 80 | ) 81 | endforeach() 82 | 83 | -------------------------------------------------------------------------------- /test/c/cmake/test_disabled.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # GLAD: true 4 | # COMPILE: echo "$(pwd) - $tmp | $test_dir" && cd $tmp && cmake $test_dir 5 | # RUN: ctest --no-compress-output -T Test --verbose 6 | -------------------------------------------------------------------------------- /test/c/compile/egl/alias/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Issue #362, aliasing func is not called. 3 | * Note this does not actually verify the functions get properly initialized only that it compiles 4 | * 5 | * GLAD: $GLAD --out-path=$tmp --api="egl=" c --alias 6 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/egl.c -ldl 7 | * RUN: $tmp/test 8 | */ 9 | 10 | #include 11 | 12 | int main(void) { 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /test/c/compile/egl/default/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full EGL 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="egl=" c --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/egl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int main(void) { 13 | EGLDisplay display = NULL; 14 | (void) gladLoaderLoadEGL(display); 15 | (void) gladLoaderUnloadEGL(); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/c/compile/egl/default/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * EGL 1.0 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="egl=1.0" c --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/egl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int main(void) { 13 | EGLDisplay display = NULL; 14 | (void) gladLoaderLoadEGL(display); 15 | (void) gladLoaderUnloadEGL(); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/c/compile/egl/header-only/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full header only only EGL 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="egl=" c --loader --header-only 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #define GLAD_EGL_IMPLEMENTATION 10 | #include 11 | 12 | int main(void) { 13 | EGLDisplay display = NULL; 14 | (void) gladLoaderLoadEGL(display); 15 | (void) gladLoaderUnloadEGL(); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/c/compile/egl/on-demand/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full on demand EGL 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="egl" c --on-demand 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/egl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/compile/egl/on-demand/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full on demand EGL with loader 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="egl" c --on-demand --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/egl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/compile/gl/alias/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full compatibility GL, with aliasing 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility" c --loader --alias 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | #ifndef GL_KHR_debug 12 | #error 13 | #endif 14 | 15 | int main(void) { 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/c/compile/gl/alias/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full core GL, with aliasing 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" c --loader --alias 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | #ifndef GL_KHR_debug 12 | #error 13 | #endif 14 | 15 | int main(void) { 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/c/compile/gl/alias/003/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * No extensions compatibility GL, with aliasing 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility" --extensions="" c --loader --alias 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | #ifndef GL_KHR_debug /* extension should be added by aliasing */ 12 | #error 13 | #endif 14 | 15 | int main(void) { 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/c/compile/gl/alias/004/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * No extensions core GL, with aliasing 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" --extensions="" c --loader --alias 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | #ifndef GL_KHR_debug /* extension should be added by aliasing */ 12 | #error 13 | #endif 14 | 15 | int main(void) { 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/c/compile/gl/alias/005/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GL 2.1 All extensions, with aliasing 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility=2.1" c --loader --alias 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | #ifndef GL_KHR_debug 12 | #error 13 | #endif 14 | 15 | int main(void) { 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/c/compile/gl/alias/006/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GL 2.1 No extensions, with aliasing 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility=2.1" --extensions="" c --loader --alias 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | #ifndef GL_KHR_debug /* extension should be added by aliasing */ 12 | #error 13 | #endif 14 | 15 | int main(void) { 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/c/compile/gl/alias/007/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GL 4.6 No extensions, with aliasing 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core=4.6" --extensions="" c --alias 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | (void) glActiveTextureARB; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /test/c/compile/gl/debug/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full compatibility debug GL 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility" c --loader --debug 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int main(void) { 13 | gladSetGLPreCallback(NULL); 14 | gladSetGLPostCallback(NULL); 15 | gladInstallGLDebug(); 16 | gladUninstallGLDebug(); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /test/c/compile/gl/debug/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full core debug GL 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" c --loader --debug 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/compile/gl/debug/003/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * No extensions compatibility debug GL 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility" --extensions="" c --loader --debug 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/compile/gl/debug/004/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * No extensions core debug GL 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" --extensions="" c --loader --debug 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/compile/gl/debug/005/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Debug GL 2.1 All extensions 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility=2.1" c --loader --debug 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/compile/gl/debug/006/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Debug GL 2.1 No extensions 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility=2.1" --extensions="" c --loader --debug 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/compile/gl/default/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full compatibility GL 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility" c --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | #ifndef GL_KHR_debug 12 | #error 13 | #endif 14 | 15 | int main(void) { 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/c/compile/gl/default/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full core GL 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" c --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | #ifndef GL_KHR_debug 12 | #error 13 | #endif 14 | 15 | int main(void) { 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/c/compile/gl/default/003/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * No extensions compatibility GL 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility" --extensions="" c --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | #ifdef GL_KHR_debug 12 | #error 13 | #endif 14 | 15 | int main(void) { 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/c/compile/gl/default/004/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * No extensions core GL 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" --extensions="" c --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | #ifdef GL_KHR_debug 12 | #error 13 | #endif 14 | 15 | int main(void) { 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/c/compile/gl/default/005/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GL 2.1 All extensions 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility=2.1" c --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | #ifndef GL_KHR_debug 12 | #error 13 | #endif 14 | 15 | int main(void) { 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/c/compile/gl/default/006/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GL 2.1 No extensions 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility=2.1" --extensions="" c --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | #ifdef GL_KHR_debug 12 | #error 13 | #endif 14 | 15 | int main(void) { 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/c/compile/gl/default/007/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Issue #171. Enums being aliased, but the enum that they are aliased to 3 | * do not exist (e.g. because they don't exist in this profile). 4 | * 5 | * GLAD: $GLAD --out-path=$tmp --api="gl:core=4.5" --extensions="" c --loader 6 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 7 | * RUN: $tmp/test 8 | */ 9 | 10 | #include 11 | 12 | #if GL_CLIP_DISTANCE0 != 0x3000 13 | #error 14 | #endif 15 | 16 | #if GL_MAX_CLIP_DISTANCES != 0x0D32 17 | #error 18 | #endif 19 | 20 | int main(void) { 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /test/c/compile/gl/header-only+mx/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full compatibility GL MX header only 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility" c --loader --mx --header-only 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #define GLAD_GL_IMPLEMENTATION 10 | #include 11 | 12 | int main(void) { 13 | GladGLContext gl = {0}; 14 | (void) gladLoaderLoadGLContext(&gl); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/c/compile/gl/header-only+mx/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full core GL MX header only 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" c --loader --mx --header-only 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #define GLAD_GL_IMPLEMENTATION 10 | #include 11 | 12 | int main(void) { 13 | GladGLContext gl = {0}; 14 | (void) gladLoaderLoadGLContext(&gl); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/c/compile/gl/header-only+mx/003/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * No extensions compatibility GL MX header only 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility" --extensions="" c --loader --mx --header-only 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #define GLAD_GL_IMPLEMENTATION 10 | #include 11 | 12 | int main(void) { 13 | GladGLContext gl = {0}; 14 | (void) gladLoaderLoadGLContext(&gl); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/c/compile/gl/header-only+mx/004/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * No extensions core GL MX header only 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" --extensions="" c --loader --mx --header-only 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #define GLAD_GL_IMPLEMENTATION 10 | #include 11 | 12 | int main(void) { 13 | GladGLContext gl = {0}; 14 | (void) gladLoaderLoadGLContext(&gl); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/c/compile/gl/header-only+mx/005/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MX header only GL 2.1 All extensions 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility=2.1" c --loader --mx --header-only 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #define GLAD_GL_IMPLEMENTATION 10 | #include 11 | 12 | int main(void) { 13 | GladGLContext gl = {0}; 14 | (void) gladLoaderLoadGLContext(&gl); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/c/compile/gl/header-only+mx/006/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MX header only GL 2.1 No extensions 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility=2.1" --extensions="" c --loader --mx --header-only 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #define GLAD_GL_IMPLEMENTATION 10 | #include 11 | 12 | int main(void) { 13 | GladGLContext gl = {0}; 14 | (void) gladLoaderLoadGLContext(&gl); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/c/compile/gl/header-only+mx/007/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MX header only, global generation, should compile basic API 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility" c --loader --mx --header-only 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #define GLAD_GL_IMPLEMENTATION 10 | #include 11 | 12 | typedef void (*VOID_FUNCPTR)(void); 13 | 14 | VOID_FUNCPTR loader_userptr(void *userptr, const char *name) { 15 | (void) name; 16 | (void) userptr; 17 | return NULL; 18 | } 19 | 20 | VOID_FUNCPTR loader(const char *name) { 21 | (void) name; 22 | return NULL; 23 | } 24 | 25 | int main(void) { 26 | GladGLContext gl = {0}; 27 | 28 | gladLoadGLContextUserPtr(&gl, loader_userptr, NULL); 29 | gladLoaderLoadGLContext(&gl); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /test/c/compile/gl/header-only/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full compatibility GL header only 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility" c --loader --header-only 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #define GLAD_GL_IMPLEMENTATION 10 | #include 11 | 12 | int main(void) { 13 | (void) gladLoaderLoadGL(); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /test/c/compile/gl/header-only/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full core GL header only 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" c --loader --header-only 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #define GLAD_GL_IMPLEMENTATION 10 | #include 11 | 12 | int main(void) { 13 | (void) gladLoaderLoadGL(); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /test/c/compile/gl/header-only/003/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * No extensions compatibility GL header only 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility" --extensions="" c --loader --header-only 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #define GLAD_GL_IMPLEMENTATION 10 | #include 11 | 12 | int main(void) { 13 | (void) gladLoaderLoadGL(); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /test/c/compile/gl/header-only/004/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * No extensions core GL header only 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" --extensions="" c --loader --header-only 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #define GLAD_GL_IMPLEMENTATION 10 | #include 11 | 12 | int main(void) { 13 | (void) gladLoaderLoadGL(); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /test/c/compile/gl/header-only/005/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Header only GL 2.1 All extensions 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility=2.1" c --loader --header-only 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #define GLAD_GL_IMPLEMENTATION 10 | #include 11 | 12 | int main(void) { 13 | (void) gladLoaderLoadGL(); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /test/c/compile/gl/header-only/006/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Header only GL 2.1 No extensions 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility=2.1" --extensions="" c --loader --header-only 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #define GLAD_GL_IMPLEMENTATION 10 | #include 11 | 12 | int main(void) { 13 | (void) gladLoaderLoadGL(); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /test/c/compile/gl/mx+mx-global/001/test_disabled.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full compatibility GL MX 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility" c --loader --mx --mx-global 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | GladGLContext gl = {0}; 13 | (void) gladLoaderLoadGL(); 14 | (void) gladLoaderLoadGLContext(&gl); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/c/compile/gl/mx+mx-global/002/test_disabled.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full core GL MX 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" c --loader --mx --mx-global 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | GladGLContext gl = {0}; 13 | (void) gladLoaderLoadGL(); 14 | (void) gladLoaderLoadGLContext(&gl); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/c/compile/gl/mx+mx-global/003/test_disabled.c: -------------------------------------------------------------------------------- 1 | /* 2 | * No extensions compatibility GL MX 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility" --extensions="" c --loader --mx --mx-global 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | GladGLContext gl = {0}; 13 | (void) gladLoaderLoadGL(); 14 | (void) gladLoaderLoadGLContext(&gl); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/c/compile/gl/mx+mx-global/004/test_disabled.c: -------------------------------------------------------------------------------- 1 | /* 2 | * No extensions core GL MX 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" --extensions="" c --loader --mx --mx-global 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | GladGLContext gl = {0}; 13 | (void) gladLoaderLoadGL(); 14 | (void) gladLoaderLoadGLContext(&gl); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/c/compile/gl/mx+mx-global/005/test_disabled.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MX GL 2.1 All extensions 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility=2.1" c --loader --mx --mx-global 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | GladGLContext gl = {0}; 13 | (void) gladLoaderLoadGL(); 14 | (void) gladLoaderLoadGLContext(&gl); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/c/compile/gl/mx+mx-global/006/test_disabled.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MX GL 2.1 No extensions 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility=2.1" --extensions="" c --loader --mx --mx-global 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | GladGLContext gl = {0}; 13 | (void) gladLoaderLoadGL(); 14 | (void) gladLoaderLoadGLContext(&gl); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/c/compile/gl/mx+mx-global/007/test_disabled.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MX global generation, should compile basic API 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility" c --loader --mx --mx-global 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | typedef void (*VOID_FUNCPTR)(void); 13 | 14 | VOID_FUNCPTR loader_userptr(void *userptr, const char *name) { 15 | (void) name; 16 | (void) userptr; 17 | return NULL; 18 | } 19 | 20 | VOID_FUNCPTR loader(const char *name) { 21 | (void) name; 22 | return NULL; 23 | } 24 | 25 | int main(void) { 26 | GladGLContext gl = {0}; 27 | 28 | gladLoadGLContextUserPtr(&gl, loader_userptr, NULL); 29 | gladLoadGLContext(&gl, loader); 30 | gladLoaderLoadGLContext(&gl); 31 | 32 | gladLoadGLUserPtr(loader_userptr, NULL); 33 | gladLoadGL(loader); 34 | gladLoaderLoadGL(); 35 | 36 | gladSetGLContext(&gl); 37 | (void) gladGetGLContext(); 38 | return 0; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /test/c/compile/gl/mx+mx-global/008/test_disabled.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full compatibility GL MX should not contain any symbols in COMMON section, 3 | * to prevent linking issues with OSX. 4 | * 5 | * Only tested here under the assumption that this build contains the most symbols. 6 | * 7 | * See: https://github.com/Dav1dde/glad/issues/158 8 | * 9 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility" c --loader --mx --mx-global 10 | * COMPILE: $GCC -c -o $tmp/test.o -I$tmp/include $tmp/src/gl.c -ldl 11 | * RUN: [ "$(nm $tmp/test.o | grep ' C ' | wc -l)" -eq "0" ] 12 | */ 13 | 14 | #error "this testfile should not be compiled" 15 | -------------------------------------------------------------------------------- /test/c/compile/gl/on-demand/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full on demand GL 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" c --on-demand 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/compile/gl/on-demand/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full on demand GL with loader 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" c --on-demand --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /test/c/compile/gles1/default/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full GLES1 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gles1" c 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gles1.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/compile/gles1/default/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full GLES1 with loader 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="egl,gles1" c --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/egl.c $tmp/src/gles1.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/compile/gles1/on-demand/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full on demand GLES1 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gles1" c --on-demand 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gles1.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/compile/gles1/on-demand/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full on demand GLES1 with loader 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gles1,egl" c --on-demand --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gles1.c $tmp/src/egl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/compile/gles2/alias/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GLES2 No extensions, with aliasing 3 | * 4 | * Issue: https://github.com/Dav1dde/glad/issues/334 5 | * 6 | * GLAD: $GLAD --out-path=$tmp --api="gles2=3.2" --extensions="" c --alias 7 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gles2.c -ldl 8 | * RUN: $tmp/test 9 | */ 10 | 11 | #include 12 | 13 | int main(void) { 14 | (void) glGenVertexArraysOES; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/c/compile/gles2/default/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full GLES2 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gles2" c 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gles2.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/compile/gles2/default/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full GLES2 with loader 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="egl,gles2" c --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/egl.c $tmp/src/gles2.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/compile/gles2/default/003/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Emscripten GLES2 + EGL header only. 3 | * Related Issues: #387 4 | * 5 | * GLAD: $GLAD --out-path=$tmp --api="egl,gles2" c --loader --header-only 6 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl 7 | * RUN: $tmp/test 8 | */ 9 | 10 | #include 11 | 12 | #define GLAD_GLES2_IMPLEMENTATION 13 | #define GLAD_PLATFORM_EMSCRIPTEN 1 14 | #include /* egl before gles2 */ 15 | #include 16 | 17 | __eglMustCastToProperFunctionPointerType emscripten_GetProcAddress(const char *name) { 18 | GLAD_UNUSED(name); 19 | return GLAD_GNUC_EXTENSION (__eglMustCastToProperFunctionPointerType) NULL; 20 | } 21 | 22 | int main(void) { 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /test/c/compile/gles2/default/004/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Emscripten GLES2 + header only. See also 003. 3 | * Related Issues: #387 4 | * 5 | * GLAD: $GLAD --out-path=$tmp --api="egl,gles2" c --loader --header-only 6 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl -Wno-pedantic 7 | * RUN: $tmp/test 8 | */ 9 | 10 | #include 11 | 12 | #define GLAD_GLES2_IMPLEMENTATION 13 | #define GLAD_PLATFORM_EMSCRIPTEN 1 14 | #include 15 | /* 16 | * egl after gles2 17 | * this is not correct, that's why we disable pedantic but it should still compile without 18 | */ 19 | #include 20 | 21 | __eglMustCastToProperFunctionPointerType emscripten_GetProcAddress(const char *name) { 22 | GLAD_UNUSED(name); 23 | return GLAD_GNUC_EXTENSION (__eglMustCastToProperFunctionPointerType) NULL; 24 | } 25 | 26 | int main(void) { 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /test/c/compile/gles2/default/005/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Emscripten GLES2 + header only. See also 003. 3 | * Related Issues: #387 4 | * 5 | * GLAD: $GLAD --out-path=$tmp --api="gles2" c --loader --header-only 6 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl 7 | * RUN: $tmp/test 8 | */ 9 | 10 | #include 11 | 12 | #define GLAD_GLES2_IMPLEMENTATION 13 | #define GLAD_PLATFORM_EMSCRIPTEN 1 14 | #include 15 | 16 | __eglMustCastToProperFunctionPointerType emscripten_GetProcAddress(const char *name) { 17 | GLAD_UNUSED(name); 18 | return GLAD_GNUC_EXTENSION (__eglMustCastToProperFunctionPointerType) NULL; 19 | } 20 | 21 | int main(void) { 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /test/c/compile/gles2/on-demand/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full on demand GLES2 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gles2" c --on-demand 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gles2.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/compile/gles2/on-demand/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full on demand GLES2 with loader 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gles2,egl" c --on-demand --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gles2.c $tmp/src/egl.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/compile/glx/alias/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Issue #362, aliasing func is not called. 3 | * Note this does not actually verify the functions get properly initialized only that it compiles 4 | * 5 | * GLAD: $GLAD --out-path=$tmp --api="glx,gl:core" c --alias 6 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/glx.c -ldl -lX11 7 | * RUN: $tmp/test 8 | */ 9 | 10 | #include 11 | 12 | int main(void) { 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /test/c/compile/glx/default/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full GLX 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="glx,gl:core" c --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/glx.c -ldl -lX11 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | Display *display = NULL; 13 | (void) gladLoaderLoadGLX(display, 0); 14 | (void) gladLoaderUnloadGLX(); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/c/compile/glx/default/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full GLX, without X11 as dependency 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="glx,gl:core" c --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/glx.c -ldl -DGLAD_GLX_NO_X11 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | Display *display = NULL; 13 | (void) gladLoaderLoadGLX(display, 0); 14 | (void) gladLoaderUnloadGLX(); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/c/compile/glx/default/003/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GLX 1.0 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="glx=1.0,gl:core" c --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/glx.c -ldl -DGLAD_GLX_NO_X11 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | Display *display = NULL; 13 | (void) gladLoaderLoadGLX(display, 0); 14 | (void) gladLoaderUnloadGLX(); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/c/compile/glx/header-only/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full header only only GLX 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="glx,gl:core" c --loader --header-only 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl -lX11 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #define GLAD_GLX_IMPLEMENTATION 10 | #include 11 | 12 | int main(void) { 13 | Display *display = NULL; 14 | (void) gladLoaderLoadGLX(display, 0); 15 | (void) gladLoaderUnloadGLX(); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/c/compile/glx/header-only/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full header only only GLX, without X11 as dependency 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="glx,gl:core" c --loader --header-only 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl -DGLAD_GLX_NO_X11 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #define GLAD_GLX_IMPLEMENTATION 10 | #include 11 | 12 | int main(void) { 13 | Display *display = NULL; 14 | (void) gladLoaderLoadGLX(display, 0); 15 | (void) gladLoaderUnloadGLX(); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/c/compile/glx/on-demand/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full on demand GLX 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="glx,gl:core" c --on-demand 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/glx.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/compile/glx/on-demand/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full on demand GLX with loader 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="glx,gl:core" c --on-demand --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/glx.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/compile/vulkan/alias/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full Vulkan with aliasing 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="vulkan" c --loader --alias 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/vulkan.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | #if !defined(VK_EXT_debug_report) || !defined(VK_VERSION_1_0) 12 | #error 13 | #endif 14 | 15 | int main(void) { 16 | (void) gladLoaderLoadVulkan(NULL, NULL, NULL); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /test/c/compile/vulkan/alias/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full Vulkan with aliasing and without extensions 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="vulkan" --extensions="" c --loader --alias 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/vulkan.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | #if defined(VK_EXT_debug_report) || !defined(VK_VERSION_1_0) 12 | #error 13 | #endif 14 | 15 | int main(void) { 16 | (void) gladLoaderLoadVulkan(NULL, NULL, NULL); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /test/c/compile/vulkan/debug/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Issue #335. Debug functions are not guarded/protected by platform. 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="vulkan=1.1" --extensions=VK_KHR_external_memory_win32 c --debug 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/vulkan.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/compile/vulkan/default/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full Vulkan 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="vulkan" c --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/vulkan.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | (void) gladLoaderLoadVulkan(NULL, NULL, NULL); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /test/c/compile/vulkan/default/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full Vulkan without extensions 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="vulkan" --extensions="" c --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/vulkan.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | (void) gladLoaderLoadVulkan(NULL, NULL, NULL); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /test/c/compile/vulkan/default/003/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Vulkan 1.0 without extensions 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="vulkan=1.0" --extensions="" c --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/vulkan.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | (void) gladLoaderLoadVulkan(NULL, NULL, NULL); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /test/c/compile/vulkan/default/004/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Vulkan 1.0 with extensions 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="vulkan=1.0" c --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/vulkan.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int main(void) { 13 | (void) gladLoaderLoadVulkan(NULL, NULL, NULL); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /test/c/compile/vulkan/default/005/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Issue #171. Enums being aliased, but the enum that they are aliased to 3 | * do not exist (e.g. because they don't exist in this profile). 4 | * This is to make sure Vulkan handles the enums correctly as well (since 5 | * the vulkan specification only specifies the alias and no value). 6 | * 7 | * See also c/compile/gl/default/007 8 | * 9 | * GLAD: $GLAD --out-path=$tmp --api="vulkan=1.1" --extensions="VK_KHR_external_memory_capabilities" c 10 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/vulkan.c -ldl 11 | * RUN: $tmp/test 12 | */ 13 | 14 | #include 15 | 16 | #if VK_LUID_SIZE_KHR != 8 17 | #error 18 | #endif 19 | 20 | int main(void) { 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /test/c/compile/vulkan/default/006/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Issue #350, missing ENUM_MAX values 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="vulkan=1.1" c 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/vulkan.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | VkDeviceGroupPresentModeFlagBitsKHR a = VK_DEVICE_GROUP_PRESENT_MODE_FLAG_BITS_MAX_ENUM_KHR; 13 | VkSubgroupFeatureFlagBits b = VK_SUBGROUP_FEATURE_FLAG_BITS_MAX_ENUM; 14 | (void) a; 15 | (void) b; 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/c/compile/vulkan/header-only+mx/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full vulkan, header only, mx 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="vulkan" c --loader --header-only --mx 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #define GLAD_VULKAN_IMPLEMENTATION 10 | #include 11 | 12 | typedef void (*VOID_FUNCPTR)(void); 13 | VOID_FUNCPTR loader_userptr(void *userptr, const char *name) { (void) name; (void) userptr; return NULL; } 14 | VOID_FUNCPTR loader(const char *name) { (void) name; return NULL; } 15 | 16 | int main(void) { 17 | GladVulkanContext context = {0}; 18 | (void) gladLoadVulkanContextUserPtr(&context, NULL, loader_userptr, NULL); 19 | (void) gladLoadVulkanContext(&context, NULL, loader); 20 | (void) gladLoaderLoadVulkanContext(&context, NULL, NULL, NULL); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /test/c/compile/vulkan/header-only+mx/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full vulkan without extensions, header only, mx 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="vulkan" --extensions="" c --loader --header-only --mx 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #define GLAD_VULKAN_IMPLEMENTATION 10 | #include 11 | 12 | typedef void (*VOID_FUNCPTR)(void); 13 | VOID_FUNCPTR loader_userptr(void *userptr, const char *name) { (void) name; (void) userptr; return NULL; } 14 | VOID_FUNCPTR loader(const char *name) { (void) name; return NULL; } 15 | 16 | int main(void) { 17 | GladVulkanContext context = {0}; 18 | (void) gladLoadVulkanContextUserPtr(&context, NULL, loader_userptr, NULL); 19 | (void) gladLoadVulkanContext(&context, NULL, loader); 20 | (void) gladLoaderLoadVulkanContext(&context, NULL, NULL, NULL); 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /test/c/compile/vulkan/header-only/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full Vulkan header only 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="vulkan" c --loader --header-only 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #define GLAD_VULKAN_IMPLEMENTATION 10 | #include 11 | 12 | #if !defined(VK_EXT_debug_report) || !defined(VK_VERSION_1_0) 13 | #error 14 | #endif 15 | 16 | int main(void) { 17 | (void) gladLoaderLoadVulkan(NULL, NULL, NULL); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /test/c/compile/vulkan/header-only/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full Vulkan without extensions, header only 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="vulkan" --extensions="" c --loader --header-only 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #define GLAD_VULKAN_IMPLEMENTATION 10 | #include 11 | 12 | #if defined(VK_EXT_debug_report) || !defined(VK_VERSION_1_0) 13 | #error 14 | #endif 15 | 16 | int main(void) { 17 | (void) gladLoaderLoadVulkan(NULL, NULL, NULL); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /test/c/compile/vulkan/mx+mx-global/001/test_disabled.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full vulkan, mx 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="vulkan" c --loader --mx --mx-global 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/vulkan.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | typedef void (*VOID_FUNCPTR)(void); 12 | VOID_FUNCPTR loader_userptr(void *userptr, const char *name) { (void) name; (void) userptr; return NULL; } 13 | VOID_FUNCPTR loader(const char *name) { (void) name; return NULL; } 14 | 15 | int main(void) { 16 | GladVulkanContext context = {0}; 17 | (void) gladLoadVulkanUserPtr(NULL, loader_userptr, NULL); 18 | (void) gladLoadVulkanContextUserPtr(&context, NULL, loader_userptr, NULL); 19 | (void) gladLoadVulkan(NULL, loader); 20 | (void) gladLoadVulkanContext(&context, NULL, loader); 21 | (void) gladLoaderLoadVulkan(NULL, NULL, NULL); 22 | (void) gladLoaderLoadVulkanContext(&context, NULL, NULL, NULL); 23 | return 0; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /test/c/compile/vulkan/mx+mx-global/002/test_disabled.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full vulkan without extensions, mx 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="vulkan" --extensions="" c --loader --mx --mx-global 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/vulkan.c -ldl -g 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | typedef void (*VOID_FUNCPTR)(void); 12 | VOID_FUNCPTR loader_userptr(void *userptr, const char *name) { (void) name; (void) userptr; return NULL; } 13 | VOID_FUNCPTR loader(const char *name) { (void) name; return NULL; } 14 | 15 | int main(void) { 16 | GladVulkanContext context = {0}; 17 | (void) gladLoadVulkanUserPtr(NULL, loader_userptr, NULL); 18 | (void) gladLoadVulkanContextUserPtr(&context, NULL, loader_userptr, NULL); 19 | (void) gladLoadVulkan(NULL, loader); 20 | (void) gladLoadVulkanContext(&context, NULL, loader); 21 | (void) gladLoaderLoadVulkan(NULL, NULL, NULL); 22 | (void) gladLoaderLoadVulkanContext(&context, NULL, NULL, NULL); 23 | return 0; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /test/c/compile/vulkan/on-demand/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full on demand Vulkan 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="vulkan" c --on-demand 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/vulkan.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/compile/vulkan/on-demand/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Full on demand Vulkan with loader 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="vulkan" c --on-demand --loader 5 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/vulkan.c -ldl 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/c/parse/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GL_VERTEX_ARRAY was removed in gl:core=3.2 and later reintroduced in gl=4.3. 3 | * Test checks if the symbol exists in the generated code. 4 | * Related Issues: #137, #139 5 | * 6 | * GLAD: $GLAD --out-path=$tmp --api="gl:core=4.3" --extensions="" c 7 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 8 | * RUN: $tmp/test 9 | */ 10 | 11 | #include 12 | 13 | int main(void) { 14 | if (GL_VERTEX_ARRAY == 0x8074) { 15 | return 0; 16 | } 17 | 18 | return 1; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /test/c/parse/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VK_NV_ray_tracing depends on a type which depends on an aliased type. 3 | * The aliased type is not part of the feature set. 4 | * Make sure the aliased type is part generated, since the alias is done through a typedef. 5 | * 6 | * GLAD: $GLAD --out-path=$tmp --api="vulkan=1.1" --extensions="VK_NV_ray_tracing" c 7 | * COMPILE: $GCC $test -o $tmp/test -I$tmp/include $tmp/src/vulkan.c -ldl 8 | * RUN: $tmp/test 9 | */ 10 | 11 | #include 12 | 13 | int main(void) { 14 | /* make sure something is referenced so stuff doesn't just get optimized away */ 15 | VkAccelerationStructureMemoryRequirementsInfoNV unused; 16 | (void) unused; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /test/c/parse/003/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The GL_KHR_debug has suffixed symbols for GLES but symbols without suffix for GL. 3 | * Make sure only the suffixed symbols appear in the generated output for gles. 4 | * Related Issues: #281 5 | * 6 | * See also: 004 7 | * 8 | * GLAD: $GLAD --out-path=$tmp --api="gles2=3.1" --extensions="GL_KHR_debug" c 9 | * COMPILE: ! $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gles2.c -ldl 10 | * RUN: true 11 | */ 12 | 13 | #include 14 | 15 | int main(void) { 16 | (void) glObjectLabel; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /test/c/parse/004/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The GL_KHR_debug has suffixed symbols for GLES but symbols without suffix for GL. 3 | * Make sure only the symbols without suffix appear in the generated output for gl. 4 | * Related Issues: #281 5 | * 6 | * See also: 003 7 | * 8 | * GLAD: $GLAD --out-path=$tmp --api="gl:core=3.3" --extensions="GL_KHR_debug" c 9 | * COMPILE: ! $GCC $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl 10 | * RUN: true 11 | */ 12 | 13 | #include 14 | 15 | int main(void) { 16 | (void) glObjectLabelKHR; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /test/c/run/gl/debug/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Core 3.3 debug profile using glfw to load 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" --extensions="" c --debug 5 | * COMPILE: $GCC -Wno-pedantic $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl -lglfw 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #define ASSERT(expression, message, args...) if(!(expression)) { fprintf(stderr, "%s(%d): " message "\n", __FILE__, __LINE__, ##args); exit(1); } 17 | #define WIDTH 50 18 | #define HEIGHT 50 19 | 20 | static int pre = 0; 21 | static int post = 0; 22 | 23 | static void pre_call_gl_callback(const char *name, GLADapiproc apiproc, int len_args, ...) { 24 | ASSERT(strcmp(name, "glClear") == 0, "got %s expected glClear", name); 25 | ASSERT(apiproc != NULL, "glClear proc is null"); 26 | ASSERT((void*) apiproc == (void*) glad_glClear, "passed in proc is not actual implementation"); 27 | ASSERT((void*) apiproc != (void*) glad_debug_glClear, "passed in proc is debug implementation"); 28 | ASSERT(len_args == 1, "expected only one argument, got %d", len_args); 29 | 30 | ++pre; 31 | 32 | va_list args; 33 | va_start(args, len_args); 34 | int value = va_arg(args, int); 35 | va_end(args); 36 | 37 | ASSERT(value == GL_COLOR_BUFFER_BIT || value == GL_DEPTH_BUFFER_BIT, "invalid argument in debug callback"); 38 | } 39 | 40 | static void post_call_gl_callback(void *ret, const char *name, GLADapiproc apiproc, int len_args, ...) { 41 | ASSERT(strcmp(name, "glClear") == 0, "got %s expected glClear", name); 42 | ASSERT(apiproc != NULL, "glClear proc is null"); 43 | ASSERT((void*) apiproc == (void*) glad_glClear, "passed in proc is not actual implementation"); 44 | ASSERT((void*) apiproc != (void*) glad_debug_glClear, "passed in proc is debug implementation"); 45 | ASSERT(len_args == 1, "expected only one argument, got %d", len_args); 46 | ASSERT(ret == NULL, "return value not null"); 47 | 48 | ++post; 49 | 50 | va_list args; 51 | va_start(args, len_args); 52 | int value = va_arg(args, int); 53 | va_end(args); 54 | 55 | ASSERT(value == GL_COLOR_BUFFER_BIT || value == GL_DEPTH_BUFFER_BIT, "invalid argument in debug callback"); 56 | } 57 | 58 | int main(void) { 59 | ASSERT(glfwInit(), "glfw init failed"); 60 | 61 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 62 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 63 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 64 | 65 | GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "", NULL, NULL); 66 | ASSERT(window != NULL, "glfw window creation failed"); 67 | glfwMakeContextCurrent(window); 68 | 69 | int version = gladLoadGL(glfwGetProcAddress); 70 | ASSERT(version >= 3003, "glad version %d < 3003", version); 71 | ASSERT(GLAD_VERSION_MAJOR(version) >= 3, "glad major version %d < 3", GLAD_VERSION_MAJOR(version)); 72 | ASSERT(GLAD_VERSION_MAJOR(version) > 3 || GLAD_VERSION_MINOR(version) >= 3, "glad minor version %d < 3", GLAD_VERSION_MINOR(version)); 73 | ASSERT(GLAD_GL_VERSION_3_3, "GL_VERSION_3_3 not set"); 74 | 75 | glViewport(0, 0, WIDTH, HEIGHT); 76 | glClearColor(0.2f, 0.3f, 0.3f, 1.0f); 77 | 78 | gladSetGLPreCallback(pre_call_gl_callback); 79 | gladSetGLPostCallback(post_call_gl_callback); 80 | 81 | glClear(GL_COLOR_BUFFER_BIT); 82 | 83 | /* make sure install/uninstall is working as expected */ 84 | gladUninstallGLDebug(); 85 | glViewport(0, 0, WIDTH, HEIGHT); 86 | glClear(GL_COLOR_BUFFER_BIT); 87 | gladInstallGLDebug(); 88 | 89 | glClear(GL_DEPTH_BUFFER_BIT); 90 | 91 | ASSERT(pre == 2, "pre callback called %d times, expected twice", pre); 92 | ASSERT(post == 2, "post callback called %d times, expected twice", post); 93 | 94 | glfwSwapBuffers(window); 95 | 96 | glfwTerminate(); 97 | 98 | return 0; 99 | } 100 | -------------------------------------------------------------------------------- /test/c/run/gl/default/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Core 3.3 profile using glfw to load 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" c 5 | * COMPILE: $GCC -Wno-pedantic $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl -lglfw 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define ASSERT(expression, message, args...) if(!(expression)) { fprintf(stderr, "%s(%d): " message "\n", __FILE__, __LINE__, ##args); exit(1); } 15 | #define WIDTH 50 16 | #define HEIGHT 50 17 | 18 | int main(void) { 19 | ASSERT(glfwInit(), "glfw init failed"); 20 | 21 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 22 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 23 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 24 | 25 | GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "", NULL, NULL); 26 | ASSERT(window != NULL, "glfw window creation failed"); 27 | glfwMakeContextCurrent(window); 28 | 29 | int version = gladLoadGL(glfwGetProcAddress); 30 | ASSERT(version >= 3003, "glad version %d < 3003", version); 31 | ASSERT(GLAD_VERSION_MAJOR(version) >= 3, "glad major version %d < 3", GLAD_VERSION_MAJOR(version)); 32 | ASSERT(GLAD_VERSION_MAJOR(version) > 3 || GLAD_VERSION_MINOR(version) >= 3, "glad minor version %d < 3", GLAD_VERSION_MINOR(version)); 33 | ASSERT(GLAD_GL_VERSION_3_3, "GL_VERSION_3_3 not set"); 34 | ASSERT(GLAD_GL_KHR_debug == 1, "KHR_debug not available"); 35 | 36 | glViewport(0, 0, WIDTH, HEIGHT); 37 | glClearColor(0.2f, 0.3f, 0.3f, 1.0f); 38 | glClear(GL_COLOR_BUFFER_BIT); 39 | 40 | glfwSwapBuffers(window); 41 | 42 | glfwTerminate(); 43 | 44 | return 0; 45 | } -------------------------------------------------------------------------------- /test/c/run/gl/default/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Core 3.3 profile using internal loader to load 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" c --loader 5 | * COMPILE: $GCC -Wno-pedantic $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl -lglfw 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define ASSERT(expression, message, args...) if(!(expression)) { fprintf(stderr, "%s(%d): " message "\n", __FILE__, __LINE__, ##args); exit(1); } 15 | #define WIDTH 50 16 | #define HEIGHT 50 17 | 18 | int main(void) { 19 | ASSERT(glfwInit(), "glfw init failed"); 20 | 21 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 22 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 23 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 24 | 25 | GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "", NULL, NULL); 26 | ASSERT(window != NULL, "glfw window creation failed"); 27 | glfwMakeContextCurrent(window); 28 | 29 | int version = gladLoaderLoadGL(); 30 | ASSERT(version >= 3003, "glad version %d < 3003", version); 31 | ASSERT(GLAD_VERSION_MAJOR(version) >= 3, "glad major version %d < 3", GLAD_VERSION_MAJOR(version)); 32 | ASSERT(GLAD_VERSION_MAJOR(version) > 3 || GLAD_VERSION_MINOR(version) >= 3, "glad minor version %d < 3", GLAD_VERSION_MINOR(version)); 33 | ASSERT(GLAD_GL_VERSION_3_3, "GL_VERSION_3_3 not set"); 34 | ASSERT(GLAD_GL_KHR_debug == 1, "KHR_debug not available"); 35 | 36 | glViewport(0, 0, WIDTH, HEIGHT); 37 | glClearColor(0.2f, 0.3f, 0.3f, 1.0f); 38 | glClear(GL_COLOR_BUFFER_BIT); 39 | 40 | glfwSwapBuffers(window); 41 | 42 | glfwTerminate(); 43 | 44 | return 0; 45 | } -------------------------------------------------------------------------------- /test/c/run/gl/default/003/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 2.1 using internal loader to load 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core=2.1" c --loader 5 | * COMPILE: $GCC -Wno-pedantic $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl -lglfw 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define ASSERT(expression, message, args...) if(!(expression)) { fprintf(stderr, "%s(%d): " message "\n", __FILE__, __LINE__, ##args); exit(1); } 15 | #define WIDTH 50 16 | #define HEIGHT 50 17 | 18 | int main(void) { 19 | ASSERT(glfwInit(), "glfw init failed"); 20 | 21 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); 22 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); 23 | 24 | GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "", NULL, NULL); 25 | ASSERT(window != NULL, "glfw window creation failed"); 26 | glfwMakeContextCurrent(window); 27 | 28 | int version = gladLoaderLoadGL(); 29 | ASSERT(version >= 2001, "glad version %d < 2001", version); 30 | ASSERT(GLAD_VERSION_MAJOR(version) >= 2, "glad major version %d < 2", GLAD_VERSION_MAJOR(version)); 31 | ASSERT(GLAD_VERSION_MAJOR(version) > 2 || GLAD_VERSION_MINOR(version) >= 1, "glad minor version %d < 1", GLAD_VERSION_MINOR(version)); 32 | ASSERT(GLAD_GL_VERSION_2_1, "GL_VERSION_2_1 not set"); 33 | ASSERT(GLAD_GL_KHR_debug == 1, "KHR_debug not available"); 34 | 35 | glViewport(0, 0, WIDTH, HEIGHT); 36 | glClearColor(0.2f, 0.3f, 0.3f, 1.0f); 37 | glClear(GL_COLOR_BUFFER_BIT); 38 | 39 | glfwSwapBuffers(window); 40 | 41 | glfwTerminate(); 42 | 43 | return 0; 44 | } -------------------------------------------------------------------------------- /test/c/run/gl/mx/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MX Core 3.3 profile using glfw to load 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" c --mx 5 | * COMPILE: $GCC -Wno-pedantic $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl -lglfw 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define ASSERT(expression, message, args...) if(!(expression)) { fprintf(stderr, "%s(%d): " message "\n", __FILE__, __LINE__, ##args); exit(1); } 15 | #define WIDTH 50 16 | #define HEIGHT 50 17 | 18 | GLFWwindow* create_window(void) { 19 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 20 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 21 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 22 | 23 | GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "", NULL, NULL); 24 | ASSERT(window != NULL, "glfw window creation failed"); 25 | return window; 26 | } 27 | 28 | void run(GLFWwindow *window) { 29 | GladGLContext context = {0}; 30 | 31 | glfwMakeContextCurrent(window); 32 | 33 | int version = gladLoadGLContext(&context, glfwGetProcAddress); 34 | ASSERT(version >= 3003, "glad version %d < 3003", version); 35 | ASSERT(GLAD_VERSION_MAJOR(version) >= 3, "glad major version %d < 3", GLAD_VERSION_MAJOR(version)); 36 | ASSERT(GLAD_VERSION_MAJOR(version) > 3 || GLAD_VERSION_MINOR(version) >= 3, "glad minor version %d < 3", GLAD_VERSION_MINOR(version)); 37 | ASSERT(context.VERSION_3_3, "GL_VERSION_3_3 not set"); 38 | ASSERT(context.KHR_debug, "KHR_debug not available"); 39 | 40 | context.Viewport(0, 0, WIDTH, HEIGHT); 41 | context.ClearColor(0.2f, 0.3f, 0.3f, 1.0f); 42 | context.Clear(GL_COLOR_BUFFER_BIT); 43 | 44 | glfwSwapBuffers(window); 45 | } 46 | 47 | int main(void) { 48 | ASSERT(glfwInit(), "glfw init failed"); 49 | 50 | GLFWwindow *window1 = create_window(); 51 | GLFWwindow *window2 = create_window(); 52 | 53 | run(window1); 54 | run(window2); 55 | 56 | glfwTerminate(); 57 | 58 | return 0; 59 | } -------------------------------------------------------------------------------- /test/c/run/gl/mx/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MX Core 3.3 profile using internal loader 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" c --mx --loader 5 | * COMPILE: $GCC -Wno-pedantic $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl -lglfw 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define ASSERT(expression, message, args...) if(!(expression)) { fprintf(stderr, "%s(%d): " message "\n", __FILE__, __LINE__, ##args); exit(1); } 15 | #define WIDTH 50 16 | #define HEIGHT 50 17 | 18 | GLFWwindow* create_window(void) { 19 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 20 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 21 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 22 | 23 | GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "", NULL, NULL); 24 | ASSERT(window != NULL, "glfw window creation failed"); 25 | return window; 26 | } 27 | 28 | void run(GLFWwindow *window) { 29 | GladGLContext context = {0}; 30 | 31 | glfwMakeContextCurrent(window); 32 | 33 | int version = gladLoaderLoadGLContext(&context); 34 | ASSERT(version >= 3003, "glad version %d < 3003", version); 35 | ASSERT(GLAD_VERSION_MAJOR(version) >= 3, "glad major version %d < 3", GLAD_VERSION_MAJOR(version)); 36 | ASSERT(GLAD_VERSION_MAJOR(version) > 3 || GLAD_VERSION_MINOR(version) >= 3, "glad minor version %d < 3", GLAD_VERSION_MINOR(version)); 37 | ASSERT(context.VERSION_3_3, "GL_VERSION_3_3 not set"); 38 | ASSERT(context.KHR_debug, "KHR_debug not available"); 39 | 40 | context.Viewport(0, 0, WIDTH, HEIGHT); 41 | context.ClearColor(0.2f, 0.3f, 0.3f, 1.0f); 42 | context.Clear(GL_COLOR_BUFFER_BIT); 43 | 44 | glfwSwapBuffers(window); 45 | } 46 | 47 | int main(void) { 48 | ASSERT(glfwInit(), "glfw init failed"); 49 | 50 | GLFWwindow *window1 = create_window(); 51 | GLFWwindow *window2 = create_window(); 52 | 53 | run(window1); 54 | run(window2); 55 | 56 | glfwTerminate(); 57 | 58 | return 0; 59 | } -------------------------------------------------------------------------------- /test/c/run/gl/mx/003/test_disabled.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MX Core 3.3 profile using glfw to load. 3 | * Using MX Global for GL calls. 4 | * 5 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" c --mx --mx-global 6 | * COMPILE: $GCC -Wno-pedantic $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl -lglfw 7 | * RUN: $tmp/test 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #define ASSERT(expression, message, args...) if(!(expression)) { fprintf(stderr, "%s(%d): " message "\n", __FILE__, __LINE__, ##args); exit(1); } 17 | #define WIDTH 50 18 | #define HEIGHT 50 19 | 20 | GLFWwindow* create_window(void) { 21 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 22 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 23 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 24 | 25 | GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "", NULL, NULL); 26 | ASSERT(window != NULL, "glfw window creation failed"); 27 | return window; 28 | } 29 | 30 | void run(GLFWwindow *window) { 31 | GladGLContext context = {0}; 32 | context.userptr = (void*) &context; 33 | 34 | glfwMakeContextCurrent(window); 35 | 36 | int version = gladLoadGLContext(&context, glfwGetProcAddress); 37 | ASSERT(memcmp(&context, gladGetGLContext(), sizeof(GladGLContext)) == 0, "invalid global context"); 38 | ASSERT(version >= 3003, "glad version %d < 3003", version); 39 | ASSERT(GLAD_VERSION_MAJOR(version) >= 3, "glad major version %d < 3", GLAD_VERSION_MAJOR(version)); 40 | ASSERT(GLAD_VERSION_MAJOR(version) > 3 || GLAD_VERSION_MINOR(version) >= 3, "glad minor version %d < 3", GLAD_VERSION_MINOR(version)); 41 | ASSERT(context.VERSION_3_3, "GL_VERSION_3_3 not set"); 42 | ASSERT(context.KHR_debug, "KHR_debug not available"); 43 | 44 | glViewport(0, 0, WIDTH, HEIGHT); 45 | glClearColor(0.2f, 0.3f, 0.3f, 1.0f); 46 | glClear(GL_COLOR_BUFFER_BIT); 47 | 48 | glfwSwapBuffers(window); 49 | } 50 | 51 | int main(void) { 52 | ASSERT(glfwInit(), "glfw init failed"); 53 | 54 | GLFWwindow *window1 = create_window(); 55 | GLFWwindow *window2 = create_window(); 56 | 57 | run(window1); 58 | run(window2); 59 | 60 | glfwTerminate(); 61 | 62 | return 0; 63 | } -------------------------------------------------------------------------------- /test/c/run/gl/mx/004/test_disabled.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MX Core 3.3 profile using internal loader. 3 | * Using MX Global for GL calls. 4 | * 5 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" c --mx --mx-global --loader 6 | * COMPILE: $GCC -Wno-pedantic $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl -lglfw 7 | * RUN: $tmp/test 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #define ASSERT(expression, message, args...) if(!(expression)) { fprintf(stderr, "%s(%d): " message "\n", __FILE__, __LINE__, ##args); exit(1); } 17 | #define WIDTH 50 18 | #define HEIGHT 50 19 | 20 | GLFWwindow* create_window(void) { 21 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 22 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 23 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 24 | 25 | GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "", NULL, NULL); 26 | ASSERT(window != NULL, "glfw window creation failed"); 27 | return window; 28 | } 29 | 30 | void run(GLFWwindow *window) { 31 | GladGLContext context = {0}; 32 | context.userptr = (void*) &context; 33 | 34 | glfwMakeContextCurrent(window); 35 | 36 | int version = gladLoaderLoadGLContext(&context); 37 | ASSERT(memcmp(&context, gladGetGLContext(), sizeof(GladGLContext)) == 0, "invalid global context"); 38 | ASSERT(version >= 3003, "glad version %d < 3003", version); 39 | ASSERT(GLAD_VERSION_MAJOR(version) >= 3, "glad major version %d < 3", GLAD_VERSION_MAJOR(version)); 40 | ASSERT(GLAD_VERSION_MAJOR(version) > 3 || GLAD_VERSION_MINOR(version) >= 3, "glad minor version %d < 3", GLAD_VERSION_MINOR(version)); 41 | ASSERT(context.VERSION_3_3, "GL_VERSION_3_3 not set"); 42 | ASSERT(context.KHR_debug, "KHR_debug not available"); 43 | 44 | glViewport(0, 0, WIDTH, HEIGHT); 45 | glClearColor(0.2f, 0.3f, 0.3f, 1.0f); 46 | glClear(GL_COLOR_BUFFER_BIT); 47 | 48 | glfwSwapBuffers(window); 49 | } 50 | 51 | int main(void) { 52 | ASSERT(glfwInit(), "glfw init failed"); 53 | 54 | GLFWwindow *window1 = create_window(); 55 | GLFWwindow *window2 = create_window(); 56 | 57 | run(window1); 58 | run(window2); 59 | 60 | glfwTerminate(); 61 | 62 | return 0; 63 | } -------------------------------------------------------------------------------- /test/c/run/gl/mx/005/test_disabled.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MX Core 3.3 profile using glfw to load. 3 | * Using MX Global for GL calls and the global context. 4 | * 5 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" c --mx --mx-global 6 | * COMPILE: $GCC -Wno-pedantic $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl -lglfw 7 | * RUN: $tmp/test 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #define ASSERT(expression, message, args...) if(!(expression)) { fprintf(stderr, "%s(%d): " message "\n", __FILE__, __LINE__, ##args); exit(1); } 17 | #define WIDTH 50 18 | #define HEIGHT 50 19 | 20 | GLFWwindow* create_window(void) { 21 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 22 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 23 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 24 | 25 | GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "", NULL, NULL); 26 | ASSERT(window != NULL, "glfw window creation failed"); 27 | return window; 28 | } 29 | 30 | void run(GLFWwindow *window) { 31 | GladGLContext *context = gladGetGLContext(); 32 | 33 | glfwMakeContextCurrent(window); 34 | 35 | int version = gladLoadGL(glfwGetProcAddress); 36 | ASSERT(version >= 3003, "glad version %d < 3003", version); 37 | ASSERT(GLAD_VERSION_MAJOR(version) >= 3, "glad major version %d < 3", GLAD_VERSION_MAJOR(version)); 38 | ASSERT(GLAD_VERSION_MAJOR(version) > 3 || GLAD_VERSION_MINOR(version) >= 3, "glad minor version %d < 3", GLAD_VERSION_MINOR(version)); 39 | ASSERT(context->VERSION_3_3, "GL_VERSION_3_3 not set"); 40 | ASSERT(context->KHR_debug, "KHR_debug not available"); 41 | 42 | glViewport(0, 0, WIDTH, HEIGHT); 43 | glClearColor(0.2f, 0.3f, 0.3f, 1.0f); 44 | glClear(GL_COLOR_BUFFER_BIT); 45 | 46 | glfwSwapBuffers(window); 47 | } 48 | 49 | int main(void) { 50 | ASSERT(glfwInit(), "glfw init failed"); 51 | 52 | GLFWwindow *window1 = create_window(); 53 | GLFWwindow *window2 = create_window(); 54 | 55 | run(window1); 56 | run(window2); 57 | 58 | glfwTerminate(); 59 | 60 | return 0; 61 | } -------------------------------------------------------------------------------- /test/c/run/gl/mx/006/test_disabled.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MX Core 3.3 profile using internal loader. 3 | * Using MX Global for GL calls and the global context. 4 | * 5 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" c --mx --mx-global --loader 6 | * COMPILE: $GCC -Wno-pedantic $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl -lglfw 7 | * RUN: $tmp/test 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #define ASSERT(expression, message, args...) if(!(expression)) { fprintf(stderr, "%s(%d): " message "\n", __FILE__, __LINE__, ##args); exit(1); } 17 | #define WIDTH 50 18 | #define HEIGHT 50 19 | 20 | GLFWwindow* create_window(void) { 21 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 22 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 23 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 24 | 25 | GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "", NULL, NULL); 26 | ASSERT(window != NULL, "glfw window creation failed"); 27 | return window; 28 | } 29 | 30 | void run(GLFWwindow *window) { 31 | GladGLContext *context = gladGetGLContext(); 32 | 33 | glfwMakeContextCurrent(window); 34 | 35 | int version = gladLoaderLoadGL(); 36 | ASSERT(version >= 3003, "glad version %d < 3003", version); 37 | ASSERT(GLAD_VERSION_MAJOR(version) >= 3, "glad major version %d < 3", GLAD_VERSION_MAJOR(version)); 38 | ASSERT(GLAD_VERSION_MAJOR(version) > 3 || GLAD_VERSION_MINOR(version) >= 3, "glad minor version %d < 3", GLAD_VERSION_MINOR(version)); 39 | ASSERT(context->VERSION_3_3, "GL_VERSION_3_3 not set"); 40 | ASSERT(context->KHR_debug, "KHR_debug not available"); 41 | 42 | glViewport(0, 0, WIDTH, HEIGHT); 43 | glClearColor(0.2f, 0.3f, 0.3f, 1.0f); 44 | glClear(GL_COLOR_BUFFER_BIT); 45 | 46 | glfwSwapBuffers(window); 47 | } 48 | 49 | int main(void) { 50 | ASSERT(glfwInit(), "glfw init failed"); 51 | 52 | GLFWwindow *window1 = create_window(); 53 | GLFWwindow *window2 = create_window(); 54 | 55 | run(window1); 56 | run(window2); 57 | 58 | glfwTerminate(); 59 | 60 | return 0; 61 | } -------------------------------------------------------------------------------- /test/c/run/gl/on-demand+debug/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Core 3.3 on demand debug profile using glad to load 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" --extensions="" c --debug --on-demand --loader 5 | * COMPILE: $GCC -Wno-pedantic $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl -lglfw 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #define ASSERT(expression, message, args...) if(!(expression)) { fprintf(stderr, "%s(%d): " message "\n", __FILE__, __LINE__, ##args); exit(1); } 17 | #define WIDTH 50 18 | #define HEIGHT 50 19 | 20 | static int pre = 0; 21 | static int post = 0; 22 | 23 | static void pre_call_gl_callback(const char *name, GLADapiproc apiproc, int len_args, ...) { 24 | (void) name; 25 | (void) apiproc; 26 | (void) len_args; 27 | ++pre; 28 | } 29 | 30 | static void post_call_gl_callback(void *ret, const char *name, GLADapiproc apiproc, int len_args, ...) { 31 | (void) ret; 32 | (void) name; 33 | (void) apiproc; 34 | (void) len_args; 35 | ++post; 36 | } 37 | 38 | int main(void) { 39 | ASSERT(glfwInit(), "glfw init failed"); 40 | 41 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 42 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 43 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 44 | 45 | GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "", NULL, NULL); 46 | ASSERT(window != NULL, "glfw window creation failed"); 47 | glfwMakeContextCurrent(window); 48 | 49 | glViewport(0, 0, WIDTH, HEIGHT); 50 | 51 | gladSetGLPreCallback(pre_call_gl_callback); 52 | gladSetGLPostCallback(post_call_gl_callback); 53 | 54 | glClearColor(0.2f, 0.3f, 0.3f, 1.0f); 55 | glClear(GL_COLOR_BUFFER_BIT); 56 | 57 | ASSERT(pre == 2, "pre callback called %d times, expected twice", pre); 58 | ASSERT(post == 2, "post callback called %d times, expected twice", post); 59 | 60 | glfwSwapBuffers(window); 61 | 62 | glfwTerminate(); 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /test/c/run/gl/on-demand+debug/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Core 3.3 on demand debug profile using glfw to load 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" --extensions="" c --debug --on-demand 5 | * COMPILE: $GCC -Wno-pedantic $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl -lglfw 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #define ASSERT(expression, message, args...) if(!(expression)) { fprintf(stderr, "%s(%d): " message "\n", __FILE__, __LINE__, ##args); exit(1); } 17 | #define WIDTH 50 18 | #define HEIGHT 50 19 | 20 | static int pre = 0; 21 | static int post = 0; 22 | 23 | static void pre_call_gl_callback(const char *name, GLADapiproc apiproc, int len_args, ...) { 24 | (void) name; 25 | (void) apiproc; 26 | (void) len_args; 27 | ++pre; 28 | } 29 | 30 | static void post_call_gl_callback(void *ret, const char *name, GLADapiproc apiproc, int len_args, ...) { 31 | (void) ret; 32 | (void) name; 33 | (void) apiproc; 34 | (void) len_args; 35 | ++post; 36 | } 37 | 38 | int main(void) { 39 | ASSERT(glfwInit(), "glfw init failed"); 40 | 41 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 42 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 43 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 44 | 45 | GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "", NULL, NULL); 46 | ASSERT(window != NULL, "glfw window creation failed"); 47 | glfwMakeContextCurrent(window); 48 | 49 | gladSetGLOnDemandLoader(glfwGetProcAddress); 50 | 51 | glViewport(0, 0, WIDTH, HEIGHT); 52 | 53 | gladSetGLPreCallback(pre_call_gl_callback); 54 | gladSetGLPostCallback(post_call_gl_callback); 55 | 56 | glClearColor(0.2f, 0.3f, 0.3f, 1.0f); 57 | glClear(GL_COLOR_BUFFER_BIT); 58 | 59 | ASSERT(pre == 2, "pre callback called %d times, expected twice", pre); 60 | ASSERT(post == 2, "post callback called %d times, expected twice", post); 61 | 62 | glfwSwapBuffers(window); 63 | 64 | glfwTerminate(); 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /test/c/run/gl/on-demand/001/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Core 3.3 profile using glfw to load on-demand 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" c --on-demand 5 | * COMPILE: $GCC -Wno-pedantic $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl -lglfw 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define ASSERT(expression, message, args...) if(!(expression)) { fprintf(stderr, "%s(%d): " message "\n", __FILE__, __LINE__, ##args); exit(1); } 15 | #define WIDTH 50 16 | #define HEIGHT 50 17 | 18 | int main(void) { 19 | ASSERT(glfwInit(), "glfw init failed"); 20 | 21 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 22 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 23 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 24 | 25 | GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "", NULL, NULL); 26 | ASSERT(window != NULL, "glfw window creation failed"); 27 | glfwMakeContextCurrent(window); 28 | 29 | gladSetGLOnDemandLoader(glfwGetProcAddress); 30 | 31 | glViewport(0, 0, WIDTH, HEIGHT); 32 | glClearColor(0.2f, 0.3f, 0.3f, 1.0f); 33 | glClear(GL_COLOR_BUFFER_BIT); 34 | 35 | glfwSwapBuffers(window); 36 | 37 | glfwTerminate(); 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /test/c/run/gl/on-demand/002/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Core 3.3 profile builtin on-demand loader 3 | * 4 | * GLAD: $GLAD --out-path=$tmp --api="gl:core" c --on-demand --loader 5 | * COMPILE: $GCC -Wno-pedantic $test -o $tmp/test -I$tmp/include $tmp/src/gl.c -ldl -lglfw 6 | * RUN: $tmp/test 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define ASSERT(expression, message, args...) if(!(expression)) { fprintf(stderr, "%s(%d): " message "\n", __FILE__, __LINE__, ##args); exit(1); } 15 | #define WIDTH 50 16 | #define HEIGHT 50 17 | 18 | int main(void) { 19 | ASSERT(glfwInit(), "glfw init failed"); 20 | 21 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 22 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 23 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 24 | 25 | GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "", NULL, NULL); 26 | ASSERT(window != NULL, "glfw window creation failed"); 27 | glfwMakeContextCurrent(window); 28 | 29 | glViewport(0, 0, WIDTH, HEIGHT); 30 | glClearColor(0.2f, 0.3f, 0.3f, 1.0f); 31 | glClear(GL_COLOR_BUFFER_BIT); 32 | 33 | glfwSwapBuffers(window); 34 | 35 | glfwTerminate(); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /test/rust/compile/egl/default/001/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "compile-egl-default-001" 3 | version = "0.1.0" 4 | 5 | [[bin]] 6 | path = "test.rs" 7 | name = "test" 8 | 9 | [dependencies] 10 | glad-egl = { path = "./glad-egl/" } 11 | -------------------------------------------------------------------------------- /test/rust/compile/egl/default/001/test.rs: -------------------------------------------------------------------------------- 1 | #![deny(warnings)] 2 | /** 3 | * Full EGL should compile 4 | * 5 | * GLAD: $GLAD --out-path=$tmp --api="egl=" rust 6 | * COMPILE: cp -r $test_dir/. $tmp && cd $tmp && cargo build 7 | * RUN: cargo run 8 | */ 9 | extern crate glad_egl; 10 | use glad_egl::egl; 11 | 12 | #[allow(path_statements)] 13 | fn main() { 14 | egl::GetProcAddress; 15 | egl::SwapBuffersWithDamageEXT; 16 | } 17 | -------------------------------------------------------------------------------- /test/rust/compile/gl/default/001/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "compile-gl-default-001" 3 | version = "0.1.0" 4 | 5 | [[bin]] 6 | path = "test.rs" 7 | name = "test" 8 | 9 | [dependencies] 10 | glad-gl = { path = "./glad-gl/" } 11 | -------------------------------------------------------------------------------- /test/rust/compile/gl/default/001/test.rs: -------------------------------------------------------------------------------- 1 | #![deny(warnings)] 2 | /** 3 | * Full core GL, should compile 4 | * 5 | * GLAD: $GLAD --out-path=$tmp --api="gl:core=" rust 6 | * COMPILE: cp -r $test_dir/. $tmp && cd $tmp && cargo build 7 | * RUN: cargo run 8 | */ 9 | extern crate glad_gl; 10 | use glad_gl::gl; 11 | 12 | #[allow(path_statements)] 13 | fn main() { 14 | gl::Clear; 15 | gl::MultiDrawElementsEXT; 16 | } 17 | -------------------------------------------------------------------------------- /test/rust/compile/gl/default/002/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "compile-gl-default-002" 3 | version = "0.1.0" 4 | 5 | [[bin]] 6 | path = "test.rs" 7 | name = "test" 8 | 9 | [dependencies] 10 | glad-gl = { path = "./glad-gl/" } 11 | -------------------------------------------------------------------------------- /test/rust/compile/gl/default/002/test.rs: -------------------------------------------------------------------------------- 1 | #![deny(warnings)] 2 | /** 3 | * Full compatibility GL, should compile 4 | * 5 | * GLAD: $GLAD --out-path=$tmp --api="gl:compatibility=" rust 6 | * COMPILE: cp -r $test_dir/. $tmp && cd $tmp && cargo build 7 | * RUN: cargo run 8 | */ 9 | extern crate glad_gl; 10 | use glad_gl::gl; 11 | 12 | #[allow(path_statements)] 13 | fn main() { 14 | gl::Begin; 15 | gl::Clear; 16 | gl::MultiDrawElementsEXT; 17 | } 18 | -------------------------------------------------------------------------------- /test/rust/compile/gl/default/003/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "compile-gl-default-003" 3 | version = "0.1.0" 4 | 5 | [[bin]] 6 | path = "test.rs" 7 | name = "test" 8 | 9 | [dependencies] 10 | glad-gl = { path = "./glad-gl/" } 11 | -------------------------------------------------------------------------------- /test/rust/compile/gl/default/003/test.rs: -------------------------------------------------------------------------------- 1 | #![deny(warnings)] 2 | /** 3 | * Enums / Constants should not be prefixed. 4 | * 5 | * GLAD: $GLAD --out-path=$tmp --api="gl:core=" rust 6 | * COMPILE: cp -r $test_dir/. $tmp && cd $tmp && cargo build 7 | * RUN: cargo run 8 | */ 9 | extern crate glad_gl; 10 | use glad_gl::gl; 11 | 12 | #[allow(path_statements)] 13 | fn main() { 14 | gl::_1PASS_EXT; 15 | gl::ALPHA; 16 | } 17 | -------------------------------------------------------------------------------- /test/rust/compile/glx/default/001/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "compile-glx-default-001" 3 | version = "0.1.0" 4 | 5 | [[bin]] 6 | path = "test.rs" 7 | name = "test" 8 | 9 | [dependencies] 10 | glad-glx = { path = "./glad-glx/" } 11 | -------------------------------------------------------------------------------- /test/rust/compile/glx/default/001/test.rs: -------------------------------------------------------------------------------- 1 | #![deny(warnings)] 2 | /** 3 | * Full GLX, should compile 4 | * 5 | * GLAD: $GLAD --out-path=$tmp --api="glx=" rust 6 | * COMPILE: cp -r $test_dir/. $tmp && cd $tmp && cargo build 7 | * RUN: cargo run 8 | */ 9 | extern crate glad_glx; 10 | use glad_glx::glx; 11 | 12 | #[allow(path_statements)] 13 | fn main() { 14 | glx::GetProcAddress; 15 | glx::FreeContextEXT; 16 | } 17 | -------------------------------------------------------------------------------- /test/rust/compile/vulkan/default/001/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "compile-vulkan-default-001" 3 | version = "0.1.0" 4 | 5 | [[bin]] 6 | path = "test.rs" 7 | name = "test" 8 | 9 | [dependencies] 10 | glad-vulkan = { path = "./glad-vulkan/", features = ["xcb", "macos", "xlib_xrandr", "xlib", "ios", "win32", "wayland", "vi", "android"] } 11 | -------------------------------------------------------------------------------- /test/rust/compile/vulkan/default/001/test.rs: -------------------------------------------------------------------------------- 1 | #![deny(warnings)] 2 | /** 3 | * Full VK should compile 4 | * 5 | * GLAD: $GLAD --out-path=$tmp --api="vulkan=" --extensions="VK_KHR_swapchain,VK_NV_external_memory_win32,VK_MVK_macos_surface,VK_KHR_wayland_surface,VK_NN_vi_surface,VK_MVK_ios_surface,VK_EXT_acquire_xlib_display,VK_KHR_xcb_surface,VK_ANDROID_external_memory_android_hardware_buffer" rust 6 | * COMPILE: cp -r $test_dir/. $tmp && cd $tmp && cargo build 7 | * RUN: cargo run 8 | */ 9 | extern crate glad_vulkan; 10 | use glad_vulkan::vk; 11 | 12 | #[allow(path_statements)] 13 | fn main() { 14 | vk::GetDeviceProcAddr; 15 | vk::GetSwapchainImagesKHR; 16 | 17 | vk::GetMemoryWin32HandleNV; 18 | vk::CreateMacOSSurfaceMVK; 19 | vk::CreateWaylandSurfaceKHR; 20 | vk::CreateViSurfaceNN; 21 | vk::CreateIOSSurfaceMVK; 22 | vk::GetRandROutputDisplayEXT; 23 | vk::GetPhysicalDeviceXcbPresentationSupportKHR; 24 | vk::GetMemoryAndroidHardwareBufferANDROID; 25 | } 26 | -------------------------------------------------------------------------------- /test/rust/compile/wgl/default/001/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "compile-wgl-default-001" 3 | version = "0.1.0" 4 | 5 | [[bin]] 6 | path = "test.rs" 7 | name = "test" 8 | 9 | [dependencies] 10 | glad-wgl = { path = "./glad-wgl/" } 11 | -------------------------------------------------------------------------------- /test/rust/compile/wgl/default/001/test.rs: -------------------------------------------------------------------------------- 1 | #![deny(warnings)] 2 | /** 3 | * Full WGL should compile 4 | * 5 | * GLAD: $GLAD --out-path=$tmp --api="wgl=" rust 6 | * COMPILE: cp -r $test_dir/. $tmp && cd $tmp && cargo build 7 | * RUN: cargo run 8 | */ 9 | extern crate glad_wgl; 10 | use glad_wgl::wgl; 11 | 12 | #[allow(path_statements)] 13 | fn main() { 14 | wgl::GetProcAddress; 15 | wgl::GetSwapIntervalEXT; 16 | } 17 | -------------------------------------------------------------------------------- /test/rust/gen/mx/001/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "gen-mx-001" 3 | version = "0.1.0" 4 | 5 | [[bin]] 6 | path = "test.rs" 7 | name = "test" 8 | 9 | [dependencies] 10 | glad-gl = { path = "./glad-gl/" } 11 | -------------------------------------------------------------------------------- /test/rust/gen/mx/001/test.rs: -------------------------------------------------------------------------------- 1 | #![deny(warnings)] 2 | /** 3 | * Make sure the generated context struct is Send + Sync 4 | * 5 | * GLAD: $GLAD --out-path=$tmp --api="gl:core=" rust --mx 6 | * COMPILE: cp -r $test_dir/. $tmp && cd $tmp && cargo build 7 | * RUN: cargo run 8 | */ 9 | extern crate glad_gl; 10 | use glad_gl::gl; 11 | use std::mem::MaybeUninit; 12 | 13 | fn requires_sync(_x: &T) {} 14 | fn requires_send(_x: &T) {} 15 | 16 | #[allow(path_statements)] 17 | fn main() { 18 | #[allow(invalid_value)] 19 | let gl: gl::Gl = unsafe { MaybeUninit::uninit().assume_init() }; 20 | 21 | requires_send(&gl); 22 | requires_sync(&gl); 23 | } 24 | -------------------------------------------------------------------------------- /test/rust/run/gl/default/001/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "run-gl-default-001" 3 | version = "0.1.0" 4 | 5 | [[bin]] 6 | path = "test.rs" 7 | name = "test" 8 | 9 | [dependencies] 10 | glad-gl = { path = "./glad-gl/" } 11 | glfw = { version = "0.23.0", default-features = false } 12 | -------------------------------------------------------------------------------- /test/rust/run/gl/default/001/test.rs: -------------------------------------------------------------------------------- 1 | #![deny(warnings)] 2 | /** 3 | * Full core GL, should compile 4 | * 5 | * GLAD: $GLAD --out-path=$tmp --api="gl:core=" rust 6 | * COMPILE: cp -r $test_dir/. $tmp && cd $tmp && cargo build 7 | * RUN: cargo run 8 | */ 9 | extern crate glad_gl; 10 | extern crate glfw; 11 | 12 | use glad_gl::gl; 13 | use glfw::Context; 14 | 15 | fn main() { 16 | let mut glfw = glfw::init(glfw::LOG_ERRORS).unwrap(); 17 | 18 | let (mut window, _events) = 19 | glfw.create_window(300, 300, "[glad] Rust - OpenGL with GLFW", glfw::WindowMode::Windowed) 20 | .expect("Failed to create GLFW window."); 21 | 22 | window.set_key_polling(true); 23 | window.make_current(); 24 | 25 | gl::load(|e| glfw.get_proc_address_raw(e) as *const std::os::raw::c_void); 26 | 27 | glfw.poll_events(); 28 | 29 | unsafe { 30 | gl::Viewport(0, 0, 300, 300); 31 | gl::ClearColor(0.7, 0.9, 0.1, 1.0); 32 | gl::Clear(gl::COLOR_BUFFER_BIT); 33 | } 34 | 35 | window.swap_buffers(); 36 | } 37 | -------------------------------------------------------------------------------- /utility/bump_version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | if [ -z "$1" ]; then 4 | echo "No version supplied" 5 | exit 1 6 | fi 7 | 8 | VERSION="$1" 9 | VERSION_PYTHON="__version__ = '${VERSION}'" 10 | 11 | OLD_VERSION=$(python -c "import glad; print(glad.__version__)") 12 | 13 | echo "Old Version: $OLD_VERSION" 14 | echo "New Version: $VERSION" 15 | echo 16 | 17 | if [ "$VERSION" == "$OLD_VERSION" ] 18 | then 19 | echo "Version equals the old version" 20 | exit 1 21 | fi 22 | 23 | echo "Python: $VERSION_PYTHON" 24 | read -p "Do you want to update to version $VERSION? [y/n]: " -n 1 -r 25 | echo 26 | 27 | if [[ ! $REPLY =~ ^[Yy]$ ]] 28 | then 29 | echo "Aborted" 30 | exit 1 31 | fi 32 | 33 | 34 | echo -e "\n$VERSION_PYTHON\n" > glad/__init__.py 35 | 36 | git commit -am "setup: Bumped version: $VERSION." 37 | git tag "v$VERSION" 38 | 39 | rm -rf build/ 40 | rm -rf dist/ 41 | 42 | python -m build 43 | twine upload dist/* 44 | 45 | -------------------------------------------------------------------------------- /utility/download.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | 6 | TARGET=${TARGET:="."} 7 | 8 | 9 | rm -f "${TARGET}/egl.xml" 10 | wget -O "${TARGET}/egl.xml" https://raw.githubusercontent.com/KhronosGroup/EGL-Registry/main/api/egl.xml 11 | 12 | rm -f "${TARGET}/gl.xml" 13 | wget -O "${TARGET}/gl.xml" https://raw.githubusercontent.com/KhronosGroup/OpenGL-Registry/main/xml/gl.xml 14 | 15 | rm -f "${TARGET}/glx.xml" 16 | wget -O "${TARGET}/glx.xml" https://raw.githubusercontent.com/KhronosGroup/OpenGL-Registry/main/xml/glx.xml 17 | 18 | rm -f "${TARGET}/wgl.xml" 19 | wget -O "${TARGET}/wgl.xml" https://raw.githubusercontent.com/KhronosGroup/OpenGL-Registry/main/xml/wgl.xml 20 | 21 | rm -f "${TARGET}/vk.xml" 22 | wget -O "${TARGET}/vk.xml" https://raw.githubusercontent.com/KhronosGroup/Vulkan-Docs/main/xml/vk.xml 23 | 24 | rm -f "${TARGET}/khrplatform.h" 25 | wget -O "${TARGET}/khrplatform.h" https://raw.githubusercontent.com/KhronosGroup/EGL-Registry/main/api/KHR/khrplatform.h 26 | 27 | rm -f "${TARGET}/eglplatform.h" 28 | wget -O "${TARGET}/eglplatform.h" https://raw.githubusercontent.com/KhronosGroup/EGL-Registry/main/api/EGL/eglplatform.h 29 | 30 | rm -f "${TARGET}/vk_platform.h" 31 | wget -O "${TARGET}/vk_platform.h" https://raw.githubusercontent.com/KhronosGroup/Vulkan-Docs/main/include/vulkan/vk_platform.h 32 | 33 | rm -f "${TARGET}/vulkan_video_codecs_common.h" 34 | wget -O "${TARGET}/vulkan_video_codecs_common.h" https://raw.githubusercontent.com/KhronosGroup/Vulkan-Headers/main/include/vk_video/vulkan_video_codecs_common.h 35 | 36 | rm -f "${TARGET}/vulkan_video_codec_h264std.h" 37 | wget -O "${TARGET}/vulkan_video_codec_h264std.h" https://raw.githubusercontent.com/KhronosGroup/Vulkan-Headers/main/include/vk_video/vulkan_video_codec_h264std.h 38 | rm -f "${TARGET}/vulkan_video_codec_h264std_decode.h" 39 | wget -O "${TARGET}/vulkan_video_codec_h264std_decode.h" https://raw.githubusercontent.com/KhronosGroup/Vulkan-Headers/main/include/vk_video/vulkan_video_codec_h264std_decode.h 40 | rm -f "${TARGET}/vulkan_video_codec_h264std_encode.h" 41 | wget -O "${TARGET}/vulkan_video_codec_h264std_encode.h" https://raw.githubusercontent.com/KhronosGroup/Vulkan-Headers/main/include/vk_video/vulkan_video_codec_h264std_encode.h 42 | 43 | rm -f "${TARGET}/vulkan_video_codec_h265std.h" 44 | wget -O "${TARGET}/vulkan_video_codec_h265std.h" https://raw.githubusercontent.com/KhronosGroup/Vulkan-Headers/main/include/vk_video/vulkan_video_codec_h265std.h 45 | rm -f "${TARGET}/vulkan_video_codec_h265std_decode.h" 46 | wget -O "${TARGET}/vulkan_video_codec_h265std_decode.h" https://raw.githubusercontent.com/KhronosGroup/Vulkan-Headers/main/include/vk_video/vulkan_video_codec_h265std_decode.h 47 | rm -f "${TARGET}/vulkan_video_codec_h265std_encode.h" 48 | wget -O "${TARGET}/vulkan_video_codec_h265std_encode.h" https://raw.githubusercontent.com/KhronosGroup/Vulkan-Headers/main/include/vk_video/vulkan_video_codec_h265std_encode.h 49 | 50 | 51 | rm -f "${TARGET}/vulkan_video_codec_av1std.h" 52 | wget -O "${TARGET}/vulkan_video_codec_av1std.h" https://raw.githubusercontent.com/KhronosGroup/Vulkan-Headers/main/include/vk_video/vulkan_video_codec_av1std.h 53 | rm -f "${TARGET}/vulkan_video_codec_av1std_decode.h" 54 | wget -O "${TARGET}/vulkan_video_codec_av1std_decode.h" https://raw.githubusercontent.com/KhronosGroup/Vulkan-Headers/main/include/vk_video/vulkan_video_codec_av1std_decode.h 55 | -------------------------------------------------------------------------------- /utility/examples.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | TMP=${TMP:="./build"} 6 | 7 | PYTHON=${PYTHON:="python"} 8 | GLAD=${GLAD:="$PYTHON -m glad --quiet"} 9 | 10 | _GCC=${_GCC:="gcc"} 11 | _GPP=${_GPP:="g++"} 12 | _MINGW_GCC=${_MINGW_GCC:="x86_64-w64-mingw32-gcc"} 13 | _GCC_FLAGS="-Wall -Wextra -Werror -Wno-unused-parameter" 14 | 15 | GCC=${GCC:="$_GCC $_GCC_FLAGS"} 16 | GPP=${GPP:="$_GPP $_GCC_FLAGS"} 17 | MINGW_GCC=${MINGW_GCC:="$_MINGW_GCC $_GCC_FLAGS"} 18 | 19 | WINE=${WINE:="wine"} 20 | 21 | 22 | function start { 23 | echo "-------> ${1}" 24 | rm -rf ${TMP} 25 | } 26 | 27 | function end { 28 | echo 29 | } 30 | 31 | start "egl_glfw.c" 32 | ${GLAD} --out-path="${TMP}" --api="gles1" c --loader 33 | ${GLAD} --out-path="${TMP}" --api="egl" c --loader 34 | ${GCC} example/c/egl_glfw.c -o ${TMP}/run -Ibuild/include ${TMP}/src/*.c -ldl -lglfw && ${TMP}/run 35 | end 36 | 37 | start "egl_x11.c" 38 | ${GLAD} --out-path="${TMP}" --api="gles2" c --loader 39 | ${GLAD} --out-path="${TMP}" --api="egl" c --loader 40 | ${GCC} example/c/egl_x11/egl_x11.c -o ${TMP}/run -Ibuild/include ${TMP}/src/*.c -ldl -lX11 && ${TMP}/run 41 | end 42 | 43 | start "gl_glfw.c" 44 | ${GLAD} --out-path="${TMP}" --api="gl:core" c 45 | ${GCC} example/c/gl_glfw.c -o ${TMP}/run -Ibuild/include ${TMP}/src/*.c -ldl -lglfw && ${TMP}/run 46 | end 47 | 48 | start "gl_sdl2.c" 49 | ${GLAD} --out-path="${TMP}" --api="gl:core" c 50 | ${GCC} example/c/gl_sdl2.c -o ${TMP}/run -Ibuild/include ${TMP}/src/*.c -ldl `sdl2-config --libs --cflags` && ${TMP}/run 51 | end 52 | 53 | start "glut.c" 54 | ${GLAD} --out-path="${TMP}" --api="gl:core" c --loader 55 | ${GCC} example/c/glut.c -o ${TMP}/run -Ibuild/include ${TMP}/src/*.c -ldl -lglut && ${TMP}/run 56 | end 57 | 58 | start "glx.c" 59 | ${GLAD} --out-path="${TMP}" --api="gl:core" c --loader 60 | ${GLAD} --out-path="${TMP}" --api="glx" c --loader 61 | ${GCC} example/c/glx.c -o ${TMP}/run -Ibuild/include ${TMP}/src/*.c -ldl -lX11 && ${TMP}/run 62 | end 63 | 64 | start "glx_modern.c" 65 | ${GLAD} --out-path="${TMP}" --api="gl:core" c --loader 66 | ${GLAD} --out-path="${TMP}" --api="glx" c --loader 67 | ${GCC} example/c/glx_modern.c -o ${TMP}/run -Ibuild/include ${TMP}/src/*.c -ldl -lX11 && ${TMP}/run 68 | end 69 | 70 | start "vulkan_tri_glfw.c" 71 | ${GLAD} --out-path="${TMP}" --api="vulkan" c --loader 72 | ${GCC} example/c/vulkan_tri_glfw/vulkan_tri_glfw.c -o ${TMP}/run -Ibuild/include ${TMP}/src/*.c -ldl -lglfw && ${TMP}/run 73 | end 74 | 75 | start "wgl.c" 76 | ${GLAD} --out-path="${TMP}" --api="gl:core" c --loader 77 | ${GLAD} --out-path="${TMP}" --api="wgl" c --loader 78 | ${MINGW_GCC} example/c/wgl.c -o ${TMP}/run -Ibuild/include ${TMP}/src/*.c -lgdi32 -lopengl32 && ${WINE} ${TMP}/run 79 | end 80 | 81 | start "hellowindow2.c" 82 | ${GLAD} --out-path="${TMP}" --api="gl:core" c --loader 83 | ${GPP} example/c++/hellowindow2.cpp -o ${TMP}/run -Ibuild/include ${TMP}/src/*.c -ldl -lglfw && ${TMP}/run 84 | end 85 | 86 | start "hellowindow2_macro.c" 87 | ${GLAD} --out-path="${TMP}" --api="gl:core" c --loader --header-only 88 | ${GPP} example/c++/hellowindow2_macro.cpp -o ${TMP}/run -Ibuild/include -ldl -lglfw && ${TMP}/run 89 | end 90 | 91 | start "hellowindow2_mx.c" 92 | ${GLAD} --out-path="${TMP}" --api="gl:core" c --loader --mx 93 | ${GPP} example/c++/hellowindow2_mx.cpp -o ${TMP}/run -Ibuild/include ${TMP}/src/*.c -ldl -lglfw && ${TMP}/run 94 | end 95 | 96 | start "multiwin_mx.c" 97 | ${GLAD} --out-path="${TMP}" --api="gl:core" c --loader --mx 98 | ${GPP} example/c++/multiwin_mx/multiwin_mx.cpp -o ${TMP}/run -Ibuild/include ${TMP}/src/*.c -ldl -lglfw && ${TMP}/run 99 | end 100 | 101 | -------------------------------------------------------------------------------- /utility/generateall.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | if [ -z ${PYTHON+x} ]; then 6 | PYTHON="/usr/bin/env python" 7 | fi 8 | 9 | echo "Using python \"$PYTHON\"" 10 | 11 | if [ "$1" != "no-download" ]; then 12 | ./utility/download.sh 13 | fi 14 | 15 | 16 | rm -rf build 17 | echo "Generating C" 18 | $PYTHON -m glad --out-path=build --spec=egl --generator=c 19 | $PYTHON -m glad --out-path=build --spec=gl --api="gl=,gles1=,gles2=" --generator=c 20 | $PYTHON -m glad --out-path=build --spec=glx --generator=c 21 | $PYTHON -m glad --out-path=build --spec=wgl --generator=c 22 | echo "Generating D" 23 | $PYTHON -m glad --out-path=build --spec=egl --generator=d 24 | $PYTHON -m glad --out-path=build --spec=gl --api="gl=,gles1=,gles2=" --generator=d 25 | $PYTHON -m glad --out-path=build --spec=glx --generator=d 26 | $PYTHON -m glad --out-path=build --spec=wgl --generator=d 27 | echo "Generating Volt" 28 | $PYTHON -m glad --out-path=build --spec=egl --generator=volt 29 | $PYTHON -m glad --out-path=build --spec=gl --api="gl=,gles1=,gles2=" --generator=volt 30 | $PYTHON -m glad --out-path=build --spec=glx --generator=volt 31 | $PYTHON -m glad --out-path=build --spec=wgl --generator=volt 32 | -------------------------------------------------------------------------------- /utility/updatesub.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | git checkout master 6 | ./utility/generateall.sh 7 | 8 | echo "Updating C" 9 | git checkout c 10 | git rm -rf include 11 | git rm -rf src 12 | mv build/include include/ 13 | mv build/src src/ 14 | git add --all include 15 | git add --all src 16 | git commit -am "automatically updated" 17 | git push origin c:c 18 | 19 | echo "Updating D" 20 | git checkout d 21 | git rm -rf glad 22 | mv build/glad glad/ 23 | git add --all glad 24 | git commit -am "automatically updated" 25 | git push origin d:d 26 | 27 | echo "Updating Volt" 28 | git checkout volt 29 | git rm -rf amp 30 | mv build/amp amp/ 31 | git add --all amp 32 | git commit -am "automatically updated" 33 | git push origin volt:volt 34 | 35 | git checkout master 36 | --------------------------------------------------------------------------------