Issue #8462: Add support for BufferSubData, CompressedTexImage2D and

CompressedSubTexImage2D and re-enable individual webgl WPT tests.
This commit is contained in:
Simon Martin 2015-11-14 12:21:47 +01:00
parent 3720e4d5ef
commit f79e1521b2
7 changed files with 84 additions and 19 deletions

View file

@ -72,6 +72,8 @@ impl WebGLPaintTask {
gl::attach_shader(program_id, shader_id),
CanvasWebGLMsg::BufferData(buffer_type, data, usage) =>
gl::buffer_data(buffer_type, &data, usage),
CanvasWebGLMsg::BufferSubData(buffer_type, offset, data) =>
gl::buffer_sub_data(buffer_type, offset, &data),
CanvasWebGLMsg::Clear(mask) =>
gl::clear(mask),
CanvasWebGLMsg::ClearColor(r, g, b, a) =>

View file

@ -128,6 +128,7 @@ pub enum CanvasWebGLMsg {
BlendFuncSeparate(u32, u32, u32, u32),
AttachShader(u32, u32),
BufferData(u32, Vec<f32>, u32),
BufferSubData(u32, isize, Vec<f32>),
Clear(u32),
ClearColor(f32, f32, f32, f32),
ClearDepth(f64),

View file

@ -378,16 +378,27 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
#[allow(unsafe_code)]
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5
fn BufferData(&self, _cx: *mut JSContext, target: u32, data: Option<*mut JSObject>, usage: u32) {
match target {
constants::ARRAY_BUFFER |
constants::ELEMENT_ARRAY_BUFFER => (),
_ => return self.webgl_error(InvalidEnum),
}
match usage {
constants::STREAM_DRAW |
constants::STATIC_DRAW |
constants::DYNAMIC_DRAW => (),
_ => return self.webgl_error(InvalidEnum),
}
let data = match data {
Some(data) => data,
None => return,
None => return self.webgl_error(InvalidValue),
};
let data_vec = unsafe {
let mut length = 0;
let mut ptr = ptr::null_mut();
let buffer_data = JS_GetObjectAsArrayBufferView(data, &mut length, &mut ptr);
if buffer_data.is_null() {
panic!("Argument data to WebGLRenderingContext.bufferdata is not a Float32Array")
return self.webgl_error(InvalidValue) // https://github.com/servo/servo/issues/5014
}
let data_f32 = JS_GetFloat32ArrayData(buffer_data, ptr::null());
let data_vec_length = length / mem::size_of::<f32>() as u32;
@ -398,6 +409,56 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
.unwrap()
}
#[allow(unsafe_code)]
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5
fn BufferSubData(&self, _cx: *mut JSContext, target: u32, offset: i64, data: Option<*mut JSObject>) {
match target {
constants::ARRAY_BUFFER |
constants::ELEMENT_ARRAY_BUFFER => (),
_ => return self.webgl_error(InvalidEnum),
}
let data = match data {
Some(data) => data,
None => return,
};
if offset < 0 {
return self.webgl_error(InvalidValue);
}
let data_vec = unsafe {
let mut length = 0;
let mut ptr = ptr::null_mut();
let buffer_data = JS_GetObjectAsArrayBufferView(data, &mut length, &mut ptr);
if buffer_data.is_null() {
return self.webgl_error(InvalidValue) // https://github.com/servo/servo/issues/5014
}
let data_f32 = JS_GetFloat32ArrayData(buffer_data, ptr::null());
let data_vec_length = length / mem::size_of::<f32>() as u32;
slice::from_raw_parts(data_f32, data_vec_length as usize).to_vec()
};
// FIXME(simartin) Check that the defined region is inside the allocated one
// https://github.com/servo/servo/issues/8738
self.ipc_renderer
.send(CanvasMsg::WebGL(CanvasWebGLMsg::BufferSubData(target, offset as isize, data_vec)))
.unwrap()
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
fn CompressedTexImage2D(&self, _cx: *mut JSContext, _target: u32, _level: i32, _internal_format: u32,
_width: i32, _height: i32, _border: i32, _pixels: *mut JSObject) {
// FIXME: No compressed texture format is currently supported, so error out as per
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#COMPRESSED_TEXTURE_SUPPORT
self.webgl_error(InvalidEnum)
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
fn CompressedTexSubImage2D(&self, _cx: *mut JSContext, _target: u32, _level: i32,
_xoffset: i32, _yoffset: i32, _width: i32, _height: i32,
_format: u32, _pixels: *mut JSObject) {
// FIXME: No compressed texture format is currently supported, so error out as per
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#COMPRESSED_TEXTURE_SUPPORT
self.webgl_error(InvalidEnum)
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.11
fn Clear(&self, mask: u32) {
self.ipc_renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::Clear(mask))).unwrap();

View file

@ -492,10 +492,11 @@ interface WebGLRenderingContextBase
//void bufferData(GLenum target, GLsizeiptr size, GLenum usage);
// FIXME(dmarcos) The function below is the original function in the webIdl:
// void bufferData(GLenum target, BufferDataSource? data, GLenum usage);
// The Code genearator doesn't handle BufferDataSource so we're using 'optional object'
// The Code generator doesn't handle BufferDataSource so we're using 'optional object'
// in the meantime
void bufferData(GLenum target, optional object data, GLenum usage);
//void bufferSubData(GLenum target, GLintptr offset, BufferDataSource? data);
void bufferSubData(GLenum target, GLintptr offset, optional object data);
//[WebGLHandlesContextLoss] GLenum checkFramebufferStatus(GLenum target);
void clear(GLbitfield mask);
@ -505,13 +506,22 @@ interface WebGLRenderingContextBase
void colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
void compileShader(WebGLShader? shader);
//void compressedTexImage2D(GLenum target, GLint level, GLenum internalformat,
// FIXME(simartin) The Code generator doesn't handle ArrayBufferView so we're
// using 'object' in the meantime
// void compressedTexImage2D(GLenum target, GLint level, GLenum internalformat,
// GLsizei width, GLsizei height, GLint border,
// ArrayBufferView data);
//void compressedTexSubImage2D(GLenum target, GLint level,
void compressedTexImage2D(GLenum target, GLint level, GLenum internalformat,
GLsizei width, GLsizei height, GLint border,
object data);
// void compressedTexSubImage2D(GLenum target, GLint level,
// GLint xoffset, GLint yoffset,
// GLsizei width, GLsizei height, GLenum format,
// ArrayBufferView data);
void compressedTexSubImage2D(GLenum target, GLint level,
GLint xoffset, GLint yoffset,
GLsizei width, GLsizei height, GLenum format,
object data);
//void copyTexImage2D(GLenum target, GLint level, GLenum internalformat,
// GLint x, GLint y, GLsizei width, GLsizei height,

View file

@ -1,3 +0,0 @@
[bufferSubData.html]
type: testharness
disabled: https://github.com/servo/servo/issues/8462

View file

@ -1,3 +0,0 @@
[compressedTexImage2D.html]
type: testharness
disabled: https://github.com/servo/servo/issues/8462

View file

@ -1,3 +0,0 @@
[compressedTexSubImage2D.html]
type: testharness
disabled: https://github.com/servo/servo/issues/8462