mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Improve WebGLBuffer::buffer_data
It now checks the usage argument itself and use generics for the data vector.
This commit is contained in:
parent
34b13dac66
commit
605da95076
2 changed files with 16 additions and 24 deletions
|
@ -7,6 +7,7 @@ use canvas_traits::webgl::{WebGLBufferId, WebGLCommand, WebGLError, WebGLMsgSend
|
|||
use canvas_traits::webgl::webgl_channel;
|
||||
use dom::bindings::cell::DomRefCell;
|
||||
use dom::bindings::codegen::Bindings::WebGLBufferBinding;
|
||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants;
|
||||
use dom::bindings::reflector::reflect_dom_object;
|
||||
use dom::bindings::root::DomRoot;
|
||||
use dom::webglobject::WebGLObject;
|
||||
|
@ -86,18 +87,25 @@ impl WebGLBuffer {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn buffer_data(&self, target: u32, data: &[u8], usage: u32) -> WebGLResult<()> {
|
||||
pub fn buffer_data<T>(&self, target: u32, data: T, usage: u32) -> WebGLResult<()>
|
||||
where
|
||||
T: Into<Vec<u8>>,
|
||||
{
|
||||
match usage {
|
||||
WebGLRenderingContextConstants::STREAM_DRAW |
|
||||
WebGLRenderingContextConstants::STATIC_DRAW |
|
||||
WebGLRenderingContextConstants::DYNAMIC_DRAW => (),
|
||||
_ => return Err(WebGLError::InvalidEnum),
|
||||
}
|
||||
|
||||
if let Some(previous_target) = self.target.get() {
|
||||
if target != previous_target {
|
||||
return Err(WebGLError::InvalidOperation);
|
||||
}
|
||||
}
|
||||
let data = data.into();
|
||||
self.capacity.set(data.len());
|
||||
self.renderer.send(WebGLCommand::BufferData(
|
||||
target,
|
||||
data.to_vec().into(),
|
||||
usage,
|
||||
)).unwrap();
|
||||
self.renderer.send(WebGLCommand::BufferData(target, data.into(), usage)).unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue