aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webglrenderingcontext.rs
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <me@emiliocobos.me>2016-04-19 13:11:28 +0200
committerEmilio Cobos Álvarez <me@emiliocobos.me>2016-04-19 13:27:19 +0200
commit6a15c2f245a32677edd76dd0e1dedbd404132bd9 (patch)
tree467a6f8f61ef691e729c00dc738e2cac07492683 /components/script/dom/webglrenderingcontext.rs
parentf470ad0d884f50247f4846a8271e67616ffc7354 (diff)
downloadservo-6a15c2f245a32677edd76dd0e1dedbd404132bd9.tar.gz
servo-6a15c2f245a32677edd76dd0e1dedbd404132bd9.zip
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.
Diffstat (limited to 'components/script/dom/webglrenderingcontext.rs')
-rw-r--r--components/script/dom/webglrenderingcontext.rs50
1 files changed, 28 insertions, 22 deletions
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs
index 408558d3031..8257f8536a1 100644
--- a/components/script/dom/webglrenderingcontext.rs
+++ b/components/script/dom/webglrenderingcontext.rs
@@ -3,7 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
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::{WebGLRenderingContextMethods};
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{self, WebGLContextAttributes};
@@ -68,6 +67,7 @@ bitflags! {
}
}
+#[derive(Debug, PartialEq)]
pub enum UniformType {
Int,
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 {
match *self {
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
fn validate_uniform_parameters<T>(&self,
uniform: Option<&WebGLUniformLocation>,
- type_: UniformType,
+ uniform_type: UniformType,
data: Option<&[T]>) -> bool {
let uniform = match uniform {
Some(uniform) => uniform,
@@ -233,8 +252,8 @@ impl WebGLRenderingContext {
};
let program = self.current_program.get();
- let program = match program {
- Some(ref program) if program.id() == uniform.program_id() => program,
+ match program {
+ Some(ref program) if program.id() == uniform.program_id() => {},
_ => {
self.webgl_error(InvalidOperation);
return false;
@@ -249,28 +268,15 @@ impl WebGLRenderingContext {
},
};
- // TODO(autrilla): Don't request this every time, cache it
- let active_uniform = match program.get_active_uniform(
- uniform.id() as u32) {
- Ok(active_uniform) => active_uniform,
- Err(_) => {
+ // TODO(emilio): Get more complex uniform info from ANGLE, and use it to
+ // properly validate that the uniform type is compatible with the
+ // uniform type, and that the uniform size matches.
+ if data.len() % uniform_type.element_count() != 0 {
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);
- return false;
- }
-
- if type_.as_gl_constant() != active_uniform.Type() {
- self.webgl_error(InvalidOperation);
- return false;
}
- return true;
+ true
}
fn validate_tex_image_parameters(&self,