Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Cache BUFFER_USAGE value on the DOM side
  • Loading branch information
nox committed Apr 4, 2018
1 parent e06f0d3 commit ae286a5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 31 deletions.
11 changes: 0 additions & 11 deletions components/canvas/webgl_thread.rs
Expand Up @@ -758,8 +758,6 @@ impl WebGLImpl {
Self::vertex_attrib(ctx.gl(), index, pname, chan),
WebGLCommand::GetVertexAttribOffset(index, pname, chan) =>
Self::vertex_attrib_offset(ctx.gl(), index, pname, chan),
WebGLCommand::GetBufferParameter(target, param_id, chan) =>
Self::buffer_parameter(ctx.gl(), target, param_id, chan),
WebGLCommand::GetParameter(param_id, chan) =>
Self::parameter(ctx.gl(), param_id, chan),
WebGLCommand::GetTexParameter(target, pname, chan) =>
Expand Down Expand Up @@ -1127,15 +1125,6 @@ impl WebGLImpl {
chan.send(result).unwrap();
}

fn buffer_parameter(gl: &gl::Gl,
target: u32,
param_id: u32,
chan: WebGLSender<i32>) {
let result = gl.get_buffer_parameter_iv(target, param_id);

chan.send(result).unwrap();
}

fn program_parameter(gl: &gl::Gl,
program_id: WebGLProgramId,
param_id: u32,
Expand Down
2 changes: 0 additions & 2 deletions components/canvas_traits/webgl.rs
Expand Up @@ -205,7 +205,6 @@ pub enum WebGLCommand {
EnableVertexAttribArray(u32),
FramebufferRenderbuffer(u32, u32, u32, Option<WebGLRenderbufferId>),
FramebufferTexture2D(u32, u32, u32, Option<WebGLTextureId>, i32),
GetBufferParameter(u32, u32, WebGLSender<i32>),
GetExtensions(WebGLSender<String>),
GetParameter(u32, WebGLSender<WebGLResult<WebGLParameter>>),
GetTexParameter(u32, u32, WebGLSender<i32>),
Expand Down Expand Up @@ -479,7 +478,6 @@ impl fmt::Debug for WebGLCommand {
EnableVertexAttribArray(..) => "EnableVertexAttribArray",
FramebufferRenderbuffer(..) => "FramebufferRenderbuffer",
FramebufferTexture2D(..) => "FramebufferTexture2D",
GetBufferParameter(..) => "GetBufferParameter",
GetExtensions(..) => "GetExtensions",
GetParameter(..) => "GetParameter",
GetTexParameter(..) => "GetTexParameter",
Expand Down
8 changes: 8 additions & 0 deletions components/script/dom/webglbuffer.rs
Expand Up @@ -30,6 +30,8 @@ pub struct WebGLBuffer {
pending_delete: Cell<bool>,
#[ignore_malloc_size_of = "Defined in ipc-channel"]
renderer: WebGLMsgSender,
/// https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glGetBufferParameteriv.xml
usage: Cell<u32>,
}

impl WebGLBuffer {
Expand All @@ -45,6 +47,7 @@ impl WebGLBuffer {
vao_references: DomRefCell::new(None),
pending_delete: Cell::new(false),
renderer: renderer,
usage: Cell::new(WebGLRenderingContextConstants::STATIC_DRAW),
}
}

Expand Down Expand Up @@ -105,6 +108,7 @@ impl WebGLBuffer {
}
let data = data.into();
self.capacity.set(data.len());
self.usage.set(usage);
self.renderer.send(WebGLCommand::BufferData(target, data.into(), usage)).unwrap();

Ok(())
Expand Down Expand Up @@ -158,6 +162,10 @@ impl WebGLBuffer {
}
}
}

pub fn usage(&self) -> u32 {
self.usage.get()
}
}

impl Drop for WebGLBuffer {
Expand Down
26 changes: 8 additions & 18 deletions components/script/dom/webglrenderingcontext.rs
Expand Up @@ -1250,30 +1250,20 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
target: u32,
parameter: u32,
) -> JSVal {
let buffer = handle_potential_webgl_error!(self, self.bound_buffer(target), return NullValue());
let buffer = handle_potential_webgl_error!(
self,
self.bound_buffer(target).and_then(|buf| buf.ok_or(InvalidOperation)),
return NullValue()
);

match parameter {
constants::BUFFER_SIZE | constants::BUFFER_USAGE => {},
constants::BUFFER_SIZE => Int32Value(buffer.capacity() as i32),
constants::BUFFER_USAGE => Int32Value(buffer.usage() as i32),
_ => {
self.webgl_error(InvalidEnum);
return NullValue();
}
}
let buffer = match buffer {
Some(buffer) => buffer,
None => {
self.webgl_error(InvalidOperation);
return NullValue();
NullValue()
}
};

if parameter == constants::BUFFER_SIZE {
return Int32Value(buffer.capacity() as i32);
}

let (sender, receiver) = webgl_channel().unwrap();
self.send_command(WebGLCommand::GetBufferParameter(target, parameter, sender));
Int32Value(receiver.recv().unwrap())
}

#[allow(unsafe_code)]
Expand Down

0 comments on commit ae286a5

Please sign in to comment.