Adventures in the Absurd

A blog about programming, languages and Rust. Mostly Rust.

Graphics Engine From Scratch - Pt 1

Computer graphics has always been an interesting topic for me. The large amout of theory and maths required to render complex, detailed scenes at interactive framerates tickles a particular part of my brain. Fortunately for me, I’m doing a computer graphics course at university starting in a couple months.

However I doubt they’ll be using Rust in the course and I wouldn’t mind getting a bit of a headstart anyway. I’ve also thought about writing a graphics on and off frequently, but end up getting overloaded by the volume of information out there. So my goal here is to try to build a 3D graphics engine, in Rust, from scratch.

Unboxed Closures and FFI Callbacks

Rust is awesome, but sometimes you need to step out of the comforting embrace of a powerful type system and watchful compiler and interact with other languages. Fortunately Rust handles this quite well, with a robust and easy-to-use foreign function interface that requires little more than writing out the signatures of the foreign functions.

However that is only half the battle when writing bindings. The next part is figuring out the best way to present the (normally) C API to Rust users; exploiting the type system and features of the language as best you can. Sometimes this is easy, sometimes hard, but one thing that is always tricky to manage are callbacks.

Rust has closures as first-class entities, so it’s natural that a bindings author would want to use them when exposing a callback API to users. But how do you map Rust’s closures to C’s idea of functions? Well, that’s what I’m going to show you.

A Rustic Linker Model

This is a kinda-sorta proposal for a linking model for the rust compiler to use, allowing us to separate out from system-specific semantics and avoid being tied too closely to a system linker. The goals are to maintain most compatibility with system tools (linkers in particular), allow common cases to behave identically on all supported platforms and maintain an escape hatch to allow complex and/or esoteric cases to still work without too much hackery or relying on undocumented behaviour.

Paying Technical Debt in Rustc

With the 0.7 release of Rust almost upon us, it seems like a good time talk about some of the technical debt that has accrued in the compiler, the issues in the codegen module and plan of action to try and start paying off some of that debt.