Add buffer_slice_field! macro

This commit is contained in:
Pierre Krieger 2016-05-02 11:18:26 +02:00
parent 39f84d554c
commit efb6dcdc2f
2 changed files with 10 additions and 6 deletions

View File

@ -2,12 +2,6 @@
- No way to store an object and its borrowing in the same struct. This is the reason why the whole API uses `Arc`s.
- No pointer-to-struct-member. When you request the GPU to perform an operation on some data, you have to give a pointer to the data that
must be manipulated. However regular Rust pointers can't be used, as the buffers are not necessarily in the memory accessible from your
program. Instead vulkano provides its own pointer-like struct named `BufferSlice`. The problem is that there is no way to safely convert
a `BufferSlice<Foo>` (equivalent of a virtual `&Foo`), where `struct Foo { a: i32 }`, into a `BufferSlice<i32>` (equivalent of a virtual
`&i32`) pointing to the `a` member.
- Lack of plugins means that you have to use a build script to compile your shaders instead of inlining them directly where they are used.
In addition to this, lots of existing macros would be much simpler to implement with plugins. The code generated by macros is currently
inefficient because using the efficient way would make the code very difficult to read.

View File

@ -232,6 +232,16 @@ impl<'a, T, B: 'a> From<BufferSlice<'a, T, B>> for BufferSlice<'a, [T], B>
}
}
/// Takes a `BufferSlice` that points to a struct, and returns a `BufferSlice` that points to
/// a specific field of that struct.
#[macro_export]
macro_rules! buffer_slice_field {
($slice:expr, $field:ident) => (
// TODO: add #[allow(unsafe_code)] when that's allowed
unsafe { $slice.slice_custom(|s| &s.$field) }
)
}
#[cfg(test)]
mod tests {
// TODO: restore these tests