mirror of
https://github.com/servo/servo.git
synced 2025-07-05 22:43:40 +01:00
webgl: Remove active_uniform related validation.
It's broken for uniform arrays, since uniform.id() stops being the index then. We need to add a more complex integration with angle for this to ever be correct. Unfortunately the ANGLE part that we should touch is C++, and it has destructors, so we need to hook destructors there, and I can't do it right now.
This commit is contained in:
parent
f470ad0d88
commit
6a15c2f245
2 changed files with 33 additions and 22 deletions
|
@ -3,7 +3,6 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use canvas_traits::{CanvasCommonMsg, CanvasMsg};
|
use canvas_traits::{CanvasCommonMsg, CanvasMsg};
|
||||||
use dom::bindings::codegen::Bindings::WebGLActiveInfoBinding::WebGLActiveInfoMethods;
|
|
||||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
|
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
|
||||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{WebGLRenderingContextMethods};
|
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{WebGLRenderingContextMethods};
|
||||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{self, WebGLContextAttributes};
|
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{self, WebGLContextAttributes};
|
||||||
|
@ -68,6 +67,7 @@ bitflags! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum UniformType {
|
pub enum UniformType {
|
||||||
Int,
|
Int,
|
||||||
IntVec2,
|
IntVec2,
|
||||||
|
@ -93,6 +93,25 @@ impl UniformType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_compatible_with(&self, gl_type: u32) -> bool {
|
||||||
|
gl_type == self.as_gl_constant() || match *self {
|
||||||
|
// Sampler uniform variables have an index value (the index of the
|
||||||
|
// texture), and as such they have to be set as ints
|
||||||
|
UniformType::Int => gl_type == constants::SAMPLER_2D ||
|
||||||
|
gl_type == constants::SAMPLER_CUBE,
|
||||||
|
// Don't ask me why, but it seems we must allow setting bool
|
||||||
|
// uniforms with uniform1f.
|
||||||
|
//
|
||||||
|
// See the WebGL conformance test
|
||||||
|
// conformance/uniforms/gl-uniform-bool.html
|
||||||
|
UniformType::Float => gl_type == constants::BOOL,
|
||||||
|
UniformType::FloatVec2 => gl_type == constants::BOOL_VEC2,
|
||||||
|
UniformType::FloatVec3 => gl_type == constants::BOOL_VEC3,
|
||||||
|
UniformType::FloatVec4 => gl_type == constants::BOOL_VEC4,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn as_gl_constant(&self) -> u32 {
|
fn as_gl_constant(&self) -> u32 {
|
||||||
match *self {
|
match *self {
|
||||||
UniformType::Int => constants::INT,
|
UniformType::Int => constants::INT,
|
||||||
|
@ -225,7 +244,7 @@ impl WebGLRenderingContext {
|
||||||
// https://www.khronos.org/registry/gles/specs/2.0/es_full_spec_2.0.25.pdf#nameddest=section-2.10.4
|
// https://www.khronos.org/registry/gles/specs/2.0/es_full_spec_2.0.25.pdf#nameddest=section-2.10.4
|
||||||
fn validate_uniform_parameters<T>(&self,
|
fn validate_uniform_parameters<T>(&self,
|
||||||
uniform: Option<&WebGLUniformLocation>,
|
uniform: Option<&WebGLUniformLocation>,
|
||||||
type_: UniformType,
|
uniform_type: UniformType,
|
||||||
data: Option<&[T]>) -> bool {
|
data: Option<&[T]>) -> bool {
|
||||||
let uniform = match uniform {
|
let uniform = match uniform {
|
||||||
Some(uniform) => uniform,
|
Some(uniform) => uniform,
|
||||||
|
@ -233,8 +252,8 @@ impl WebGLRenderingContext {
|
||||||
};
|
};
|
||||||
|
|
||||||
let program = self.current_program.get();
|
let program = self.current_program.get();
|
||||||
let program = match program {
|
match program {
|
||||||
Some(ref program) if program.id() == uniform.program_id() => program,
|
Some(ref program) if program.id() == uniform.program_id() => {},
|
||||||
_ => {
|
_ => {
|
||||||
self.webgl_error(InvalidOperation);
|
self.webgl_error(InvalidOperation);
|
||||||
return false;
|
return false;
|
||||||
|
@ -249,28 +268,15 @@ impl WebGLRenderingContext {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO(autrilla): Don't request this every time, cache it
|
// TODO(emilio): Get more complex uniform info from ANGLE, and use it to
|
||||||
let active_uniform = match program.get_active_uniform(
|
// properly validate that the uniform type is compatible with the
|
||||||
uniform.id() as u32) {
|
// uniform type, and that the uniform size matches.
|
||||||
Ok(active_uniform) => active_uniform,
|
if data.len() % uniform_type.element_count() != 0 {
|
||||||
Err(_) => {
|
|
||||||
self.webgl_error(InvalidOperation);
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
if data.len() % type_.element_count() != 0 ||
|
|
||||||
(data.len() / type_.element_count() > active_uniform.Size() as usize) {
|
|
||||||
self.webgl_error(InvalidOperation);
|
self.webgl_error(InvalidOperation);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if type_.as_gl_constant() != active_uniform.Type() {
|
true
|
||||||
self.webgl_error(InvalidOperation);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate_tex_image_parameters(&self,
|
fn validate_tex_image_parameters(&self,
|
||||||
|
|
|
@ -116,6 +116,11 @@ impl WebGLShader {
|
||||||
}
|
}
|
||||||
|
|
||||||
*self.info_log.borrow_mut() = Some(validator.info_log());
|
*self.info_log.borrow_mut() = Some(validator.info_log());
|
||||||
|
// TODO(emilio): More data (like uniform data) should be collected
|
||||||
|
// here to properly validate uniforms.
|
||||||
|
//
|
||||||
|
// This requires a more complex interface with ANGLE, using C++
|
||||||
|
// bindings and being extremely cautious about destructing things.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue