Move glium support to a separate file

This commit is contained in:
Joonas Javanainen 2017-02-17 22:15:46 +02:00
parent 063606ceb3
commit f3a243adcf
No known key found for this signature in database
GPG Key ID: D39CCA5CB19B9179
2 changed files with 37 additions and 32 deletions

View File

@ -0,0 +1,34 @@
use glium::vertex::{Attribute, AttributeType, Vertex, VertexFormat};
use std::borrow::Cow;
use std::mem;
use std::os::raw::{c_float};
use super::{ImDrawVert, ImVec2, ImVec4};
#[cfg(feature = "glium")]
unsafe impl Attribute for ImVec2 {
fn get_type() -> AttributeType { <(c_float, c_float) as Attribute>::get_type() }
}
#[cfg(feature = "glium")]
unsafe impl Attribute for ImVec4 {
fn get_type() -> AttributeType {
<(c_float, c_float, c_float, c_float) as Attribute>::get_type()
}
}
#[cfg(feature = "glium")]
impl Vertex for ImDrawVert {
fn build_bindings() -> VertexFormat {
unsafe {
let dummy: &ImDrawVert = mem::transmute(0usize);
Cow::Owned(vec![("pos".into(),
mem::transmute(&dummy.pos),
<ImVec2 as Attribute>::get_type()),
("uv".into(),
mem::transmute(&dummy.uv),
<ImVec2 as Attribute>::get_type()),
("col".into(), mem::transmute(&dummy.col), AttributeType::U8U8U8U8)])
}
}
}

View File

@ -7,15 +7,14 @@ extern crate bitflags;
#[macro_use]
extern crate glium;
#[cfg(feature = "glium")]
use glium::vertex::{Attribute, AttributeType, Vertex, VertexFormat};
#[cfg(feature = "glium")]
use std::borrow::Cow;
use std::convert::From;
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 = "glium")]
mod glium_support;
/// ImGui context (opaque)
pub enum ImGuiContext { }
@ -304,11 +303,6 @@ impl Into<(f32, f32)> for ImVec2 {
fn into(self) -> (f32, f32) { (self.x, self.y) }
}
#[cfg(feature = "glium")]
unsafe impl Attribute for ImVec2 {
fn get_type() -> AttributeType { <(c_float, c_float) as Attribute>::get_type() }
}
/// A tuple of 4 floating-point values
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, PartialEq)]
@ -354,13 +348,6 @@ impl Into<(f32, f32, f32, f32)> for ImVec4 {
fn into(self) -> (f32, f32, f32, f32) { (self.x, self.y, self.z, self.w) }
}
#[cfg(feature = "glium")]
unsafe impl Attribute for ImVec4 {
fn get_type() -> AttributeType {
<(c_float, c_float, c_float, c_float) as Attribute>::get_type()
}
}
/// Runtime data for styling/colors
#[repr(C)]
pub struct ImGuiStyle {
@ -601,22 +588,6 @@ pub struct ImDrawVert {
pub col: ImU32,
}
#[cfg(feature = "glium")]
impl Vertex for ImDrawVert {
fn build_bindings() -> VertexFormat {
unsafe {
let dummy: &ImDrawVert = mem::transmute(0usize);
Cow::Owned(vec![("pos".into(),
mem::transmute(&dummy.pos),
<ImVec2 as Attribute>::get_type()),
("uv".into(),
mem::transmute(&dummy.uv),
<ImVec2 as Attribute>::get_type()),
("col".into(), mem::transmute(&dummy.col), AttributeType::U8U8U8U8)])
}
}
}
/// Temporary storage for outputting drawing commands out of order
#[repr(C)]
pub struct ImDrawChannel {