aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webglbuffer.rs
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2018-04-04 12:42:38 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2018-04-04 13:12:39 +0200
commit605da950766f1fbe9200b5780b3b58296daaa50a (patch)
tree0ede324970291c195c6c0f51294274abe6213995 /components/script/dom/webglbuffer.rs
parent34b13dac66b48790003ccd069f4636f1def77e7d (diff)
downloadservo-605da950766f1fbe9200b5780b3b58296daaa50a.tar.gz
servo-605da950766f1fbe9200b5780b3b58296daaa50a.zip
Improve WebGLBuffer::buffer_data
It now checks the usage argument itself and use generics for the data vector.
Diffstat (limited to 'components/script/dom/webglbuffer.rs')
-rw-r--r--components/script/dom/webglbuffer.rs20
1 files changed, 14 insertions, 6 deletions
diff --git a/components/script/dom/webglbuffer.rs b/components/script/dom/webglbuffer.rs
index 4bb7959f8dd..5f00c7f45cc 100644
--- a/components/script/dom/webglbuffer.rs
+++ b/components/script/dom/webglbuffer.rs
@@ -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(())
}