mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-11 13:38:35 +00:00
Initial gfx support in imgui-sys
This commit is contained in:
parent
800f9d1b9c
commit
9db8cf94cf
@ -12,6 +12,7 @@ build = "build.rs"
|
||||
[dependencies]
|
||||
bitflags = "0.8"
|
||||
glium = { version = "0.16", default-features = false, optional = true }
|
||||
gfx = { version = "0.14", optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
gcc = "0.3"
|
||||
|
||||
58
imgui-sys/src/gfx_support.rs
Normal file
58
imgui-sys/src/gfx_support.rs
Normal file
@ -0,0 +1,58 @@
|
||||
use gfx::format::{Format, Formatted, U8Norm};
|
||||
use gfx::pso::buffer::{Element, ElemOffset, Structure};
|
||||
use gfx::traits::Pod;
|
||||
use std::mem;
|
||||
|
||||
use super::{ImDrawVert, ImVec2};
|
||||
|
||||
unsafe impl Pod for ImDrawVert {}
|
||||
|
||||
impl Structure<Format> for ImDrawVert {
|
||||
fn query(name: &str) -> Option<Element<Format>> {
|
||||
// array query hack from gfx_impl_struct_meta macro
|
||||
let (sub_name, big_offset) = {
|
||||
let mut split = name.split(|c| c == '[' || c == ']');
|
||||
let _ = split.next().unwrap();
|
||||
match split.next() {
|
||||
Some(s) => {
|
||||
let array_id: ElemOffset = s.parse().unwrap();
|
||||
let sub_name = match split.next() {
|
||||
Some(s) if s.starts_with('.') => &s[1..],
|
||||
_ => name,
|
||||
};
|
||||
(sub_name, array_id * (mem::size_of::<ImDrawVert>() as ElemOffset))
|
||||
}
|
||||
None => (name, 0),
|
||||
}
|
||||
};
|
||||
let dummy: &ImDrawVert = unsafe { mem::transmute(0usize) };
|
||||
match sub_name {
|
||||
"pos" => {
|
||||
Some(Element {
|
||||
format: <ImVec2 as Formatted>::get_format(),
|
||||
offset: unsafe { mem::transmute::<_, usize>(&dummy.pos) } as ElemOffset +
|
||||
big_offset,
|
||||
})
|
||||
}
|
||||
"uv" => {
|
||||
Some(Element {
|
||||
format: <ImVec2 as Formatted>::get_format(),
|
||||
offset: unsafe { mem::transmute::<_, usize>(&dummy.uv) } as ElemOffset +
|
||||
big_offset,
|
||||
})
|
||||
}
|
||||
"col" => {
|
||||
Some(Element {
|
||||
format: <[U8Norm; 4] as Formatted>::get_format(),
|
||||
offset: unsafe { mem::transmute::<_, usize>(&dummy.col) } as ElemOffset +
|
||||
big_offset,
|
||||
})
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gfx_format! {
|
||||
ImVec2: R32_G32 = Vec2<Float>
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
use glium::vertex::{Attribute, AttributeType, Vertex, VertexFormat};
|
||||
use std::borrow::Cow;
|
||||
use std::mem;
|
||||
use std::os::raw::{c_float};
|
||||
use std::os::raw::c_float;
|
||||
|
||||
use super::{ImDrawVert, ImVec2, ImVec4};
|
||||
|
||||
|
||||
@ -3,6 +3,10 @@
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
|
||||
#[cfg(feature = "gfx")]
|
||||
#[macro_use]
|
||||
extern crate gfx;
|
||||
|
||||
#[cfg(feature = "glium")]
|
||||
extern crate glium;
|
||||
|
||||
@ -11,6 +15,9 @@ use std::mem;
|
||||
use std::os::raw::{c_char, c_float, c_int, c_short, c_uchar, c_uint, c_ushort, c_void};
|
||||
use std::slice;
|
||||
|
||||
#[cfg(feature = "gfx")]
|
||||
mod gfx_support;
|
||||
|
||||
#[cfg(feature = "glium")]
|
||||
mod glium_support;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user