6个版本
0.1.5 | 2020年12月31日 |
---|---|
0.1.4 | 2020年10月5日 |
0.1.3 | 2020年2月24日 |
0.1.2 | 2020年1月25日 |
329 在 图形API 中排名
1,226 每月下载量
在 14 个crate中使用(通过 miniquad-fork-x)
655KB
21K SLoC
Miniquad
Miniquad 是在一个不需要深层依赖树和数千行代码来使用计算机绘制事物的世界里实现的梦想。
Miniquad 致力于提供一种在任何具有GPU的平台上都能以相同方式工作的图形抽象,尽可能轻量,同时覆盖尽可能多的机器。
支持的平台
- Windows, OpenGL 3, OpenGL 2.2;
- Linux, OpenGL 2.2, OpenGL 3, GLES 2, GLES 3;
- macOS, OpenGL 3, Metal;
- iOS, GLES 2, GLES 3, Metal;
- WASM, WebGL 1 - 已在iOS Safari、Firefox、Chrome上进行测试;
- Android, GLES 2, GLES 3.
示例
examples/quad.rs: 网络演示
examples/offscreen.rs: 网络演示
PonasKovas/miniquad-mandelbrot: 网络演示
构建示例
Linux
cargo run --example quad
在 NixOS Linux 上,您可以使用 shell.nix
开始一个开发环境,在Miniquad可以构建和运行。
Windows
# both MSVC and GNU target is supported:
rustup target add x86_64-pc-windows-msvc
# or
rustup target add x86_64-pc-windows-gnu
cargo run --example quad
WASM
rustup target add wasm32-unknown-unknown
cargo build --example quad --target wasm32-unknown-unknown
然后使用以下.html文件来加载.wasm
index.html
<html lang="en">
<head>
<meta charset="utf-8">
<title>TITLE</title>
<style>
html,
body,
canvas {
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background: black;
z-index: 0;
}
</style>
</head>
<body>
<canvas id="glcanvas" tabindex='1'></canvas>
<!-- Minified and statically hosted version of https://github.com/not-fl3/miniquad/blob/master/native/sapp-wasm/js/gl.js -->
<script src="https://not-fl3.github.io/miniquad-samples/gl.js"></script>
<script>load("quad.wasm");</script> <!-- Your compiled wasm file -->
</body>
</html>
提供静态.wasm和.html文件的一种方法
cargo install basic-http-server
basic-http-server .
Android
构建Android推荐的办法是使用Docker。
miniquad使用稍作修改的cargo-apk
docker run --rm -v $(pwd)":/root/src" -w /root/src notfl3/cargo-apk cargo quad-apk build --example quad
APK文件将在 target/android-artifacts/(debug|release)/apk
启用 "log-impl" 后,所有日志调用将被转发到 adb 控制台。不需要对 Android 进行代码修改,一切应该都能正常工作。
苹果iOS
在模拟器上运行
mkdir MyGame.app
cargo build --target x86_64-apple-ios --release
cp target/release/mygame MyGame.app
# only if the game have any assets
cp -r assets MyGame.app
cat > MyGame.app/Info.plist << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>mygame</string>
<key>CFBundleIdentifier</key>
<string>com.mygame</string>
<key>CFBundleName</key>
<string>mygame</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
</dict>
</plist>
EOF
xcrun simctl install booted MyGame.app/
xcrun simctl launch booted com.mygame
有关为真 iPhone 进行配置的详细信息和建议,请查看 https://macroquad.rs/articles/ios/
交叉编译
# windows target from linux host:
# this is how windows builds are tested from linux machine:
rustup target add x86_64-pc-windows-gnu
cargo run --example quad --target x86_64-pc-windows-gnu
目标
-
快速编译时间。目前从 "cargo clean" 开始,桌面和网页均为约 5 秒。
-
跨平台。所需平台特定用户代码量应尽可能少。
-
低端设备支持。
-
可修改性。在制作自己的游戏时,很可能发现一些硬件不兼容性。解决这类错误应很容易,实现细节不应被隐藏在抽象层之下。
-
可分支。每个平台实现通常只是一个纯 Rust 文件。而且这个文件非常易于复制粘贴 - 它不使用任何 miniquad 特定的抽象。只需复制 miniquad 平台实现的一部分即可轻松使用。
非目标
-
最终类型安全性。库应完全符合 Rust 的安全定义 - 无 UB 或内存不安全。但正确的 GPU 状态不能保证类型正确。用户代码中可以自由提供安全性抽象!
白金赞助商
Miniquad 由以下机构支持