diff options
author | ecoal95 <ecoal95@gmail.com> | 2015-06-14 22:55:50 +0200 |
---|---|---|
committer | ecoal95 <ecoal95@gmail.com> | 2015-07-06 19:54:05 +0200 |
commit | b1765c68821d12a21cd304f7dffaa3bdc8f101e4 (patch) | |
tree | d98d8aa769e2894c5ffee3e8597ed93945d4bbed /components/canvas/webgl_paint_task.rs | |
parent | c0222628264423a67bf98775be83dcf2f85211ab (diff) | |
download | servo-b1765c68821d12a21cd304f7dffaa3bdc8f101e4.tar.gz servo-b1765c68821d12a21cd304f7dffaa3bdc8f101e4.zip |
webgl: Refactor implementation to move logic inside the DOM interfaces
This improves the encapsulation and consistency in our WebGL
implementation.
Also allows to implement new methods such as `getShaderSource()`.
It will also allow us to use `delete()` in the destructors of them (note
that we will want to keep track of them from the context).
Diffstat (limited to 'components/canvas/webgl_paint_task.rs')
-rw-r--r-- | components/canvas/webgl_paint_task.rs | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/components/canvas/webgl_paint_task.rs b/components/canvas/webgl_paint_task.rs index 24258954c1e..4f6e0605dd8 100644 --- a/components/canvas/webgl_paint_task.rs +++ b/components/canvas/webgl_paint_task.rs @@ -361,19 +361,35 @@ impl WebGLPaintTask { gl::enable_vertex_attrib_array(attrib_id); } - fn get_attrib_location(&self, program_id: u32, name: String, chan: Sender<i32> ) { + fn get_attrib_location(&self, program_id: u32, name: String, chan: Sender<Option<i32>> ) { let attrib_location = gl::get_attrib_location(program_id, &name); + + let attrib_location = if attrib_location == -1 { + None + } else { + Some(attrib_location) + }; + chan.send(attrib_location).unwrap(); } - fn get_shader_info_log(&self, shader_id: u32, chan: Sender<String>) { + fn get_shader_info_log(&self, shader_id: u32, chan: Sender<Option<String>>) { + // TODO(ecoal95): Right now we always return a value, we should + // check for gl errors and return None there let info = gl::get_shader_info_log(shader_id); - chan.send(info).unwrap(); + chan.send(Some(info)).unwrap(); } - fn get_shader_parameter(&self, shader_id: u32, param_id: u32, chan: Sender<i32>) { - let parameter = gl::get_shader_iv(shader_id, param_id); - chan.send(parameter as i32).unwrap(); + fn get_shader_parameter(&self, shader_id: u32, param_id: u32, chan: Sender<WebGLShaderParameter>) { + let result = match param_id { + gl::SHADER_TYPE => + WebGLShaderParameter::Int(gl::get_shader_iv(shader_id, param_id)), + gl::DELETE_STATUS | gl::COMPILE_STATUS => + WebGLShaderParameter::Bool(gl::get_shader_iv(shader_id, param_id) != 0), + _ => panic!("Unexpected shader parameter type"), + }; + + chan.send(result).unwrap(); } fn get_uniform_location(&self, program_id: u32, name: String, chan: Sender<Option<i32>>) { |