mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Auto merge of #20646 - servo:webgl, r=emilio
Some drive-by error condition fix for gl.drawElements <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20646) <!-- Reviewable:end -->
This commit is contained in:
commit
441f1cd231
1 changed files with 23 additions and 21 deletions
|
@ -2143,6 +2143,14 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.11
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.11
|
||||||
fn DrawElements(&self, mode: u32, count: i32, type_: u32, offset: i64) {
|
fn DrawElements(&self, mode: u32, count: i32, type_: u32, offset: i64) {
|
||||||
|
match mode {
|
||||||
|
constants::POINTS | constants::LINE_STRIP |
|
||||||
|
constants::LINE_LOOP | constants::LINES |
|
||||||
|
constants::TRIANGLE_STRIP | constants::TRIANGLE_FAN |
|
||||||
|
constants::TRIANGLES => {},
|
||||||
|
_ => return self.webgl_error(InvalidEnum),
|
||||||
|
}
|
||||||
|
|
||||||
// From the GLES 2.0.25 spec, page 21:
|
// From the GLES 2.0.25 spec, page 21:
|
||||||
//
|
//
|
||||||
// "type must be one of UNSIGNED_BYTE or UNSIGNED_SHORT"
|
// "type must be one of UNSIGNED_BYTE or UNSIGNED_SHORT"
|
||||||
|
@ -2175,35 +2183,29 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
return self.webgl_error(InvalidOperation);
|
return self.webgl_error(InvalidOperation);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(array_buffer) = self.bound_buffer_element_array.get() {
|
if count > 0 {
|
||||||
// WebGL Spec: check buffer overflows, must be a valid multiple of the size.
|
if let Some(array_buffer) = self.bound_buffer_element_array.get() {
|
||||||
let val = offset as u64 + (count as u64 * type_size as u64);
|
// WebGL Spec: check buffer overflows, must be a valid multiple of the size.
|
||||||
if val > array_buffer.capacity() as u64 {
|
let val = offset as u64 + (count as u64 * type_size as u64);
|
||||||
|
if val > array_buffer.capacity() as u64 {
|
||||||
|
return self.webgl_error(InvalidOperation);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// From the WebGL spec
|
||||||
|
//
|
||||||
|
// a non-null WebGLBuffer must be bound to the ELEMENT_ARRAY_BUFFER binding point
|
||||||
|
// or an INVALID_OPERATION error will be generated.
|
||||||
|
//
|
||||||
return self.webgl_error(InvalidOperation);
|
return self.webgl_error(InvalidOperation);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// From the WebGL spec
|
|
||||||
//
|
|
||||||
// a non-null WebGLBuffer must be bound to the ELEMENT_ARRAY_BUFFER binding point
|
|
||||||
// or an INVALID_OPERATION error will be generated.
|
|
||||||
//
|
|
||||||
return self.webgl_error(InvalidOperation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.validate_framebuffer_complete() {
|
if !self.validate_framebuffer_complete() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
match mode {
|
self.send_command(WebGLCommand::DrawElements(mode, count, type_, offset));
|
||||||
constants::POINTS | constants::LINE_STRIP |
|
self.mark_as_dirty();
|
||||||
constants::LINE_LOOP | constants::LINES |
|
|
||||||
constants::TRIANGLE_STRIP | constants::TRIANGLE_FAN |
|
|
||||||
constants::TRIANGLES => {
|
|
||||||
self.send_command(WebGLCommand::DrawElements(mode, count, type_, offset));
|
|
||||||
self.mark_as_dirty();
|
|
||||||
},
|
|
||||||
_ => self.webgl_error(InvalidEnum),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue