aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <ecoal95@gmail.com>2015-12-29 13:51:10 +0100
committerEmilio Cobos Álvarez <ecoal95@gmail.com>2016-01-13 13:41:30 +0100
commit221a58378450d26ff9e3bb645df8fcf5fb43994f (patch)
tree8680d4237fabc0f3b4956caa3a98665888967af3
parent532b53ddc94cd99d737411b635f2fb6a6d50af51 (diff)
downloadservo-221a58378450d26ff9e3bb645df8fcf5fb43994f.tar.gz
servo-221a58378450d26ff9e3bb645df8fcf5fb43994f.zip
webgl: Track uniformlocation's program
-rw-r--r--components/script/dom/webglprogram.rs4
-rw-r--r--components/script/dom/webglrenderingcontext.rs29
-rw-r--r--components/script/dom/webgluniformlocation.rs13
3 files changed, 35 insertions, 11 deletions
diff --git a/components/script/dom/webglprogram.rs b/components/script/dom/webglprogram.rs
index 350fc31929c..272eeae72aa 100644
--- a/components/script/dom/webglprogram.rs
+++ b/components/script/dom/webglprogram.rs
@@ -55,6 +55,10 @@ impl WebGLProgram {
impl WebGLProgram {
+ pub fn id(&self) -> u32 {
+ self.id
+ }
+
/// glDeleteProgram
pub fn delete(&self) {
if !self.is_deleted.get() {
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs
index 701ae737ba8..33735d83633 100644
--- a/components/script/dom/webglrenderingcontext.rs
+++ b/components/script/dom/webglrenderingcontext.rs
@@ -79,6 +79,7 @@ pub struct WebGLRenderingContext {
bound_texture_cube_map: MutNullableHeap<JS<WebGLTexture>>,
bound_buffer_array: MutNullableHeap<JS<WebGLBuffer>>,
bound_buffer_element_array: MutNullableHeap<JS<WebGLBuffer>>,
+ current_program: MutNullableHeap<JS<WebGLProgram>>,
}
impl WebGLRenderingContext {
@@ -106,6 +107,7 @@ impl WebGLRenderingContext {
bound_texture_cube_map: MutNullableHeap::new(None),
bound_buffer_array: MutNullableHeap::new(None),
bound_buffer_element_array: MutNullableHeap::new(None),
+ current_program: MutNullableHeap::new(None),
}
})
}
@@ -804,7 +806,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
name: DOMString) -> Option<Root<WebGLUniformLocation>> {
if let Some(program) = program {
handle_potential_webgl_error!(self, program.get_uniform_location(name), None)
- .map(|location| WebGLUniformLocation::new(self.global().r(), location))
+ .map(|location| WebGLUniformLocation::new(self.global().r(), location, program.id()))
} else {
None
}
@@ -934,13 +936,18 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
fn Uniform1f(&self,
uniform: Option<&WebGLUniformLocation>,
val: f32) {
- let uniform_id = match uniform {
- Some(uniform) => uniform.id(),
+ let uniform = match uniform {
+ Some(uniform) => uniform,
None => return,
};
+ match self.current_program.get() {
+ Some(ref program) if program.id() == uniform.program_id() => {},
+ _ => return self.webgl_error(InvalidOperation),
+ };
+
self.ipc_renderer
- .send(CanvasMsg::WebGL(CanvasWebGLMsg::Uniform1f(uniform_id, val)))
+ .send(CanvasMsg::WebGL(CanvasWebGLMsg::Uniform1f(uniform.id(), val)))
.unwrap()
}
@@ -959,13 +966,18 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
fn Uniform4f(&self,
uniform: Option<&WebGLUniformLocation>,
x: f32, y: f32, z: f32, w: f32) {
- let uniform_id = match uniform {
- Some(uniform) => uniform.id(),
+ let uniform = match uniform {
+ Some(uniform) => uniform,
None => return,
};
+ match self.current_program.get() {
+ Some(ref program) if program.id() == uniform.program_id() => {},
+ _ => return self.webgl_error(InvalidOperation),
+ };
+
self.ipc_renderer
- .send(CanvasMsg::WebGL(CanvasWebGLMsg::Uniform4f(uniform_id, x, y, z, w)))
+ .send(CanvasMsg::WebGL(CanvasWebGLMsg::Uniform4f(uniform.id(), x, y, z, w)))
.unwrap()
}
@@ -993,7 +1005,8 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn UseProgram(&self, program: Option<&WebGLProgram>) {
if let Some(program) = program {
- program.use_program()
+ program.use_program();
+ self.current_program.set(Some(program));
}
}
diff --git a/components/script/dom/webgluniformlocation.rs b/components/script/dom/webgluniformlocation.rs
index 7367f9f1d7d..43244ec4a33 100644
--- a/components/script/dom/webgluniformlocation.rs
+++ b/components/script/dom/webgluniformlocation.rs
@@ -12,18 +12,21 @@ use dom::bindings::reflector::{Reflector, reflect_dom_object};
pub struct WebGLUniformLocation {
reflector_: Reflector,
id: i32,
+ program_id: u32,
}
impl WebGLUniformLocation {
- fn new_inherited(id: i32) -> WebGLUniformLocation {
+ fn new_inherited(id: i32, program_id: u32) -> WebGLUniformLocation {
WebGLUniformLocation {
reflector_: Reflector::new(),
id: id,
+ program_id: program_id,
}
}
- pub fn new(global: GlobalRef, id: i32) -> Root<WebGLUniformLocation> {
- reflect_dom_object(box WebGLUniformLocation::new_inherited(id), global, WebGLUniformLocationBinding::Wrap)
+ pub fn new(global: GlobalRef, id: i32, program_id: u32) -> Root<WebGLUniformLocation> {
+ reflect_dom_object(
+ box WebGLUniformLocation::new_inherited(id, program_id), global, WebGLUniformLocationBinding::Wrap)
}
}
@@ -32,4 +35,8 @@ impl WebGLUniformLocation {
pub fn id(&self) -> i32 {
self.id
}
+
+ pub fn program_id(&self) -> u32 {
+ self.program_id
+ }
}