use libc;
use std::ops::Deref;
use std::ops::DerefMut;
use backend::Facade;
use buffer::{BufferCreationError, BufferType, BufferView};
use index::{IndicesSource, PrimitiveType};
#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[allow(missing_docs)] pub struct DrawCommandNoIndices {
pub count: libc::c_uint,
pub instance_count: libc::c_uint,
pub first_index: libc::c_uint,
pub base_instance: libc::c_uint,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[allow(missing_docs)] pub struct DrawCommandIndices {
pub count: libc::c_uint,
pub instance_count: libc::c_uint,
pub first_index: libc::c_uint,
pub base_vertex: libc::c_uint,
pub base_instance: libc::c_uint,
}
pub struct DrawCommandsNoIndicesBuffer {
buffer: BufferView<DrawCommandNoIndices>,
}
impl DrawCommandsNoIndicesBuffer {
pub fn empty_if_supported<F>(facade: &F, elements: usize)
-> Option<DrawCommandsNoIndicesBuffer>
where F: Facade
{
match BufferView::empty(facade, BufferType::DrawIndirectBuffer,
elements, false)
{
Ok(buf) => Some(DrawCommandsNoIndicesBuffer { buffer: buf }),
Err(BufferCreationError::BufferTypeNotSupported) => None,
Err(_) => panic!()
}
}
pub fn empty_dynamic_if_supported<F>(facade: &F, elements: usize)
-> Option<DrawCommandsNoIndicesBuffer>
where F: Facade
{
match BufferView::empty(facade, BufferType::DrawIndirectBuffer,
elements, true)
{
Ok(buf) => Some(DrawCommandsNoIndicesBuffer { buffer: buf }),
Err(BufferCreationError::BufferTypeNotSupported) => None,
Err(_) => panic!()
}
}
pub fn with_primitive_type(&self, primitives: PrimitiveType) -> IndicesSource {
IndicesSource::MultidrawArray {
buffer: self.buffer.as_slice_any(),
primitives: primitives,
}
}
}
impl Deref for DrawCommandsNoIndicesBuffer {
type Target = BufferView<DrawCommandNoIndices>;
fn deref(&self) -> &BufferView<DrawCommandNoIndices> {
&self.buffer
}
}
impl DerefMut for DrawCommandsNoIndicesBuffer {
fn deref_mut(&mut self) -> &mut BufferView<DrawCommandNoIndices> {
&mut self.buffer
}
}