Skip to content

Commit 82160f1

Browse files
committed
Add resource types to CommandBuffer
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.
1 parent e99c46f commit 82160f1

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/device/draw.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ impl DataBuffer {
7777
/// An interface of the abstract command buffer. It collects commands in an
7878
/// efficient API-specific manner, to be ready for execution on the device.
7979
pub trait CommandBuffer {
80+
type Buffer;
81+
type ArrayBuffer;
82+
type Program;
83+
type FrameBuffer;
84+
type Surface;
85+
type Texture;
86+
type Sampler;
87+
8088
/// An empty constructor
8189
fn new() -> Self;
8290
/// Clear the command buffer contents, retain the allocated storage

src/device/gl_device/draw.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::slice;
1818

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

2323
/// Serialized device command.
2424
#[derive(Copy, Debug)]
@@ -62,6 +62,14 @@ impl CommandBuffer {
6262
}
6363

6464
impl draw::CommandBuffer for CommandBuffer {
65+
type Buffer = Buffer;
66+
type ArrayBuffer = ArrayBuffer;
67+
type Program = Program;
68+
type FrameBuffer = FrameBuffer;
69+
type Surface = Surface;
70+
type Texture = Texture;
71+
type Sampler = Sampler;
72+
6573
fn new() -> CommandBuffer {
6674
CommandBuffer {
6775
buf: Vec::new(),

src/device/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,16 @@ pub struct BufferInfo {
318318
/// An interface for performing draw calls using a specific graphics API
319319
#[allow(missing_docs)]
320320
pub trait Device {
321-
type CommandBuffer: draw::CommandBuffer;
321+
type CommandBuffer:
322+
draw::CommandBuffer<
323+
Buffer = Self::Buffer,
324+
ArrayBuffer = Self::ArrayBuffer,
325+
Program = Self::Program,
326+
FrameBuffer = Self::FrameBuffer,
327+
Surface = Self::Surface,
328+
Texture = Self::Texture,
329+
Sampler = Self::Sampler,
330+
>;
322331

323332
type Buffer;
324333
type ArrayBuffer;

0 commit comments

Comments
 (0)