Skip to content

Commit

Permalink
Add resource types to CommandBuffer
Browse files Browse the repository at this point in the history
This is a little ugly, but it allows us to have access to the resource types without CommandBuffer needing to have access to Device, which would result in a rustc stack overflow.
  • Loading branch information
brendanzab committed Feb 17, 2015
1 parent 01f212d commit 6337291
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/device/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ impl DataBuffer {
/// An interface of the abstract command buffer. It collects commands in an
/// efficient API-specific manner, to be ready for execution on the device.
pub trait CommandBuffer {
type Buffer;
type ArrayBuffer;
type Program;
type FrameBuffer;
type Surface;
type Texture;
type Sampler;

/// An empty constructor
fn new() -> Self;
/// Clear the command buffer contents, retain the allocated storage
Expand Down
10 changes: 9 additions & 1 deletion src/device/gl_device/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::slice;

use {attrib, draw, target, tex, shade, state};
use {AttributeSlot, IndexType, InstanceCount, PrimitiveType, TextureSlot, UniformBlockIndex, UniformBufferSlot, VertexCount};
use super::{ArrayBuffer, Buffer, FrameBuffer, Program, Surface, Texture};
use super::{ArrayBuffer, Buffer, FrameBuffer, Program, Sampler, Surface, Texture};

/// Serialized device command.
#[derive(Copy, Debug)]
Expand Down Expand Up @@ -62,6 +62,14 @@ impl CommandBuffer {
}

impl draw::CommandBuffer for CommandBuffer {
type Buffer = Buffer;
type ArrayBuffer = ArrayBuffer;
type Program = Program;
type FrameBuffer = FrameBuffer;
type Surface = Surface;
type Texture = Texture;
type Sampler = Sampler;

fn new() -> CommandBuffer {
CommandBuffer {
buf: Vec::new(),
Expand Down
11 changes: 10 additions & 1 deletion src/device/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,16 @@ pub struct BufferInfo {
/// An interface for performing draw calls using a specific graphics API
#[allow(missing_docs)]
pub trait Device {
type CommandBuffer: draw::CommandBuffer;
type CommandBuffer:
draw::CommandBuffer<
Buffer = Self::Buffer,
ArrayBuffer = Self::ArrayBuffer,
Program = Self::Program,
FrameBuffer = Self::FrameBuffer,
Surface = Self::Surface,
Texture = Self::Texture,
Sampler = Self::Sampler,
>;

type Buffer;
type ArrayBuffer;
Expand Down

0 comments on commit 6337291

Please sign in to comment.