Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webgl: Implement the pending texImage2D overload, and add more validation #10443

Merged
merged 12 commits into from Apr 22, 2016

webgl: Refactor WebGLProgram::link

This makes it more correct, since we don't blindly send the Link
command. It's not observable though.
  • Loading branch information
emilio committed Apr 19, 2016
commit f470ad0d884f50247f4846a8271e67616ffc7354
@@ -23,6 +23,7 @@ pub struct WebGLProgram {
webgl_object: WebGLObject,
id: u32,
is_deleted: Cell<bool>,
linked: Cell<bool>,
fragment_shader: MutNullableHeap<JS<WebGLShader>>,
vertex_shader: MutNullableHeap<JS<WebGLShader>>,
#[ignore_heap_size_of = "Defined in ipc-channel"]
@@ -35,6 +36,7 @@ impl WebGLProgram {
webgl_object: WebGLObject::new_inherited(),
id: id,
is_deleted: Cell::new(false),
linked: Cell::new(false),
fragment_shader: Default::default(),
vertex_shader: Default::default(),
renderer: renderer,
@@ -71,19 +73,27 @@ impl WebGLProgram {

/// glLinkProgram
pub fn link(&self) {
self.renderer.send(CanvasMsg::WebGL(WebGLCommand::LinkProgram(self.id))).unwrap();
}
self.linked.set(false);

/// glUseProgram
pub fn use_program(&self) -> WebGLResult<()> {
match self.fragment_shader.get() {
Some(ref shader) if shader.successfully_compiled() => {},
_ => return Err(WebGLError::InvalidOperation),
_ => return,
}

match self.vertex_shader.get() {
Some(ref shader) if shader.successfully_compiled() => {},
_ => return Err(WebGLError::InvalidOperation),
_ => return,
}

self.linked.set(true);

self.renderer.send(CanvasMsg::WebGL(WebGLCommand::LinkProgram(self.id))).unwrap();
}

/// glUseProgram
pub fn use_program(&self) -> WebGLResult<()> {
if !self.linked.get() {
return Err(WebGLError::InvalidOperation);
}

self.renderer.send(CanvasMsg::WebGL(WebGLCommand::UseProgram(self.id))).unwrap();
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.