added bytes_to_u32_vec function using byteorder crate
This commit is contained in:
parent
6f4259ee36
commit
cf60417ecc
|
@ -7,6 +7,7 @@ authors = ["maik klein <maikklein@googlemail.com>"]
|
||||||
winit = "0.16"
|
winit = "0.16"
|
||||||
image = "0.10.4"
|
image = "0.10.4"
|
||||||
ash = { path = "../ash" }
|
ash = { path = "../ash" }
|
||||||
|
byteorder = "1.2.7"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
winapi = { version = "0.3.4", features = ["windef", "winuser"] }
|
winapi = { version = "0.3.4", features = ["windef", "winuser"] }
|
||||||
|
|
|
@ -549,19 +549,12 @@ fn main() {
|
||||||
.bytes()
|
.bytes()
|
||||||
.filter_map(|byte| byte.ok())
|
.filter_map(|byte| byte.ok())
|
||||||
.collect();
|
.collect();
|
||||||
let vertex_bytes = examples::bytes_to_u32_vec(vertex_bytes.iter().cloned());
|
let vertex_code = bytes_to_u32_vec(&vertex_bytes);
|
||||||
|
let vertex_shader_info = vk::ShaderModuleCreateInfo::builder().code(&vertex_code);
|
||||||
let vertex_shader_info = vk::ShaderModuleCreateInfo::builder()
|
|
||||||
.code(&vertex_bytes)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
let frag_bytes: Vec<u8> = frag_spv_file.bytes().filter_map(|byte| byte.ok()).collect();
|
let frag_bytes: Vec<u8> = frag_spv_file.bytes().filter_map(|byte| byte.ok()).collect();
|
||||||
|
let frag_code = bytes_to_u32_vec(&frag_bytes);
|
||||||
let frag_bytes = examples::bytes_to_u32_vec(frag_bytes.iter().cloned());
|
let frag_shader_info = vk::ShaderModuleCreateInfo::builder().code(&frag_code);
|
||||||
|
|
||||||
let frag_shader_info = vk::ShaderModuleCreateInfo::builder()
|
|
||||||
.code(&frag_bytes)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
let vertex_shader_module = base
|
let vertex_shader_module = base
|
||||||
.device
|
.device
|
||||||
|
|
|
@ -197,18 +197,14 @@ fn main() {
|
||||||
.bytes()
|
.bytes()
|
||||||
.filter_map(|byte| byte.ok())
|
.filter_map(|byte| byte.ok())
|
||||||
.collect();
|
.collect();
|
||||||
let vertex_bytes = examples::bytes_to_u32_vec(vertex_bytes.iter().cloned());
|
|
||||||
|
|
||||||
let vertex_shader_info = vk::ShaderModuleCreateInfo::builder()
|
let vertex_code = bytes_to_u32_vec(&vertex_bytes);
|
||||||
.code(&vertex_bytes)
|
|
||||||
.build();
|
let vertex_shader_info = vk::ShaderModuleCreateInfo::builder().code(&vertex_code);
|
||||||
|
|
||||||
let frag_bytes: Vec<u8> = frag_spv_file.bytes().filter_map(|byte| byte.ok()).collect();
|
let frag_bytes: Vec<u8> = frag_spv_file.bytes().filter_map(|byte| byte.ok()).collect();
|
||||||
let frag_bytes = examples::bytes_to_u32_vec(frag_bytes.iter().cloned());
|
let frag_code = bytes_to_u32_vec(&frag_bytes);
|
||||||
|
let frag_shader_info = vk::ShaderModuleCreateInfo::builder().code(&frag_code);
|
||||||
let frag_shader_info = vk::ShaderModuleCreateInfo::builder()
|
|
||||||
.code(&frag_bytes)
|
|
||||||
.build();
|
|
||||||
let vertex_shader_module = base
|
let vertex_shader_module = base
|
||||||
.device
|
.device
|
||||||
.create_shader_module(&vertex_shader_info, None)
|
.create_shader_module(&vertex_shader_info, None)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate ash;
|
extern crate ash;
|
||||||
|
extern crate byteorder;
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
extern crate winapi;
|
extern crate winapi;
|
||||||
|
|
||||||
|
@ -35,13 +36,32 @@ use ash::extensions::khr::Win32Surface;
|
||||||
use ash::extensions::mvk::MacOSSurface;
|
use ash::extensions::mvk::MacOSSurface;
|
||||||
pub use ash::version::{DeviceV1_0, EntryV1_0, InstanceV1_0};
|
pub use ash::version::{DeviceV1_0, EntryV1_0, InstanceV1_0};
|
||||||
use ash::{vk, Device, Entry, Instance};
|
use ash::{vk, Device, Entry, Instance};
|
||||||
|
use byteorder::{LittleEndian, ReadBytesExt};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::ffi::{CStr, CString};
|
use std::ffi::{CStr, CString};
|
||||||
|
use std::io::Cursor;
|
||||||
use std::ops::Drop;
|
use std::ops::Drop;
|
||||||
use std::os::raw::{c_char, c_void};
|
use std::os::raw::{c_char, c_void};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
|
pub fn bytes_to_u32_vec(bytes: &[u8]) -> Vec<u32> {
|
||||||
|
let mut output = vec![];
|
||||||
|
let mut buffer: [u8; 4] = [0, 0, 0, 0];
|
||||||
|
for (i, b) in bytes.iter().enumerate() {
|
||||||
|
let idx = i % 4;
|
||||||
|
buffer[idx] = *b;
|
||||||
|
if idx == 3 {
|
||||||
|
output.push(Cursor::new(buffer).read_u32::<LittleEndian>().unwrap());
|
||||||
|
buffer = [0, 0, 0, 0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if bytes.len() % 4 != 0 {
|
||||||
|
output.push(Cursor::new(buffer).read_u32::<LittleEndian>().unwrap());
|
||||||
|
}
|
||||||
|
output
|
||||||
|
}
|
||||||
|
|
||||||
// Simple offset_of macro akin to C++ offsetof
|
// Simple offset_of macro akin to C++ offsetof
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! offset_of {
|
macro_rules! offset_of {
|
||||||
|
|
Loading…
Reference in a new issue