diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2020-01-09 08:52:15 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-09 08:52:15 -0500 |
commit | 123d43bb16cd6807ad6de3e83316191a58505d5b (patch) | |
tree | 1bb3050695e0c2df00d9a8f111a75c30cb24e3ee /components/script/dom/webglrenderingcontext.rs | |
parent | ff6ddb4b613b8028bd16fb2355c539dc14bec7a6 (diff) | |
parent | da94f8d0e78546a40972596ad0ae4ded510057de (diff) | |
download | servo-123d43bb16cd6807ad6de3e83316191a58505d5b.tar.gz servo-123d43bb16cd6807ad6de3e83316191a58505d5b.zip |
Auto merge of #25229 - mmatyas:webgl_fns_ubo, r=jdm
Add initial support for WebGL2 uniform buffer functions
This *work-in-progress* patch adds initial support for the following WebGL2 calls:
- `bindBufferBase`
- `bindBufferRange`
- `getUniformIndices`
- `getUniformBlockIndex`
- `getActiveUniforms`
- `getActiveUniformBlockParameter`
- `getActiveUniformBlockName`
- `uniformBlockBinding`
See: https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.16
However, indexed uniforms and `getIndexedParameter`, which would be used by some of the functions (and transform feedback) is still missing. Also this patch depends on:
- https://github.com/servo/sparkle/pull/16
- https://github.com/servo/servo/issues/25034
(required for both building and running the tests).
cc @jdm @zakorgy @imiklos
<!-- Please describe your changes on the following line: -->
---
<!-- 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
- [ ] These changes fix #___ (GitHub issue number if applicable)
<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because ___
<!-- 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/webglrenderingcontext.rs')
-rw-r--r-- | components/script/dom/webglrenderingcontext.rs | 68 |
1 files changed, 44 insertions, 24 deletions
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 85930cd3529..68eccfa711d 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -1020,6 +1020,13 @@ impl WebGLRenderingContext { } } + pub fn buffer_usage(&self, usage: u32) -> WebGLResult<u32> { + match usage { + constants::STREAM_DRAW | constants::STATIC_DRAW | constants::DYNAMIC_DRAW => Ok(usage), + _ => Err(WebGLError::InvalidEnum), + } + } + pub fn create_vertex_array(&self) -> Option<DomRoot<WebGLVertexArrayObjectOES>> { let (sender, receiver) = webgl_channel().unwrap(); self.send_command(WebGLCommand::CreateVertexArray(sender)); @@ -1146,6 +1153,40 @@ impl WebGLRenderingContext { handle_potential_webgl_error!(self, bound_buffer.buffer_data(target, &data, usage)); } + #[allow(unsafe_code)] + pub fn buffer_sub_data( + &self, + target: u32, + offset: i64, + data: ArrayBufferViewOrArrayBuffer, + bound_buffer: Option<DomRoot<WebGLBuffer>>, + ) { + let bound_buffer = + handle_potential_webgl_error!(self, bound_buffer.ok_or(InvalidOperation), return); + + if offset < 0 { + return self.webgl_error(InvalidValue); + } + + let data = unsafe { + // Safe because we don't do anything with JS until the end of the method. + match data { + ArrayBufferViewOrArrayBuffer::ArrayBuffer(ref data) => data.as_slice(), + ArrayBufferViewOrArrayBuffer::ArrayBufferView(ref data) => data.as_slice(), + } + }; + if (offset as u64) + data.len() as u64 > bound_buffer.capacity() as u64 { + return self.webgl_error(InvalidValue); + } + let (sender, receiver) = ipc::bytes_channel().unwrap(); + self.send_command(WebGLCommand::BufferSubData( + target, + offset as isize, + receiver, + )); + sender.send(data).unwrap(); + } + pub fn bind_buffer_maybe( &self, slot: &MutNullableDom<WebGLBuffer>, @@ -1764,12 +1805,14 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5 fn BufferData(&self, target: u32, data: Option<ArrayBufferViewOrArrayBuffer>, usage: u32) { + let usage = handle_potential_webgl_error!(self, self.buffer_usage(usage), return); let bound_buffer = handle_potential_webgl_error!(self, self.bound_buffer(target), return); self.buffer_data(target, data, usage, bound_buffer) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5 fn BufferData_(&self, target: u32, size: i64, usage: u32) { + let usage = handle_potential_webgl_error!(self, self.buffer_usage(usage), return); let bound_buffer = handle_potential_webgl_error!(self, self.bound_buffer(target), return); self.buffer_data_(target, size, usage, bound_buffer) } @@ -1778,30 +1821,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { #[allow(unsafe_code)] fn BufferSubData(&self, target: u32, offset: i64, data: ArrayBufferViewOrArrayBuffer) { let bound_buffer = handle_potential_webgl_error!(self, self.bound_buffer(target), return); - let bound_buffer = - handle_potential_webgl_error!(self, bound_buffer.ok_or(InvalidOperation), return); - - if offset < 0 { - return self.webgl_error(InvalidValue); - } - - let data = unsafe { - // Safe because we don't do anything with JS until the end of the method. - match data { - ArrayBufferViewOrArrayBuffer::ArrayBuffer(ref data) => data.as_slice(), - ArrayBufferViewOrArrayBuffer::ArrayBufferView(ref data) => data.as_slice(), - } - }; - if (offset as u64) + data.len() as u64 > bound_buffer.capacity() as u64 { - return self.webgl_error(InvalidValue); - } - let (sender, receiver) = ipc::bytes_channel().unwrap(); - self.send_command(WebGLCommand::BufferSubData( - target, - offset as isize, - receiver, - )); - sender.send(data).unwrap(); + self.buffer_sub_data(target, offset, data, bound_buffer) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 |