diff --git a/res/blend.fs.glsl b/res/blend.fs.glsl index fab8c5164f..f2b201a0d2 100644 --- a/res/blend.fs.glsl +++ b/res/blend.fs.glsl @@ -141,8 +141,8 @@ vec3 Luminosity(vec3 Cb, vec3 Cs) { void main(void) { - vec3 Cs = Texture2D(sDiffuse2D, vColorTexCoord.xy).xyz; - vec3 Cb = Texture2D(sMask2D, vMaskTexCoord.xy).xyz; + vec3 Cs = Texture(sDiffuse, vColorTexCoord).xyz; + vec3 Cb = Texture(sMask, vMaskTexCoord).xyz; // TODO: Relies on the ordering of MixBlendMode enum! // TODO: May be best to have separate shaders (esp. on Tegra) diff --git a/res/blend.vs.glsl b/res/blend.vs.glsl index 4814a7a326..405c7184bb 100644 --- a/res/blend.vs.glsl +++ b/res/blend.vs.glsl @@ -1,6 +1,6 @@ void main(void) { - vColorTexCoord = vec3(aColorTexCoord, 0.0); - vMaskTexCoord = vec3(aMaskTexCoord / 65535.0, 0.0); + vColorTexCoord = aColorTexCoord; + vMaskTexCoord = aMaskTexCoord / 65535.0; gl_Position = uTransform * vec4(aPosition, 1.0); } diff --git a/res/blit.fs.glsl b/res/blit.fs.glsl index 8cd9bbb040..9e9c35ee9c 100644 --- a/res/blit.fs.glsl +++ b/res/blit.fs.glsl @@ -1,5 +1,5 @@ void main(void) { - vec4 diffuse = Texture2D(sDiffuse2D, vColorTexCoord.xy); + vec4 diffuse = Texture(sDiffuse, vColorTexCoord.xy); SetFragColor(diffuse * vColor); } diff --git a/res/blit.vs.glsl b/res/blit.vs.glsl index 47d5551336..d64135b04c 100644 --- a/res/blit.vs.glsl +++ b/res/blit.vs.glsl @@ -1,7 +1,7 @@ void main(void) { vColor = aColor / 255.0; - vColorTexCoord = vec3(aColorTexCoord.xy, aMisc.y); + vColorTexCoord = aColorTexCoord; vec4 pos = vec4(aPosition, 1.0); pos.xy = floor(pos.xy * uDevicePixelRatio + 0.5) / uDevicePixelRatio; gl_Position = uTransform * pos; diff --git a/res/blur.fs.glsl b/res/blur.fs.glsl index 8ceeac3337..555597c139 100644 --- a/res/blur.fs.glsl +++ b/res/blur.fs.glsl @@ -20,8 +20,7 @@ void main(void) { lColorTexCoord.x <= 1.0 && lColorTexCoord.y >= 0.0 && lColorTexCoord.y <= 1.0 ? - Texture(sDiffuse, vec3(lColorTexCoord * sourceTextureUvSize + sourceTextureUvOrigin, - vColorTexCoord.z)).r : + Texture(sDiffuse, lColorTexCoord * sourceTextureUvSize + sourceTextureUvOrigin).r : 0.0; value += x * gauss(offsetF, sigma); } diff --git a/res/blur.vs.glsl b/res/blur.vs.glsl index d14a170656..4307ee9987 100644 --- a/res/blur.vs.glsl +++ b/res/blur.vs.glsl @@ -1,6 +1,6 @@ void main(void) { - vColorTexCoord = vec3(aColorTexCoord, aMisc.y); + vColorTexCoord = aColorTexCoord; vBorderPosition = aBorderPosition; vBlurRadius = aBlurRadius; vDestTextureSize = aDestTextureSize; diff --git a/res/es2_common.fs.glsl b/res/es2_common.fs.glsl index 22b57add64..d170041542 100644 --- a/res/es2_common.fs.glsl +++ b/res/es2_common.fs.glsl @@ -2,8 +2,6 @@ uniform sampler2D sDiffuse; uniform sampler2D sMask; -uniform sampler2D sDiffuse2D; -uniform sampler2D sMask2D; uniform vec4 uBlendParams; uniform vec4 uAtlasParams; uniform vec2 uDirection; @@ -11,8 +9,8 @@ uniform vec4 uFilterParams; varying vec2 vPosition; varying vec4 vColor; -varying vec3 vColorTexCoord; -varying vec3 vMaskTexCoord; +varying vec2 vColorTexCoord; +varying vec2 vMaskTexCoord; varying vec4 vBorderPosition; varying vec4 vBorderRadii; varying vec2 vDestTextureSize; @@ -20,12 +18,8 @@ varying vec2 vSourceTextureSize; varying float vBlurRadius; varying vec4 vTileParams; -vec4 Texture(sampler2D sampler, vec3 texCoord) { - return texture2D(sampler, texCoord.xy); -} - -vec4 Texture2D(sampler2D sampler, vec2 texCoord) { - return texture(sampler, texCoord); +vec4 Texture(sampler2D sampler, vec2 texCoord) { + return texture2D(sampler, texCoord); } float GetAlphaFromMask(vec4 mask) { diff --git a/res/es2_common.vs.glsl b/res/es2_common.vs.glsl index 2a0e0663f4..821842761f 100644 --- a/res/es2_common.vs.glsl +++ b/res/es2_common.vs.glsl @@ -17,12 +17,12 @@ attribute vec4 aBorderRadii; attribute vec2 aSourceTextureSize; attribute vec2 aDestTextureSize; attribute float aBlurRadius; -attribute vec4 aMisc; // x = matrix index; y = color tex index; z = mask tex index; w=tile params index +attribute vec4 aMisc; // x = matrix index; w = tile params index varying vec2 vPosition; varying vec4 vColor; -varying vec3 vColorTexCoord; -varying vec3 vMaskTexCoord; +varying vec2 vColorTexCoord; +varying vec2 vMaskTexCoord; varying vec4 vBorderPosition; varying vec4 vBorderRadii; varying vec2 vDestTextureSize; diff --git a/res/filter.fs.glsl b/res/filter.fs.glsl index e40798b6ce..35a7809988 100644 --- a/res/filter.fs.glsl +++ b/res/filter.fs.glsl @@ -61,7 +61,7 @@ vec4 Blur(float radius, vec2 direction) { texCoord.x <= 1.0 && texCoord.y >= 0.0 && texCoord.y <= 1.0 ? - Texture2D(sDiffuse2D, texCoord) : + Texture(sDiffuse, texCoord) : vec4(0.0); color += x * gauss(offsetF, sigma); } @@ -115,7 +115,7 @@ void main(void) // Gaussian blur is specially handled: result = Blur(amount, uFilterParams.zw); } else { - vec4 Cs = Texture2D(sDiffuse2D, vColorTexCoord.xy); + vec4 Cs = Texture(sDiffuse, vColorTexCoord); if (filterOp == 1) { result = Contrast(Cs, amount); diff --git a/res/filter.vs.glsl b/res/filter.vs.glsl index 7d9eb2e011..ea1d9e621f 100644 --- a/res/filter.vs.glsl +++ b/res/filter.vs.glsl @@ -1,7 +1,7 @@ void main(void) { - vColorTexCoord = vec3(aColorTexCoord, 0.0); - vMaskTexCoord = vec3(aMaskTexCoord, 0.0); + vColorTexCoord = aColorTexCoord; + vMaskTexCoord = aMaskTexCoord; gl_Position = uTransform * vec4(aPosition, 1.0); } diff --git a/res/gl3_common.fs.glsl b/res/gl3_common.fs.glsl index e485c665d3..b71f38e880 100644 --- a/res/gl3_common.fs.glsl +++ b/res/gl3_common.fs.glsl @@ -1,9 +1,7 @@ #version 150 -uniform sampler2DArray sDiffuse; -uniform sampler2DArray sMask; -uniform sampler2D sDiffuse2D; -uniform sampler2D sMask2D; +uniform sampler2D sDiffuse; +uniform sampler2D sMask; uniform vec4 uBlendParams; uniform vec4 uAtlasParams; uniform vec2 uDirection; @@ -11,8 +9,8 @@ uniform vec4 uFilterParams; in vec2 vPosition; in vec4 vColor; -in vec3 vColorTexCoord; -in vec3 vMaskTexCoord; +in vec2 vColorTexCoord; +in vec2 vMaskTexCoord; in vec4 vBorderPosition; in vec4 vBorderRadii; in vec2 vDestTextureSize; @@ -22,11 +20,7 @@ in vec4 vTileParams; out vec4 oFragColor; -vec4 Texture(sampler2DArray sampler, vec3 texCoord) { - return texture(sampler, texCoord); -} - -vec4 Texture2D(sampler2D sampler, vec2 texCoord) { +vec4 Texture(sampler2D sampler, vec2 texCoord) { return texture(sampler, texCoord); } diff --git a/res/gl3_common.vs.glsl b/res/gl3_common.vs.glsl index ecc1e8577a..7f236a0087 100644 --- a/res/gl3_common.vs.glsl +++ b/res/gl3_common.vs.glsl @@ -17,12 +17,12 @@ in vec4 aBorderRadii; in vec2 aSourceTextureSize; in vec2 aDestTextureSize; in float aBlurRadius; -in vec4 aMisc; // x = matrix index; y = color tex index; z = mask tex index; w=tile params index +in vec4 aMisc; // x = matrix index; w = tile params index out vec2 vPosition; out vec4 vColor; -out vec3 vColorTexCoord; -out vec3 vMaskTexCoord; +out vec2 vColorTexCoord; +out vec2 vMaskTexCoord; out vec4 vBorderPosition; out vec4 vBorderRadii; out vec2 vDestTextureSize; diff --git a/res/quad.fs.glsl b/res/quad.fs.glsl index cd6e97e775..fd9a81610b 100644 --- a/res/quad.fs.glsl +++ b/res/quad.fs.glsl @@ -15,8 +15,8 @@ void main(void) vec2 snappedMaskTexCoord = dMask + floor(maskTexCoord * uAtlasParams.zw) / uAtlasParams.zw; // Fetch the diffuse and mask texels. - vec4 diffuse = Texture(sDiffuse, vec3(snappedColorTexCoord, vColorTexCoord.z)); - vec4 mask = Texture(sMask, vec3(snappedMaskTexCoord, vMaskTexCoord.z)); + vec4 diffuse = Texture(sDiffuse, snappedColorTexCoord); + vec4 mask = Texture(sMask, snappedMaskTexCoord); // Extract alpha from the mask (component depends on platform) float alpha = GetAlphaFromMask(mask); diff --git a/res/quad.vs.glsl b/res/quad.vs.glsl index a1a1816dbd..027e1fe672 100644 --- a/res/quad.vs.glsl +++ b/res/quad.vs.glsl @@ -9,12 +9,12 @@ void main(void) vTileParams = uTileParams[int(aMisc.w)]; // Normalize the mask texture coordinates. - vec2 maskTexCoord = aMaskTexCoord.xy / 65535.0; - vec2 colorTexCoord = aColorTexCoord.xy; + vec2 maskTexCoord = aMaskTexCoord / 65535.0; + vec2 colorTexCoord = aColorTexCoord; // Pass through the color and mask texture coordinates to fragment shader - vColorTexCoord = vec3(colorTexCoord, aMisc.y); - vMaskTexCoord = vec3(maskTexCoord, aMisc.z); + vColorTexCoord = colorTexCoord; + vMaskTexCoord = maskTexCoord; // Extract the complete (stacking context + css transform) transform // for this vertex. Transform the position by it. diff --git a/res/tile.fs.glsl b/res/tile.fs.glsl index 023793f703..a4930edf8c 100644 --- a/res/tile.fs.glsl +++ b/res/tile.fs.glsl @@ -1,7 +1,6 @@ void main(void) { vec2 textureSize = vBorderPosition.zw - vBorderPosition.xy; - vec3 colorTexCoord = vec3(vBorderPosition.xy + mod(vColorTexCoord.xy, 1.0) * textureSize, - vColorTexCoord.z); + vec2 colorTexCoord = vBorderPosition.xy + mod(vColorTexCoord.xy, 1.0) * textureSize; vec4 diffuse = Texture(sDiffuse, colorTexCoord); SetFragColor(diffuse); } diff --git a/res/tile.vs.glsl b/res/tile.vs.glsl index 7d26996c51..f29930aeee 100644 --- a/res/tile.vs.glsl +++ b/res/tile.vs.glsl @@ -1,6 +1,6 @@ void main(void) { - vColorTexCoord = vec3(aBorderRadii.xy, aMisc.y); + vColorTexCoord = aBorderRadii.xy; vBorderPosition = aBorderPosition; gl_Position = uTransform * vec4(aPosition, 1.0); } diff --git a/src/batch.rs b/src/batch.rs index 3c68a33a86..4bb71fc41e 100644 --- a/src/batch.rs +++ b/src/batch.rs @@ -1,4 +1,4 @@ -use device::{ProgramId, TextureId, TextureIndex}; +use device::{ProgramId, TextureId}; use internal_types::{BlurDirection, PackedVertex}; use internal_types::{PackedVertexForTextureCacheUpdate, Primitive}; use std::sync::atomic::Ordering::SeqCst; @@ -209,7 +209,6 @@ pub struct RasterBatch { pub program_id: ProgramId, pub blur_direction: Option, pub dest_texture_id: TextureId, - pub dest_texture_index: TextureIndex, pub color_texture_id: TextureId, pub vertices: Vec, pub indices: Vec, @@ -219,7 +218,6 @@ impl RasterBatch { pub fn new(program_id: ProgramId, blur_direction: Option, dest_texture_id: TextureId, - dest_texture_index: TextureIndex, color_texture_id: TextureId) -> RasterBatch { debug_assert!(dest_texture_id != color_texture_id); @@ -227,7 +225,6 @@ impl RasterBatch { program_id: program_id, blur_direction: blur_direction, dest_texture_id: dest_texture_id, - dest_texture_index: dest_texture_index, color_texture_id: color_texture_id, vertices: Vec::new(), indices: Vec::new(), @@ -236,7 +233,6 @@ impl RasterBatch { pub fn can_add_to_batch(&self, dest_texture_id: TextureId, - dest_texture_index: TextureIndex, color_texture_id: TextureId, program_id: ProgramId, blur_direction: Option) @@ -244,16 +240,13 @@ impl RasterBatch { let batch_ok = program_id == self.program_id && blur_direction == self.blur_direction && dest_texture_id == self.dest_texture_id && - dest_texture_index == self.dest_texture_index && color_texture_id == self.color_texture_id; println!("batch ok? {:?} program_id={:?}/{:?} blur_direction={:?}/{:?} \ - dest_texture_id {:?}/{:?} dest_texture_index {:?}/{:?} \ - color_texture_id={:?}/{:?}", + dest_texture_id {:?}/{:?} color_texture_id={:?}/{:?}", batch_ok, program_id, self.program_id, blur_direction, self.blur_direction, dest_texture_id, self.dest_texture_id, - dest_texture_index, self.dest_texture_index, color_texture_id, self.color_texture_id); batch_ok } diff --git a/src/batch_builder.rs b/src/batch_builder.rs index 9a4a558d70..3503f78a8a 100644 --- a/src/batch_builder.rs +++ b/src/batch_builder.rs @@ -1,7 +1,7 @@ use app_units::Au; use batch::{BatchBuilder, MatrixIndex, TileParams}; use clipper::{self, ClipBuffers, Polygon}; -use device::{TextureId, TextureIndex}; +use device::TextureId; use euclid::{Rect, Point2D, Size2D}; use fnv::FnvHasher; use internal_types::{CombinedClipRegion, RectPosUv}; @@ -100,9 +100,7 @@ impl<'a> BatchBuilder<'a> { for clip_region in clip_buffers.rect_pos_uv.clip_rect_to_region_result_output.drain(..) { let mask = mask_for_clip_region(resource_cache, &clip_region, false); let colors = [*color, *color, *color, *color]; - let mut vertices = clip_region.make_packed_vertices_for_rect(&colors, - mask, - image_info.texture_index); + let mut vertices = clip_region.make_packed_vertices_for_rect(&colors, mask); self.add_draw_item(matrix_index, image_info.texture_id, @@ -136,7 +134,7 @@ impl<'a> BatchBuilder<'a> { let mut glyph_key = GlyphKey::new(font_key, size, blur_radius, glyphs[0].index); let blur_offset = blur_radius.to_f32_px() * (BLUR_INFLATION_FACTOR as f32) / 2.0; - let mut text_batches: HashMap<(TextureId, TextureIndex), Vec, DefaultState> = + let mut text_batches: HashMap, DefaultState> = HashMap::with_hash_state(Default::default()); for glyph in glyphs { @@ -154,14 +152,9 @@ impl<'a> BatchBuilder<'a> { uv: image_info.uv_rect, }; - let rect_buffer = match text_batches.entry((image_info.texture_id, - image_info.texture_index)) { - Occupied(entry) => { - entry.into_mut() - } - Vacant(entry) => { - entry.insert(Vec::new()) - } + let rect_buffer = match text_batches.entry(image_info.texture_id) { + Occupied(entry) => entry.into_mut(), + Vacant(entry) => entry.insert(Vec::new()), }; rect_buffer.push(rect); @@ -169,7 +162,7 @@ impl<'a> BatchBuilder<'a> { } let mut vertex_buffer = Vec::new(); - for ((texture_id, texture_index), mut rect_buffer) in text_batches { + for (texture_id, mut rect_buffer) in text_batches { let rect_buffer = if need_text_clip { let mut clipped_rects = Vec::new(); for rect in rect_buffer.drain(..) { @@ -194,30 +187,26 @@ impl<'a> BatchBuilder<'a> { x0, y0, color, rect.uv.top_left.x, rect.uv.top_left.y, - dummy_mask_image.uv_rect.top_left.x, dummy_mask_image.uv_rect.top_left.y, - texture_index, - dummy_mask_image.texture_index)); + dummy_mask_image.uv_rect.top_left.x, + dummy_mask_image.uv_rect.top_left.y)); vertex_buffer.push(PackedVertex::from_components( x1, y0, color, rect.uv.top_right.x, rect.uv.top_right.y, - dummy_mask_image.uv_rect.top_right.x, dummy_mask_image.uv_rect.top_right.y, - texture_index, - dummy_mask_image.texture_index)); + dummy_mask_image.uv_rect.top_right.x, + dummy_mask_image.uv_rect.top_right.y)); vertex_buffer.push(PackedVertex::from_components( x0, y1, color, rect.uv.bottom_left.x, rect.uv.bottom_left.y, - dummy_mask_image.uv_rect.bottom_left.x, dummy_mask_image.uv_rect.bottom_left.y, - texture_index, - dummy_mask_image.texture_index)); + dummy_mask_image.uv_rect.bottom_left.x, + dummy_mask_image.uv_rect.bottom_left.y)); vertex_buffer.push(PackedVertex::from_components( x1, y1, color, rect.uv.bottom_right.x, rect.uv.bottom_right.y, - dummy_mask_image.uv_rect.bottom_right.x, dummy_mask_image.uv_rect.bottom_right.y, - texture_index, - dummy_mask_image.texture_index)); + dummy_mask_image.uv_rect.bottom_right.x, + dummy_mask_image.uv_rect.bottom_right.y)); } self.add_draw_item(matrix_index, @@ -272,9 +261,7 @@ impl<'a> BatchBuilder<'a> { for clip_region in clip_buffers.rect_pos_uv.clip_rect_to_region_result_output.drain(..) { let mask = mask_for_clip_region(resource_cache, &clip_region, false); - let mut vertices = clip_region.make_packed_vertices_for_rect(colors, - mask, - image_info.texture_index); + let mut vertices = clip_region.make_packed_vertices_for_rect(colors, mask); self.add_draw_item(matrix_index, image_info.texture_id, @@ -358,12 +345,10 @@ impl<'a> BatchBuilder<'a> { let mut packed_vertices = Vec::new(); if clip_result.rect_result.vertices.len() >= 3 { for vert in clip_result.rect_result.vertices.iter() { - packed_vertices.push(clip_result.make_packed_vertex( - &vert.position(), - &vert.uv(), - &vert.color(), - &mask, - white_image.texture_index)); + packed_vertices.push(clip_result.make_packed_vertex(&vert.position(), + &vert.uv(), + &vert.color(), + &mask)); } } @@ -1007,42 +992,12 @@ impl<'a> BatchBuilder<'a> { } let mut vertices = [ - PackedVertex::from_components(v0.x, v0.y, - color0, - 0.0, 0.0, - muv0.x, muv0.y, - white_image.texture_index, - mask_image.texture_index), - PackedVertex::from_components(v1.x, v1.y, - color0, - 0.0, 0.0, - muv2.x, muv2.y, - white_image.texture_index, - mask_image.texture_index), - PackedVertex::from_components(v0.x, v1.y, - color0, - 0.0, 0.0, - muv3.x, muv3.y, - white_image.texture_index, - mask_image.texture_index), - PackedVertex::from_components(v0.x, v0.y, - color1, - 0.0, 0.0, - muv0.x, muv0.y, - white_image.texture_index, - mask_image.texture_index), - PackedVertex::from_components(v1.x, v0.y, - color1, - 0.0, 0.0, - muv1.x, muv1.y, - white_image.texture_index, - mask_image.texture_index), - PackedVertex::from_components(v1.x, v1.y, - color1, - 0.0, 0.0, - muv2.x, muv2.y, - white_image.texture_index, - mask_image.texture_index), + PackedVertex::from_components(v0.x, v0.y, color0, 0.0, 0.0, muv0.x, muv0.y), + PackedVertex::from_components(v1.x, v1.y, color0, 0.0, 0.0, muv2.x, muv2.y), + PackedVertex::from_components(v0.x, v1.y, color0, 0.0, 0.0, muv3.x, muv3.y), + PackedVertex::from_components(v0.x, v0.y, color1, 0.0, 0.0, muv0.x, muv0.y), + PackedVertex::from_components(v1.x, v0.y, color1, 0.0, 0.0, muv1.x, muv1.y), + PackedVertex::from_components(v1.x, v1.y, color1, 0.0, 0.0, muv2.x, muv2.y), ]; self.add_draw_item(matrix_index, @@ -1085,9 +1040,7 @@ impl<'a> BatchBuilder<'a> { &clip_region, false); let colors = [*color0, *color0, *color1, *color1]; - let mut vertices = clip_region.make_packed_vertices_for_rect(&colors, - mask, - color_image.texture_index); + let mut vertices = clip_region.make_packed_vertices_for_rect(&colors, mask); self.add_draw_item(matrix_index, color_image.texture_id, diff --git a/src/device.rs b/src/device.rs index 80b0303d09..af425ce52c 100644 --- a/src/device.rs +++ b/src/device.rs @@ -2,7 +2,7 @@ use euclid::Matrix4; use fnv::FnvHasher; use gleam::gl; use internal_types::{PackedVertex, PackedVertexForTextureCacheUpdate, RenderTargetMode}; -use internal_types::{TextureSampler, TextureTarget, VertexAttribute}; +use internal_types::{TextureSampler, VertexAttribute}; use std::collections::HashMap; use std::collections::hash_state::DefaultState; use std::fs::File; @@ -50,9 +50,9 @@ pub enum TextureFilter { } impl TextureId { - fn bind(&self, target: TextureTarget) { + fn bind(&self) { let TextureId(id) = *self; - gl::bind_texture(target.to_gl(), id); + gl::bind_texture(gl::TEXTURE_2D, id); } pub fn invalid() -> TextureId { @@ -151,9 +151,6 @@ impl Drop for VAO { #[derive(PartialEq, Eq, Hash, Debug, Copy, Clone)] pub struct TextureId(pub gl::GLuint); // TODO: HACK: Should not be public! -#[derive(PartialEq, Eq, Hash, Debug, Copy, Clone)] -pub struct TextureIndex(pub u8); - #[derive(PartialEq, Eq, Hash, Debug, Copy, Clone)] pub struct ProgramId(gl::GLuint); @@ -278,14 +275,6 @@ impl Device { id } - #[cfg(any(target_os = "android", target_os = "gonk"))] - fn unbind_2d_texture_array(&mut self) {} - - #[cfg(not(any(target_os = "android", target_os = "gonk")))] - fn unbind_2d_texture_array(&mut self) { - gl::bind_texture(gl::TEXTURE_2D_ARRAY, 0); - } - pub fn begin_frame(&mut self) { debug_assert!(!self.inside_frame); self.inside_frame = true; @@ -299,12 +288,10 @@ impl Device { self.bound_color_texture = TextureId(0); gl::active_texture(gl::TEXTURE0); gl::bind_texture(gl::TEXTURE_2D, 0); - self.unbind_2d_texture_array(); self.bound_mask_texture = TextureId(0); gl::active_texture(gl::TEXTURE1); gl::bind_texture(gl::TEXTURE_2D, 0); - self.unbind_2d_texture_array(); // Shader state self.bound_program = ProgramId(0); @@ -324,54 +311,51 @@ impl Device { gl::active_texture(gl::TEXTURE0); } - pub fn bind_color_texture(&mut self, target: TextureTarget, texture_id: TextureId) { + pub fn bind_color_texture(&mut self, texture_id: TextureId) { debug_assert!(self.inside_frame); if self.bound_color_texture != texture_id { self.bound_color_texture = texture_id; - texture_id.bind(target); + texture_id.bind(); } } #[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(TextureTarget::Texture2D, texture_id); + 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(TextureTarget::TextureArray, texture_id); + self.bind_color_texture(texture_id); } - pub fn bind_mask_texture(&mut self, target: TextureTarget, texture_id: TextureId) { + pub fn bind_mask_texture(&mut self, texture_id: TextureId) { debug_assert!(self.inside_frame); if self.bound_mask_texture != texture_id { self.bound_mask_texture = texture_id; gl::active_texture(gl::TEXTURE1); - texture_id.bind(target); + texture_id.bind(); gl::active_texture(gl::TEXTURE0); } } #[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(TextureTarget::Texture2D, texture_id); + 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(TextureTarget::TextureArray, texture_id); + self.bind_mask_texture(texture_id); } - pub fn bind_render_target(&mut self, texture_id_and_index: Option<(TextureId, TextureIndex)>) { + pub fn bind_render_target(&mut self, texture_id: Option) { debug_assert!(self.inside_frame); - let fbo_id = texture_id_and_index.map_or(FBOId(self.default_fbo), |texture_id_and_index| { - self.textures - .get(&texture_id_and_index.0) - .unwrap() - .fbo_ids[(texture_id_and_index.1).0 as usize] + let fbo_id = texture_id.map_or(FBOId(self.default_fbo), |texture_id| { + self.textures.get(&texture_id).unwrap().fbo_ids[0] }); if self.bound_fbo != fbo_id { @@ -423,9 +407,7 @@ impl Device { (texture.width, texture.height) } - fn set_texture_parameters(&mut self, - target: TextureTarget, - filter: TextureFilter) { + fn set_texture_parameters(&mut self, filter: TextureFilter) { let filter = match filter { TextureFilter::Nearest => { gl::NEAREST @@ -435,11 +417,11 @@ impl Device { } }; - gl::tex_parameter_i(target.to_gl(), gl::TEXTURE_MAG_FILTER, filter as gl::GLint); - gl::tex_parameter_i(target.to_gl(), gl::TEXTURE_MIN_FILTER, filter as gl::GLint); + gl::tex_parameter_i(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, filter as gl::GLint); + gl::tex_parameter_i(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, filter as gl::GLint); - gl::tex_parameter_i(target.to_gl(), gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE as gl::GLint); - gl::tex_parameter_i(target.to_gl(), gl::TEXTURE_WRAP_T, gl::CLAMP_TO_EDGE as gl::GLint); + gl::tex_parameter_i(gl::TEXTURE_2D, gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE as gl::GLint); + gl::tex_parameter_i(gl::TEXTURE_2D, gl::TEXTURE_WRAP_T, gl::CLAMP_TO_EDGE as gl::GLint); } fn upload_2d_texture_image(&mut self, @@ -458,58 +440,16 @@ impl Device { pixels); } - fn upload_texture_array_image(&mut self, - width: u32, - height: u32, - levels: u32, - internal_format: u32, - format: u32, - pixels: Option<&[u8]>) { - gl::tex_image_3d(gl::TEXTURE_2D_ARRAY, - 0, - internal_format as gl::GLint, - width as gl::GLint, height as gl::GLint, levels as gl::GLint, - 0, - format, - gl::UNSIGNED_BYTE, - pixels); - } - - #[cfg(any(target_os = "android", target_os = "gonk"))] fn upload_texture_image(&mut self, - target: TextureTarget, - width: u32, height: u32, levels: u32, + width: u32, + height: u32, internal_format: u32, format: u32, pixels: Option<&[u8]>) { - debug_assert!(target == TextureTarget::Texture2D); - debug_assert!(levels == 1); self.upload_2d_texture_image(width, height, internal_format, format, pixels) } - #[cfg(not(any(target_os = "android", target_os = "gonk")))] - fn upload_texture_image(&mut self, - target: TextureTarget, - width: u32, height: u32, levels: u32, - internal_format: u32, - format: u32, - pixels: Option<&[u8]>) { - match target { - TextureTarget::Texture2D => { - debug_assert!(levels == 1); - self.upload_2d_texture_image(width, height, internal_format, format, pixels) - } - TextureTarget::TextureArray => { - self.upload_texture_array_image(width, height, levels, - internal_format, - format, - pixels) - } - } - } - - #[cfg(any(target_os = "android", target_os = "gonk"))] - fn deinit_texture_image(&mut self, _: TextureTarget) { + fn deinit_texture_image(&mut self) { gl::tex_image_2d(gl::TEXTURE_2D, 0, gl::RGB as gl::GLint, @@ -521,41 +461,10 @@ impl Device { None); } - #[cfg(not(any(target_os = "android", target_os = "gonk")))] - fn deinit_texture_image(&mut self, target: TextureTarget) { - match target { - TextureTarget::Texture2D => { - gl::tex_image_2d(gl::TEXTURE_2D, - 0, - gl::RGB as gl::GLint, - 0, - 0, - 0, - gl::RGB, - gl::UNSIGNED_BYTE, - None); - } - TextureTarget::TextureArray => { - gl::tex_image_3d(gl::TEXTURE_2D_ARRAY, - 0, - gl::RGB as gl::GLint, - 0, - 0, - 0, - 0, - gl::RGB, - gl::UNSIGNED_BYTE, - None); - } - } - } - pub fn init_texture(&mut self, - target: TextureTarget, texture_id: TextureId, width: u32, height: u32, - levels: u32, format: ImageFormat, filter: TextureFilter, mode: RenderTargetMode, @@ -576,51 +485,21 @@ impl Device { match mode { RenderTargetMode::RenderTarget => { - self.bind_color_texture(target, texture_id); - self.set_texture_parameters(target, filter); - - match target { - TextureTarget::Texture2D => { - debug_assert!(levels == 1); - self.upload_2d_texture_image(width, - height, - internal_format, - gl_format, - None) - } - TextureTarget::TextureArray => { - self.upload_texture_array_image(width, - height, - levels, - internal_format, - gl_format, - None) - } - } + self.bind_color_texture(texture_id); + self.set_texture_parameters(filter); + + self.upload_2d_texture_image(width, height, internal_format, gl_format, None); let fbo_ids: Vec<_> = - gl::gen_framebuffers(levels as i32).into_iter() - .map(|fbo_id| FBOId(fbo_id)) - .collect(); - for (i, fbo_id) in fbo_ids.iter().enumerate() { + gl::gen_framebuffers(1).into_iter().map(|fbo_id| FBOId(fbo_id)).collect(); + for fbo_id in &fbo_ids[..] { gl::bind_framebuffer(gl::FRAMEBUFFER, fbo_id.0); - match target { - TextureTarget::Texture2D => { - gl::framebuffer_texture_2d(gl::FRAMEBUFFER, - gl::COLOR_ATTACHMENT0, - gl::TEXTURE_2D, - texture_id.0, - 0); - } - TextureTarget::TextureArray => { - gl::framebuffer_texture_layer(gl::FRAMEBUFFER, - gl::COLOR_ATTACHMENT0, - texture_id.0, - 0, - i as gl::GLint); - } - } + gl::framebuffer_texture_2d(gl::FRAMEBUFFER, + gl::COLOR_ATTACHMENT0, + gl::TEXTURE_2D, + texture_id.0, + 0); } gl::bind_framebuffer(gl::FRAMEBUFFER, self.default_fbo); @@ -628,11 +507,10 @@ impl Device { self.textures.get_mut(&texture_id).unwrap().fbo_ids = fbo_ids; } RenderTargetMode::None => { - texture_id.bind(target); - self.set_texture_parameters(target, filter); + texture_id.bind(); + self.set_texture_parameters(filter); - self.upload_texture_image(target, - width, height, levels, + self.upload_texture_image(width, height, internal_format, gl_format, pixels); @@ -640,11 +518,11 @@ impl Device { } } - pub fn deinit_texture(&mut self, target: TextureTarget, texture_id: TextureId) { + pub fn deinit_texture(&mut self, texture_id: TextureId) { debug_assert!(self.inside_frame); - self.bind_color_texture(target, texture_id); - self.deinit_texture_image(target); + self.bind_color_texture(texture_id); + self.deinit_texture_image(); let texture = self.textures.get_mut(&texture_id).unwrap(); if !texture.fbo_ids.is_empty() { @@ -823,27 +701,8 @@ impl Device { data); } - fn update_image_for_texture_array(&mut self, - x0: gl::GLint, - y0: gl::GLint, - level: gl::GLint, - width: gl::GLint, - height: gl::GLint, - format: gl::GLuint, - data: &[u8]) { - gl::tex_sub_image_3d(gl::TEXTURE_2D_ARRAY, - 0, - x0, y0, level, - width, height, 1, - format, - gl::UNSIGNED_BYTE, - data); - } - pub fn update_texture(&mut self, - target: TextureTarget, texture_id: TextureId, - texture_index: TextureIndex, x0: u32, y0: u32, width: u32, @@ -860,69 +719,30 @@ impl Device { debug_assert!(data.len() as u32 == bpp * width * height); - self.bind_color_texture(target, texture_id); - - match target { - TextureTarget::TextureArray => { - self.update_image_for_texture_array(x0 as gl::GLint, - y0 as gl::GLint, - texture_index.0 as gl::GLint, - width as gl::GLint, - height as gl::GLint, - gl_format, - data); - } - TextureTarget::Texture2D => { - debug_assert!(texture_index == TextureIndex(0)); - self.update_image_for_2d_texture(x0 as gl::GLint, - y0 as gl::GLint, - width as gl::GLint, - height as gl::GLint, - gl_format, - data); - } - } - } - - #[cfg(any(target_os = "android", target_os = "gonk"))] - pub fn update_texture_for_noncomposite_operation(&mut self, - texture_id: TextureId, - texture_index: TextureIndex, - x0: u32, - y0: u32, - width: u32, - height: u32, - data: &[u8]) { - self.update_texture(TextureTarget::Texture2D, - texture_id, - texture_index, - x0, y0, - width, height, - data) + self.bind_color_texture(texture_id); + self.update_image_for_2d_texture(x0 as gl::GLint, + y0 as gl::GLint, + width as gl::GLint, + height as gl::GLint, + gl_format, + data); } - #[cfg(not(any(target_os = "android", target_os = "gonk")))] pub fn update_texture_for_noncomposite_operation(&mut self, texture_id: TextureId, - texture_index: TextureIndex, x0: u32, y0: u32, width: u32, height: u32, data: &[u8]) { - self.update_texture(TextureTarget::TextureArray, - texture_id, - texture_index, - x0, y0, - width, height, - data) + self.update_texture(texture_id, x0, y0, width, height, data) } fn read_framebuffer_rect_for_2d_texture(&mut self, texture_id: TextureId, x: u32, y: u32, width: u32, height: u32) { - self.bind_color_texture(TextureTarget::Texture2D, texture_id); + self.bind_color_texture(texture_id); gl::copy_tex_sub_image_2d(gl::TEXTURE_2D, 0, 0, @@ -931,47 +751,15 @@ impl Device { width as gl::GLint, height as gl::GLint); } - #[cfg(any(target_os = "android", target_os = "gonk"))] pub fn read_framebuffer_rect(&mut self, - texture_target: TextureTarget, texture_id: TextureId, - texture_index: TextureIndex, x: u32, y: u32, width: u32, height: u32) { - debug_assert!(texture_target == TextureTarget::Texture2D); self.read_framebuffer_rect_for_2d_texture(texture_id, x, y, width, height) } - #[cfg(not(any(target_os = "android", target_os = "gonk")))] - pub fn read_framebuffer_rect(&mut self, - texture_target: TextureTarget, - texture_id: TextureId, - texture_index: TextureIndex, - x: u32, - y: u32, - width: u32, - height: u32) { - match texture_target { - TextureTarget::Texture2D => { - self.read_framebuffer_rect_for_2d_texture(texture_id, x, y, width, height) - } - TextureTarget::TextureArray => { - self.bind_color_texture(TextureTarget::TextureArray, texture_id); - gl::copy_tex_sub_image_3d(gl::TEXTURE_2D_ARRAY, - 0, - 0, - 0, - x as gl::GLint, - y as gl::GLint, - texture_index.0 as gl::GLint, - width as gl::GLint, - height as gl::GLint) - } - } - } - #[cfg(any(target_os = "android", target_os = "gonk"))] fn clear_vertex_array(&mut self) { debug_assert!(self.inside_frame); @@ -1399,7 +1187,6 @@ impl Device { debug_assert!(self.inside_frame); self.inside_frame = false; - self.unbind_2d_texture_array(); gl::bind_texture(gl::TEXTURE_2D, 0); gl::use_program(0); } diff --git a/src/frame.rs b/src/frame.rs index bf8dc4a92c..6627f1c5fc 100644 --- a/src/frame.rs +++ b/src/frame.rs @@ -4,7 +4,7 @@ use device::{TextureId}; use euclid::{Rect, Point2D, Size2D, Matrix4}; use fnv::FnvHasher; use internal_types::{BlurDirection, LowLevelFilterOp, CompositionOp, DrawListItemIndex}; -use internal_types::{BatchUpdateList, DrawListId, TextureTarget}; +use internal_types::{BatchUpdateList, DrawListId}; use internal_types::{RendererFrame, DrawListContext, BatchInfo, DrawCall}; use internal_types::{BatchUpdate, BatchUpdateOp, DrawLayer}; use internal_types::{DrawCommand, ClearInfo, CompositeInfo, ANGLE_FLOAT_TO_FIXED}; @@ -467,10 +467,8 @@ impl Frame { // TODO(gw): Get composition ops working with transforms let origin = Point2D::new(child_offset.x as u32, child_offset.y as u32); - let texture_id = resource_cache.allocate_render_target(TextureTarget::Texture2D, - size.width, + let texture_id = resource_cache.allocate_render_target(size.width, size.height, - 1, ImageFormat::RGBA8); self.push_composite(CompositeInfo { diff --git a/src/internal_types.rs b/src/internal_types.rs index b5edc24ba0..c66a082ec5 100644 --- a/src/internal_types.rs +++ b/src/internal_types.rs @@ -1,10 +1,9 @@ use app_units::Au; use batch::{VertexBuffer, Batch, VertexBufferId, TileParams}; -use device::{TextureId, TextureIndex, TextureFilter}; +use device::{TextureId, TextureFilter}; use euclid::{Matrix4, Point2D, Rect, Size2D}; use fnv::FnvHasher; use freelist::{FreeListItem, FreeListItemId}; -use gleam::gl; use std::collections::HashMap; use std::collections::hash_state::DefaultState; use std::sync::Arc; @@ -137,8 +136,8 @@ pub struct PackedVertex { pub mu: u16, pub mv: u16, pub matrix_index: u8, - pub uv_index: u8, - pub muv_index: u8, + pub unused0: u8, + pub unused1: u8, pub tile_params_index: u8, } @@ -149,9 +148,7 @@ impl PackedVertex { u: f32, v: f32, mu: f32, - mv: f32, - uv_index: TextureIndex, - muv_index: TextureIndex) + mv: f32) -> PackedVertex { PackedVertex { x: x, @@ -162,8 +159,8 @@ impl PackedVertex { mu: (mu * UV_FLOAT_TO_FIXED) as u16, mv: (mv * UV_FLOAT_TO_FIXED) as u16, matrix_index: 0, - uv_index: uv_index.0, - muv_index: muv_index.0, + unused0: 0, + unused1: 0, tile_params_index: 0, } } @@ -174,9 +171,7 @@ impl PackedVertex { pub fn from_components_unscaled_muv(x: f32, y: f32, color: &ColorF, u: f32, v: f32, - mu: u16, mv: u16, - uv_index: TextureIndex, - muv_index: TextureIndex) + mu: u16, mv: u16) -> PackedVertex { PackedVertex { x: x, @@ -187,8 +182,8 @@ impl PackedVertex { mu: mu, mv: mv, matrix_index: 0, - uv_index: uv_index.0, - muv_index: muv_index.0, + unused0: 0, + unused1: 0, tile_params_index: 0, } } @@ -196,16 +191,9 @@ impl PackedVertex { pub fn from_points(position: &Point2D, color: &ColorF, uv: &Point2D, - muv: &Point2D, - uv_index: TextureIndex, - muv_index: TextureIndex) + muv: &Point2D) -> PackedVertex { - PackedVertex::from_components(position.x, position.y, - color, - uv.x, uv.y, - muv.x, muv.y, - uv_index, - muv_index) + PackedVertex::from_components(position.x, position.y, color, uv.x, uv.y, muv.x, muv.y) } } @@ -239,20 +227,18 @@ pub enum BoxShadowPart { #[derive(Clone, Copy, Debug)] pub struct TextureImage { pub texture_id: TextureId, - pub texture_index: TextureIndex, pub texel_uv: Rect, pub pixel_uv: Point2D, } pub enum TextureUpdateOp { - Create(TextureTarget, u32, u32, u32, ImageFormat, TextureFilter, RenderTargetMode, Option>), + Create(u32, u32, ImageFormat, TextureFilter, RenderTargetMode, Option>), Update(u32, u32, u32, u32, TextureUpdateDetails), DeinitRenderTarget(TextureId), } pub struct TextureUpdate { pub id: TextureId, - pub index: TextureIndex, pub op: TextureUpdateOp, } @@ -457,46 +443,33 @@ impl

ClipRectToRegionResult

{ position: &Point2D, uv: &Point2D, color: &ColorF, - mask: &TextureCacheItem, - uv_index: TextureIndex) + mask: &TextureCacheItem) -> PackedVertex { - PackedVertex::from_points(position, - color, - uv, - &self.muv_for_position(position, mask), - uv_index, - mask.texture_index) + PackedVertex::from_points(position, color, uv, &self.muv_for_position(position, mask)) } } impl ClipRectToRegionResult { // TODO(pcwalton): Clip colors too! - pub fn make_packed_vertices_for_rect(&self, - colors: &[ColorF; 4], - mask: &TextureCacheItem, - uv_index: TextureIndex) + pub fn make_packed_vertices_for_rect(&self, colors: &[ColorF; 4], mask: &TextureCacheItem) -> [PackedVertex; 4] { [ self.make_packed_vertex(&self.rect_result.pos.origin, &self.rect_result.uv.top_left, &colors[0], - mask, - uv_index), + mask), self.make_packed_vertex(&self.rect_result.pos.top_right(), &self.rect_result.uv.top_right, &colors[1], - mask, - uv_index), + mask), self.make_packed_vertex(&self.rect_result.pos.bottom_left(), &self.rect_result.uv.bottom_left, &colors[3], - mask, - uv_index), + mask), self.make_packed_vertex(&self.rect_result.pos.bottom_right(), &self.rect_result.uv.bottom_right, &colors[2], - mask, - uv_index), + mask), ] } } @@ -695,7 +668,7 @@ pub struct PackedVertexForTextureCacheUpdate { pub source_texture_size_y: f32, pub blur_radius: f32, pub misc0: u8, - pub uv_index: u8, + pub misc1: u8, pub misc2: u8, pub misc3: u8, } @@ -704,7 +677,6 @@ impl PackedVertexForTextureCacheUpdate { pub fn new(position: &Point2D, color: &ColorF, uv: &Point2D, - uv_index: TextureIndex, border_radii_outer: &Point2D, border_radii_inner: &Point2D, border_position: &Point2D, @@ -733,28 +705,13 @@ impl PackedVertexForTextureCacheUpdate { source_texture_size_y: source_texture_size.height, blur_radius: blur_radius, misc0: 0, - uv_index: uv_index.0 as u8, + misc1: 0, misc2: 0, misc3: 0, } } } -#[derive(Clone, Copy, Debug)] -pub enum TextureTarget { - Texture2D, - TextureArray, -} - -impl TextureTarget { - pub fn to_gl(&self) -> gl::GLuint { - match *self { - TextureTarget::Texture2D => gl::TEXTURE_2D, - TextureTarget::TextureArray => gl::TEXTURE_2D_ARRAY, - } - } -} - #[derive(Clone, Debug, Hash, Eq, PartialEq)] pub struct BorderRadiusRasterOp { pub outer_radius_x: Au, diff --git a/src/renderer.rs b/src/renderer.rs index 587f67164e..36174b0757 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -1,6 +1,6 @@ use app_units::Au; use batch::{RasterBatch, VertexBufferId}; -use device::{Device, ProgramId, TextureId, TextureIndex, UniformLocation}; +use device::{Device, ProgramId, TextureId, UniformLocation}; use device::{TextureFilter, VAOId, VertexUsageHint}; use euclid::{Rect, Matrix4, Point2D, Size2D}; use fnv::FnvHasher; @@ -8,7 +8,7 @@ use gleam::gl; use internal_types::{RendererFrame, ResultMsg, TextureUpdateOp, BatchUpdateOp, BatchUpdateList}; use internal_types::{TextureUpdateDetails, TextureUpdateList, PackedVertex, RenderTargetMode}; use internal_types::{ORTHO_NEAR_PLANE, ORTHO_FAR_PLANE, BoxShadowPart, BasicRotationAngle}; -use internal_types::{PackedVertexForTextureCacheUpdate, TextureTarget, CompositionOp}; +use internal_types::{PackedVertexForTextureCacheUpdate, CompositionOp}; use internal_types::{BlurDirection, LowLevelFilterOp, DrawCommand, ANGLE_FLOAT_TO_FIXED}; use render_backend::RenderBackend; use std::collections::HashMap; @@ -255,27 +255,22 @@ impl Renderer { for update_list in pending_texture_updates.drain(..) { for update in update_list.updates { match update.op { - TextureUpdateOp::Create(target, - width, height, levels, - format, - filter, - mode, - maybe_bytes) => { + TextureUpdateOp::Create(width, height, format, filter, mode, maybe_bytes) => { // TODO: clean up match match maybe_bytes { Some(bytes) => { - self.device.init_texture(target, - update.id, - width, height, levels, + self.device.init_texture(update.id, + width, + height, format, filter, mode, Some(bytes.as_slice())); } None => { - self.device.init_texture(target, - update.id, - width, height, levels, + self.device.init_texture(update.id, + width, + height, format, filter, mode, @@ -284,15 +279,15 @@ impl Renderer { } } TextureUpdateOp::DeinitRenderTarget(id) => { - self.device.deinit_texture(TextureTarget::Texture2D, id); + self.device.deinit_texture(id); } TextureUpdateOp::Update(x, y, width, height, details) => { match details { TextureUpdateDetails::Blit(bytes) => { self.device.update_texture_for_noncomposite_operation( update.id, - update.index, - x, y, + x, + y, width, height, bytes.as_slice()); } @@ -305,7 +300,6 @@ impl Renderer { f32::ceil(radius.to_f32_px() * self.device_pixel_ratio) as u32; self.device.update_texture_for_noncomposite_operation( unblurred_glyph_texture_image.texture_id, - unblurred_glyph_texture_image.texture_index, unblurred_glyph_texture_image.pixel_uv.x, unblurred_glyph_texture_image.pixel_uv.y, glyph_size.width, @@ -331,7 +325,6 @@ impl Renderer { &dest_texture_origin, &white, &Point2D::new(0.0, 0.0), - unblurred_glyph_texture_image.texture_index, &zero_point, &zero_point, &unblurred_glyph_texture_image.texel_uv.origin, @@ -344,7 +337,6 @@ impl Renderer { dest_texture_origin.y), &white, &Point2D::new(1.0, 0.0), - unblurred_glyph_texture_image.texture_index, &zero_point, &zero_point, &unblurred_glyph_texture_image.texel_uv.origin, @@ -357,7 +349,6 @@ impl Renderer { dest_texture_origin.y + height), &white, &Point2D::new(0.0, 1.0), - unblurred_glyph_texture_image.texture_index, &zero_point, &zero_point, &unblurred_glyph_texture_image.texel_uv.origin, @@ -370,7 +361,6 @@ impl Renderer { dest_texture_origin.y + height), &white, &Point2D::new(1.0, 1.0), - unblurred_glyph_texture_image.texture_index, &zero_point, &zero_point, &unblurred_glyph_texture_image.texel_uv.origin, @@ -383,7 +373,6 @@ impl Renderer { { let mut batch = self.get_or_create_raster_batch( horizontal_blur_texture_image.texture_id, - horizontal_blur_texture_image.texture_index, unblurred_glyph_texture_image.texture_id, blur_program_id, Some(BlurDirection::Horizontal)); @@ -399,7 +388,6 @@ impl Renderer { &Point2D::new(x, y), &white, &Point2D::new(0.0, 0.0), - horizontal_blur_texture_image.texture_index, &zero_point, &zero_point, &horizontal_blur_texture_image.texel_uv.origin, @@ -411,7 +399,6 @@ impl Renderer { &Point2D::new(x + width, y), &white, &Point2D::new(1.0, 0.0), - horizontal_blur_texture_image.texture_index, &zero_point, &zero_point, &horizontal_blur_texture_image.texel_uv.origin, @@ -423,7 +410,6 @@ impl Renderer { &Point2D::new(x, y + height), &white, &Point2D::new(0.0, 1.0), - horizontal_blur_texture_image.texture_index, &zero_point, &zero_point, &horizontal_blur_texture_image.texel_uv.origin, @@ -435,7 +421,6 @@ impl Renderer { &Point2D::new(x + width, y + height), &white, &Point2D::new(1.0, 1.0), - horizontal_blur_texture_image.texture_index, &zero_point, &zero_point, &horizontal_blur_texture_image.texel_uv.origin, @@ -448,7 +433,6 @@ impl Renderer { { let mut batch = self.get_or_create_raster_batch( update.id, - update.index, horizontal_blur_texture_image.texture_id, blur_program_id, Some(BlurDirection::Vertical)); @@ -506,7 +490,6 @@ impl Renderer { &Point2D::new(x, y), &color, &zero_point, - TextureIndex(0), &border_radii_outer, &border_radii_inner, &border_position, @@ -518,7 +501,6 @@ impl Renderer { &Point2D::new(x + width, y), &color, &zero_point, - TextureIndex(0), &border_radii_outer, &border_radii_inner, &border_position, @@ -530,7 +512,6 @@ impl Renderer { &Point2D::new(x, y + height), &color, &zero_point, - TextureIndex(0), &border_radii_outer, &border_radii_inner, &border_position, @@ -542,7 +523,6 @@ impl Renderer { &Point2D::new(x + width, y + height), &color, &zero_point, - TextureIndex(0), &border_radii_outer, &border_radii_inner, &border_position, @@ -553,7 +533,6 @@ impl Renderer { ]; let mut batch = self.get_or_create_raster_batch(update.id, - update.index, TextureId(0), border_program_id, None); @@ -562,7 +541,6 @@ impl Renderer { TextureUpdateDetails::BoxShadow(blur_radius, part, inverted) => { self.update_texture_cache_for_box_shadow( update.id, - update.index, &Rect::new(Point2D::new(x as f32, y as f32), Size2D::new(width as f32, height as f32)), blur_radius, @@ -580,7 +558,6 @@ impl Renderer { fn update_texture_cache_for_box_shadow(&mut self, update_id: TextureId, - update_index: TextureIndex, rect: &Rect, blur_radius: Au, box_shadow_part: BoxShadowPart, @@ -609,7 +586,6 @@ impl Renderer { PackedVertexForTextureCacheUpdate::new(&rect.origin, &color, &zero_point, - TextureIndex(0), &arc_radius, &zero_point, &zero_point, @@ -620,7 +596,6 @@ impl Renderer { PackedVertexForTextureCacheUpdate::new(&rect.top_right(), &color, &zero_point, - TextureIndex(0), &arc_radius, &zero_point, &zero_point, @@ -631,7 +606,6 @@ impl Renderer { PackedVertexForTextureCacheUpdate::new(&rect.bottom_left(), &color, &zero_point, - TextureIndex(0), &arc_radius, &zero_point, &zero_point, @@ -642,7 +616,6 @@ impl Renderer { PackedVertexForTextureCacheUpdate::new(&rect.bottom_right(), &color, &zero_point, - TextureIndex(0), &arc_radius, &zero_point, &zero_point, @@ -653,7 +626,6 @@ impl Renderer { ]; let mut batch = self.get_or_create_raster_batch(update_id, - update_index, TextureId(0), box_shadow_program_id, None); @@ -662,7 +634,6 @@ impl Renderer { fn get_or_create_raster_batch(&mut self, dest_texture_id: TextureId, - dest_texture_index: TextureIndex, color_texture_id: TextureId, program_id: ProgramId, blur_direction: Option) @@ -671,7 +642,6 @@ impl Renderer { let mut index = None; for (i, batch) in self.raster_batches.iter_mut().enumerate() { if batch.can_add_to_batch(dest_texture_id, - dest_texture_index, color_texture_id, program_id, blur_direction) { @@ -685,7 +655,6 @@ impl Renderer { self.raster_batches.push(RasterBatch::new(program_id, blur_direction, dest_texture_id, - dest_texture_index, color_texture_id)); } @@ -707,7 +676,6 @@ impl Renderer { } self.set_up_gl_state_for_texture_cache_update(batch.dest_texture_id, - batch.dest_texture_index, batch.color_texture_id, batch.program_id, batch.blur_direction); @@ -717,7 +685,6 @@ impl Renderer { // Flush the remaining batches. for batch in remaining_batches.into_iter() { self.set_up_gl_state_for_texture_cache_update(batch.dest_texture_id, - batch.dest_texture_index, batch.color_texture_id, batch.program_id, batch.blur_direction); @@ -727,7 +694,6 @@ impl Renderer { fn set_up_gl_state_for_texture_cache_update(&mut self, update_id: TextureId, - update_index: TextureIndex, color_texture_id: TextureId, program_id: ProgramId, blur_direction: Option) { @@ -743,7 +709,7 @@ impl Renderer { ORTHO_NEAR_PLANE, ORTHO_FAR_PLANE); - self.device.bind_render_target(Some((update_id, update_index))); + self.device.bind_render_target(Some(update_id)); gl::viewport(0, 0, texture_width as gl::GLint, texture_height as gl::GLint); self.device.bind_program(program_id, &projection); @@ -802,10 +768,8 @@ impl Renderer { ORTHO_NEAR_PLANE, ORTHO_FAR_PLANE); - let layer_texture_id_and_index = layer.texture_id.map(|texture_id| { - (texture_id, TextureIndex(0)) - }); - self.device.bind_render_target(layer_texture_id_and_index); + let layer_texture_id = layer.texture_id; + self.device.bind_render_target(layer_texture_id); gl::viewport(0, 0, (layer.size.width as f32 * self.device_pixel_ratio) as gl::GLint, @@ -928,19 +892,15 @@ impl Renderer { gl::disable(gl::BLEND); // TODO: No need to re-init this FB working copy texture every time... - self.device.init_texture(TextureTarget::Texture2D, - render_context.temporary_fb_texture, + self.device.init_texture(render_context.temporary_fb_texture, info.rect.size.width, info.rect.size.height, - 1, ImageFormat::RGBA8, TextureFilter::Nearest, RenderTargetMode::None, None); self.device.read_framebuffer_rect( - TextureTarget::Texture2D, render_context.temporary_fb_texture, - TextureIndex(0), x0, framebuffer_size.height - info.rect.size.height - y0, info.rect.size.width, @@ -1011,8 +971,7 @@ impl Renderer { param1); } } - self.device.bind_mask_texture(TextureTarget::Texture2D, - render_context.temporary_fb_texture); + self.device.bind_mask_texture(render_context.temporary_fb_texture); alpha = 1.0; } else { gl::enable(gl::BLEND); @@ -1057,46 +1016,36 @@ impl Renderer { let color = ColorF::new(1.0, 1.0, 1.0, alpha); let indices: [u16; 6] = [ 0, 1, 2, 2, 3, 1 ]; - let color_texture_index = TextureIndex(0); let vertices: [PackedVertex; 4] = [ PackedVertex::from_components_unscaled_muv( x0 as f32, y0 as f32, &color, 0.0, 1.0, info.rect.size.width as u16, - info.rect.size.height as u16, - color_texture_index, - TextureIndex(0)), + info.rect.size.height as u16), PackedVertex::from_components_unscaled_muv( x1 as f32, y0 as f32, &color, 1.0, 1.0, info.rect.size.width as u16, - info.rect.size.height as u16, - color_texture_index, - TextureIndex(0)), + info.rect.size.height as u16), PackedVertex::from_components_unscaled_muv( x0 as f32, y1 as f32, &color, 0.0, 0.0, info.rect.size.width as u16, - info.rect.size.height as u16, - color_texture_index, - TextureIndex(0)), + info.rect.size.height as u16), PackedVertex::from_components_unscaled_muv( x1 as f32, y1 as f32, &color, 1.0, 0.0, info.rect.size.width as u16, - info.rect.size.height as u16, - color_texture_index, - TextureIndex(0)), + info.rect.size.height as u16), ]; // TODO: Don't re-create this VAO all the time. // Create it once and set positions via uniforms. let vao_id = self.device.create_vao(); - self.device.bind_color_texture(TextureTarget::Texture2D, - info.color_texture_id); + self.device.bind_color_texture(info.color_texture_id); self.device.bind_vao(vao_id); self.device.update_vao_indices(vao_id, &indices, VertexUsageHint::Dynamic); self.device.update_vao_vertices(vao_id, &vertices, VertexUsageHint::Dynamic); diff --git a/src/resource_cache.rs b/src/resource_cache.rs index 06a784a29b..0cc7b72cc7 100644 --- a/src/resource_cache.rs +++ b/src/resource_cache.rs @@ -4,7 +4,7 @@ use euclid::Size2D; use fnv::FnvHasher; use freelist::FreeList; use internal_types::{FontTemplate, GlyphKey, RasterItem}; -use internal_types::{TextureTarget, TextureUpdateList, DrawListId, DrawList}; +use internal_types::{TextureUpdateList, DrawListId, DrawList}; use platform::font::{FontContext, RasterizedGlyph}; use renderer::BLUR_INFLATION_FACTOR; use resource_list::ResourceList; @@ -285,18 +285,9 @@ impl ResourceCache { self.draw_lists.free(draw_list_id); } - pub fn allocate_render_target(&mut self, - target: TextureTarget, - width: u32, - height: u32, - levels: u32, - format: ImageFormat) + pub fn allocate_render_target(&mut self, width: u32, height: u32, format: ImageFormat) -> TextureId { - self.texture_cache.allocate_render_target(target, - width, - height, - levels, - format) + self.texture_cache.allocate_render_target(width, height, format) } pub fn free_render_target(&mut self, texture_id: TextureId) { diff --git a/src/texture_cache.rs b/src/texture_cache.rs index 4e127e9889..895fc5c3fd 100644 --- a/src/texture_cache.rs +++ b/src/texture_cache.rs @@ -1,9 +1,9 @@ use app_units::Au; -use device::{MAX_TEXTURE_SIZE, TextureId, TextureIndex, TextureFilter}; +use device::{MAX_TEXTURE_SIZE, TextureId, TextureFilter}; use euclid::{Point2D, Rect, Size2D}; use fnv::FnvHasher; use freelist::{FreeList, FreeListItem, FreeListItemId}; -use internal_types::{TextureTarget, TextureUpdate, TextureUpdateOp, TextureUpdateDetails}; +use internal_types::{TextureUpdate, TextureUpdateOp, TextureUpdateDetails}; use internal_types::{RasterItem, RenderTargetMode, TextureImage, TextureUpdateList}; use internal_types::{BasicRotationAngle, RectUv}; use std::cmp::Ordering; @@ -68,16 +68,14 @@ struct TexturePage { texture_id: TextureId, texture_size: u32, free_list: FreeRectList, - texture_index: TextureIndex, allocations: u32, dirty: bool, } impl TexturePage { - fn new(texture_id: TextureId, texture_index: TextureIndex, texture_size: u32) -> TexturePage { + fn new(texture_id: TextureId, texture_size: u32) -> TexturePage { let mut page = TexturePage { texture_id: texture_id, - texture_index: texture_index, texture_size: texture_size, free_list: FreeRectList::new(), allocations: 0, @@ -403,7 +401,6 @@ impl FreeListBin { pub struct TextureCacheItem { // Identifies the texture and array slice pub texture_id: TextureId, - pub texture_index: TextureIndex, // Custom data - unused by texture cache itself pub user_data: TextureCacheItemUserData, @@ -451,7 +448,6 @@ impl FreeListItem for TextureCacheItem { impl TextureCacheItem { fn new(texture_id: TextureId, - texture_index: TextureIndex, user_x0: i32, user_y0: i32, allocated_rect: Rect, requested_rect: Rect, @@ -460,7 +456,6 @@ impl TextureCacheItem { -> TextureCacheItem { TextureCacheItem { texture_id: texture_id, - texture_index: texture_index, texture_size: *texture_size, uv_rect: uv_rect, user_data: TextureCacheItemUserData { @@ -476,7 +471,6 @@ impl TextureCacheItem { let texture_size = texture_size() as f32; TextureImage { texture_id: self.texture_id, - texture_index: self.texture_index, texel_uv: Rect::new(Point2D::new(self.uv_rect.top_left.x, self.uv_rect.top_left.y), Size2D::new(self.uv_rect.bottom_right.x - self.uv_rect.top_left.x, @@ -564,28 +558,19 @@ impl TextureCache { requested_rect: Rect::zero(), texture_id: TextureId::invalid(), texture_size: Size2D::zero(), - texture_index: TextureIndex(0), }; self.items.insert(new_item) } - pub fn allocate_render_target(&mut self, - target: TextureTarget, - width: u32, - height: u32, - levels: u32, - format: ImageFormat) + pub fn allocate_render_target(&mut self, width: u32, height: u32, format: ImageFormat) -> TextureId { let texture_id = self.free_texture_ids .pop() .expect("TODO: Handle running out of texture IDs!"); let update_op = TextureUpdate { id: texture_id, - index: TextureIndex(0), - op: TextureUpdateOp::Create(target, - width, + op: TextureUpdateOp::Create(width, height, - levels, format, TextureFilter::Nearest, RenderTargetMode::RenderTarget, @@ -599,7 +584,6 @@ impl TextureCache { self.free_texture_ids.push(texture_id); let update_op = TextureUpdate { id: texture_id, - index: TextureIndex(0), op: TextureUpdateOp::DeinitRenderTarget(texture_id), }; self.pending_updates.push(update_op); @@ -650,7 +634,7 @@ impl TextureCache { None => { // We need a new page. let texture_size = texture_size(); - let (texture_id, texture_index) = { + let texture_id = { let free_texture_levels_entry = match kind { TextureCacheItemKind::Standard => self.free_texture_levels.entry(format), TextureCacheItemKind::Alternate => { @@ -670,14 +654,13 @@ impl TextureCache { mode); } let free_texture_level = free_texture_levels.pop().unwrap(); - (free_texture_level.texture_id, free_texture_level.texture_index) + free_texture_level.texture_id }; - let page = TexturePage::new(texture_id, texture_index, texture_size); + let page = TexturePage::new(texture_id, texture_size); page_list.push(page); - match page_list.last_mut().unwrap().allocate(&allocation_size, - filter) { + match page_list.last_mut().unwrap().allocate(&allocation_size, filter) { Some(location) => location, None => { // Fall back to standalone texture allocation. @@ -685,7 +668,6 @@ impl TextureCache { .pop() .expect("TODO: Handle running out of texture ids!"); let cache_item = TextureCacheItem::new(texture_id, - TextureIndex(0), user_x0, user_y0, Rect::new(Point2D::zero(), requested_size), @@ -721,7 +703,6 @@ impl TextureCache { let u1 = u0 + requested_size.width as f32 / page.texture_size as f32; let v1 = v0 + requested_size.height as f32 / page.texture_size as f32; let cache_item = TextureCacheItem::new(page.texture_id, - page.texture_index, user_x0, user_y0, allocated_rect, requested_rect, @@ -772,7 +753,6 @@ impl TextureCache { TextureUpdate { id: allocation.item.texture_id, - index: allocation.item.texture_index, op: TextureUpdateOp::Update(allocation.item.requested_rect.origin.x, allocation.item.requested_rect.origin.y, width, @@ -802,7 +782,6 @@ impl TextureCache { TextureUpdate { id: allocation.item.texture_id, - index: allocation.item.texture_index, op: TextureUpdateOp::Update( allocation.item.requested_rect.origin.x, allocation.item.requested_rect.origin.y, @@ -836,7 +815,6 @@ impl TextureCache { let update_op = TextureUpdate { id: existing_item.texture_id, - index: existing_item.texture_index, op: op, }; @@ -897,7 +875,6 @@ impl TextureCache { let border_update_op_top = TextureUpdate { id: result.item.texture_id, - index: result.item.texture_index, op: TextureUpdateOp::Update(result.item.allocated_rect.origin.x, result.item.allocated_rect.origin.y, result.item.allocated_rect.size.width, @@ -907,27 +884,27 @@ impl TextureCache { let border_update_op_bottom = TextureUpdate { id: result.item.texture_id, - index: result.item.texture_index, - op: TextureUpdateOp::Update(result.item.allocated_rect.origin.x, - result.item.allocated_rect.origin.y + result.item.requested_rect.size.height + 1, - result.item.allocated_rect.size.width, - 1, - TextureUpdateDetails::Blit(bottom_row_bytes)) + op: TextureUpdateOp::Update( + result.item.allocated_rect.origin.x, + result.item.allocated_rect.origin.y + + result.item.requested_rect.size.height + 1, + result.item.allocated_rect.size.width, + 1, + TextureUpdateDetails::Blit(bottom_row_bytes)) }; let border_update_op_left = TextureUpdate { id: result.item.texture_id, - index: result.item.texture_index, - op: TextureUpdateOp::Update(result.item.allocated_rect.origin.x, - result.item.requested_rect.origin.y, - 1, - result.item.requested_rect.size.height, - TextureUpdateDetails::Blit(left_column_bytes)) + op: TextureUpdateOp::Update( + result.item.allocated_rect.origin.x, + result.item.requested_rect.origin.y, + 1, + result.item.requested_rect.size.height, + TextureUpdateDetails::Blit(left_column_bytes)) }; let border_update_op_right = TextureUpdate { id: result.item.texture_id, - index: result.item.texture_index, op: TextureUpdateOp::Update(result.item.allocated_rect.origin.x + result.item.requested_rect.size.width + 1, result.item.requested_rect.origin.y, 1, @@ -981,10 +958,8 @@ impl TextureCache { horizontal_blur_item.to_image())) } (AllocationKind::Standalone, TextureInsertOp::Blit(bytes)) => { - TextureUpdateOp::Create(self.texture_target_for_standalone_texture(), - width, + TextureUpdateOp::Create(width, height, - 1, format, filter, RenderTargetMode::None, @@ -998,54 +973,21 @@ impl TextureCache { let update_op = TextureUpdate { id: result.item.texture_id, - index: result.item.texture_index, op: op, }; self.pending_updates.push(update_op); } - #[cfg(any(target_os = "android", target_os = "gonk"))] - pub fn texture_target_for_standalone_texture(&self) -> TextureTarget { - TextureTarget::Texture2D - } - - #[cfg(not(any(target_os = "android", target_os = "gonk")))] - pub fn texture_target_for_standalone_texture(&self) -> TextureTarget { - TextureTarget::TextureArray - } - pub fn get(&self, id: TextureCacheItemId) -> &TextureCacheItem { self.items.get(id) } } -#[cfg(any(target_os = "android", target_os = "gonk"))] -fn texture_create_op(texture_size: u32, levels: u32, format: ImageFormat, mode: RenderTargetMode) - -> TextureUpdateOp { - debug_assert!(levels == 1); - TextureUpdateOp::Create(TextureTarget::Texture2D, - texture_size, - texture_size, - levels, - format, - TextureFilter::Linear, - mode, - None) -} - -#[cfg(not(any(target_os = "android", target_os = "gonk")))] -fn texture_create_op(texture_size: u32, levels: u32, format: ImageFormat, mode: RenderTargetMode) +fn texture_create_op(texture_size: u32, format: ImageFormat, mode: RenderTargetMode) -> TextureUpdateOp { - TextureUpdateOp::Create(TextureTarget::TextureArray, - texture_size, - texture_size, - levels, - format, - TextureFilter::Linear, - mode, - None) + TextureUpdateOp::Create(texture_size, texture_size, format, TextureFilter::Linear, mode, None) } pub enum TextureInsertOp { @@ -1067,7 +1009,6 @@ impl FitsInside for Size2D { #[derive(Clone, Copy)] pub struct FreeTextureLevel { texture_id: TextureId, - texture_index: TextureIndex, } fn create_new_texture_page(pending_updates: &mut TextureUpdateList, @@ -1079,17 +1020,13 @@ fn create_new_texture_page(pending_updates: &mut TextureUpdateList, let texture_id = free_texture_ids.pop().expect("TODO: Handle running out of texture IDs!"); let update_op = TextureUpdate { id: texture_id, - index: TextureIndex(0), - op: texture_create_op(texture_size, levels_per_texture() as u32, format, mode), + op: texture_create_op(texture_size, format, mode), }; pending_updates.push(update_op); - for i in 0..levels_per_texture() { - free_texture_levels.push(FreeTextureLevel { - texture_id: texture_id, - texture_index: TextureIndex(i), - }) - } + free_texture_levels.push(FreeTextureLevel { + texture_id: texture_id, + }) } /// Returns the number of pixels on a side we're allowed to use for our texture atlases. @@ -1102,12 +1039,6 @@ fn texture_size() -> u32 { } } -/// Returns the number of texture levels we're allowed to use. -fn levels_per_texture() -> u8 { - let texture_size = texture_size(); - (MAX_RGBA_PIXELS_PER_TEXTURE / (texture_size * texture_size)) as u8 -} - #[derive(Clone, Copy, Debug, PartialEq)] pub enum TextureCacheItemKind { Standard,