Improve performance of image handle access in API draw calls.

Use raw Lua C API to store image handles in Lua userdata instead
of using `mlua::UserData`. `mlua` wraps UserData in a special way
to maintain Rust safety guarantees which prevents direct access
of the underlying data from a raw Lua state.
The `DrawImage` and `DrawImageQuad` API calls used a workaround to
access the underlying image handle before which added significant
overhead. The overhead is eliminated by manually constructing the
userdata metatable for `ImageHandle` at the cost of weaker safety
guarantees.
This commit is contained in:
meehl committed 2026-08-12 18:03:41 +02:00
1 parent c1d91768bb
commit 99fc9f608e
3 files changed
+302 -128

No files matched your search

+2 -2
View File
@@ -5,7 +5,7 @@ use crate::{
clipboard::{copy, paste},
compression::{deflate, inflate},
console::{console_clear, console_execute, console_print_table, console_printf},
image_handle::new_image_handle,
image_handle::register_image_handle_api,
input::{get_cursor_pos, is_key_down},
lua::{load_module, protected_call, protected_load_module},
paths::{
@@ -79,7 +79,7 @@ pub fn register_globals(lua: &Lua) -> LuaResult<()> {
globals.set("NewFileSearch", lua.create_function(new_search_handle)?)?;
// image handle
globals.set("NewImageHandle", lua.create_function(new_image_handle)?)?;
register_image_handle_api(&lua)?;
// clipboard
globals.set("Copy", lua.create_function(copy)?)?;