diff options
author | bors-servo <servo-ops@mozilla.com> | 2020-03-30 13:59:05 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-30 13:59:05 -0400 |
commit | 69004e43ddf4800b3db3d86ec58b0224a602457a (patch) | |
tree | 5896a8dd6376b0c0e680c98bcd30d0be0b256818 /components/script/dom/webgl2renderingcontext.rs | |
parent | 236762880c48263f8fa2c5a4deb9cf8f7746013c (diff) | |
parent | bfa43fbeba1ffb1adca44d18bb22dbee81069af9 (diff) | |
download | servo-69004e43ddf4800b3db3d86ec58b0224a602457a.tar.gz servo-69004e43ddf4800b3db3d86ec58b0224a602457a.zip |
Auto merge of #26025 - szeged:webgl_draw_range_elements, r=jdm
Add support for DrawRangeElements in WebGL2
Adds initial support for the WebGL2 `DrawRangeElements` call.
<!-- Please describe your changes on the following line: -->
I have started working on this function, but not sure how could I check for the Uniform Block Backing (https://www.khronos.org/registry/webgl/specs/latest/2.0/#ACTIVE_UNIFORM_BLOCK_BACKING).
I am looking for some advice.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] There are tests for these changes
cc @mmatyas @zakorgy @jdm
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Diffstat (limited to 'components/script/dom/webgl2renderingcontext.rs')
-rw-r--r-- | components/script/dom/webgl2renderingcontext.rs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/components/script/dom/webgl2renderingcontext.rs b/components/script/dom/webgl2renderingcontext.rs index 8ae05c05363..54c0da20333 100644 --- a/components/script/dom/webgl2renderingcontext.rs +++ b/components/script/dom/webgl2renderingcontext.rs @@ -189,6 +189,48 @@ impl WebGL2RenderingContext { self.base.current_vao_webgl2() } + pub fn validate_uniform_block_for_draw(&self) { + let program = match self.base.current_program() { + Some(program) => program, + None => return, + }; + for uniform_block in program.active_uniform_blocks().iter() { + let data_size = uniform_block.size as usize; + for block in program.active_uniforms().iter() { + let index = match block.bind_index { + Some(index) => index, + None => continue, + }; + let indexed = &self.indexed_uniform_buffer_bindings[index as usize]; + let buffer = match indexed.buffer.get() { + Some(buffer) => buffer, + None => { + self.base.webgl_error(InvalidOperation); + return; + }, + }; + if indexed.size.get() == 0 { + if data_size > buffer.capacity() { + self.base.webgl_error(InvalidOperation); + return; + } + } else { + let start = indexed.start.get() as usize; + let mut size = indexed.size.get() as usize; + if start >= size { + self.base.webgl_error(InvalidOperation); + return; + } + size -= start; + if data_size > size { + self.base.webgl_error(InvalidOperation); + return; + } + } + } + } + } + pub fn base_context(&self) -> DomRoot<WebGLRenderingContext> { DomRoot::from_ref(&*self.base) } @@ -1527,11 +1569,13 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext { /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.11 fn DrawArrays(&self, mode: u32, first: i32, count: i32) { + self.validate_uniform_block_for_draw(); self.base.DrawArrays(mode, first, count) } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.11 fn DrawElements(&self, mode: u32, count: i32, type_: u32, offset: i64) { + self.validate_uniform_block_for_draw(); self.base.DrawElements(mode, count, type_, offset) } @@ -2776,6 +2820,7 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext { /// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.9 fn DrawArraysInstanced(&self, mode: u32, first: i32, count: i32, primcount: i32) { + self.validate_uniform_block_for_draw(); handle_potential_webgl_error!( self.base, self.base @@ -2792,6 +2837,7 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext { offset: i64, primcount: i32, ) { + self.validate_uniform_block_for_draw(); handle_potential_webgl_error!( self.base, self.base @@ -2800,6 +2846,28 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext { } /// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.9 + fn DrawRangeElements( + &self, + mode: u32, + start: u32, + end: u32, + count: i32, + type_: u32, + offset: i64, + ) { + if end < start { + self.base.webgl_error(InvalidValue); + return; + } + self.validate_uniform_block_for_draw(); + handle_potential_webgl_error!( + self.base, + self.base + .draw_elements_instanced(mode, count, type_, offset, 1) + ) + } + + /// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.9 fn VertexAttribDivisor(&self, index: u32, divisor: u32) { self.base.vertex_attrib_divisor(index, divisor); } |