aboutsummaryrefslogtreecommitdiffstats
path: root/components/canvas/webgl_thread.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2020-01-09 08:52:15 -0500
committerGitHub <noreply@github.com>2020-01-09 08:52:15 -0500
commit123d43bb16cd6807ad6de3e83316191a58505d5b (patch)
tree1bb3050695e0c2df00d9a8f111a75c30cb24e3ee /components/canvas/webgl_thread.rs
parentff6ddb4b613b8028bd16fb2355c539dc14bec7a6 (diff)
parentda94f8d0e78546a40972596ad0ae4ded510057de (diff)
downloadservo-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/canvas/webgl_thread.rs')
-rw-r--r--components/canvas/webgl_thread.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/components/canvas/webgl_thread.rs b/components/canvas/webgl_thread.rs
index b9a4533f134..46ea56c1c4f 100644
--- a/components/canvas/webgl_thread.rs
+++ b/components/canvas/webgl_thread.rs
@@ -6,6 +6,7 @@ use crate::webgl_limits::GLLimitsDetect;
use byteorder::{ByteOrder, NativeEndian, WriteBytesExt};
use canvas_traits::webgl;
use canvas_traits::webgl::ActiveAttribInfo;
+use canvas_traits::webgl::ActiveUniformBlockInfo;
use canvas_traits::webgl::ActiveUniformInfo;
use canvas_traits::webgl::AlphaTreatment;
use canvas_traits::webgl::DOMToTextureCommand;
@@ -1744,6 +1745,40 @@ impl WebGLImpl {
}
sender.send(value).unwrap();
},
+ WebGLCommand::GetUniformBlockIndex(program_id, ref name, ref sender) => {
+ let name = to_name_in_compiled_shader(name);
+ let index = gl.get_uniform_block_index(program_id.get(), &name);
+ sender.send(index).unwrap();
+ },
+ WebGLCommand::GetUniformIndices(program_id, ref names, ref sender) => {
+ let names = names
+ .iter()
+ .map(|name| to_name_in_compiled_shader(name))
+ .collect::<Vec<_>>();
+ let name_strs = names.iter().map(|name| name.as_str()).collect::<Vec<_>>();
+ let indices = gl.get_uniform_indices(program_id.get(), &name_strs);
+ sender.send(indices).unwrap();
+ },
+ WebGLCommand::GetActiveUniforms(program_id, ref indices, pname, ref sender) => {
+ let results = gl.get_active_uniforms_iv(program_id.get(), indices, pname);
+ sender.send(results).unwrap();
+ },
+ WebGLCommand::GetActiveUniformBlockName(program_id, block_idx, ref sender) => {
+ let name = gl.get_active_uniform_block_name(program_id.get(), block_idx);
+ sender.send(name).unwrap();
+ },
+ WebGLCommand::GetActiveUniformBlockParameter(
+ program_id,
+ block_idx,
+ pname,
+ ref sender,
+ ) => {
+ let results = gl.get_active_uniform_block_iv(program_id.get(), block_idx, pname);
+ sender.send(results).unwrap();
+ },
+ WebGLCommand::UniformBlockBinding(program_id, block_idx, block_binding) => {
+ gl.uniform_block_binding(program_id.get(), block_idx, block_binding)
+ },
WebGLCommand::InitializeFramebuffer {
color,
depth,
@@ -1790,6 +1825,16 @@ impl WebGLImpl {
let value = gl.get_sampler_parameter_fv(sampler_id.get(), pname)[0];
sender.send(value).unwrap();
},
+ WebGLCommand::BindBufferBase(target, index, id) => {
+ gl.bind_buffer_base(target, index, id.map_or(0, WebGLBufferId::get))
+ },
+ WebGLCommand::BindBufferRange(target, index, id, offset, size) => gl.bind_buffer_range(
+ target,
+ index,
+ id.map_or(0, WebGLBufferId::get),
+ offset as isize,
+ size as isize,
+ ),
}
// If debug asertions are enabled, then check the error state.
@@ -1890,6 +1935,7 @@ impl WebGLImpl {
linked: false,
active_attribs: vec![].into(),
active_uniforms: vec![].into(),
+ active_uniform_blocks: vec![].into(),
transform_feedback_length: Default::default(),
transform_feedback_mode: Default::default(),
};
@@ -1945,6 +1991,26 @@ impl WebGLImpl {
})
.collect::<Vec<_>>()
.into();
+
+ let mut num_active_uniform_blocks = [0];
+ unsafe {
+ gl.get_program_iv(
+ program.get(),
+ gl::ACTIVE_UNIFORM_BLOCKS,
+ &mut num_active_uniform_blocks,
+ );
+ }
+ let active_uniform_blocks = (0..num_active_uniform_blocks[0] as u32)
+ .map(|i| {
+ let name = gl.get_active_uniform_block_name(program.get(), i);
+ let size =
+ gl.get_active_uniform_block_iv(program.get(), i, gl::UNIFORM_BLOCK_DATA_SIZE)
+ [0];
+ ActiveUniformBlockInfo { name, size }
+ })
+ .collect::<Vec<_>>()
+ .into();
+
let mut transform_feedback_length = [0];
unsafe {
gl.get_program_iv(
@@ -1965,6 +2031,7 @@ impl WebGLImpl {
linked: true,
active_attribs,
active_uniforms,
+ active_uniform_blocks,
transform_feedback_length: transform_feedback_length[0],
transform_feedback_mode: transform_feedback_mode[0],
}