{"id":15052421,"url":"https://github.com/fuzzyzilla/glhf","last_synced_at":"2026-01-02T00:16:57.958Z","repository":{"id":251671292,"uuid":"837738229","full_name":"Fuzzyzilla/glhf","owner":"Fuzzyzilla","description":"Experimental Zero-Cost Type-State OpenGLES Wrapper","archived":false,"fork":false,"pushed_at":"2024-08-19T03:53:16.000Z","size":235,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-20T23:26:03.310Z","etag":null,"topics":["crate","graphics-programming","opengl","opengl-es","opengles","opengles3","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Fuzzyzilla.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-03T21:54:42.000Z","updated_at":"2024-08-18T23:47:13.000Z","dependencies_parsed_at":"2024-11-19T19:46:08.613Z","dependency_job_id":"f49b623d-e361-4c48-b622-02664d07eab1","html_url":"https://github.com/Fuzzyzilla/glhf","commit_stats":{"total_commits":20,"total_committers":1,"mean_commits":20.0,"dds":0.0,"last_synced_commit":"6c3927df9c7b0909b091d4e7b9fd8a089131c297"},"previous_names":["fuzzyzilla/glhf"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fuzzyzilla%2Fglhf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fuzzyzilla%2Fglhf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fuzzyzilla%2Fglhf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fuzzyzilla%2Fglhf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Fuzzyzilla","download_url":"https://codeload.github.com/Fuzzyzilla/glhf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243523077,"owners_count":20304525,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crate","graphics-programming","opengl","opengl-es","opengles","opengles3","rust"],"created_at":"2024-09-24T21:37:26.409Z","updated_at":"2026-01-02T00:16:57.919Z","avatar_url":"https://github.com/Fuzzyzilla.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GL, HF\nA quirky lil OpenGL ES 3.X wrapper crate making excessive use of typestate and the borrow checker to ensure correct API\nusage at compile time with *zero* runtime cost.\n\n**Why ES 3?** Unfortunately, this is the lingua-franca of legacy graphics. Apps targeting GL ES 3 can compile to\nthe Web, to Android, and even to iOS. While efforts exist to bridge this gap, for my purposes this is the tool I need.\n\nAlong with regular rust-ification of the API (splitting up the monolithic `GLenum` with many disjoint enums and\neliminating invalid argument combinations at the type level), two primary strategies are at play:\n\n## Typestate\nSome types in OpenGL require passing certain runtime checks before becoming usable, or have important runtime state\ndetermined by the ways in which they are accessed - for example, when a texture name is first bound to a texture target,\nit goes from an uninitialized state to being permanently associated with that texture target type; a framebuffer must\npass \"Completeness\" checking; a program must be linked.\n\nThis is codified in a \"Typestate\" API, where the types of variables change depending on the statically-known dataflow\nthey are used in.\n\nAlong with this, the bindpoints themselves (`glBindBuffer` and the likes) are written in a typestate manner. For example,\nIt must be statically known that a *non-null* buffer is bound to the `GL_ELEMENT_ARRAY_BUFFER` buffer in order to call\n`gl.draw.elements(...)`.\n\n## Borrow Checker\nThe relationship between objects in OpenGL is sometimes complex and oftentimes difficult to find documentation for. This\ncrate expresses those relationships by projecting them as rust borrows.\n\nTo execute a command, you must prove (at compile time) that you hold all the necessary resources. If any call is made\nthat may sneakily change those resources out from under you, the references are invalidated, creating an error at compile\ntime instead of a hard-to-track bug at runtime.\n\n```rust\n// Bind our texture to `TEXTURE_2D`...\nlet active_texture = gl.texture.d2.bind(\u0026awesome_texture);\n\n// (Whoops! glActiveTexture switches out every texture binding!)\ngl.texture.unit(1);\n\n// ...try to update our previously-bound `awesome_texture`\nactive_texture.mag_filter(glhf::texture::Filter::Linear);\n```\n\n```rust\nerror[E0499]: cannot borrow `gl.texture` as mutable more than once at a time\n|\n| let active_texture = gl.texture.d2.bind(\u0026self.shadow_texture);\n|                      ------------- first mutable borrow occurs here\n| gl.texture.unit(1);\n| ^^^^^^^^^^ second mutable borrow occurs here\n|\n| active_texture.mag_filter(glhf::texture::Filter::Linear);\n| -------------- first borrow later used here\n```\n\n## Cool tricks\nI just think they're neat :3\n\n```rust\nlet [a, handful, of, textures] = gl.new.textures();\n```\n\n## Non-goals\n* Automatic resource management - object handles do not have drop glue, and must be manually deleted.\n* Preventative error checking - other than the not-unsubstantial compile-time error prevention, runtime state is not\n  queried to ensure GL calls will not error. \n* Full safety - unsafe APIs are required to make use of this library, as even something as simple as `gl.draw.arrays`\n  may invoke UB. To to greatest extent possible howerver, UB is documented and some is prevented at compile time.\n* Object-oriented API - All handles are thin-wrappers around `NonZero\u003cGLuint\u003e`, and all state APIs are ZSTs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuzzyzilla%2Fglhf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffuzzyzilla%2Fglhf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuzzyzilla%2Fglhf/lists"}