From abec4bb2d46b368a381e88688aae132812da58e8 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Tue, 1 Dec 2015 11:49:08 +1000 Subject: [PATCH] Various fixes and cleanups for android (mostly VAO related). --- src/device.rs | 590 +++++++++++++++++++----------------------------- src/renderer.rs | 30 ++- 2 files changed, 253 insertions(+), 367 deletions(-) diff --git a/src/device.rs b/src/device.rs index aedb82510c..f59bb8746b 100644 --- a/src/device.rs +++ b/src/device.rs @@ -50,11 +50,206 @@ pub enum TextureFilter { Linear, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum VertexFormat { Batch, DebugFont, DebugColor, + RasterOp, +} + +impl VertexFormat { + fn bind(&self) { + match *self { + VertexFormat::DebugFont => { + gl::enable_vertex_attrib_array(VertexAttribute::Position as gl::GLuint); + gl::enable_vertex_attrib_array(VertexAttribute::Color as gl::GLuint); + gl::enable_vertex_attrib_array(VertexAttribute::ColorTexCoord as gl::GLuint); + + let vertex_stride = mem::size_of::() as gl::GLint; + + gl::vertex_attrib_pointer(VertexAttribute::Position as gl::GLuint, + 2, + gl::FLOAT, + false, + vertex_stride, + 0); + gl::vertex_attrib_pointer(VertexAttribute::Color as gl::GLuint, + 4, + gl::UNSIGNED_BYTE, + true, + vertex_stride, + 8); + gl::vertex_attrib_pointer(VertexAttribute::ColorTexCoord as gl::GLuint, + 2, + gl::FLOAT, + false, + vertex_stride, + 12); + } + VertexFormat::DebugColor => { + gl::enable_vertex_attrib_array(VertexAttribute::Position as gl::GLuint); + gl::enable_vertex_attrib_array(VertexAttribute::Color as gl::GLuint); + + let vertex_stride = mem::size_of::() as gl::GLint; + + gl::vertex_attrib_pointer(VertexAttribute::Position as gl::GLuint, + 2, + gl::FLOAT, + false, + vertex_stride, + 0); + gl::vertex_attrib_pointer(VertexAttribute::Color as gl::GLuint, + 4, + gl::UNSIGNED_BYTE, + true, + vertex_stride, + 8); + } + VertexFormat::Batch => { + gl::enable_vertex_attrib_array(VertexAttribute::Position as gl::GLuint); + gl::enable_vertex_attrib_array(VertexAttribute::Color as gl::GLuint); + gl::enable_vertex_attrib_array(VertexAttribute::ColorTexCoord as gl::GLuint); + gl::enable_vertex_attrib_array(VertexAttribute::MaskTexCoord as gl::GLuint); + gl::enable_vertex_attrib_array(VertexAttribute::Misc as gl::GLuint); + + let vertex_stride = mem::size_of::() as gl::GLint; + + gl::vertex_attrib_pointer(VertexAttribute::Position as gl::GLuint, + 2, + gl::FLOAT, + false, + vertex_stride, + 0); + gl::vertex_attrib_pointer(VertexAttribute::Color as gl::GLuint, + 4, + gl::UNSIGNED_BYTE, + false, + vertex_stride, + 8); + gl::vertex_attrib_pointer(VertexAttribute::ColorTexCoord as gl::GLuint, + 2, + gl::FLOAT, + false, + vertex_stride, + 12); + gl::vertex_attrib_pointer(VertexAttribute::MaskTexCoord as gl::GLuint, + 2, + gl::UNSIGNED_SHORT, + false, + vertex_stride, + 20); + gl::vertex_attrib_pointer(VertexAttribute::Misc as gl::GLuint, + 4, + gl::UNSIGNED_BYTE, + false, + vertex_stride, + 24); + } + VertexFormat::RasterOp => { + gl::enable_vertex_attrib_array(VertexAttribute::Position as gl::GLuint); + gl::enable_vertex_attrib_array(VertexAttribute::Color as gl::GLuint); + gl::enable_vertex_attrib_array(VertexAttribute::ColorTexCoord as gl::GLuint); + gl::enable_vertex_attrib_array(VertexAttribute::BorderRadii as gl::GLuint); + gl::enable_vertex_attrib_array(VertexAttribute::BorderPosition as gl::GLuint); + gl::enable_vertex_attrib_array(VertexAttribute::BlurRadius as gl::GLuint); + gl::enable_vertex_attrib_array(VertexAttribute::DestTextureSize as gl::GLuint); + gl::enable_vertex_attrib_array(VertexAttribute::SourceTextureSize as gl::GLuint); + gl::enable_vertex_attrib_array(VertexAttribute::Misc as gl::GLuint); + + let vertex_stride = mem::size_of::() as gl::GLint; + + gl::vertex_attrib_pointer(VertexAttribute::Position as gl::GLuint, + 2, + gl::FLOAT, + false, + vertex_stride, + 0); + gl::vertex_attrib_pointer(VertexAttribute::Color as gl::GLuint, + 4, + gl::UNSIGNED_BYTE, + true, + vertex_stride, + 8); + gl::vertex_attrib_pointer(VertexAttribute::ColorTexCoord as gl::GLuint, + 2, + gl::UNSIGNED_SHORT, + true, + vertex_stride, + 12); + gl::vertex_attrib_pointer(VertexAttribute::BorderRadii as gl::GLuint, + 4, + gl::FLOAT, + false, + vertex_stride, + 16); + gl::vertex_attrib_pointer(VertexAttribute::BorderPosition as gl::GLuint, + 4, + gl::FLOAT, + false, + vertex_stride, + 32); + gl::vertex_attrib_pointer(VertexAttribute::DestTextureSize as gl::GLuint, + 2, + gl::FLOAT, + false, + vertex_stride, + 48); + gl::vertex_attrib_pointer(VertexAttribute::SourceTextureSize as gl::GLuint, + 2, + gl::FLOAT, + false, + vertex_stride, + 56); + gl::vertex_attrib_pointer(VertexAttribute::BlurRadius as gl::GLuint, + 1, + gl::FLOAT, + false, + vertex_stride, + 64); + gl::vertex_attrib_pointer(VertexAttribute::Misc as gl::GLuint, + 4, + gl::UNSIGNED_BYTE, + false, + vertex_stride, + 68); + } + } + } + + #[cfg(any(target_os = "android", target_os = "gonk"))] + fn unbind(&self) { + // TODO(gw): This can be made smarter by diffing the two vertex formats. + match *self { + VertexFormat::DebugFont => { + gl::disable_vertex_attrib_array(VertexAttribute::Position as gl::GLuint); + gl::disable_vertex_attrib_array(VertexAttribute::Color as gl::GLuint); + gl::disable_vertex_attrib_array(VertexAttribute::ColorTexCoord as gl::GLuint); + } + VertexFormat::DebugColor => { + gl::disable_vertex_attrib_array(VertexAttribute::Position as gl::GLuint); + gl::disable_vertex_attrib_array(VertexAttribute::Color as gl::GLuint); + } + VertexFormat::Batch => { + gl::disable_vertex_attrib_array(VertexAttribute::Position as gl::GLuint); + gl::disable_vertex_attrib_array(VertexAttribute::Color as gl::GLuint); + gl::disable_vertex_attrib_array(VertexAttribute::ColorTexCoord as gl::GLuint); + gl::disable_vertex_attrib_array(VertexAttribute::MaskTexCoord as gl::GLuint); + gl::disable_vertex_attrib_array(VertexAttribute::Misc as gl::GLuint); + } + VertexFormat::RasterOp => { + gl::disable_vertex_attrib_array(VertexAttribute::Position as gl::GLuint); + gl::disable_vertex_attrib_array(VertexAttribute::Color as gl::GLuint); + gl::disable_vertex_attrib_array(VertexAttribute::ColorTexCoord as gl::GLuint); + gl::disable_vertex_attrib_array(VertexAttribute::BorderRadii as gl::GLuint); + gl::disable_vertex_attrib_array(VertexAttribute::BorderPosition as gl::GLuint); + gl::disable_vertex_attrib_array(VertexAttribute::BlurRadius as gl::GLuint); + gl::disable_vertex_attrib_array(VertexAttribute::DestTextureSize as gl::GLuint); + gl::disable_vertex_attrib_array(VertexAttribute::SourceTextureSize as gl::GLuint); + gl::disable_vertex_attrib_array(VertexAttribute::Misc as gl::GLuint); + } + } + } } impl TextureId { @@ -93,7 +288,6 @@ impl FBOId { fn bind(&self) { let FBOId(id) = *self; gl::bind_framebuffer(gl::FRAMEBUFFER, id); - gl::bind_framebuffer(gl::READ_FRAMEBUFFER, id); } } @@ -128,6 +322,7 @@ impl Drop for Program { struct VAO { id: gl::GLuint, + vertex_format: VertexFormat, vbo_id: VBOId, ibo_id: IBOId, } @@ -328,16 +523,6 @@ impl Device { } } - #[cfg(any(target_os = "android", target_os = "gonk"))] - pub fn bind_color_texture_for_noncomposite_operation(&mut self, texture_id: TextureId) { - self.bind_color_texture(texture_id); - } - - #[cfg(not(any(target_os = "android", target_os = "gonk")))] - pub fn bind_color_texture_for_noncomposite_operation(&mut self, texture_id: TextureId) { - self.bind_color_texture(texture_id); - } - pub fn bind_mask_texture(&mut self, texture_id: TextureId) { debug_assert!(self.inside_frame); @@ -349,16 +534,6 @@ impl Device { } } - #[cfg(any(target_os = "android", target_os = "gonk"))] - pub fn bind_mask_texture_for_noncomposite_operation(&mut self, texture_id: TextureId) { - self.bind_mask_texture(texture_id); - } - - #[cfg(not(any(target_os = "android", target_os = "gonk")))] - pub fn bind_mask_texture_for_noncomposite_operation(&mut self, texture_id: TextureId) { - self.bind_mask_texture(texture_id); - } - pub fn bind_render_target(&mut self, texture_id: Option) { debug_assert!(self.inside_frame); @@ -768,10 +943,15 @@ impl Device { self.read_framebuffer_rect_for_2d_texture(texture_id, x, y, width, height) } - #[cfg(any(target_os = "android", target_os = "gonk"))] + #[cfg(not(any(target_os = "android", target_os = "gonk")))] fn clear_vertex_array(&mut self) { debug_assert!(self.inside_frame); + gl::bind_vertex_array(0); + } + #[cfg(any(target_os = "android", target_os = "gonk"))] + fn clear_vertex_array(&mut self) { + debug_assert!(self.inside_frame); gl::disable_vertex_attrib_array(VertexAttribute::Position as gl::GLuint); gl::disable_vertex_attrib_array(VertexAttribute::Color as gl::GLuint); gl::disable_vertex_attrib_array(VertexAttribute::ColorTexCoord as gl::GLuint); @@ -784,60 +964,8 @@ impl Device { gl::disable_vertex_attrib_array(VertexAttribute::Misc as gl::GLuint); } - #[cfg(any(target_os = "android", target_os = "gonk"))] - pub fn bind_vao(&mut self, vao_id: VAOId) { - debug_assert!(self.inside_frame); - - if self.bound_vao != vao_id { - self.bound_vao = vao_id; - - let vao = self.vaos.get(&vao_id).unwrap(); - vao.vbo_id.bind(); - vao.ibo_id.bind(); - - let vertex_stride = mem::size_of::() as gl::GLint; - - gl::enable_vertex_attrib_array(VertexAttribute::Position as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::Color as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::ColorTexCoord as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::MaskTexCoord as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::Misc as gl::GLuint); - - gl::vertex_attrib_pointer(VertexAttribute::Position as gl::GLuint, - 2, - gl::FLOAT, - false, - vertex_stride, - 0); - gl::vertex_attrib_pointer(VertexAttribute::Color as gl::GLuint, - 4, - gl::UNSIGNED_BYTE, - false, - vertex_stride, - 8); - gl::vertex_attrib_pointer(VertexAttribute::ColorTexCoord as gl::GLuint, - 2, - gl::FLOAT, - false, - vertex_stride, - 12); - gl::vertex_attrib_pointer(VertexAttribute::MaskTexCoord as gl::GLuint, - 2, - gl::UNSIGNED_SHORT, - false, - vertex_stride, - 20); - gl::vertex_attrib_pointer(VertexAttribute::Misc as gl::GLuint, - 4, - gl::UNSIGNED_BYTE, - false, - vertex_stride, - 24); - } - } - #[cfg(not(any(target_os = "android", target_os = "gonk")))] - pub fn bind_vao_for_texture_cache_update(&mut self, vao_id: VAOId) { + pub fn bind_vao(&mut self, vao_id: VAOId) { debug_assert!(self.inside_frame); if self.bound_vao != vao_id { @@ -849,89 +977,36 @@ impl Device { } #[cfg(any(target_os = "android", target_os = "gonk"))] - pub fn bind_vao_for_texture_cache_update(&mut self, vao_id: VAOId) { + pub fn bind_vao(&mut self, vao_id: VAOId) { debug_assert!(self.inside_frame); - if self.bound_vao == vao_id { - return - } + if self.bound_vao != vao_id { + let prev_vertex_format = self.vaos + .get(&self.bound_vao) + .map(|vao| vao.vertex_format); - self.bound_vao = vao_id; + let vao = self.vaos.get(&vao_id).unwrap(); + self.bound_vao = vao_id; - let vao = self.vaos.get(&vao_id).unwrap(); - vao.vbo_id.bind(); - vao.ibo_id.bind(); + match (prev_vertex_format, vao.vertex_format) { + (None, format) => { + format.bind(); + } + (Some(old_format), new_format) => { + if old_format != new_format { + old_format.unbind(); + new_format.bind(); + } + } + } - let vertex_stride = mem::size_of::() as gl::GLint; - - gl::enable_vertex_attrib_array(VertexAttribute::Position as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::Color as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::ColorTexCoord as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::BorderRadii as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::BorderPosition as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::BlurRadius as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::DestTextureSize as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::SourceTextureSize as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::Misc as gl::GLuint); - - gl::vertex_attrib_pointer(VertexAttribute::Position as gl::GLuint, - 2, - gl::FLOAT, - false, - vertex_stride, - 0); - gl::vertex_attrib_pointer(VertexAttribute::Color as gl::GLuint, - 4, - gl::UNSIGNED_BYTE, - true, - vertex_stride, - 8); - gl::vertex_attrib_pointer(VertexAttribute::ColorTexCoord as gl::GLuint, - 2, - gl::UNSIGNED_SHORT, - true, - vertex_stride, - 12); - gl::vertex_attrib_pointer(VertexAttribute::BorderRadii as gl::GLuint, - 4, - gl::FLOAT, - false, - vertex_stride, - 16); - gl::vertex_attrib_pointer(VertexAttribute::BorderPosition as gl::GLuint, - 4, - gl::FLOAT, - false, - vertex_stride, - 32); - gl::vertex_attrib_pointer(VertexAttribute::DestTextureSize as gl::GLuint, - 2, - gl::FLOAT, - false, - vertex_stride, - 48); - gl::vertex_attrib_pointer(VertexAttribute::SourceTextureSize as gl::GLuint, - 2, - gl::FLOAT, - false, - vertex_stride, - 56); - gl::vertex_attrib_pointer(VertexAttribute::BlurRadius as gl::GLuint, - 1, - gl::FLOAT, - false, - vertex_stride, - 64); - gl::vertex_attrib_pointer(VertexAttribute::Misc as gl::GLuint, - 4, - gl::UNSIGNED_BYTE, - false, - vertex_stride, - 68); + vao.vbo_id.bind(); + vao.ibo_id.bind(); + } } #[cfg(any(target_os = "android", target_os = "gonk"))] - pub fn create_vao(&mut self) -> VAOId { + pub fn create_vao(&mut self, format: VertexFormat) -> VAOId { debug_assert!(self.inside_frame); let vao_id = self.next_vao_id; @@ -945,7 +1020,8 @@ impl Device { let ibo_id = IBOId(ibo_id); let vao = VAO { - //id: vao_id, + id: vao_id, + vertex_format: format, vbo_id: vbo_id, ibo_id: ibo_id, }; @@ -958,30 +1034,12 @@ impl Device { vao_id } - #[cfg(not(any(target_os = "android", target_os = "gonk")))] - fn clear_vertex_array(&mut self) { - debug_assert!(self.inside_frame); - gl::bind_vertex_array(0); - } - - #[cfg(not(any(target_os = "android", target_os = "gonk")))] - pub fn bind_vao(&mut self, vao_id: VAOId) { - debug_assert!(self.inside_frame); - - if self.bound_vao != vao_id { - self.bound_vao = vao_id; - - let VAOId(id) = vao_id; - gl::bind_vertex_array(id); - } - } - #[cfg(not(any(target_os = "android", target_os = "gonk")))] pub fn create_vao(&mut self, format: VertexFormat) -> VAOId { debug_assert!(self.inside_frame); - let buffer_ids = gl::gen_buffers(2); let vao_ids = gl::gen_vertex_arrays(1); + let buffer_ids = gl::gen_buffers(2); let vbo_id = buffer_ids[0]; let ibo_id = buffer_ids[1]; @@ -991,206 +1049,20 @@ impl Device { gl::bind_buffer(gl::ARRAY_BUFFER, vbo_id); gl::bind_buffer(gl::ELEMENT_ARRAY_BUFFER, ibo_id); - match format { - VertexFormat::DebugFont => { - gl::enable_vertex_attrib_array(VertexAttribute::Position as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::Color as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::ColorTexCoord as gl::GLuint); - - let vertex_stride = mem::size_of::() as gl::GLint; - - gl::vertex_attrib_pointer(VertexAttribute::Position as gl::GLuint, - 2, - gl::FLOAT, - false, - vertex_stride, - 0); - gl::vertex_attrib_pointer(VertexAttribute::Color as gl::GLuint, - 4, - gl::UNSIGNED_BYTE, - true, - vertex_stride, - 8); - gl::vertex_attrib_pointer(VertexAttribute::ColorTexCoord as gl::GLuint, - 2, - gl::FLOAT, - false, - vertex_stride, - 12); - } - VertexFormat::DebugColor => { - gl::enable_vertex_attrib_array(VertexAttribute::Position as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::Color as gl::GLuint); - - let vertex_stride = mem::size_of::() as gl::GLint; - - gl::vertex_attrib_pointer(VertexAttribute::Position as gl::GLuint, - 2, - gl::FLOAT, - false, - vertex_stride, - 0); - gl::vertex_attrib_pointer(VertexAttribute::Color as gl::GLuint, - 4, - gl::UNSIGNED_BYTE, - true, - vertex_stride, - 8); - } - VertexFormat::Batch => { - gl::enable_vertex_attrib_array(VertexAttribute::Position as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::Color as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::ColorTexCoord as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::MaskTexCoord as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::Misc as gl::GLuint); - - let vertex_stride = mem::size_of::() as gl::GLint; - - gl::vertex_attrib_pointer(VertexAttribute::Position as gl::GLuint, - 2, - gl::FLOAT, - false, - vertex_stride, - 0); - gl::vertex_attrib_pointer(VertexAttribute::Color as gl::GLuint, - 4, - gl::UNSIGNED_BYTE, - false, - vertex_stride, - 8); - gl::vertex_attrib_pointer(VertexAttribute::ColorTexCoord as gl::GLuint, - 2, - gl::FLOAT, - false, - vertex_stride, - 12); - gl::vertex_attrib_pointer(VertexAttribute::MaskTexCoord as gl::GLuint, - 2, - gl::UNSIGNED_SHORT, - false, - vertex_stride, - 20); - gl::vertex_attrib_pointer(VertexAttribute::Misc as gl::GLuint, - 4, - gl::UNSIGNED_BYTE, - false, - vertex_stride, - 24); - } - } - - gl::bind_vertex_array(0); - let vbo_id = VBOId(vbo_id); let ibo_id = IBOId(ibo_id); let vao = VAO { id: vao_id, + vertex_format: format, vbo_id: vbo_id, ibo_id: ibo_id, }; - let vao_id = VAOId(vao_id); - - debug_assert!(self.vaos.contains_key(&vao_id) == false); - self.vaos.insert(vao_id, vao); - - vao_id - } - - #[cfg(not(any(target_os = "android", target_os = "gonk")))] - pub fn create_vao_for_texture_cache_update(&mut self) -> VAOId { - debug_assert!(self.inside_frame); - - let buffer_ids = gl::gen_buffers(2); - let vao_ids = gl::gen_vertex_arrays(1); - - let vbo_id = buffer_ids[0]; - let ibo_id = buffer_ids[1]; - let vao_id = vao_ids[0]; - - gl::bind_vertex_array(vao_id); - gl::bind_buffer(gl::ARRAY_BUFFER, vbo_id); - gl::bind_buffer(gl::ELEMENT_ARRAY_BUFFER, ibo_id); - - let vertex_stride = mem::size_of::() as gl::GLint; - - gl::enable_vertex_attrib_array(VertexAttribute::Position as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::Color as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::ColorTexCoord as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::BorderRadii as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::BorderPosition as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::BlurRadius as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::DestTextureSize as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::SourceTextureSize as gl::GLuint); - gl::enable_vertex_attrib_array(VertexAttribute::Misc as gl::GLuint); - - gl::vertex_attrib_pointer(VertexAttribute::Position as gl::GLuint, - 2, - gl::FLOAT, - false, - vertex_stride, - 0); - gl::vertex_attrib_pointer(VertexAttribute::Color as gl::GLuint, - 4, - gl::UNSIGNED_BYTE, - true, - vertex_stride, - 8); - gl::vertex_attrib_pointer(VertexAttribute::ColorTexCoord as gl::GLuint, - 2, - gl::UNSIGNED_SHORT, - true, - vertex_stride, - 12); - gl::vertex_attrib_pointer(VertexAttribute::BorderRadii as gl::GLuint, - 4, - gl::FLOAT, - false, - vertex_stride, - 16); - gl::vertex_attrib_pointer(VertexAttribute::BorderPosition as gl::GLuint, - 4, - gl::FLOAT, - false, - vertex_stride, - 32); - gl::vertex_attrib_pointer(VertexAttribute::DestTextureSize as gl::GLuint, - 2, - gl::FLOAT, - false, - vertex_stride, - 48); - gl::vertex_attrib_pointer(VertexAttribute::SourceTextureSize as gl::GLuint, - 2, - gl::FLOAT, - false, - vertex_stride, - 56); - gl::vertex_attrib_pointer(VertexAttribute::BlurRadius as gl::GLuint, - 1, - gl::FLOAT, - false, - vertex_stride, - 64); - gl::vertex_attrib_pointer(VertexAttribute::Misc as gl::GLuint, - 4, - gl::UNSIGNED_BYTE, - false, - vertex_stride, - 68); + vao.vertex_format.bind(); gl::bind_vertex_array(0); - let vbo_id = VBOId(vbo_id); - let ibo_id = IBOId(ibo_id); - - let vao = VAO { - id: vao_id, - vbo_id: vbo_id, - ibo_id: ibo_id, - }; - let vao_id = VAOId(vao_id); debug_assert!(self.vaos.contains_key(&vao_id) == false); diff --git a/src/renderer.rs b/src/renderer.rs index 7506e0bd9e..6172fccaec 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -32,6 +32,20 @@ use webrender_traits::{ImageFormat, MixBlendMode, RenderApiSender}; pub const BLUR_INFLATION_FACTOR: u32 = 3; +// TODO(gw): HACK! Need to support lighten/darken mix-blend-mode properly on android... + +#[cfg(not(any(target_os = "android", target_os = "gonk")))] +const GL_BLEND_MIN: gl::GLuint = gl::MIN; + +#[cfg(any(target_os = "android", target_os = "gonk"))] +const GL_BLEND_MIN: gl::GLuint = gl::FUNC_ADD; + +#[cfg(not(any(target_os = "android", target_os = "gonk")))] +const GL_BLEND_MAX: gl::GLuint = gl::MAX; + +#[cfg(any(target_os = "android", target_os = "gonk"))] +const GL_BLEND_MAX: gl::GLuint = gl::FUNC_ADD; + struct VertexBuffer { vao_id: VAOId, } @@ -767,8 +781,8 @@ impl Renderer { self.device.bind_program(program_id, &projection); - self.device.bind_color_texture_for_noncomposite_operation(color_texture_id); - self.device.bind_mask_texture_for_noncomposite_operation(TextureId(0)); + self.device.bind_color_texture(color_texture_id); + self.device.bind_mask_texture(TextureId(0)); match blur_direction { Some(AxisDirection::Horizontal) => { @@ -782,8 +796,8 @@ impl Renderer { } fn perform_gl_texture_cache_update(&mut self, batch: RasterBatch) { - let vao_id = self.device.create_vao_for_texture_cache_update(); - self.device.bind_vao_for_texture_cache_update(vao_id); + let vao_id = self.device.create_vao(VertexFormat::RasterOp); + self.device.bind_vao(vao_id); self.device.update_vao_indices(vao_id, &batch.indices[..], VertexUsageHint::Dynamic); self.device.update_vao_vertices(vao_id, &batch.vertices[..], VertexUsageHint::Dynamic); @@ -885,8 +899,8 @@ impl Renderer { &floats); } - self.device.bind_mask_texture_for_noncomposite_operation(draw_call.mask_texture_id); - self.device.bind_color_texture_for_noncomposite_operation(draw_call.color_texture_id); + self.device.bind_mask_texture(draw_call.mask_texture_id); + self.device.bind_color_texture(draw_call.color_texture_id); // TODO(gw): Although a minor cost, this is an extra hashtable lookup for every // draw call, when the batch textures are (almost) always the same. @@ -1057,12 +1071,12 @@ impl Renderer { } CompositionOp::MixBlend(MixBlendMode::Darken) => { gl::blend_func(gl::ONE, gl::ONE); - gl::blend_equation(gl::MIN); + gl::blend_equation(GL_BLEND_MIN); alpha = 1.0; } CompositionOp::MixBlend(MixBlendMode::Lighten) => { gl::blend_func(gl::ONE, gl::ONE); - gl::blend_equation(gl::MAX); + gl::blend_equation(GL_BLEND_MAX); alpha = 1.0; } _ => unreachable!(),