use gl;
use ToGlEnum;
use std::mem;
use buffer::BufferViewAnySlice;
pub use self::buffer::{IndexBuffer, IndexBufferSlice, IndexBufferAny};
pub use self::multidraw::{DrawCommandsNoIndicesBuffer, DrawCommandNoIndices};
mod buffer;
mod multidraw;
#[derive(Clone)]
pub enum IndicesSource<'a> {
IndexBuffer {
buffer: BufferViewAnySlice<'a>,
data_type: IndexType,
primitives: PrimitiveType,
},
MultidrawArray {
buffer: BufferViewAnySlice<'a>,
primitives: PrimitiveType,
},
NoIndices {
primitives: PrimitiveType,
},
}
impl<'a> IndicesSource<'a> {
pub fn get_primitives_type(&self) -> PrimitiveType {
match self {
&IndicesSource::IndexBuffer { primitives, .. } => primitives,
&IndicesSource::MultidrawArray { primitives, .. } => primitives,
&IndicesSource::NoIndices { primitives } => primitives,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PrimitiveType {
Points,
LinesList,
LinesListAdjacency,
LineStrip,
LineStripAdjacency,
TrianglesList,
TrianglesListAdjacency,
TriangleStrip,
TriangleStripAdjacency,
TriangleFan,
Patches {
vertices_per_patch: u16,
},
}
impl ToGlEnum for PrimitiveType {
fn to_glenum(&self) -> gl::types::GLenum {
match self {
&PrimitiveType::Points => gl::POINTS,
&PrimitiveType::LinesList => gl::LINES,
&PrimitiveType::LinesListAdjacency => gl::LINES_ADJACENCY,
&PrimitiveType::LineStrip => gl::LINE_STRIP,
&PrimitiveType::LineStripAdjacency => gl::LINE_STRIP_ADJACENCY,
&PrimitiveType::TrianglesList => gl::TRIANGLES,
&PrimitiveType::TrianglesListAdjacency => gl::TRIANGLES_ADJACENCY,
&PrimitiveType::TriangleStrip => gl::TRIANGLE_STRIP,
&PrimitiveType::TriangleStripAdjacency => gl::TRIANGLE_STRIP_ADJACENCY,
&PrimitiveType::TriangleFan => gl::TRIANGLE_FAN,
&PrimitiveType::Patches { .. } => gl::PATCHES,
}
}
}
#[derive(Copy, Clone, Debug)]
pub struct NoIndices(pub PrimitiveType);
impl<'a> From<NoIndices> for IndicesSource<'a> {
fn from(marker: NoIndices) -> IndicesSource<'a> {
IndicesSource::NoIndices {
primitives: marker.0
}
}
}
impl<'a, 'b> From<&'b NoIndices> for IndicesSource<'a> {
fn from(marker: &'b NoIndices) -> IndicesSource<'a> {
IndicesSource::NoIndices {
primitives: marker.0
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)] pub enum IndexType {
U8 = gl::UNSIGNED_BYTE,
U16 = gl::UNSIGNED_SHORT,
U32 = gl::UNSIGNED_INT,
}
impl IndexType {
pub fn get_size(&self) -> usize {
match *self {
IndexType::U8 => mem::size_of::<u8>(),
IndexType::U16 => mem::size_of::<u16>(),
IndexType::U32 => mem::size_of::<u32>(),
}
}
}
impl ToGlEnum for IndexType {
fn to_glenum(&self) -> gl::types::GLenum {
*self as gl::types::GLenum
}
}
pub unsafe trait Index: Copy + Send + 'static {
fn get_type() -> IndexType;
}
unsafe impl Index for u8 {
fn get_type() -> IndexType {
IndexType::U8
}
}
unsafe impl Index for u16 {
fn get_type() -> IndexType {
IndexType::U16
}
}
unsafe impl Index for u32 {
fn get_type() -> IndexType {
IndexType::U32
}
}