mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-11 06:36:05 +00:00
Whitelist WebGlRenderingContext float slices
This commit is contained in:
parent
048a22bc77
commit
2e6880c43c
@ -152,9 +152,6 @@ export function new_title() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function new_webgl_rendering_context() {
|
export function new_webgl_rendering_context() {
|
||||||
const foo = document.createElement('canvas');
|
|
||||||
console.log('Does get context work? ' + foo.getContext('webgl'));
|
|
||||||
|
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
return canvas.getContext('webgl');
|
return canvas.getContext('webgl');
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
//! example when working with the WebGlRenderingContext APIs.
|
//! example when working with the WebGlRenderingContext APIs.
|
||||||
//!
|
//!
|
||||||
//! These tests ensure that whitelisted methods do indeed accept mutable slices.
|
//! These tests ensure that whitelisted methods do indeed accept mutable slices.
|
||||||
|
//! Especially important since this whitelist is stringly typed and currently
|
||||||
|
//! maintained by hand.
|
||||||
//!
|
//!
|
||||||
//! @see https://github.com/rustwasm/wasm-bindgen/issues/1005
|
//! @see https://github.com/rustwasm/wasm-bindgen/issues/1005
|
||||||
|
|
||||||
@ -20,7 +22,25 @@ extern "C" {
|
|||||||
// Ensure that our whitelisted WebGlRenderingContext methods work
|
// Ensure that our whitelisted WebGlRenderingContext methods work
|
||||||
#[wasm_bindgen_test]
|
#[wasm_bindgen_test]
|
||||||
fn test_webgl_rendering_context_immutable_slices() {
|
fn test_webgl_rendering_context_immutable_slices() {
|
||||||
|
// WebGl wasn't working in headless firefox at the time of writing..
|
||||||
let gl = new_webgl_rendering_context();
|
let gl = new_webgl_rendering_context();
|
||||||
|
|
||||||
gl.vertex_attrib1fv_with_f32_array(0, &[5000.]);
|
gl.vertex_attrib1fv_with_f32_array(0, &[1.]);
|
||||||
|
gl.vertex_attrib2fv_with_f32_array(0, &[1.]);
|
||||||
|
gl.vertex_attrib3fv_with_f32_array(0, &[1.]);
|
||||||
|
gl.vertex_attrib4fv_with_f32_array(0, &[1.]);
|
||||||
|
|
||||||
|
gl.uniform1fv_with_f32_array(None, &[1.]);
|
||||||
|
gl.uniform2fv_with_f32_array(None, &[1.]);
|
||||||
|
gl.uniform3fv_with_f32_array(None, &[1.]);
|
||||||
|
gl.uniform4fv_with_f32_array(None, &[1.]);
|
||||||
|
|
||||||
|
gl.uniform_matrix2fv_with_f32_array(None, false, &[1.]);
|
||||||
|
gl.uniform_matrix3fv_with_f32_array(None, false, &[1.]);
|
||||||
|
gl.uniform_matrix4fv_with_f32_array(None, false, &[1.]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
//#[wasm_bindgen_test]
|
||||||
|
//fn test_another_types_immutable_slices_here() {
|
||||||
|
//}
|
||||||
|
@ -340,10 +340,7 @@ macro_rules! terms_to_idl_type {
|
|||||||
($($t:tt => $r:tt)*) => ($(
|
($($t:tt => $r:tt)*) => ($(
|
||||||
impl<'a> ToIdlType<'a> for term::$t {
|
impl<'a> ToIdlType<'a> for term::$t {
|
||||||
fn to_idl_type(&self, _record: &FirstPassRecord<'a>) -> IdlType<'a> {
|
fn to_idl_type(&self, _record: &FirstPassRecord<'a>) -> IdlType<'a> {
|
||||||
match IdlType::$r {
|
IdlType::$r
|
||||||
IdlType::Callback => IdlType::Float32Array { immutable: false },
|
|
||||||
_ => IdlType::$r
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)*);
|
)*);
|
||||||
|
@ -12,8 +12,8 @@ use weedle::literal::{ConstValue, FloatLit, IntegerLit};
|
|||||||
|
|
||||||
use first_pass::{FirstPassRecord, OperationData, OperationId, Signature};
|
use first_pass::{FirstPassRecord, OperationData, OperationId, Signature};
|
||||||
use idl_type::{IdlType, ToIdlType};
|
use idl_type::{IdlType, ToIdlType};
|
||||||
// TODO: Remove.. just using this to see what idl types I need to change..
|
|
||||||
use std::io::Write;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
/// For variadic operations an overload with a `js_sys::Array` argument is generated alongside with
|
/// For variadic operations an overload with a `js_sys::Array` argument is generated alongside with
|
||||||
/// `operation_name_0`, `operation_name_1`, `operation_name_2`, ..., `operation_name_n` overloads
|
/// `operation_name_0`, `operation_name_1`, `operation_name_2`, ..., `operation_name_n` overloads
|
||||||
@ -721,31 +721,40 @@ pub fn public() -> syn::Visibility {
|
|||||||
///
|
///
|
||||||
/// Here we implement a whitelist for those cases. This whitelist is currently
|
/// Here we implement a whitelist for those cases. This whitelist is currently
|
||||||
/// maintained by hand.
|
/// maintained by hand.
|
||||||
fn maybe_adjust<'a> (mut idl_type: IdlType<'a>, id: &'a OperationId) -> IdlType<'a> {
|
fn maybe_adjust<'a>(mut idl_type: IdlType<'a>, id: &'a OperationId) -> IdlType<'a> {
|
||||||
// let mut file = ::std::fs::OpenOptions::new().append(true).create(true).open("foo").unwrap();
|
let immutable_f32_fns: Vec<&'static str> = vec![
|
||||||
|
// WebGlRenderingContext
|
||||||
|
"vertexAttrib1fv",
|
||||||
|
"vertexAttrib2fv",
|
||||||
|
"vertexAttrib3fv",
|
||||||
|
"vertexAttrib4fv",
|
||||||
|
"uniform1fv",
|
||||||
|
"uniform2fv",
|
||||||
|
"uniform3fv",
|
||||||
|
"uniform4fv",
|
||||||
|
"uniformMatrix2fv",
|
||||||
|
"uniformMatrix3fv",
|
||||||
|
"uniformMatrix4fv",
|
||||||
|
// TODO: Add another type's functions here
|
||||||
|
];
|
||||||
|
|
||||||
match id {
|
let mut immutable_f32_slice_whitelist: HashSet<&'static str> = HashSet::new();
|
||||||
OperationId::Operation(Some(op)) => {
|
for function_name in immutable_f32_fns.into_iter() {
|
||||||
match *op {
|
immutable_f32_slice_whitelist.insert(function_name);
|
||||||
"vertexAttrib1fv" => {
|
|
||||||
// TODO: Remove.. just using this to see what idl types I need to change..
|
|
||||||
// file.write(
|
|
||||||
// format!("{:#?}", idl_type).as_bytes()
|
|
||||||
// );
|
|
||||||
// file.write(r#"
|
|
||||||
// "#.as_bytes());
|
|
||||||
|
|
||||||
if let IdlType::Union(ref mut union) = idl_type {
|
|
||||||
if let IdlType::Float32Array { ref mut immutable } = union[0] {
|
|
||||||
*immutable = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
};
|
|
||||||
|
|
||||||
return idl_type
|
|
||||||
}
|
|
||||||
_ => idl_type
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// example `op`... -> "vertexAttrib1fv"
|
||||||
|
if let OperationId::Operation(Some(op)) = id {
|
||||||
|
// Look up this funtion in our whitelist and see if we should make its
|
||||||
|
// slice argument immutable.
|
||||||
|
if immutable_f32_slice_whitelist.get(op).is_some() {
|
||||||
|
if let IdlType::Union(ref mut union) = idl_type {
|
||||||
|
if let IdlType::Float32Array { ref mut immutable } = union[0] {
|
||||||
|
*immutable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
idl_type
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user