1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use std::cmp::Ordering;
use super::state_dynamic::DynamicState;
use super::state_static::Pipeline;
use renderer::types::{Buffer, ClearMask};
#[derive(Clone)]
pub enum Command {
Clear(ClearMask, [f32; 4]),
Draw(u32, u32),
DrawIndexed(u32, u32, usize),
SetBuffer(Buffer),
SetDynamicState(DynamicState),
SetPipeline(Pipeline),
}
pub type SortKey = u64;
pub struct CommandBuffer {
key: SortKey,
commands: Vec<Command>,
}
impl CommandBuffer {
pub fn new(commands: Vec<Command>, key: SortKey) -> CommandBuffer {
CommandBuffer {
commands: commands,
key: key,
}
}
pub fn unpack(&mut self) -> Vec<Command> {
self.commands.drain(..).collect()
}
}
impl Ord for CommandBuffer {
fn cmp(&self, other: &Self) -> Ordering {
self.key.cmp(&other.key)
}
}
impl Eq for CommandBuffer {}
impl PartialEq for CommandBuffer {
fn eq(&self, other: &Self) -> bool {
self.key == other.key
}
}
impl PartialOrd for CommandBuffer {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}