Make gl.useProgram(null) do the right thing

This commit is contained in:
Anthony Ramine 2018-07-05 09:40:22 +02:00
parent fc593c68c5
commit 15389586d9
5 changed files with 9 additions and 23 deletions

View file

@ -826,8 +826,6 @@ impl WebGLImpl {
ctx.gl().uniform_matrix_3fv(uniform_id, transpose, v), ctx.gl().uniform_matrix_3fv(uniform_id, transpose, v),
WebGLCommand::UniformMatrix4fv(uniform_id, transpose, ref v) => WebGLCommand::UniformMatrix4fv(uniform_id, transpose, ref v) =>
ctx.gl().uniform_matrix_4fv(uniform_id, transpose, v), ctx.gl().uniform_matrix_4fv(uniform_id, transpose, v),
WebGLCommand::UseProgram(program_id) =>
ctx.gl().use_program(program_id.get()),
WebGLCommand::ValidateProgram(program_id) => WebGLCommand::ValidateProgram(program_id) =>
ctx.gl().validate_program(program_id.get()), ctx.gl().validate_program(program_id.get()),
WebGLCommand::VertexAttrib(attrib_id, x, y, z, w) => WebGLCommand::VertexAttrib(attrib_id, x, y, z, w) =>
@ -965,6 +963,9 @@ impl WebGLImpl {
WebGLCommand::LinkProgram(program_id, ref sender) => { WebGLCommand::LinkProgram(program_id, ref sender) => {
return sender.send(Self::link_program(ctx.gl(), program_id)).unwrap(); return sender.send(Self::link_program(ctx.gl(), program_id)).unwrap();
} }
WebGLCommand::UseProgram(program_id) => {
ctx.gl().use_program(program_id.map_or(0, |p| p.get()))
}
} }
// TODO: update test expectations in order to enable debug assertions // TODO: update test expectations in order to enable debug assertions

View file

@ -249,7 +249,7 @@ pub enum WebGLCommand {
UniformMatrix2fv(i32, bool, Vec<f32>), UniformMatrix2fv(i32, bool, Vec<f32>),
UniformMatrix3fv(i32, bool, Vec<f32>), UniformMatrix3fv(i32, bool, Vec<f32>),
UniformMatrix4fv(i32, bool, Vec<f32>), UniformMatrix4fv(i32, bool, Vec<f32>),
UseProgram(WebGLProgramId), UseProgram(Option<WebGLProgramId>),
ValidateProgram(WebGLProgramId), ValidateProgram(WebGLProgramId),
VertexAttrib(u32, f32, f32, f32, f32), VertexAttrib(u32, f32, f32, f32, f32),
VertexAttribPointer(u32, i32, u32, bool, i32, u32), VertexAttribPointer(u32, i32, u32, bool, i32, u32),

View file

@ -130,19 +130,6 @@ impl WebGLProgram {
Ref::map(self.active_attribs.borrow(), |attribs| &**attribs) Ref::map(self.active_attribs.borrow(), |attribs| &**attribs)
} }
/// glUseProgram
pub fn use_program(&self) -> WebGLResult<()> {
if self.is_deleted() {
return Err(WebGLError::InvalidOperation);
}
if !self.linked.get() {
return Err(WebGLError::InvalidOperation);
}
self.renderer.send(WebGLCommand::UseProgram(self.id)).unwrap();
Ok(())
}
/// glValidateProgram /// glValidateProgram
pub fn validate(&self) -> WebGLResult<()> { pub fn validate(&self) -> WebGLResult<()> {
if self.is_deleted() { if self.is_deleted() {

View file

@ -2314,7 +2314,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
fn GetActiveAttrib(&self, program: &WebGLProgram, index: u32) -> Option<DomRoot<WebGLActiveInfo>> { fn GetActiveAttrib(&self, program: &WebGLProgram, index: u32) -> Option<DomRoot<WebGLActiveInfo>> {
handle_potential_webgl_error!(self, program.get_active_attrib(index), None) handle_potential_webgl_error!(self, program.get_active_attrib(index).map(Some), None)
} }
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
@ -3242,11 +3242,12 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9 // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn UseProgram(&self, program: Option<&WebGLProgram>) { fn UseProgram(&self, program: Option<&WebGLProgram>) {
if let Some(program) = program { if let Some(program) = program {
match program.use_program() { if program.is_deleted() || !program.is_linked() {
Ok(()) => self.current_program.set(Some(program)), return self.webgl_error(InvalidOperation);
Err(e) => self.webgl_error(e),
} }
} }
self.send_command(WebGLCommand::UseProgram(program.map(|p| p.id())));
self.current_program.set(program);
} }
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9 // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9

View file

@ -1,7 +1,4 @@
[program-test.html] [program-test.html]
[WebGL test #53: getError expected: INVALID_OPERATION. Was NO_ERROR : drawing with a null program should generate INVALID_OPERATION]
expected: FAIL
[WebGL test #64: getError expected: NO_ERROR. Was INVALID_OPERATION : delete the current program shouldn't change the current rendering state] [WebGL test #64: getError expected: NO_ERROR. Was INVALID_OPERATION : delete the current program shouldn't change the current rendering state]
expected: FAIL expected: FAIL