From c9ae10a8a9efebda1cf3ef8b1bdd11746bd1f49c Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Wed, 3 Jun 2020 11:15:58 -0700 Subject: [PATCH] make mesh byte conversion zero-copy again --- crates/bevy_render/src/mesh.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/bevy_render/src/mesh.rs b/crates/bevy_render/src/mesh.rs index 3828896ac3..9195c81868 100644 --- a/crates/bevy_render/src/mesh.rs +++ b/crates/bevy_render/src/mesh.rs @@ -8,11 +8,11 @@ use crate::{ shader::AsUniforms, Renderable, Vertex, }; -use bevy_app::{GetEventReader, Events}; +use bevy_app::{Events, GetEventReader}; use bevy_asset::{AssetEvent, Assets, Handle}; +use bevy_core::bytes::AsBytes; use glam::*; use legion::prelude::*; -use bevy_core::bytes::{Byteable, AsBytes}; use std::{borrow::Cow, collections::HashSet}; use thiserror::Error; @@ -37,13 +37,12 @@ impl VertexAttributeValues { } // TODO: add vertex format as parameter here and perform type conversions - // TODO: make this zero-copy if possible. how did zerocopy implement AsBytes for Vec? - pub fn get_bytes(&self) -> Vec { + pub fn get_bytes(&self) -> &[u8] { match self { - VertexAttributeValues::Float(values) => values.as_slice().as_bytes().to_vec(), - VertexAttributeValues::Float2(values) => values.as_slice().as_bytes().to_vec(), - VertexAttributeValues::Float3(values) => values.as_slice().as_bytes().to_vec(), - VertexAttributeValues::Float4(values) => values.as_slice().as_bytes().to_vec(), + VertexAttributeValues::Float(values) => values.as_slice().as_bytes(), + VertexAttributeValues::Float2(values) => values.as_slice().as_bytes(), + VertexAttributeValues::Float3(values) => values.as_slice().as_bytes(), + VertexAttributeValues::Float4(values) => values.as_slice().as_bytes(), } } }