Simplify WebGLBuffer::buffer_data

There is no need to pass the target to that buffer method, given the buffer
has been retrieved by looking up the one bound to that target in the context.
This commit is contained in:
Anthony Ramine 2018-09-07 10:40:30 +02:00
parent 5a206d5137
commit 1293692ef8
2 changed files with 7 additions and 25 deletions

View file

@ -62,10 +62,7 @@ impl WebGLBuffer {
self.id
}
pub fn buffer_data<T>(&self, target: u32, data: T, usage: u32) -> WebGLResult<()>
where
T: Into<Vec<u8>>,
{
pub fn buffer_data(&self, data: Vec<u8>, usage: u32) -> WebGLResult<()> {
match usage {
WebGLRenderingContextConstants::STREAM_DRAW |
WebGLRenderingContextConstants::STATIC_DRAW |
@ -73,17 +70,11 @@ impl WebGLBuffer {
_ => 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.usage.set(usage);
self.upcast::<WebGLObject>()
.context()
.send_command(WebGLCommand::BufferData(target, data.into(), usage));
.send_command(WebGLCommand::BufferData(self.target.get().unwrap(), data.into(), usage));
Ok(())
}

View file

@ -1859,21 +1859,15 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
};
let bound_buffer = handle_potential_webgl_error!(self, self.bound_buffer(target), return);
let bound_buffer = match bound_buffer {
Some(bound_buffer) => bound_buffer,
None => return self.webgl_error(InvalidOperation),
};
let bound_buffer = handle_potential_webgl_error!(self, bound_buffer.ok_or(InvalidOperation), return);
handle_potential_webgl_error!(self, bound_buffer.buffer_data(target, data, usage));
handle_potential_webgl_error!(self, bound_buffer.buffer_data(data, usage));
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5
fn BufferData_(&self, target: u32, size: i64, usage: u32) {
let bound_buffer = handle_potential_webgl_error!(self, self.bound_buffer(target), return);
let bound_buffer = match bound_buffer {
Some(bound_buffer) => bound_buffer,
None => return self.webgl_error(InvalidOperation),
};
let bound_buffer = handle_potential_webgl_error!(self, bound_buffer.ok_or(InvalidOperation), return);
if size < 0 {
return self.webgl_error(InvalidValue);
@ -1882,7 +1876,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
// FIXME: Allocating a buffer based on user-requested size is
// not great, but we don't have a fallible allocation to try.
let data = vec![0u8; size as usize];
handle_potential_webgl_error!(self, bound_buffer.buffer_data(target, data, usage));
handle_potential_webgl_error!(self, bound_buffer.buffer_data(data, usage));
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5
@ -1894,10 +1888,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
};
let bound_buffer = handle_potential_webgl_error!(self, self.bound_buffer(target), return);
let bound_buffer = match bound_buffer {
Some(bound_buffer) => bound_buffer,
None => return self.webgl_error(InvalidOperation),
};
let bound_buffer = handle_potential_webgl_error!(self, bound_buffer.ok_or(InvalidOperation), return);
if offset < 0 {
return self.webgl_error(InvalidValue);