#![feature(prelude_import)]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std;
#[cfg(target_os = "linux")]
extern crate sapp_linux as sapp;
pub mod clipboard {
use crate::Context;
#[cfg(target_os = "linux")]
pub fn get(_ctx: &mut Context) -> Option<String> {
use std::ffi::CString;
let bufname = CString::new("CLIPBOARD").unwrap();
let fmtname = CString::new("UTF8_STRING").unwrap();
unsafe { sapp_linux::clipboard::get_clipboard(bufname.as_ptr(), fmtname.as_ptr()) }
}
#[cfg(target_os = "linux")]
pub fn set(_ctx: &mut Context, data: &str) {
use std::ffi::CString;
let bufname = CString::new("CLIPBOARD").unwrap();
unsafe {
sapp_linux::clipboard::claim_clipboard_ownership(bufname.as_ptr(), data.to_owned())
};
}
}
pub mod conf {
pub enum Cache {
No,
Index,
List(Vec<&'static str>),
Tar(&'static [u8]),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Cache {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&Cache::No,) => {
let mut debug_trait_builder = f.debug_tuple("No");
debug_trait_builder.finish()
}
(&Cache::Index,) => {
let mut debug_trait_builder = f.debug_tuple("Index");
debug_trait_builder.finish()
}
(&Cache::List(ref __self_0),) => {
let mut debug_trait_builder = f.debug_tuple("List");
let _ = debug_trait_builder.field(&&(*__self_0));
debug_trait_builder.finish()
}
(&Cache::Tar(ref __self_0),) => {
let mut debug_trait_builder = f.debug_tuple("Tar");
let _ = debug_trait_builder.field(&&(*__self_0));
debug_trait_builder.finish()
}
}
}
}
pub enum Loading {
No,
Embedded,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Loading {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&Loading::No,) => {
let mut debug_trait_builder = f.debug_tuple("No");
debug_trait_builder.finish()
}
(&Loading::Embedded,) => {
let mut debug_trait_builder = f.debug_tuple("Embedded");
debug_trait_builder.finish()
}
}
}
}
pub struct Conf {
pub cache: Cache,
pub loading: Loading,
pub window_title: String,
pub window_width: i32,
pub window_height: i32,
pub high_dpi: bool,
pub fullscreen: bool,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Conf {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
Conf {
cache: ref __self_0_0,
loading: ref __self_0_1,
window_title: ref __self_0_2,
window_width: ref __self_0_3,
window_height: ref __self_0_4,
high_dpi: ref __self_0_5,
fullscreen: ref __self_0_6,
} => {
let mut debug_trait_builder = f.debug_struct("Conf");
let _ = debug_trait_builder.field("cache", &&(*__self_0_0));
let _ = debug_trait_builder.field("loading", &&(*__self_0_1));
let _ = debug_trait_builder.field("window_title", &&(*__self_0_2));
let _ = debug_trait_builder.field("window_width", &&(*__self_0_3));
let _ = debug_trait_builder.field("window_height", &&(*__self_0_4));
let _ = debug_trait_builder.field("high_dpi", &&(*__self_0_5));
let _ = debug_trait_builder.field("fullscreen", &&(*__self_0_6));
debug_trait_builder.finish()
}
}
}
}
impl Default for Conf {
fn default() -> Conf {
Conf {
cache: Cache::No,
loading: Loading::No,
window_title: "".to_owned(),
window_width: 800,
window_height: 600,
high_dpi: false,
fullscreen: false,
}
}
}
}
mod event {
use crate::sapp::{self, sapp_keycode, sapp_mousebutton};
use crate::Context;
pub enum MouseButton {
Right,
Left,
Middle,
Unknown,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for MouseButton {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&MouseButton::Right,) => {
let mut debug_trait_builder = f.debug_tuple("Right");
debug_trait_builder.finish()
}
(&MouseButton::Left,) => {
let mut debug_trait_builder = f.debug_tuple("Left");
debug_trait_builder.finish()
}
(&MouseButton::Middle,) => {
let mut debug_trait_builder = f.debug_tuple("Middle");
debug_trait_builder.finish()
}
(&MouseButton::Unknown,) => {
let mut debug_trait_builder = f.debug_tuple("Unknown");
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for MouseButton {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for MouseButton {
#[inline]
fn clone(&self) -> MouseButton {
{
*self
}
}
}
impl ::core::marker::StructuralPartialEq for MouseButton {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for MouseButton {
#[inline]
fn eq(&self, other: &MouseButton) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::hash::Hash for MouseButton {
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
match (&*self,) {
_ => ::core::hash::Hash::hash(
&unsafe { ::core::intrinsics::discriminant_value(self) },
state,
),
}
}
}
impl ::core::marker::StructuralEq for MouseButton {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for MouseButton {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
pub struct Touch {
pub id: u32,
pub x: f32,
pub y: f32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Touch {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
Touch {
id: ref __self_0_0,
x: ref __self_0_1,
y: ref __self_0_2,
} => {
let mut debug_trait_builder = f.debug_struct("Touch");
let _ = debug_trait_builder.field("id", &&(*__self_0_0));
let _ = debug_trait_builder.field("x", &&(*__self_0_1));
let _ = debug_trait_builder.field("y", &&(*__self_0_2));
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Touch {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Touch {
#[inline]
fn clone(&self) -> Touch {
{
let _: ::core::clone::AssertParamIsClone<u32>;
let _: ::core::clone::AssertParamIsClone<f32>;
let _: ::core::clone::AssertParamIsClone<f32>;
*self
}
}
}
impl From<sapp_mousebutton> for MouseButton {
fn from(btn: sapp_mousebutton) -> MouseButton {
match btn {
sapp::sapp_mousebutton_SAPP_MOUSEBUTTON_LEFT => MouseButton::Left,
sapp::sapp_mousebutton_SAPP_MOUSEBUTTON_RIGHT => MouseButton::Right,
sapp::sapp_mousebutton_SAPP_MOUSEBUTTON_MIDDLE => MouseButton::Middle,
_ => MouseButton::Unknown,
}
}
}
#[repr(u32)]
pub enum KeyCode {
Space,
Apostrophe,
Comma,
Minus,
Period,
Slash,
Key0,
Key1,
Key2,
Key3,
Key4,
Key5,
Key6,
Key7,
Key8,
Key9,
Semicolon,
Equal,
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q,
R,
S,
T,
U,
V,
W,
X,
Y,
Z,
LeftBracket,
Backslash,
RightBracket,
GraveAccent,
World1,
World2,
Escape,
Enter,
Tab,
Backspace,
Insert,
Delete,
Right,
Left,
Down,
Up,
PageUp,
PageDown,
Home,
End,
CapsLock,
ScrollLock,
NumLock,
PrintScreen,
Pause,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
F13,
F14,
F15,
F16,
F17,
F18,
F19,
F20,
F21,
F22,
F23,
F24,
F25,
Kp0,
Kp1,
Kp2,
Kp3,
Kp4,
Kp5,
Kp6,
Kp7,
Kp8,
Kp9,
KpDecimal,
KpDivide,
KpMultiply,
KpSubtract,
KpAdd,
KpEnter,
KpEqual,
LeftShift,
LeftControl,
LeftAlt,
LeftSuper,
RightShift,
RightControl,
RightAlt,
RightSuper,
Menu,
Unknown,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for KeyCode {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&KeyCode::Space,) => {
let mut debug_trait_builder = f.debug_tuple("Space");
debug_trait_builder.finish()
}
(&KeyCode::Apostrophe,) => {
let mut debug_trait_builder = f.debug_tuple("Apostrophe");
debug_trait_builder.finish()
}
(&KeyCode::Comma,) => {
let mut debug_trait_builder = f.debug_tuple("Comma");
debug_trait_builder.finish()
}
(&KeyCode::Minus,) => {
let mut debug_trait_builder = f.debug_tuple("Minus");
debug_trait_builder.finish()
}
(&KeyCode::Period,) => {
let mut debug_trait_builder = f.debug_tuple("Period");
debug_trait_builder.finish()
}
(&KeyCode::Slash,) => {
let mut debug_trait_builder = f.debug_tuple("Slash");
debug_trait_builder.finish()
}
(&KeyCode::Key0,) => {
let mut debug_trait_builder = f.debug_tuple("Key0");
debug_trait_builder.finish()
}
(&KeyCode::Key1,) => {
let mut debug_trait_builder = f.debug_tuple("Key1");
debug_trait_builder.finish()
}
(&KeyCode::Key2,) => {
let mut debug_trait_builder = f.debug_tuple("Key2");
debug_trait_builder.finish()
}
(&KeyCode::Key3,) => {
let mut debug_trait_builder = f.debug_tuple("Key3");
debug_trait_builder.finish()
}
(&KeyCode::Key4,) => {
let mut debug_trait_builder = f.debug_tuple("Key4");
debug_trait_builder.finish()
}
(&KeyCode::Key5,) => {
let mut debug_trait_builder = f.debug_tuple("Key5");
debug_trait_builder.finish()
}
(&KeyCode::Key6,) => {
let mut debug_trait_builder = f.debug_tuple("Key6");
debug_trait_builder.finish()
}
(&KeyCode::Key7,) => {
let mut debug_trait_builder = f.debug_tuple("Key7");
debug_trait_builder.finish()
}
(&KeyCode::Key8,) => {
let mut debug_trait_builder = f.debug_tuple("Key8");
debug_trait_builder.finish()
}
(&KeyCode::Key9,) => {
let mut debug_trait_builder = f.debug_tuple("Key9");
debug_trait_builder.finish()
}
(&KeyCode::Semicolon,) => {
let mut debug_trait_builder = f.debug_tuple("Semicolon");
debug_trait_builder.finish()
}
(&KeyCode::Equal,) => {
let mut debug_trait_builder = f.debug_tuple("Equal");
debug_trait_builder.finish()
}
(&KeyCode::A,) => {
let mut debug_trait_builder = f.debug_tuple("A");
debug_trait_builder.finish()
}
(&KeyCode::B,) => {
let mut debug_trait_builder = f.debug_tuple("B");
debug_trait_builder.finish()
}
(&KeyCode::C,) => {
let mut debug_trait_builder = f.debug_tuple("C");
debug_trait_builder.finish()
}
(&KeyCode::D,) => {
let mut debug_trait_builder = f.debug_tuple("D");
debug_trait_builder.finish()
}
(&KeyCode::E,) => {
let mut debug_trait_builder = f.debug_tuple("E");
debug_trait_builder.finish()
}
(&KeyCode::F,) => {
let mut debug_trait_builder = f.debug_tuple("F");
debug_trait_builder.finish()
}
(&KeyCode::G,) => {
let mut debug_trait_builder = f.debug_tuple("G");
debug_trait_builder.finish()
}
(&KeyCode::H,) => {
let mut debug_trait_builder = f.debug_tuple("H");
debug_trait_builder.finish()
}
(&KeyCode::I,) => {
let mut debug_trait_builder = f.debug_tuple("I");
debug_trait_builder.finish()
}
(&KeyCode::J,) => {
let mut debug_trait_builder = f.debug_tuple("J");
debug_trait_builder.finish()
}
(&KeyCode::K,) => {
let mut debug_trait_builder = f.debug_tuple("K");
debug_trait_builder.finish()
}
(&KeyCode::L,) => {
let mut debug_trait_builder = f.debug_tuple("L");
debug_trait_builder.finish()
}
(&KeyCode::M,) => {
let mut debug_trait_builder = f.debug_tuple("M");
debug_trait_builder.finish()
}
(&KeyCode::N,) => {
let mut debug_trait_builder = f.debug_tuple("N");
debug_trait_builder.finish()
}
(&KeyCode::O,) => {
let mut debug_trait_builder = f.debug_tuple("O");
debug_trait_builder.finish()
}
(&KeyCode::P,) => {
let mut debug_trait_builder = f.debug_tuple("P");
debug_trait_builder.finish()
}
(&KeyCode::Q,) => {
let mut debug_trait_builder = f.debug_tuple("Q");
debug_trait_builder.finish()
}
(&KeyCode::R,) => {
let mut debug_trait_builder = f.debug_tuple("R");
debug_trait_builder.finish()
}
(&KeyCode::S,) => {
let mut debug_trait_builder = f.debug_tuple("S");
debug_trait_builder.finish()
}
(&KeyCode::T,) => {
let mut debug_trait_builder = f.debug_tuple("T");
debug_trait_builder.finish()
}
(&KeyCode::U,) => {
let mut debug_trait_builder = f.debug_tuple("U");
debug_trait_builder.finish()
}
(&KeyCode::V,) => {
let mut debug_trait_builder = f.debug_tuple("V");
debug_trait_builder.finish()
}
(&KeyCode::W,) => {
let mut debug_trait_builder = f.debug_tuple("W");
debug_trait_builder.finish()
}
(&KeyCode::X,) => {
let mut debug_trait_builder = f.debug_tuple("X");
debug_trait_builder.finish()
}
(&KeyCode::Y,) => {
let mut debug_trait_builder = f.debug_tuple("Y");
debug_trait_builder.finish()
}
(&KeyCode::Z,) => {
let mut debug_trait_builder = f.debug_tuple("Z");
debug_trait_builder.finish()
}
(&KeyCode::LeftBracket,) => {
let mut debug_trait_builder = f.debug_tuple("LeftBracket");
debug_trait_builder.finish()
}
(&KeyCode::Backslash,) => {
let mut debug_trait_builder = f.debug_tuple("Backslash");
debug_trait_builder.finish()
}
(&KeyCode::RightBracket,) => {
let mut debug_trait_builder = f.debug_tuple("RightBracket");
debug_trait_builder.finish()
}
(&KeyCode::GraveAccent,) => {
let mut debug_trait_builder = f.debug_tuple("GraveAccent");
debug_trait_builder.finish()
}
(&KeyCode::World1,) => {
let mut debug_trait_builder = f.debug_tuple("World1");
debug_trait_builder.finish()
}
(&KeyCode::World2,) => {
let mut debug_trait_builder = f.debug_tuple("World2");
debug_trait_builder.finish()
}
(&KeyCode::Escape,) => {
let mut debug_trait_builder = f.debug_tuple("Escape");
debug_trait_builder.finish()
}
(&KeyCode::Enter,) => {
let mut debug_trait_builder = f.debug_tuple("Enter");
debug_trait_builder.finish()
}
(&KeyCode::Tab,) => {
let mut debug_trait_builder = f.debug_tuple("Tab");
debug_trait_builder.finish()
}
(&KeyCode::Backspace,) => {
let mut debug_trait_builder = f.debug_tuple("Backspace");
debug_trait_builder.finish()
}
(&KeyCode::Insert,) => {
let mut debug_trait_builder = f.debug_tuple("Insert");
debug_trait_builder.finish()
}
(&KeyCode::Delete,) => {
let mut debug_trait_builder = f.debug_tuple("Delete");
debug_trait_builder.finish()
}
(&KeyCode::Right,) => {
let mut debug_trait_builder = f.debug_tuple("Right");
debug_trait_builder.finish()
}
(&KeyCode::Left,) => {
let mut debug_trait_builder = f.debug_tuple("Left");
debug_trait_builder.finish()
}
(&KeyCode::Down,) => {
let mut debug_trait_builder = f.debug_tuple("Down");
debug_trait_builder.finish()
}
(&KeyCode::Up,) => {
let mut debug_trait_builder = f.debug_tuple("Up");
debug_trait_builder.finish()
}
(&KeyCode::PageUp,) => {
let mut debug_trait_builder = f.debug_tuple("PageUp");
debug_trait_builder.finish()
}
(&KeyCode::PageDown,) => {
let mut debug_trait_builder = f.debug_tuple("PageDown");
debug_trait_builder.finish()
}
(&KeyCode::Home,) => {
let mut debug_trait_builder = f.debug_tuple("Home");
debug_trait_builder.finish()
}
(&KeyCode::End,) => {
let mut debug_trait_builder = f.debug_tuple("End");
debug_trait_builder.finish()
}
(&KeyCode::CapsLock,) => {
let mut debug_trait_builder = f.debug_tuple("CapsLock");
debug_trait_builder.finish()
}
(&KeyCode::ScrollLock,) => {
let mut debug_trait_builder = f.debug_tuple("ScrollLock");
debug_trait_builder.finish()
}
(&KeyCode::NumLock,) => {
let mut debug_trait_builder = f.debug_tuple("NumLock");
debug_trait_builder.finish()
}
(&KeyCode::PrintScreen,) => {
let mut debug_trait_builder = f.debug_tuple("PrintScreen");
debug_trait_builder.finish()
}
(&KeyCode::Pause,) => {
let mut debug_trait_builder = f.debug_tuple("Pause");
debug_trait_builder.finish()
}
(&KeyCode::F1,) => {
let mut debug_trait_builder = f.debug_tuple("F1");
debug_trait_builder.finish()
}
(&KeyCode::F2,) => {
let mut debug_trait_builder = f.debug_tuple("F2");
debug_trait_builder.finish()
}
(&KeyCode::F3,) => {
let mut debug_trait_builder = f.debug_tuple("F3");
debug_trait_builder.finish()
}
(&KeyCode::F4,) => {
let mut debug_trait_builder = f.debug_tuple("F4");
debug_trait_builder.finish()
}
(&KeyCode::F5,) => {
let mut debug_trait_builder = f.debug_tuple("F5");
debug_trait_builder.finish()
}
(&KeyCode::F6,) => {
let mut debug_trait_builder = f.debug_tuple("F6");
debug_trait_builder.finish()
}
(&KeyCode::F7,) => {
let mut debug_trait_builder = f.debug_tuple("F7");
debug_trait_builder.finish()
}
(&KeyCode::F8,) => {
let mut debug_trait_builder = f.debug_tuple("F8");
debug_trait_builder.finish()
}
(&KeyCode::F9,) => {
let mut debug_trait_builder = f.debug_tuple("F9");
debug_trait_builder.finish()
}
(&KeyCode::F10,) => {
let mut debug_trait_builder = f.debug_tuple("F10");
debug_trait_builder.finish()
}
(&KeyCode::F11,) => {
let mut debug_trait_builder = f.debug_tuple("F11");
debug_trait_builder.finish()
}
(&KeyCode::F12,) => {
let mut debug_trait_builder = f.debug_tuple("F12");
debug_trait_builder.finish()
}
(&KeyCode::F13,) => {
let mut debug_trait_builder = f.debug_tuple("F13");
debug_trait_builder.finish()
}
(&KeyCode::F14,) => {
let mut debug_trait_builder = f.debug_tuple("F14");
debug_trait_builder.finish()
}
(&KeyCode::F15,) => {
let mut debug_trait_builder = f.debug_tuple("F15");
debug_trait_builder.finish()
}
(&KeyCode::F16,) => {
let mut debug_trait_builder = f.debug_tuple("F16");
debug_trait_builder.finish()
}
(&KeyCode::F17,) => {
let mut debug_trait_builder = f.debug_tuple("F17");
debug_trait_builder.finish()
}
(&KeyCode::F18,) => {
let mut debug_trait_builder = f.debug_tuple("F18");
debug_trait_builder.finish()
}
(&KeyCode::F19,) => {
let mut debug_trait_builder = f.debug_tuple("F19");
debug_trait_builder.finish()
}
(&KeyCode::F20,) => {
let mut debug_trait_builder = f.debug_tuple("F20");
debug_trait_builder.finish()
}
(&KeyCode::F21,) => {
let mut debug_trait_builder = f.debug_tuple("F21");
debug_trait_builder.finish()
}
(&KeyCode::F22,) => {
let mut debug_trait_builder = f.debug_tuple("F22");
debug_trait_builder.finish()
}
(&KeyCode::F23,) => {
let mut debug_trait_builder = f.debug_tuple("F23");
debug_trait_builder.finish()
}
(&KeyCode::F24,) => {
let mut debug_trait_builder = f.debug_tuple("F24");
debug_trait_builder.finish()
}
(&KeyCode::F25,) => {
let mut debug_trait_builder = f.debug_tuple("F25");
debug_trait_builder.finish()
}
(&KeyCode::Kp0,) => {
let mut debug_trait_builder = f.debug_tuple("Kp0");
debug_trait_builder.finish()
}
(&KeyCode::Kp1,) => {
let mut debug_trait_builder = f.debug_tuple("Kp1");
debug_trait_builder.finish()
}
(&KeyCode::Kp2,) => {
let mut debug_trait_builder = f.debug_tuple("Kp2");
debug_trait_builder.finish()
}
(&KeyCode::Kp3,) => {
let mut debug_trait_builder = f.debug_tuple("Kp3");
debug_trait_builder.finish()
}
(&KeyCode::Kp4,) => {
let mut debug_trait_builder = f.debug_tuple("Kp4");
debug_trait_builder.finish()
}
(&KeyCode::Kp5,) => {
let mut debug_trait_builder = f.debug_tuple("Kp5");
debug_trait_builder.finish()
}
(&KeyCode::Kp6,) => {
let mut debug_trait_builder = f.debug_tuple("Kp6");
debug_trait_builder.finish()
}
(&KeyCode::Kp7,) => {
let mut debug_trait_builder = f.debug_tuple("Kp7");
debug_trait_builder.finish()
}
(&KeyCode::Kp8,) => {
let mut debug_trait_builder = f.debug_tuple("Kp8");
debug_trait_builder.finish()
}
(&KeyCode::Kp9,) => {
let mut debug_trait_builder = f.debug_tuple("Kp9");
debug_trait_builder.finish()
}
(&KeyCode::KpDecimal,) => {
let mut debug_trait_builder = f.debug_tuple("KpDecimal");
debug_trait_builder.finish()
}
(&KeyCode::KpDivide,) => {
let mut debug_trait_builder = f.debug_tuple("KpDivide");
debug_trait_builder.finish()
}
(&KeyCode::KpMultiply,) => {
let mut debug_trait_builder = f.debug_tuple("KpMultiply");
debug_trait_builder.finish()
}
(&KeyCode::KpSubtract,) => {
let mut debug_trait_builder = f.debug_tuple("KpSubtract");
debug_trait_builder.finish()
}
(&KeyCode::KpAdd,) => {
let mut debug_trait_builder = f.debug_tuple("KpAdd");
debug_trait_builder.finish()
}
(&KeyCode::KpEnter,) => {
let mut debug_trait_builder = f.debug_tuple("KpEnter");
debug_trait_builder.finish()
}
(&KeyCode::KpEqual,) => {
let mut debug_trait_builder = f.debug_tuple("KpEqual");
debug_trait_builder.finish()
}
(&KeyCode::LeftShift,) => {
let mut debug_trait_builder = f.debug_tuple("LeftShift");
debug_trait_builder.finish()
}
(&KeyCode::LeftControl,) => {
let mut debug_trait_builder = f.debug_tuple("LeftControl");
debug_trait_builder.finish()
}
(&KeyCode::LeftAlt,) => {
let mut debug_trait_builder = f.debug_tuple("LeftAlt");
debug_trait_builder.finish()
}
(&KeyCode::LeftSuper,) => {
let mut debug_trait_builder = f.debug_tuple("LeftSuper");
debug_trait_builder.finish()
}
(&KeyCode::RightShift,) => {
let mut debug_trait_builder = f.debug_tuple("RightShift");
debug_trait_builder.finish()
}
(&KeyCode::RightControl,) => {
let mut debug_trait_builder = f.debug_tuple("RightControl");
debug_trait_builder.finish()
}
(&KeyCode::RightAlt,) => {
let mut debug_trait_builder = f.debug_tuple("RightAlt");
debug_trait_builder.finish()
}
(&KeyCode::RightSuper,) => {
let mut debug_trait_builder = f.debug_tuple("RightSuper");
debug_trait_builder.finish()
}
(&KeyCode::Menu,) => {
let mut debug_trait_builder = f.debug_tuple("Menu");
debug_trait_builder.finish()
}
(&KeyCode::Unknown,) => {
let mut debug_trait_builder = f.debug_tuple("Unknown");
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for KeyCode {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for KeyCode {
#[inline]
fn clone(&self) -> KeyCode {
{
*self
}
}
}
impl ::core::marker::StructuralPartialEq for KeyCode {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for KeyCode {
#[inline]
fn eq(&self, other: &KeyCode) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as u32;
let __arg_1_vi = unsafe { ::core::intrinsics::discriminant_value(&*other) } as u32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::hash::Hash for KeyCode {
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
match (&*self,) {
_ => ::core::hash::Hash::hash(
&unsafe { ::core::intrinsics::discriminant_value(self) },
state,
),
}
}
}
impl ::core::marker::StructuralEq for KeyCode {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for KeyCode {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
impl From<sapp_keycode> for KeyCode {
fn from(key_code: sapp_keycode) -> KeyCode {
match key_code {
sapp::sapp_keycode_SAPP_KEYCODE_SPACE => KeyCode::Space,
sapp::sapp_keycode_SAPP_KEYCODE_APOSTROPHE => KeyCode::Apostrophe,
sapp::sapp_keycode_SAPP_KEYCODE_COMMA => KeyCode::Comma,
sapp::sapp_keycode_SAPP_KEYCODE_MINUS => KeyCode::Minus,
sapp::sapp_keycode_SAPP_KEYCODE_PERIOD => KeyCode::Period,
sapp::sapp_keycode_SAPP_KEYCODE_SLASH => KeyCode::Slash,
sapp::sapp_keycode_SAPP_KEYCODE_0 => KeyCode::Key0,
sapp::sapp_keycode_SAPP_KEYCODE_1 => KeyCode::Key1,
sapp::sapp_keycode_SAPP_KEYCODE_2 => KeyCode::Key2,
sapp::sapp_keycode_SAPP_KEYCODE_3 => KeyCode::Key3,
sapp::sapp_keycode_SAPP_KEYCODE_4 => KeyCode::Key4,
sapp::sapp_keycode_SAPP_KEYCODE_5 => KeyCode::Key5,
sapp::sapp_keycode_SAPP_KEYCODE_6 => KeyCode::Key6,
sapp::sapp_keycode_SAPP_KEYCODE_7 => KeyCode::Key7,
sapp::sapp_keycode_SAPP_KEYCODE_8 => KeyCode::Key8,
sapp::sapp_keycode_SAPP_KEYCODE_9 => KeyCode::Key9,
sapp::sapp_keycode_SAPP_KEYCODE_SEMICOLON => KeyCode::Semicolon,
sapp::sapp_keycode_SAPP_KEYCODE_EQUAL => KeyCode::Equal,
sapp::sapp_keycode_SAPP_KEYCODE_A => KeyCode::A,
sapp::sapp_keycode_SAPP_KEYCODE_B => KeyCode::B,
sapp::sapp_keycode_SAPP_KEYCODE_C => KeyCode::C,
sapp::sapp_keycode_SAPP_KEYCODE_D => KeyCode::D,
sapp::sapp_keycode_SAPP_KEYCODE_E => KeyCode::E,
sapp::sapp_keycode_SAPP_KEYCODE_F => KeyCode::F,
sapp::sapp_keycode_SAPP_KEYCODE_G => KeyCode::G,
sapp::sapp_keycode_SAPP_KEYCODE_H => KeyCode::H,
sapp::sapp_keycode_SAPP_KEYCODE_I => KeyCode::I,
sapp::sapp_keycode_SAPP_KEYCODE_J => KeyCode::J,
sapp::sapp_keycode_SAPP_KEYCODE_K => KeyCode::K,
sapp::sapp_keycode_SAPP_KEYCODE_L => KeyCode::L,
sapp::sapp_keycode_SAPP_KEYCODE_M => KeyCode::M,
sapp::sapp_keycode_SAPP_KEYCODE_N => KeyCode::N,
sapp::sapp_keycode_SAPP_KEYCODE_O => KeyCode::O,
sapp::sapp_keycode_SAPP_KEYCODE_P => KeyCode::P,
sapp::sapp_keycode_SAPP_KEYCODE_Q => KeyCode::Q,
sapp::sapp_keycode_SAPP_KEYCODE_R => KeyCode::R,
sapp::sapp_keycode_SAPP_KEYCODE_S => KeyCode::S,
sapp::sapp_keycode_SAPP_KEYCODE_T => KeyCode::T,
sapp::sapp_keycode_SAPP_KEYCODE_U => KeyCode::U,
sapp::sapp_keycode_SAPP_KEYCODE_V => KeyCode::V,
sapp::sapp_keycode_SAPP_KEYCODE_W => KeyCode::W,
sapp::sapp_keycode_SAPP_KEYCODE_X => KeyCode::X,
sapp::sapp_keycode_SAPP_KEYCODE_Y => KeyCode::Y,
sapp::sapp_keycode_SAPP_KEYCODE_Z => KeyCode::Z,
sapp::sapp_keycode_SAPP_KEYCODE_LEFT_BRACKET => KeyCode::LeftBracket,
sapp::sapp_keycode_SAPP_KEYCODE_BACKSLASH => KeyCode::Backslash,
sapp::sapp_keycode_SAPP_KEYCODE_RIGHT_BRACKET => KeyCode::RightBracket,
sapp::sapp_keycode_SAPP_KEYCODE_GRAVE_ACCENT => KeyCode::GraveAccent,
sapp::sapp_keycode_SAPP_KEYCODE_WORLD_1 => KeyCode::World1,
sapp::sapp_keycode_SAPP_KEYCODE_WORLD_2 => KeyCode::World2,
sapp::sapp_keycode_SAPP_KEYCODE_ESCAPE => KeyCode::Escape,
sapp::sapp_keycode_SAPP_KEYCODE_ENTER => KeyCode::Enter,
sapp::sapp_keycode_SAPP_KEYCODE_TAB => KeyCode::Tab,
sapp::sapp_keycode_SAPP_KEYCODE_BACKSPACE => KeyCode::Backspace,
sapp::sapp_keycode_SAPP_KEYCODE_INSERT => KeyCode::Insert,
sapp::sapp_keycode_SAPP_KEYCODE_DELETE => KeyCode::Delete,
sapp::sapp_keycode_SAPP_KEYCODE_RIGHT => KeyCode::Right,
sapp::sapp_keycode_SAPP_KEYCODE_LEFT => KeyCode::Left,
sapp::sapp_keycode_SAPP_KEYCODE_DOWN => KeyCode::Down,
sapp::sapp_keycode_SAPP_KEYCODE_UP => KeyCode::Up,
sapp::sapp_keycode_SAPP_KEYCODE_PAGE_UP => KeyCode::PageUp,
sapp::sapp_keycode_SAPP_KEYCODE_PAGE_DOWN => KeyCode::PageDown,
sapp::sapp_keycode_SAPP_KEYCODE_HOME => KeyCode::Home,
sapp::sapp_keycode_SAPP_KEYCODE_END => KeyCode::End,
sapp::sapp_keycode_SAPP_KEYCODE_CAPS_LOCK => KeyCode::CapsLock,
sapp::sapp_keycode_SAPP_KEYCODE_SCROLL_LOCK => KeyCode::ScrollLock,
sapp::sapp_keycode_SAPP_KEYCODE_NUM_LOCK => KeyCode::NumLock,
sapp::sapp_keycode_SAPP_KEYCODE_PRINT_SCREEN => KeyCode::PrintScreen,
sapp::sapp_keycode_SAPP_KEYCODE_PAUSE => KeyCode::Pause,
sapp::sapp_keycode_SAPP_KEYCODE_F1 => KeyCode::F1,
sapp::sapp_keycode_SAPP_KEYCODE_F2 => KeyCode::F2,
sapp::sapp_keycode_SAPP_KEYCODE_F3 => KeyCode::F3,
sapp::sapp_keycode_SAPP_KEYCODE_F4 => KeyCode::F4,
sapp::sapp_keycode_SAPP_KEYCODE_F5 => KeyCode::F5,
sapp::sapp_keycode_SAPP_KEYCODE_F6 => KeyCode::F6,
sapp::sapp_keycode_SAPP_KEYCODE_F7 => KeyCode::F7,
sapp::sapp_keycode_SAPP_KEYCODE_F8 => KeyCode::F8,
sapp::sapp_keycode_SAPP_KEYCODE_F9 => KeyCode::F9,
sapp::sapp_keycode_SAPP_KEYCODE_F10 => KeyCode::F10,
sapp::sapp_keycode_SAPP_KEYCODE_F11 => KeyCode::F11,
sapp::sapp_keycode_SAPP_KEYCODE_F12 => KeyCode::F12,
sapp::sapp_keycode_SAPP_KEYCODE_F13 => KeyCode::F13,
sapp::sapp_keycode_SAPP_KEYCODE_F14 => KeyCode::F14,
sapp::sapp_keycode_SAPP_KEYCODE_F15 => KeyCode::F15,
sapp::sapp_keycode_SAPP_KEYCODE_F16 => KeyCode::F16,
sapp::sapp_keycode_SAPP_KEYCODE_F17 => KeyCode::F17,
sapp::sapp_keycode_SAPP_KEYCODE_F18 => KeyCode::F18,
sapp::sapp_keycode_SAPP_KEYCODE_F19 => KeyCode::F19,
sapp::sapp_keycode_SAPP_KEYCODE_F20 => KeyCode::F20,
sapp::sapp_keycode_SAPP_KEYCODE_F21 => KeyCode::F21,
sapp::sapp_keycode_SAPP_KEYCODE_F22 => KeyCode::F22,
sapp::sapp_keycode_SAPP_KEYCODE_F23 => KeyCode::F23,
sapp::sapp_keycode_SAPP_KEYCODE_F24 => KeyCode::F24,
sapp::sapp_keycode_SAPP_KEYCODE_F25 => KeyCode::F25,
sapp::sapp_keycode_SAPP_KEYCODE_KP_0 => KeyCode::Kp0,
sapp::sapp_keycode_SAPP_KEYCODE_KP_1 => KeyCode::Kp1,
sapp::sapp_keycode_SAPP_KEYCODE_KP_2 => KeyCode::Kp2,
sapp::sapp_keycode_SAPP_KEYCODE_KP_3 => KeyCode::Kp3,
sapp::sapp_keycode_SAPP_KEYCODE_KP_4 => KeyCode::Kp4,
sapp::sapp_keycode_SAPP_KEYCODE_KP_5 => KeyCode::Kp5,
sapp::sapp_keycode_SAPP_KEYCODE_KP_6 => KeyCode::Kp6,
sapp::sapp_keycode_SAPP_KEYCODE_KP_7 => KeyCode::Kp7,
sapp::sapp_keycode_SAPP_KEYCODE_KP_8 => KeyCode::Kp8,
sapp::sapp_keycode_SAPP_KEYCODE_KP_9 => KeyCode::Kp9,
sapp::sapp_keycode_SAPP_KEYCODE_KP_DECIMAL => KeyCode::KpDecimal,
sapp::sapp_keycode_SAPP_KEYCODE_KP_DIVIDE => KeyCode::KpDivide,
sapp::sapp_keycode_SAPP_KEYCODE_KP_MULTIPLY => KeyCode::KpMultiply,
sapp::sapp_keycode_SAPP_KEYCODE_KP_SUBTRACT => KeyCode::KpSubtract,
sapp::sapp_keycode_SAPP_KEYCODE_KP_ADD => KeyCode::KpAdd,
sapp::sapp_keycode_SAPP_KEYCODE_KP_ENTER => KeyCode::KpEnter,
sapp::sapp_keycode_SAPP_KEYCODE_KP_EQUAL => KeyCode::KpEqual,
sapp::sapp_keycode_SAPP_KEYCODE_LEFT_SHIFT => KeyCode::LeftShift,
sapp::sapp_keycode_SAPP_KEYCODE_LEFT_CONTROL => KeyCode::LeftControl,
sapp::sapp_keycode_SAPP_KEYCODE_LEFT_ALT => KeyCode::LeftAlt,
sapp::sapp_keycode_SAPP_KEYCODE_LEFT_SUPER => KeyCode::LeftSuper,
sapp::sapp_keycode_SAPP_KEYCODE_RIGHT_SHIFT => KeyCode::RightShift,
sapp::sapp_keycode_SAPP_KEYCODE_RIGHT_CONTROL => KeyCode::RightControl,
sapp::sapp_keycode_SAPP_KEYCODE_RIGHT_ALT => KeyCode::RightAlt,
sapp::sapp_keycode_SAPP_KEYCODE_RIGHT_SUPER => KeyCode::RightSuper,
sapp::sapp_keycode_SAPP_KEYCODE_MENU => KeyCode::Menu,
_ => KeyCode::Unknown,
}
}
}
pub struct KeyMods {
pub shift: bool,
pub ctrl: bool,
pub alt: bool,
pub logo: bool,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for KeyMods {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
KeyMods {
shift: ref __self_0_0,
ctrl: ref __self_0_1,
alt: ref __self_0_2,
logo: ref __self_0_3,
} => {
let mut debug_trait_builder = f.debug_struct("KeyMods");
let _ = debug_trait_builder.field("shift", &&(*__self_0_0));
let _ = debug_trait_builder.field("ctrl", &&(*__self_0_1));
let _ = debug_trait_builder.field("alt", &&(*__self_0_2));
let _ = debug_trait_builder.field("logo", &&(*__self_0_3));
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for KeyMods {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for KeyMods {
#[inline]
fn clone(&self) -> KeyMods {
{
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<bool>;
*self
}
}
}
impl ::core::marker::StructuralPartialEq for KeyMods {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for KeyMods {
#[inline]
fn eq(&self, other: &KeyMods) -> bool {
match *other {
KeyMods {
shift: ref __self_1_0,
ctrl: ref __self_1_1,
alt: ref __self_1_2,
logo: ref __self_1_3,
} => match *self {
KeyMods {
shift: ref __self_0_0,
ctrl: ref __self_0_1,
alt: ref __self_0_2,
logo: ref __self_0_3,
} => {
(*__self_0_0) == (*__self_1_0)
&& (*__self_0_1) == (*__self_1_1)
&& (*__self_0_2) == (*__self_1_2)
&& (*__self_0_3) == (*__self_1_3)
}
},
}
}
#[inline]
fn ne(&self, other: &KeyMods) -> bool {
match *other {
KeyMods {
shift: ref __self_1_0,
ctrl: ref __self_1_1,
alt: ref __self_1_2,
logo: ref __self_1_3,
} => match *self {
KeyMods {
shift: ref __self_0_0,
ctrl: ref __self_0_1,
alt: ref __self_0_2,
logo: ref __self_0_3,
} => {
(*__self_0_0) != (*__self_1_0)
|| (*__self_0_1) != (*__self_1_1)
|| (*__self_0_2) != (*__self_1_2)
|| (*__self_0_3) != (*__self_1_3)
}
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::default::Default for KeyMods {
#[inline]
fn default() -> KeyMods {
KeyMods {
shift: ::core::default::Default::default(),
ctrl: ::core::default::Default::default(),
alt: ::core::default::Default::default(),
logo: ::core::default::Default::default(),
}
}
}
impl From<u32> for KeyMods {
fn from(value: u32) -> KeyMods {
let mut key_mods = KeyMods::default();
if value & sapp::SAPP_MODIFIER_SHIFT != 0 {
key_mods.shift = true;
}
if value & sapp::SAPP_MODIFIER_CTRL != 0 {
key_mods.ctrl = true;
}
if value & sapp::SAPP_MODIFIER_ALT != 0 {
key_mods.alt = true;
}
if value & sapp::SAPP_MODIFIER_SUPER != 0 {
key_mods.logo = true;
}
key_mods
}
}
pub enum TouchPhase {
Started,
Moved,
Ended,
Cancelled,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for TouchPhase {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&TouchPhase::Started,) => {
let mut debug_trait_builder = f.debug_tuple("Started");
debug_trait_builder.finish()
}
(&TouchPhase::Moved,) => {
let mut debug_trait_builder = f.debug_tuple("Moved");
debug_trait_builder.finish()
}
(&TouchPhase::Ended,) => {
let mut debug_trait_builder = f.debug_tuple("Ended");
debug_trait_builder.finish()
}
(&TouchPhase::Cancelled,) => {
let mut debug_trait_builder = f.debug_tuple("Cancelled");
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::hash::Hash for TouchPhase {
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
match (&*self,) {
_ => ::core::hash::Hash::hash(
&unsafe { ::core::intrinsics::discriminant_value(self) },
state,
),
}
}
}
impl ::core::marker::StructuralPartialEq for TouchPhase {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for TouchPhase {
#[inline]
fn eq(&self, other: &TouchPhase) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for TouchPhase {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for TouchPhase {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for TouchPhase {
#[inline]
fn clone(&self) -> TouchPhase {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for TouchPhase {}
impl From<u32> for TouchPhase {
fn from(event: u32) -> TouchPhase {
match event {
sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_BEGAN => TouchPhase::Started,
sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_ENDED => TouchPhase::Ended,
sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_CANCELLED => TouchPhase::Cancelled,
sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_MOVED => TouchPhase::Moved,
_ => ::std::rt::begin_panic("internal error: entered unreachable code"),
}
}
}
pub trait EventHandler {
fn update(&mut self, _ctx: &mut Context);
fn draw(&mut self, _ctx: &mut Context);
fn resize_event(&mut self, _ctx: &mut Context, _width: f32, _height: f32) {}
fn mouse_motion_event(&mut self, _ctx: &mut Context, _x: f32, _y: f32) {}
fn mouse_wheel_event(&mut self, _ctx: &mut Context, _x: f32, _y: f32) {}
fn mouse_button_down_event(
&mut self,
_ctx: &mut Context,
_button: MouseButton,
_x: f32,
_y: f32,
) {
}
fn mouse_button_up_event(
&mut self,
_ctx: &mut Context,
_button: MouseButton,
_x: f32,
_y: f32,
) {
}
fn char_event(
&mut self,
_ctx: &mut Context,
_character: char,
_keymods: KeyMods,
_repeat: bool,
) {
}
fn key_down_event(
&mut self,
_ctx: &mut Context,
_keycode: KeyCode,
_keymods: KeyMods,
_repeat: bool,
) {
}
fn key_up_event(&mut self, _ctx: &mut Context, _keycode: KeyCode, _keymods: KeyMods) {}
fn touch_event(&mut self, ctx: &mut Context, phase: TouchPhase, _id: u64, x: f32, y: f32) {
if phase == TouchPhase::Started {
self.mouse_button_down_event(ctx, MouseButton::Left, x, y);
}
if phase == TouchPhase::Ended {
self.mouse_button_up_event(ctx, MouseButton::Left, x, y);
}
}
fn raw_mouse_motion(&mut self, _ctx: &mut Context, _dx: f32, _dy: f32) {}
fn quit_requested_event(&mut self, _ctx: &mut Context) {}
}
pub trait EventHandlerFree {
fn update(&mut self);
fn draw(&mut self);
fn resize_event(&mut self, _width: f32, _height: f32) {}
fn mouse_motion_event(&mut self, _x: f32, _y: f32) {}
fn mouse_wheel_event(&mut self, _x: f32, _y: f32) {}
fn mouse_button_down_event(&mut self, _button: MouseButton, _x: f32, _y: f32) {}
fn mouse_button_up_event(&mut self, _button: MouseButton, _x: f32, _y: f32) {}
fn char_event(&mut self, _character: char, _keymods: KeyMods, _repeat: bool) {}
fn key_down_event(&mut self, _keycode: KeyCode, _keymods: KeyMods, _repeat: bool) {}
fn key_up_event(&mut self, _keycode: KeyCode, _keymods: KeyMods) {}
fn touch_event(&mut self, phase: TouchPhase, _id: u64, x: f32, y: f32) {
if phase == TouchPhase::Started {
self.mouse_button_down_event(MouseButton::Left, x, y);
}
if phase == TouchPhase::Ended {
self.mouse_button_up_event(MouseButton::Left, x, y);
}
}
fn raw_mouse_motion(&mut self, _dx: f32, _dy: f32) {}
fn quit_requested_event(&mut self) {}
}
}
pub mod fs {
pub enum Error {
IOError(std::io::Error),
DownloadFailed,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Error {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&Error::IOError(ref __self_0),) => {
let mut debug_trait_builder = f.debug_tuple("IOError");
let _ = debug_trait_builder.field(&&(*__self_0));
debug_trait_builder.finish()
}
(&Error::DownloadFailed,) => {
let mut debug_trait_builder = f.debug_tuple("DownloadFailed");
debug_trait_builder.finish()
}
}
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match *self {
_ => f.write_fmt(::core::fmt::Arguments::new_v1(
&["Error: "],
&match (&self,) {
(arg0,) => [::core::fmt::ArgumentV1::new(arg0, ::core::fmt::Debug::fmt)],
},
)),
}
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Error {
Error::IOError(e)
}
}
pub type Response = Result<Vec<u8>, Error>;
pub fn load_file<F: Fn(Response) + 'static>(path: &str, on_loaded: F) {
#[cfg(not(target_arch = "wasm32"))]
load_file_desktop(path, on_loaded);
}
#[cfg(not(target_arch = "wasm32"))]
fn load_file_desktop<F: Fn(Response)>(path: &str, on_loaded: F) {
fn load_file_sync(path: &str) -> Response {
use std::fs::File;
use std::io::Read;
let mut response = <[_]>::into_vec(box []);
let mut file = File::open(path)?;
file.read_to_end(&mut response)?;
Ok(response)
}
let response = load_file_sync(path);
on_loaded(response);
}
}
pub mod graphics {
use std::{ffi::CString, mem};
mod texture {
use crate::{sapp::*, Context};
pub struct Texture {
pub(crate) texture: GLuint,
pub width: u32,
pub height: u32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Texture {
#[inline]
fn clone(&self) -> Texture {
{
let _: ::core::clone::AssertParamIsClone<GLuint>;
let _: ::core::clone::AssertParamIsClone<u32>;
let _: ::core::clone::AssertParamIsClone<u32>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Texture {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Texture {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
Texture {
texture: ref __self_0_0,
width: ref __self_0_1,
height: ref __self_0_2,
} => {
let mut debug_trait_builder = f.debug_struct("Texture");
let _ = debug_trait_builder.field("texture", &&(*__self_0_0));
let _ = debug_trait_builder.field("width", &&(*__self_0_1));
let _ = debug_trait_builder.field("height", &&(*__self_0_2));
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for Texture {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for Texture {
#[inline]
fn eq(&self, other: &Texture) -> bool {
match *other {
Texture {
texture: ref __self_1_0,
width: ref __self_1_1,
height: ref __self_1_2,
} => match *self {
Texture {
texture: ref __self_0_0,
width: ref __self_0_1,
height: ref __self_0_2,
} => {
(*__self_0_0) == (*__self_1_0)
&& (*__self_0_1) == (*__self_1_1)
&& (*__self_0_2) == (*__self_1_2)
}
},
}
}
#[inline]
fn ne(&self, other: &Texture) -> bool {
match *other {
Texture {
texture: ref __self_1_0,
width: ref __self_1_1,
height: ref __self_1_2,
} => match *self {
Texture {
texture: ref __self_0_0,
width: ref __self_0_1,
height: ref __self_0_2,
} => {
(*__self_0_0) != (*__self_1_0)
|| (*__self_0_1) != (*__self_1_1)
|| (*__self_0_2) != (*__self_1_2)
}
},
}
}
}
impl Texture {
pub fn empty() -> Texture {
Texture {
texture: 0,
width: 0,
height: 0,
}
}
fn delete(&self) {
let res = {
{
unsafe {
glDeleteTextures(1, &self.texture as *const _);
}
}
};
res
}
}
pub enum RenderTextureFormat {
RGBA8,
Depth,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for RenderTextureFormat {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&RenderTextureFormat::RGBA8,) => {
let mut debug_trait_builder = f.debug_tuple("RGBA8");
debug_trait_builder.finish()
}
(&RenderTextureFormat::Depth,) => {
let mut debug_trait_builder = f.debug_tuple("Depth");
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for RenderTextureFormat {
#[inline]
fn clone(&self) -> RenderTextureFormat {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for RenderTextureFormat {}
impl ::core::marker::StructuralPartialEq for RenderTextureFormat {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for RenderTextureFormat {
#[inline]
fn eq(&self, other: &RenderTextureFormat) -> bool {
{
let __self_vi =
unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl From<RenderTextureFormat> for (GLenum, GLenum, GLenum) {
fn from(format: RenderTextureFormat) -> Self {
match format {
RenderTextureFormat::RGBA8 => (GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE),
RenderTextureFormat::Depth => {
(GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT)
}
}
}
}
#[repr(u8)]
pub enum TextureFormat {
RGB8,
RGBA8,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for TextureFormat {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&TextureFormat::RGB8,) => {
let mut debug_trait_builder = f.debug_tuple("RGB8");
debug_trait_builder.finish()
}
(&TextureFormat::RGBA8,) => {
let mut debug_trait_builder = f.debug_tuple("RGBA8");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for TextureFormat {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for TextureFormat {
#[inline]
fn eq(&self, other: &TextureFormat) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as u8;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as u8;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for TextureFormat {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for TextureFormat {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for TextureFormat {
#[inline]
fn clone(&self) -> TextureFormat {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for TextureFormat {}
impl From<TextureFormat> for (GLenum, GLenum, GLenum) {
fn from(format: TextureFormat) -> Self {
match format {
TextureFormat::RGB8 => (GL_RGB, GL_RGB, GL_UNSIGNED_BYTE),
TextureFormat::RGBA8 => (GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE),
}
}
}
impl TextureFormat {
pub fn size(self, width: u32, height: u32) -> u32 {
let square = width * height;
match self {
TextureFormat::RGB8 => 3 * square,
TextureFormat::RGBA8 => 4 * square,
}
}
}
impl Default for TextureParams {
fn default() -> Self {
TextureParams {
format: TextureFormat::RGBA8,
wrap: TextureWrap::Clamp,
filter: FilterMode::Linear,
width: 0,
height: 0,
}
}
}
#[repr(u8)]
pub enum TextureWrap {
Repeat,
Mirror,
Clamp,
MirrorClamp,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for TextureWrap {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&TextureWrap::Repeat,) => {
let mut debug_trait_builder = f.debug_tuple("Repeat");
debug_trait_builder.finish()
}
(&TextureWrap::Mirror,) => {
let mut debug_trait_builder = f.debug_tuple("Mirror");
debug_trait_builder.finish()
}
(&TextureWrap::Clamp,) => {
let mut debug_trait_builder = f.debug_tuple("Clamp");
debug_trait_builder.finish()
}
(&TextureWrap::MirrorClamp,) => {
let mut debug_trait_builder = f.debug_tuple("MirrorClamp");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for TextureWrap {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for TextureWrap {
#[inline]
fn eq(&self, other: &TextureWrap) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as u8;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as u8;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for TextureWrap {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for TextureWrap {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for TextureWrap {
#[inline]
fn clone(&self) -> TextureWrap {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for TextureWrap {}
pub enum FilterMode {
Linear = GL_LINEAR as isize,
Nearest = GL_NEAREST as isize,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for FilterMode {
#[inline]
fn clone(&self) -> FilterMode {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for FilterMode {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for FilterMode {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&FilterMode::Linear,) => {
let mut debug_trait_builder = f.debug_tuple("Linear");
debug_trait_builder.finish()
}
(&FilterMode::Nearest,) => {
let mut debug_trait_builder = f.debug_tuple("Nearest");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for FilterMode {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for FilterMode {
#[inline]
fn eq(&self, other: &FilterMode) -> bool {
{
let __self_vi =
unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
pub struct TextureParams {
pub format: TextureFormat,
pub wrap: TextureWrap,
pub filter: FilterMode,
pub width: u32,
pub height: u32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for TextureParams {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
TextureParams {
format: ref __self_0_0,
wrap: ref __self_0_1,
filter: ref __self_0_2,
width: ref __self_0_3,
height: ref __self_0_4,
} => {
let mut debug_trait_builder = f.debug_struct("TextureParams");
let _ = debug_trait_builder.field("format", &&(*__self_0_0));
let _ = debug_trait_builder.field("wrap", &&(*__self_0_1));
let _ = debug_trait_builder.field("filter", &&(*__self_0_2));
let _ = debug_trait_builder.field("width", &&(*__self_0_3));
let _ = debug_trait_builder.field("height", &&(*__self_0_4));
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for TextureParams {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for TextureParams {
#[inline]
fn clone(&self) -> TextureParams {
{
let _: ::core::clone::AssertParamIsClone<TextureFormat>;
let _: ::core::clone::AssertParamIsClone<TextureWrap>;
let _: ::core::clone::AssertParamIsClone<FilterMode>;
let _: ::core::clone::AssertParamIsClone<u32>;
let _: ::core::clone::AssertParamIsClone<u32>;
*self
}
}
}
pub struct RenderTextureParams {
pub format: RenderTextureFormat,
pub wrap: TextureWrap,
pub filter: FilterMode,
pub width: u32,
pub height: u32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for RenderTextureParams {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
RenderTextureParams {
format: ref __self_0_0,
wrap: ref __self_0_1,
filter: ref __self_0_2,
width: ref __self_0_3,
height: ref __self_0_4,
} => {
let mut debug_trait_builder = f.debug_struct("RenderTextureParams");
let _ = debug_trait_builder.field("format", &&(*__self_0_0));
let _ = debug_trait_builder.field("wrap", &&(*__self_0_1));
let _ = debug_trait_builder.field("filter", &&(*__self_0_2));
let _ = debug_trait_builder.field("width", &&(*__self_0_3));
let _ = debug_trait_builder.field("height", &&(*__self_0_4));
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for RenderTextureParams {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for RenderTextureParams {
#[inline]
fn clone(&self) -> RenderTextureParams {
{
let _: ::core::clone::AssertParamIsClone<RenderTextureFormat>;
let _: ::core::clone::AssertParamIsClone<TextureWrap>;
let _: ::core::clone::AssertParamIsClone<FilterMode>;
let _: ::core::clone::AssertParamIsClone<u32>;
let _: ::core::clone::AssertParamIsClone<u32>;
*self
}
}
}
impl Default for RenderTextureParams {
fn default() -> Self {
RenderTextureParams {
format: RenderTextureFormat::RGBA8,
wrap: TextureWrap::Clamp,
filter: FilterMode::Linear,
width: 0,
height: 0,
}
}
}
impl Texture {
fn new_render_texture(ctx: &mut Context, params: RenderTextureParams) {
let res = {
()
};
res
}
fn from_data_and_format(ctx: &mut Context, bytes: &[u8], params: TextureParams) {
let res = {
()
};
res
}
pub fn from_rgba8(ctx: &mut Context, width: u16, height: u16, bytes: &[u8]) -> Texture {
{
match (&(width as usize * height as usize * 4), &bytes.len()) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
{
::std::rt::begin_panic_fmt(&::core::fmt::Arguments::new_v1(
&[
"assertion failed: `(left == right)`\n left: `",
"`,\n right: `",
"`",
],
&match (&&*left_val, &&*right_val) {
(arg0, arg1) => [
::core::fmt::ArgumentV1::new(
arg0,
::core::fmt::Debug::fmt,
),
::core::fmt::ArgumentV1::new(
arg1,
::core::fmt::Debug::fmt,
),
],
},
))
}
}
}
}
};
Self::from_data_and_format(
ctx,
bytes,
TextureParams {
width: width as _,
height: height as _,
format: TextureFormat::RGBA8,
wrap: TextureWrap::Clamp,
filter: FilterMode::Linear,
},
)
}
fn set_filter(&self, ctx: &mut Context, filter: FilterMode) {
let res = {
{
ctx.cache.store_texture_binding(0);
ctx.cache.bind_texture(0, self.texture);
unsafe {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter as i32);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter as i32);
}
ctx.cache.restore_texture_binding(0);
}
};
res
}
pub fn update(&self, ctx: &mut Context, bytes: &[u8]) {
{
match (
&(self.width as usize * self.height as usize * 4),
&bytes.len(),
) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
{
::std::rt::begin_panic_fmt(&::core::fmt::Arguments::new_v1(
&[
"assertion failed: `(left == right)`\n left: `",
"`,\n right: `",
"`",
],
&match (&&*left_val, &&*right_val) {
(arg0, arg1) => [
::core::fmt::ArgumentV1::new(
arg0,
::core::fmt::Debug::fmt,
),
::core::fmt::ArgumentV1::new(
arg1,
::core::fmt::Debug::fmt,
),
],
},
))
}
}
}
}
};
self.update_texture_part(
ctx,
0 as _,
0 as _,
self.width as _,
self.height as _,
bytes,
)
}
fn update_texture_part(
&self,
ctx: &mut Context,
x_offset: i32,
y_offset: i32,
width: i32,
height: i32,
bytes: &[u8],
) {
let res = {
{
{
match (&(width as usize * height as usize * 4), &bytes.len()) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
{
::std::rt::begin_panic_fmt(&::core::fmt::Arguments::new_v1(&["assertion failed: `(left == right)`\n left: `",
"`,\n right: `",
"`"],
&match (&&*left_val,
&&*right_val)
{
(arg0,
arg1)
=>
[::core::fmt::ArgumentV1::new(arg0,
::core::fmt::Debug::fmt),
::core::fmt::ArgumentV1::new(arg1,
::core::fmt::Debug::fmt)],
}))
}
}
}
}
};
if !(x_offset + width <= self.width as _) {
{
::std::rt::begin_panic(
"assertion failed: x_offset + width <= self.width as _",
)
}
};
if !(y_offset + height <= self.height as _) {
{
::std::rt::begin_panic(
"assertion failed: y_offset + height <= self.height as _",
)
}
};
ctx.cache.store_texture_binding(0);
ctx.cache.bind_texture(0, self.texture);
unsafe {
glTexSubImage2D(
GL_TEXTURE_2D,
0,
x_offset as _,
y_offset as _,
width as _,
height as _,
GL_RGBA,
GL_UNSIGNED_BYTE,
bytes.as_ptr() as *const _,
);
}
ctx.cache.restore_texture_binding(0);
}
};
res
}
}
}
use crate::sapp::*;
use std::option::Option::None;
pub use texture::{
FilterMode, RenderTextureFormat, RenderTextureParams, Texture, TextureFormat, TextureParams,
};
fn get_uniform_location(program: GLuint, name: &str) -> i32 {
let cname = CString::new(name).unwrap_or_else(|e| ::std::rt::begin_panic(e));
let location = unsafe { glGetUniformLocation(program, cname.as_ptr()) };
if !(location != -1) {
{
::std::rt::begin_panic({
let res = ::alloc::fmt::format(::core::fmt::Arguments::new_v1(
&["Cant get \"", "\" uniform location"],
&match (&name,) {
(arg0,) => [::core::fmt::ArgumentV1::new(
arg0,
::core::fmt::Display::fmt,
)],
},
));
res
})
}
};
location
}
pub enum UniformType {
Float1,
Float2,
Float3,
Float4,
Mat4,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for UniformType {
#[inline]
fn clone(&self) -> UniformType {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for UniformType {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for UniformType {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&UniformType::Float1,) => {
let mut debug_trait_builder = f.debug_tuple("Float1");
debug_trait_builder.finish()
}
(&UniformType::Float2,) => {
let mut debug_trait_builder = f.debug_tuple("Float2");
debug_trait_builder.finish()
}
(&UniformType::Float3,) => {
let mut debug_trait_builder = f.debug_tuple("Float3");
debug_trait_builder.finish()
}
(&UniformType::Float4,) => {
let mut debug_trait_builder = f.debug_tuple("Float4");
debug_trait_builder.finish()
}
(&UniformType::Mat4,) => {
let mut debug_trait_builder = f.debug_tuple("Mat4");
debug_trait_builder.finish()
}
}
}
}
impl UniformType {
fn size(&self, count: usize) -> usize {
match self {
UniformType::Float1 => 4 * count,
UniformType::Float2 => 8 * count,
UniformType::Float3 => 12 * count,
UniformType::Float4 => 16 * count,
UniformType::Mat4 => 64 * count,
}
}
}
pub struct UniformBlockLayout {
pub uniforms: &'static [(&'static str, UniformType)],
}
pub struct ShaderMeta {
pub uniforms: UniformBlockLayout,
pub images: &'static [&'static str],
}
pub enum VertexFormat {
Float1,
Float2,
Float3,
Float4,
Byte1,
Byte2,
Byte3,
Byte4,
Short1,
Short2,
Short3,
Short4,
Mat4,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for VertexFormat {
#[inline]
fn clone(&self) -> VertexFormat {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for VertexFormat {}
impl ::core::marker::StructuralPartialEq for VertexFormat {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for VertexFormat {
#[inline]
fn eq(&self, other: &VertexFormat) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for VertexFormat {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&VertexFormat::Float1,) => {
let mut debug_trait_builder = f.debug_tuple("Float1");
debug_trait_builder.finish()
}
(&VertexFormat::Float2,) => {
let mut debug_trait_builder = f.debug_tuple("Float2");
debug_trait_builder.finish()
}
(&VertexFormat::Float3,) => {
let mut debug_trait_builder = f.debug_tuple("Float3");
debug_trait_builder.finish()
}
(&VertexFormat::Float4,) => {
let mut debug_trait_builder = f.debug_tuple("Float4");
debug_trait_builder.finish()
}
(&VertexFormat::Byte1,) => {
let mut debug_trait_builder = f.debug_tuple("Byte1");
debug_trait_builder.finish()
}
(&VertexFormat::Byte2,) => {
let mut debug_trait_builder = f.debug_tuple("Byte2");
debug_trait_builder.finish()
}
(&VertexFormat::Byte3,) => {
let mut debug_trait_builder = f.debug_tuple("Byte3");
debug_trait_builder.finish()
}
(&VertexFormat::Byte4,) => {
let mut debug_trait_builder = f.debug_tuple("Byte4");
debug_trait_builder.finish()
}
(&VertexFormat::Short1,) => {
let mut debug_trait_builder = f.debug_tuple("Short1");
debug_trait_builder.finish()
}
(&VertexFormat::Short2,) => {
let mut debug_trait_builder = f.debug_tuple("Short2");
debug_trait_builder.finish()
}
(&VertexFormat::Short3,) => {
let mut debug_trait_builder = f.debug_tuple("Short3");
debug_trait_builder.finish()
}
(&VertexFormat::Short4,) => {
let mut debug_trait_builder = f.debug_tuple("Short4");
debug_trait_builder.finish()
}
(&VertexFormat::Mat4,) => {
let mut debug_trait_builder = f.debug_tuple("Mat4");
debug_trait_builder.finish()
}
}
}
}
impl VertexFormat {
pub fn size(&self) -> i32 {
match self {
VertexFormat::Float1 => 1,
VertexFormat::Float2 => 2,
VertexFormat::Float3 => 3,
VertexFormat::Float4 => 4,
VertexFormat::Byte1 => 1,
VertexFormat::Byte2 => 2,
VertexFormat::Byte3 => 3,
VertexFormat::Byte4 => 4,
VertexFormat::Short1 => 1,
VertexFormat::Short2 => 2,
VertexFormat::Short3 => 3,
VertexFormat::Short4 => 4,
VertexFormat::Mat4 => 16,
}
}
pub fn byte_len(&self) -> i32 {
match self {
VertexFormat::Float1 => 1 * 4,
VertexFormat::Float2 => 2 * 4,
VertexFormat::Float3 => 3 * 4,
VertexFormat::Float4 => 4 * 4,
VertexFormat::Byte1 => 1,
VertexFormat::Byte2 => 2,
VertexFormat::Byte3 => 3,
VertexFormat::Byte4 => 4,
VertexFormat::Short1 => 1 * 2,
VertexFormat::Short2 => 2 * 2,
VertexFormat::Short3 => 3 * 2,
VertexFormat::Short4 => 4 * 2,
VertexFormat::Mat4 => 16 * 4,
}
}
fn type_(&self) -> GLuint {
match self {
VertexFormat::Float1 => GL_FLOAT,
VertexFormat::Float2 => GL_FLOAT,
VertexFormat::Float3 => GL_FLOAT,
VertexFormat::Float4 => GL_FLOAT,
VertexFormat::Byte1 => GL_UNSIGNED_BYTE,
VertexFormat::Byte2 => GL_UNSIGNED_BYTE,
VertexFormat::Byte3 => GL_UNSIGNED_BYTE,
VertexFormat::Byte4 => GL_UNSIGNED_BYTE,
VertexFormat::Short1 => GL_UNSIGNED_SHORT,
VertexFormat::Short2 => GL_UNSIGNED_SHORT,
VertexFormat::Short3 => GL_UNSIGNED_SHORT,
VertexFormat::Short4 => GL_UNSIGNED_SHORT,
VertexFormat::Mat4 => GL_FLOAT,
}
}
}
pub enum VertexStep {
PerVertex,
PerInstance,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for VertexStep {
#[inline]
fn clone(&self) -> VertexStep {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for VertexStep {}
impl ::core::marker::StructuralPartialEq for VertexStep {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for VertexStep {
#[inline]
fn eq(&self, other: &VertexStep) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for VertexStep {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&VertexStep::PerVertex,) => {
let mut debug_trait_builder = f.debug_tuple("PerVertex");
debug_trait_builder.finish()
}
(&VertexStep::PerInstance,) => {
let mut debug_trait_builder = f.debug_tuple("PerInstance");
debug_trait_builder.finish()
}
}
}
}
impl Default for VertexStep {
fn default() -> VertexStep {
VertexStep::PerVertex
}
}
pub struct BufferLayout {
pub stride: i32,
pub step_func: VertexStep,
pub step_rate: i32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for BufferLayout {
#[inline]
fn clone(&self) -> BufferLayout {
match *self {
BufferLayout {
stride: ref __self_0_0,
step_func: ref __self_0_1,
step_rate: ref __self_0_2,
} => BufferLayout {
stride: ::core::clone::Clone::clone(&(*__self_0_0)),
step_func: ::core::clone::Clone::clone(&(*__self_0_1)),
step_rate: ::core::clone::Clone::clone(&(*__self_0_2)),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for BufferLayout {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
BufferLayout {
stride: ref __self_0_0,
step_func: ref __self_0_1,
step_rate: ref __self_0_2,
} => {
let mut debug_trait_builder = f.debug_struct("BufferLayout");
let _ = debug_trait_builder.field("stride", &&(*__self_0_0));
let _ = debug_trait_builder.field("step_func", &&(*__self_0_1));
let _ = debug_trait_builder.field("step_rate", &&(*__self_0_2));
debug_trait_builder.finish()
}
}
}
}
impl Default for BufferLayout {
fn default() -> BufferLayout {
BufferLayout {
stride: 0,
step_func: VertexStep::PerVertex,
step_rate: 1,
}
}
}
pub struct VertexAttribute {
pub name: &'static str,
pub format: VertexFormat,
pub buffer_index: usize,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for VertexAttribute {
#[inline]
fn clone(&self) -> VertexAttribute {
match *self {
VertexAttribute {
name: ref __self_0_0,
format: ref __self_0_1,
buffer_index: ref __self_0_2,
} => VertexAttribute {
name: ::core::clone::Clone::clone(&(*__self_0_0)),
format: ::core::clone::Clone::clone(&(*__self_0_1)),
buffer_index: ::core::clone::Clone::clone(&(*__self_0_2)),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for VertexAttribute {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
VertexAttribute {
name: ref __self_0_0,
format: ref __self_0_1,
buffer_index: ref __self_0_2,
} => {
let mut debug_trait_builder = f.debug_struct("VertexAttribute");
let _ = debug_trait_builder.field("name", &&(*__self_0_0));
let _ = debug_trait_builder.field("format", &&(*__self_0_1));
let _ = debug_trait_builder.field("buffer_index", &&(*__self_0_2));
debug_trait_builder.finish()
}
}
}
}
impl VertexAttribute {
pub fn new(name: &'static str, format: VertexFormat) -> VertexAttribute {
Self::with_buffer(name, format, 0)
}
pub fn with_buffer(
name: &'static str,
format: VertexFormat,
buffer_index: usize,
) -> VertexAttribute {
VertexAttribute {
name,
format,
buffer_index,
}
}
}
pub struct PipelineLayout {
pub buffers: &'static [BufferLayout],
pub attributes: &'static [VertexAttribute],
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for PipelineLayout {
#[inline]
fn clone(&self) -> PipelineLayout {
match *self {
PipelineLayout {
buffers: ref __self_0_0,
attributes: ref __self_0_1,
} => PipelineLayout {
buffers: ::core::clone::Clone::clone(&(*__self_0_0)),
attributes: ::core::clone::Clone::clone(&(*__self_0_1)),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for PipelineLayout {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
PipelineLayout {
buffers: ref __self_0_0,
attributes: ref __self_0_1,
} => {
let mut debug_trait_builder = f.debug_struct("PipelineLayout");
let _ = debug_trait_builder.field("buffers", &&(*__self_0_0));
let _ = debug_trait_builder.field("attributes", &&(*__self_0_1));
debug_trait_builder.finish()
}
}
}
}
pub struct Shader(usize);
impl Shader {
pub fn new(
ctx: &mut Context,
vertex_shader: &str,
fragment_shader: &str,
meta: ShaderMeta,
) -> Shader {
let shader = load_shader_internal(vertex_shader, fragment_shader, meta);
ctx.shaders.push(shader);
Shader(ctx.shaders.len() - 1)
}
}
pub struct ShaderImage {
gl_loc: GLint,
}
pub struct ShaderUniform {
gl_loc: GLint,
offset: usize,
size: usize,
uniform_type: UniformType,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for ShaderUniform {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
ShaderUniform {
gl_loc: ref __self_0_0,
offset: ref __self_0_1,
size: ref __self_0_2,
uniform_type: ref __self_0_3,
} => {
let mut debug_trait_builder = f.debug_struct("ShaderUniform");
let _ = debug_trait_builder.field("gl_loc", &&(*__self_0_0));
let _ = debug_trait_builder.field("offset", &&(*__self_0_1));
let _ = debug_trait_builder.field("size", &&(*__self_0_2));
let _ = debug_trait_builder.field("uniform_type", &&(*__self_0_3));
debug_trait_builder.finish()
}
}
}
}
struct ShaderInternal {
program: GLuint,
images: Vec<ShaderImage>,
uniforms: Vec<ShaderUniform>,
}
type BlendState = Option<(Equation, BlendFactor, BlendFactor)>;
struct CachedAttribute {
attribute: VertexAttributeInternal,
gl_vbuf: GLuint,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::default::Default for CachedAttribute {
#[inline]
fn default() -> CachedAttribute {
CachedAttribute {
attribute: ::core::default::Default::default(),
gl_vbuf: ::core::default::Default::default(),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for CachedAttribute {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for CachedAttribute {
#[inline]
fn clone(&self) -> CachedAttribute {
{
let _: ::core::clone::AssertParamIsClone<VertexAttributeInternal>;
let _: ::core::clone::AssertParamIsClone<GLuint>;
*self
}
}
}
struct GlCache {
stored_index_buffer: GLuint,
stored_vertex_buffer: GLuint,
stored_texture: GLuint,
index_buffer: GLuint,
vertex_buffer: GLuint,
textures: [GLuint; MAX_SHADERSTAGE_IMAGES],
cur_pipeline: Option<Pipeline>,
blend: BlendState,
attributes: [Option<CachedAttribute>; MAX_VERTEX_ATTRIBUTES],
}
impl GlCache {
fn bind_buffer(&mut self, target: GLenum, buffer: GLuint) {
if target == GL_ARRAY_BUFFER {
if self.vertex_buffer != buffer {
self.vertex_buffer = buffer;
unsafe {
glBindBuffer(target, buffer);
}
}
} else {
if self.index_buffer != buffer {
self.index_buffer = buffer;
unsafe {
glBindBuffer(target, buffer);
}
}
}
}
fn store_buffer_binding(&mut self, target: GLenum) {
if target == GL_ARRAY_BUFFER {
self.stored_vertex_buffer = self.vertex_buffer;
} else {
self.stored_index_buffer = self.index_buffer;
}
}
fn restore_buffer_binding(&mut self, target: GLenum) {
if target == GL_ARRAY_BUFFER {
self.bind_buffer(target, self.stored_vertex_buffer);
} else {
self.bind_buffer(target, self.stored_index_buffer);
}
}
fn bind_texture(&mut self, slot_index: usize, texture: GLuint) {
unsafe {
glActiveTexture(GL_TEXTURE0 + slot_index as GLuint);
if self.textures[slot_index] != texture {
glBindTexture(GL_TEXTURE_2D, texture);
self.textures[slot_index] = texture;
}
}
}
fn store_texture_binding(&mut self, slot_index: usize) {
self.stored_texture = self.textures[slot_index];
}
fn restore_texture_binding(&mut self, slot_index: usize) {
self.bind_texture(slot_index, self.stored_texture);
}
fn clear_buffer_bindings(&mut self) {
self.bind_buffer(GL_ARRAY_BUFFER, 0);
self.vertex_buffer = 0;
self.bind_buffer(GL_ELEMENT_ARRAY_BUFFER, 0);
self.index_buffer = 0;
}
fn clear_texture_bindings(&mut self) {
for ix in 0..MAX_SHADERSTAGE_IMAGES {
if self.textures[ix] != 0 {
self.bind_texture(ix, 0);
self.textures[ix] = 0;
}
}
}
}
pub enum PassAction {
Nothing,
Clear {
color: Option<(f32, f32, f32, f32)>,
depth: Option<f32>,
stencil: Option<i32>,
},
}
impl PassAction {
pub fn clear_color(r: f32, g: f32, b: f32, a: f32) -> PassAction {
PassAction::Clear {
color: Some((r, g, b, a)),
depth: Some(1.),
stencil: None,
}
}
}
impl Default for PassAction {
fn default() -> PassAction {
PassAction::Clear {
color: Some((0.0, 0.0, 0.0, 0.0)),
depth: Some(1.),
stencil: None,
}
}
}
pub struct RenderPass(usize);
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for RenderPass {
#[inline]
fn clone(&self) -> RenderPass {
{
let _: ::core::clone::AssertParamIsClone<usize>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for RenderPass {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for RenderPass {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
RenderPass(ref __self_0_0) => {
let mut debug_trait_builder = f.debug_tuple("RenderPass");
let _ = debug_trait_builder.field(&&(*__self_0_0));
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for RenderPass {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for RenderPass {
#[inline]
fn eq(&self, other: &RenderPass) -> bool {
match *other {
RenderPass(ref __self_1_0) => match *self {
RenderPass(ref __self_0_0) => (*__self_0_0) == (*__self_1_0),
},
}
}
#[inline]
fn ne(&self, other: &RenderPass) -> bool {
match *other {
RenderPass(ref __self_1_0) => match *self {
RenderPass(ref __self_0_0) => (*__self_0_0) != (*__self_1_0),
},
}
}
}
struct RenderPassInternal {
gl_fb: GLuint,
texture: Texture,
}
impl RenderPass {
pub fn new(
context: &mut Context,
color_img: Texture,
depth_img: impl Into<Option<Texture>>,
) -> RenderPass {
let mut gl_fb = 0;
unsafe {
glGenFramebuffers(1, &mut gl_fb as *mut _);
glBindFramebuffer(GL_FRAMEBUFFER, gl_fb);
glFramebufferTexture2D(
GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D,
color_img.texture,
0,
);
if let Some(depth_img) = depth_img.into() {
glFramebufferTexture2D(
GL_FRAMEBUFFER,
GL_DEPTH_ATTACHMENT,
GL_TEXTURE_2D,
depth_img.texture,
0,
);
}
glBindFramebuffer(GL_FRAMEBUFFER, context.default_framebuffer);
}
let pass = RenderPassInternal {
gl_fb,
texture: color_img,
};
context.passes.push(pass);
RenderPass(context.passes.len() - 1)
}
}
pub const MAX_VERTEX_ATTRIBUTES: usize = 16;
pub const MAX_SHADERSTAGE_IMAGES: usize = 12;
pub struct Context {
shaders: Vec<ShaderInternal>,
pipelines: Vec<PipelineInternal>,
passes: Vec<RenderPassInternal>,
default_framebuffer: GLuint,
cache: GlCache,
}
impl Context {
pub fn new() -> Context {
unsafe {
let mut default_framebuffer: GLuint = 0;
glGetIntegerv(
GL_FRAMEBUFFER_BINDING,
&mut default_framebuffer as *mut _ as *mut _,
);
let mut vao = 0;
glGenVertexArrays(1, &mut vao as *mut _);
glBindVertexArray(vao);
Context {
default_framebuffer,
shaders: <[_]>::into_vec(box []),
pipelines: <[_]>::into_vec(box []),
passes: <[_]>::into_vec(box []),
cache: GlCache {
stored_index_buffer: 0,
stored_vertex_buffer: 0,
index_buffer: 0,
vertex_buffer: 0,
cur_pipeline: None,
blend: None,
stored_texture: 0,
textures: [0; MAX_SHADERSTAGE_IMAGES],
attributes: [None; MAX_VERTEX_ATTRIBUTES],
},
}
}
}
pub fn screen_size(&self) -> (f32, f32) {
unsafe { (sapp_width() as f32, sapp_height() as f32) }
}
pub fn dpi_scale(&self) -> f32 {
unsafe { sapp_dpi_scale() }
}
pub fn high_dpi(&self) -> bool {
unsafe { sapp_high_dpi() }
}
fn apply_pipeline(&mut self, pipeline: &Pipeline) {
let res = {
{
self.cache.cur_pipeline = Some(*pipeline);
let pipeline = &mut self.pipelines[pipeline.0];
let shader = &mut self.shaders[pipeline.shader.0];
unsafe {
glUseProgram(shader.program);
}
unsafe {
glEnable(GL_SCISSOR_TEST);
}
if pipeline.params.depth_write {
unsafe {
glEnable(GL_DEPTH_TEST);
glDepthFunc(pipeline.params.depth_test.into())
}
} else {
unsafe {
glDisable(GL_DEPTH_TEST);
}
}
if self.cache.blend != pipeline.params.color_blend {
unsafe {
if let Some((equation, src, dst)) = pipeline.params.color_blend {
if self.cache.blend.is_none() {
glEnable(GL_BLEND);
}
glBlendFunc(src.into(), dst.into());
glBlendEquationSeparate(equation.into(), equation.into());
} else if self.cache.blend.is_some() {
glDisable(GL_BLEND);
}
self.cache.blend = pipeline.params.color_blend;
}
}
}
};
res
}
fn apply_scissor_rect(&mut self, x: i32, y: i32, w: i32, h: i32) {
let res = {
{
unsafe {
glScissor(x, y, w, h);
}
}
};
res
}
fn apply_bindings(&mut self, bindings: &Bindings) {
let res = {
{
let pip = &self.pipelines[self.cache.cur_pipeline.unwrap().0];
let shader = &self.shaders[pip.shader.0];
for (n, shader_image) in shader.images.iter().enumerate() {
let bindings_image = bindings.images.get(n).unwrap_or_else(|| {
::std::rt::begin_panic(
"Image count in bindings and shader did not match!",
)
});
unsafe {
self.cache.bind_texture(n, bindings_image.texture);
glUniform1i(shader_image.gl_loc, n as i32);
}
}
self.cache
.bind_buffer(GL_ELEMENT_ARRAY_BUFFER, bindings.index_buffer.gl_buf);
let pip = &self.pipelines[self.cache.cur_pipeline.unwrap().0];
for attr_index in 0..MAX_VERTEX_ATTRIBUTES {
let cached_attr = &mut self.cache.attributes[attr_index];
let pip_attribute = pip.layout.get(attr_index).copied();
if let Some(attribute) = pip_attribute {
let vb = bindings.vertex_buffers[attribute.buffer_index];
if cached_attr.map_or(true, |cached_attr| {
attribute != cached_attr.attribute
|| cached_attr.gl_vbuf != vb.gl_buf
}) {
self.cache.bind_buffer(GL_ARRAY_BUFFER, vb.gl_buf);
unsafe {
glVertexAttribPointer(
attr_index as GLuint,
attribute.size,
attribute.type_,
GL_FALSE as u8,
attribute.stride,
attribute.offset as *mut _,
);
glVertexAttribDivisor(
attr_index as GLuint,
attribute.divisor as u32,
);
glEnableVertexAttribArray(attr_index as GLuint);
};
let cached_attr = &mut self.cache.attributes[attr_index];
*cached_attr = Some(CachedAttribute {
attribute,
gl_vbuf: vb.gl_buf,
});
}
} else {
if cached_attr.is_some() {
unsafe {
glDisableVertexAttribArray(attr_index as GLuint);
}
*cached_attr = None;
}
}
}
}
};
res
}
pub fn apply_uniforms<U>(&mut self, uniforms: &U) {
let pip = &self.pipelines[self.cache.cur_pipeline.unwrap().0];
let shader = &self.shaders[pip.shader.0];
let mut offset = 0;
for (_, uniform) in shader.uniforms.iter().enumerate() {
use UniformType::*;
if !(offset < std::mem::size_of::<U>() - 4) {
{
::std::rt::begin_panic(
"assertion failed: offset < std::mem::size_of::<U>() - 4",
)
}
};
unsafe {
let data = (uniforms as *const _ as *const f32).offset(offset as isize);
match uniform.uniform_type {
Float1 => {
glUniform1fv(uniform.gl_loc, 1, data);
}
Float2 => {
glUniform2fv(uniform.gl_loc, 1, data);
}
Float3 => {
glUniform3fv(uniform.gl_loc, 1, data);
}
Float4 => {
glUniform4fv(uniform.gl_loc, 1, data);
}
Mat4 => {
glUniformMatrix4fv(uniform.gl_loc, 1, 0, data);
}
}
}
offset += uniform.uniform_type.size(1) / 4;
}
}
fn clear(
&self,
color: Option<(f32, f32, f32, f32)>,
depth: Option<f32>,
stencil: Option<i32>,
) {
let res = {
{
let mut bits = 0;
if let Some((r, g, b, a)) = color {
bits |= GL_COLOR_BUFFER_BIT;
unsafe {
glClearColor(r, g, b, a);
}
}
if let Some(v) = depth {
bits |= GL_DEPTH_BUFFER_BIT;
unsafe {
glClearDepthf(v);
}
}
if let Some(v) = stencil {
bits |= GL_STENCIL_BUFFER_BIT;
unsafe {
glClearStencil(v);
}
}
if bits != 0 {
unsafe {
glClear(bits);
}
}
}
};
res
}
fn begin_default_pass(&mut self, action: PassAction) {
let res = {
{
self.begin_pass(None, action);
}
};
res
}
fn begin_pass(&mut self, pass: impl Into<Option<RenderPass>>, action: PassAction) {
let res = {
{
let (framebuffer, w, h) = match pass.into() {
None => (
self.default_framebuffer,
unsafe { sapp_width() } as i32,
unsafe { sapp_height() } as i32,
),
Some(pass) => {
let pass = &self.passes[pass.0];
(
pass.gl_fb,
pass.texture.width as i32,
pass.texture.height as i32,
)
}
};
unsafe {
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glViewport(0, 0, w, h);
glScissor(0, 0, w, h);
}
match action {
PassAction::Nothing => {}
PassAction::Clear {
color,
depth,
stencil,
} => {
self.clear(color, depth, stencil);
}
}
}
};
res
}
fn end_render_pass(&mut self) {
let res = {
{
unsafe {
glBindFramebuffer(GL_FRAMEBUFFER, self.default_framebuffer);
self.cache.bind_buffer(GL_ARRAY_BUFFER, 0);
self.cache.bind_buffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
}
};
res
}
fn commit_frame(&mut self) {
let res = {
{
self.cache.clear_buffer_bindings();
self.cache.clear_texture_bindings();
}
};
res
}
fn draw(&self, base_element: i32, num_elements: i32, num_instances: i32) {
let res = {
{
unsafe {
glDrawElementsInstanced(
GL_TRIANGLES,
num_elements,
GL_UNSIGNED_SHORT,
(2 * base_element) as *mut _,
num_instances,
);
}
}
};
res
}
}
fn load_shader_internal(
vertex_shader: &str,
fragment_shader: &str,
meta: ShaderMeta,
) -> ShaderInternal {
unsafe {
let vertex_shader = load_shader(GL_VERTEX_SHADER, vertex_shader);
let fragment_shader = load_shader(GL_FRAGMENT_SHADER, fragment_shader);
let program = glCreateProgram();
glAttachShader(program, vertex_shader);
glAttachShader(program, fragment_shader);
glLinkProgram(program);
let mut link_status = 0;
glGetProgramiv(program, GL_LINK_STATUS, &mut link_status as *mut _);
if link_status == 0 {
let mut max_length = 100;
let mut error_message = ::alloc::vec::from_elem(0u8, max_length as usize + 1);
glGetProgramInfoLog(
program,
max_length,
&mut max_length as *mut _,
error_message.as_mut_ptr() as *mut _,
);
let error_message = std::string::String::from_utf8_lossy(&error_message);
{
::std::rt::begin_panic_fmt(&::core::fmt::Arguments::new_v1(
&[""],
&match (&error_message,) {
(arg0,) => [::core::fmt::ArgumentV1::new(
arg0,
::core::fmt::Display::fmt,
)],
},
))
};
}
glUseProgram(program);
#[rustfmt::skip]
let images =
meta.images.iter().map(|name|
ShaderImage{gl_loc:
get_uniform_location(program,
name),}).collect();
#[rustfmt::skip]
let uniforms =
meta.uniforms.uniforms.iter().scan(0,
|offset, uniform|
{
let res =
ShaderUniform{gl_loc:
get_uniform_location(program,
uniform.0),
offset:
*offset,
size:
uniform.1.size(1),
uniform_type:
uniform.1,};
*offset +=
uniform.1.size(1);
Some(res)
}).collect();
ShaderInternal {
program,
images,
uniforms,
}
}
}
fn load_shader(shader_type: GLenum, source: &str) -> GLuint {
unsafe {
let shader = glCreateShader(shader_type);
if !(shader != 0) {
{
::std::rt::begin_panic("assertion failed: shader != 0")
}
};
let cstring = CString::new(source).unwrap_or_else(|e| ::std::rt::begin_panic(e));
let csource = [cstring];
glShaderSource(shader, 1, csource.as_ptr() as *const _, std::ptr::null());
glCompileShader(shader);
let mut is_compiled = 0;
glGetShaderiv(shader, GL_COMPILE_STATUS, &mut is_compiled as *mut _);
if is_compiled == 0 {
let mut max_length: i32 = 0;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &mut max_length as *mut _);
let mut error_message = ::alloc::vec::from_elem(0u8, max_length as usize + 1);
glGetShaderInfoLog(
shader,
max_length,
&mut max_length as *mut _,
error_message.as_mut_ptr() as *mut _,
);
let error_message = std::string::String::from_utf8_lossy(&error_message);
{
::std::io::_eprint(::core::fmt::Arguments::new_v1(
&["", " ", "\n"],
&match (&max_length, &error_message) {
(arg0, arg1) => [
::core::fmt::ArgumentV1::new(arg0, ::core::fmt::Display::fmt),
::core::fmt::ArgumentV1::new(arg1, ::core::fmt::Debug::fmt),
],
},
));
};
glDeleteShader(shader);
{
::std::rt::begin_panic("cant compile shader!")
};
}
shader
}
}
pub enum CullFace {
Nothing,
Front,
Back,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for CullFace {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&CullFace::Nothing,) => {
let mut debug_trait_builder = f.debug_tuple("Nothing");
debug_trait_builder.finish()
}
(&CullFace::Front,) => {
let mut debug_trait_builder = f.debug_tuple("Front");
debug_trait_builder.finish()
}
(&CullFace::Back,) => {
let mut debug_trait_builder = f.debug_tuple("Back");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for CullFace {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for CullFace {
#[inline]
fn eq(&self, other: &CullFace) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for CullFace {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for CullFace {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for CullFace {
#[inline]
fn clone(&self) -> CullFace {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for CullFace {}
pub enum FrontFaceOrder {
Clockwise,
CounterClockwise,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for FrontFaceOrder {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&FrontFaceOrder::Clockwise,) => {
let mut debug_trait_builder = f.debug_tuple("Clockwise");
debug_trait_builder.finish()
}
(&FrontFaceOrder::CounterClockwise,) => {
let mut debug_trait_builder = f.debug_tuple("CounterClockwise");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for FrontFaceOrder {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for FrontFaceOrder {
#[inline]
fn eq(&self, other: &FrontFaceOrder) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for FrontFaceOrder {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for FrontFaceOrder {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for FrontFaceOrder {
#[inline]
fn clone(&self) -> FrontFaceOrder {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for FrontFaceOrder {}
pub enum Comparison {
Never,
Less,
LessOrEqual,
Greater,
GreaterOrEqual,
Equal,
NotEqual,
Always,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Comparison {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&Comparison::Never,) => {
let mut debug_trait_builder = f.debug_tuple("Never");
debug_trait_builder.finish()
}
(&Comparison::Less,) => {
let mut debug_trait_builder = f.debug_tuple("Less");
debug_trait_builder.finish()
}
(&Comparison::LessOrEqual,) => {
let mut debug_trait_builder = f.debug_tuple("LessOrEqual");
debug_trait_builder.finish()
}
(&Comparison::Greater,) => {
let mut debug_trait_builder = f.debug_tuple("Greater");
debug_trait_builder.finish()
}
(&Comparison::GreaterOrEqual,) => {
let mut debug_trait_builder = f.debug_tuple("GreaterOrEqual");
debug_trait_builder.finish()
}
(&Comparison::Equal,) => {
let mut debug_trait_builder = f.debug_tuple("Equal");
debug_trait_builder.finish()
}
(&Comparison::NotEqual,) => {
let mut debug_trait_builder = f.debug_tuple("NotEqual");
debug_trait_builder.finish()
}
(&Comparison::Always,) => {
let mut debug_trait_builder = f.debug_tuple("Always");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for Comparison {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for Comparison {
#[inline]
fn eq(&self, other: &Comparison) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for Comparison {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for Comparison {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Comparison {
#[inline]
fn clone(&self) -> Comparison {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Comparison {}
impl From<Comparison> for GLenum {
fn from(cmp: Comparison) -> Self {
match cmp {
Comparison::Never => GL_NEVER,
Comparison::Less => GL_LESS,
Comparison::LessOrEqual => GL_LEQUAL,
Comparison::Greater => GL_GREATER,
Comparison::GreaterOrEqual => GL_GEQUAL,
Comparison::Equal => GL_EQUAL,
Comparison::NotEqual => GL_NOTEQUAL,
Comparison::Always => GL_ALWAYS,
}
}
}
pub enum Equation {
Add,
Subtract,
ReverseSubtract,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Equation {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&Equation::Add,) => {
let mut debug_trait_builder = f.debug_tuple("Add");
debug_trait_builder.finish()
}
(&Equation::Subtract,) => {
let mut debug_trait_builder = f.debug_tuple("Subtract");
debug_trait_builder.finish()
}
(&Equation::ReverseSubtract,) => {
let mut debug_trait_builder = f.debug_tuple("ReverseSubtract");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for Equation {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for Equation {
#[inline]
fn eq(&self, other: &Equation) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for Equation {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for Equation {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Equation {
#[inline]
fn clone(&self) -> Equation {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Equation {}
pub enum BlendValue {
SourceColor,
SourceAlpha,
DestinationColor,
DestinationAlpha,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for BlendValue {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&BlendValue::SourceColor,) => {
let mut debug_trait_builder = f.debug_tuple("SourceColor");
debug_trait_builder.finish()
}
(&BlendValue::SourceAlpha,) => {
let mut debug_trait_builder = f.debug_tuple("SourceAlpha");
debug_trait_builder.finish()
}
(&BlendValue::DestinationColor,) => {
let mut debug_trait_builder = f.debug_tuple("DestinationColor");
debug_trait_builder.finish()
}
(&BlendValue::DestinationAlpha,) => {
let mut debug_trait_builder = f.debug_tuple("DestinationAlpha");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for BlendValue {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for BlendValue {
#[inline]
fn eq(&self, other: &BlendValue) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for BlendValue {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for BlendValue {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for BlendValue {
#[inline]
fn clone(&self) -> BlendValue {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for BlendValue {}
pub enum BlendFactor {
Zero,
One,
Value(BlendValue),
OneMinusValue(BlendValue),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for BlendFactor {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&BlendFactor::Zero,) => {
let mut debug_trait_builder = f.debug_tuple("Zero");
debug_trait_builder.finish()
}
(&BlendFactor::One,) => {
let mut debug_trait_builder = f.debug_tuple("One");
debug_trait_builder.finish()
}
(&BlendFactor::Value(ref __self_0),) => {
let mut debug_trait_builder = f.debug_tuple("Value");
let _ = debug_trait_builder.field(&&(*__self_0));
debug_trait_builder.finish()
}
(&BlendFactor::OneMinusValue(ref __self_0),) => {
let mut debug_trait_builder = f.debug_tuple("OneMinusValue");
let _ = debug_trait_builder.field(&&(*__self_0));
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for BlendFactor {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for BlendFactor {
#[inline]
fn eq(&self, other: &BlendFactor) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
(&BlendFactor::Value(ref __self_0), &BlendFactor::Value(ref __arg_1_0)) => {
(*__self_0) == (*__arg_1_0)
}
(
&BlendFactor::OneMinusValue(ref __self_0),
&BlendFactor::OneMinusValue(ref __arg_1_0),
) => (*__self_0) == (*__arg_1_0),
_ => true,
}
} else {
false
}
}
}
#[inline]
fn ne(&self, other: &BlendFactor) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
(&BlendFactor::Value(ref __self_0), &BlendFactor::Value(ref __arg_1_0)) => {
(*__self_0) != (*__arg_1_0)
}
(
&BlendFactor::OneMinusValue(ref __self_0),
&BlendFactor::OneMinusValue(ref __arg_1_0),
) => (*__self_0) != (*__arg_1_0),
_ => false,
}
} else {
true
}
}
}
}
impl ::core::marker::StructuralEq for BlendFactor {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for BlendFactor {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{
let _: ::core::cmp::AssertParamIsEq<BlendValue>;
let _: ::core::cmp::AssertParamIsEq<BlendValue>;
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for BlendFactor {
#[inline]
fn clone(&self) -> BlendFactor {
{
let _: ::core::clone::AssertParamIsClone<BlendValue>;
let _: ::core::clone::AssertParamIsClone<BlendValue>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for BlendFactor {}
impl From<Equation> for GLenum {
fn from(eq: Equation) -> Self {
match eq {
Equation::Add => GL_FUNC_ADD,
Equation::Subtract => GL_FUNC_SUBTRACT,
Equation::ReverseSubtract => GL_FUNC_REVERSE_SUBTRACT,
}
}
}
impl From<BlendFactor> for GLenum {
fn from(factor: BlendFactor) -> GLenum {
match factor {
BlendFactor::Zero => GL_ZERO,
BlendFactor::One => GL_ONE,
BlendFactor::Value(BlendValue::SourceColor) => GL_SRC_COLOR,
BlendFactor::Value(BlendValue::SourceAlpha) => GL_SRC_ALPHA,
BlendFactor::Value(BlendValue::DestinationColor) => GL_DST_COLOR,
BlendFactor::Value(BlendValue::DestinationAlpha) => GL_DST_ALPHA,
BlendFactor::OneMinusValue(BlendValue::SourceColor) => GL_ONE_MINUS_SRC_COLOR,
BlendFactor::OneMinusValue(BlendValue::SourceAlpha) => GL_ONE_MINUS_SRC_ALPHA,
BlendFactor::OneMinusValue(BlendValue::DestinationColor) => GL_ONE_MINUS_DST_COLOR,
BlendFactor::OneMinusValue(BlendValue::DestinationAlpha) => GL_ONE_MINUS_DST_ALPHA,
}
}
}
pub struct PipelineParams {
pub cull_face: CullFace,
pub front_face_order: FrontFaceOrder,
pub depth_test: Comparison,
pub depth_write: bool,
pub depth_write_offset: Option<(f32, f32)>,
pub color_blend: BlendState,
pub color_write: (bool, bool, bool, bool),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for PipelineParams {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
PipelineParams {
cull_face: ref __self_0_0,
front_face_order: ref __self_0_1,
depth_test: ref __self_0_2,
depth_write: ref __self_0_3,
depth_write_offset: ref __self_0_4,
color_blend: ref __self_0_5,
color_write: ref __self_0_6,
} => {
let mut debug_trait_builder = f.debug_struct("PipelineParams");
let _ = debug_trait_builder.field("cull_face", &&(*__self_0_0));
let _ = debug_trait_builder.field("front_face_order", &&(*__self_0_1));
let _ = debug_trait_builder.field("depth_test", &&(*__self_0_2));
let _ = debug_trait_builder.field("depth_write", &&(*__self_0_3));
let _ = debug_trait_builder.field("depth_write_offset", &&(*__self_0_4));
let _ = debug_trait_builder.field("color_blend", &&(*__self_0_5));
let _ = debug_trait_builder.field("color_write", &&(*__self_0_6));
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for PipelineParams {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for PipelineParams {
#[inline]
fn eq(&self, other: &PipelineParams) -> bool {
match *other {
PipelineParams {
cull_face: ref __self_1_0,
front_face_order: ref __self_1_1,
depth_test: ref __self_1_2,
depth_write: ref __self_1_3,
depth_write_offset: ref __self_1_4,
color_blend: ref __self_1_5,
color_write: ref __self_1_6,
} => match *self {
PipelineParams {
cull_face: ref __self_0_0,
front_face_order: ref __self_0_1,
depth_test: ref __self_0_2,
depth_write: ref __self_0_3,
depth_write_offset: ref __self_0_4,
color_blend: ref __self_0_5,
color_write: ref __self_0_6,
} => {
(*__self_0_0) == (*__self_1_0)
&& (*__self_0_1) == (*__self_1_1)
&& (*__self_0_2) == (*__self_1_2)
&& (*__self_0_3) == (*__self_1_3)
&& (*__self_0_4) == (*__self_1_4)
&& (*__self_0_5) == (*__self_1_5)
&& (*__self_0_6) == (*__self_1_6)
}
},
}
}
#[inline]
fn ne(&self, other: &PipelineParams) -> bool {
match *other {
PipelineParams {
cull_face: ref __self_1_0,
front_face_order: ref __self_1_1,
depth_test: ref __self_1_2,
depth_write: ref __self_1_3,
depth_write_offset: ref __self_1_4,
color_blend: ref __self_1_5,
color_write: ref __self_1_6,
} => match *self {
PipelineParams {
cull_face: ref __self_0_0,
front_face_order: ref __self_0_1,
depth_test: ref __self_0_2,
depth_write: ref __self_0_3,
depth_write_offset: ref __self_0_4,
color_blend: ref __self_0_5,
color_write: ref __self_0_6,
} => {
(*__self_0_0) != (*__self_1_0)
|| (*__self_0_1) != (*__self_1_1)
|| (*__self_0_2) != (*__self_1_2)
|| (*__self_0_3) != (*__self_1_3)
|| (*__self_0_4) != (*__self_1_4)
|| (*__self_0_5) != (*__self_1_5)
|| (*__self_0_6) != (*__self_1_6)
}
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for PipelineParams {
#[inline]
fn clone(&self) -> PipelineParams {
{
let _: ::core::clone::AssertParamIsClone<CullFace>;
let _: ::core::clone::AssertParamIsClone<FrontFaceOrder>;
let _: ::core::clone::AssertParamIsClone<Comparison>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<Option<(f32, f32)>>;
let _: ::core::clone::AssertParamIsClone<BlendState>;
let _: ::core::clone::AssertParamIsClone<(bool, bool, bool, bool)>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for PipelineParams {}
pub struct Pipeline(usize);
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Pipeline {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Pipeline {
#[inline]
fn clone(&self) -> Pipeline {
{
let _: ::core::clone::AssertParamIsClone<usize>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Pipeline {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
Pipeline(ref __self_0_0) => {
let mut debug_trait_builder = f.debug_tuple("Pipeline");
let _ = debug_trait_builder.field(&&(*__self_0_0));
debug_trait_builder.finish()
}
}
}
}
impl Default for PipelineParams {
fn default() -> PipelineParams {
PipelineParams {
cull_face: CullFace::Nothing,
front_face_order: FrontFaceOrder::CounterClockwise,
depth_test: Comparison::Always,
depth_write: false,
depth_write_offset: None,
color_blend: None,
color_write: (true, true, true, true),
}
}
}
impl Pipeline {
pub fn new(
ctx: &mut Context,
buffer_layout: &[BufferLayout],
attributes: &[VertexAttribute],
shader: Shader,
) -> Pipeline {
Self::with_params(ctx, buffer_layout, attributes, shader, Default::default())
}
fn with_params(
ctx: &mut Context,
buffer_layout: &[BufferLayout],
attributes: &[VertexAttribute],
shader: Shader,
params: PipelineParams,
) {
let res = {
()
};
res
}
}
struct VertexAttributeInternal {
attr_loc: GLuint,
size: i32,
type_: GLuint,
offset: i64,
stride: i32,
buffer_index: usize,
divisor: i32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for VertexAttributeInternal {
#[inline]
fn clone(&self) -> VertexAttributeInternal {
{
let _: ::core::clone::AssertParamIsClone<GLuint>;
let _: ::core::clone::AssertParamIsClone<i32>;
let _: ::core::clone::AssertParamIsClone<GLuint>;
let _: ::core::clone::AssertParamIsClone<i64>;
let _: ::core::clone::AssertParamIsClone<i32>;
let _: ::core::clone::AssertParamIsClone<usize>;
let _: ::core::clone::AssertParamIsClone<i32>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for VertexAttributeInternal {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for VertexAttributeInternal {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
VertexAttributeInternal {
attr_loc: ref __self_0_0,
size: ref __self_0_1,
type_: ref __self_0_2,
offset: ref __self_0_3,
stride: ref __self_0_4,
buffer_index: ref __self_0_5,
divisor: ref __self_0_6,
} => {
let mut debug_trait_builder = f.debug_struct("VertexAttributeInternal");
let _ = debug_trait_builder.field("attr_loc", &&(*__self_0_0));
let _ = debug_trait_builder.field("size", &&(*__self_0_1));
let _ = debug_trait_builder.field("type_", &&(*__self_0_2));
let _ = debug_trait_builder.field("offset", &&(*__self_0_3));
let _ = debug_trait_builder.field("stride", &&(*__self_0_4));
let _ = debug_trait_builder.field("buffer_index", &&(*__self_0_5));
let _ = debug_trait_builder.field("divisor", &&(*__self_0_6));
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for VertexAttributeInternal {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for VertexAttributeInternal {
#[inline]
fn eq(&self, other: &VertexAttributeInternal) -> bool {
match *other {
VertexAttributeInternal {
attr_loc: ref __self_1_0,
size: ref __self_1_1,
type_: ref __self_1_2,
offset: ref __self_1_3,
stride: ref __self_1_4,
buffer_index: ref __self_1_5,
divisor: ref __self_1_6,
} => match *self {
VertexAttributeInternal {
attr_loc: ref __self_0_0,
size: ref __self_0_1,
type_: ref __self_0_2,
offset: ref __self_0_3,
stride: ref __self_0_4,
buffer_index: ref __self_0_5,
divisor: ref __self_0_6,
} => {
(*__self_0_0) == (*__self_1_0)
&& (*__self_0_1) == (*__self_1_1)
&& (*__self_0_2) == (*__self_1_2)
&& (*__self_0_3) == (*__self_1_3)
&& (*__self_0_4) == (*__self_1_4)
&& (*__self_0_5) == (*__self_1_5)
&& (*__self_0_6) == (*__self_1_6)
}
},
}
}
#[inline]
fn ne(&self, other: &VertexAttributeInternal) -> bool {
match *other {
VertexAttributeInternal {
attr_loc: ref __self_1_0,
size: ref __self_1_1,
type_: ref __self_1_2,
offset: ref __self_1_3,
stride: ref __self_1_4,
buffer_index: ref __self_1_5,
divisor: ref __self_1_6,
} => match *self {
VertexAttributeInternal {
attr_loc: ref __self_0_0,
size: ref __self_0_1,
type_: ref __self_0_2,
offset: ref __self_0_3,
stride: ref __self_0_4,
buffer_index: ref __self_0_5,
divisor: ref __self_0_6,
} => {
(*__self_0_0) != (*__self_1_0)
|| (*__self_0_1) != (*__self_1_1)
|| (*__self_0_2) != (*__self_1_2)
|| (*__self_0_3) != (*__self_1_3)
|| (*__self_0_4) != (*__self_1_4)
|| (*__self_0_5) != (*__self_1_5)
|| (*__self_0_6) != (*__self_1_6)
}
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::default::Default for VertexAttributeInternal {
#[inline]
fn default() -> VertexAttributeInternal {
VertexAttributeInternal {
attr_loc: ::core::default::Default::default(),
size: ::core::default::Default::default(),
type_: ::core::default::Default::default(),
offset: ::core::default::Default::default(),
stride: ::core::default::Default::default(),
buffer_index: ::core::default::Default::default(),
divisor: ::core::default::Default::default(),
}
}
}
struct PipelineInternal {
layout: Vec<VertexAttributeInternal>,
shader: Shader,
params: PipelineParams,
}
pub struct Bindings {
pub vertex_buffers: Vec<Buffer>,
pub index_buffer: Buffer,
pub images: Vec<Texture>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Bindings {
#[inline]
fn clone(&self) -> Bindings {
match *self {
Bindings {
vertex_buffers: ref __self_0_0,
index_buffer: ref __self_0_1,
images: ref __self_0_2,
} => Bindings {
vertex_buffers: ::core::clone::Clone::clone(&(*__self_0_0)),
index_buffer: ::core::clone::Clone::clone(&(*__self_0_1)),
images: ::core::clone::Clone::clone(&(*__self_0_2)),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Bindings {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
Bindings {
vertex_buffers: ref __self_0_0,
index_buffer: ref __self_0_1,
images: ref __self_0_2,
} => {
let mut debug_trait_builder = f.debug_struct("Bindings");
let _ = debug_trait_builder.field("vertex_buffers", &&(*__self_0_0));
let _ = debug_trait_builder.field("index_buffer", &&(*__self_0_1));
let _ = debug_trait_builder.field("images", &&(*__self_0_2));
debug_trait_builder.finish()
}
}
}
}
pub enum BufferType {
VertexBuffer,
IndexBuffer,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for BufferType {
#[inline]
fn clone(&self) -> BufferType {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for BufferType {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for BufferType {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&BufferType::VertexBuffer,) => {
let mut debug_trait_builder = f.debug_tuple("VertexBuffer");
debug_trait_builder.finish()
}
(&BufferType::IndexBuffer,) => {
let mut debug_trait_builder = f.debug_tuple("IndexBuffer");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for BufferType {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for BufferType {
#[inline]
fn eq(&self, other: &BufferType) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
pub enum Usage {
Immutable,
Dynamic,
Stream,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Usage {
#[inline]
fn clone(&self) -> Usage {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Usage {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Usage {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&Usage::Immutable,) => {
let mut debug_trait_builder = f.debug_tuple("Immutable");
debug_trait_builder.finish()
}
(&Usage::Dynamic,) => {
let mut debug_trait_builder = f.debug_tuple("Dynamic");
debug_trait_builder.finish()
}
(&Usage::Stream,) => {
let mut debug_trait_builder = f.debug_tuple("Stream");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for Usage {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for Usage {
#[inline]
fn eq(&self, other: &Usage) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
fn gl_buffer_target(buffer_type: &BufferType) -> GLenum {
match buffer_type {
BufferType::VertexBuffer => GL_ARRAY_BUFFER,
BufferType::IndexBuffer => GL_ELEMENT_ARRAY_BUFFER,
}
}
fn gl_usage(usage: &Usage) -> GLenum {
match usage {
Usage::Immutable => GL_STATIC_DRAW,
Usage::Dynamic => GL_DYNAMIC_DRAW,
Usage::Stream => GL_STREAM_DRAW,
}
}
pub struct Buffer {
gl_buf: GLuint,
buffer_type: BufferType,
size: usize,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Buffer {
#[inline]
fn clone(&self) -> Buffer {
{
let _: ::core::clone::AssertParamIsClone<GLuint>;
let _: ::core::clone::AssertParamIsClone<BufferType>;
let _: ::core::clone::AssertParamIsClone<usize>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Buffer {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Buffer {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
Buffer {
gl_buf: ref __self_0_0,
buffer_type: ref __self_0_1,
size: ref __self_0_2,
} => {
let mut debug_trait_builder = f.debug_struct("Buffer");
let _ = debug_trait_builder.field("gl_buf", &&(*__self_0_0));
let _ = debug_trait_builder.field("buffer_type", &&(*__self_0_1));
let _ = debug_trait_builder.field("size", &&(*__self_0_2));
debug_trait_builder.finish()
}
}
}
}
impl Buffer {
pub fn immutable<T>(ctx: &mut Context, buffer_type: BufferType, data: &[T]) -> Buffer {
if buffer_type == BufferType::IndexBuffer {
if !(mem::size_of::<T>() == 2) {
{
::std::rt::begin_panic(
"Only u16/i16 index buffers are implemented right now",
)
}
};
}
let gl_target = gl_buffer_target(&buffer_type);
let gl_usage = gl_usage(&Usage::Immutable);
let size = mem::size_of_val(data) as i64;
let mut gl_buf: u32 = 0;
unsafe {
glGenBuffers(1, &mut gl_buf as *mut _);
ctx.cache.store_buffer_binding(gl_target);
ctx.cache.bind_buffer(gl_target, gl_buf);
glBufferData(gl_target, size as _, std::ptr::null() as *const _, gl_usage);
glBufferSubData(gl_target, 0, size as _, data.as_ptr() as *const _);
ctx.cache.restore_buffer_binding(gl_target);
}
Buffer {
gl_buf,
buffer_type,
size: size as usize,
}
}
pub fn stream(ctx: &mut Context, buffer_type: BufferType, size: usize) -> Buffer {
let gl_target = gl_buffer_target(&buffer_type);
let gl_usage = gl_usage(&Usage::Stream);
let mut gl_buf: u32 = 0;
unsafe {
glGenBuffers(1, &mut gl_buf as *mut _);
ctx.cache.store_buffer_binding(gl_target);
ctx.cache.bind_buffer(gl_target, gl_buf);
glBufferData(gl_target, size as _, std::ptr::null() as *const _, gl_usage);
ctx.cache.restore_buffer_binding(gl_target);
}
Buffer {
gl_buf,
buffer_type,
size,
}
}
pub fn update<T>(&self, ctx: &mut Context, data: &[T]) {
let size = mem::size_of_val(data);
if !(size <= self.size) {
{
::std::rt::begin_panic("assertion failed: size <= self.size")
}
};
let gl_target = gl_buffer_target(&self.buffer_type);
ctx.cache.bind_buffer(gl_target, self.gl_buf);
unsafe { glBufferSubData(gl_target, 0, size as _, data.as_ptr() as *const _) };
ctx.cache.restore_buffer_binding(gl_target);
}
pub fn size(&self) -> usize {
self.size
}
pub fn delete(&self) {
unsafe { glDeleteBuffers(1, &self.gl_buf as *const _) }
}
}
}
pub use event::*;
pub use graphics::*;
pub use sapp::{rand, RAND_MAX};
use std::ffi::CString;
pub mod date {
#[cfg(not(target_arch = "wasm32"))]
pub fn now() -> f64 {
use std::time::SystemTime;
let time = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap_or_else(|e| ::std::rt::begin_panic(e));
time.as_secs_f64()
}
}
impl Context {
pub fn quit(&self) {
#[cfg(not(target_arch = "wasm32"))]
unsafe {
sapp::sapp_quit();
}
}
pub fn request_quit(&self) {
#[cfg(not(target_arch = "wasm32"))]
unsafe {
sapp::sapp_request_quit();
}
}
pub fn cancel_quit(&self) {
#[cfg(not(target_arch = "wasm32"))]
unsafe {
sapp::sapp_cancel_quit();
}
}
pub fn set_cursor_grab(&self, grab: bool) {
unsafe {
sapp::sapp_set_cursor_grab(grab);
}
}
pub fn show_mouse(&self, shown: bool) {
unsafe {
sapp::sapp_show_mouse(shown);
}
}
}
pub enum UserData {
Owning((Box<dyn EventHandler>, Context)),
Free(Box<dyn EventHandlerFree>),
}
impl UserData {
pub fn owning(event_handler: impl EventHandler + 'static, ctx: Context) -> UserData {
UserData::Owning((Box::new(event_handler), ctx))
}
pub fn free(event_handler: impl EventHandlerFree + 'static) -> UserData {
UserData::Free(Box::new(event_handler))
}
}
macro_rules! event_call {
($ event_handler : expr, $ fn : ident $ (, $ args : expr) *) =>
{
{
match $ event_handler
{
UserData :: Owning ((ref mut event_handler, ref mut context))
=> { event_handler . $ fn (context, $ ($ args,) *) ; }
UserData :: Free (ref mut event_handler) =>
{ event_handler . $ fn ($ ($ args,) *) ; }
}
}
} ;
}
enum UserDataState {
Uninitialized(Box<dyn 'static + FnOnce(Context) -> UserData>),
Intialized(UserData),
Empty,
}
extern "C" fn init(user_data: *mut ::std::os::raw::c_void) {
let data: &mut UserDataState = unsafe { &mut *(user_data as *mut UserDataState) };
let empty = UserDataState::Empty;
let f = std::mem::replace(data, empty);
let f = if let UserDataState::Uninitialized(f) = f {
f
} else {
{
{
::std::rt::begin_panic("explicit panic")
}
};
};
let context = graphics::Context::new();
let user_data = f(context);
std::mem::replace(data, UserDataState::Intialized(user_data));
}
extern "C" fn frame(user_data: *mut ::std::os::raw::c_void) {
let data: &mut UserDataState = unsafe { &mut *(user_data as *mut UserDataState) };
let data = if let UserDataState::Intialized(ref mut data) = data {
data
} else {
{
{
::std::rt::begin_panic("explicit panic")
}
}
};
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.update(context);
}
UserData::Free(ref mut event_handler) => {
event_handler.update();
}
}
};
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.draw(context);
}
UserData::Free(ref mut event_handler) => {
event_handler.draw();
}
}
};
}
extern "C" fn event(event: *const sapp::sapp_event, user_data: *mut ::std::os::raw::c_void) {
let data: &mut UserDataState = unsafe { &mut *(user_data as *mut UserDataState) };
let event = unsafe { &*event };
let data = if let UserDataState::Intialized(ref mut data) = data {
data
} else {
{
{
::std::rt::begin_panic("explicit panic")
}
}
};
match event.type_ {
sapp::sapp_event_type_SAPP_EVENTTYPE_MOUSE_MOVE => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.mouse_motion_event(context, event.mouse_x, event.mouse_y);
}
UserData::Free(ref mut event_handler) => {
event_handler.mouse_motion_event(event.mouse_x, event.mouse_y);
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_MOUSE_SCROLL => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.mouse_wheel_event(context, event.scroll_x, event.scroll_y);
}
UserData::Free(ref mut event_handler) => {
event_handler.mouse_wheel_event(event.scroll_x, event.scroll_y);
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_MOUSE_DOWN => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.mouse_button_down_event(
context,
MouseButton::from(event.mouse_button),
event.mouse_x,
event.mouse_y,
);
}
UserData::Free(ref mut event_handler) => {
event_handler.mouse_button_down_event(
MouseButton::from(event.mouse_button),
event.mouse_x,
event.mouse_y,
);
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_MOUSE_UP => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.mouse_button_up_event(
context,
MouseButton::from(event.mouse_button),
event.mouse_x,
event.mouse_y,
);
}
UserData::Free(ref mut event_handler) => {
event_handler.mouse_button_up_event(
MouseButton::from(event.mouse_button),
event.mouse_x,
event.mouse_y,
);
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_CHAR => {
if let Some(character) = std::char::from_u32(event.char_code) {
let key_mods = KeyMods::from(event.modifiers);
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.char_event(
context,
character,
key_mods,
event.key_repeat,
);
}
UserData::Free(ref mut event_handler) => {
event_handler.char_event(character, key_mods, event.key_repeat);
}
}
}
}
}
sapp::sapp_event_type_SAPP_EVENTTYPE_KEY_DOWN => {
let keycode = KeyCode::from(event.key_code);
let key_mods = KeyMods::from(event.modifiers);
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.key_down_event(context, keycode, key_mods, false);
}
UserData::Free(ref mut event_handler) => {
event_handler.key_down_event(keycode, key_mods, false);
}
}
}
}
sapp::sapp_event_type_SAPP_EVENTTYPE_KEY_UP => {
let keycode = KeyCode::from(event.key_code);
let key_mods = KeyMods::from(event.modifiers);
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.key_up_event(context, keycode, key_mods);
}
UserData::Free(ref mut event_handler) => {
event_handler.key_up_event(keycode, key_mods);
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_RESIZED => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.resize_event(
context,
event.window_width as f32,
event.window_height as f32,
);
}
UserData::Free(ref mut event_handler) => {
event_handler
.resize_event(event.window_width as f32, event.window_height as f32);
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_BEGAN
| sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_ENDED
| sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_CANCELLED
| sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_MOVED => {
for i in 0..(event.num_touches as usize) {
if event.touches[i].changed {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.touch_event(
context,
event.type_.into(),
event.touches[i].identifier as u64,
event.touches[i].pos_x,
event.touches[i].pos_y,
);
}
UserData::Free(ref mut event_handler) => {
event_handler.touch_event(
event.type_.into(),
event.touches[i].identifier as u64,
event.touches[i].pos_x,
event.touches[i].pos_y,
);
}
}
};
}
}
}
sapp::sapp_event_type_SAPP_EVENTTYPE_QUIT_REQUESTED => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.quit_requested_event(context);
}
UserData::Free(ref mut event_handler) => {
event_handler.quit_requested_event();
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_RAW_DEVICE => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.raw_mouse_motion(context, event.mouse_dx, event.mouse_dy);
}
UserData::Free(ref mut event_handler) => {
event_handler.raw_mouse_motion(event.mouse_dx, event.mouse_dy);
}
}
};
}
_ => {}
}
}
pub fn start<F>(conf: conf::Conf, f: F)
where
F: 'static + FnOnce(Context) -> UserData,
{
let mut desc: sapp::sapp_desc = unsafe { std::mem::zeroed() };
let title =
CString::new(conf.window_title.as_bytes()).unwrap_or_else(|e| ::std::rt::begin_panic(e));
let mut user_data = Box::new(UserDataState::Uninitialized(Box::new(f)));
desc.width = conf.window_width;
desc.height = conf.window_height;
desc.fullscreen = conf.fullscreen as _;
desc.high_dpi = conf.high_dpi as _;
desc.window_title = title.as_ptr();
desc.user_data = &mut *user_data as *mut _ as *mut _;
desc.init_userdata_cb = Some(init);
desc.frame_userdata_cb = Some(frame);
desc.event_userdata_cb = Some(event);
std::mem::forget(user_data);
unsafe { sapp::sapp_run(&desc as *const _) };
}
{ unsafe { glDeleteTextures (1, & self . texture as * const _) ; } }
AA
-> Texture
{
let (internal_format, format, pixel_type) = params . format . into () ;
ctx . cache . store_texture_binding (0) ; let mut texture : GLuint = 0 ;
unsafe
{
glGenTextures (1, & mut texture as * mut _) ; glActiveTexture
(GL_TEXTURE0) ; ctx . cache . bind_texture (0, texture) ; glTexImage2D
(GL_TEXTURE_2D, 0, internal_format as i32, params . width as i32,
params . height as i32, 0, format, pixel_type, std :: ptr :: null
(),) ; glTexParameteri
(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE as i32) ;
glTexParameteri
(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE as i32) ;
glTexParameteri
(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR as i32) ;
glTexParameteri
(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR as i32) ;
} ctx . cache . restore_texture_binding (0) ; Texture
{ texture, width : params . width, height : params . height, }
}
AA
-> Texture
{
assert_eq !
(params . format . size (params . width, params . height), bytes . len ()
as u32) ; let (internal_format, format, pixel_type) = params . format .
into () ; unsafe
{
ctx . cache . store_texture_binding (0) ; let mut texture : GLuint = 0
; glGenTextures (1, & mut texture as * mut _) ; ctx . cache .
bind_texture (0, texture) ; glTexImage2D
(GL_TEXTURE_2D, 0, internal_format as i32, params . width as i32,
params . height as i32, 0, format, pixel_type, bytes . as_ptr () as *
const _,) ; glTexParameteri
(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE as i32) ;
glTexParameteri
(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE as i32) ;
glTexParameteri
(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR as i32) ;
glTexParameteri
(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR as i32) ; ctx . cache
. restore_texture_binding (0) ; Texture
{
texture, width : params . width as u32, height : params . height
as u32,
}
}
}
AA
{
ctx . cache . store_texture_binding (0) ; ctx . cache . bind_texture
(0, self . texture) ; unsafe
{
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter as i32)
; glTexParameteri
(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter as i32) ;
} ctx . cache . restore_texture_binding (0) ;
}
AA
{
assert_eq ! (width as usize * height as usize * 4, bytes . len ()) ;
assert ! (x_offset + width <= self . width as _) ; assert !
(y_offset + height <= self . height as _) ; ctx . cache .
store_texture_binding (0) ; ctx . cache . bind_texture (0, self . texture)
; unsafe
{
glTexSubImage2D
(GL_TEXTURE_2D, 0, x_offset as _, y_offset as _, width as _, height as
_, GL_RGBA, GL_UNSIGNED_BYTE, bytes . as_ptr () as * const _,) ;
} ctx . cache . restore_texture_binding (0) ;
}
AA
{
self . cache . cur_pipeline = Some (* pipeline) ; let pipeline = & mut
self . pipelines [pipeline . 0] ; let shader = & mut self . shaders
[pipeline . shader . 0] ; unsafe { glUseProgram (shader . program) ; }
unsafe { glEnable (GL_SCISSOR_TEST) ; } if pipeline . params . depth_write
{
unsafe
{
glEnable (GL_DEPTH_TEST) ; glDepthFunc
(pipeline . params . depth_test . into ())
}
} else { unsafe { glDisable (GL_DEPTH_TEST) ; } } if self . cache . blend
!= pipeline . params . color_blend
{
unsafe
{
if let Some ((equation, src, dst)) = pipeline . params .
color_blend
{
if self . cache . blend . is_none () { glEnable (GL_BLEND) ; }
glBlendFunc (src . into (), dst . into ()) ;
glBlendEquationSeparate
(equation . into (), equation . into ()) ;
} else if self . cache . blend . is_some ()
{ glDisable (GL_BLEND) ; } self . cache . blend = pipeline .
params . color_blend ;
}
}
}
AA
{ unsafe { glScissor (x, y, w, h) ; } }
AA
{
let pip = & self . pipelines [self . cache . cur_pipeline . unwrap () . 0]
; let shader = & self . shaders [pip . shader . 0] ; for (n, shader_image)
in shader . images . iter () . enumerate ()
{
let bindings_image = bindings . images . get (n) . unwrap_or_else
(|| panic ! ("Image count in bindings and shader did not match!")) ;
unsafe
{
self . cache . bind_texture (n, bindings_image . texture) ;
glUniform1i (shader_image . gl_loc, n as i32) ;
}
} self . cache . bind_buffer
(GL_ELEMENT_ARRAY_BUFFER, bindings . index_buffer . gl_buf) ; let pip = &
self . pipelines [self . cache . cur_pipeline . unwrap () . 0] ; for
attr_index in 0 .. MAX_VERTEX_ATTRIBUTES
{
let cached_attr = & mut self . cache . attributes [attr_index] ; let
pip_attribute = pip . layout . get (attr_index) . copied () ; if let
Some (attribute) = pip_attribute
{
let vb = bindings . vertex_buffers [attribute . buffer_index] ; if
cached_attr . map_or
(true, | cached_attr |
{
attribute != cached_attr . attribute || cached_attr . gl_vbuf
!= vb . gl_buf
})
{
self . cache . bind_buffer (GL_ARRAY_BUFFER, vb . gl_buf) ;
unsafe
{
glVertexAttribPointer
(attr_index as GLuint, attribute . size, attribute .
type_, GL_FALSE as u8, attribute . stride, attribute .
offset as * mut _,) ; glVertexAttribDivisor
(attr_index as GLuint, attribute . divisor as u32) ;
glEnableVertexAttribArray (attr_index as GLuint) ;
} ; let cached_attr = & mut self . cache . attributes
[attr_index] ; * cached_attr = Some
(CachedAttribute { attribute, gl_vbuf : vb . gl_buf, }) ;
}
} else
{
if cached_attr . is_some ()
{
unsafe { glDisableVertexAttribArray (attr_index as GLuint) ; }
* cached_attr = None ;
}
}
}
}
AA
{
let mut bits = 0 ; if let Some ((r, g, b, a)) = color
{ bits |= GL_COLOR_BUFFER_BIT ; unsafe { glClearColor (r, g, b, a) ; } }
if let Some (v) = depth
{ bits |= GL_DEPTH_BUFFER_BIT ; unsafe { glClearDepthf (v) ; } } if let
Some (v) = stencil
{ bits |= GL_STENCIL_BUFFER_BIT ; unsafe { glClearStencil (v) ; } } if
bits != 0 { unsafe { glClear (bits) ; } }
}
AA
{ self . begin_pass (None, action) ; }
AA
{
let (framebuffer, w, h) = match pass . into ()
{
None =>
(self . default_framebuffer, unsafe { sapp_width () } as i32, unsafe
{ sapp_height () } as i32,), Some (pass) =>
{
let pass = & self . passes [pass . 0] ;
(pass . gl_fb, pass . texture . width as i32, pass . texture .
height as i32,)
}
} ; unsafe
{
glBindFramebuffer (GL_FRAMEBUFFER, framebuffer) ; glViewport
(0, 0, w, h) ; glScissor (0, 0, w, h) ;
} match action
{
PassAction :: Nothing => { } PassAction :: Clear
{ color, depth, stencil, } =>
{ self . clear (color, depth, stencil) ; }
}
}
AA
{
unsafe
{
glBindFramebuffer (GL_FRAMEBUFFER, self . default_framebuffer) ; self
. cache . bind_buffer (GL_ARRAY_BUFFER, 0) ; self . cache .
bind_buffer (GL_ELEMENT_ARRAY_BUFFER, 0) ;
}
}
AA
{
self . cache . clear_buffer_bindings () ; self . cache .
clear_texture_bindings () ;
}
AA
{
unsafe
{
glDrawElementsInstanced
(GL_TRIANGLES, num_elements, GL_UNSIGNED_SHORT, (2 * base_element) as
* mut _, num_instances,) ;
}
}
AA
-> Pipeline
{
# [derive (Clone, Copy, Default)] struct BufferCacheData
{ stride : i32, offset : i64, } let mut buffer_cache : Vec <
BufferCacheData > = vec !
[BufferCacheData :: default () ; buffer_layout . len ()] ; for
VertexAttribute { format, buffer_index, .. } in attributes
{
let layout = buffer_layout . get (* buffer_index) . unwrap_or_else
(|| panic ! ()) ; let mut cache = buffer_cache . get_mut
(* buffer_index) . unwrap_or_else (|| panic ! ()) ; if layout . stride
== 0 { cache . stride += format . byte_len () ; } else
{ cache . stride = layout . stride ; }
} let program = ctx . shaders [shader . 0] . program ; let attributes_len
= attributes . iter () . map
(| layout | match layout . format { VertexFormat :: Mat4 => 4, _ => 1, })
. sum () ; let mut vertex_layout : Vec < VertexAttributeInternal > = vec !
[VertexAttributeInternal :: default () ; attributes_len] ; for
VertexAttribute { name, format, buffer_index, } in attributes
{
let mut buffer_data = & mut buffer_cache . get_mut (* buffer_index) .
unwrap_or_else (|| panic ! ()) ; let layout = buffer_layout . get
(* buffer_index) . unwrap_or_else (|| panic ! ()) ; let cname =
CString :: new (* name) . unwrap_or_else (| e | panic ! (e)) ; let
attr_loc = unsafe
{ glGetAttribLocation (program, cname . as_ptr () as * const _) } ; if
attr_loc == - 1
{ panic ! ("failed to obtain location of attribute {}", name) ; } let
divisor = if layout . step_func == VertexStep :: PerVertex { 0 } else
{ layout . step_rate } ; let mut attributes_count : usize = 1 ; let
mut format = * format ; if format == VertexFormat :: Mat4
{ format = VertexFormat :: Float4 ; attributes_count = 4 ; } for i in
0 .. attributes_count
{
let attr_loc = attr_loc as GLuint + i as GLuint ; let attr =
VertexAttributeInternal
{
attr_loc, size : format . size (), type_ : format . type_ (),
offset : buffer_data . offset, stride : buffer_data . stride,
buffer_index : * buffer_index, divisor,
} ; assert !
(attr_loc < vertex_layout . len () as u32, format !
("attribute: {} outside of allocated attributes array len: {}",
name, vertex_layout . len ())) ; vertex_layout
[attr_loc as usize] = attr ; buffer_data . offset += format .
byte_len () as i64
}
} assert !
(vertex_layout . iter () . any (| attr | attr . size == 0) == false) ; let
pipeline = PipelineInternal { layout : vertex_layout, shader, params, } ;
ctx . pipelines . push (pipeline) ; Pipeline
(ctx . pipelines . len () - 1)
}
AA
#![feature(prelude_import)]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std;
#[cfg(target_os = "linux")]
extern crate sapp_linux as sapp;
pub mod clipboard {
use crate::Context;
#[cfg(target_os = "linux")]
pub fn get(_ctx: &mut Context) -> Option<String> {
use std::ffi::CString;
let bufname = CString::new("CLIPBOARD").unwrap();
let fmtname = CString::new("UTF8_STRING").unwrap();
unsafe { sapp_linux::clipboard::get_clipboard(bufname.as_ptr(), fmtname.as_ptr()) }
}
#[cfg(target_os = "linux")]
pub fn set(_ctx: &mut Context, data: &str) {
use std::ffi::CString;
let bufname = CString::new("CLIPBOARD").unwrap();
unsafe {
sapp_linux::clipboard::claim_clipboard_ownership(bufname.as_ptr(), data.to_owned())
};
}
}
pub mod conf {
pub enum Cache {
No,
Index,
List(Vec<&'static str>),
Tar(&'static [u8]),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Cache {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&Cache::No,) => {
let mut debug_trait_builder = f.debug_tuple("No");
debug_trait_builder.finish()
}
(&Cache::Index,) => {
let mut debug_trait_builder = f.debug_tuple("Index");
debug_trait_builder.finish()
}
(&Cache::List(ref __self_0),) => {
let mut debug_trait_builder = f.debug_tuple("List");
let _ = debug_trait_builder.field(&&(*__self_0));
debug_trait_builder.finish()
}
(&Cache::Tar(ref __self_0),) => {
let mut debug_trait_builder = f.debug_tuple("Tar");
let _ = debug_trait_builder.field(&&(*__self_0));
debug_trait_builder.finish()
}
}
}
}
pub enum Loading {
No,
Embedded,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Loading {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&Loading::No,) => {
let mut debug_trait_builder = f.debug_tuple("No");
debug_trait_builder.finish()
}
(&Loading::Embedded,) => {
let mut debug_trait_builder = f.debug_tuple("Embedded");
debug_trait_builder.finish()
}
}
}
}
pub struct Conf {
pub cache: Cache,
pub loading: Loading,
pub window_title: String,
pub window_width: i32,
pub window_height: i32,
pub high_dpi: bool,
pub fullscreen: bool,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Conf {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
Conf {
cache: ref __self_0_0,
loading: ref __self_0_1,
window_title: ref __self_0_2,
window_width: ref __self_0_3,
window_height: ref __self_0_4,
high_dpi: ref __self_0_5,
fullscreen: ref __self_0_6,
} => {
let mut debug_trait_builder = f.debug_struct("Conf");
let _ = debug_trait_builder.field("cache", &&(*__self_0_0));
let _ = debug_trait_builder.field("loading", &&(*__self_0_1));
let _ = debug_trait_builder.field("window_title", &&(*__self_0_2));
let _ = debug_trait_builder.field("window_width", &&(*__self_0_3));
let _ = debug_trait_builder.field("window_height", &&(*__self_0_4));
let _ = debug_trait_builder.field("high_dpi", &&(*__self_0_5));
let _ = debug_trait_builder.field("fullscreen", &&(*__self_0_6));
debug_trait_builder.finish()
}
}
}
}
impl Default for Conf {
fn default() -> Conf {
Conf {
cache: Cache::No,
loading: Loading::No,
window_title: "".to_owned(),
window_width: 800,
window_height: 600,
high_dpi: false,
fullscreen: false,
}
}
}
}
mod event {
use crate::sapp::{self, sapp_keycode, sapp_mousebutton};
use crate::Context;
pub enum MouseButton {
Right,
Left,
Middle,
Unknown,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for MouseButton {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&MouseButton::Right,) => {
let mut debug_trait_builder = f.debug_tuple("Right");
debug_trait_builder.finish()
}
(&MouseButton::Left,) => {
let mut debug_trait_builder = f.debug_tuple("Left");
debug_trait_builder.finish()
}
(&MouseButton::Middle,) => {
let mut debug_trait_builder = f.debug_tuple("Middle");
debug_trait_builder.finish()
}
(&MouseButton::Unknown,) => {
let mut debug_trait_builder = f.debug_tuple("Unknown");
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for MouseButton {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for MouseButton {
#[inline]
fn clone(&self) -> MouseButton {
{
*self
}
}
}
impl ::core::marker::StructuralPartialEq for MouseButton {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for MouseButton {
#[inline]
fn eq(&self, other: &MouseButton) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::hash::Hash for MouseButton {
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
match (&*self,) {
_ => ::core::hash::Hash::hash(
&unsafe { ::core::intrinsics::discriminant_value(self) },
state,
),
}
}
}
impl ::core::marker::StructuralEq for MouseButton {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for MouseButton {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
pub struct Touch {
pub id: u32,
pub x: f32,
pub y: f32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Touch {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
Touch {
id: ref __self_0_0,
x: ref __self_0_1,
y: ref __self_0_2,
} => {
let mut debug_trait_builder = f.debug_struct("Touch");
let _ = debug_trait_builder.field("id", &&(*__self_0_0));
let _ = debug_trait_builder.field("x", &&(*__self_0_1));
let _ = debug_trait_builder.field("y", &&(*__self_0_2));
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Touch {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Touch {
#[inline]
fn clone(&self) -> Touch {
{
let _: ::core::clone::AssertParamIsClone<u32>;
let _: ::core::clone::AssertParamIsClone<f32>;
let _: ::core::clone::AssertParamIsClone<f32>;
*self
}
}
}
impl From<sapp_mousebutton> for MouseButton {
fn from(btn: sapp_mousebutton) -> MouseButton {
match btn {
sapp::sapp_mousebutton_SAPP_MOUSEBUTTON_LEFT => MouseButton::Left,
sapp::sapp_mousebutton_SAPP_MOUSEBUTTON_RIGHT => MouseButton::Right,
sapp::sapp_mousebutton_SAPP_MOUSEBUTTON_MIDDLE => MouseButton::Middle,
_ => MouseButton::Unknown,
}
}
}
#[repr(u32)]
pub enum KeyCode {
Space,
Apostrophe,
Comma,
Minus,
Period,
Slash,
Key0,
Key1,
Key2,
Key3,
Key4,
Key5,
Key6,
Key7,
Key8,
Key9,
Semicolon,
Equal,
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q,
R,
S,
T,
U,
V,
W,
X,
Y,
Z,
LeftBracket,
Backslash,
RightBracket,
GraveAccent,
World1,
World2,
Escape,
Enter,
Tab,
Backspace,
Insert,
Delete,
Right,
Left,
Down,
Up,
PageUp,
PageDown,
Home,
End,
CapsLock,
ScrollLock,
NumLock,
PrintScreen,
Pause,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
F13,
F14,
F15,
F16,
F17,
F18,
F19,
F20,
F21,
F22,
F23,
F24,
F25,
Kp0,
Kp1,
Kp2,
Kp3,
Kp4,
Kp5,
Kp6,
Kp7,
Kp8,
Kp9,
KpDecimal,
KpDivide,
KpMultiply,
KpSubtract,
KpAdd,
KpEnter,
KpEqual,
LeftShift,
LeftControl,
LeftAlt,
LeftSuper,
RightShift,
RightControl,
RightAlt,
RightSuper,
Menu,
Unknown,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for KeyCode {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&KeyCode::Space,) => {
let mut debug_trait_builder = f.debug_tuple("Space");
debug_trait_builder.finish()
}
(&KeyCode::Apostrophe,) => {
let mut debug_trait_builder = f.debug_tuple("Apostrophe");
debug_trait_builder.finish()
}
(&KeyCode::Comma,) => {
let mut debug_trait_builder = f.debug_tuple("Comma");
debug_trait_builder.finish()
}
(&KeyCode::Minus,) => {
let mut debug_trait_builder = f.debug_tuple("Minus");
debug_trait_builder.finish()
}
(&KeyCode::Period,) => {
let mut debug_trait_builder = f.debug_tuple("Period");
debug_trait_builder.finish()
}
(&KeyCode::Slash,) => {
let mut debug_trait_builder = f.debug_tuple("Slash");
debug_trait_builder.finish()
}
(&KeyCode::Key0,) => {
let mut debug_trait_builder = f.debug_tuple("Key0");
debug_trait_builder.finish()
}
(&KeyCode::Key1,) => {
let mut debug_trait_builder = f.debug_tuple("Key1");
debug_trait_builder.finish()
}
(&KeyCode::Key2,) => {
let mut debug_trait_builder = f.debug_tuple("Key2");
debug_trait_builder.finish()
}
(&KeyCode::Key3,) => {
let mut debug_trait_builder = f.debug_tuple("Key3");
debug_trait_builder.finish()
}
(&KeyCode::Key4,) => {
let mut debug_trait_builder = f.debug_tuple("Key4");
debug_trait_builder.finish()
}
(&KeyCode::Key5,) => {
let mut debug_trait_builder = f.debug_tuple("Key5");
debug_trait_builder.finish()
}
(&KeyCode::Key6,) => {
let mut debug_trait_builder = f.debug_tuple("Key6");
debug_trait_builder.finish()
}
(&KeyCode::Key7,) => {
let mut debug_trait_builder = f.debug_tuple("Key7");
debug_trait_builder.finish()
}
(&KeyCode::Key8,) => {
let mut debug_trait_builder = f.debug_tuple("Key8");
debug_trait_builder.finish()
}
(&KeyCode::Key9,) => {
let mut debug_trait_builder = f.debug_tuple("Key9");
debug_trait_builder.finish()
}
(&KeyCode::Semicolon,) => {
let mut debug_trait_builder = f.debug_tuple("Semicolon");
debug_trait_builder.finish()
}
(&KeyCode::Equal,) => {
let mut debug_trait_builder = f.debug_tuple("Equal");
debug_trait_builder.finish()
}
(&KeyCode::A,) => {
let mut debug_trait_builder = f.debug_tuple("A");
debug_trait_builder.finish()
}
(&KeyCode::B,) => {
let mut debug_trait_builder = f.debug_tuple("B");
debug_trait_builder.finish()
}
(&KeyCode::C,) => {
let mut debug_trait_builder = f.debug_tuple("C");
debug_trait_builder.finish()
}
(&KeyCode::D,) => {
let mut debug_trait_builder = f.debug_tuple("D");
debug_trait_builder.finish()
}
(&KeyCode::E,) => {
let mut debug_trait_builder = f.debug_tuple("E");
debug_trait_builder.finish()
}
(&KeyCode::F,) => {
let mut debug_trait_builder = f.debug_tuple("F");
debug_trait_builder.finish()
}
(&KeyCode::G,) => {
let mut debug_trait_builder = f.debug_tuple("G");
debug_trait_builder.finish()
}
(&KeyCode::H,) => {
let mut debug_trait_builder = f.debug_tuple("H");
debug_trait_builder.finish()
}
(&KeyCode::I,) => {
let mut debug_trait_builder = f.debug_tuple("I");
debug_trait_builder.finish()
}
(&KeyCode::J,) => {
let mut debug_trait_builder = f.debug_tuple("J");
debug_trait_builder.finish()
}
(&KeyCode::K,) => {
let mut debug_trait_builder = f.debug_tuple("K");
debug_trait_builder.finish()
}
(&KeyCode::L,) => {
let mut debug_trait_builder = f.debug_tuple("L");
debug_trait_builder.finish()
}
(&KeyCode::M,) => {
let mut debug_trait_builder = f.debug_tuple("M");
debug_trait_builder.finish()
}
(&KeyCode::N,) => {
let mut debug_trait_builder = f.debug_tuple("N");
debug_trait_builder.finish()
}
(&KeyCode::O,) => {
let mut debug_trait_builder = f.debug_tuple("O");
debug_trait_builder.finish()
}
(&KeyCode::P,) => {
let mut debug_trait_builder = f.debug_tuple("P");
debug_trait_builder.finish()
}
(&KeyCode::Q,) => {
let mut debug_trait_builder = f.debug_tuple("Q");
debug_trait_builder.finish()
}
(&KeyCode::R,) => {
let mut debug_trait_builder = f.debug_tuple("R");
debug_trait_builder.finish()
}
(&KeyCode::S,) => {
let mut debug_trait_builder = f.debug_tuple("S");
debug_trait_builder.finish()
}
(&KeyCode::T,) => {
let mut debug_trait_builder = f.debug_tuple("T");
debug_trait_builder.finish()
}
(&KeyCode::U,) => {
let mut debug_trait_builder = f.debug_tuple("U");
debug_trait_builder.finish()
}
(&KeyCode::V,) => {
let mut debug_trait_builder = f.debug_tuple("V");
debug_trait_builder.finish()
}
(&KeyCode::W,) => {
let mut debug_trait_builder = f.debug_tuple("W");
debug_trait_builder.finish()
}
(&KeyCode::X,) => {
let mut debug_trait_builder = f.debug_tuple("X");
debug_trait_builder.finish()
}
(&KeyCode::Y,) => {
let mut debug_trait_builder = f.debug_tuple("Y");
debug_trait_builder.finish()
}
(&KeyCode::Z,) => {
let mut debug_trait_builder = f.debug_tuple("Z");
debug_trait_builder.finish()
}
(&KeyCode::LeftBracket,) => {
let mut debug_trait_builder = f.debug_tuple("LeftBracket");
debug_trait_builder.finish()
}
(&KeyCode::Backslash,) => {
let mut debug_trait_builder = f.debug_tuple("Backslash");
debug_trait_builder.finish()
}
(&KeyCode::RightBracket,) => {
let mut debug_trait_builder = f.debug_tuple("RightBracket");
debug_trait_builder.finish()
}
(&KeyCode::GraveAccent,) => {
let mut debug_trait_builder = f.debug_tuple("GraveAccent");
debug_trait_builder.finish()
}
(&KeyCode::World1,) => {
let mut debug_trait_builder = f.debug_tuple("World1");
debug_trait_builder.finish()
}
(&KeyCode::World2,) => {
let mut debug_trait_builder = f.debug_tuple("World2");
debug_trait_builder.finish()
}
(&KeyCode::Escape,) => {
let mut debug_trait_builder = f.debug_tuple("Escape");
debug_trait_builder.finish()
}
(&KeyCode::Enter,) => {
let mut debug_trait_builder = f.debug_tuple("Enter");
debug_trait_builder.finish()
}
(&KeyCode::Tab,) => {
let mut debug_trait_builder = f.debug_tuple("Tab");
debug_trait_builder.finish()
}
(&KeyCode::Backspace,) => {
let mut debug_trait_builder = f.debug_tuple("Backspace");
debug_trait_builder.finish()
}
(&KeyCode::Insert,) => {
let mut debug_trait_builder = f.debug_tuple("Insert");
debug_trait_builder.finish()
}
(&KeyCode::Delete,) => {
let mut debug_trait_builder = f.debug_tuple("Delete");
debug_trait_builder.finish()
}
(&KeyCode::Right,) => {
let mut debug_trait_builder = f.debug_tuple("Right");
debug_trait_builder.finish()
}
(&KeyCode::Left,) => {
let mut debug_trait_builder = f.debug_tuple("Left");
debug_trait_builder.finish()
}
(&KeyCode::Down,) => {
let mut debug_trait_builder = f.debug_tuple("Down");
debug_trait_builder.finish()
}
(&KeyCode::Up,) => {
let mut debug_trait_builder = f.debug_tuple("Up");
debug_trait_builder.finish()
}
(&KeyCode::PageUp,) => {
let mut debug_trait_builder = f.debug_tuple("PageUp");
debug_trait_builder.finish()
}
(&KeyCode::PageDown,) => {
let mut debug_trait_builder = f.debug_tuple("PageDown");
debug_trait_builder.finish()
}
(&KeyCode::Home,) => {
let mut debug_trait_builder = f.debug_tuple("Home");
debug_trait_builder.finish()
}
(&KeyCode::End,) => {
let mut debug_trait_builder = f.debug_tuple("End");
debug_trait_builder.finish()
}
(&KeyCode::CapsLock,) => {
let mut debug_trait_builder = f.debug_tuple("CapsLock");
debug_trait_builder.finish()
}
(&KeyCode::ScrollLock,) => {
let mut debug_trait_builder = f.debug_tuple("ScrollLock");
debug_trait_builder.finish()
}
(&KeyCode::NumLock,) => {
let mut debug_trait_builder = f.debug_tuple("NumLock");
debug_trait_builder.finish()
}
(&KeyCode::PrintScreen,) => {
let mut debug_trait_builder = f.debug_tuple("PrintScreen");
debug_trait_builder.finish()
}
(&KeyCode::Pause,) => {
let mut debug_trait_builder = f.debug_tuple("Pause");
debug_trait_builder.finish()
}
(&KeyCode::F1,) => {
let mut debug_trait_builder = f.debug_tuple("F1");
debug_trait_builder.finish()
}
(&KeyCode::F2,) => {
let mut debug_trait_builder = f.debug_tuple("F2");
debug_trait_builder.finish()
}
(&KeyCode::F3,) => {
let mut debug_trait_builder = f.debug_tuple("F3");
debug_trait_builder.finish()
}
(&KeyCode::F4,) => {
let mut debug_trait_builder = f.debug_tuple("F4");
debug_trait_builder.finish()
}
(&KeyCode::F5,) => {
let mut debug_trait_builder = f.debug_tuple("F5");
debug_trait_builder.finish()
}
(&KeyCode::F6,) => {
let mut debug_trait_builder = f.debug_tuple("F6");
debug_trait_builder.finish()
}
(&KeyCode::F7,) => {
let mut debug_trait_builder = f.debug_tuple("F7");
debug_trait_builder.finish()
}
(&KeyCode::F8,) => {
let mut debug_trait_builder = f.debug_tuple("F8");
debug_trait_builder.finish()
}
(&KeyCode::F9,) => {
let mut debug_trait_builder = f.debug_tuple("F9");
debug_trait_builder.finish()
}
(&KeyCode::F10,) => {
let mut debug_trait_builder = f.debug_tuple("F10");
debug_trait_builder.finish()
}
(&KeyCode::F11,) => {
let mut debug_trait_builder = f.debug_tuple("F11");
debug_trait_builder.finish()
}
(&KeyCode::F12,) => {
let mut debug_trait_builder = f.debug_tuple("F12");
debug_trait_builder.finish()
}
(&KeyCode::F13,) => {
let mut debug_trait_builder = f.debug_tuple("F13");
debug_trait_builder.finish()
}
(&KeyCode::F14,) => {
let mut debug_trait_builder = f.debug_tuple("F14");
debug_trait_builder.finish()
}
(&KeyCode::F15,) => {
let mut debug_trait_builder = f.debug_tuple("F15");
debug_trait_builder.finish()
}
(&KeyCode::F16,) => {
let mut debug_trait_builder = f.debug_tuple("F16");
debug_trait_builder.finish()
}
(&KeyCode::F17,) => {
let mut debug_trait_builder = f.debug_tuple("F17");
debug_trait_builder.finish()
}
(&KeyCode::F18,) => {
let mut debug_trait_builder = f.debug_tuple("F18");
debug_trait_builder.finish()
}
(&KeyCode::F19,) => {
let mut debug_trait_builder = f.debug_tuple("F19");
debug_trait_builder.finish()
}
(&KeyCode::F20,) => {
let mut debug_trait_builder = f.debug_tuple("F20");
debug_trait_builder.finish()
}
(&KeyCode::F21,) => {
let mut debug_trait_builder = f.debug_tuple("F21");
debug_trait_builder.finish()
}
(&KeyCode::F22,) => {
let mut debug_trait_builder = f.debug_tuple("F22");
debug_trait_builder.finish()
}
(&KeyCode::F23,) => {
let mut debug_trait_builder = f.debug_tuple("F23");
debug_trait_builder.finish()
}
(&KeyCode::F24,) => {
let mut debug_trait_builder = f.debug_tuple("F24");
debug_trait_builder.finish()
}
(&KeyCode::F25,) => {
let mut debug_trait_builder = f.debug_tuple("F25");
debug_trait_builder.finish()
}
(&KeyCode::Kp0,) => {
let mut debug_trait_builder = f.debug_tuple("Kp0");
debug_trait_builder.finish()
}
(&KeyCode::Kp1,) => {
let mut debug_trait_builder = f.debug_tuple("Kp1");
debug_trait_builder.finish()
}
(&KeyCode::Kp2,) => {
let mut debug_trait_builder = f.debug_tuple("Kp2");
debug_trait_builder.finish()
}
(&KeyCode::Kp3,) => {
let mut debug_trait_builder = f.debug_tuple("Kp3");
debug_trait_builder.finish()
}
(&KeyCode::Kp4,) => {
let mut debug_trait_builder = f.debug_tuple("Kp4");
debug_trait_builder.finish()
}
(&KeyCode::Kp5,) => {
let mut debug_trait_builder = f.debug_tuple("Kp5");
debug_trait_builder.finish()
}
(&KeyCode::Kp6,) => {
let mut debug_trait_builder = f.debug_tuple("Kp6");
debug_trait_builder.finish()
}
(&KeyCode::Kp7,) => {
let mut debug_trait_builder = f.debug_tuple("Kp7");
debug_trait_builder.finish()
}
(&KeyCode::Kp8,) => {
let mut debug_trait_builder = f.debug_tuple("Kp8");
debug_trait_builder.finish()
}
(&KeyCode::Kp9,) => {
let mut debug_trait_builder = f.debug_tuple("Kp9");
debug_trait_builder.finish()
}
(&KeyCode::KpDecimal,) => {
let mut debug_trait_builder = f.debug_tuple("KpDecimal");
debug_trait_builder.finish()
}
(&KeyCode::KpDivide,) => {
let mut debug_trait_builder = f.debug_tuple("KpDivide");
debug_trait_builder.finish()
}
(&KeyCode::KpMultiply,) => {
let mut debug_trait_builder = f.debug_tuple("KpMultiply");
debug_trait_builder.finish()
}
(&KeyCode::KpSubtract,) => {
let mut debug_trait_builder = f.debug_tuple("KpSubtract");
debug_trait_builder.finish()
}
(&KeyCode::KpAdd,) => {
let mut debug_trait_builder = f.debug_tuple("KpAdd");
debug_trait_builder.finish()
}
(&KeyCode::KpEnter,) => {
let mut debug_trait_builder = f.debug_tuple("KpEnter");
debug_trait_builder.finish()
}
(&KeyCode::KpEqual,) => {
let mut debug_trait_builder = f.debug_tuple("KpEqual");
debug_trait_builder.finish()
}
(&KeyCode::LeftShift,) => {
let mut debug_trait_builder = f.debug_tuple("LeftShift");
debug_trait_builder.finish()
}
(&KeyCode::LeftControl,) => {
let mut debug_trait_builder = f.debug_tuple("LeftControl");
debug_trait_builder.finish()
}
(&KeyCode::LeftAlt,) => {
let mut debug_trait_builder = f.debug_tuple("LeftAlt");
debug_trait_builder.finish()
}
(&KeyCode::LeftSuper,) => {
let mut debug_trait_builder = f.debug_tuple("LeftSuper");
debug_trait_builder.finish()
}
(&KeyCode::RightShift,) => {
let mut debug_trait_builder = f.debug_tuple("RightShift");
debug_trait_builder.finish()
}
(&KeyCode::RightControl,) => {
let mut debug_trait_builder = f.debug_tuple("RightControl");
debug_trait_builder.finish()
}
(&KeyCode::RightAlt,) => {
let mut debug_trait_builder = f.debug_tuple("RightAlt");
debug_trait_builder.finish()
}
(&KeyCode::RightSuper,) => {
let mut debug_trait_builder = f.debug_tuple("RightSuper");
debug_trait_builder.finish()
}
(&KeyCode::Menu,) => {
let mut debug_trait_builder = f.debug_tuple("Menu");
debug_trait_builder.finish()
}
(&KeyCode::Unknown,) => {
let mut debug_trait_builder = f.debug_tuple("Unknown");
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for KeyCode {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for KeyCode {
#[inline]
fn clone(&self) -> KeyCode {
{
*self
}
}
}
impl ::core::marker::StructuralPartialEq for KeyCode {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for KeyCode {
#[inline]
fn eq(&self, other: &KeyCode) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as u32;
let __arg_1_vi = unsafe { ::core::intrinsics::discriminant_value(&*other) } as u32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::hash::Hash for KeyCode {
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
match (&*self,) {
_ => ::core::hash::Hash::hash(
&unsafe { ::core::intrinsics::discriminant_value(self) },
state,
),
}
}
}
impl ::core::marker::StructuralEq for KeyCode {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for KeyCode {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
impl From<sapp_keycode> for KeyCode {
fn from(key_code: sapp_keycode) -> KeyCode {
match key_code {
sapp::sapp_keycode_SAPP_KEYCODE_SPACE => KeyCode::Space,
sapp::sapp_keycode_SAPP_KEYCODE_APOSTROPHE => KeyCode::Apostrophe,
sapp::sapp_keycode_SAPP_KEYCODE_COMMA => KeyCode::Comma,
sapp::sapp_keycode_SAPP_KEYCODE_MINUS => KeyCode::Minus,
sapp::sapp_keycode_SAPP_KEYCODE_PERIOD => KeyCode::Period,
sapp::sapp_keycode_SAPP_KEYCODE_SLASH => KeyCode::Slash,
sapp::sapp_keycode_SAPP_KEYCODE_0 => KeyCode::Key0,
sapp::sapp_keycode_SAPP_KEYCODE_1 => KeyCode::Key1,
sapp::sapp_keycode_SAPP_KEYCODE_2 => KeyCode::Key2,
sapp::sapp_keycode_SAPP_KEYCODE_3 => KeyCode::Key3,
sapp::sapp_keycode_SAPP_KEYCODE_4 => KeyCode::Key4,
sapp::sapp_keycode_SAPP_KEYCODE_5 => KeyCode::Key5,
sapp::sapp_keycode_SAPP_KEYCODE_6 => KeyCode::Key6,
sapp::sapp_keycode_SAPP_KEYCODE_7 => KeyCode::Key7,
sapp::sapp_keycode_SAPP_KEYCODE_8 => KeyCode::Key8,
sapp::sapp_keycode_SAPP_KEYCODE_9 => KeyCode::Key9,
sapp::sapp_keycode_SAPP_KEYCODE_SEMICOLON => KeyCode::Semicolon,
sapp::sapp_keycode_SAPP_KEYCODE_EQUAL => KeyCode::Equal,
sapp::sapp_keycode_SAPP_KEYCODE_A => KeyCode::A,
sapp::sapp_keycode_SAPP_KEYCODE_B => KeyCode::B,
sapp::sapp_keycode_SAPP_KEYCODE_C => KeyCode::C,
sapp::sapp_keycode_SAPP_KEYCODE_D => KeyCode::D,
sapp::sapp_keycode_SAPP_KEYCODE_E => KeyCode::E,
sapp::sapp_keycode_SAPP_KEYCODE_F => KeyCode::F,
sapp::sapp_keycode_SAPP_KEYCODE_G => KeyCode::G,
sapp::sapp_keycode_SAPP_KEYCODE_H => KeyCode::H,
sapp::sapp_keycode_SAPP_KEYCODE_I => KeyCode::I,
sapp::sapp_keycode_SAPP_KEYCODE_J => KeyCode::J,
sapp::sapp_keycode_SAPP_KEYCODE_K => KeyCode::K,
sapp::sapp_keycode_SAPP_KEYCODE_L => KeyCode::L,
sapp::sapp_keycode_SAPP_KEYCODE_M => KeyCode::M,
sapp::sapp_keycode_SAPP_KEYCODE_N => KeyCode::N,
sapp::sapp_keycode_SAPP_KEYCODE_O => KeyCode::O,
sapp::sapp_keycode_SAPP_KEYCODE_P => KeyCode::P,
sapp::sapp_keycode_SAPP_KEYCODE_Q => KeyCode::Q,
sapp::sapp_keycode_SAPP_KEYCODE_R => KeyCode::R,
sapp::sapp_keycode_SAPP_KEYCODE_S => KeyCode::S,
sapp::sapp_keycode_SAPP_KEYCODE_T => KeyCode::T,
sapp::sapp_keycode_SAPP_KEYCODE_U => KeyCode::U,
sapp::sapp_keycode_SAPP_KEYCODE_V => KeyCode::V,
sapp::sapp_keycode_SAPP_KEYCODE_W => KeyCode::W,
sapp::sapp_keycode_SAPP_KEYCODE_X => KeyCode::X,
sapp::sapp_keycode_SAPP_KEYCODE_Y => KeyCode::Y,
sapp::sapp_keycode_SAPP_KEYCODE_Z => KeyCode::Z,
sapp::sapp_keycode_SAPP_KEYCODE_LEFT_BRACKET => KeyCode::LeftBracket,
sapp::sapp_keycode_SAPP_KEYCODE_BACKSLASH => KeyCode::Backslash,
sapp::sapp_keycode_SAPP_KEYCODE_RIGHT_BRACKET => KeyCode::RightBracket,
sapp::sapp_keycode_SAPP_KEYCODE_GRAVE_ACCENT => KeyCode::GraveAccent,
sapp::sapp_keycode_SAPP_KEYCODE_WORLD_1 => KeyCode::World1,
sapp::sapp_keycode_SAPP_KEYCODE_WORLD_2 => KeyCode::World2,
sapp::sapp_keycode_SAPP_KEYCODE_ESCAPE => KeyCode::Escape,
sapp::sapp_keycode_SAPP_KEYCODE_ENTER => KeyCode::Enter,
sapp::sapp_keycode_SAPP_KEYCODE_TAB => KeyCode::Tab,
sapp::sapp_keycode_SAPP_KEYCODE_BACKSPACE => KeyCode::Backspace,
sapp::sapp_keycode_SAPP_KEYCODE_INSERT => KeyCode::Insert,
sapp::sapp_keycode_SAPP_KEYCODE_DELETE => KeyCode::Delete,
sapp::sapp_keycode_SAPP_KEYCODE_RIGHT => KeyCode::Right,
sapp::sapp_keycode_SAPP_KEYCODE_LEFT => KeyCode::Left,
sapp::sapp_keycode_SAPP_KEYCODE_DOWN => KeyCode::Down,
sapp::sapp_keycode_SAPP_KEYCODE_UP => KeyCode::Up,
sapp::sapp_keycode_SAPP_KEYCODE_PAGE_UP => KeyCode::PageUp,
sapp::sapp_keycode_SAPP_KEYCODE_PAGE_DOWN => KeyCode::PageDown,
sapp::sapp_keycode_SAPP_KEYCODE_HOME => KeyCode::Home,
sapp::sapp_keycode_SAPP_KEYCODE_END => KeyCode::End,
sapp::sapp_keycode_SAPP_KEYCODE_CAPS_LOCK => KeyCode::CapsLock,
sapp::sapp_keycode_SAPP_KEYCODE_SCROLL_LOCK => KeyCode::ScrollLock,
sapp::sapp_keycode_SAPP_KEYCODE_NUM_LOCK => KeyCode::NumLock,
sapp::sapp_keycode_SAPP_KEYCODE_PRINT_SCREEN => KeyCode::PrintScreen,
sapp::sapp_keycode_SAPP_KEYCODE_PAUSE => KeyCode::Pause,
sapp::sapp_keycode_SAPP_KEYCODE_F1 => KeyCode::F1,
sapp::sapp_keycode_SAPP_KEYCODE_F2 => KeyCode::F2,
sapp::sapp_keycode_SAPP_KEYCODE_F3 => KeyCode::F3,
sapp::sapp_keycode_SAPP_KEYCODE_F4 => KeyCode::F4,
sapp::sapp_keycode_SAPP_KEYCODE_F5 => KeyCode::F5,
sapp::sapp_keycode_SAPP_KEYCODE_F6 => KeyCode::F6,
sapp::sapp_keycode_SAPP_KEYCODE_F7 => KeyCode::F7,
sapp::sapp_keycode_SAPP_KEYCODE_F8 => KeyCode::F8,
sapp::sapp_keycode_SAPP_KEYCODE_F9 => KeyCode::F9,
sapp::sapp_keycode_SAPP_KEYCODE_F10 => KeyCode::F10,
sapp::sapp_keycode_SAPP_KEYCODE_F11 => KeyCode::F11,
sapp::sapp_keycode_SAPP_KEYCODE_F12 => KeyCode::F12,
sapp::sapp_keycode_SAPP_KEYCODE_F13 => KeyCode::F13,
sapp::sapp_keycode_SAPP_KEYCODE_F14 => KeyCode::F14,
sapp::sapp_keycode_SAPP_KEYCODE_F15 => KeyCode::F15,
sapp::sapp_keycode_SAPP_KEYCODE_F16 => KeyCode::F16,
sapp::sapp_keycode_SAPP_KEYCODE_F17 => KeyCode::F17,
sapp::sapp_keycode_SAPP_KEYCODE_F18 => KeyCode::F18,
sapp::sapp_keycode_SAPP_KEYCODE_F19 => KeyCode::F19,
sapp::sapp_keycode_SAPP_KEYCODE_F20 => KeyCode::F20,
sapp::sapp_keycode_SAPP_KEYCODE_F21 => KeyCode::F21,
sapp::sapp_keycode_SAPP_KEYCODE_F22 => KeyCode::F22,
sapp::sapp_keycode_SAPP_KEYCODE_F23 => KeyCode::F23,
sapp::sapp_keycode_SAPP_KEYCODE_F24 => KeyCode::F24,
sapp::sapp_keycode_SAPP_KEYCODE_F25 => KeyCode::F25,
sapp::sapp_keycode_SAPP_KEYCODE_KP_0 => KeyCode::Kp0,
sapp::sapp_keycode_SAPP_KEYCODE_KP_1 => KeyCode::Kp1,
sapp::sapp_keycode_SAPP_KEYCODE_KP_2 => KeyCode::Kp2,
sapp::sapp_keycode_SAPP_KEYCODE_KP_3 => KeyCode::Kp3,
sapp::sapp_keycode_SAPP_KEYCODE_KP_4 => KeyCode::Kp4,
sapp::sapp_keycode_SAPP_KEYCODE_KP_5 => KeyCode::Kp5,
sapp::sapp_keycode_SAPP_KEYCODE_KP_6 => KeyCode::Kp6,
sapp::sapp_keycode_SAPP_KEYCODE_KP_7 => KeyCode::Kp7,
sapp::sapp_keycode_SAPP_KEYCODE_KP_8 => KeyCode::Kp8,
sapp::sapp_keycode_SAPP_KEYCODE_KP_9 => KeyCode::Kp9,
sapp::sapp_keycode_SAPP_KEYCODE_KP_DECIMAL => KeyCode::KpDecimal,
sapp::sapp_keycode_SAPP_KEYCODE_KP_DIVIDE => KeyCode::KpDivide,
sapp::sapp_keycode_SAPP_KEYCODE_KP_MULTIPLY => KeyCode::KpMultiply,
sapp::sapp_keycode_SAPP_KEYCODE_KP_SUBTRACT => KeyCode::KpSubtract,
sapp::sapp_keycode_SAPP_KEYCODE_KP_ADD => KeyCode::KpAdd,
sapp::sapp_keycode_SAPP_KEYCODE_KP_ENTER => KeyCode::KpEnter,
sapp::sapp_keycode_SAPP_KEYCODE_KP_EQUAL => KeyCode::KpEqual,
sapp::sapp_keycode_SAPP_KEYCODE_LEFT_SHIFT => KeyCode::LeftShift,
sapp::sapp_keycode_SAPP_KEYCODE_LEFT_CONTROL => KeyCode::LeftControl,
sapp::sapp_keycode_SAPP_KEYCODE_LEFT_ALT => KeyCode::LeftAlt,
sapp::sapp_keycode_SAPP_KEYCODE_LEFT_SUPER => KeyCode::LeftSuper,
sapp::sapp_keycode_SAPP_KEYCODE_RIGHT_SHIFT => KeyCode::RightShift,
sapp::sapp_keycode_SAPP_KEYCODE_RIGHT_CONTROL => KeyCode::RightControl,
sapp::sapp_keycode_SAPP_KEYCODE_RIGHT_ALT => KeyCode::RightAlt,
sapp::sapp_keycode_SAPP_KEYCODE_RIGHT_SUPER => KeyCode::RightSuper,
sapp::sapp_keycode_SAPP_KEYCODE_MENU => KeyCode::Menu,
_ => KeyCode::Unknown,
}
}
}
pub struct KeyMods {
pub shift: bool,
pub ctrl: bool,
pub alt: bool,
pub logo: bool,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for KeyMods {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
KeyMods {
shift: ref __self_0_0,
ctrl: ref __self_0_1,
alt: ref __self_0_2,
logo: ref __self_0_3,
} => {
let mut debug_trait_builder = f.debug_struct("KeyMods");
let _ = debug_trait_builder.field("shift", &&(*__self_0_0));
let _ = debug_trait_builder.field("ctrl", &&(*__self_0_1));
let _ = debug_trait_builder.field("alt", &&(*__self_0_2));
let _ = debug_trait_builder.field("logo", &&(*__self_0_3));
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for KeyMods {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for KeyMods {
#[inline]
fn clone(&self) -> KeyMods {
{
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<bool>;
*self
}
}
}
impl ::core::marker::StructuralPartialEq for KeyMods {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for KeyMods {
#[inline]
fn eq(&self, other: &KeyMods) -> bool {
match *other {
KeyMods {
shift: ref __self_1_0,
ctrl: ref __self_1_1,
alt: ref __self_1_2,
logo: ref __self_1_3,
} => match *self {
KeyMods {
shift: ref __self_0_0,
ctrl: ref __self_0_1,
alt: ref __self_0_2,
logo: ref __self_0_3,
} => {
(*__self_0_0) == (*__self_1_0)
&& (*__self_0_1) == (*__self_1_1)
&& (*__self_0_2) == (*__self_1_2)
&& (*__self_0_3) == (*__self_1_3)
}
},
}
}
#[inline]
fn ne(&self, other: &KeyMods) -> bool {
match *other {
KeyMods {
shift: ref __self_1_0,
ctrl: ref __self_1_1,
alt: ref __self_1_2,
logo: ref __self_1_3,
} => match *self {
KeyMods {
shift: ref __self_0_0,
ctrl: ref __self_0_1,
alt: ref __self_0_2,
logo: ref __self_0_3,
} => {
(*__self_0_0) != (*__self_1_0)
|| (*__self_0_1) != (*__self_1_1)
|| (*__self_0_2) != (*__self_1_2)
|| (*__self_0_3) != (*__self_1_3)
}
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::default::Default for KeyMods {
#[inline]
fn default() -> KeyMods {
KeyMods {
shift: ::core::default::Default::default(),
ctrl: ::core::default::Default::default(),
alt: ::core::default::Default::default(),
logo: ::core::default::Default::default(),
}
}
}
impl From<u32> for KeyMods {
fn from(value: u32) -> KeyMods {
let mut key_mods = KeyMods::default();
if value & sapp::SAPP_MODIFIER_SHIFT != 0 {
key_mods.shift = true;
}
if value & sapp::SAPP_MODIFIER_CTRL != 0 {
key_mods.ctrl = true;
}
if value & sapp::SAPP_MODIFIER_ALT != 0 {
key_mods.alt = true;
}
if value & sapp::SAPP_MODIFIER_SUPER != 0 {
key_mods.logo = true;
}
key_mods
}
}
pub enum TouchPhase {
Started,
Moved,
Ended,
Cancelled,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for TouchPhase {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&TouchPhase::Started,) => {
let mut debug_trait_builder = f.debug_tuple("Started");
debug_trait_builder.finish()
}
(&TouchPhase::Moved,) => {
let mut debug_trait_builder = f.debug_tuple("Moved");
debug_trait_builder.finish()
}
(&TouchPhase::Ended,) => {
let mut debug_trait_builder = f.debug_tuple("Ended");
debug_trait_builder.finish()
}
(&TouchPhase::Cancelled,) => {
let mut debug_trait_builder = f.debug_tuple("Cancelled");
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::hash::Hash for TouchPhase {
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
match (&*self,) {
_ => ::core::hash::Hash::hash(
&unsafe { ::core::intrinsics::discriminant_value(self) },
state,
),
}
}
}
impl ::core::marker::StructuralPartialEq for TouchPhase {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for TouchPhase {
#[inline]
fn eq(&self, other: &TouchPhase) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for TouchPhase {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for TouchPhase {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for TouchPhase {
#[inline]
fn clone(&self) -> TouchPhase {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for TouchPhase {}
impl From<u32> for TouchPhase {
fn from(event: u32) -> TouchPhase {
match event {
sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_BEGAN => TouchPhase::Started,
sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_ENDED => TouchPhase::Ended,
sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_CANCELLED => TouchPhase::Cancelled,
sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_MOVED => TouchPhase::Moved,
_ => ::std::rt::begin_panic("internal error: entered unreachable code"),
}
}
}
pub trait EventHandler {
fn update(&mut self, _ctx: &mut Context);
fn draw(&mut self, _ctx: &mut Context);
fn resize_event(&mut self, _ctx: &mut Context, _width: f32, _height: f32) {}
fn mouse_motion_event(&mut self, _ctx: &mut Context, _x: f32, _y: f32) {}
fn mouse_wheel_event(&mut self, _ctx: &mut Context, _x: f32, _y: f32) {}
fn mouse_button_down_event(
&mut self,
_ctx: &mut Context,
_button: MouseButton,
_x: f32,
_y: f32,
) {
}
fn mouse_button_up_event(
&mut self,
_ctx: &mut Context,
_button: MouseButton,
_x: f32,
_y: f32,
) {
}
fn char_event(
&mut self,
_ctx: &mut Context,
_character: char,
_keymods: KeyMods,
_repeat: bool,
) {
}
fn key_down_event(
&mut self,
_ctx: &mut Context,
_keycode: KeyCode,
_keymods: KeyMods,
_repeat: bool,
) {
}
fn key_up_event(&mut self, _ctx: &mut Context, _keycode: KeyCode, _keymods: KeyMods) {}
fn touch_event(&mut self, ctx: &mut Context, phase: TouchPhase, _id: u64, x: f32, y: f32) {
if phase == TouchPhase::Started {
self.mouse_button_down_event(ctx, MouseButton::Left, x, y);
}
if phase == TouchPhase::Ended {
self.mouse_button_up_event(ctx, MouseButton::Left, x, y);
}
}
fn raw_mouse_motion(&mut self, _ctx: &mut Context, _dx: f32, _dy: f32) {}
fn quit_requested_event(&mut self, _ctx: &mut Context) {}
}
pub trait EventHandlerFree {
fn update(&mut self);
fn draw(&mut self);
fn resize_event(&mut self, _width: f32, _height: f32) {}
fn mouse_motion_event(&mut self, _x: f32, _y: f32) {}
fn mouse_wheel_event(&mut self, _x: f32, _y: f32) {}
fn mouse_button_down_event(&mut self, _button: MouseButton, _x: f32, _y: f32) {}
fn mouse_button_up_event(&mut self, _button: MouseButton, _x: f32, _y: f32) {}
fn char_event(&mut self, _character: char, _keymods: KeyMods, _repeat: bool) {}
fn key_down_event(&mut self, _keycode: KeyCode, _keymods: KeyMods, _repeat: bool) {}
fn key_up_event(&mut self, _keycode: KeyCode, _keymods: KeyMods) {}
fn touch_event(&mut self, phase: TouchPhase, _id: u64, x: f32, y: f32) {
if phase == TouchPhase::Started {
self.mouse_button_down_event(MouseButton::Left, x, y);
}
if phase == TouchPhase::Ended {
self.mouse_button_up_event(MouseButton::Left, x, y);
}
}
fn raw_mouse_motion(&mut self, _dx: f32, _dy: f32) {}
fn quit_requested_event(&mut self) {}
}
}
pub mod fs {
pub enum Error {
IOError(std::io::Error),
DownloadFailed,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Error {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&Error::IOError(ref __self_0),) => {
let mut debug_trait_builder = f.debug_tuple("IOError");
let _ = debug_trait_builder.field(&&(*__self_0));
debug_trait_builder.finish()
}
(&Error::DownloadFailed,) => {
let mut debug_trait_builder = f.debug_tuple("DownloadFailed");
debug_trait_builder.finish()
}
}
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match *self {
_ => f.write_fmt(::core::fmt::Arguments::new_v1(
&["Error: "],
&match (&self,) {
(arg0,) => [::core::fmt::ArgumentV1::new(arg0, ::core::fmt::Debug::fmt)],
},
)),
}
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Error {
Error::IOError(e)
}
}
pub type Response = Result<Vec<u8>, Error>;
pub fn load_file<F: Fn(Response) + 'static>(path: &str, on_loaded: F) {
#[cfg(not(target_arch = "wasm32"))]
load_file_desktop(path, on_loaded);
}
#[cfg(not(target_arch = "wasm32"))]
fn load_file_desktop<F: Fn(Response)>(path: &str, on_loaded: F) {
fn load_file_sync(path: &str) -> Response {
use std::fs::File;
use std::io::Read;
let mut response = <[_]>::into_vec(box []);
let mut file = File::open(path)?;
file.read_to_end(&mut response)?;
Ok(response)
}
let response = load_file_sync(path);
on_loaded(response);
}
}
pub mod graphics {
use std::{ffi::CString, mem};
mod texture {
use crate::{sapp::*, Context};
pub struct Texture {
pub(crate) texture: GLuint,
pub width: u32,
pub height: u32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Texture {
#[inline]
fn clone(&self) -> Texture {
{
let _: ::core::clone::AssertParamIsClone<GLuint>;
let _: ::core::clone::AssertParamIsClone<u32>;
let _: ::core::clone::AssertParamIsClone<u32>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Texture {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Texture {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
Texture {
texture: ref __self_0_0,
width: ref __self_0_1,
height: ref __self_0_2,
} => {
let mut debug_trait_builder = f.debug_struct("Texture");
let _ = debug_trait_builder.field("texture", &&(*__self_0_0));
let _ = debug_trait_builder.field("width", &&(*__self_0_1));
let _ = debug_trait_builder.field("height", &&(*__self_0_2));
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for Texture {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for Texture {
#[inline]
fn eq(&self, other: &Texture) -> bool {
match *other {
Texture {
texture: ref __self_1_0,
width: ref __self_1_1,
height: ref __self_1_2,
} => match *self {
Texture {
texture: ref __self_0_0,
width: ref __self_0_1,
height: ref __self_0_2,
} => {
(*__self_0_0) == (*__self_1_0)
&& (*__self_0_1) == (*__self_1_1)
&& (*__self_0_2) == (*__self_1_2)
}
},
}
}
#[inline]
fn ne(&self, other: &Texture) -> bool {
match *other {
Texture {
texture: ref __self_1_0,
width: ref __self_1_1,
height: ref __self_1_2,
} => match *self {
Texture {
texture: ref __self_0_0,
width: ref __self_0_1,
height: ref __self_0_2,
} => {
(*__self_0_0) != (*__self_1_0)
|| (*__self_0_1) != (*__self_1_1)
|| (*__self_0_2) != (*__self_1_2)
}
},
}
}
}
impl Texture {
pub fn empty() -> Texture {
Texture {
texture: 0,
width: 0,
height: 0,
}
}
fn delete(&self) {
let res = {
unsafe {
glDeleteTextures(1, &self.texture as *const _);
}
};
res
}
}
pub enum RenderTextureFormat {
RGBA8,
Depth,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for RenderTextureFormat {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&RenderTextureFormat::RGBA8,) => {
let mut debug_trait_builder = f.debug_tuple("RGBA8");
debug_trait_builder.finish()
}
(&RenderTextureFormat::Depth,) => {
let mut debug_trait_builder = f.debug_tuple("Depth");
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for RenderTextureFormat {
#[inline]
fn clone(&self) -> RenderTextureFormat {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for RenderTextureFormat {}
impl ::core::marker::StructuralPartialEq for RenderTextureFormat {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for RenderTextureFormat {
#[inline]
fn eq(&self, other: &RenderTextureFormat) -> bool {
{
let __self_vi =
unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl From<RenderTextureFormat> for (GLenum, GLenum, GLenum) {
fn from(format: RenderTextureFormat) -> Self {
match format {
RenderTextureFormat::RGBA8 => (GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE),
RenderTextureFormat::Depth => {
(GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT)
}
}
}
}
#[repr(u8)]
pub enum TextureFormat {
RGB8,
RGBA8,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for TextureFormat {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&TextureFormat::RGB8,) => {
let mut debug_trait_builder = f.debug_tuple("RGB8");
debug_trait_builder.finish()
}
(&TextureFormat::RGBA8,) => {
let mut debug_trait_builder = f.debug_tuple("RGBA8");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for TextureFormat {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for TextureFormat {
#[inline]
fn eq(&self, other: &TextureFormat) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as u8;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as u8;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for TextureFormat {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for TextureFormat {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for TextureFormat {
#[inline]
fn clone(&self) -> TextureFormat {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for TextureFormat {}
impl From<TextureFormat> for (GLenum, GLenum, GLenum) {
fn from(format: TextureFormat) -> Self {
match format {
TextureFormat::RGB8 => (GL_RGB, GL_RGB, GL_UNSIGNED_BYTE),
TextureFormat::RGBA8 => (GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE),
}
}
}
impl TextureFormat {
pub fn size(self, width: u32, height: u32) -> u32 {
let square = width * height;
match self {
TextureFormat::RGB8 => 3 * square,
TextureFormat::RGBA8 => 4 * square,
}
}
}
impl Default for TextureParams {
fn default() -> Self {
TextureParams {
format: TextureFormat::RGBA8,
wrap: TextureWrap::Clamp,
filter: FilterMode::Linear,
width: 0,
height: 0,
}
}
}
#[repr(u8)]
pub enum TextureWrap {
Repeat,
Mirror,
Clamp,
MirrorClamp,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for TextureWrap {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&TextureWrap::Repeat,) => {
let mut debug_trait_builder = f.debug_tuple("Repeat");
debug_trait_builder.finish()
}
(&TextureWrap::Mirror,) => {
let mut debug_trait_builder = f.debug_tuple("Mirror");
debug_trait_builder.finish()
}
(&TextureWrap::Clamp,) => {
let mut debug_trait_builder = f.debug_tuple("Clamp");
debug_trait_builder.finish()
}
(&TextureWrap::MirrorClamp,) => {
let mut debug_trait_builder = f.debug_tuple("MirrorClamp");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for TextureWrap {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for TextureWrap {
#[inline]
fn eq(&self, other: &TextureWrap) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as u8;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as u8;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for TextureWrap {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for TextureWrap {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for TextureWrap {
#[inline]
fn clone(&self) -> TextureWrap {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for TextureWrap {}
pub enum FilterMode {
Linear = GL_LINEAR as isize,
Nearest = GL_NEAREST as isize,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for FilterMode {
#[inline]
fn clone(&self) -> FilterMode {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for FilterMode {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for FilterMode {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&FilterMode::Linear,) => {
let mut debug_trait_builder = f.debug_tuple("Linear");
debug_trait_builder.finish()
}
(&FilterMode::Nearest,) => {
let mut debug_trait_builder = f.debug_tuple("Nearest");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for FilterMode {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for FilterMode {
#[inline]
fn eq(&self, other: &FilterMode) -> bool {
{
let __self_vi =
unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
pub struct TextureParams {
pub format: TextureFormat,
pub wrap: TextureWrap,
pub filter: FilterMode,
pub width: u32,
pub height: u32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for TextureParams {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
TextureParams {
format: ref __self_0_0,
wrap: ref __self_0_1,
filter: ref __self_0_2,
width: ref __self_0_3,
height: ref __self_0_4,
} => {
let mut debug_trait_builder = f.debug_struct("TextureParams");
let _ = debug_trait_builder.field("format", &&(*__self_0_0));
let _ = debug_trait_builder.field("wrap", &&(*__self_0_1));
let _ = debug_trait_builder.field("filter", &&(*__self_0_2));
let _ = debug_trait_builder.field("width", &&(*__self_0_3));
let _ = debug_trait_builder.field("height", &&(*__self_0_4));
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for TextureParams {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for TextureParams {
#[inline]
fn clone(&self) -> TextureParams {
{
let _: ::core::clone::AssertParamIsClone<TextureFormat>;
let _: ::core::clone::AssertParamIsClone<TextureWrap>;
let _: ::core::clone::AssertParamIsClone<FilterMode>;
let _: ::core::clone::AssertParamIsClone<u32>;
let _: ::core::clone::AssertParamIsClone<u32>;
*self
}
}
}
pub struct RenderTextureParams {
pub format: RenderTextureFormat,
pub wrap: TextureWrap,
pub filter: FilterMode,
pub width: u32,
pub height: u32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for RenderTextureParams {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
RenderTextureParams {
format: ref __self_0_0,
wrap: ref __self_0_1,
filter: ref __self_0_2,
width: ref __self_0_3,
height: ref __self_0_4,
} => {
let mut debug_trait_builder = f.debug_struct("RenderTextureParams");
let _ = debug_trait_builder.field("format", &&(*__self_0_0));
let _ = debug_trait_builder.field("wrap", &&(*__self_0_1));
let _ = debug_trait_builder.field("filter", &&(*__self_0_2));
let _ = debug_trait_builder.field("width", &&(*__self_0_3));
let _ = debug_trait_builder.field("height", &&(*__self_0_4));
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for RenderTextureParams {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for RenderTextureParams {
#[inline]
fn clone(&self) -> RenderTextureParams {
{
let _: ::core::clone::AssertParamIsClone<RenderTextureFormat>;
let _: ::core::clone::AssertParamIsClone<TextureWrap>;
let _: ::core::clone::AssertParamIsClone<FilterMode>;
let _: ::core::clone::AssertParamIsClone<u32>;
let _: ::core::clone::AssertParamIsClone<u32>;
*self
}
}
}
impl Default for RenderTextureParams {
fn default() -> Self {
RenderTextureParams {
format: RenderTextureFormat::RGBA8,
wrap: TextureWrap::Clamp,
filter: FilterMode::Linear,
width: 0,
height: 0,
}
}
}
impl Texture {
fn new_render_texture(ctx: &mut Context, params: RenderTextureParams) {
()
}
fn from_data_and_format(ctx: &mut Context, bytes: &[u8], params: TextureParams) {
()
}
pub fn from_rgba8(ctx: &mut Context, width: u16, height: u16, bytes: &[u8]) -> Texture {
{
match (&(width as usize * height as usize * 4), &bytes.len()) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
{
::std::rt::begin_panic_fmt(&::core::fmt::Arguments::new_v1(
&[
"assertion failed: `(left == right)`\n left: `",
"`,\n right: `",
"`",
],
&match (&&*left_val, &&*right_val) {
(arg0, arg1) => [
::core::fmt::ArgumentV1::new(
arg0,
::core::fmt::Debug::fmt,
),
::core::fmt::ArgumentV1::new(
arg1,
::core::fmt::Debug::fmt,
),
],
},
))
}
}
}
}
};
Self::from_data_and_format(
ctx,
bytes,
TextureParams {
width: width as _,
height: height as _,
format: TextureFormat::RGBA8,
wrap: TextureWrap::Clamp,
filter: FilterMode::Linear,
},
)
}
fn set_filter(&self, ctx: &mut Context, filter: FilterMode) {
let res = {
ctx.cache.store_texture_binding(0);
ctx.cache.bind_texture(0, self.texture);
unsafe {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter as i32);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter as i32);
}
ctx.cache.restore_texture_binding(0);
};
res
}
pub fn update(&self, ctx: &mut Context, bytes: &[u8]) {
{
match (
&(self.width as usize * self.height as usize * 4),
&bytes.len(),
) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
{
::std::rt::begin_panic_fmt(&::core::fmt::Arguments::new_v1(
&[
"assertion failed: `(left == right)`\n left: `",
"`,\n right: `",
"`",
],
&match (&&*left_val, &&*right_val) {
(arg0, arg1) => [
::core::fmt::ArgumentV1::new(
arg0,
::core::fmt::Debug::fmt,
),
::core::fmt::ArgumentV1::new(
arg1,
::core::fmt::Debug::fmt,
),
],
},
))
}
}
}
}
};
self.update_texture_part(
ctx,
0 as _,
0 as _,
self.width as _,
self.height as _,
bytes,
)
}
fn update_texture_part(
&self,
ctx: &mut Context,
x_offset: i32,
y_offset: i32,
width: i32,
height: i32,
bytes: &[u8],
) {
let res = {
{
match (&(width as usize * height as usize * 4), &bytes.len()) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
{
::std::rt::begin_panic_fmt(&::core::fmt::Arguments::new_v1(
&[
"assertion failed: `(left == right)`\n left: `",
"`,\n right: `",
"`",
],
&match (&&*left_val, &&*right_val) {
(arg0, arg1) => [
::core::fmt::ArgumentV1::new(
arg0,
::core::fmt::Debug::fmt,
),
::core::fmt::ArgumentV1::new(
arg1,
::core::fmt::Debug::fmt,
),
],
},
))
}
}
}
}
};
if !(x_offset + width <= self.width as _) {
{
::std::rt::begin_panic(
"assertion failed: x_offset + width <= self.width as _",
)
}
};
if !(y_offset + height <= self.height as _) {
{
::std::rt::begin_panic(
"assertion failed: y_offset + height <= self.height as _",
)
}
};
ctx.cache.store_texture_binding(0);
ctx.cache.bind_texture(0, self.texture);
unsafe {
glTexSubImage2D(
GL_TEXTURE_2D,
0,
x_offset as _,
y_offset as _,
width as _,
height as _,
GL_RGBA,
GL_UNSIGNED_BYTE,
bytes.as_ptr() as *const _,
);
}
ctx.cache.restore_texture_binding(0);
};
res
}
}
}
use crate::sapp::*;
use std::option::Option::None;
pub use texture::{
FilterMode, RenderTextureFormat, RenderTextureParams, Texture, TextureFormat, TextureParams,
};
fn get_uniform_location(program: GLuint, name: &str) -> i32 {
let cname = CString::new(name).unwrap_or_else(|e| ::std::rt::begin_panic(e));
let location = unsafe { glGetUniformLocation(program, cname.as_ptr()) };
if !(location != -1) {
{
::std::rt::begin_panic({
let res = ::alloc::fmt::format(::core::fmt::Arguments::new_v1(
&["Cant get \"", "\" uniform location"],
&match (&name,) {
(arg0,) => [::core::fmt::ArgumentV1::new(
arg0,
::core::fmt::Display::fmt,
)],
},
));
res
})
}
};
location
}
pub enum UniformType {
Float1,
Float2,
Float3,
Float4,
Mat4,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for UniformType {
#[inline]
fn clone(&self) -> UniformType {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for UniformType {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for UniformType {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&UniformType::Float1,) => {
let mut debug_trait_builder = f.debug_tuple("Float1");
debug_trait_builder.finish()
}
(&UniformType::Float2,) => {
let mut debug_trait_builder = f.debug_tuple("Float2");
debug_trait_builder.finish()
}
(&UniformType::Float3,) => {
let mut debug_trait_builder = f.debug_tuple("Float3");
debug_trait_builder.finish()
}
(&UniformType::Float4,) => {
let mut debug_trait_builder = f.debug_tuple("Float4");
debug_trait_builder.finish()
}
(&UniformType::Mat4,) => {
let mut debug_trait_builder = f.debug_tuple("Mat4");
debug_trait_builder.finish()
}
}
}
}
impl UniformType {
fn size(&self, count: usize) -> usize {
match self {
UniformType::Float1 => 4 * count,
UniformType::Float2 => 8 * count,
UniformType::Float3 => 12 * count,
UniformType::Float4 => 16 * count,
UniformType::Mat4 => 64 * count,
}
}
}
pub struct UniformBlockLayout {
pub uniforms: &'static [(&'static str, UniformType)],
}
pub struct ShaderMeta {
pub uniforms: UniformBlockLayout,
pub images: &'static [&'static str],
}
pub enum VertexFormat {
Float1,
Float2,
Float3,
Float4,
Byte1,
Byte2,
Byte3,
Byte4,
Short1,
Short2,
Short3,
Short4,
Mat4,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for VertexFormat {
#[inline]
fn clone(&self) -> VertexFormat {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for VertexFormat {}
impl ::core::marker::StructuralPartialEq for VertexFormat {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for VertexFormat {
#[inline]
fn eq(&self, other: &VertexFormat) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for VertexFormat {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&VertexFormat::Float1,) => {
let mut debug_trait_builder = f.debug_tuple("Float1");
debug_trait_builder.finish()
}
(&VertexFormat::Float2,) => {
let mut debug_trait_builder = f.debug_tuple("Float2");
debug_trait_builder.finish()
}
(&VertexFormat::Float3,) => {
let mut debug_trait_builder = f.debug_tuple("Float3");
debug_trait_builder.finish()
}
(&VertexFormat::Float4,) => {
let mut debug_trait_builder = f.debug_tuple("Float4");
debug_trait_builder.finish()
}
(&VertexFormat::Byte1,) => {
let mut debug_trait_builder = f.debug_tuple("Byte1");
debug_trait_builder.finish()
}
(&VertexFormat::Byte2,) => {
let mut debug_trait_builder = f.debug_tuple("Byte2");
debug_trait_builder.finish()
}
(&VertexFormat::Byte3,) => {
let mut debug_trait_builder = f.debug_tuple("Byte3");
debug_trait_builder.finish()
}
(&VertexFormat::Byte4,) => {
let mut debug_trait_builder = f.debug_tuple("Byte4");
debug_trait_builder.finish()
}
(&VertexFormat::Short1,) => {
let mut debug_trait_builder = f.debug_tuple("Short1");
debug_trait_builder.finish()
}
(&VertexFormat::Short2,) => {
let mut debug_trait_builder = f.debug_tuple("Short2");
debug_trait_builder.finish()
}
(&VertexFormat::Short3,) => {
let mut debug_trait_builder = f.debug_tuple("Short3");
debug_trait_builder.finish()
}
(&VertexFormat::Short4,) => {
let mut debug_trait_builder = f.debug_tuple("Short4");
debug_trait_builder.finish()
}
(&VertexFormat::Mat4,) => {
let mut debug_trait_builder = f.debug_tuple("Mat4");
debug_trait_builder.finish()
}
}
}
}
impl VertexFormat {
pub fn size(&self) -> i32 {
match self {
VertexFormat::Float1 => 1,
VertexFormat::Float2 => 2,
VertexFormat::Float3 => 3,
VertexFormat::Float4 => 4,
VertexFormat::Byte1 => 1,
VertexFormat::Byte2 => 2,
VertexFormat::Byte3 => 3,
VertexFormat::Byte4 => 4,
VertexFormat::Short1 => 1,
VertexFormat::Short2 => 2,
VertexFormat::Short3 => 3,
VertexFormat::Short4 => 4,
VertexFormat::Mat4 => 16,
}
}
pub fn byte_len(&self) -> i32 {
match self {
VertexFormat::Float1 => 1 * 4,
VertexFormat::Float2 => 2 * 4,
VertexFormat::Float3 => 3 * 4,
VertexFormat::Float4 => 4 * 4,
VertexFormat::Byte1 => 1,
VertexFormat::Byte2 => 2,
VertexFormat::Byte3 => 3,
VertexFormat::Byte4 => 4,
VertexFormat::Short1 => 1 * 2,
VertexFormat::Short2 => 2 * 2,
VertexFormat::Short3 => 3 * 2,
VertexFormat::Short4 => 4 * 2,
VertexFormat::Mat4 => 16 * 4,
}
}
fn type_(&self) -> GLuint {
match self {
VertexFormat::Float1 => GL_FLOAT,
VertexFormat::Float2 => GL_FLOAT,
VertexFormat::Float3 => GL_FLOAT,
VertexFormat::Float4 => GL_FLOAT,
VertexFormat::Byte1 => GL_UNSIGNED_BYTE,
VertexFormat::Byte2 => GL_UNSIGNED_BYTE,
VertexFormat::Byte3 => GL_UNSIGNED_BYTE,
VertexFormat::Byte4 => GL_UNSIGNED_BYTE,
VertexFormat::Short1 => GL_UNSIGNED_SHORT,
VertexFormat::Short2 => GL_UNSIGNED_SHORT,
VertexFormat::Short3 => GL_UNSIGNED_SHORT,
VertexFormat::Short4 => GL_UNSIGNED_SHORT,
VertexFormat::Mat4 => GL_FLOAT,
}
}
}
pub enum VertexStep {
PerVertex,
PerInstance,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for VertexStep {
#[inline]
fn clone(&self) -> VertexStep {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for VertexStep {}
impl ::core::marker::StructuralPartialEq for VertexStep {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for VertexStep {
#[inline]
fn eq(&self, other: &VertexStep) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for VertexStep {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&VertexStep::PerVertex,) => {
let mut debug_trait_builder = f.debug_tuple("PerVertex");
debug_trait_builder.finish()
}
(&VertexStep::PerInstance,) => {
let mut debug_trait_builder = f.debug_tuple("PerInstance");
debug_trait_builder.finish()
}
}
}
}
impl Default for VertexStep {
fn default() -> VertexStep {
VertexStep::PerVertex
}
}
pub struct BufferLayout {
pub stride: i32,
pub step_func: VertexStep,
pub step_rate: i32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for BufferLayout {
#[inline]
fn clone(&self) -> BufferLayout {
match *self {
BufferLayout {
stride: ref __self_0_0,
step_func: ref __self_0_1,
step_rate: ref __self_0_2,
} => BufferLayout {
stride: ::core::clone::Clone::clone(&(*__self_0_0)),
step_func: ::core::clone::Clone::clone(&(*__self_0_1)),
step_rate: ::core::clone::Clone::clone(&(*__self_0_2)),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for BufferLayout {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
BufferLayout {
stride: ref __self_0_0,
step_func: ref __self_0_1,
step_rate: ref __self_0_2,
} => {
let mut debug_trait_builder = f.debug_struct("BufferLayout");
let _ = debug_trait_builder.field("stride", &&(*__self_0_0));
let _ = debug_trait_builder.field("step_func", &&(*__self_0_1));
let _ = debug_trait_builder.field("step_rate", &&(*__self_0_2));
debug_trait_builder.finish()
}
}
}
}
impl Default for BufferLayout {
fn default() -> BufferLayout {
BufferLayout {
stride: 0,
step_func: VertexStep::PerVertex,
step_rate: 1,
}
}
}
pub struct VertexAttribute {
pub name: &'static str,
pub format: VertexFormat,
pub buffer_index: usize,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for VertexAttribute {
#[inline]
fn clone(&self) -> VertexAttribute {
match *self {
VertexAttribute {
name: ref __self_0_0,
format: ref __self_0_1,
buffer_index: ref __self_0_2,
} => VertexAttribute {
name: ::core::clone::Clone::clone(&(*__self_0_0)),
format: ::core::clone::Clone::clone(&(*__self_0_1)),
buffer_index: ::core::clone::Clone::clone(&(*__self_0_2)),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for VertexAttribute {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
VertexAttribute {
name: ref __self_0_0,
format: ref __self_0_1,
buffer_index: ref __self_0_2,
} => {
let mut debug_trait_builder = f.debug_struct("VertexAttribute");
let _ = debug_trait_builder.field("name", &&(*__self_0_0));
let _ = debug_trait_builder.field("format", &&(*__self_0_1));
let _ = debug_trait_builder.field("buffer_index", &&(*__self_0_2));
debug_trait_builder.finish()
}
}
}
}
impl VertexAttribute {
pub fn new(name: &'static str, format: VertexFormat) -> VertexAttribute {
Self::with_buffer(name, format, 0)
}
pub fn with_buffer(
name: &'static str,
format: VertexFormat,
buffer_index: usize,
) -> VertexAttribute {
VertexAttribute {
name,
format,
buffer_index,
}
}
}
pub struct PipelineLayout {
pub buffers: &'static [BufferLayout],
pub attributes: &'static [VertexAttribute],
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for PipelineLayout {
#[inline]
fn clone(&self) -> PipelineLayout {
match *self {
PipelineLayout {
buffers: ref __self_0_0,
attributes: ref __self_0_1,
} => PipelineLayout {
buffers: ::core::clone::Clone::clone(&(*__self_0_0)),
attributes: ::core::clone::Clone::clone(&(*__self_0_1)),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for PipelineLayout {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
PipelineLayout {
buffers: ref __self_0_0,
attributes: ref __self_0_1,
} => {
let mut debug_trait_builder = f.debug_struct("PipelineLayout");
let _ = debug_trait_builder.field("buffers", &&(*__self_0_0));
let _ = debug_trait_builder.field("attributes", &&(*__self_0_1));
debug_trait_builder.finish()
}
}
}
}
pub struct Shader(usize);
impl Shader {
pub fn new(
ctx: &mut Context,
vertex_shader: &str,
fragment_shader: &str,
meta: ShaderMeta,
) -> Shader {
let shader = load_shader_internal(vertex_shader, fragment_shader, meta);
ctx.shaders.push(shader);
Shader(ctx.shaders.len() - 1)
}
}
pub struct ShaderImage {
gl_loc: GLint,
}
pub struct ShaderUniform {
gl_loc: GLint,
offset: usize,
size: usize,
uniform_type: UniformType,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for ShaderUniform {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
ShaderUniform {
gl_loc: ref __self_0_0,
offset: ref __self_0_1,
size: ref __self_0_2,
uniform_type: ref __self_0_3,
} => {
let mut debug_trait_builder = f.debug_struct("ShaderUniform");
let _ = debug_trait_builder.field("gl_loc", &&(*__self_0_0));
let _ = debug_trait_builder.field("offset", &&(*__self_0_1));
let _ = debug_trait_builder.field("size", &&(*__self_0_2));
let _ = debug_trait_builder.field("uniform_type", &&(*__self_0_3));
debug_trait_builder.finish()
}
}
}
}
struct ShaderInternal {
program: GLuint,
images: Vec<ShaderImage>,
uniforms: Vec<ShaderUniform>,
}
type BlendState = Option<(Equation, BlendFactor, BlendFactor)>;
struct CachedAttribute {
attribute: VertexAttributeInternal,
gl_vbuf: GLuint,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::default::Default for CachedAttribute {
#[inline]
fn default() -> CachedAttribute {
CachedAttribute {
attribute: ::core::default::Default::default(),
gl_vbuf: ::core::default::Default::default(),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for CachedAttribute {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for CachedAttribute {
#[inline]
fn clone(&self) -> CachedAttribute {
{
let _: ::core::clone::AssertParamIsClone<VertexAttributeInternal>;
let _: ::core::clone::AssertParamIsClone<GLuint>;
*self
}
}
}
struct GlCache {
stored_index_buffer: GLuint,
stored_vertex_buffer: GLuint,
stored_texture: GLuint,
index_buffer: GLuint,
vertex_buffer: GLuint,
textures: [GLuint; MAX_SHADERSTAGE_IMAGES],
cur_pipeline: Option<Pipeline>,
blend: BlendState,
attributes: [Option<CachedAttribute>; MAX_VERTEX_ATTRIBUTES],
}
impl GlCache {
fn bind_buffer(&mut self, target: GLenum, buffer: GLuint) {
if target == GL_ARRAY_BUFFER {
if self.vertex_buffer != buffer {
self.vertex_buffer = buffer;
unsafe {
glBindBuffer(target, buffer);
}
}
} else {
if self.index_buffer != buffer {
self.index_buffer = buffer;
unsafe {
glBindBuffer(target, buffer);
}
}
}
}
fn store_buffer_binding(&mut self, target: GLenum) {
if target == GL_ARRAY_BUFFER {
self.stored_vertex_buffer = self.vertex_buffer;
} else {
self.stored_index_buffer = self.index_buffer;
}
}
fn restore_buffer_binding(&mut self, target: GLenum) {
if target == GL_ARRAY_BUFFER {
self.bind_buffer(target, self.stored_vertex_buffer);
} else {
self.bind_buffer(target, self.stored_index_buffer);
}
}
fn bind_texture(&mut self, slot_index: usize, texture: GLuint) {
unsafe {
glActiveTexture(GL_TEXTURE0 + slot_index as GLuint);
if self.textures[slot_index] != texture {
glBindTexture(GL_TEXTURE_2D, texture);
self.textures[slot_index] = texture;
}
}
}
fn store_texture_binding(&mut self, slot_index: usize) {
self.stored_texture = self.textures[slot_index];
}
fn restore_texture_binding(&mut self, slot_index: usize) {
self.bind_texture(slot_index, self.stored_texture);
}
fn clear_buffer_bindings(&mut self) {
self.bind_buffer(GL_ARRAY_BUFFER, 0);
self.vertex_buffer = 0;
self.bind_buffer(GL_ELEMENT_ARRAY_BUFFER, 0);
self.index_buffer = 0;
}
fn clear_texture_bindings(&mut self) {
for ix in 0..MAX_SHADERSTAGE_IMAGES {
if self.textures[ix] != 0 {
self.bind_texture(ix, 0);
self.textures[ix] = 0;
}
}
}
}
pub enum PassAction {
Nothing,
Clear {
color: Option<(f32, f32, f32, f32)>,
depth: Option<f32>,
stencil: Option<i32>,
},
}
impl PassAction {
pub fn clear_color(r: f32, g: f32, b: f32, a: f32) -> PassAction {
PassAction::Clear {
color: Some((r, g, b, a)),
depth: Some(1.),
stencil: None,
}
}
}
impl Default for PassAction {
fn default() -> PassAction {
PassAction::Clear {
color: Some((0.0, 0.0, 0.0, 0.0)),
depth: Some(1.),
stencil: None,
}
}
}
pub struct RenderPass(usize);
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for RenderPass {
#[inline]
fn clone(&self) -> RenderPass {
{
let _: ::core::clone::AssertParamIsClone<usize>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for RenderPass {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for RenderPass {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
RenderPass(ref __self_0_0) => {
let mut debug_trait_builder = f.debug_tuple("RenderPass");
let _ = debug_trait_builder.field(&&(*__self_0_0));
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for RenderPass {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for RenderPass {
#[inline]
fn eq(&self, other: &RenderPass) -> bool {
match *other {
RenderPass(ref __self_1_0) => match *self {
RenderPass(ref __self_0_0) => (*__self_0_0) == (*__self_1_0),
},
}
}
#[inline]
fn ne(&self, other: &RenderPass) -> bool {
match *other {
RenderPass(ref __self_1_0) => match *self {
RenderPass(ref __self_0_0) => (*__self_0_0) != (*__self_1_0),
},
}
}
}
struct RenderPassInternal {
gl_fb: GLuint,
texture: Texture,
}
impl RenderPass {
pub fn new(
context: &mut Context,
color_img: Texture,
depth_img: impl Into<Option<Texture>>,
) -> RenderPass {
let mut gl_fb = 0;
unsafe {
glGenFramebuffers(1, &mut gl_fb as *mut _);
glBindFramebuffer(GL_FRAMEBUFFER, gl_fb);
glFramebufferTexture2D(
GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D,
color_img.texture,
0,
);
if let Some(depth_img) = depth_img.into() {
glFramebufferTexture2D(
GL_FRAMEBUFFER,
GL_DEPTH_ATTACHMENT,
GL_TEXTURE_2D,
depth_img.texture,
0,
);
}
glBindFramebuffer(GL_FRAMEBUFFER, context.default_framebuffer);
}
let pass = RenderPassInternal {
gl_fb,
texture: color_img,
};
context.passes.push(pass);
RenderPass(context.passes.len() - 1)
}
}
pub const MAX_VERTEX_ATTRIBUTES: usize = 16;
pub const MAX_SHADERSTAGE_IMAGES: usize = 12;
pub struct Context {
shaders: Vec<ShaderInternal>,
pipelines: Vec<PipelineInternal>,
passes: Vec<RenderPassInternal>,
default_framebuffer: GLuint,
cache: GlCache,
}
impl Context {
pub fn new() -> Context {
unsafe {
let mut default_framebuffer: GLuint = 0;
glGetIntegerv(
GL_FRAMEBUFFER_BINDING,
&mut default_framebuffer as *mut _ as *mut _,
);
let mut vao = 0;
glGenVertexArrays(1, &mut vao as *mut _);
glBindVertexArray(vao);
Context {
default_framebuffer,
shaders: <[_]>::into_vec(box []),
pipelines: <[_]>::into_vec(box []),
passes: <[_]>::into_vec(box []),
cache: GlCache {
stored_index_buffer: 0,
stored_vertex_buffer: 0,
index_buffer: 0,
vertex_buffer: 0,
cur_pipeline: None,
blend: None,
stored_texture: 0,
textures: [0; MAX_SHADERSTAGE_IMAGES],
attributes: [None; MAX_VERTEX_ATTRIBUTES],
},
}
}
}
pub fn screen_size(&self) -> (f32, f32) {
unsafe { (sapp_width() as f32, sapp_height() as f32) }
}
pub fn dpi_scale(&self) -> f32 {
unsafe { sapp_dpi_scale() }
}
pub fn high_dpi(&self) -> bool {
unsafe { sapp_high_dpi() }
}
fn apply_pipeline(&mut self, pipeline: &Pipeline) {
let res = {
self.cache.cur_pipeline = Some(*pipeline);
let pipeline = &mut self.pipelines[pipeline.0];
let shader = &mut self.shaders[pipeline.shader.0];
unsafe {
glUseProgram(shader.program);
}
unsafe {
glEnable(GL_SCISSOR_TEST);
}
if pipeline.params.depth_write {
unsafe {
glEnable(GL_DEPTH_TEST);
glDepthFunc(pipeline.params.depth_test.into())
}
} else {
unsafe {
glDisable(GL_DEPTH_TEST);
}
}
if self.cache.blend != pipeline.params.color_blend {
unsafe {
if let Some((equation, src, dst)) = pipeline.params.color_blend {
if self.cache.blend.is_none() {
glEnable(GL_BLEND);
}
glBlendFunc(src.into(), dst.into());
glBlendEquationSeparate(equation.into(), equation.into());
} else if self.cache.blend.is_some() {
glDisable(GL_BLEND);
}
self.cache.blend = pipeline.params.color_blend;
}
}
};
res
}
fn apply_scissor_rect(&mut self, x: i32, y: i32, w: i32, h: i32) {
let res = {
unsafe {
glScissor(x, y, w, h);
}
};
res
}
fn apply_bindings(&mut self, bindings: &Bindings) {
let res = {
let pip = &self.pipelines[self.cache.cur_pipeline.unwrap().0];
let shader = &self.shaders[pip.shader.0];
for (n, shader_image) in shader.images.iter().enumerate() {
let bindings_image = bindings.images.get(n).unwrap_or_else(|| {
::std::rt::begin_panic("Image count in bindings and shader did not match!")
});
unsafe {
self.cache.bind_texture(n, bindings_image.texture);
glUniform1i(shader_image.gl_loc, n as i32);
}
}
self.cache
.bind_buffer(GL_ELEMENT_ARRAY_BUFFER, bindings.index_buffer.gl_buf);
let pip = &self.pipelines[self.cache.cur_pipeline.unwrap().0];
for attr_index in 0..MAX_VERTEX_ATTRIBUTES {
let cached_attr = &mut self.cache.attributes[attr_index];
let pip_attribute = pip.layout.get(attr_index).copied();
if let Some(attribute) = pip_attribute {
let vb = bindings.vertex_buffers[attribute.buffer_index];
if cached_attr.map_or(true, |cached_attr| {
attribute != cached_attr.attribute || cached_attr.gl_vbuf != vb.gl_buf
}) {
self.cache.bind_buffer(GL_ARRAY_BUFFER, vb.gl_buf);
unsafe {
glVertexAttribPointer(
attr_index as GLuint,
attribute.size,
attribute.type_,
GL_FALSE as u8,
attribute.stride,
attribute.offset as *mut _,
);
glVertexAttribDivisor(
attr_index as GLuint,
attribute.divisor as u32,
);
glEnableVertexAttribArray(attr_index as GLuint);
};
let cached_attr = &mut self.cache.attributes[attr_index];
*cached_attr = Some(CachedAttribute {
attribute,
gl_vbuf: vb.gl_buf,
});
}
} else {
if cached_attr.is_some() {
unsafe {
glDisableVertexAttribArray(attr_index as GLuint);
}
*cached_attr = None;
}
}
}
};
res
}
pub fn apply_uniforms<U>(&mut self, uniforms: &U) {
let pip = &self.pipelines[self.cache.cur_pipeline.unwrap().0];
let shader = &self.shaders[pip.shader.0];
let mut offset = 0;
for (_, uniform) in shader.uniforms.iter().enumerate() {
use UniformType::*;
if !(offset < std::mem::size_of::<U>() - 4) {
{
::std::rt::begin_panic(
"assertion failed: offset < std::mem::size_of::<U>() - 4",
)
}
};
unsafe {
let data = (uniforms as *const _ as *const f32).offset(offset as isize);
match uniform.uniform_type {
Float1 => {
glUniform1fv(uniform.gl_loc, 1, data);
}
Float2 => {
glUniform2fv(uniform.gl_loc, 1, data);
}
Float3 => {
glUniform3fv(uniform.gl_loc, 1, data);
}
Float4 => {
glUniform4fv(uniform.gl_loc, 1, data);
}
Mat4 => {
glUniformMatrix4fv(uniform.gl_loc, 1, 0, data);
}
}
}
offset += uniform.uniform_type.size(1) / 4;
}
}
fn clear(
&self,
color: Option<(f32, f32, f32, f32)>,
depth: Option<f32>,
stencil: Option<i32>,
) {
let res = {
let mut bits = 0;
if let Some((r, g, b, a)) = color {
bits |= GL_COLOR_BUFFER_BIT;
unsafe {
glClearColor(r, g, b, a);
}
}
if let Some(v) = depth {
bits |= GL_DEPTH_BUFFER_BIT;
unsafe {
glClearDepthf(v);
}
}
if let Some(v) = stencil {
bits |= GL_STENCIL_BUFFER_BIT;
unsafe {
glClearStencil(v);
}
}
if bits != 0 {
unsafe {
glClear(bits);
}
}
};
res
}
fn begin_default_pass(&mut self, action: PassAction) {
let res = {
self.begin_pass(None, action);
};
res
}
fn begin_pass(&mut self, pass: impl Into<Option<RenderPass>>, action: PassAction) {
let res = {
let (framebuffer, w, h) = match pass.into() {
None => (
self.default_framebuffer,
unsafe { sapp_width() } as i32,
unsafe { sapp_height() } as i32,
),
Some(pass) => {
let pass = &self.passes[pass.0];
(
pass.gl_fb,
pass.texture.width as i32,
pass.texture.height as i32,
)
}
};
unsafe {
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glViewport(0, 0, w, h);
glScissor(0, 0, w, h);
}
match action {
PassAction::Nothing => {}
PassAction::Clear {
color,
depth,
stencil,
} => {
self.clear(color, depth, stencil);
}
}
};
res
}
fn end_render_pass(&mut self) {
let res = {
unsafe {
glBindFramebuffer(GL_FRAMEBUFFER, self.default_framebuffer);
self.cache.bind_buffer(GL_ARRAY_BUFFER, 0);
self.cache.bind_buffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
};
res
}
fn commit_frame(&mut self) {
let res = {
self.cache.clear_buffer_bindings();
self.cache.clear_texture_bindings();
};
res
}
fn draw(&self, base_element: i32, num_elements: i32, num_instances: i32) {
let res = {
unsafe {
glDrawElementsInstanced(
GL_TRIANGLES,
num_elements,
GL_UNSIGNED_SHORT,
(2 * base_element) as *mut _,
num_instances,
);
}
};
res
}
}
fn load_shader_internal(
vertex_shader: &str,
fragment_shader: &str,
meta: ShaderMeta,
) -> ShaderInternal {
unsafe {
let vertex_shader = load_shader(GL_VERTEX_SHADER, vertex_shader);
let fragment_shader = load_shader(GL_FRAGMENT_SHADER, fragment_shader);
let program = glCreateProgram();
glAttachShader(program, vertex_shader);
glAttachShader(program, fragment_shader);
glLinkProgram(program);
let mut link_status = 0;
glGetProgramiv(program, GL_LINK_STATUS, &mut link_status as *mut _);
if link_status == 0 {
let mut max_length = 100;
let mut error_message = ::alloc::vec::from_elem(0u8, max_length as usize + 1);
glGetProgramInfoLog(
program,
max_length,
&mut max_length as *mut _,
error_message.as_mut_ptr() as *mut _,
);
let error_message = std::string::String::from_utf8_lossy(&error_message);
{
::std::rt::begin_panic_fmt(&::core::fmt::Arguments::new_v1(
&[""],
&match (&error_message,) {
(arg0,) => [::core::fmt::ArgumentV1::new(
arg0,
::core::fmt::Display::fmt,
)],
},
))
};
}
glUseProgram(program);
#[rustfmt::skip]
let images =
meta.images.iter().map(|name|
ShaderImage{gl_loc:
get_uniform_location(program,
name),}).collect();
#[rustfmt::skip]
let uniforms =
meta.uniforms.uniforms.iter().scan(0,
|offset, uniform|
{
let res =
ShaderUniform{gl_loc:
get_uniform_location(program,
uniform.0),
offset:
*offset,
size:
uniform.1.size(1),
uniform_type:
uniform.1,};
*offset +=
uniform.1.size(1);
Some(res)
}).collect();
ShaderInternal {
program,
images,
uniforms,
}
}
}
fn load_shader(shader_type: GLenum, source: &str) -> GLuint {
unsafe {
let shader = glCreateShader(shader_type);
if !(shader != 0) {
{
::std::rt::begin_panic("assertion failed: shader != 0")
}
};
let cstring = CString::new(source).unwrap_or_else(|e| ::std::rt::begin_panic(e));
let csource = [cstring];
glShaderSource(shader, 1, csource.as_ptr() as *const _, std::ptr::null());
glCompileShader(shader);
let mut is_compiled = 0;
glGetShaderiv(shader, GL_COMPILE_STATUS, &mut is_compiled as *mut _);
if is_compiled == 0 {
let mut max_length: i32 = 0;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &mut max_length as *mut _);
let mut error_message = ::alloc::vec::from_elem(0u8, max_length as usize + 1);
glGetShaderInfoLog(
shader,
max_length,
&mut max_length as *mut _,
error_message.as_mut_ptr() as *mut _,
);
let error_message = std::string::String::from_utf8_lossy(&error_message);
{
::std::io::_eprint(::core::fmt::Arguments::new_v1(
&["", " ", "\n"],
&match (&max_length, &error_message) {
(arg0, arg1) => [
::core::fmt::ArgumentV1::new(arg0, ::core::fmt::Display::fmt),
::core::fmt::ArgumentV1::new(arg1, ::core::fmt::Debug::fmt),
],
},
));
};
glDeleteShader(shader);
{
::std::rt::begin_panic("cant compile shader!")
};
}
shader
}
}
pub enum CullFace {
Nothing,
Front,
Back,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for CullFace {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&CullFace::Nothing,) => {
let mut debug_trait_builder = f.debug_tuple("Nothing");
debug_trait_builder.finish()
}
(&CullFace::Front,) => {
let mut debug_trait_builder = f.debug_tuple("Front");
debug_trait_builder.finish()
}
(&CullFace::Back,) => {
let mut debug_trait_builder = f.debug_tuple("Back");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for CullFace {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for CullFace {
#[inline]
fn eq(&self, other: &CullFace) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for CullFace {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for CullFace {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for CullFace {
#[inline]
fn clone(&self) -> CullFace {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for CullFace {}
pub enum FrontFaceOrder {
Clockwise,
CounterClockwise,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for FrontFaceOrder {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&FrontFaceOrder::Clockwise,) => {
let mut debug_trait_builder = f.debug_tuple("Clockwise");
debug_trait_builder.finish()
}
(&FrontFaceOrder::CounterClockwise,) => {
let mut debug_trait_builder = f.debug_tuple("CounterClockwise");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for FrontFaceOrder {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for FrontFaceOrder {
#[inline]
fn eq(&self, other: &FrontFaceOrder) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for FrontFaceOrder {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for FrontFaceOrder {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for FrontFaceOrder {
#[inline]
fn clone(&self) -> FrontFaceOrder {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for FrontFaceOrder {}
pub enum Comparison {
Never,
Less,
LessOrEqual,
Greater,
GreaterOrEqual,
Equal,
NotEqual,
Always,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Comparison {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&Comparison::Never,) => {
let mut debug_trait_builder = f.debug_tuple("Never");
debug_trait_builder.finish()
}
(&Comparison::Less,) => {
let mut debug_trait_builder = f.debug_tuple("Less");
debug_trait_builder.finish()
}
(&Comparison::LessOrEqual,) => {
let mut debug_trait_builder = f.debug_tuple("LessOrEqual");
debug_trait_builder.finish()
}
(&Comparison::Greater,) => {
let mut debug_trait_builder = f.debug_tuple("Greater");
debug_trait_builder.finish()
}
(&Comparison::GreaterOrEqual,) => {
let mut debug_trait_builder = f.debug_tuple("GreaterOrEqual");
debug_trait_builder.finish()
}
(&Comparison::Equal,) => {
let mut debug_trait_builder = f.debug_tuple("Equal");
debug_trait_builder.finish()
}
(&Comparison::NotEqual,) => {
let mut debug_trait_builder = f.debug_tuple("NotEqual");
debug_trait_builder.finish()
}
(&Comparison::Always,) => {
let mut debug_trait_builder = f.debug_tuple("Always");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for Comparison {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for Comparison {
#[inline]
fn eq(&self, other: &Comparison) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for Comparison {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for Comparison {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Comparison {
#[inline]
fn clone(&self) -> Comparison {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Comparison {}
impl From<Comparison> for GLenum {
fn from(cmp: Comparison) -> Self {
match cmp {
Comparison::Never => GL_NEVER,
Comparison::Less => GL_LESS,
Comparison::LessOrEqual => GL_LEQUAL,
Comparison::Greater => GL_GREATER,
Comparison::GreaterOrEqual => GL_GEQUAL,
Comparison::Equal => GL_EQUAL,
Comparison::NotEqual => GL_NOTEQUAL,
Comparison::Always => GL_ALWAYS,
}
}
}
pub enum Equation {
Add,
Subtract,
ReverseSubtract,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Equation {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&Equation::Add,) => {
let mut debug_trait_builder = f.debug_tuple("Add");
debug_trait_builder.finish()
}
(&Equation::Subtract,) => {
let mut debug_trait_builder = f.debug_tuple("Subtract");
debug_trait_builder.finish()
}
(&Equation::ReverseSubtract,) => {
let mut debug_trait_builder = f.debug_tuple("ReverseSubtract");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for Equation {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for Equation {
#[inline]
fn eq(&self, other: &Equation) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for Equation {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for Equation {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Equation {
#[inline]
fn clone(&self) -> Equation {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Equation {}
pub enum BlendValue {
SourceColor,
SourceAlpha,
DestinationColor,
DestinationAlpha,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for BlendValue {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&BlendValue::SourceColor,) => {
let mut debug_trait_builder = f.debug_tuple("SourceColor");
debug_trait_builder.finish()
}
(&BlendValue::SourceAlpha,) => {
let mut debug_trait_builder = f.debug_tuple("SourceAlpha");
debug_trait_builder.finish()
}
(&BlendValue::DestinationColor,) => {
let mut debug_trait_builder = f.debug_tuple("DestinationColor");
debug_trait_builder.finish()
}
(&BlendValue::DestinationAlpha,) => {
let mut debug_trait_builder = f.debug_tuple("DestinationAlpha");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for BlendValue {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for BlendValue {
#[inline]
fn eq(&self, other: &BlendValue) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for BlendValue {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for BlendValue {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for BlendValue {
#[inline]
fn clone(&self) -> BlendValue {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for BlendValue {}
pub enum BlendFactor {
Zero,
One,
Value(BlendValue),
OneMinusValue(BlendValue),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for BlendFactor {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&BlendFactor::Zero,) => {
let mut debug_trait_builder = f.debug_tuple("Zero");
debug_trait_builder.finish()
}
(&BlendFactor::One,) => {
let mut debug_trait_builder = f.debug_tuple("One");
debug_trait_builder.finish()
}
(&BlendFactor::Value(ref __self_0),) => {
let mut debug_trait_builder = f.debug_tuple("Value");
let _ = debug_trait_builder.field(&&(*__self_0));
debug_trait_builder.finish()
}
(&BlendFactor::OneMinusValue(ref __self_0),) => {
let mut debug_trait_builder = f.debug_tuple("OneMinusValue");
let _ = debug_trait_builder.field(&&(*__self_0));
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for BlendFactor {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for BlendFactor {
#[inline]
fn eq(&self, other: &BlendFactor) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
(&BlendFactor::Value(ref __self_0), &BlendFactor::Value(ref __arg_1_0)) => {
(*__self_0) == (*__arg_1_0)
}
(
&BlendFactor::OneMinusValue(ref __self_0),
&BlendFactor::OneMinusValue(ref __arg_1_0),
) => (*__self_0) == (*__arg_1_0),
_ => true,
}
} else {
false
}
}
}
#[inline]
fn ne(&self, other: &BlendFactor) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
(&BlendFactor::Value(ref __self_0), &BlendFactor::Value(ref __arg_1_0)) => {
(*__self_0) != (*__arg_1_0)
}
(
&BlendFactor::OneMinusValue(ref __self_0),
&BlendFactor::OneMinusValue(ref __arg_1_0),
) => (*__self_0) != (*__arg_1_0),
_ => false,
}
} else {
true
}
}
}
}
impl ::core::marker::StructuralEq for BlendFactor {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for BlendFactor {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{
let _: ::core::cmp::AssertParamIsEq<BlendValue>;
let _: ::core::cmp::AssertParamIsEq<BlendValue>;
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for BlendFactor {
#[inline]
fn clone(&self) -> BlendFactor {
{
let _: ::core::clone::AssertParamIsClone<BlendValue>;
let _: ::core::clone::AssertParamIsClone<BlendValue>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for BlendFactor {}
impl From<Equation> for GLenum {
fn from(eq: Equation) -> Self {
match eq {
Equation::Add => GL_FUNC_ADD,
Equation::Subtract => GL_FUNC_SUBTRACT,
Equation::ReverseSubtract => GL_FUNC_REVERSE_SUBTRACT,
}
}
}
impl From<BlendFactor> for GLenum {
fn from(factor: BlendFactor) -> GLenum {
match factor {
BlendFactor::Zero => GL_ZERO,
BlendFactor::One => GL_ONE,
BlendFactor::Value(BlendValue::SourceColor) => GL_SRC_COLOR,
BlendFactor::Value(BlendValue::SourceAlpha) => GL_SRC_ALPHA,
BlendFactor::Value(BlendValue::DestinationColor) => GL_DST_COLOR,
BlendFactor::Value(BlendValue::DestinationAlpha) => GL_DST_ALPHA,
BlendFactor::OneMinusValue(BlendValue::SourceColor) => GL_ONE_MINUS_SRC_COLOR,
BlendFactor::OneMinusValue(BlendValue::SourceAlpha) => GL_ONE_MINUS_SRC_ALPHA,
BlendFactor::OneMinusValue(BlendValue::DestinationColor) => GL_ONE_MINUS_DST_COLOR,
BlendFactor::OneMinusValue(BlendValue::DestinationAlpha) => GL_ONE_MINUS_DST_ALPHA,
}
}
}
pub struct PipelineParams {
pub cull_face: CullFace,
pub front_face_order: FrontFaceOrder,
pub depth_test: Comparison,
pub depth_write: bool,
pub depth_write_offset: Option<(f32, f32)>,
pub color_blend: BlendState,
pub color_write: (bool, bool, bool, bool),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for PipelineParams {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
PipelineParams {
cull_face: ref __self_0_0,
front_face_order: ref __self_0_1,
depth_test: ref __self_0_2,
depth_write: ref __self_0_3,
depth_write_offset: ref __self_0_4,
color_blend: ref __self_0_5,
color_write: ref __self_0_6,
} => {
let mut debug_trait_builder = f.debug_struct("PipelineParams");
let _ = debug_trait_builder.field("cull_face", &&(*__self_0_0));
let _ = debug_trait_builder.field("front_face_order", &&(*__self_0_1));
let _ = debug_trait_builder.field("depth_test", &&(*__self_0_2));
let _ = debug_trait_builder.field("depth_write", &&(*__self_0_3));
let _ = debug_trait_builder.field("depth_write_offset", &&(*__self_0_4));
let _ = debug_trait_builder.field("color_blend", &&(*__self_0_5));
let _ = debug_trait_builder.field("color_write", &&(*__self_0_6));
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for PipelineParams {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for PipelineParams {
#[inline]
fn eq(&self, other: &PipelineParams) -> bool {
match *other {
PipelineParams {
cull_face: ref __self_1_0,
front_face_order: ref __self_1_1,
depth_test: ref __self_1_2,
depth_write: ref __self_1_3,
depth_write_offset: ref __self_1_4,
color_blend: ref __self_1_5,
color_write: ref __self_1_6,
} => match *self {
PipelineParams {
cull_face: ref __self_0_0,
front_face_order: ref __self_0_1,
depth_test: ref __self_0_2,
depth_write: ref __self_0_3,
depth_write_offset: ref __self_0_4,
color_blend: ref __self_0_5,
color_write: ref __self_0_6,
} => {
(*__self_0_0) == (*__self_1_0)
&& (*__self_0_1) == (*__self_1_1)
&& (*__self_0_2) == (*__self_1_2)
&& (*__self_0_3) == (*__self_1_3)
&& (*__self_0_4) == (*__self_1_4)
&& (*__self_0_5) == (*__self_1_5)
&& (*__self_0_6) == (*__self_1_6)
}
},
}
}
#[inline]
fn ne(&self, other: &PipelineParams) -> bool {
match *other {
PipelineParams {
cull_face: ref __self_1_0,
front_face_order: ref __self_1_1,
depth_test: ref __self_1_2,
depth_write: ref __self_1_3,
depth_write_offset: ref __self_1_4,
color_blend: ref __self_1_5,
color_write: ref __self_1_6,
} => match *self {
PipelineParams {
cull_face: ref __self_0_0,
front_face_order: ref __self_0_1,
depth_test: ref __self_0_2,
depth_write: ref __self_0_3,
depth_write_offset: ref __self_0_4,
color_blend: ref __self_0_5,
color_write: ref __self_0_6,
} => {
(*__self_0_0) != (*__self_1_0)
|| (*__self_0_1) != (*__self_1_1)
|| (*__self_0_2) != (*__self_1_2)
|| (*__self_0_3) != (*__self_1_3)
|| (*__self_0_4) != (*__self_1_4)
|| (*__self_0_5) != (*__self_1_5)
|| (*__self_0_6) != (*__self_1_6)
}
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for PipelineParams {
#[inline]
fn clone(&self) -> PipelineParams {
{
let _: ::core::clone::AssertParamIsClone<CullFace>;
let _: ::core::clone::AssertParamIsClone<FrontFaceOrder>;
let _: ::core::clone::AssertParamIsClone<Comparison>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<Option<(f32, f32)>>;
let _: ::core::clone::AssertParamIsClone<BlendState>;
let _: ::core::clone::AssertParamIsClone<(bool, bool, bool, bool)>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for PipelineParams {}
pub struct Pipeline(usize);
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Pipeline {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Pipeline {
#[inline]
fn clone(&self) -> Pipeline {
{
let _: ::core::clone::AssertParamIsClone<usize>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Pipeline {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
Pipeline(ref __self_0_0) => {
let mut debug_trait_builder = f.debug_tuple("Pipeline");
let _ = debug_trait_builder.field(&&(*__self_0_0));
debug_trait_builder.finish()
}
}
}
}
impl Default for PipelineParams {
fn default() -> PipelineParams {
PipelineParams {
cull_face: CullFace::Nothing,
front_face_order: FrontFaceOrder::CounterClockwise,
depth_test: Comparison::Always,
depth_write: false,
depth_write_offset: None,
color_blend: None,
color_write: (true, true, true, true),
}
}
}
impl Pipeline {
pub fn new(
ctx: &mut Context,
buffer_layout: &[BufferLayout],
attributes: &[VertexAttribute],
shader: Shader,
) -> Pipeline {
Self::with_params(ctx, buffer_layout, attributes, shader, Default::default())
}
fn with_params(
ctx: &mut Context,
buffer_layout: &[BufferLayout],
attributes: &[VertexAttribute],
shader: Shader,
params: PipelineParams,
) {
()
}
}
struct VertexAttributeInternal {
attr_loc: GLuint,
size: i32,
type_: GLuint,
offset: i64,
stride: i32,
buffer_index: usize,
divisor: i32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for VertexAttributeInternal {
#[inline]
fn clone(&self) -> VertexAttributeInternal {
{
let _: ::core::clone::AssertParamIsClone<GLuint>;
let _: ::core::clone::AssertParamIsClone<i32>;
let _: ::core::clone::AssertParamIsClone<GLuint>;
let _: ::core::clone::AssertParamIsClone<i64>;
let _: ::core::clone::AssertParamIsClone<i32>;
let _: ::core::clone::AssertParamIsClone<usize>;
let _: ::core::clone::AssertParamIsClone<i32>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for VertexAttributeInternal {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for VertexAttributeInternal {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
VertexAttributeInternal {
attr_loc: ref __self_0_0,
size: ref __self_0_1,
type_: ref __self_0_2,
offset: ref __self_0_3,
stride: ref __self_0_4,
buffer_index: ref __self_0_5,
divisor: ref __self_0_6,
} => {
let mut debug_trait_builder = f.debug_struct("VertexAttributeInternal");
let _ = debug_trait_builder.field("attr_loc", &&(*__self_0_0));
let _ = debug_trait_builder.field("size", &&(*__self_0_1));
let _ = debug_trait_builder.field("type_", &&(*__self_0_2));
let _ = debug_trait_builder.field("offset", &&(*__self_0_3));
let _ = debug_trait_builder.field("stride", &&(*__self_0_4));
let _ = debug_trait_builder.field("buffer_index", &&(*__self_0_5));
let _ = debug_trait_builder.field("divisor", &&(*__self_0_6));
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for VertexAttributeInternal {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for VertexAttributeInternal {
#[inline]
fn eq(&self, other: &VertexAttributeInternal) -> bool {
match *other {
VertexAttributeInternal {
attr_loc: ref __self_1_0,
size: ref __self_1_1,
type_: ref __self_1_2,
offset: ref __self_1_3,
stride: ref __self_1_4,
buffer_index: ref __self_1_5,
divisor: ref __self_1_6,
} => match *self {
VertexAttributeInternal {
attr_loc: ref __self_0_0,
size: ref __self_0_1,
type_: ref __self_0_2,
offset: ref __self_0_3,
stride: ref __self_0_4,
buffer_index: ref __self_0_5,
divisor: ref __self_0_6,
} => {
(*__self_0_0) == (*__self_1_0)
&& (*__self_0_1) == (*__self_1_1)
&& (*__self_0_2) == (*__self_1_2)
&& (*__self_0_3) == (*__self_1_3)
&& (*__self_0_4) == (*__self_1_4)
&& (*__self_0_5) == (*__self_1_5)
&& (*__self_0_6) == (*__self_1_6)
}
},
}
}
#[inline]
fn ne(&self, other: &VertexAttributeInternal) -> bool {
match *other {
VertexAttributeInternal {
attr_loc: ref __self_1_0,
size: ref __self_1_1,
type_: ref __self_1_2,
offset: ref __self_1_3,
stride: ref __self_1_4,
buffer_index: ref __self_1_5,
divisor: ref __self_1_6,
} => match *self {
VertexAttributeInternal {
attr_loc: ref __self_0_0,
size: ref __self_0_1,
type_: ref __self_0_2,
offset: ref __self_0_3,
stride: ref __self_0_4,
buffer_index: ref __self_0_5,
divisor: ref __self_0_6,
} => {
(*__self_0_0) != (*__self_1_0)
|| (*__self_0_1) != (*__self_1_1)
|| (*__self_0_2) != (*__self_1_2)
|| (*__self_0_3) != (*__self_1_3)
|| (*__self_0_4) != (*__self_1_4)
|| (*__self_0_5) != (*__self_1_5)
|| (*__self_0_6) != (*__self_1_6)
}
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::default::Default for VertexAttributeInternal {
#[inline]
fn default() -> VertexAttributeInternal {
VertexAttributeInternal {
attr_loc: ::core::default::Default::default(),
size: ::core::default::Default::default(),
type_: ::core::default::Default::default(),
offset: ::core::default::Default::default(),
stride: ::core::default::Default::default(),
buffer_index: ::core::default::Default::default(),
divisor: ::core::default::Default::default(),
}
}
}
struct PipelineInternal {
layout: Vec<VertexAttributeInternal>,
shader: Shader,
params: PipelineParams,
}
pub struct Bindings {
pub vertex_buffers: Vec<Buffer>,
pub index_buffer: Buffer,
pub images: Vec<Texture>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Bindings {
#[inline]
fn clone(&self) -> Bindings {
match *self {
Bindings {
vertex_buffers: ref __self_0_0,
index_buffer: ref __self_0_1,
images: ref __self_0_2,
} => Bindings {
vertex_buffers: ::core::clone::Clone::clone(&(*__self_0_0)),
index_buffer: ::core::clone::Clone::clone(&(*__self_0_1)),
images: ::core::clone::Clone::clone(&(*__self_0_2)),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Bindings {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
Bindings {
vertex_buffers: ref __self_0_0,
index_buffer: ref __self_0_1,
images: ref __self_0_2,
} => {
let mut debug_trait_builder = f.debug_struct("Bindings");
let _ = debug_trait_builder.field("vertex_buffers", &&(*__self_0_0));
let _ = debug_trait_builder.field("index_buffer", &&(*__self_0_1));
let _ = debug_trait_builder.field("images", &&(*__self_0_2));
debug_trait_builder.finish()
}
}
}
}
pub enum BufferType {
VertexBuffer,
IndexBuffer,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for BufferType {
#[inline]
fn clone(&self) -> BufferType {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for BufferType {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for BufferType {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&BufferType::VertexBuffer,) => {
let mut debug_trait_builder = f.debug_tuple("VertexBuffer");
debug_trait_builder.finish()
}
(&BufferType::IndexBuffer,) => {
let mut debug_trait_builder = f.debug_tuple("IndexBuffer");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for BufferType {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for BufferType {
#[inline]
fn eq(&self, other: &BufferType) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
pub enum Usage {
Immutable,
Dynamic,
Stream,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Usage {
#[inline]
fn clone(&self) -> Usage {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Usage {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Usage {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&Usage::Immutable,) => {
let mut debug_trait_builder = f.debug_tuple("Immutable");
debug_trait_builder.finish()
}
(&Usage::Dynamic,) => {
let mut debug_trait_builder = f.debug_tuple("Dynamic");
debug_trait_builder.finish()
}
(&Usage::Stream,) => {
let mut debug_trait_builder = f.debug_tuple("Stream");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for Usage {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for Usage {
#[inline]
fn eq(&self, other: &Usage) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
fn gl_buffer_target(buffer_type: &BufferType) -> GLenum {
match buffer_type {
BufferType::VertexBuffer => GL_ARRAY_BUFFER,
BufferType::IndexBuffer => GL_ELEMENT_ARRAY_BUFFER,
}
}
fn gl_usage(usage: &Usage) -> GLenum {
match usage {
Usage::Immutable => GL_STATIC_DRAW,
Usage::Dynamic => GL_DYNAMIC_DRAW,
Usage::Stream => GL_STREAM_DRAW,
}
}
pub struct Buffer {
gl_buf: GLuint,
buffer_type: BufferType,
size: usize,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Buffer {
#[inline]
fn clone(&self) -> Buffer {
{
let _: ::core::clone::AssertParamIsClone<GLuint>;
let _: ::core::clone::AssertParamIsClone<BufferType>;
let _: ::core::clone::AssertParamIsClone<usize>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Buffer {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Buffer {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
Buffer {
gl_buf: ref __self_0_0,
buffer_type: ref __self_0_1,
size: ref __self_0_2,
} => {
let mut debug_trait_builder = f.debug_struct("Buffer");
let _ = debug_trait_builder.field("gl_buf", &&(*__self_0_0));
let _ = debug_trait_builder.field("buffer_type", &&(*__self_0_1));
let _ = debug_trait_builder.field("size", &&(*__self_0_2));
debug_trait_builder.finish()
}
}
}
}
impl Buffer {
pub fn immutable<T>(ctx: &mut Context, buffer_type: BufferType, data: &[T]) -> Buffer {
if buffer_type == BufferType::IndexBuffer {
if !(mem::size_of::<T>() == 2) {
{
::std::rt::begin_panic(
"Only u16/i16 index buffers are implemented right now",
)
}
};
}
let gl_target = gl_buffer_target(&buffer_type);
let gl_usage = gl_usage(&Usage::Immutable);
let size = mem::size_of_val(data) as i64;
let mut gl_buf: u32 = 0;
unsafe {
glGenBuffers(1, &mut gl_buf as *mut _);
ctx.cache.store_buffer_binding(gl_target);
ctx.cache.bind_buffer(gl_target, gl_buf);
glBufferData(gl_target, size as _, std::ptr::null() as *const _, gl_usage);
glBufferSubData(gl_target, 0, size as _, data.as_ptr() as *const _);
ctx.cache.restore_buffer_binding(gl_target);
}
Buffer {
gl_buf,
buffer_type,
size: size as usize,
}
}
pub fn stream(ctx: &mut Context, buffer_type: BufferType, size: usize) -> Buffer {
let gl_target = gl_buffer_target(&buffer_type);
let gl_usage = gl_usage(&Usage::Stream);
let mut gl_buf: u32 = 0;
unsafe {
glGenBuffers(1, &mut gl_buf as *mut _);
ctx.cache.store_buffer_binding(gl_target);
ctx.cache.bind_buffer(gl_target, gl_buf);
glBufferData(gl_target, size as _, std::ptr::null() as *const _, gl_usage);
ctx.cache.restore_buffer_binding(gl_target);
}
Buffer {
gl_buf,
buffer_type,
size,
}
}
pub fn update<T>(&self, ctx: &mut Context, data: &[T]) {
let size = mem::size_of_val(data);
if !(size <= self.size) {
{
::std::rt::begin_panic("assertion failed: size <= self.size")
}
};
let gl_target = gl_buffer_target(&self.buffer_type);
ctx.cache.bind_buffer(gl_target, self.gl_buf);
unsafe { glBufferSubData(gl_target, 0, size as _, data.as_ptr() as *const _) };
ctx.cache.restore_buffer_binding(gl_target);
}
pub fn size(&self) -> usize {
self.size
}
pub fn delete(&self) {
unsafe { glDeleteBuffers(1, &self.gl_buf as *const _) }
}
}
}
pub use event::*;
pub use graphics::*;
pub use sapp::{rand, RAND_MAX};
use std::ffi::CString;
pub mod date {
#[cfg(not(target_arch = "wasm32"))]
pub fn now() -> f64 {
use std::time::SystemTime;
let time = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap_or_else(|e| ::std::rt::begin_panic(e));
time.as_secs_f64()
}
}
impl Context {
pub fn quit(&self) {
#[cfg(not(target_arch = "wasm32"))]
unsafe {
sapp::sapp_quit();
}
}
pub fn request_quit(&self) {
#[cfg(not(target_arch = "wasm32"))]
unsafe {
sapp::sapp_request_quit();
}
}
pub fn cancel_quit(&self) {
#[cfg(not(target_arch = "wasm32"))]
unsafe {
sapp::sapp_cancel_quit();
}
}
pub fn set_cursor_grab(&self, grab: bool) {
unsafe {
sapp::sapp_set_cursor_grab(grab);
}
}
pub fn show_mouse(&self, shown: bool) {
unsafe {
sapp::sapp_show_mouse(shown);
}
}
}
pub enum UserData {
Owning((Box<dyn EventHandler>, Context)),
Free(Box<dyn EventHandlerFree>),
}
impl UserData {
pub fn owning(event_handler: impl EventHandler + 'static, ctx: Context) -> UserData {
UserData::Owning((Box::new(event_handler), ctx))
}
pub fn free(event_handler: impl EventHandlerFree + 'static) -> UserData {
UserData::Free(Box::new(event_handler))
}
}
macro_rules! event_call {
($ event_handler : expr, $ fn : ident $ (, $ args : expr) *) =>
{
{
match $ event_handler
{
UserData :: Owning ((ref mut event_handler, ref mut context))
=> { event_handler . $ fn (context, $ ($ args,) *) ; }
UserData :: Free (ref mut event_handler) =>
{ event_handler . $ fn ($ ($ args,) *) ; }
}
}
} ;
}
enum UserDataState {
Uninitialized(Box<dyn 'static + FnOnce(Context) -> UserData>),
Intialized(UserData),
Empty,
}
extern "C" fn init(user_data: *mut ::std::os::raw::c_void) {
let data: &mut UserDataState = unsafe { &mut *(user_data as *mut UserDataState) };
let empty = UserDataState::Empty;
let f = std::mem::replace(data, empty);
let f = if let UserDataState::Uninitialized(f) = f {
f
} else {
{
{
::std::rt::begin_panic("explicit panic")
}
};
};
let context = graphics::Context::new();
let user_data = f(context);
std::mem::replace(data, UserDataState::Intialized(user_data));
}
extern "C" fn frame(user_data: *mut ::std::os::raw::c_void) {
let data: &mut UserDataState = unsafe { &mut *(user_data as *mut UserDataState) };
let data = if let UserDataState::Intialized(ref mut data) = data {
data
} else {
{
{
::std::rt::begin_panic("explicit panic")
}
}
};
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.update(context);
}
UserData::Free(ref mut event_handler) => {
event_handler.update();
}
}
};
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.draw(context);
}
UserData::Free(ref mut event_handler) => {
event_handler.draw();
}
}
};
}
extern "C" fn event(event: *const sapp::sapp_event, user_data: *mut ::std::os::raw::c_void) {
let data: &mut UserDataState = unsafe { &mut *(user_data as *mut UserDataState) };
let event = unsafe { &*event };
let data = if let UserDataState::Intialized(ref mut data) = data {
data
} else {
{
{
::std::rt::begin_panic("explicit panic")
}
}
};
match event.type_ {
sapp::sapp_event_type_SAPP_EVENTTYPE_MOUSE_MOVE => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.mouse_motion_event(context, event.mouse_x, event.mouse_y);
}
UserData::Free(ref mut event_handler) => {
event_handler.mouse_motion_event(event.mouse_x, event.mouse_y);
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_MOUSE_SCROLL => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.mouse_wheel_event(context, event.scroll_x, event.scroll_y);
}
UserData::Free(ref mut event_handler) => {
event_handler.mouse_wheel_event(event.scroll_x, event.scroll_y);
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_MOUSE_DOWN => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.mouse_button_down_event(
context,
MouseButton::from(event.mouse_button),
event.mouse_x,
event.mouse_y,
);
}
UserData::Free(ref mut event_handler) => {
event_handler.mouse_button_down_event(
MouseButton::from(event.mouse_button),
event.mouse_x,
event.mouse_y,
);
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_MOUSE_UP => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.mouse_button_up_event(
context,
MouseButton::from(event.mouse_button),
event.mouse_x,
event.mouse_y,
);
}
UserData::Free(ref mut event_handler) => {
event_handler.mouse_button_up_event(
MouseButton::from(event.mouse_button),
event.mouse_x,
event.mouse_y,
);
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_CHAR => {
if let Some(character) = std::char::from_u32(event.char_code) {
let key_mods = KeyMods::from(event.modifiers);
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.char_event(
context,
character,
key_mods,
event.key_repeat,
);
}
UserData::Free(ref mut event_handler) => {
event_handler.char_event(character, key_mods, event.key_repeat);
}
}
}
}
}
sapp::sapp_event_type_SAPP_EVENTTYPE_KEY_DOWN => {
let keycode = KeyCode::from(event.key_code);
let key_mods = KeyMods::from(event.modifiers);
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.key_down_event(context, keycode, key_mods, false);
}
UserData::Free(ref mut event_handler) => {
event_handler.key_down_event(keycode, key_mods, false);
}
}
}
}
sapp::sapp_event_type_SAPP_EVENTTYPE_KEY_UP => {
let keycode = KeyCode::from(event.key_code);
let key_mods = KeyMods::from(event.modifiers);
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.key_up_event(context, keycode, key_mods);
}
UserData::Free(ref mut event_handler) => {
event_handler.key_up_event(keycode, key_mods);
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_RESIZED => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.resize_event(
context,
event.window_width as f32,
event.window_height as f32,
);
}
UserData::Free(ref mut event_handler) => {
event_handler
.resize_event(event.window_width as f32, event.window_height as f32);
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_BEGAN
| sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_ENDED
| sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_CANCELLED
| sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_MOVED => {
for i in 0..(event.num_touches as usize) {
if event.touches[i].changed {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.touch_event(
context,
event.type_.into(),
event.touches[i].identifier as u64,
event.touches[i].pos_x,
event.touches[i].pos_y,
);
}
UserData::Free(ref mut event_handler) => {
event_handler.touch_event(
event.type_.into(),
event.touches[i].identifier as u64,
event.touches[i].pos_x,
event.touches[i].pos_y,
);
}
}
};
}
}
}
sapp::sapp_event_type_SAPP_EVENTTYPE_QUIT_REQUESTED => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.quit_requested_event(context);
}
UserData::Free(ref mut event_handler) => {
event_handler.quit_requested_event();
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_RAW_DEVICE => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.raw_mouse_motion(context, event.mouse_dx, event.mouse_dy);
}
UserData::Free(ref mut event_handler) => {
event_handler.raw_mouse_motion(event.mouse_dx, event.mouse_dy);
}
}
};
}
_ => {}
}
}
pub fn start<F>(conf: conf::Conf, f: F)
where
F: 'static + FnOnce(Context) -> UserData,
{
let mut desc: sapp::sapp_desc = unsafe { std::mem::zeroed() };
let title =
CString::new(conf.window_title.as_bytes()).unwrap_or_else(|e| ::std::rt::begin_panic(e));
let mut user_data = Box::new(UserDataState::Uninitialized(Box::new(f)));
desc.width = conf.window_width;
desc.height = conf.window_height;
desc.fullscreen = conf.fullscreen as _;
desc.high_dpi = conf.high_dpi as _;
desc.window_title = title.as_ptr();
desc.user_data = &mut *user_data as *mut _ as *mut _;
desc.init_userdata_cb = Some(init);
desc.frame_userdata_cb = Some(frame);
desc.event_userdata_cb = Some(event);
std::mem::forget(user_data);
unsafe { sapp::sapp_run(&desc as *const _) };
}
#![feature(prelude_import)]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std;
#[cfg(target_os = "linux")]
extern crate sapp_linux as sapp;
pub mod clipboard {
use crate::Context;
#[cfg(target_os = "linux")]
pub fn get(_ctx: &mut Context) -> Option<String> {
use std::ffi::CString;
let bufname = CString::new("CLIPBOARD").unwrap();
let fmtname = CString::new("UTF8_STRING").unwrap();
unsafe { sapp_linux::clipboard::get_clipboard(bufname.as_ptr(), fmtname.as_ptr()) }
}
#[cfg(target_os = "linux")]
pub fn set(_ctx: &mut Context, data: &str) {
use std::ffi::CString;
let bufname = CString::new("CLIPBOARD").unwrap();
unsafe {
sapp_linux::clipboard::claim_clipboard_ownership(bufname.as_ptr(), data.to_owned())
};
}
}
pub mod conf {
pub enum Cache {
No,
Index,
List(Vec<&'static str>),
Tar(&'static [u8]),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Cache {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&Cache::No,) => {
let mut debug_trait_builder = f.debug_tuple("No");
debug_trait_builder.finish()
}
(&Cache::Index,) => {
let mut debug_trait_builder = f.debug_tuple("Index");
debug_trait_builder.finish()
}
(&Cache::List(ref __self_0),) => {
let mut debug_trait_builder = f.debug_tuple("List");
let _ = debug_trait_builder.field(&&(*__self_0));
debug_trait_builder.finish()
}
(&Cache::Tar(ref __self_0),) => {
let mut debug_trait_builder = f.debug_tuple("Tar");
let _ = debug_trait_builder.field(&&(*__self_0));
debug_trait_builder.finish()
}
}
}
}
pub enum Loading {
No,
Embedded,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Loading {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&Loading::No,) => {
let mut debug_trait_builder = f.debug_tuple("No");
debug_trait_builder.finish()
}
(&Loading::Embedded,) => {
let mut debug_trait_builder = f.debug_tuple("Embedded");
debug_trait_builder.finish()
}
}
}
}
pub struct Conf {
pub cache: Cache,
pub loading: Loading,
pub window_title: String,
pub window_width: i32,
pub window_height: i32,
pub high_dpi: bool,
pub fullscreen: bool,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Conf {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
Conf {
cache: ref __self_0_0,
loading: ref __self_0_1,
window_title: ref __self_0_2,
window_width: ref __self_0_3,
window_height: ref __self_0_4,
high_dpi: ref __self_0_5,
fullscreen: ref __self_0_6,
} => {
let mut debug_trait_builder = f.debug_struct("Conf");
let _ = debug_trait_builder.field("cache", &&(*__self_0_0));
let _ = debug_trait_builder.field("loading", &&(*__self_0_1));
let _ = debug_trait_builder.field("window_title", &&(*__self_0_2));
let _ = debug_trait_builder.field("window_width", &&(*__self_0_3));
let _ = debug_trait_builder.field("window_height", &&(*__self_0_4));
let _ = debug_trait_builder.field("high_dpi", &&(*__self_0_5));
let _ = debug_trait_builder.field("fullscreen", &&(*__self_0_6));
debug_trait_builder.finish()
}
}
}
}
impl Default for Conf {
fn default() -> Conf {
Conf {
cache: Cache::No,
loading: Loading::No,
window_title: "".to_owned(),
window_width: 800,
window_height: 600,
high_dpi: false,
fullscreen: false,
}
}
}
}
mod event {
use crate::sapp::{self, sapp_keycode, sapp_mousebutton};
use crate::Context;
pub enum MouseButton {
Right,
Left,
Middle,
Unknown,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for MouseButton {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&MouseButton::Right,) => {
let mut debug_trait_builder = f.debug_tuple("Right");
debug_trait_builder.finish()
}
(&MouseButton::Left,) => {
let mut debug_trait_builder = f.debug_tuple("Left");
debug_trait_builder.finish()
}
(&MouseButton::Middle,) => {
let mut debug_trait_builder = f.debug_tuple("Middle");
debug_trait_builder.finish()
}
(&MouseButton::Unknown,) => {
let mut debug_trait_builder = f.debug_tuple("Unknown");
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for MouseButton {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for MouseButton {
#[inline]
fn clone(&self) -> MouseButton {
{
*self
}
}
}
impl ::core::marker::StructuralPartialEq for MouseButton {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for MouseButton {
#[inline]
fn eq(&self, other: &MouseButton) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::hash::Hash for MouseButton {
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
match (&*self,) {
_ => ::core::hash::Hash::hash(
&unsafe { ::core::intrinsics::discriminant_value(self) },
state,
),
}
}
}
impl ::core::marker::StructuralEq for MouseButton {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for MouseButton {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
pub struct Touch {
pub id: u32,
pub x: f32,
pub y: f32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Touch {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
Touch {
id: ref __self_0_0,
x: ref __self_0_1,
y: ref __self_0_2,
} => {
let mut debug_trait_builder = f.debug_struct("Touch");
let _ = debug_trait_builder.field("id", &&(*__self_0_0));
let _ = debug_trait_builder.field("x", &&(*__self_0_1));
let _ = debug_trait_builder.field("y", &&(*__self_0_2));
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Touch {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Touch {
#[inline]
fn clone(&self) -> Touch {
{
let _: ::core::clone::AssertParamIsClone<u32>;
let _: ::core::clone::AssertParamIsClone<f32>;
let _: ::core::clone::AssertParamIsClone<f32>;
*self
}
}
}
impl From<sapp_mousebutton> for MouseButton {
fn from(btn: sapp_mousebutton) -> MouseButton {
match btn {
sapp::sapp_mousebutton_SAPP_MOUSEBUTTON_LEFT => MouseButton::Left,
sapp::sapp_mousebutton_SAPP_MOUSEBUTTON_RIGHT => MouseButton::Right,
sapp::sapp_mousebutton_SAPP_MOUSEBUTTON_MIDDLE => MouseButton::Middle,
_ => MouseButton::Unknown,
}
}
}
#[repr(u32)]
pub enum KeyCode {
Space,
Apostrophe,
Comma,
Minus,
Period,
Slash,
Key0,
Key1,
Key2,
Key3,
Key4,
Key5,
Key6,
Key7,
Key8,
Key9,
Semicolon,
Equal,
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q,
R,
S,
T,
U,
V,
W,
X,
Y,
Z,
LeftBracket,
Backslash,
RightBracket,
GraveAccent,
World1,
World2,
Escape,
Enter,
Tab,
Backspace,
Insert,
Delete,
Right,
Left,
Down,
Up,
PageUp,
PageDown,
Home,
End,
CapsLock,
ScrollLock,
NumLock,
PrintScreen,
Pause,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
F13,
F14,
F15,
F16,
F17,
F18,
F19,
F20,
F21,
F22,
F23,
F24,
F25,
Kp0,
Kp1,
Kp2,
Kp3,
Kp4,
Kp5,
Kp6,
Kp7,
Kp8,
Kp9,
KpDecimal,
KpDivide,
KpMultiply,
KpSubtract,
KpAdd,
KpEnter,
KpEqual,
LeftShift,
LeftControl,
LeftAlt,
LeftSuper,
RightShift,
RightControl,
RightAlt,
RightSuper,
Menu,
Unknown,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for KeyCode {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&KeyCode::Space,) => {
let mut debug_trait_builder = f.debug_tuple("Space");
debug_trait_builder.finish()
}
(&KeyCode::Apostrophe,) => {
let mut debug_trait_builder = f.debug_tuple("Apostrophe");
debug_trait_builder.finish()
}
(&KeyCode::Comma,) => {
let mut debug_trait_builder = f.debug_tuple("Comma");
debug_trait_builder.finish()
}
(&KeyCode::Minus,) => {
let mut debug_trait_builder = f.debug_tuple("Minus");
debug_trait_builder.finish()
}
(&KeyCode::Period,) => {
let mut debug_trait_builder = f.debug_tuple("Period");
debug_trait_builder.finish()
}
(&KeyCode::Slash,) => {
let mut debug_trait_builder = f.debug_tuple("Slash");
debug_trait_builder.finish()
}
(&KeyCode::Key0,) => {
let mut debug_trait_builder = f.debug_tuple("Key0");
debug_trait_builder.finish()
}
(&KeyCode::Key1,) => {
let mut debug_trait_builder = f.debug_tuple("Key1");
debug_trait_builder.finish()
}
(&KeyCode::Key2,) => {
let mut debug_trait_builder = f.debug_tuple("Key2");
debug_trait_builder.finish()
}
(&KeyCode::Key3,) => {
let mut debug_trait_builder = f.debug_tuple("Key3");
debug_trait_builder.finish()
}
(&KeyCode::Key4,) => {
let mut debug_trait_builder = f.debug_tuple("Key4");
debug_trait_builder.finish()
}
(&KeyCode::Key5,) => {
let mut debug_trait_builder = f.debug_tuple("Key5");
debug_trait_builder.finish()
}
(&KeyCode::Key6,) => {
let mut debug_trait_builder = f.debug_tuple("Key6");
debug_trait_builder.finish()
}
(&KeyCode::Key7,) => {
let mut debug_trait_builder = f.debug_tuple("Key7");
debug_trait_builder.finish()
}
(&KeyCode::Key8,) => {
let mut debug_trait_builder = f.debug_tuple("Key8");
debug_trait_builder.finish()
}
(&KeyCode::Key9,) => {
let mut debug_trait_builder = f.debug_tuple("Key9");
debug_trait_builder.finish()
}
(&KeyCode::Semicolon,) => {
let mut debug_trait_builder = f.debug_tuple("Semicolon");
debug_trait_builder.finish()
}
(&KeyCode::Equal,) => {
let mut debug_trait_builder = f.debug_tuple("Equal");
debug_trait_builder.finish()
}
(&KeyCode::A,) => {
let mut debug_trait_builder = f.debug_tuple("A");
debug_trait_builder.finish()
}
(&KeyCode::B,) => {
let mut debug_trait_builder = f.debug_tuple("B");
debug_trait_builder.finish()
}
(&KeyCode::C,) => {
let mut debug_trait_builder = f.debug_tuple("C");
debug_trait_builder.finish()
}
(&KeyCode::D,) => {
let mut debug_trait_builder = f.debug_tuple("D");
debug_trait_builder.finish()
}
(&KeyCode::E,) => {
let mut debug_trait_builder = f.debug_tuple("E");
debug_trait_builder.finish()
}
(&KeyCode::F,) => {
let mut debug_trait_builder = f.debug_tuple("F");
debug_trait_builder.finish()
}
(&KeyCode::G,) => {
let mut debug_trait_builder = f.debug_tuple("G");
debug_trait_builder.finish()
}
(&KeyCode::H,) => {
let mut debug_trait_builder = f.debug_tuple("H");
debug_trait_builder.finish()
}
(&KeyCode::I,) => {
let mut debug_trait_builder = f.debug_tuple("I");
debug_trait_builder.finish()
}
(&KeyCode::J,) => {
let mut debug_trait_builder = f.debug_tuple("J");
debug_trait_builder.finish()
}
(&KeyCode::K,) => {
let mut debug_trait_builder = f.debug_tuple("K");
debug_trait_builder.finish()
}
(&KeyCode::L,) => {
let mut debug_trait_builder = f.debug_tuple("L");
debug_trait_builder.finish()
}
(&KeyCode::M,) => {
let mut debug_trait_builder = f.debug_tuple("M");
debug_trait_builder.finish()
}
(&KeyCode::N,) => {
let mut debug_trait_builder = f.debug_tuple("N");
debug_trait_builder.finish()
}
(&KeyCode::O,) => {
let mut debug_trait_builder = f.debug_tuple("O");
debug_trait_builder.finish()
}
(&KeyCode::P,) => {
let mut debug_trait_builder = f.debug_tuple("P");
debug_trait_builder.finish()
}
(&KeyCode::Q,) => {
let mut debug_trait_builder = f.debug_tuple("Q");
debug_trait_builder.finish()
}
(&KeyCode::R,) => {
let mut debug_trait_builder = f.debug_tuple("R");
debug_trait_builder.finish()
}
(&KeyCode::S,) => {
let mut debug_trait_builder = f.debug_tuple("S");
debug_trait_builder.finish()
}
(&KeyCode::T,) => {
let mut debug_trait_builder = f.debug_tuple("T");
debug_trait_builder.finish()
}
(&KeyCode::U,) => {
let mut debug_trait_builder = f.debug_tuple("U");
debug_trait_builder.finish()
}
(&KeyCode::V,) => {
let mut debug_trait_builder = f.debug_tuple("V");
debug_trait_builder.finish()
}
(&KeyCode::W,) => {
let mut debug_trait_builder = f.debug_tuple("W");
debug_trait_builder.finish()
}
(&KeyCode::X,) => {
let mut debug_trait_builder = f.debug_tuple("X");
debug_trait_builder.finish()
}
(&KeyCode::Y,) => {
let mut debug_trait_builder = f.debug_tuple("Y");
debug_trait_builder.finish()
}
(&KeyCode::Z,) => {
let mut debug_trait_builder = f.debug_tuple("Z");
debug_trait_builder.finish()
}
(&KeyCode::LeftBracket,) => {
let mut debug_trait_builder = f.debug_tuple("LeftBracket");
debug_trait_builder.finish()
}
(&KeyCode::Backslash,) => {
let mut debug_trait_builder = f.debug_tuple("Backslash");
debug_trait_builder.finish()
}
(&KeyCode::RightBracket,) => {
let mut debug_trait_builder = f.debug_tuple("RightBracket");
debug_trait_builder.finish()
}
(&KeyCode::GraveAccent,) => {
let mut debug_trait_builder = f.debug_tuple("GraveAccent");
debug_trait_builder.finish()
}
(&KeyCode::World1,) => {
let mut debug_trait_builder = f.debug_tuple("World1");
debug_trait_builder.finish()
}
(&KeyCode::World2,) => {
let mut debug_trait_builder = f.debug_tuple("World2");
debug_trait_builder.finish()
}
(&KeyCode::Escape,) => {
let mut debug_trait_builder = f.debug_tuple("Escape");
debug_trait_builder.finish()
}
(&KeyCode::Enter,) => {
let mut debug_trait_builder = f.debug_tuple("Enter");
debug_trait_builder.finish()
}
(&KeyCode::Tab,) => {
let mut debug_trait_builder = f.debug_tuple("Tab");
debug_trait_builder.finish()
}
(&KeyCode::Backspace,) => {
let mut debug_trait_builder = f.debug_tuple("Backspace");
debug_trait_builder.finish()
}
(&KeyCode::Insert,) => {
let mut debug_trait_builder = f.debug_tuple("Insert");
debug_trait_builder.finish()
}
(&KeyCode::Delete,) => {
let mut debug_trait_builder = f.debug_tuple("Delete");
debug_trait_builder.finish()
}
(&KeyCode::Right,) => {
let mut debug_trait_builder = f.debug_tuple("Right");
debug_trait_builder.finish()
}
(&KeyCode::Left,) => {
let mut debug_trait_builder = f.debug_tuple("Left");
debug_trait_builder.finish()
}
(&KeyCode::Down,) => {
let mut debug_trait_builder = f.debug_tuple("Down");
debug_trait_builder.finish()
}
(&KeyCode::Up,) => {
let mut debug_trait_builder = f.debug_tuple("Up");
debug_trait_builder.finish()
}
(&KeyCode::PageUp,) => {
let mut debug_trait_builder = f.debug_tuple("PageUp");
debug_trait_builder.finish()
}
(&KeyCode::PageDown,) => {
let mut debug_trait_builder = f.debug_tuple("PageDown");
debug_trait_builder.finish()
}
(&KeyCode::Home,) => {
let mut debug_trait_builder = f.debug_tuple("Home");
debug_trait_builder.finish()
}
(&KeyCode::End,) => {
let mut debug_trait_builder = f.debug_tuple("End");
debug_trait_builder.finish()
}
(&KeyCode::CapsLock,) => {
let mut debug_trait_builder = f.debug_tuple("CapsLock");
debug_trait_builder.finish()
}
(&KeyCode::ScrollLock,) => {
let mut debug_trait_builder = f.debug_tuple("ScrollLock");
debug_trait_builder.finish()
}
(&KeyCode::NumLock,) => {
let mut debug_trait_builder = f.debug_tuple("NumLock");
debug_trait_builder.finish()
}
(&KeyCode::PrintScreen,) => {
let mut debug_trait_builder = f.debug_tuple("PrintScreen");
debug_trait_builder.finish()
}
(&KeyCode::Pause,) => {
let mut debug_trait_builder = f.debug_tuple("Pause");
debug_trait_builder.finish()
}
(&KeyCode::F1,) => {
let mut debug_trait_builder = f.debug_tuple("F1");
debug_trait_builder.finish()
}
(&KeyCode::F2,) => {
let mut debug_trait_builder = f.debug_tuple("F2");
debug_trait_builder.finish()
}
(&KeyCode::F3,) => {
let mut debug_trait_builder = f.debug_tuple("F3");
debug_trait_builder.finish()
}
(&KeyCode::F4,) => {
let mut debug_trait_builder = f.debug_tuple("F4");
debug_trait_builder.finish()
}
(&KeyCode::F5,) => {
let mut debug_trait_builder = f.debug_tuple("F5");
debug_trait_builder.finish()
}
(&KeyCode::F6,) => {
let mut debug_trait_builder = f.debug_tuple("F6");
debug_trait_builder.finish()
}
(&KeyCode::F7,) => {
let mut debug_trait_builder = f.debug_tuple("F7");
debug_trait_builder.finish()
}
(&KeyCode::F8,) => {
let mut debug_trait_builder = f.debug_tuple("F8");
debug_trait_builder.finish()
}
(&KeyCode::F9,) => {
let mut debug_trait_builder = f.debug_tuple("F9");
debug_trait_builder.finish()
}
(&KeyCode::F10,) => {
let mut debug_trait_builder = f.debug_tuple("F10");
debug_trait_builder.finish()
}
(&KeyCode::F11,) => {
let mut debug_trait_builder = f.debug_tuple("F11");
debug_trait_builder.finish()
}
(&KeyCode::F12,) => {
let mut debug_trait_builder = f.debug_tuple("F12");
debug_trait_builder.finish()
}
(&KeyCode::F13,) => {
let mut debug_trait_builder = f.debug_tuple("F13");
debug_trait_builder.finish()
}
(&KeyCode::F14,) => {
let mut debug_trait_builder = f.debug_tuple("F14");
debug_trait_builder.finish()
}
(&KeyCode::F15,) => {
let mut debug_trait_builder = f.debug_tuple("F15");
debug_trait_builder.finish()
}
(&KeyCode::F16,) => {
let mut debug_trait_builder = f.debug_tuple("F16");
debug_trait_builder.finish()
}
(&KeyCode::F17,) => {
let mut debug_trait_builder = f.debug_tuple("F17");
debug_trait_builder.finish()
}
(&KeyCode::F18,) => {
let mut debug_trait_builder = f.debug_tuple("F18");
debug_trait_builder.finish()
}
(&KeyCode::F19,) => {
let mut debug_trait_builder = f.debug_tuple("F19");
debug_trait_builder.finish()
}
(&KeyCode::F20,) => {
let mut debug_trait_builder = f.debug_tuple("F20");
debug_trait_builder.finish()
}
(&KeyCode::F21,) => {
let mut debug_trait_builder = f.debug_tuple("F21");
debug_trait_builder.finish()
}
(&KeyCode::F22,) => {
let mut debug_trait_builder = f.debug_tuple("F22");
debug_trait_builder.finish()
}
(&KeyCode::F23,) => {
let mut debug_trait_builder = f.debug_tuple("F23");
debug_trait_builder.finish()
}
(&KeyCode::F24,) => {
let mut debug_trait_builder = f.debug_tuple("F24");
debug_trait_builder.finish()
}
(&KeyCode::F25,) => {
let mut debug_trait_builder = f.debug_tuple("F25");
debug_trait_builder.finish()
}
(&KeyCode::Kp0,) => {
let mut debug_trait_builder = f.debug_tuple("Kp0");
debug_trait_builder.finish()
}
(&KeyCode::Kp1,) => {
let mut debug_trait_builder = f.debug_tuple("Kp1");
debug_trait_builder.finish()
}
(&KeyCode::Kp2,) => {
let mut debug_trait_builder = f.debug_tuple("Kp2");
debug_trait_builder.finish()
}
(&KeyCode::Kp3,) => {
let mut debug_trait_builder = f.debug_tuple("Kp3");
debug_trait_builder.finish()
}
(&KeyCode::Kp4,) => {
let mut debug_trait_builder = f.debug_tuple("Kp4");
debug_trait_builder.finish()
}
(&KeyCode::Kp5,) => {
let mut debug_trait_builder = f.debug_tuple("Kp5");
debug_trait_builder.finish()
}
(&KeyCode::Kp6,) => {
let mut debug_trait_builder = f.debug_tuple("Kp6");
debug_trait_builder.finish()
}
(&KeyCode::Kp7,) => {
let mut debug_trait_builder = f.debug_tuple("Kp7");
debug_trait_builder.finish()
}
(&KeyCode::Kp8,) => {
let mut debug_trait_builder = f.debug_tuple("Kp8");
debug_trait_builder.finish()
}
(&KeyCode::Kp9,) => {
let mut debug_trait_builder = f.debug_tuple("Kp9");
debug_trait_builder.finish()
}
(&KeyCode::KpDecimal,) => {
let mut debug_trait_builder = f.debug_tuple("KpDecimal");
debug_trait_builder.finish()
}
(&KeyCode::KpDivide,) => {
let mut debug_trait_builder = f.debug_tuple("KpDivide");
debug_trait_builder.finish()
}
(&KeyCode::KpMultiply,) => {
let mut debug_trait_builder = f.debug_tuple("KpMultiply");
debug_trait_builder.finish()
}
(&KeyCode::KpSubtract,) => {
let mut debug_trait_builder = f.debug_tuple("KpSubtract");
debug_trait_builder.finish()
}
(&KeyCode::KpAdd,) => {
let mut debug_trait_builder = f.debug_tuple("KpAdd");
debug_trait_builder.finish()
}
(&KeyCode::KpEnter,) => {
let mut debug_trait_builder = f.debug_tuple("KpEnter");
debug_trait_builder.finish()
}
(&KeyCode::KpEqual,) => {
let mut debug_trait_builder = f.debug_tuple("KpEqual");
debug_trait_builder.finish()
}
(&KeyCode::LeftShift,) => {
let mut debug_trait_builder = f.debug_tuple("LeftShift");
debug_trait_builder.finish()
}
(&KeyCode::LeftControl,) => {
let mut debug_trait_builder = f.debug_tuple("LeftControl");
debug_trait_builder.finish()
}
(&KeyCode::LeftAlt,) => {
let mut debug_trait_builder = f.debug_tuple("LeftAlt");
debug_trait_builder.finish()
}
(&KeyCode::LeftSuper,) => {
let mut debug_trait_builder = f.debug_tuple("LeftSuper");
debug_trait_builder.finish()
}
(&KeyCode::RightShift,) => {
let mut debug_trait_builder = f.debug_tuple("RightShift");
debug_trait_builder.finish()
}
(&KeyCode::RightControl,) => {
let mut debug_trait_builder = f.debug_tuple("RightControl");
debug_trait_builder.finish()
}
(&KeyCode::RightAlt,) => {
let mut debug_trait_builder = f.debug_tuple("RightAlt");
debug_trait_builder.finish()
}
(&KeyCode::RightSuper,) => {
let mut debug_trait_builder = f.debug_tuple("RightSuper");
debug_trait_builder.finish()
}
(&KeyCode::Menu,) => {
let mut debug_trait_builder = f.debug_tuple("Menu");
debug_trait_builder.finish()
}
(&KeyCode::Unknown,) => {
let mut debug_trait_builder = f.debug_tuple("Unknown");
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for KeyCode {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for KeyCode {
#[inline]
fn clone(&self) -> KeyCode {
{
*self
}
}
}
impl ::core::marker::StructuralPartialEq for KeyCode {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for KeyCode {
#[inline]
fn eq(&self, other: &KeyCode) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as u32;
let __arg_1_vi = unsafe { ::core::intrinsics::discriminant_value(&*other) } as u32;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::hash::Hash for KeyCode {
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
match (&*self,) {
_ => ::core::hash::Hash::hash(
&unsafe { ::core::intrinsics::discriminant_value(self) },
state,
),
}
}
}
impl ::core::marker::StructuralEq for KeyCode {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for KeyCode {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
impl From<sapp_keycode> for KeyCode {
fn from(key_code: sapp_keycode) -> KeyCode {
match key_code {
sapp::sapp_keycode_SAPP_KEYCODE_SPACE => KeyCode::Space,
sapp::sapp_keycode_SAPP_KEYCODE_APOSTROPHE => KeyCode::Apostrophe,
sapp::sapp_keycode_SAPP_KEYCODE_COMMA => KeyCode::Comma,
sapp::sapp_keycode_SAPP_KEYCODE_MINUS => KeyCode::Minus,
sapp::sapp_keycode_SAPP_KEYCODE_PERIOD => KeyCode::Period,
sapp::sapp_keycode_SAPP_KEYCODE_SLASH => KeyCode::Slash,
sapp::sapp_keycode_SAPP_KEYCODE_0 => KeyCode::Key0,
sapp::sapp_keycode_SAPP_KEYCODE_1 => KeyCode::Key1,
sapp::sapp_keycode_SAPP_KEYCODE_2 => KeyCode::Key2,
sapp::sapp_keycode_SAPP_KEYCODE_3 => KeyCode::Key3,
sapp::sapp_keycode_SAPP_KEYCODE_4 => KeyCode::Key4,
sapp::sapp_keycode_SAPP_KEYCODE_5 => KeyCode::Key5,
sapp::sapp_keycode_SAPP_KEYCODE_6 => KeyCode::Key6,
sapp::sapp_keycode_SAPP_KEYCODE_7 => KeyCode::Key7,
sapp::sapp_keycode_SAPP_KEYCODE_8 => KeyCode::Key8,
sapp::sapp_keycode_SAPP_KEYCODE_9 => KeyCode::Key9,
sapp::sapp_keycode_SAPP_KEYCODE_SEMICOLON => KeyCode::Semicolon,
sapp::sapp_keycode_SAPP_KEYCODE_EQUAL => KeyCode::Equal,
sapp::sapp_keycode_SAPP_KEYCODE_A => KeyCode::A,
sapp::sapp_keycode_SAPP_KEYCODE_B => KeyCode::B,
sapp::sapp_keycode_SAPP_KEYCODE_C => KeyCode::C,
sapp::sapp_keycode_SAPP_KEYCODE_D => KeyCode::D,
sapp::sapp_keycode_SAPP_KEYCODE_E => KeyCode::E,
sapp::sapp_keycode_SAPP_KEYCODE_F => KeyCode::F,
sapp::sapp_keycode_SAPP_KEYCODE_G => KeyCode::G,
sapp::sapp_keycode_SAPP_KEYCODE_H => KeyCode::H,
sapp::sapp_keycode_SAPP_KEYCODE_I => KeyCode::I,
sapp::sapp_keycode_SAPP_KEYCODE_J => KeyCode::J,
sapp::sapp_keycode_SAPP_KEYCODE_K => KeyCode::K,
sapp::sapp_keycode_SAPP_KEYCODE_L => KeyCode::L,
sapp::sapp_keycode_SAPP_KEYCODE_M => KeyCode::M,
sapp::sapp_keycode_SAPP_KEYCODE_N => KeyCode::N,
sapp::sapp_keycode_SAPP_KEYCODE_O => KeyCode::O,
sapp::sapp_keycode_SAPP_KEYCODE_P => KeyCode::P,
sapp::sapp_keycode_SAPP_KEYCODE_Q => KeyCode::Q,
sapp::sapp_keycode_SAPP_KEYCODE_R => KeyCode::R,
sapp::sapp_keycode_SAPP_KEYCODE_S => KeyCode::S,
sapp::sapp_keycode_SAPP_KEYCODE_T => KeyCode::T,
sapp::sapp_keycode_SAPP_KEYCODE_U => KeyCode::U,
sapp::sapp_keycode_SAPP_KEYCODE_V => KeyCode::V,
sapp::sapp_keycode_SAPP_KEYCODE_W => KeyCode::W,
sapp::sapp_keycode_SAPP_KEYCODE_X => KeyCode::X,
sapp::sapp_keycode_SAPP_KEYCODE_Y => KeyCode::Y,
sapp::sapp_keycode_SAPP_KEYCODE_Z => KeyCode::Z,
sapp::sapp_keycode_SAPP_KEYCODE_LEFT_BRACKET => KeyCode::LeftBracket,
sapp::sapp_keycode_SAPP_KEYCODE_BACKSLASH => KeyCode::Backslash,
sapp::sapp_keycode_SAPP_KEYCODE_RIGHT_BRACKET => KeyCode::RightBracket,
sapp::sapp_keycode_SAPP_KEYCODE_GRAVE_ACCENT => KeyCode::GraveAccent,
sapp::sapp_keycode_SAPP_KEYCODE_WORLD_1 => KeyCode::World1,
sapp::sapp_keycode_SAPP_KEYCODE_WORLD_2 => KeyCode::World2,
sapp::sapp_keycode_SAPP_KEYCODE_ESCAPE => KeyCode::Escape,
sapp::sapp_keycode_SAPP_KEYCODE_ENTER => KeyCode::Enter,
sapp::sapp_keycode_SAPP_KEYCODE_TAB => KeyCode::Tab,
sapp::sapp_keycode_SAPP_KEYCODE_BACKSPACE => KeyCode::Backspace,
sapp::sapp_keycode_SAPP_KEYCODE_INSERT => KeyCode::Insert,
sapp::sapp_keycode_SAPP_KEYCODE_DELETE => KeyCode::Delete,
sapp::sapp_keycode_SAPP_KEYCODE_RIGHT => KeyCode::Right,
sapp::sapp_keycode_SAPP_KEYCODE_LEFT => KeyCode::Left,
sapp::sapp_keycode_SAPP_KEYCODE_DOWN => KeyCode::Down,
sapp::sapp_keycode_SAPP_KEYCODE_UP => KeyCode::Up,
sapp::sapp_keycode_SAPP_KEYCODE_PAGE_UP => KeyCode::PageUp,
sapp::sapp_keycode_SAPP_KEYCODE_PAGE_DOWN => KeyCode::PageDown,
sapp::sapp_keycode_SAPP_KEYCODE_HOME => KeyCode::Home,
sapp::sapp_keycode_SAPP_KEYCODE_END => KeyCode::End,
sapp::sapp_keycode_SAPP_KEYCODE_CAPS_LOCK => KeyCode::CapsLock,
sapp::sapp_keycode_SAPP_KEYCODE_SCROLL_LOCK => KeyCode::ScrollLock,
sapp::sapp_keycode_SAPP_KEYCODE_NUM_LOCK => KeyCode::NumLock,
sapp::sapp_keycode_SAPP_KEYCODE_PRINT_SCREEN => KeyCode::PrintScreen,
sapp::sapp_keycode_SAPP_KEYCODE_PAUSE => KeyCode::Pause,
sapp::sapp_keycode_SAPP_KEYCODE_F1 => KeyCode::F1,
sapp::sapp_keycode_SAPP_KEYCODE_F2 => KeyCode::F2,
sapp::sapp_keycode_SAPP_KEYCODE_F3 => KeyCode::F3,
sapp::sapp_keycode_SAPP_KEYCODE_F4 => KeyCode::F4,
sapp::sapp_keycode_SAPP_KEYCODE_F5 => KeyCode::F5,
sapp::sapp_keycode_SAPP_KEYCODE_F6 => KeyCode::F6,
sapp::sapp_keycode_SAPP_KEYCODE_F7 => KeyCode::F7,
sapp::sapp_keycode_SAPP_KEYCODE_F8 => KeyCode::F8,
sapp::sapp_keycode_SAPP_KEYCODE_F9 => KeyCode::F9,
sapp::sapp_keycode_SAPP_KEYCODE_F10 => KeyCode::F10,
sapp::sapp_keycode_SAPP_KEYCODE_F11 => KeyCode::F11,
sapp::sapp_keycode_SAPP_KEYCODE_F12 => KeyCode::F12,
sapp::sapp_keycode_SAPP_KEYCODE_F13 => KeyCode::F13,
sapp::sapp_keycode_SAPP_KEYCODE_F14 => KeyCode::F14,
sapp::sapp_keycode_SAPP_KEYCODE_F15 => KeyCode::F15,
sapp::sapp_keycode_SAPP_KEYCODE_F16 => KeyCode::F16,
sapp::sapp_keycode_SAPP_KEYCODE_F17 => KeyCode::F17,
sapp::sapp_keycode_SAPP_KEYCODE_F18 => KeyCode::F18,
sapp::sapp_keycode_SAPP_KEYCODE_F19 => KeyCode::F19,
sapp::sapp_keycode_SAPP_KEYCODE_F20 => KeyCode::F20,
sapp::sapp_keycode_SAPP_KEYCODE_F21 => KeyCode::F21,
sapp::sapp_keycode_SAPP_KEYCODE_F22 => KeyCode::F22,
sapp::sapp_keycode_SAPP_KEYCODE_F23 => KeyCode::F23,
sapp::sapp_keycode_SAPP_KEYCODE_F24 => KeyCode::F24,
sapp::sapp_keycode_SAPP_KEYCODE_F25 => KeyCode::F25,
sapp::sapp_keycode_SAPP_KEYCODE_KP_0 => KeyCode::Kp0,
sapp::sapp_keycode_SAPP_KEYCODE_KP_1 => KeyCode::Kp1,
sapp::sapp_keycode_SAPP_KEYCODE_KP_2 => KeyCode::Kp2,
sapp::sapp_keycode_SAPP_KEYCODE_KP_3 => KeyCode::Kp3,
sapp::sapp_keycode_SAPP_KEYCODE_KP_4 => KeyCode::Kp4,
sapp::sapp_keycode_SAPP_KEYCODE_KP_5 => KeyCode::Kp5,
sapp::sapp_keycode_SAPP_KEYCODE_KP_6 => KeyCode::Kp6,
sapp::sapp_keycode_SAPP_KEYCODE_KP_7 => KeyCode::Kp7,
sapp::sapp_keycode_SAPP_KEYCODE_KP_8 => KeyCode::Kp8,
sapp::sapp_keycode_SAPP_KEYCODE_KP_9 => KeyCode::Kp9,
sapp::sapp_keycode_SAPP_KEYCODE_KP_DECIMAL => KeyCode::KpDecimal,
sapp::sapp_keycode_SAPP_KEYCODE_KP_DIVIDE => KeyCode::KpDivide,
sapp::sapp_keycode_SAPP_KEYCODE_KP_MULTIPLY => KeyCode::KpMultiply,
sapp::sapp_keycode_SAPP_KEYCODE_KP_SUBTRACT => KeyCode::KpSubtract,
sapp::sapp_keycode_SAPP_KEYCODE_KP_ADD => KeyCode::KpAdd,
sapp::sapp_keycode_SAPP_KEYCODE_KP_ENTER => KeyCode::KpEnter,
sapp::sapp_keycode_SAPP_KEYCODE_KP_EQUAL => KeyCode::KpEqual,
sapp::sapp_keycode_SAPP_KEYCODE_LEFT_SHIFT => KeyCode::LeftShift,
sapp::sapp_keycode_SAPP_KEYCODE_LEFT_CONTROL => KeyCode::LeftControl,
sapp::sapp_keycode_SAPP_KEYCODE_LEFT_ALT => KeyCode::LeftAlt,
sapp::sapp_keycode_SAPP_KEYCODE_LEFT_SUPER => KeyCode::LeftSuper,
sapp::sapp_keycode_SAPP_KEYCODE_RIGHT_SHIFT => KeyCode::RightShift,
sapp::sapp_keycode_SAPP_KEYCODE_RIGHT_CONTROL => KeyCode::RightControl,
sapp::sapp_keycode_SAPP_KEYCODE_RIGHT_ALT => KeyCode::RightAlt,
sapp::sapp_keycode_SAPP_KEYCODE_RIGHT_SUPER => KeyCode::RightSuper,
sapp::sapp_keycode_SAPP_KEYCODE_MENU => KeyCode::Menu,
_ => KeyCode::Unknown,
}
}
}
pub struct KeyMods {
pub shift: bool,
pub ctrl: bool,
pub alt: bool,
pub logo: bool,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for KeyMods {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
KeyMods {
shift: ref __self_0_0,
ctrl: ref __self_0_1,
alt: ref __self_0_2,
logo: ref __self_0_3,
} => {
let mut debug_trait_builder = f.debug_struct("KeyMods");
let _ = debug_trait_builder.field("shift", &&(*__self_0_0));
let _ = debug_trait_builder.field("ctrl", &&(*__self_0_1));
let _ = debug_trait_builder.field("alt", &&(*__self_0_2));
let _ = debug_trait_builder.field("logo", &&(*__self_0_3));
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for KeyMods {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for KeyMods {
#[inline]
fn clone(&self) -> KeyMods {
{
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<bool>;
*self
}
}
}
impl ::core::marker::StructuralPartialEq for KeyMods {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for KeyMods {
#[inline]
fn eq(&self, other: &KeyMods) -> bool {
match *other {
KeyMods {
shift: ref __self_1_0,
ctrl: ref __self_1_1,
alt: ref __self_1_2,
logo: ref __self_1_3,
} => match *self {
KeyMods {
shift: ref __self_0_0,
ctrl: ref __self_0_1,
alt: ref __self_0_2,
logo: ref __self_0_3,
} => {
(*__self_0_0) == (*__self_1_0)
&& (*__self_0_1) == (*__self_1_1)
&& (*__self_0_2) == (*__self_1_2)
&& (*__self_0_3) == (*__self_1_3)
}
},
}
}
#[inline]
fn ne(&self, other: &KeyMods) -> bool {
match *other {
KeyMods {
shift: ref __self_1_0,
ctrl: ref __self_1_1,
alt: ref __self_1_2,
logo: ref __self_1_3,
} => match *self {
KeyMods {
shift: ref __self_0_0,
ctrl: ref __self_0_1,
alt: ref __self_0_2,
logo: ref __self_0_3,
} => {
(*__self_0_0) != (*__self_1_0)
|| (*__self_0_1) != (*__self_1_1)
|| (*__self_0_2) != (*__self_1_2)
|| (*__self_0_3) != (*__self_1_3)
}
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::default::Default for KeyMods {
#[inline]
fn default() -> KeyMods {
KeyMods {
shift: ::core::default::Default::default(),
ctrl: ::core::default::Default::default(),
alt: ::core::default::Default::default(),
logo: ::core::default::Default::default(),
}
}
}
impl From<u32> for KeyMods {
fn from(value: u32) -> KeyMods {
let mut key_mods = KeyMods::default();
if value & sapp::SAPP_MODIFIER_SHIFT != 0 {
key_mods.shift = true;
}
if value & sapp::SAPP_MODIFIER_CTRL != 0 {
key_mods.ctrl = true;
}
if value & sapp::SAPP_MODIFIER_ALT != 0 {
key_mods.alt = true;
}
if value & sapp::SAPP_MODIFIER_SUPER != 0 {
key_mods.logo = true;
}
key_mods
}
}
pub enum TouchPhase {
Started,
Moved,
Ended,
Cancelled,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for TouchPhase {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&TouchPhase::Started,) => {
let mut debug_trait_builder = f.debug_tuple("Started");
debug_trait_builder.finish()
}
(&TouchPhase::Moved,) => {
let mut debug_trait_builder = f.debug_tuple("Moved");
debug_trait_builder.finish()
}
(&TouchPhase::Ended,) => {
let mut debug_trait_builder = f.debug_tuple("Ended");
debug_trait_builder.finish()
}
(&TouchPhase::Cancelled,) => {
let mut debug_trait_builder = f.debug_tuple("Cancelled");
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::hash::Hash for TouchPhase {
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
match (&*self,) {
_ => ::core::hash::Hash::hash(
&unsafe { ::core::intrinsics::discriminant_value(self) },
state,
),
}
}
}
impl ::core::marker::StructuralPartialEq for TouchPhase {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for TouchPhase {
#[inline]
fn eq(&self, other: &TouchPhase) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for TouchPhase {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for TouchPhase {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for TouchPhase {
#[inline]
fn clone(&self) -> TouchPhase {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for TouchPhase {}
impl From<u32> for TouchPhase {
fn from(event: u32) -> TouchPhase {
match event {
sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_BEGAN => TouchPhase::Started,
sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_ENDED => TouchPhase::Ended,
sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_CANCELLED => TouchPhase::Cancelled,
sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_MOVED => TouchPhase::Moved,
_ => ::std::rt::begin_panic("internal error: entered unreachable code"),
}
}
}
pub trait EventHandler {
fn update(&mut self, _ctx: &mut Context);
fn draw(&mut self, _ctx: &mut Context);
fn resize_event(&mut self, _ctx: &mut Context, _width: f32, _height: f32) {}
fn mouse_motion_event(&mut self, _ctx: &mut Context, _x: f32, _y: f32) {}
fn mouse_wheel_event(&mut self, _ctx: &mut Context, _x: f32, _y: f32) {}
fn mouse_button_down_event(
&mut self,
_ctx: &mut Context,
_button: MouseButton,
_x: f32,
_y: f32,
) {
}
fn mouse_button_up_event(
&mut self,
_ctx: &mut Context,
_button: MouseButton,
_x: f32,
_y: f32,
) {
}
fn char_event(
&mut self,
_ctx: &mut Context,
_character: char,
_keymods: KeyMods,
_repeat: bool,
) {
}
fn key_down_event(
&mut self,
_ctx: &mut Context,
_keycode: KeyCode,
_keymods: KeyMods,
_repeat: bool,
) {
}
fn key_up_event(&mut self, _ctx: &mut Context, _keycode: KeyCode, _keymods: KeyMods) {}
fn touch_event(&mut self, ctx: &mut Context, phase: TouchPhase, _id: u64, x: f32, y: f32) {
if phase == TouchPhase::Started {
self.mouse_button_down_event(ctx, MouseButton::Left, x, y);
}
if phase == TouchPhase::Ended {
self.mouse_button_up_event(ctx, MouseButton::Left, x, y);
}
}
fn raw_mouse_motion(&mut self, _ctx: &mut Context, _dx: f32, _dy: f32) {}
fn quit_requested_event(&mut self, _ctx: &mut Context) {}
}
pub trait EventHandlerFree {
fn update(&mut self);
fn draw(&mut self);
fn resize_event(&mut self, _width: f32, _height: f32) {}
fn mouse_motion_event(&mut self, _x: f32, _y: f32) {}
fn mouse_wheel_event(&mut self, _x: f32, _y: f32) {}
fn mouse_button_down_event(&mut self, _button: MouseButton, _x: f32, _y: f32) {}
fn mouse_button_up_event(&mut self, _button: MouseButton, _x: f32, _y: f32) {}
fn char_event(&mut self, _character: char, _keymods: KeyMods, _repeat: bool) {}
fn key_down_event(&mut self, _keycode: KeyCode, _keymods: KeyMods, _repeat: bool) {}
fn key_up_event(&mut self, _keycode: KeyCode, _keymods: KeyMods) {}
fn touch_event(&mut self, phase: TouchPhase, _id: u64, x: f32, y: f32) {
if phase == TouchPhase::Started {
self.mouse_button_down_event(MouseButton::Left, x, y);
}
if phase == TouchPhase::Ended {
self.mouse_button_up_event(MouseButton::Left, x, y);
}
}
fn raw_mouse_motion(&mut self, _dx: f32, _dy: f32) {}
fn quit_requested_event(&mut self) {}
}
}
pub mod fs {
pub enum Error {
IOError(std::io::Error),
DownloadFailed,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Error {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&Error::IOError(ref __self_0),) => {
let mut debug_trait_builder = f.debug_tuple("IOError");
let _ = debug_trait_builder.field(&&(*__self_0));
debug_trait_builder.finish()
}
(&Error::DownloadFailed,) => {
let mut debug_trait_builder = f.debug_tuple("DownloadFailed");
debug_trait_builder.finish()
}
}
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match *self {
_ => f.write_fmt(::core::fmt::Arguments::new_v1(
&["Error: "],
&match (&self,) {
(arg0,) => [::core::fmt::ArgumentV1::new(arg0, ::core::fmt::Debug::fmt)],
},
)),
}
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Error {
Error::IOError(e)
}
}
pub type Response = Result<Vec<u8>, Error>;
pub fn load_file<F: Fn(Response) + 'static>(path: &str, on_loaded: F) {
#[cfg(not(target_arch = "wasm32"))]
load_file_desktop(path, on_loaded);
}
#[cfg(not(target_arch = "wasm32"))]
fn load_file_desktop<F: Fn(Response)>(path: &str, on_loaded: F) {
fn load_file_sync(path: &str) -> Response {
use std::fs::File;
use std::io::Read;
let mut response = <[_]>::into_vec(box []);
let mut file = File::open(path)?;
file.read_to_end(&mut response)?;
Ok(response)
}
let response = load_file_sync(path);
on_loaded(response);
}
}
pub mod graphics {
use std::{ffi::CString, mem};
mod texture {
use crate::{sapp::*, Context};
pub struct Texture {
pub(crate) texture: GLuint,
pub width: u32,
pub height: u32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Texture {
#[inline]
fn clone(&self) -> Texture {
{
let _: ::core::clone::AssertParamIsClone<GLuint>;
let _: ::core::clone::AssertParamIsClone<u32>;
let _: ::core::clone::AssertParamIsClone<u32>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Texture {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Texture {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
Texture {
texture: ref __self_0_0,
width: ref __self_0_1,
height: ref __self_0_2,
} => {
let mut debug_trait_builder = f.debug_struct("Texture");
let _ = debug_trait_builder.field("texture", &&(*__self_0_0));
let _ = debug_trait_builder.field("width", &&(*__self_0_1));
let _ = debug_trait_builder.field("height", &&(*__self_0_2));
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for Texture {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for Texture {
#[inline]
fn eq(&self, other: &Texture) -> bool {
match *other {
Texture {
texture: ref __self_1_0,
width: ref __self_1_1,
height: ref __self_1_2,
} => match *self {
Texture {
texture: ref __self_0_0,
width: ref __self_0_1,
height: ref __self_0_2,
} => {
(*__self_0_0) == (*__self_1_0)
&& (*__self_0_1) == (*__self_1_1)
&& (*__self_0_2) == (*__self_1_2)
}
},
}
}
#[inline]
fn ne(&self, other: &Texture) -> bool {
match *other {
Texture {
texture: ref __self_1_0,
width: ref __self_1_1,
height: ref __self_1_2,
} => match *self {
Texture {
texture: ref __self_0_0,
width: ref __self_0_1,
height: ref __self_0_2,
} => {
(*__self_0_0) != (*__self_1_0)
|| (*__self_0_1) != (*__self_1_1)
|| (*__self_0_2) != (*__self_1_2)
}
},
}
}
}
impl Texture {
pub fn empty() -> Texture {
Texture {
texture: 0,
width: 0,
height: 0,
}
}
fn delete(&self) {
let res = {
unsafe {
glDeleteTextures(1, &self.texture as *const _);
}
};
res
}
}
pub enum RenderTextureFormat {
RGBA8,
Depth,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for RenderTextureFormat {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&RenderTextureFormat::RGBA8,) => {
let mut debug_trait_builder = f.debug_tuple("RGBA8");
debug_trait_builder.finish()
}
(&RenderTextureFormat::Depth,) => {
let mut debug_trait_builder = f.debug_tuple("Depth");
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for RenderTextureFormat {
#[inline]
fn clone(&self) -> RenderTextureFormat {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for RenderTextureFormat {}
impl ::core::marker::StructuralPartialEq for RenderTextureFormat {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for RenderTextureFormat {
#[inline]
fn eq(&self, other: &RenderTextureFormat) -> bool {
{
let __self_vi =
unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl From<RenderTextureFormat> for (GLenum, GLenum, GLenum) {
fn from(format: RenderTextureFormat) -> Self {
match format {
RenderTextureFormat::RGBA8 => (GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE),
RenderTextureFormat::Depth => {
(GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT)
}
}
}
}
#[repr(u8)]
pub enum TextureFormat {
RGB8,
RGBA8,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for TextureFormat {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&TextureFormat::RGB8,) => {
let mut debug_trait_builder = f.debug_tuple("RGB8");
debug_trait_builder.finish()
}
(&TextureFormat::RGBA8,) => {
let mut debug_trait_builder = f.debug_tuple("RGBA8");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for TextureFormat {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for TextureFormat {
#[inline]
fn eq(&self, other: &TextureFormat) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as u8;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as u8;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for TextureFormat {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for TextureFormat {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for TextureFormat {
#[inline]
fn clone(&self) -> TextureFormat {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for TextureFormat {}
impl From<TextureFormat> for (GLenum, GLenum, GLenum) {
fn from(format: TextureFormat) -> Self {
match format {
TextureFormat::RGB8 => (GL_RGB, GL_RGB, GL_UNSIGNED_BYTE),
TextureFormat::RGBA8 => (GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE),
}
}
}
impl TextureFormat {
pub fn size(self, width: u32, height: u32) -> u32 {
let square = width * height;
match self {
TextureFormat::RGB8 => 3 * square,
TextureFormat::RGBA8 => 4 * square,
}
}
}
impl Default for TextureParams {
fn default() -> Self {
TextureParams {
format: TextureFormat::RGBA8,
wrap: TextureWrap::Clamp,
filter: FilterMode::Linear,
width: 0,
height: 0,
}
}
}
#[repr(u8)]
pub enum TextureWrap {
Repeat,
Mirror,
Clamp,
MirrorClamp,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for TextureWrap {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&TextureWrap::Repeat,) => {
let mut debug_trait_builder = f.debug_tuple("Repeat");
debug_trait_builder.finish()
}
(&TextureWrap::Mirror,) => {
let mut debug_trait_builder = f.debug_tuple("Mirror");
debug_trait_builder.finish()
}
(&TextureWrap::Clamp,) => {
let mut debug_trait_builder = f.debug_tuple("Clamp");
debug_trait_builder.finish()
}
(&TextureWrap::MirrorClamp,) => {
let mut debug_trait_builder = f.debug_tuple("MirrorClamp");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for TextureWrap {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for TextureWrap {
#[inline]
fn eq(&self, other: &TextureWrap) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as u8;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as u8;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for TextureWrap {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for TextureWrap {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for TextureWrap {
#[inline]
fn clone(&self) -> TextureWrap {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for TextureWrap {}
pub enum FilterMode {
Linear = GL_LINEAR as isize,
Nearest = GL_NEAREST as isize,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for FilterMode {
#[inline]
fn clone(&self) -> FilterMode {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for FilterMode {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for FilterMode {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&FilterMode::Linear,) => {
let mut debug_trait_builder = f.debug_tuple("Linear");
debug_trait_builder.finish()
}
(&FilterMode::Nearest,) => {
let mut debug_trait_builder = f.debug_tuple("Nearest");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for FilterMode {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for FilterMode {
#[inline]
fn eq(&self, other: &FilterMode) -> bool {
{
let __self_vi =
unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
pub struct TextureParams {
pub format: TextureFormat,
pub wrap: TextureWrap,
pub filter: FilterMode,
pub width: u32,
pub height: u32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for TextureParams {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
TextureParams {
format: ref __self_0_0,
wrap: ref __self_0_1,
filter: ref __self_0_2,
width: ref __self_0_3,
height: ref __self_0_4,
} => {
let mut debug_trait_builder = f.debug_struct("TextureParams");
let _ = debug_trait_builder.field("format", &&(*__self_0_0));
let _ = debug_trait_builder.field("wrap", &&(*__self_0_1));
let _ = debug_trait_builder.field("filter", &&(*__self_0_2));
let _ = debug_trait_builder.field("width", &&(*__self_0_3));
let _ = debug_trait_builder.field("height", &&(*__self_0_4));
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for TextureParams {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for TextureParams {
#[inline]
fn clone(&self) -> TextureParams {
{
let _: ::core::clone::AssertParamIsClone<TextureFormat>;
let _: ::core::clone::AssertParamIsClone<TextureWrap>;
let _: ::core::clone::AssertParamIsClone<FilterMode>;
let _: ::core::clone::AssertParamIsClone<u32>;
let _: ::core::clone::AssertParamIsClone<u32>;
*self
}
}
}
pub struct RenderTextureParams {
pub format: RenderTextureFormat,
pub wrap: TextureWrap,
pub filter: FilterMode,
pub width: u32,
pub height: u32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for RenderTextureParams {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
RenderTextureParams {
format: ref __self_0_0,
wrap: ref __self_0_1,
filter: ref __self_0_2,
width: ref __self_0_3,
height: ref __self_0_4,
} => {
let mut debug_trait_builder = f.debug_struct("RenderTextureParams");
let _ = debug_trait_builder.field("format", &&(*__self_0_0));
let _ = debug_trait_builder.field("wrap", &&(*__self_0_1));
let _ = debug_trait_builder.field("filter", &&(*__self_0_2));
let _ = debug_trait_builder.field("width", &&(*__self_0_3));
let _ = debug_trait_builder.field("height", &&(*__self_0_4));
debug_trait_builder.finish()
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for RenderTextureParams {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for RenderTextureParams {
#[inline]
fn clone(&self) -> RenderTextureParams {
{
let _: ::core::clone::AssertParamIsClone<RenderTextureFormat>;
let _: ::core::clone::AssertParamIsClone<TextureWrap>;
let _: ::core::clone::AssertParamIsClone<FilterMode>;
let _: ::core::clone::AssertParamIsClone<u32>;
let _: ::core::clone::AssertParamIsClone<u32>;
*self
}
}
}
impl Default for RenderTextureParams {
fn default() -> Self {
RenderTextureParams {
format: RenderTextureFormat::RGBA8,
wrap: TextureWrap::Clamp,
filter: FilterMode::Linear,
width: 0,
height: 0,
}
}
}
impl Texture {
fn new_render_texture(ctx: &mut Context, params: RenderTextureParams) {
()
}
fn from_data_and_format(ctx: &mut Context, bytes: &[u8], params: TextureParams) {
()
}
pub fn from_rgba8(ctx: &mut Context, width: u16, height: u16, bytes: &[u8]) -> Texture {
{
match (&(width as usize * height as usize * 4), &bytes.len()) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
{
::std::rt::begin_panic_fmt(&::core::fmt::Arguments::new_v1(
&[
"assertion failed: `(left == right)`\n left: `",
"`,\n right: `",
"`",
],
&match (&&*left_val, &&*right_val) {
(arg0, arg1) => [
::core::fmt::ArgumentV1::new(
arg0,
::core::fmt::Debug::fmt,
),
::core::fmt::ArgumentV1::new(
arg1,
::core::fmt::Debug::fmt,
),
],
},
))
}
}
}
}
};
Self::from_data_and_format(
ctx,
bytes,
TextureParams {
width: width as _,
height: height as _,
format: TextureFormat::RGBA8,
wrap: TextureWrap::Clamp,
filter: FilterMode::Linear,
},
)
}
fn set_filter(&self, ctx: &mut Context, filter: FilterMode) {
let res = {
ctx.cache.store_texture_binding(0);
ctx.cache.bind_texture(0, self.texture);
unsafe {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter as i32);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter as i32);
}
ctx.cache.restore_texture_binding(0);
};
res
}
pub fn update(&self, ctx: &mut Context, bytes: &[u8]) {
{
match (
&(self.width as usize * self.height as usize * 4),
&bytes.len(),
) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
{
::std::rt::begin_panic_fmt(&::core::fmt::Arguments::new_v1(
&[
"assertion failed: `(left == right)`\n left: `",
"`,\n right: `",
"`",
],
&match (&&*left_val, &&*right_val) {
(arg0, arg1) => [
::core::fmt::ArgumentV1::new(
arg0,
::core::fmt::Debug::fmt,
),
::core::fmt::ArgumentV1::new(
arg1,
::core::fmt::Debug::fmt,
),
],
},
))
}
}
}
}
};
self.update_texture_part(
ctx,
0 as _,
0 as _,
self.width as _,
self.height as _,
bytes,
)
}
fn update_texture_part(
&self,
ctx: &mut Context,
x_offset: i32,
y_offset: i32,
width: i32,
height: i32,
bytes: &[u8],
) {
let res = {
{
match (&(width as usize * height as usize * 4), &bytes.len()) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
{
::std::rt::begin_panic_fmt(&::core::fmt::Arguments::new_v1(
&[
"assertion failed: `(left == right)`\n left: `",
"`,\n right: `",
"`",
],
&match (&&*left_val, &&*right_val) {
(arg0, arg1) => [
::core::fmt::ArgumentV1::new(
arg0,
::core::fmt::Debug::fmt,
),
::core::fmt::ArgumentV1::new(
arg1,
::core::fmt::Debug::fmt,
),
],
},
))
}
}
}
}
};
if !(x_offset + width <= self.width as _) {
{
::std::rt::begin_panic(
"assertion failed: x_offset + width <= self.width as _",
)
}
};
if !(y_offset + height <= self.height as _) {
{
::std::rt::begin_panic(
"assertion failed: y_offset + height <= self.height as _",
)
}
};
ctx.cache.store_texture_binding(0);
ctx.cache.bind_texture(0, self.texture);
unsafe {
glTexSubImage2D(
GL_TEXTURE_2D,
0,
x_offset as _,
y_offset as _,
width as _,
height as _,
GL_RGBA,
GL_UNSIGNED_BYTE,
bytes.as_ptr() as *const _,
);
}
ctx.cache.restore_texture_binding(0);
};
res
}
}
}
use crate::sapp::*;
use std::option::Option::None;
pub use texture::{
FilterMode, RenderTextureFormat, RenderTextureParams, Texture, TextureFormat, TextureParams,
};
fn get_uniform_location(program: GLuint, name: &str) -> i32 {
let cname = CString::new(name).unwrap_or_else(|e| ::std::rt::begin_panic(e));
let location = unsafe { glGetUniformLocation(program, cname.as_ptr()) };
if !(location != -1) {
{
::std::rt::begin_panic({
let res = ::alloc::fmt::format(::core::fmt::Arguments::new_v1(
&["Cant get \"", "\" uniform location"],
&match (&name,) {
(arg0,) => [::core::fmt::ArgumentV1::new(
arg0,
::core::fmt::Display::fmt,
)],
},
));
res
})
}
};
location
}
pub enum UniformType {
Float1,
Float2,
Float3,
Float4,
Mat4,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for UniformType {
#[inline]
fn clone(&self) -> UniformType {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for UniformType {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for UniformType {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&UniformType::Float1,) => {
let mut debug_trait_builder = f.debug_tuple("Float1");
debug_trait_builder.finish()
}
(&UniformType::Float2,) => {
let mut debug_trait_builder = f.debug_tuple("Float2");
debug_trait_builder.finish()
}
(&UniformType::Float3,) => {
let mut debug_trait_builder = f.debug_tuple("Float3");
debug_trait_builder.finish()
}
(&UniformType::Float4,) => {
let mut debug_trait_builder = f.debug_tuple("Float4");
debug_trait_builder.finish()
}
(&UniformType::Mat4,) => {
let mut debug_trait_builder = f.debug_tuple("Mat4");
debug_trait_builder.finish()
}
}
}
}
impl UniformType {
fn size(&self, count: usize) -> usize {
match self {
UniformType::Float1 => 4 * count,
UniformType::Float2 => 8 * count,
UniformType::Float3 => 12 * count,
UniformType::Float4 => 16 * count,
UniformType::Mat4 => 64 * count,
}
}
}
pub struct UniformBlockLayout {
pub uniforms: &'static [(&'static str, UniformType)],
}
pub struct ShaderMeta {
pub uniforms: UniformBlockLayout,
pub images: &'static [&'static str],
}
pub enum VertexFormat {
Float1,
Float2,
Float3,
Float4,
Byte1,
Byte2,
Byte3,
Byte4,
Short1,
Short2,
Short3,
Short4,
Mat4,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for VertexFormat {
#[inline]
fn clone(&self) -> VertexFormat {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for VertexFormat {}
impl ::core::marker::StructuralPartialEq for VertexFormat {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for VertexFormat {
#[inline]
fn eq(&self, other: &VertexFormat) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for VertexFormat {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&VertexFormat::Float1,) => {
let mut debug_trait_builder = f.debug_tuple("Float1");
debug_trait_builder.finish()
}
(&VertexFormat::Float2,) => {
let mut debug_trait_builder = f.debug_tuple("Float2");
debug_trait_builder.finish()
}
(&VertexFormat::Float3,) => {
let mut debug_trait_builder = f.debug_tuple("Float3");
debug_trait_builder.finish()
}
(&VertexFormat::Float4,) => {
let mut debug_trait_builder = f.debug_tuple("Float4");
debug_trait_builder.finish()
}
(&VertexFormat::Byte1,) => {
let mut debug_trait_builder = f.debug_tuple("Byte1");
debug_trait_builder.finish()
}
(&VertexFormat::Byte2,) => {
let mut debug_trait_builder = f.debug_tuple("Byte2");
debug_trait_builder.finish()
}
(&VertexFormat::Byte3,) => {
let mut debug_trait_builder = f.debug_tuple("Byte3");
debug_trait_builder.finish()
}
(&VertexFormat::Byte4,) => {
let mut debug_trait_builder = f.debug_tuple("Byte4");
debug_trait_builder.finish()
}
(&VertexFormat::Short1,) => {
let mut debug_trait_builder = f.debug_tuple("Short1");
debug_trait_builder.finish()
}
(&VertexFormat::Short2,) => {
let mut debug_trait_builder = f.debug_tuple("Short2");
debug_trait_builder.finish()
}
(&VertexFormat::Short3,) => {
let mut debug_trait_builder = f.debug_tuple("Short3");
debug_trait_builder.finish()
}
(&VertexFormat::Short4,) => {
let mut debug_trait_builder = f.debug_tuple("Short4");
debug_trait_builder.finish()
}
(&VertexFormat::Mat4,) => {
let mut debug_trait_builder = f.debug_tuple("Mat4");
debug_trait_builder.finish()
}
}
}
}
impl VertexFormat {
pub fn size(&self) -> i32 {
match self {
VertexFormat::Float1 => 1,
VertexFormat::Float2 => 2,
VertexFormat::Float3 => 3,
VertexFormat::Float4 => 4,
VertexFormat::Byte1 => 1,
VertexFormat::Byte2 => 2,
VertexFormat::Byte3 => 3,
VertexFormat::Byte4 => 4,
VertexFormat::Short1 => 1,
VertexFormat::Short2 => 2,
VertexFormat::Short3 => 3,
VertexFormat::Short4 => 4,
VertexFormat::Mat4 => 16,
}
}
pub fn byte_len(&self) -> i32 {
match self {
VertexFormat::Float1 => 1 * 4,
VertexFormat::Float2 => 2 * 4,
VertexFormat::Float3 => 3 * 4,
VertexFormat::Float4 => 4 * 4,
VertexFormat::Byte1 => 1,
VertexFormat::Byte2 => 2,
VertexFormat::Byte3 => 3,
VertexFormat::Byte4 => 4,
VertexFormat::Short1 => 1 * 2,
VertexFormat::Short2 => 2 * 2,
VertexFormat::Short3 => 3 * 2,
VertexFormat::Short4 => 4 * 2,
VertexFormat::Mat4 => 16 * 4,
}
}
fn type_(&self) -> GLuint {
match self {
VertexFormat::Float1 => GL_FLOAT,
VertexFormat::Float2 => GL_FLOAT,
VertexFormat::Float3 => GL_FLOAT,
VertexFormat::Float4 => GL_FLOAT,
VertexFormat::Byte1 => GL_UNSIGNED_BYTE,
VertexFormat::Byte2 => GL_UNSIGNED_BYTE,
VertexFormat::Byte3 => GL_UNSIGNED_BYTE,
VertexFormat::Byte4 => GL_UNSIGNED_BYTE,
VertexFormat::Short1 => GL_UNSIGNED_SHORT,
VertexFormat::Short2 => GL_UNSIGNED_SHORT,
VertexFormat::Short3 => GL_UNSIGNED_SHORT,
VertexFormat::Short4 => GL_UNSIGNED_SHORT,
VertexFormat::Mat4 => GL_FLOAT,
}
}
}
pub enum VertexStep {
PerVertex,
PerInstance,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for VertexStep {
#[inline]
fn clone(&self) -> VertexStep {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for VertexStep {}
impl ::core::marker::StructuralPartialEq for VertexStep {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for VertexStep {
#[inline]
fn eq(&self, other: &VertexStep) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for VertexStep {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&VertexStep::PerVertex,) => {
let mut debug_trait_builder = f.debug_tuple("PerVertex");
debug_trait_builder.finish()
}
(&VertexStep::PerInstance,) => {
let mut debug_trait_builder = f.debug_tuple("PerInstance");
debug_trait_builder.finish()
}
}
}
}
impl Default for VertexStep {
fn default() -> VertexStep {
VertexStep::PerVertex
}
}
pub struct BufferLayout {
pub stride: i32,
pub step_func: VertexStep,
pub step_rate: i32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for BufferLayout {
#[inline]
fn clone(&self) -> BufferLayout {
match *self {
BufferLayout {
stride: ref __self_0_0,
step_func: ref __self_0_1,
step_rate: ref __self_0_2,
} => BufferLayout {
stride: ::core::clone::Clone::clone(&(*__self_0_0)),
step_func: ::core::clone::Clone::clone(&(*__self_0_1)),
step_rate: ::core::clone::Clone::clone(&(*__self_0_2)),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for BufferLayout {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
BufferLayout {
stride: ref __self_0_0,
step_func: ref __self_0_1,
step_rate: ref __self_0_2,
} => {
let mut debug_trait_builder = f.debug_struct("BufferLayout");
let _ = debug_trait_builder.field("stride", &&(*__self_0_0));
let _ = debug_trait_builder.field("step_func", &&(*__self_0_1));
let _ = debug_trait_builder.field("step_rate", &&(*__self_0_2));
debug_trait_builder.finish()
}
}
}
}
impl Default for BufferLayout {
fn default() -> BufferLayout {
BufferLayout {
stride: 0,
step_func: VertexStep::PerVertex,
step_rate: 1,
}
}
}
pub struct VertexAttribute {
pub name: &'static str,
pub format: VertexFormat,
pub buffer_index: usize,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for VertexAttribute {
#[inline]
fn clone(&self) -> VertexAttribute {
match *self {
VertexAttribute {
name: ref __self_0_0,
format: ref __self_0_1,
buffer_index: ref __self_0_2,
} => VertexAttribute {
name: ::core::clone::Clone::clone(&(*__self_0_0)),
format: ::core::clone::Clone::clone(&(*__self_0_1)),
buffer_index: ::core::clone::Clone::clone(&(*__self_0_2)),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for VertexAttribute {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
VertexAttribute {
name: ref __self_0_0,
format: ref __self_0_1,
buffer_index: ref __self_0_2,
} => {
let mut debug_trait_builder = f.debug_struct("VertexAttribute");
let _ = debug_trait_builder.field("name", &&(*__self_0_0));
let _ = debug_trait_builder.field("format", &&(*__self_0_1));
let _ = debug_trait_builder.field("buffer_index", &&(*__self_0_2));
debug_trait_builder.finish()
}
}
}
}
impl VertexAttribute {
pub fn new(name: &'static str, format: VertexFormat) -> VertexAttribute {
Self::with_buffer(name, format, 0)
}
pub fn with_buffer(
name: &'static str,
format: VertexFormat,
buffer_index: usize,
) -> VertexAttribute {
VertexAttribute {
name,
format,
buffer_index,
}
}
}
pub struct PipelineLayout {
pub buffers: &'static [BufferLayout],
pub attributes: &'static [VertexAttribute],
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for PipelineLayout {
#[inline]
fn clone(&self) -> PipelineLayout {
match *self {
PipelineLayout {
buffers: ref __self_0_0,
attributes: ref __self_0_1,
} => PipelineLayout {
buffers: ::core::clone::Clone::clone(&(*__self_0_0)),
attributes: ::core::clone::Clone::clone(&(*__self_0_1)),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for PipelineLayout {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
PipelineLayout {
buffers: ref __self_0_0,
attributes: ref __self_0_1,
} => {
let mut debug_trait_builder = f.debug_struct("PipelineLayout");
let _ = debug_trait_builder.field("buffers", &&(*__self_0_0));
let _ = debug_trait_builder.field("attributes", &&(*__self_0_1));
debug_trait_builder.finish()
}
}
}
}
pub struct Shader(usize);
impl Shader {
pub fn new(
ctx: &mut Context,
vertex_shader: &str,
fragment_shader: &str,
meta: ShaderMeta,
) -> Shader {
let shader = load_shader_internal(vertex_shader, fragment_shader, meta);
ctx.shaders.push(shader);
Shader(ctx.shaders.len() - 1)
}
}
pub struct ShaderImage {
gl_loc: GLint,
}
pub struct ShaderUniform {
gl_loc: GLint,
offset: usize,
size: usize,
uniform_type: UniformType,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for ShaderUniform {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
ShaderUniform {
gl_loc: ref __self_0_0,
offset: ref __self_0_1,
size: ref __self_0_2,
uniform_type: ref __self_0_3,
} => {
let mut debug_trait_builder = f.debug_struct("ShaderUniform");
let _ = debug_trait_builder.field("gl_loc", &&(*__self_0_0));
let _ = debug_trait_builder.field("offset", &&(*__self_0_1));
let _ = debug_trait_builder.field("size", &&(*__self_0_2));
let _ = debug_trait_builder.field("uniform_type", &&(*__self_0_3));
debug_trait_builder.finish()
}
}
}
}
struct ShaderInternal {
program: GLuint,
images: Vec<ShaderImage>,
uniforms: Vec<ShaderUniform>,
}
type BlendState = Option<(Equation, BlendFactor, BlendFactor)>;
struct CachedAttribute {
attribute: VertexAttributeInternal,
gl_vbuf: GLuint,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::default::Default for CachedAttribute {
#[inline]
fn default() -> CachedAttribute {
CachedAttribute {
attribute: ::core::default::Default::default(),
gl_vbuf: ::core::default::Default::default(),
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for CachedAttribute {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for CachedAttribute {
#[inline]
fn clone(&self) -> CachedAttribute {
{
let _: ::core::clone::AssertParamIsClone<VertexAttributeInternal>;
let _: ::core::clone::AssertParamIsClone<GLuint>;
*self
}
}
}
struct GlCache {
stored_index_buffer: GLuint,
stored_vertex_buffer: GLuint,
stored_texture: GLuint,
index_buffer: GLuint,
vertex_buffer: GLuint,
textures: [GLuint; MAX_SHADERSTAGE_IMAGES],
cur_pipeline: Option<Pipeline>,
blend: BlendState,
attributes: [Option<CachedAttribute>; MAX_VERTEX_ATTRIBUTES],
}
impl GlCache {
fn bind_buffer(&mut self, target: GLenum, buffer: GLuint) {
if target == GL_ARRAY_BUFFER {
if self.vertex_buffer != buffer {
self.vertex_buffer = buffer;
unsafe {
glBindBuffer(target, buffer);
}
}
} else {
if self.index_buffer != buffer {
self.index_buffer = buffer;
unsafe {
glBindBuffer(target, buffer);
}
}
}
}
fn store_buffer_binding(&mut self, target: GLenum) {
if target == GL_ARRAY_BUFFER {
self.stored_vertex_buffer = self.vertex_buffer;
} else {
self.stored_index_buffer = self.index_buffer;
}
}
fn restore_buffer_binding(&mut self, target: GLenum) {
if target == GL_ARRAY_BUFFER {
self.bind_buffer(target, self.stored_vertex_buffer);
} else {
self.bind_buffer(target, self.stored_index_buffer);
}
}
fn bind_texture(&mut self, slot_index: usize, texture: GLuint) {
unsafe {
glActiveTexture(GL_TEXTURE0 + slot_index as GLuint);
if self.textures[slot_index] != texture {
glBindTexture(GL_TEXTURE_2D, texture);
self.textures[slot_index] = texture;
}
}
}
fn store_texture_binding(&mut self, slot_index: usize) {
self.stored_texture = self.textures[slot_index];
}
fn restore_texture_binding(&mut self, slot_index: usize) {
self.bind_texture(slot_index, self.stored_texture);
}
fn clear_buffer_bindings(&mut self) {
self.bind_buffer(GL_ARRAY_BUFFER, 0);
self.vertex_buffer = 0;
self.bind_buffer(GL_ELEMENT_ARRAY_BUFFER, 0);
self.index_buffer = 0;
}
fn clear_texture_bindings(&mut self) {
for ix in 0..MAX_SHADERSTAGE_IMAGES {
if self.textures[ix] != 0 {
self.bind_texture(ix, 0);
self.textures[ix] = 0;
}
}
}
}
pub enum PassAction {
Nothing,
Clear {
color: Option<(f32, f32, f32, f32)>,
depth: Option<f32>,
stencil: Option<i32>,
},
}
impl PassAction {
pub fn clear_color(r: f32, g: f32, b: f32, a: f32) -> PassAction {
PassAction::Clear {
color: Some((r, g, b, a)),
depth: Some(1.),
stencil: None,
}
}
}
impl Default for PassAction {
fn default() -> PassAction {
PassAction::Clear {
color: Some((0.0, 0.0, 0.0, 0.0)),
depth: Some(1.),
stencil: None,
}
}
}
pub struct RenderPass(usize);
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for RenderPass {
#[inline]
fn clone(&self) -> RenderPass {
{
let _: ::core::clone::AssertParamIsClone<usize>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for RenderPass {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for RenderPass {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
RenderPass(ref __self_0_0) => {
let mut debug_trait_builder = f.debug_tuple("RenderPass");
let _ = debug_trait_builder.field(&&(*__self_0_0));
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for RenderPass {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for RenderPass {
#[inline]
fn eq(&self, other: &RenderPass) -> bool {
match *other {
RenderPass(ref __self_1_0) => match *self {
RenderPass(ref __self_0_0) => (*__self_0_0) == (*__self_1_0),
},
}
}
#[inline]
fn ne(&self, other: &RenderPass) -> bool {
match *other {
RenderPass(ref __self_1_0) => match *self {
RenderPass(ref __self_0_0) => (*__self_0_0) != (*__self_1_0),
},
}
}
}
struct RenderPassInternal {
gl_fb: GLuint,
texture: Texture,
}
impl RenderPass {
pub fn new(
context: &mut Context,
color_img: Texture,
depth_img: impl Into<Option<Texture>>,
) -> RenderPass {
let mut gl_fb = 0;
unsafe {
glGenFramebuffers(1, &mut gl_fb as *mut _);
glBindFramebuffer(GL_FRAMEBUFFER, gl_fb);
glFramebufferTexture2D(
GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D,
color_img.texture,
0,
);
if let Some(depth_img) = depth_img.into() {
glFramebufferTexture2D(
GL_FRAMEBUFFER,
GL_DEPTH_ATTACHMENT,
GL_TEXTURE_2D,
depth_img.texture,
0,
);
}
glBindFramebuffer(GL_FRAMEBUFFER, context.default_framebuffer);
}
let pass = RenderPassInternal {
gl_fb,
texture: color_img,
};
context.passes.push(pass);
RenderPass(context.passes.len() - 1)
}
}
pub const MAX_VERTEX_ATTRIBUTES: usize = 16;
pub const MAX_SHADERSTAGE_IMAGES: usize = 12;
pub struct Context {
shaders: Vec<ShaderInternal>,
pipelines: Vec<PipelineInternal>,
passes: Vec<RenderPassInternal>,
default_framebuffer: GLuint,
cache: GlCache,
}
impl Context {
pub fn new() -> Context {
unsafe {
let mut default_framebuffer: GLuint = 0;
glGetIntegerv(
GL_FRAMEBUFFER_BINDING,
&mut default_framebuffer as *mut _ as *mut _,
);
let mut vao = 0;
glGenVertexArrays(1, &mut vao as *mut _);
glBindVertexArray(vao);
Context {
default_framebuffer,
shaders: <[_]>::into_vec(box []),
pipelines: <[_]>::into_vec(box []),
passes: <[_]>::into_vec(box []),
cache: GlCache {
stored_index_buffer: 0,
stored_vertex_buffer: 0,
index_buffer: 0,
vertex_buffer: 0,
cur_pipeline: None,
blend: None,
stored_texture: 0,
textures: [0; MAX_SHADERSTAGE_IMAGES],
attributes: [None; MAX_VERTEX_ATTRIBUTES],
},
}
}
}
pub fn screen_size(&self) -> (f32, f32) {
unsafe { (sapp_width() as f32, sapp_height() as f32) }
}
pub fn dpi_scale(&self) -> f32 {
unsafe { sapp_dpi_scale() }
}
pub fn high_dpi(&self) -> bool {
unsafe { sapp_high_dpi() }
}
fn apply_pipeline(&mut self, pipeline: &Pipeline) {
let res = {
self.cache.cur_pipeline = Some(*pipeline);
let pipeline = &mut self.pipelines[pipeline.0];
let shader = &mut self.shaders[pipeline.shader.0];
unsafe {
glUseProgram(shader.program);
}
unsafe {
glEnable(GL_SCISSOR_TEST);
}
if pipeline.params.depth_write {
unsafe {
glEnable(GL_DEPTH_TEST);
glDepthFunc(pipeline.params.depth_test.into())
}
} else {
unsafe {
glDisable(GL_DEPTH_TEST);
}
}
if self.cache.blend != pipeline.params.color_blend {
unsafe {
if let Some((equation, src, dst)) = pipeline.params.color_blend {
if self.cache.blend.is_none() {
glEnable(GL_BLEND);
}
glBlendFunc(src.into(), dst.into());
glBlendEquationSeparate(equation.into(), equation.into());
} else if self.cache.blend.is_some() {
glDisable(GL_BLEND);
}
self.cache.blend = pipeline.params.color_blend;
}
}
};
res
}
fn apply_scissor_rect(&mut self, x: i32, y: i32, w: i32, h: i32) {
let res = {
unsafe {
glScissor(x, y, w, h);
}
};
res
}
fn apply_bindings(&mut self, bindings: &Bindings) {
let res = {
let pip = &self.pipelines[self.cache.cur_pipeline.unwrap().0];
let shader = &self.shaders[pip.shader.0];
for (n, shader_image) in shader.images.iter().enumerate() {
let bindings_image = bindings.images.get(n).unwrap_or_else(|| {
::std::rt::begin_panic("Image count in bindings and shader did not match!")
});
unsafe {
self.cache.bind_texture(n, bindings_image.texture);
glUniform1i(shader_image.gl_loc, n as i32);
}
}
self.cache
.bind_buffer(GL_ELEMENT_ARRAY_BUFFER, bindings.index_buffer.gl_buf);
let pip = &self.pipelines[self.cache.cur_pipeline.unwrap().0];
for attr_index in 0..MAX_VERTEX_ATTRIBUTES {
let cached_attr = &mut self.cache.attributes[attr_index];
let pip_attribute = pip.layout.get(attr_index).copied();
if let Some(attribute) = pip_attribute {
let vb = bindings.vertex_buffers[attribute.buffer_index];
if cached_attr.map_or(true, |cached_attr| {
attribute != cached_attr.attribute || cached_attr.gl_vbuf != vb.gl_buf
}) {
self.cache.bind_buffer(GL_ARRAY_BUFFER, vb.gl_buf);
unsafe {
glVertexAttribPointer(
attr_index as GLuint,
attribute.size,
attribute.type_,
GL_FALSE as u8,
attribute.stride,
attribute.offset as *mut _,
);
glVertexAttribDivisor(
attr_index as GLuint,
attribute.divisor as u32,
);
glEnableVertexAttribArray(attr_index as GLuint);
};
let cached_attr = &mut self.cache.attributes[attr_index];
*cached_attr = Some(CachedAttribute {
attribute,
gl_vbuf: vb.gl_buf,
});
}
} else {
if cached_attr.is_some() {
unsafe {
glDisableVertexAttribArray(attr_index as GLuint);
}
*cached_attr = None;
}
}
}
};
res
}
pub fn apply_uniforms<U>(&mut self, uniforms: &U) {
let pip = &self.pipelines[self.cache.cur_pipeline.unwrap().0];
let shader = &self.shaders[pip.shader.0];
let mut offset = 0;
for (_, uniform) in shader.uniforms.iter().enumerate() {
use UniformType::*;
if !(offset < std::mem::size_of::<U>() - 4) {
{
::std::rt::begin_panic(
"assertion failed: offset < std::mem::size_of::<U>() - 4",
)
}
};
unsafe {
let data = (uniforms as *const _ as *const f32).offset(offset as isize);
match uniform.uniform_type {
Float1 => {
glUniform1fv(uniform.gl_loc, 1, data);
}
Float2 => {
glUniform2fv(uniform.gl_loc, 1, data);
}
Float3 => {
glUniform3fv(uniform.gl_loc, 1, data);
}
Float4 => {
glUniform4fv(uniform.gl_loc, 1, data);
}
Mat4 => {
glUniformMatrix4fv(uniform.gl_loc, 1, 0, data);
}
}
}
offset += uniform.uniform_type.size(1) / 4;
}
}
fn clear(
&self,
color: Option<(f32, f32, f32, f32)>,
depth: Option<f32>,
stencil: Option<i32>,
) {
let res = {
let mut bits = 0;
if let Some((r, g, b, a)) = color {
bits |= GL_COLOR_BUFFER_BIT;
unsafe {
glClearColor(r, g, b, a);
}
}
if let Some(v) = depth {
bits |= GL_DEPTH_BUFFER_BIT;
unsafe {
glClearDepthf(v);
}
}
if let Some(v) = stencil {
bits |= GL_STENCIL_BUFFER_BIT;
unsafe {
glClearStencil(v);
}
}
if bits != 0 {
unsafe {
glClear(bits);
}
}
};
res
}
fn begin_default_pass(&mut self, action: PassAction) {
let res = {
self.begin_pass(None, action);
};
res
}
fn begin_pass(&mut self, pass: impl Into<Option<RenderPass>>, action: PassAction) {
let res = {
let (framebuffer, w, h) = match pass.into() {
None => (
self.default_framebuffer,
unsafe { sapp_width() } as i32,
unsafe { sapp_height() } as i32,
),
Some(pass) => {
let pass = &self.passes[pass.0];
(
pass.gl_fb,
pass.texture.width as i32,
pass.texture.height as i32,
)
}
};
unsafe {
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glViewport(0, 0, w, h);
glScissor(0, 0, w, h);
}
match action {
PassAction::Nothing => {}
PassAction::Clear {
color,
depth,
stencil,
} => {
self.clear(color, depth, stencil);
}
}
};
res
}
fn end_render_pass(&mut self) {
let res = {
unsafe {
glBindFramebuffer(GL_FRAMEBUFFER, self.default_framebuffer);
self.cache.bind_buffer(GL_ARRAY_BUFFER, 0);
self.cache.bind_buffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
};
res
}
fn commit_frame(&mut self) {
let res = {
self.cache.clear_buffer_bindings();
self.cache.clear_texture_bindings();
};
res
}
fn draw(&self, base_element: i32, num_elements: i32, num_instances: i32) {
let res = {
unsafe {
glDrawElementsInstanced(
GL_TRIANGLES,
num_elements,
GL_UNSIGNED_SHORT,
(2 * base_element) as *mut _,
num_instances,
);
}
};
res
}
}
fn load_shader_internal(
vertex_shader: &str,
fragment_shader: &str,
meta: ShaderMeta,
) -> ShaderInternal {
unsafe {
let vertex_shader = load_shader(GL_VERTEX_SHADER, vertex_shader);
let fragment_shader = load_shader(GL_FRAGMENT_SHADER, fragment_shader);
let program = glCreateProgram();
glAttachShader(program, vertex_shader);
glAttachShader(program, fragment_shader);
glLinkProgram(program);
let mut link_status = 0;
glGetProgramiv(program, GL_LINK_STATUS, &mut link_status as *mut _);
if link_status == 0 {
let mut max_length = 100;
let mut error_message = ::alloc::vec::from_elem(0u8, max_length as usize + 1);
glGetProgramInfoLog(
program,
max_length,
&mut max_length as *mut _,
error_message.as_mut_ptr() as *mut _,
);
let error_message = std::string::String::from_utf8_lossy(&error_message);
{
::std::rt::begin_panic_fmt(&::core::fmt::Arguments::new_v1(
&[""],
&match (&error_message,) {
(arg0,) => [::core::fmt::ArgumentV1::new(
arg0,
::core::fmt::Display::fmt,
)],
},
))
};
}
glUseProgram(program);
#[rustfmt::skip]
let images =
meta.images.iter().map(|name|
ShaderImage{gl_loc:
get_uniform_location(program,
name),}).collect();
#[rustfmt::skip]
let uniforms =
meta.uniforms.uniforms.iter().scan(0,
|offset, uniform|
{
let res =
ShaderUniform{gl_loc:
get_uniform_location(program,
uniform.0),
offset:
*offset,
size:
uniform.1.size(1),
uniform_type:
uniform.1,};
*offset +=
uniform.1.size(1);
Some(res)
}).collect();
ShaderInternal {
program,
images,
uniforms,
}
}
}
fn load_shader(shader_type: GLenum, source: &str) -> GLuint {
unsafe {
let shader = glCreateShader(shader_type);
if !(shader != 0) {
{
::std::rt::begin_panic("assertion failed: shader != 0")
}
};
let cstring = CString::new(source).unwrap_or_else(|e| ::std::rt::begin_panic(e));
let csource = [cstring];
glShaderSource(shader, 1, csource.as_ptr() as *const _, std::ptr::null());
glCompileShader(shader);
let mut is_compiled = 0;
glGetShaderiv(shader, GL_COMPILE_STATUS, &mut is_compiled as *mut _);
if is_compiled == 0 {
let mut max_length: i32 = 0;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &mut max_length as *mut _);
let mut error_message = ::alloc::vec::from_elem(0u8, max_length as usize + 1);
glGetShaderInfoLog(
shader,
max_length,
&mut max_length as *mut _,
error_message.as_mut_ptr() as *mut _,
);
let error_message = std::string::String::from_utf8_lossy(&error_message);
{
::std::io::_eprint(::core::fmt::Arguments::new_v1(
&["", " ", "\n"],
&match (&max_length, &error_message) {
(arg0, arg1) => [
::core::fmt::ArgumentV1::new(arg0, ::core::fmt::Display::fmt),
::core::fmt::ArgumentV1::new(arg1, ::core::fmt::Debug::fmt),
],
},
));
};
glDeleteShader(shader);
{
::std::rt::begin_panic("cant compile shader!")
};
}
shader
}
}
pub enum CullFace {
Nothing,
Front,
Back,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for CullFace {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&CullFace::Nothing,) => {
let mut debug_trait_builder = f.debug_tuple("Nothing");
debug_trait_builder.finish()
}
(&CullFace::Front,) => {
let mut debug_trait_builder = f.debug_tuple("Front");
debug_trait_builder.finish()
}
(&CullFace::Back,) => {
let mut debug_trait_builder = f.debug_tuple("Back");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for CullFace {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for CullFace {
#[inline]
fn eq(&self, other: &CullFace) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for CullFace {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for CullFace {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for CullFace {
#[inline]
fn clone(&self) -> CullFace {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for CullFace {}
pub enum FrontFaceOrder {
Clockwise,
CounterClockwise,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for FrontFaceOrder {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&FrontFaceOrder::Clockwise,) => {
let mut debug_trait_builder = f.debug_tuple("Clockwise");
debug_trait_builder.finish()
}
(&FrontFaceOrder::CounterClockwise,) => {
let mut debug_trait_builder = f.debug_tuple("CounterClockwise");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for FrontFaceOrder {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for FrontFaceOrder {
#[inline]
fn eq(&self, other: &FrontFaceOrder) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for FrontFaceOrder {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for FrontFaceOrder {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for FrontFaceOrder {
#[inline]
fn clone(&self) -> FrontFaceOrder {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for FrontFaceOrder {}
pub enum Comparison {
Never,
Less,
LessOrEqual,
Greater,
GreaterOrEqual,
Equal,
NotEqual,
Always,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Comparison {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&Comparison::Never,) => {
let mut debug_trait_builder = f.debug_tuple("Never");
debug_trait_builder.finish()
}
(&Comparison::Less,) => {
let mut debug_trait_builder = f.debug_tuple("Less");
debug_trait_builder.finish()
}
(&Comparison::LessOrEqual,) => {
let mut debug_trait_builder = f.debug_tuple("LessOrEqual");
debug_trait_builder.finish()
}
(&Comparison::Greater,) => {
let mut debug_trait_builder = f.debug_tuple("Greater");
debug_trait_builder.finish()
}
(&Comparison::GreaterOrEqual,) => {
let mut debug_trait_builder = f.debug_tuple("GreaterOrEqual");
debug_trait_builder.finish()
}
(&Comparison::Equal,) => {
let mut debug_trait_builder = f.debug_tuple("Equal");
debug_trait_builder.finish()
}
(&Comparison::NotEqual,) => {
let mut debug_trait_builder = f.debug_tuple("NotEqual");
debug_trait_builder.finish()
}
(&Comparison::Always,) => {
let mut debug_trait_builder = f.debug_tuple("Always");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for Comparison {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for Comparison {
#[inline]
fn eq(&self, other: &Comparison) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for Comparison {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for Comparison {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Comparison {
#[inline]
fn clone(&self) -> Comparison {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Comparison {}
impl From<Comparison> for GLenum {
fn from(cmp: Comparison) -> Self {
match cmp {
Comparison::Never => GL_NEVER,
Comparison::Less => GL_LESS,
Comparison::LessOrEqual => GL_LEQUAL,
Comparison::Greater => GL_GREATER,
Comparison::GreaterOrEqual => GL_GEQUAL,
Comparison::Equal => GL_EQUAL,
Comparison::NotEqual => GL_NOTEQUAL,
Comparison::Always => GL_ALWAYS,
}
}
}
pub enum Equation {
Add,
Subtract,
ReverseSubtract,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Equation {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&Equation::Add,) => {
let mut debug_trait_builder = f.debug_tuple("Add");
debug_trait_builder.finish()
}
(&Equation::Subtract,) => {
let mut debug_trait_builder = f.debug_tuple("Subtract");
debug_trait_builder.finish()
}
(&Equation::ReverseSubtract,) => {
let mut debug_trait_builder = f.debug_tuple("ReverseSubtract");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for Equation {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for Equation {
#[inline]
fn eq(&self, other: &Equation) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for Equation {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for Equation {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Equation {
#[inline]
fn clone(&self) -> Equation {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Equation {}
pub enum BlendValue {
SourceColor,
SourceAlpha,
DestinationColor,
DestinationAlpha,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for BlendValue {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&BlendValue::SourceColor,) => {
let mut debug_trait_builder = f.debug_tuple("SourceColor");
debug_trait_builder.finish()
}
(&BlendValue::SourceAlpha,) => {
let mut debug_trait_builder = f.debug_tuple("SourceAlpha");
debug_trait_builder.finish()
}
(&BlendValue::DestinationColor,) => {
let mut debug_trait_builder = f.debug_tuple("DestinationColor");
debug_trait_builder.finish()
}
(&BlendValue::DestinationAlpha,) => {
let mut debug_trait_builder = f.debug_tuple("DestinationAlpha");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for BlendValue {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for BlendValue {
#[inline]
fn eq(&self, other: &BlendValue) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
impl ::core::marker::StructuralEq for BlendValue {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for BlendValue {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for BlendValue {
#[inline]
fn clone(&self) -> BlendValue {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for BlendValue {}
pub enum BlendFactor {
Zero,
One,
Value(BlendValue),
OneMinusValue(BlendValue),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for BlendFactor {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&BlendFactor::Zero,) => {
let mut debug_trait_builder = f.debug_tuple("Zero");
debug_trait_builder.finish()
}
(&BlendFactor::One,) => {
let mut debug_trait_builder = f.debug_tuple("One");
debug_trait_builder.finish()
}
(&BlendFactor::Value(ref __self_0),) => {
let mut debug_trait_builder = f.debug_tuple("Value");
let _ = debug_trait_builder.field(&&(*__self_0));
debug_trait_builder.finish()
}
(&BlendFactor::OneMinusValue(ref __self_0),) => {
let mut debug_trait_builder = f.debug_tuple("OneMinusValue");
let _ = debug_trait_builder.field(&&(*__self_0));
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for BlendFactor {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for BlendFactor {
#[inline]
fn eq(&self, other: &BlendFactor) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
(&BlendFactor::Value(ref __self_0), &BlendFactor::Value(ref __arg_1_0)) => {
(*__self_0) == (*__arg_1_0)
}
(
&BlendFactor::OneMinusValue(ref __self_0),
&BlendFactor::OneMinusValue(ref __arg_1_0),
) => (*__self_0) == (*__arg_1_0),
_ => true,
}
} else {
false
}
}
}
#[inline]
fn ne(&self, other: &BlendFactor) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
(&BlendFactor::Value(ref __self_0), &BlendFactor::Value(ref __arg_1_0)) => {
(*__self_0) != (*__arg_1_0)
}
(
&BlendFactor::OneMinusValue(ref __self_0),
&BlendFactor::OneMinusValue(ref __arg_1_0),
) => (*__self_0) != (*__arg_1_0),
_ => false,
}
} else {
true
}
}
}
}
impl ::core::marker::StructuralEq for BlendFactor {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::Eq for BlendFactor {
#[inline]
#[doc(hidden)]
fn assert_receiver_is_total_eq(&self) -> () {
{
let _: ::core::cmp::AssertParamIsEq<BlendValue>;
let _: ::core::cmp::AssertParamIsEq<BlendValue>;
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for BlendFactor {
#[inline]
fn clone(&self) -> BlendFactor {
{
let _: ::core::clone::AssertParamIsClone<BlendValue>;
let _: ::core::clone::AssertParamIsClone<BlendValue>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for BlendFactor {}
impl From<Equation> for GLenum {
fn from(eq: Equation) -> Self {
match eq {
Equation::Add => GL_FUNC_ADD,
Equation::Subtract => GL_FUNC_SUBTRACT,
Equation::ReverseSubtract => GL_FUNC_REVERSE_SUBTRACT,
}
}
}
impl From<BlendFactor> for GLenum {
fn from(factor: BlendFactor) -> GLenum {
match factor {
BlendFactor::Zero => GL_ZERO,
BlendFactor::One => GL_ONE,
BlendFactor::Value(BlendValue::SourceColor) => GL_SRC_COLOR,
BlendFactor::Value(BlendValue::SourceAlpha) => GL_SRC_ALPHA,
BlendFactor::Value(BlendValue::DestinationColor) => GL_DST_COLOR,
BlendFactor::Value(BlendValue::DestinationAlpha) => GL_DST_ALPHA,
BlendFactor::OneMinusValue(BlendValue::SourceColor) => GL_ONE_MINUS_SRC_COLOR,
BlendFactor::OneMinusValue(BlendValue::SourceAlpha) => GL_ONE_MINUS_SRC_ALPHA,
BlendFactor::OneMinusValue(BlendValue::DestinationColor) => GL_ONE_MINUS_DST_COLOR,
BlendFactor::OneMinusValue(BlendValue::DestinationAlpha) => GL_ONE_MINUS_DST_ALPHA,
}
}
}
pub struct PipelineParams {
pub cull_face: CullFace,
pub front_face_order: FrontFaceOrder,
pub depth_test: Comparison,
pub depth_write: bool,
pub depth_write_offset: Option<(f32, f32)>,
pub color_blend: BlendState,
pub color_write: (bool, bool, bool, bool),
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for PipelineParams {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
PipelineParams {
cull_face: ref __self_0_0,
front_face_order: ref __self_0_1,
depth_test: ref __self_0_2,
depth_write: ref __self_0_3,
depth_write_offset: ref __self_0_4,
color_blend: ref __self_0_5,
color_write: ref __self_0_6,
} => {
let mut debug_trait_builder = f.debug_struct("PipelineParams");
let _ = debug_trait_builder.field("cull_face", &&(*__self_0_0));
let _ = debug_trait_builder.field("front_face_order", &&(*__self_0_1));
let _ = debug_trait_builder.field("depth_test", &&(*__self_0_2));
let _ = debug_trait_builder.field("depth_write", &&(*__self_0_3));
let _ = debug_trait_builder.field("depth_write_offset", &&(*__self_0_4));
let _ = debug_trait_builder.field("color_blend", &&(*__self_0_5));
let _ = debug_trait_builder.field("color_write", &&(*__self_0_6));
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for PipelineParams {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for PipelineParams {
#[inline]
fn eq(&self, other: &PipelineParams) -> bool {
match *other {
PipelineParams {
cull_face: ref __self_1_0,
front_face_order: ref __self_1_1,
depth_test: ref __self_1_2,
depth_write: ref __self_1_3,
depth_write_offset: ref __self_1_4,
color_blend: ref __self_1_5,
color_write: ref __self_1_6,
} => match *self {
PipelineParams {
cull_face: ref __self_0_0,
front_face_order: ref __self_0_1,
depth_test: ref __self_0_2,
depth_write: ref __self_0_3,
depth_write_offset: ref __self_0_4,
color_blend: ref __self_0_5,
color_write: ref __self_0_6,
} => {
(*__self_0_0) == (*__self_1_0)
&& (*__self_0_1) == (*__self_1_1)
&& (*__self_0_2) == (*__self_1_2)
&& (*__self_0_3) == (*__self_1_3)
&& (*__self_0_4) == (*__self_1_4)
&& (*__self_0_5) == (*__self_1_5)
&& (*__self_0_6) == (*__self_1_6)
}
},
}
}
#[inline]
fn ne(&self, other: &PipelineParams) -> bool {
match *other {
PipelineParams {
cull_face: ref __self_1_0,
front_face_order: ref __self_1_1,
depth_test: ref __self_1_2,
depth_write: ref __self_1_3,
depth_write_offset: ref __self_1_4,
color_blend: ref __self_1_5,
color_write: ref __self_1_6,
} => match *self {
PipelineParams {
cull_face: ref __self_0_0,
front_face_order: ref __self_0_1,
depth_test: ref __self_0_2,
depth_write: ref __self_0_3,
depth_write_offset: ref __self_0_4,
color_blend: ref __self_0_5,
color_write: ref __self_0_6,
} => {
(*__self_0_0) != (*__self_1_0)
|| (*__self_0_1) != (*__self_1_1)
|| (*__self_0_2) != (*__self_1_2)
|| (*__self_0_3) != (*__self_1_3)
|| (*__self_0_4) != (*__self_1_4)
|| (*__self_0_5) != (*__self_1_5)
|| (*__self_0_6) != (*__self_1_6)
}
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for PipelineParams {
#[inline]
fn clone(&self) -> PipelineParams {
{
let _: ::core::clone::AssertParamIsClone<CullFace>;
let _: ::core::clone::AssertParamIsClone<FrontFaceOrder>;
let _: ::core::clone::AssertParamIsClone<Comparison>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<Option<(f32, f32)>>;
let _: ::core::clone::AssertParamIsClone<BlendState>;
let _: ::core::clone::AssertParamIsClone<(bool, bool, bool, bool)>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for PipelineParams {}
pub struct Pipeline(usize);
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Pipeline {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Pipeline {
#[inline]
fn clone(&self) -> Pipeline {
{
let _: ::core::clone::AssertParamIsClone<usize>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Pipeline {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
Pipeline(ref __self_0_0) => {
let mut debug_trait_builder = f.debug_tuple("Pipeline");
let _ = debug_trait_builder.field(&&(*__self_0_0));
debug_trait_builder.finish()
}
}
}
}
impl Default for PipelineParams {
fn default() -> PipelineParams {
PipelineParams {
cull_face: CullFace::Nothing,
front_face_order: FrontFaceOrder::CounterClockwise,
depth_test: Comparison::Always,
depth_write: false,
depth_write_offset: None,
color_blend: None,
color_write: (true, true, true, true),
}
}
}
impl Pipeline {
pub fn new(
ctx: &mut Context,
buffer_layout: &[BufferLayout],
attributes: &[VertexAttribute],
shader: Shader,
) -> Pipeline {
Self::with_params(ctx, buffer_layout, attributes, shader, Default::default())
}
fn with_params(
ctx: &mut Context,
buffer_layout: &[BufferLayout],
attributes: &[VertexAttribute],
shader: Shader,
params: PipelineParams,
) {
()
}
}
struct VertexAttributeInternal {
attr_loc: GLuint,
size: i32,
type_: GLuint,
offset: i64,
stride: i32,
buffer_index: usize,
divisor: i32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for VertexAttributeInternal {
#[inline]
fn clone(&self) -> VertexAttributeInternal {
{
let _: ::core::clone::AssertParamIsClone<GLuint>;
let _: ::core::clone::AssertParamIsClone<i32>;
let _: ::core::clone::AssertParamIsClone<GLuint>;
let _: ::core::clone::AssertParamIsClone<i64>;
let _: ::core::clone::AssertParamIsClone<i32>;
let _: ::core::clone::AssertParamIsClone<usize>;
let _: ::core::clone::AssertParamIsClone<i32>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for VertexAttributeInternal {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for VertexAttributeInternal {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
VertexAttributeInternal {
attr_loc: ref __self_0_0,
size: ref __self_0_1,
type_: ref __self_0_2,
offset: ref __self_0_3,
stride: ref __self_0_4,
buffer_index: ref __self_0_5,
divisor: ref __self_0_6,
} => {
let mut debug_trait_builder = f.debug_struct("VertexAttributeInternal");
let _ = debug_trait_builder.field("attr_loc", &&(*__self_0_0));
let _ = debug_trait_builder.field("size", &&(*__self_0_1));
let _ = debug_trait_builder.field("type_", &&(*__self_0_2));
let _ = debug_trait_builder.field("offset", &&(*__self_0_3));
let _ = debug_trait_builder.field("stride", &&(*__self_0_4));
let _ = debug_trait_builder.field("buffer_index", &&(*__self_0_5));
let _ = debug_trait_builder.field("divisor", &&(*__self_0_6));
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for VertexAttributeInternal {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for VertexAttributeInternal {
#[inline]
fn eq(&self, other: &VertexAttributeInternal) -> bool {
match *other {
VertexAttributeInternal {
attr_loc: ref __self_1_0,
size: ref __self_1_1,
type_: ref __self_1_2,
offset: ref __self_1_3,
stride: ref __self_1_4,
buffer_index: ref __self_1_5,
divisor: ref __self_1_6,
} => match *self {
VertexAttributeInternal {
attr_loc: ref __self_0_0,
size: ref __self_0_1,
type_: ref __self_0_2,
offset: ref __self_0_3,
stride: ref __self_0_4,
buffer_index: ref __self_0_5,
divisor: ref __self_0_6,
} => {
(*__self_0_0) == (*__self_1_0)
&& (*__self_0_1) == (*__self_1_1)
&& (*__self_0_2) == (*__self_1_2)
&& (*__self_0_3) == (*__self_1_3)
&& (*__self_0_4) == (*__self_1_4)
&& (*__self_0_5) == (*__self_1_5)
&& (*__self_0_6) == (*__self_1_6)
}
},
}
}
#[inline]
fn ne(&self, other: &VertexAttributeInternal) -> bool {
match *other {
VertexAttributeInternal {
attr_loc: ref __self_1_0,
size: ref __self_1_1,
type_: ref __self_1_2,
offset: ref __self_1_3,
stride: ref __self_1_4,
buffer_index: ref __self_1_5,
divisor: ref __self_1_6,
} => match *self {
VertexAttributeInternal {
attr_loc: ref __self_0_0,
size: ref __self_0_1,
type_: ref __self_0_2,
offset: ref __self_0_3,
stride: ref __self_0_4,
buffer_index: ref __self_0_5,
divisor: ref __self_0_6,
} => {
(*__self_0_0) != (*__self_1_0)
|| (*__self_0_1) != (*__self_1_1)
|| (*__self_0_2) != (*__self_1_2)
|| (*__self_0_3) != (*__self_1_3)
|| (*__self_0_4) != (*__self_1_4)
|| (*__self_0_5) != (*__self_1_5)
|| (*__self_0_6) != (*__self_1_6)
}
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::default::Default for VertexAttributeInternal {
#[inline]
fn default() -> VertexAttributeInternal {
VertexAttributeInternal {
attr_loc: ::core::default::Default::default(),
size: ::core::default::Default::default(),
type_: ::core::default::Default::default(),
offset: ::core::default::Default::default(),
stride: ::core::default::Default::default(),
buffer_index: ::core::default::Default::default(),
divisor: ::core::default::Default::default(),
}
}
}
struct PipelineInternal {
layout: Vec<VertexAttributeInternal>,
shader: Shader,
params: PipelineParams,
}
pub struct Bindings {
pub vertex_buffers: Vec<Buffer>,
pub index_buffer: Buffer,
pub images: Vec<Texture>,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Bindings {
#[inline]
fn clone(&self) -> Bindings {
match *self {
Bindings {
vertex_buffers: ref __self_0_0,
index_buffer: ref __self_0_1,
images: ref __self_0_2,
} => Bindings {
vertex_buffers: ::core::clone::Clone::clone(&(*__self_0_0)),
index_buffer: ::core::clone::Clone::clone(&(*__self_0_1)),
images: ::core::clone::Clone::clone(&(*__self_0_2)),
},
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Bindings {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
Bindings {
vertex_buffers: ref __self_0_0,
index_buffer: ref __self_0_1,
images: ref __self_0_2,
} => {
let mut debug_trait_builder = f.debug_struct("Bindings");
let _ = debug_trait_builder.field("vertex_buffers", &&(*__self_0_0));
let _ = debug_trait_builder.field("index_buffer", &&(*__self_0_1));
let _ = debug_trait_builder.field("images", &&(*__self_0_2));
debug_trait_builder.finish()
}
}
}
}
pub enum BufferType {
VertexBuffer,
IndexBuffer,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for BufferType {
#[inline]
fn clone(&self) -> BufferType {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for BufferType {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for BufferType {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&BufferType::VertexBuffer,) => {
let mut debug_trait_builder = f.debug_tuple("VertexBuffer");
debug_trait_builder.finish()
}
(&BufferType::IndexBuffer,) => {
let mut debug_trait_builder = f.debug_tuple("IndexBuffer");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for BufferType {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for BufferType {
#[inline]
fn eq(&self, other: &BufferType) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
pub enum Usage {
Immutable,
Dynamic,
Stream,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Usage {
#[inline]
fn clone(&self) -> Usage {
{
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Usage {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Usage {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match (&*self,) {
(&Usage::Immutable,) => {
let mut debug_trait_builder = f.debug_tuple("Immutable");
debug_trait_builder.finish()
}
(&Usage::Dynamic,) => {
let mut debug_trait_builder = f.debug_tuple("Dynamic");
debug_trait_builder.finish()
}
(&Usage::Stream,) => {
let mut debug_trait_builder = f.debug_tuple("Stream");
debug_trait_builder.finish()
}
}
}
}
impl ::core::marker::StructuralPartialEq for Usage {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::cmp::PartialEq for Usage {
#[inline]
fn eq(&self, other: &Usage) -> bool {
{
let __self_vi = unsafe { ::core::intrinsics::discriminant_value(&*self) } as isize;
let __arg_1_vi =
unsafe { ::core::intrinsics::discriminant_value(&*other) } as isize;
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
_ => true,
}
} else {
false
}
}
}
}
fn gl_buffer_target(buffer_type: &BufferType) -> GLenum {
match buffer_type {
BufferType::VertexBuffer => GL_ARRAY_BUFFER,
BufferType::IndexBuffer => GL_ELEMENT_ARRAY_BUFFER,
}
}
fn gl_usage(usage: &Usage) -> GLenum {
match usage {
Usage::Immutable => GL_STATIC_DRAW,
Usage::Dynamic => GL_DYNAMIC_DRAW,
Usage::Stream => GL_STREAM_DRAW,
}
}
pub struct Buffer {
gl_buf: GLuint,
buffer_type: BufferType,
size: usize,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::clone::Clone for Buffer {
#[inline]
fn clone(&self) -> Buffer {
{
let _: ::core::clone::AssertParamIsClone<GLuint>;
let _: ::core::clone::AssertParamIsClone<BufferType>;
let _: ::core::clone::AssertParamIsClone<usize>;
*self
}
}
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::marker::Copy for Buffer {}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Buffer {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
Buffer {
gl_buf: ref __self_0_0,
buffer_type: ref __self_0_1,
size: ref __self_0_2,
} => {
let mut debug_trait_builder = f.debug_struct("Buffer");
let _ = debug_trait_builder.field("gl_buf", &&(*__self_0_0));
let _ = debug_trait_builder.field("buffer_type", &&(*__self_0_1));
let _ = debug_trait_builder.field("size", &&(*__self_0_2));
debug_trait_builder.finish()
}
}
}
}
impl Buffer {
pub fn immutable<T>(ctx: &mut Context, buffer_type: BufferType, data: &[T]) -> Buffer {
if buffer_type == BufferType::IndexBuffer {
if !(mem::size_of::<T>() == 2) {
{
::std::rt::begin_panic(
"Only u16/i16 index buffers are implemented right now",
)
}
};
}
let gl_target = gl_buffer_target(&buffer_type);
let gl_usage = gl_usage(&Usage::Immutable);
let size = mem::size_of_val(data) as i64;
let mut gl_buf: u32 = 0;
unsafe {
glGenBuffers(1, &mut gl_buf as *mut _);
ctx.cache.store_buffer_binding(gl_target);
ctx.cache.bind_buffer(gl_target, gl_buf);
glBufferData(gl_target, size as _, std::ptr::null() as *const _, gl_usage);
glBufferSubData(gl_target, 0, size as _, data.as_ptr() as *const _);
ctx.cache.restore_buffer_binding(gl_target);
}
Buffer {
gl_buf,
buffer_type,
size: size as usize,
}
}
pub fn stream(ctx: &mut Context, buffer_type: BufferType, size: usize) -> Buffer {
let gl_target = gl_buffer_target(&buffer_type);
let gl_usage = gl_usage(&Usage::Stream);
let mut gl_buf: u32 = 0;
unsafe {
glGenBuffers(1, &mut gl_buf as *mut _);
ctx.cache.store_buffer_binding(gl_target);
ctx.cache.bind_buffer(gl_target, gl_buf);
glBufferData(gl_target, size as _, std::ptr::null() as *const _, gl_usage);
ctx.cache.restore_buffer_binding(gl_target);
}
Buffer {
gl_buf,
buffer_type,
size,
}
}
pub fn update<T>(&self, ctx: &mut Context, data: &[T]) {
let size = mem::size_of_val(data);
if !(size <= self.size) {
{
::std::rt::begin_panic("assertion failed: size <= self.size")
}
};
let gl_target = gl_buffer_target(&self.buffer_type);
ctx.cache.bind_buffer(gl_target, self.gl_buf);
unsafe { glBufferSubData(gl_target, 0, size as _, data.as_ptr() as *const _) };
ctx.cache.restore_buffer_binding(gl_target);
}
pub fn size(&self) -> usize {
self.size
}
pub fn delete(&self) {
unsafe { glDeleteBuffers(1, &self.gl_buf as *const _) }
}
}
}
pub use event::*;
pub use graphics::*;
pub use sapp::{rand, RAND_MAX};
use std::ffi::CString;
pub mod date {
#[cfg(not(target_arch = "wasm32"))]
pub fn now() -> f64 {
use std::time::SystemTime;
let time = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap_or_else(|e| ::std::rt::begin_panic(e));
time.as_secs_f64()
}
}
impl Context {
pub fn quit(&self) {
#[cfg(not(target_arch = "wasm32"))]
unsafe {
sapp::sapp_quit();
}
}
pub fn request_quit(&self) {
#[cfg(not(target_arch = "wasm32"))]
unsafe {
sapp::sapp_request_quit();
}
}
pub fn cancel_quit(&self) {
#[cfg(not(target_arch = "wasm32"))]
unsafe {
sapp::sapp_cancel_quit();
}
}
pub fn set_cursor_grab(&self, grab: bool) {
unsafe {
sapp::sapp_set_cursor_grab(grab);
}
}
pub fn show_mouse(&self, shown: bool) {
unsafe {
sapp::sapp_show_mouse(shown);
}
}
}
pub enum UserData {
Owning((Box<dyn EventHandler>, Context)),
Free(Box<dyn EventHandlerFree>),
}
impl UserData {
pub fn owning(event_handler: impl EventHandler + 'static, ctx: Context) -> UserData {
UserData::Owning((Box::new(event_handler), ctx))
}
pub fn free(event_handler: impl EventHandlerFree + 'static) -> UserData {
UserData::Free(Box::new(event_handler))
}
}
macro_rules! event_call {
($ event_handler : expr, $ fn : ident $ (, $ args : expr) *) =>
{
{
match $ event_handler
{
UserData :: Owning ((ref mut event_handler, ref mut context))
=> { event_handler . $ fn (context, $ ($ args,) *) ; }
UserData :: Free (ref mut event_handler) =>
{ event_handler . $ fn ($ ($ args,) *) ; }
}
}
} ;
}
enum UserDataState {
Uninitialized(Box<dyn 'static + FnOnce(Context) -> UserData>),
Intialized(UserData),
Empty,
}
extern "C" fn init(user_data: *mut ::std::os::raw::c_void) {
let data: &mut UserDataState = unsafe { &mut *(user_data as *mut UserDataState) };
let empty = UserDataState::Empty;
let f = std::mem::replace(data, empty);
let f = if let UserDataState::Uninitialized(f) = f {
f
} else {
{
{
::std::rt::begin_panic("explicit panic")
}
};
};
let context = graphics::Context::new();
let user_data = f(context);
std::mem::replace(data, UserDataState::Intialized(user_data));
}
extern "C" fn frame(user_data: *mut ::std::os::raw::c_void) {
let data: &mut UserDataState = unsafe { &mut *(user_data as *mut UserDataState) };
let data = if let UserDataState::Intialized(ref mut data) = data {
data
} else {
{
{
::std::rt::begin_panic("explicit panic")
}
}
};
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.update(context);
}
UserData::Free(ref mut event_handler) => {
event_handler.update();
}
}
};
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.draw(context);
}
UserData::Free(ref mut event_handler) => {
event_handler.draw();
}
}
};
}
extern "C" fn event(event: *const sapp::sapp_event, user_data: *mut ::std::os::raw::c_void) {
let data: &mut UserDataState = unsafe { &mut *(user_data as *mut UserDataState) };
let event = unsafe { &*event };
let data = if let UserDataState::Intialized(ref mut data) = data {
data
} else {
{
{
::std::rt::begin_panic("explicit panic")
}
}
};
match event.type_ {
sapp::sapp_event_type_SAPP_EVENTTYPE_MOUSE_MOVE => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.mouse_motion_event(context, event.mouse_x, event.mouse_y);
}
UserData::Free(ref mut event_handler) => {
event_handler.mouse_motion_event(event.mouse_x, event.mouse_y);
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_MOUSE_SCROLL => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.mouse_wheel_event(context, event.scroll_x, event.scroll_y);
}
UserData::Free(ref mut event_handler) => {
event_handler.mouse_wheel_event(event.scroll_x, event.scroll_y);
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_MOUSE_DOWN => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.mouse_button_down_event(
context,
MouseButton::from(event.mouse_button),
event.mouse_x,
event.mouse_y,
);
}
UserData::Free(ref mut event_handler) => {
event_handler.mouse_button_down_event(
MouseButton::from(event.mouse_button),
event.mouse_x,
event.mouse_y,
);
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_MOUSE_UP => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.mouse_button_up_event(
context,
MouseButton::from(event.mouse_button),
event.mouse_x,
event.mouse_y,
);
}
UserData::Free(ref mut event_handler) => {
event_handler.mouse_button_up_event(
MouseButton::from(event.mouse_button),
event.mouse_x,
event.mouse_y,
);
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_CHAR => {
if let Some(character) = std::char::from_u32(event.char_code) {
let key_mods = KeyMods::from(event.modifiers);
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.char_event(
context,
character,
key_mods,
event.key_repeat,
);
}
UserData::Free(ref mut event_handler) => {
event_handler.char_event(character, key_mods, event.key_repeat);
}
}
}
}
}
sapp::sapp_event_type_SAPP_EVENTTYPE_KEY_DOWN => {
let keycode = KeyCode::from(event.key_code);
let key_mods = KeyMods::from(event.modifiers);
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.key_down_event(context, keycode, key_mods, false);
}
UserData::Free(ref mut event_handler) => {
event_handler.key_down_event(keycode, key_mods, false);
}
}
}
}
sapp::sapp_event_type_SAPP_EVENTTYPE_KEY_UP => {
let keycode = KeyCode::from(event.key_code);
let key_mods = KeyMods::from(event.modifiers);
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.key_up_event(context, keycode, key_mods);
}
UserData::Free(ref mut event_handler) => {
event_handler.key_up_event(keycode, key_mods);
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_RESIZED => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.resize_event(
context,
event.window_width as f32,
event.window_height as f32,
);
}
UserData::Free(ref mut event_handler) => {
event_handler
.resize_event(event.window_width as f32, event.window_height as f32);
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_BEGAN
| sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_ENDED
| sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_CANCELLED
| sapp::sapp_event_type_SAPP_EVENTTYPE_TOUCHES_MOVED => {
for i in 0..(event.num_touches as usize) {
if event.touches[i].changed {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.touch_event(
context,
event.type_.into(),
event.touches[i].identifier as u64,
event.touches[i].pos_x,
event.touches[i].pos_y,
);
}
UserData::Free(ref mut event_handler) => {
event_handler.touch_event(
event.type_.into(),
event.touches[i].identifier as u64,
event.touches[i].pos_x,
event.touches[i].pos_y,
);
}
}
};
}
}
}
sapp::sapp_event_type_SAPP_EVENTTYPE_QUIT_REQUESTED => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.quit_requested_event(context);
}
UserData::Free(ref mut event_handler) => {
event_handler.quit_requested_event();
}
}
};
}
sapp::sapp_event_type_SAPP_EVENTTYPE_RAW_DEVICE => {
{
match data {
UserData::Owning((ref mut event_handler, ref mut context)) => {
event_handler.raw_mouse_motion(context, event.mouse_dx, event.mouse_dy);
}
UserData::Free(ref mut event_handler) => {
event_handler.raw_mouse_motion(event.mouse_dx, event.mouse_dy);
}
}
};
}
_ => {}
}
}
pub fn start<F>(conf: conf::Conf, f: F)
where
F: 'static + FnOnce(Context) -> UserData,
{
let mut desc: sapp::sapp_desc = unsafe { std::mem::zeroed() };
let title =
CString::new(conf.window_title.as_bytes()).unwrap_or_else(|e| ::std::rt::begin_panic(e));
let mut user_data = Box::new(UserDataState::Uninitialized(Box::new(f)));
desc.width = conf.window_width;
desc.height = conf.window_height;
desc.fullscreen = conf.fullscreen as _;
desc.high_dpi = conf.high_dpi as _;
desc.window_title = title.as_ptr();
desc.user_data = &mut *user_data as *mut _ as *mut _;
desc.init_userdata_cb = Some(init);
desc.frame_userdata_cb = Some(frame);
desc.event_userdata_cb = Some(event);
std::mem::forget(user_data);
unsafe { sapp::sapp_run(&desc as *const _) };
}
pub fn delete(&self) {
unsafe { glDeleteTextures(1, &self.texture as *const _); }
}
pub fn delete(&self) {
unsafe { glDeleteTextures(1, &self.texture as *const _); }
}
AAA
pub fn delete(&self) {
unsafe { glDeleteTextures(1, &self.texture as *const _); }
}
AAA