diff --git a/components/canvas/webgl_paint_thread.rs b/components/canvas/webgl_paint_thread.rs index 084ce49d491..84d4906aa85 100644 --- a/components/canvas/webgl_paint_thread.rs +++ b/components/canvas/webgl_paint_thread.rs @@ -157,8 +157,10 @@ impl WebGLPaintThread { gl::bind_texture(target, id), CanvasWebGLMsg::LinkProgram(program_id) => gl::link_program(program_id), - CanvasWebGLMsg::Uniform4fv(uniform_id, data) => - gl::uniform_4f(uniform_id, data[0], data[1], data[2], data[3]), + CanvasWebGLMsg::Uniform1f(uniform_id, x) => + gl::uniform_1f(uniform_id, x), + CanvasWebGLMsg::Uniform4f(uniform_id, x, y, z, w) => + gl::uniform_4f(uniform_id, x, y, z, w), CanvasWebGLMsg::UseProgram(program_id) => gl::use_program(program_id), CanvasWebGLMsg::VertexAttrib(attrib_id, x, y, z, w) => diff --git a/components/canvas_traits/lib.rs b/components/canvas_traits/lib.rs index 90ff7d0daac..bba0db60234 100644 --- a/components/canvas_traits/lib.rs +++ b/components/canvas_traits/lib.rs @@ -180,7 +180,8 @@ pub enum CanvasWebGLMsg { LineWidth(f32), PixelStorei(u32, i32), LinkProgram(u32), - Uniform4fv(i32, Vec), + Uniform1f(i32, f32), + Uniform4f(i32, f32, f32, f32, f32), UseProgram(u32), VertexAttrib(u32, f32, f32, f32, f32), VertexAttribPointer2f(u32, i32, bool, i32, u32), diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 7481b161a77..701ae737ba8 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -930,30 +930,61 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } } - #[allow(unsafe_code)] // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - fn Uniform4fv(&self, - _cx: *mut JSContext, + fn Uniform1f(&self, uniform: Option<&WebGLUniformLocation>, - data: Option<*mut JSObject>) { + val: f32) { let uniform_id = match uniform { Some(uniform) => uniform.id(), None => return, }; - let data = match data { - Some(data) => data, + self.ipc_renderer + .send(CanvasMsg::WebGL(CanvasWebGLMsg::Uniform1f(uniform_id, val))) + .unwrap() + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn Uniform1fv(&self, + uniform: Option<&WebGLUniformLocation>, + data: Vec) { + if data.is_empty() { + return self.webgl_error(InvalidValue); + } + + self.Uniform1f(uniform, data[0]); + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn Uniform4f(&self, + uniform: Option<&WebGLUniformLocation>, + x: f32, y: f32, z: f32, w: f32) { + let uniform_id = match uniform { + Some(uniform) => uniform.id(), None => return, }; - if let Some(data_vec) = array_buffer_view_to_vec_checked::(data) { - if data_vec.len() < 4 { + self.ipc_renderer + .send(CanvasMsg::WebGL(CanvasWebGLMsg::Uniform4f(uniform_id, x, y, z, w))) + .unwrap() + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn Uniform4fv(&self, + _cx: *mut JSContext, + uniform: Option<&WebGLUniformLocation>, + data: Option<*mut JSObject>) { + let data = match data { + Some(data) => data, + None => return self.webgl_error(InvalidValue), + }; + + if let Some(data) = array_buffer_view_to_vec_checked::(data) { + if data.len() < 4 { return self.webgl_error(InvalidOperation); } - self.ipc_renderer - .send(CanvasMsg::WebGL(CanvasWebGLMsg::Uniform4fv(uniform_id, data_vec))) - .unwrap() + self.Uniform4f(uniform, data[0], data[1], data[2], data[3]); } else { self.webgl_error(InvalidValue); } diff --git a/components/script/dom/webidls/WebGLRenderingContext.webidl b/components/script/dom/webidls/WebGLRenderingContext.webidl index c2c82b5ff17..37e1e5fe81d 100644 --- a/components/script/dom/webidls/WebGLRenderingContext.webidl +++ b/components/script/dom/webidls/WebGLRenderingContext.webidl @@ -644,9 +644,9 @@ interface WebGLRenderingContextBase //void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, // GLenum format, GLenum type, TexImageSource? source); // May throw DOMException - //void uniform1f(WebGLUniformLocation? location, GLfloat x); + void uniform1f(WebGLUniformLocation? location, GLfloat x); //void uniform1fv(WebGLUniformLocation? location, Float32Array v); - //void uniform1fv(WebGLUniformLocation? location, sequence v); + void uniform1fv(WebGLUniformLocation? location, sequence v); //void uniform1i(WebGLUniformLocation? location, GLint x); //void uniform1iv(WebGLUniformLocation? location, Int32Array v); //void uniform1iv(WebGLUniformLocation? location, sequence v); @@ -662,9 +662,9 @@ interface WebGLRenderingContextBase //void uniform3i(WebGLUniformLocation? location, GLint x, GLint y, GLint z); //void uniform3iv(WebGLUniformLocation? location, Int32Array v); //void uniform3iv(WebGLUniformLocation? location, sequence v); - //void uniform4f(WebGLUniformLocation? location, GLfloat x, GLfloat y, GLfloat z, GLfloat w); + void uniform4f(WebGLUniformLocation? location, GLfloat x, GLfloat y, GLfloat z, GLfloat w); // FIXME(dmarcos) The function below is the original function in the webIdl: - // void uniform4fv(WebGLUniformLocation? location, Float32Array v); + //void uniform4fv(WebGLUniformLocation? location, Float32Array v); // The Code genearator doesn't handle BufferDataSource so we're using 'optional object' // in the meantime void uniform4fv(WebGLUniformLocation? location, optional object v);