mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Implement checks for vertex attribs enabled as arrays without a bound buffer
This commit is contained in:
parent
440e855c33
commit
fc3dd7cefc
9 changed files with 94 additions and 114 deletions
|
@ -13,7 +13,6 @@ use dom_struct::dom_struct;
|
|||
use js::conversions::ToJSValConvertible;
|
||||
use js::jsapi::JSContext;
|
||||
use js::jsval::{JSVal, NullValue};
|
||||
use std::iter;
|
||||
use super::{WebGLExtension, WebGLExtensions, WebGLExtensionSpec};
|
||||
|
||||
#[dom_struct]
|
||||
|
@ -70,9 +69,10 @@ impl OESVertexArrayObjectMethods for OESVertexArrayObject {
|
|||
}
|
||||
|
||||
// Remove VAO references from buffers
|
||||
let buffers = vao.bound_attrib_buffers();
|
||||
for buffer in buffers {
|
||||
buffer.remove_vao_reference(vao.id());
|
||||
for (_, &(_, ref buffer)) in vao.bound_attrib_buffers().borrow().iter() {
|
||||
if let Some(ref buffer) = *buffer {
|
||||
buffer.remove_vao_reference(vao.id());
|
||||
}
|
||||
}
|
||||
if let Some(buffer) = vao.bound_buffer_element_array() {
|
||||
buffer.remove_vao_reference(vao.id());
|
||||
|
@ -94,11 +94,12 @@ impl OESVertexArrayObjectMethods for OESVertexArrayObject {
|
|||
fn BindVertexArrayOES(&self, vao: Option<&WebGLVertexArrayObjectOES>) {
|
||||
if let Some(bound_vao) = self.bound_vao.get() {
|
||||
// Store buffers attached to attrib pointers
|
||||
let buffers = self.ctx.borrow_bound_attrib_buffers();
|
||||
bound_vao.set_bound_attrib_buffers(buffers.iter().map(|(key, buffer)| {
|
||||
(*buffer).add_vao_reference(bound_vao.id());
|
||||
(*key, &**buffer)
|
||||
}));
|
||||
bound_vao.bound_attrib_buffers().set_from(&self.ctx.bound_attrib_buffers());
|
||||
for (_, (_, ref buffer)) in bound_vao.bound_attrib_buffers().borrow().iter() {
|
||||
if let Some(ref buffer) = *buffer {
|
||||
buffer.add_vao_reference(bound_vao.id());
|
||||
}
|
||||
}
|
||||
// Store element array buffer
|
||||
let element_array = self.ctx.bound_buffer_element_array();
|
||||
bound_vao.set_bound_buffer_element_array(element_array.as_ref().map(|buffer| {
|
||||
|
@ -118,14 +119,13 @@ impl OESVertexArrayObjectMethods for OESVertexArrayObject {
|
|||
self.bound_vao.set(Some(&vao));
|
||||
|
||||
// Restore WebGLRenderingContext current bindings
|
||||
let buffers = vao.borrow_bound_attrib_buffers();
|
||||
self.ctx.set_bound_attrib_buffers(buffers.iter().map(|(k, v)| (*k, &**v)));
|
||||
self.ctx.bound_attrib_buffers().set_from(&vao.bound_attrib_buffers());
|
||||
let element_array = vao.bound_buffer_element_array();
|
||||
self.ctx.set_bound_buffer_element_array(element_array.as_ref().map(|buffer| &**buffer));
|
||||
} else {
|
||||
self.ctx.send_command(WebGLCommand::BindVertexArray(None));
|
||||
self.bound_vao.set(None);
|
||||
self.ctx.set_bound_attrib_buffers(iter::empty());
|
||||
self.ctx.bound_attrib_buffers().clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,11 +57,11 @@ use js::typedarray::ArrayBufferView;
|
|||
use net_traits::image::base::PixelFormat;
|
||||
use net_traits::image_cache::ImageResponse;
|
||||
use offscreen_gl_context::{GLContextAttributes, GLLimits};
|
||||
use ref_filter_map::ref_filter_map;
|
||||
use script_layout_interface::HTMLCanvasDataSource;
|
||||
use servo_config::prefs::PREFS;
|
||||
use std::cell::{Cell, Ref};
|
||||
use std::cmp;
|
||||
use std::iter::FromIterator;
|
||||
use std::ptr::NonNull;
|
||||
use webrender_api;
|
||||
|
||||
|
@ -192,7 +192,7 @@ pub struct WebGLRenderingContext {
|
|||
bound_texture_unit: Cell<u32>,
|
||||
bound_buffer_array: MutNullableDom<WebGLBuffer>,
|
||||
bound_buffer_element_array: MutNullableDom<WebGLBuffer>,
|
||||
bound_attrib_buffers: DomRefCell<FnvHashMap<u32, Dom<WebGLBuffer>>>,
|
||||
bound_attrib_buffers: BoundAttribBuffers,
|
||||
current_program: MutNullableDom<WebGLProgram>,
|
||||
#[ignore_malloc_size_of = "Because it's small"]
|
||||
current_vertex_attrib_0: Cell<(f32, f32, f32, f32)>,
|
||||
|
@ -243,7 +243,7 @@ impl WebGLRenderingContext {
|
|||
bound_texture_unit: Cell::new(constants::TEXTURE0),
|
||||
bound_buffer_array: MutNullableDom::new(None),
|
||||
bound_buffer_element_array: MutNullableDom::new(None),
|
||||
bound_attrib_buffers: DomRefCell::new(Default::default()),
|
||||
bound_attrib_buffers: Default::default(),
|
||||
bound_renderbuffer: MutNullableDom::new(None),
|
||||
current_program: MutNullableDom::new(None),
|
||||
current_vertex_attrib_0: Cell::new((0f32, 0f32, 0f32, 1f32)),
|
||||
|
@ -311,12 +311,8 @@ impl WebGLRenderingContext {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn borrow_bound_attrib_buffers(&self) -> Ref<FnvHashMap<u32, Dom<WebGLBuffer>>> {
|
||||
self.bound_attrib_buffers.borrow()
|
||||
}
|
||||
|
||||
pub fn set_bound_attrib_buffers<'a, T>(&self, iter: T) where T: Iterator<Item=(u32, &'a WebGLBuffer)> {
|
||||
*self.bound_attrib_buffers.borrow_mut() = FnvHashMap::from_iter(iter.map(|(k,v)| (k, Dom::from_ref(v))));
|
||||
pub fn bound_attrib_buffers(&self) -> &BoundAttribBuffers {
|
||||
&self.bound_attrib_buffers
|
||||
}
|
||||
|
||||
pub fn bound_buffer_element_array(&self) -> Option<DomRoot<WebGLBuffer>> {
|
||||
|
@ -2079,13 +2075,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
|||
}
|
||||
|
||||
// Remove deleted buffer from bound attrib buffers.
|
||||
let attrib_ids: Vec<_> = self.bound_attrib_buffers.borrow().iter()
|
||||
.filter(|&(_, v)| v.id() == buffer.id())
|
||||
.map(|(&k, _)| k)
|
||||
.collect();
|
||||
for id in attrib_ids {
|
||||
self.bound_attrib_buffers.borrow_mut().remove(&id);
|
||||
}
|
||||
self.bound_attrib_buffers.remove_buffer(buffer);
|
||||
|
||||
// Delete buffer.
|
||||
handle_object_deletion!(self, self.bound_buffer_array, buffer,
|
||||
|
@ -2211,6 +2201,15 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
|||
return self.webgl_error(InvalidOperation);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#6.2
|
||||
let buffers = self.bound_attrib_buffers.borrow();
|
||||
if buffers.iter().any(|(_, &(enabled, ref buffer))| enabled && buffer.is_none()) {
|
||||
return self.webgl_error(InvalidOperation);
|
||||
}
|
||||
}
|
||||
|
||||
if !self.validate_framebuffer_complete() {
|
||||
return;
|
||||
}
|
||||
|
@ -2278,6 +2277,14 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#6.2
|
||||
let buffers = self.bound_attrib_buffers.borrow();
|
||||
if buffers.iter().any(|(_, &(enabled, ref buffer))| enabled && buffer.is_none()) {
|
||||
return self.webgl_error(InvalidOperation);
|
||||
}
|
||||
}
|
||||
|
||||
if !self.validate_framebuffer_complete() {
|
||||
return;
|
||||
}
|
||||
|
@ -2292,6 +2299,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
|||
return self.webgl_error(InvalidValue);
|
||||
}
|
||||
|
||||
self.bound_attrib_buffers.enabled(attrib_id, true);
|
||||
self.send_command(WebGLCommand::EnableVertexAttribArray(attrib_id));
|
||||
}
|
||||
|
||||
|
@ -2301,6 +2309,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
|||
return self.webgl_error(InvalidValue);
|
||||
}
|
||||
|
||||
self.bound_attrib_buffers.enabled(attrib_id, false);
|
||||
self.send_command(WebGLCommand::DisableVertexAttribArray(attrib_id));
|
||||
}
|
||||
|
||||
|
@ -2563,7 +2572,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
|||
|
||||
if param == constants::VERTEX_ATTRIB_ARRAY_BUFFER_BINDING {
|
||||
rooted!(in(cx) let mut jsval = NullValue());
|
||||
if let Some(buffer) = self.bound_attrib_buffers.borrow().get(&index) {
|
||||
if let Some(buffer) = self.bound_attrib_buffers.get(index) {
|
||||
buffer.to_jsval(cx, jsval.handle_mut());
|
||||
}
|
||||
return jsval.get();
|
||||
|
@ -3329,7 +3338,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
|||
|
||||
}
|
||||
|
||||
self.bound_attrib_buffers.borrow_mut().insert(attrib_id, Dom::from_ref(&*buffer_array));
|
||||
self.bound_attrib_buffers.bind_buffer(attrib_id, &buffer_array);
|
||||
|
||||
let msg = WebGLCommand::VertexAttribPointer(attrib_id, size, data_type, normalized, stride, offset as u32);
|
||||
self.send_command(msg);
|
||||
|
@ -3766,3 +3775,49 @@ impl UniformSetterType {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, JSTraceable, MallocSizeOf)]
|
||||
#[must_root]
|
||||
pub struct BoundAttribBuffers {
|
||||
elements: DomRefCell<FnvHashMap<u32, (bool, Option<Dom<WebGLBuffer>>)>>,
|
||||
}
|
||||
|
||||
impl BoundAttribBuffers {
|
||||
pub fn clear(&self) {
|
||||
self.elements.borrow_mut().clear()
|
||||
}
|
||||
|
||||
pub fn set_from(&self, other: &BoundAttribBuffers) {
|
||||
*self.elements.borrow_mut() = other.elements.borrow().clone();
|
||||
}
|
||||
|
||||
pub fn borrow(&self) -> Ref<FnvHashMap<u32, (bool, Option<Dom<WebGLBuffer>>)>> {
|
||||
self.elements.borrow()
|
||||
}
|
||||
|
||||
fn remove_buffer(&self, buffer: &WebGLBuffer) {
|
||||
self.elements.borrow_mut().retain(|_, v| {
|
||||
v.1.as_ref().map_or(true, |b| b.id() != buffer.id())
|
||||
})
|
||||
}
|
||||
|
||||
fn get(&self, index: u32) -> Option<Ref<WebGLBuffer>> {
|
||||
ref_filter_map(self.elements.borrow(), |elements| {
|
||||
elements.get(&index).and_then(|&(_, ref buffer)| {
|
||||
buffer.as_ref().map(|b| &**b)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn enabled(&self, index: u32, value: bool) {
|
||||
let mut elements = self.elements.borrow_mut();
|
||||
let pair = elements.entry(index).or_insert((false, None));
|
||||
pair.0 = value;
|
||||
}
|
||||
|
||||
fn bind_buffer(&self, index: u32, buffer: &WebGLBuffer) {
|
||||
let mut elements = self.elements.borrow_mut();
|
||||
let pair = elements.entry(index).or_insert((false, None));
|
||||
pair.1 = Some(Dom::from_ref(buffer));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,17 +3,15 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use canvas_traits::webgl::WebGLVertexArrayId;
|
||||
use dom::bindings::cell::DomRefCell;
|
||||
use dom::bindings::codegen::Bindings::WebGLVertexArrayObjectOESBinding;
|
||||
use dom::bindings::reflector::reflect_dom_object;
|
||||
use dom::bindings::root::{Dom, DomRoot, MutNullableDom};
|
||||
use dom::bindings::root::{DomRoot, MutNullableDom};
|
||||
use dom::globalscope::GlobalScope;
|
||||
use dom::webglbuffer::WebGLBuffer;
|
||||
use dom::webglobject::WebGLObject;
|
||||
use dom::webglrenderingcontext::BoundAttribBuffers;
|
||||
use dom_struct::dom_struct;
|
||||
use std::cell::{Cell, Ref};
|
||||
use std::collections::HashMap;
|
||||
use std::iter::FromIterator;
|
||||
use std::cell::Cell;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct WebGLVertexArrayObjectOES {
|
||||
|
@ -21,7 +19,7 @@ pub struct WebGLVertexArrayObjectOES {
|
|||
id: WebGLVertexArrayId,
|
||||
ever_bound: Cell<bool>,
|
||||
is_deleted: Cell<bool>,
|
||||
bound_attrib_buffers: DomRefCell<HashMap<u32, Dom<WebGLBuffer>>>,
|
||||
bound_attrib_buffers: BoundAttribBuffers,
|
||||
bound_buffer_element_array: MutNullableDom<WebGLBuffer>,
|
||||
}
|
||||
|
||||
|
@ -32,7 +30,7 @@ impl WebGLVertexArrayObjectOES {
|
|||
id: id,
|
||||
ever_bound: Cell::new(false),
|
||||
is_deleted: Cell::new(false),
|
||||
bound_attrib_buffers: DomRefCell::new(HashMap::new()),
|
||||
bound_attrib_buffers: Default::default(),
|
||||
bound_buffer_element_array: MutNullableDom::new(None),
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +41,10 @@ impl WebGLVertexArrayObjectOES {
|
|||
WebGLVertexArrayObjectOESBinding::Wrap)
|
||||
}
|
||||
|
||||
pub fn bound_attrib_buffers(&self) -> &BoundAttribBuffers {
|
||||
&self.bound_attrib_buffers
|
||||
}
|
||||
|
||||
pub fn id(&self) -> WebGLVertexArrayId {
|
||||
self.id
|
||||
}
|
||||
|
@ -63,18 +65,6 @@ impl WebGLVertexArrayObjectOES {
|
|||
self.ever_bound.set(true);
|
||||
}
|
||||
|
||||
pub fn borrow_bound_attrib_buffers(&self) -> Ref<HashMap<u32, Dom<WebGLBuffer>>> {
|
||||
self.bound_attrib_buffers.borrow()
|
||||
}
|
||||
|
||||
pub fn bound_attrib_buffers(&self) -> Vec<DomRoot<WebGLBuffer>> {
|
||||
self.bound_attrib_buffers.borrow().iter().map(|(_, b)| DomRoot::from_ref(&**b)).collect()
|
||||
}
|
||||
|
||||
pub fn set_bound_attrib_buffers<'a, T>(&self, iter: T) where T: Iterator<Item=(u32, &'a WebGLBuffer)> {
|
||||
*self.bound_attrib_buffers.borrow_mut() = HashMap::from_iter(iter.map(|(k,v)| (k, Dom::from_ref(v))));
|
||||
}
|
||||
|
||||
pub fn bound_buffer_element_array(&self) -> Option<DomRoot<WebGLBuffer>> {
|
||||
self.bound_buffer_element_array.get()
|
||||
}
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
[index-validation-copies-indices.html]
|
||||
type: testharness
|
||||
[WebGL test #1: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 0)]
|
||||
expected: FAIL
|
||||
|
||||
[WebGL test #2: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 4)]
|
||||
expected: FAIL
|
||||
|
||||
[WebGL test #4: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 0)]
|
||||
expected: FAIL
|
||||
|
||||
[WebGL test #5: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 4)]
|
||||
expected: FAIL
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[index-validation-verifies-too-many-indices.html]
|
||||
type: testharness
|
||||
[WebGL test #1: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 0)]
|
||||
expected: FAIL
|
||||
|
||||
[WebGL test #2: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: context.drawElements(context.TRIANGLE_STRIP, 4, context.UNSIGNED_SHORT, 4)]
|
||||
expected: FAIL
|
||||
|
|
@ -1,8 +1,4 @@
|
|||
[index-validation.html]
|
||||
type: testharness
|
||||
[WebGL test #9: getError expected: INVALID_OPERATION. Was NO_ERROR : ]
|
||||
expected: FAIL
|
||||
|
||||
[WebGL test #12: getError expected: INVALID_OPERATION. Was NO_ERROR : ]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
[oes-element-index-uint.html]
|
||||
[WebGL test #20: getError expected: INVALID_OPERATION. Was NO_ERROR : ]
|
||||
expected: FAIL
|
||||
|
||||
[WebGL test #64: getError expected: INVALID_OPERATION. Was NO_ERROR : ]
|
||||
expected: FAIL
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
[draw-elements-out-of-bounds.html]
|
||||
type: testharness
|
||||
[WebGL test #19: getError expected: NO_ERROR. Was INVALID_OPERATION : after evaluating: gl.drawElements(gl.TRIANGLES, 0, gl.UNSIGNED_BYTE, 4)]
|
||||
expected: FAIL
|
||||
|
||||
[WebGL test #25: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_BYTE, 0)]
|
||||
expected: FAIL
|
||||
|
||||
[WebGL test #31: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.drawElements(gl.TRIANGLES, 12, gl.UNSIGNED_SHORT, 0)]
|
||||
expected: FAIL
|
||||
|
||||
[WebGL test #32: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.drawElements(gl.TRIANGLES, 15, gl.UNSIGNED_SHORT, 0)]
|
||||
expected: FAIL
|
||||
|
||||
[WebGL test #33: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.drawElements(gl.TRIANGLES, 18, gl.UNSIGNED_SHORT, 0)]
|
||||
expected: FAIL
|
||||
|
||||
[WebGL test #34: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 30)]
|
||||
expected: FAIL
|
||||
|
|
@ -1,16 +1,7 @@
|
|||
[element-index-uint.html]
|
||||
[WebGL test #1: Draw 0 failed pixel test]
|
||||
expected: FAIL
|
||||
|
||||
[WebGL test #2: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).]
|
||||
expected: FAIL
|
||||
|
||||
[WebGL test #11: getError expected: INVALID_OPERATION. Was NO_ERROR : ]
|
||||
expected: FAIL
|
||||
|
||||
[WebGL test #14: getError expected: INVALID_OPERATION. Was NO_ERROR : ]
|
||||
expected: FAIL
|
||||
|
||||
[WebGL test #20: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.drawElements(gl.TRIANGLE_STRIP, 4, gl.UNSIGNED_INT, 0)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -32,9 +23,6 @@
|
|||
[WebGL test #49: getError expected: INVALID_OPERATION. Was NO_ERROR : ]
|
||||
expected: FAIL
|
||||
|
||||
[WebGL test #52: getError expected: INVALID_OPERATION. Was NO_ERROR : ]
|
||||
expected: FAIL
|
||||
|
||||
[WebGL test #58: getError expected: INVALID_OPERATION. Was NO_ERROR : after evaluating: gl.drawElements(gl.TRIANGLE_STRIP, 4, gl.UNSIGNED_INT, 0)]
|
||||
expected: FAIL
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue