mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
webgl: Implement Uniform1f, Uniform1fv, and Uniform4f
I was going to implement Uniform4fv with sequences, (since it practically implemented), but we can't until we support Float32Array args because codegen doesn't know how tu differenciate between both.
This commit is contained in:
parent
ee5aead60b
commit
532b53ddc9
4 changed files with 52 additions and 18 deletions
|
@ -157,8 +157,10 @@ impl WebGLPaintThread {
|
||||||
gl::bind_texture(target, id),
|
gl::bind_texture(target, id),
|
||||||
CanvasWebGLMsg::LinkProgram(program_id) =>
|
CanvasWebGLMsg::LinkProgram(program_id) =>
|
||||||
gl::link_program(program_id),
|
gl::link_program(program_id),
|
||||||
CanvasWebGLMsg::Uniform4fv(uniform_id, data) =>
|
CanvasWebGLMsg::Uniform1f(uniform_id, x) =>
|
||||||
gl::uniform_4f(uniform_id, data[0], data[1], data[2], data[3]),
|
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) =>
|
CanvasWebGLMsg::UseProgram(program_id) =>
|
||||||
gl::use_program(program_id),
|
gl::use_program(program_id),
|
||||||
CanvasWebGLMsg::VertexAttrib(attrib_id, x, y, z, w) =>
|
CanvasWebGLMsg::VertexAttrib(attrib_id, x, y, z, w) =>
|
||||||
|
|
|
@ -180,7 +180,8 @@ pub enum CanvasWebGLMsg {
|
||||||
LineWidth(f32),
|
LineWidth(f32),
|
||||||
PixelStorei(u32, i32),
|
PixelStorei(u32, i32),
|
||||||
LinkProgram(u32),
|
LinkProgram(u32),
|
||||||
Uniform4fv(i32, Vec<f32>),
|
Uniform1f(i32, f32),
|
||||||
|
Uniform4f(i32, f32, f32, f32, f32),
|
||||||
UseProgram(u32),
|
UseProgram(u32),
|
||||||
VertexAttrib(u32, f32, f32, f32, f32),
|
VertexAttrib(u32, f32, f32, f32, f32),
|
||||||
VertexAttribPointer2f(u32, i32, bool, i32, u32),
|
VertexAttribPointer2f(u32, i32, bool, i32, u32),
|
||||||
|
|
|
@ -930,30 +930,61 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
||||||
fn Uniform4fv(&self,
|
fn Uniform1f(&self,
|
||||||
_cx: *mut JSContext,
|
|
||||||
uniform: Option<&WebGLUniformLocation>,
|
uniform: Option<&WebGLUniformLocation>,
|
||||||
data: Option<*mut JSObject>) {
|
val: f32) {
|
||||||
let uniform_id = match uniform {
|
let uniform_id = match uniform {
|
||||||
Some(uniform) => uniform.id(),
|
Some(uniform) => uniform.id(),
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let data = match data {
|
self.ipc_renderer
|
||||||
Some(data) => data,
|
.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<f32>) {
|
||||||
|
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,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(data_vec) = array_buffer_view_to_vec_checked::<f32>(data) {
|
self.ipc_renderer
|
||||||
if data_vec.len() < 4 {
|
.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::<f32>(data) {
|
||||||
|
if data.len() < 4 {
|
||||||
return self.webgl_error(InvalidOperation);
|
return self.webgl_error(InvalidOperation);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.ipc_renderer
|
self.Uniform4f(uniform, data[0], data[1], data[2], data[3]);
|
||||||
.send(CanvasMsg::WebGL(CanvasWebGLMsg::Uniform4fv(uniform_id, data_vec)))
|
|
||||||
.unwrap()
|
|
||||||
} else {
|
} else {
|
||||||
self.webgl_error(InvalidValue);
|
self.webgl_error(InvalidValue);
|
||||||
}
|
}
|
||||||
|
|
|
@ -644,9 +644,9 @@ interface WebGLRenderingContextBase
|
||||||
//void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
|
//void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
|
||||||
// GLenum format, GLenum type, TexImageSource? source); // May throw DOMException
|
// 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, Float32Array v);
|
||||||
//void uniform1fv(WebGLUniformLocation? location, sequence<GLfloat> v);
|
void uniform1fv(WebGLUniformLocation? location, sequence<GLfloat> v);
|
||||||
//void uniform1i(WebGLUniformLocation? location, GLint x);
|
//void uniform1i(WebGLUniformLocation? location, GLint x);
|
||||||
//void uniform1iv(WebGLUniformLocation? location, Int32Array v);
|
//void uniform1iv(WebGLUniformLocation? location, Int32Array v);
|
||||||
//void uniform1iv(WebGLUniformLocation? location, sequence<long> v);
|
//void uniform1iv(WebGLUniformLocation? location, sequence<long> v);
|
||||||
|
@ -662,7 +662,7 @@ interface WebGLRenderingContextBase
|
||||||
//void uniform3i(WebGLUniformLocation? location, GLint x, GLint y, GLint z);
|
//void uniform3i(WebGLUniformLocation? location, GLint x, GLint y, GLint z);
|
||||||
//void uniform3iv(WebGLUniformLocation? location, Int32Array v);
|
//void uniform3iv(WebGLUniformLocation? location, Int32Array v);
|
||||||
//void uniform3iv(WebGLUniformLocation? location, sequence<long> v);
|
//void uniform3iv(WebGLUniformLocation? location, sequence<long> 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:
|
// 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'
|
// The Code genearator doesn't handle BufferDataSource so we're using 'optional object'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue