An OpenGL function pointer loader for Rust

Overview

gl-rs

Build Status

Overview

This repository contains the necessary building blocks for OpenGL wrapper libraries. For more information on each crate, see their respective READMEs listed below.

The following crates are contained in this repository:

gl

Version License Downloads

README

An OpenGL function pointer loader for the Rust Programming Language.

[dependencies]
gl = "0.14.0"

gl_generator

Version License Downloads

README

Code generators for creating bindings to the Khronos OpenGL APIs.

[build-dependencies]
gl_generator = "0.14.0"

khronos_api

Version License Downloads

README

The Khronos XML API Registry, exposed as byte string constants.

[build-dependencies]
khronos_api = "3.1.0"

Compiling from source

khronos_api makes use of git submodules. You will need to initialize these before building:

git submodule update --init

webgl_generator

Version License Downloads

README

Code generators for creating bindings to the WebGL APIs.

[build-dependencies]
webgl_generator = "0.2.0"

webgl-stdweb

Version License Downloads

README

WebGL bindings using stdweb

[build-dependencies]
webgl_stdweb = "0.3.0"
Comments
  • Implement IDL based generators

    Implement IDL based generators

    Example generated bindings: https://gist.github.com/Diggsey/c8a4cb93c7d5643d20203401ead178a7

    This can't be merged until:

    1. I've tested it beyond the bindings compiling
    2. The next version of stdweb is released, which will contain the CanvasElement type
    opened by Diggsey 30
  • [windows] gl function was not loaded

    [windows] gl function was not loaded

    Minimal reproducible case here: https://github.com/zacps/gl-error OpenGL Extensions Viewer produces the following information: https://drive.google.com/open?id=1wGiFhQkl2_af0MPlr4FanPmhyWUXbjqR

    OS: Windows 10 build 1703 GPU: GTX 970 Nvidia driver version: 388.13 Rust toolchain: {stable, nightly}-x86_64-pc-windows-msvc Build: release & debug

    opened by zacps 29
  • Generate strings instead of AST

    Generate strings instead of AST

    This change will totally remove the generate_gl_bindings macro, in favor of Cargo build scripts.

    If you simply use the gl library, nothing changes.

    If, however, you use gl_generator, then instead of:

    generate_gl_bindings! {
     api: "gl",
     profile: "core",
     version: "4.5",
     generator: "global",
     extensions: [
     "GL_EXT_texture_filter_anisotropic",
     ],
    }
    

    Replace this by:

    include!(concat!(env!("OUT_DIR"), "/gl_bindings.rs"));
    

    And create a file named build.rs:

    extern crate gl_generator;
    extern crate khronos_api;
    
    use std::os;
    use std::io::File;
    
    fn main() {
        let dest = Path::new(os::getenv("OUT_DIR").unwrap());
    
        let mut file = File::create(&dest.join("gl_bindings.rs")).unwrap();
    
        gl_generator::generate_bindings(gl_generator::GlobalGenerator,
                                                       gl_generator::registry::Ns::Gl,
                                                       khronos_api::GL_XML,
                                                       vec!["GL_EXT_texture_filter_anisotropic".to_string()],
                                                       "4.5", "core",
                                                       &mut file).unwrap();
    }
    

    You will also need to tweak your Cargo.toml:

    [package]
    # ...
    build = "build.rs"
    
    [build-dependencies.gl_generator]
    git = "https://github.com/bjz/gl-rs"
    
    [dependencies.gl_common]
    git = "https://github.com/bjz/gl-rs"
    
    # remove [dependencies.gl_generator]
    
    opened by tomaka 25
  • Bring up to date against current rust

    Bring up to date against current rust

    This should bring gl-rs up to date. The main change is due to rust now namespacing enums. Additionally, ast::TyPath now only takes two arguments.

    Please note that this technically does not build against the current master branch of rust due to an ill-defined quote_ty macro. However, once https://github.com/rust-lang/rust/pull/19387 is fully merged things should again work as expected.

    opened by alfredr 17
  • Prevent inlining loadfn too many times

    Prevent inlining loadfn too many times

    Credit goes to @arielb1, who found this while investigating rust-lang/rust#34166.

    This patch also improves compile times of glium using old trans:

    Before patch:

    time: 0.654; rss: 420MB Prepare MIR codegen passes
      time: 1.500; rss: 456MB   write metadata
      time: 0.272; rss: 458MB   translation item collection
      time: 0.047; rss: 459MB   codegen unit partitioning
    time: 4.595; rss: 568MB translation
    time: 0.004; rss: 568MB assert dep graph
    time: 0.000; rss: 568MB serialize dep graph
      time: 1.280; rss: 294MB   llvm function passes [0]
      time: 24.618; rss: 324MB  llvm module passes [0]
      time: 10.087; rss: 322MB  codegen passes [0]
      time: 0.004; rss: 190MB   codegen passes [0]
    time: 36.471; rss: 172MB    LLVM passes
    time: 0.299; rss: 174MB linking
    

    After this patch:

    time: 0.587; rss: 414MB Prepare MIR codegen passes
      time: 1.396; rss: 459MB   write metadata
      time: 0.265; rss: 460MB   translation item collection
      time: 0.050; rss: 461MB   codegen unit partitioning
    time: 4.449; rss: 570MB translation
    time: 0.003; rss: 570MB assert dep graph
    time: 0.000; rss: 570MB serialize dep graph
      time: 1.271; rss: 292MB   llvm function passes [0]
      time: 20.428; rss: 314MB  llvm module passes [0]
      time: 8.931; rss: 313MB   codegen passes [0]
      time: 0.004; rss: 177MB   codegen passes [0]
    time: 31.011; rss: 168MB    LLVM passes
    time: 0.257; rss: 169MB linking
    
    opened by jonas-schievink 15
  • Slow build time for gl::load_with usages

    Slow build time for gl::load_with usages

    On my i5-3550 this code takes 3.2 seconds to build, which is quite a bit taking into account it is only loading the OpenGL library.

    extern crate glutin;
    extern crate gl;
    
    fn main() {
        let window = glutin::Window::new().unwrap();
        unsafe { window.make_current() };
        gl::load_with(|symbol| window.get_proc_address(symbol));
    }
    

    It was tested with rustc 1.0.0-nightly (dfc5c0f1e 2015-02-18).

    opened by ntrrgc 15
  • gl_generator: implement fallbacks based on aliases

    gl_generator: implement fallbacks based on aliases

    These aliases are already present in the XML, so we might as well use them! As OpenGL evolves and is extended, it frequently occurs that a vendor introduces an extension, giving a function a name like glFooNV or glFooAMD. Then, it gets proposed to the ARB and is renamed glFooEXT. Then, this extension gets standardized and is placed in the core profile and is once again renamed to its final name, glFoo.

    For Mesa, they implement various extensions and then finally support an OpenGL version once all extensions have been implemented. Many OpenGL features can be implemented entirely in the driver, or on most hardware even if the hardware doesn't support enough features for a specific OpenGL version. So you get situations where older GPUs only expose OpenGL 2.1, but implement almost every extension that is present in OpenGL 3.3.

    So, when glFoo can't be loaded but it has known aliases, try also loading those aliases before giving up.

    Closes #150

    opened by emberian 14
  • Missing `UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER`

    Missing `UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER`

    It is defined as a valid enum here: https://www.opengl.org/sdk/docs/man3/xhtml/glGetActiveUniformBlock.xml

    Is it a bug in the GL spec that you parse?

    My glxinfo: https://gist.github.com/kvark/fe9f69f1dc84d3ff9621 Reports that OpenGL Core 3.3 is supported, and I see GL_ARB_uniform_buffer_object in the extension list.

    bug 
    opened by kvark 13
  • Incorrect PROC typedef

    Incorrect PROC typedef

    The definition of PROC causes issues on the latest nightly. The functions aren't allow to be zero, which rust makes use by annotating them with non-null. Unfortunately, the returned functions by wglGetProcAddress can be zero (e.g GL1.1 functions). Glutin currently checks if the functions are zero else it queries the addresses via kernel32::GetProcAddress. The rust compiler optimizes this call away as it assumes we don't have null functions.

    The proposed solution is to replace extern "system" fn() with *const (), which also fixes the issue for me locally.

    bug 
    opened by msiglreith 12
  • Add WebGL support

    Add WebGL support

    I'm developing an app with emscripten + WebGL, and using gl-rs to generate the GL bindings. While WebGL and GLES are similar enough that GLES works, using GLES results in hundreds of (non-fatal) errors like "bad name in getProcAddress: glActiveShaderProgram,glActiveShaderProgram", and if you accidentally call a function that isn't supported by WebGL, it seems to jump to an arbitrary address. Adding WebGL support would prevent this kind of thing, and might also allow WebGL extensions.

    opened by nstoddard 12
  • Static loader is unsafe

    Static loader is unsafe

    Scenario:

    Thread 1              |  Thread 2
    ========              |  ========
    driver1::make_current |
    gl::load_with         |
                          |  driver2::make_current
                          |  gl::Begin() // crash!
    

    In general, loading GL functions can be thread-specific, and only the struct loader can deal with this. Every function in the static loader should be marked unsafe, and it should be heavily discouraged.

    opened by emberian 11
  • Do we make crate no_std compatible possibly

    Do we make crate no_std compatible possibly

    I noted that https://github.com/brendanzab/gl-rs/pull/530. It has been inactive for a year. I have the same issue with no_std support.

    All the "OS dependent" things that gleam uses are type definitions, it's not necessary to depend on the std crate.

    opened by XiangYyang 0
  • functions that get pointers to variables don't modify the variables

    functions that get pointers to variables don't modify the variables

    unsafe {
      let mut vao = 0;
      gl::GenVertexArrays(1, &mut vao);
      assert!(vao != 0);
    }
    

    this code panics. But if i change the initial value of vao to anything else(for example 1), it doesn't panic. Similar thing with other functions that get pointers as arguments, they don't seem to modify anything so i can't create any objects or get error logs.

    opened by abirvalarg 0
  • attempted to take value of method `SwapBuffersWithDamageKHR` on type `&api::egl::egl::Egl` and others, gl_generator bug?

    attempted to take value of method `SwapBuffersWithDamageKHR` on type `&api::egl::egl::Egl` and others, gl_generator bug?

    On https://github.com/rust-windowing/glutin/issues/1307 we get errors:

    
    error[E0599]: no method named `set_suspend_callback` found for reference `&EventLoopWindowTarget<T>` in the current scope
      --> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/glutin-0.27.0/src/api/android/mod.rs:76:12
       |
    76 |         el.set_suspend_callback(Some(Box::new(move |suspended| {
       |            ^^^^^^^^^^^^^^^^^^^^ method not found in `&EventLoopWindowTarget<T>`
    
    error[E0615]: attempted to take value of method `SwapBuffersWithDamageKHR` on type `&api::egl::egl::Egl`
       --> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/glutin-0.27.0/src/api/egl/mod.rs:621:17
        |
    621 |         if !egl.SwapBuffersWithDamageKHR.is_loaded() {
        |                 ^^^^^^^^^^^^^^^^^^^^^^^^ method, not a field
        |
    help: use parentheses to call the method
        |
    621 |         if !egl.SwapBuffersWithDamageKHR(_, _, _, _).is_loaded() {
        |                                         ++++++++++++
    
    error[E0615]: attempted to take value of method `SwapBuffersWithDamageKHR` on type `&api::egl::egl::Egl`
       --> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/glutin-0.27.0/src/api/egl/mod.rs:664:13
        |
    664 |         egl.SwapBuffersWithDamageKHR.is_loaded()
        |             ^^^^^^^^^^^^^^^^^^^^^^^^ method, not a field
        |
    help: use parentheses to call the method
        |
    664 |         egl.SwapBuffersWithDamageKHR(_, _, _, _).is_loaded()
        |                                     ++++++++++++
    
    Some errors have detailed explanations: E0599, E0615.
    For more information about an error, try `rustc --explain E0599`.
    error: could not compile `glutin` due to 3 previous errors
    

    is this a bug in gl-rs or did the members turn into functions somehow? Also set_suspend_callback is gone

    opened by lattice0 0
  • Question about WebGL usage

    Question about WebGL usage

    Hey,

    I am not entirely sure how am I supposed to use this if I want to target wasm / webgl only? Can I combine this library with wasm-pack and add some simple dependency to my Cargo.toml and start coding right away? I am also confused what's the difference between this library (assuming the target is webgl) and web-sys with webgl?

    opened by kaphula 0
  • Update glutin requirement from 0.24 to 0.27

    Update glutin requirement from 0.24 to 0.27

    Updates the requirements on glutin to permit the latest version.

    Release notes

    Sourced from glutin's releases.

    v0.27.0

    Changelog

    Sourced from glutin's changelog.

    Version 0.27.0 (2021-06-01)

    Version 0.26.0 (2020-12-10)

    Version 0.25.1 (2020-10-10)

    • X11 and Wayland are now optional features (enabled by default)

    Version 0.25.0 (2020-10-02)

    • Updated winit dependency to 0.23.0. See winit's CHANGELOG for more info.
    • Avoid loading libEGL.dll from PATH on Windows.

    Version 0.24.1 (2020-05-26)

    • On X11, Fixed unnecessary instantiation of GLX/EGL

    Version 0.24.0 (2020-03-11)

    Version 0.23.0 (2020-02-06)

    • Updated winit dependency to 0.21.0. See winit's CHANGELOG for more info.
    • Removed broken CI for the armv7-apple-ios target.

    Version 0.22.1 (2020-01-29)

    • Fixed incorrectly documented default value for ContextBuilder::with_srgb

    Version 0.22.0 (2020-01-07)

    Version 0.22.0-alpha6 (2020-01-05)

    • Fixed dependencies so wrong winit version is not used.
    • On X11, got rid of mistaken XRenderFindVisualFormat call so that glutin doesn't ignore configs that lack a XRenderPictFormat.
    • On iOS, fixed not linking against OpenGLES.framework.
    • On X11, fixed VSync not being disabled when requested.

    Version 0.22.0-alpha5 (2019-11-14)

    • Fixed build issue.

    Version 0.22.0-alpha4 (2019-11-10)

    ... (truncated)

    Commits

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.

    Dependabot will not automatically merge this PR because this dependency is pre-1.0.0.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
    • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

    Additionally, you can set the following in your Dependabot dashboard:

    • Update frequency (including time of day and day of week)
    • Pull request limits (per update run and/or open at any time)
    • Automerge options (never/patch/minor, and dev/runtime dependencies)
    • Out-of-range updates (receive only lockfile updates, if desired)
    • Security updates (receive only security updates, if desired)
    dependencies 
    opened by dependabot-preview[bot] 0
Owner
Brendan Zabarauskas
I'm a poly-paradigm developer, primarily interested in how how type systems can be used as tools for thought. he/him πŸ‘¨β€πŸŽ¨πŸ‘¨β€πŸ’»πŸ‘¨β€πŸ”¬
Brendan Zabarauskas
A vector graphics renderer using OpenGL with a Rust & C API.

bufro A vector graphics renderer using OpenGL with a Rust & C API. A Rust example can be found in examples/quickstart.rs (using glutin). A C example c

Aspect 9 Dec 15, 2022
A toy ray tracer in Rust

tray_rust - A Toy Ray Tracer in Rust tray_rust is a toy physically based ray tracer built off of the techniques discussed in Physically Based Renderin

Will Usher 492 Dec 19, 2022
A low-overhead Vulkan-like GPU API for Rust.

Getting Started | Documentation | Blog gfx-rs gfx-rs is a low-level, cross-platform graphics and compute abstraction library in Rust. It consists of t

Rust Graphics Mages 5.2k Jan 8, 2023
A complete harfbuzz's shaping algorithm port to Rust

rustybuzz rustybuzz is a complete harfbuzz's shaping algorithm port to Rust. Matches harfbuzz v2.7.0 Why? Because you can add rustybuzz = "*" to your

Evgeniy Reizner 310 Dec 22, 2022
GLFW3 bindings and idiomatic wrapper for Rust.

glfw-rs GLFW bindings and wrapper for The Rust Programming Language. Example extern crate glfw; use glfw::{Action, Context, Key}; fn main() { le

PistonDevelopers 546 Jan 3, 2023
Safe and rich Rust wrapper around the Vulkan API

Vulkano See also vulkano.rs. Vulkano is a Rust wrapper around the Vulkan graphics API. It follows the Rust philosophy, which is that as long as you do

null 3.6k Jan 3, 2023
Graph data structure library for Rust.

petgraph Graph data structure library. Supports Rust 1.41 and later. Please read the API documentation here Crate feature flags: graphmap (default) en

null 2k Jan 9, 2023
A graph library for Rust.

Gamma A graph library for Rust. Gamma provides primitives and traversals for working with graphs. It is based on ideas presented in A Minimal Graph AP

Metamolecular, LLC 122 Dec 29, 2022
Simple but powerful graph library for Rust

Graphlib Graphlib is a simple and powerful Rust graph library. This library attempts to provide a generic api for building, mutating and iterating ove

Purple Protocol 177 Nov 22, 2022
Kiss3d - Keep it simple, stupid 3d graphics engine for Rust.

Kiss3d - Keep it simple, stupid 3d graphics engine for Rust.

SΓ©bastien Crozet 1.2k Dec 26, 2022
A cool, fast maze generator and solver written in Rust

MazeCruncher Welcome to maze cruncher! Download Standalone Here Usage To get started, just run the standalone .exe in target/release or compile and ru

null 69 Sep 20, 2022
ASCII 3D-renderer using Ray Marching technique written in Rust with NCurses

pistol ASCII renderer using Ray Marching technique written in Rust ?? with NCurses. This project is a giga-chad compared to my previous attempt to wri

Eugene Sokolov 5 Dec 10, 2022
A high-performance SVG renderer, powered by Rust based resvg and napi-rs.

resvg-js resvg-js is a high-performance SVG renderer, powered by Rust based resvg and napi-rs. Fast, safe and zero dependencies! No need for node-gyp

一丝 744 Jan 7, 2023
A little cross-platform graphics engine written in rust.

Bismuth This is a version of my C++ graphics engine named Bismuth re-written with Rust. My goal is to learn more about the Rust language and make my g

Admiral γ‚΅γ‚€γ‚Ώγƒž 1 Nov 1, 2021
The library provides basic functions to work with Graphviz dot lang from rust code.

Description The library provides the basic access to the graphs in graphviz format with ability to import into or export from it. Base examples: Parse

Boris 28 Dec 16, 2022
πŸ¦€ Rust Graph Routing runtime for Apollo Federation πŸš€

Apollo Router The Apollo Router is a configurable, high-performance graph router for a federated graph. Getting started Follow the quickstart tutorial

Apollo GraphQL 502 Jan 8, 2023
Rust bindings to bgfx, a cross-platform, graphics API agnostic

Rust bindings to bgfx, a cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.

Daniel Collin 65 Dec 24, 2022
Graph API client writen in Rust

graph-rs Now available on stable Rust at crates.io graph-rs-sdk = "0.1.0" 0.1.0 and above use stable Rust. Anything before 0.1.0 uses nightly Rust. M

Sean Reeise 56 Jan 3, 2023
Rust library for of graph ensembles

Rust library for random graph ensembles Minimal Rust version: 1.55.0 Implements simple sampling and monte carlo (or rather markov-) steps, that can be

Yannick Feld 2 Dec 14, 2022