Skip to content

Commit

Permalink
Use 3 color textures and one mask without overloading the names.
Browse files Browse the repository at this point in the history
  • Loading branch information
nical committed Nov 8, 2016
1 parent e27458c commit c096a94
Show file tree
Hide file tree
Showing 21 changed files with 177 additions and 144 deletions.
4 changes: 2 additions & 2 deletions webrender/res/blend.fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ vec3 Luminosity(vec3 Cb, vec3 Cs) {

void main(void)
{
vec3 Cs = Texture(COLOR_TEXTURE_0, vColorTexCoord).xyz;
vec3 Cb = Texture(COLOR_TEXTURE_1, vMaskTexCoord).xyz;
vec3 Cs = Texture(sColor0, vColorTexCoord).xyz;
vec3 Cb = Texture(sColor1, vMaskTexCoord).xyz;

// TODO: Relies on the ordering of MixBlendMode enum!
// TODO: May be best to have separate shaders (esp. on Tegra)
Expand Down
2 changes: 1 addition & 1 deletion webrender/res/blur.fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void main(void) {
lColorTexCoord.x <= 1.0 &&
lColorTexCoord.y >= 0.0 &&
lColorTexCoord.y <= 1.0 ?
texture(COLOR_TEXTURE_0, lColorTexCoord * sourceTextureUvSize + sourceTextureUvOrigin) :
texture(sColor0, lColorTexCoord * sourceTextureUvSize + sourceTextureUvOrigin) :
vec4(0.0);

// Alpha must be premultiplied in order to properly blur the alpha channel.
Expand Down
4 changes: 2 additions & 2 deletions webrender/res/clip_shared.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void write_clip(ClipData clip) {
clip.bottom_right.outer_inner_radius.x,
clip.bottom_left.outer_inner_radius.x);
//TODO: interpolate the final mask UV
vec2 texture_size = textureSize(MASK_TEXTURE, 0);
vec2 texture_size = textureSize(sMask, 0);
vClipMaskUvRect = clip.mask_data.uv_rect / texture_size.xyxy;
vClipMaskLocalRect = clip.mask_data.local_rect; //TODO: transform
}
Expand Down Expand Up @@ -58,7 +58,7 @@ float do_clip(vec2 pos) {
vec2 clamped_mask_uv = repeat_mask ? fract(vMaskUv) :
clamp(vMaskUv, vec2(0.0, 0.0), vec2(1.0, 1.0));
vec2 source_uv = clamped_mask_uv * vClipMaskUvRect.zw + vClipMaskUvRect.xy;
float mask_alpha = texture(MASK_TEXTURE, source_uv).r; //careful: texture has type A8
float mask_alpha = texture(sMask, source_uv).r; //careful: texture has type A8

return border_alpha * mask_alpha;
}
Expand Down
4 changes: 2 additions & 2 deletions webrender/res/debug_font.fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
void main(void)
{
#ifdef SERVO_ES2
float alpha = texture(COLOR_TEXTURE_0, vColorTexCoord.xy).a;
float alpha = texture(sColor0, vColorTexCoord.xy).a;
#else
float alpha = texture(COLOR_TEXTURE_0, vColorTexCoord.xy).r;
float alpha = texture(sColor0, vColorTexCoord.xy).r;
#endif
oFragColor = vec4(vColor.xyz, vColor.w * alpha);
}
10 changes: 4 additions & 6 deletions webrender/res/es2_common.fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

precision highp float;

uniform sampler2D sTexture0;
uniform sampler2D sTexture1;
uniform sampler2D sColor0;
uniform sampler2D sColor1;
uniform sampler2D sColor2;
uniform sampler2D sMask;
uniform vec4 uBlendParams;
uniform vec4 uAtlasParams;
uniform vec2 uDirection;
Expand All @@ -28,10 +30,6 @@ varying vec4 vTileParams;
varying vec4 vClipInRect;
varying vec4 vClipOutRect;

#define COLOR_TEXTURE_0 sTexture0
#define COLOR_TEXTURE_1 sTexture1
#define MASK_TEXTURE sTexture1

vec4 Texture(sampler2D sampler, vec2 texCoord) {
return texture2D(sampler, texCoord);
}
Expand Down
4 changes: 2 additions & 2 deletions webrender/res/filter.fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ vec4 Blur(float radius, vec2 direction) {
texCoord.x <= 1.0 &&
texCoord.y >= 0.0 &&
texCoord.y <= 1.0 ?
Texture(COLOR_TEXTURE_0, texCoord) :
Texture(sColor0, texCoord) :
vec4(0.0);
color += x * gauss(offsetF, sigma);
}
Expand Down Expand Up @@ -126,7 +126,7 @@ void main(void)
// Gaussian blur is specially handled:
result = Blur(amount, uFilterParams.zw);
} else {
vec4 Cs = Texture(COLOR_TEXTURE_0, vColorTexCoord);
vec4 Cs = Texture(sColor0, vColorTexCoord);

if (filterOp == 1) {
result = Contrast(Cs, amount);
Expand Down
10 changes: 4 additions & 6 deletions webrender/res/gl3_common.fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

precision highp float;

uniform sampler2D sTexture0;
uniform sampler2D sTexture1;
uniform sampler2D sColor0;
uniform sampler2D sColor1;
uniform sampler2D sColor2;
uniform sampler2D sMask;
uniform vec4 uBlendParams;
uniform vec2 uDirection;
uniform vec4 uFilterParams;
Expand All @@ -27,10 +29,6 @@ in vec4 vClipOutRect;

out vec4 oFragColor;

#define COLOR_TEXTURE_0 sTexture0
#define COLOR_TEXTURE_1 sTexture1
#define MASK_TEXTURE sTexture1

vec4 Texture(sampler2D sampler, vec2 texCoord) {
return texture(sampler, texCoord);
}
Expand Down
2 changes: 1 addition & 1 deletion webrender/res/ps_image.fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ void main(void) {
vec2 st = vTextureOffset + ((position_in_tile / vStretchSize) * vTextureSize);
alpha = alpha * float(all(bvec2(step(position_in_tile, vStretchSize))));

oFragColor = vec4(1, 1, 1, alpha) * texture(COLOR_TEXTURE_0, st);
oFragColor = vec4(1, 1, 1, alpha) * texture(sColor0, st);
}
2 changes: 1 addition & 1 deletion webrender/res/ps_image.vs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void main(void) {
#endif

// vUv will contain how many times this image has wrapped around the image size.
vec2 texture_size = vec2(textureSize(COLOR_TEXTURE_0, 0));
vec2 texture_size = vec2(textureSize(sColor0, 0));
vec2 st0 = image.st_rect.xy / texture_size;
vec2 st1 = image.st_rect.zw / texture_size;

Expand Down
2 changes: 1 addition & 1 deletion webrender/res/ps_image_clip.fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ void main(void) {
vec2 st = vTextureOffset + ((position_in_tile / vStretchSize) * vTextureSize);
alpha = alpha * float(all(bvec2(step(position_in_tile, vStretchSize))));

oFragColor = texture(COLOR_TEXTURE_0, st) * vec4(1, 1, 1, alpha);
oFragColor = texture(sColor0, st) * vec4(1, 1, 1, alpha);
}
2 changes: 1 addition & 1 deletion webrender/res/ps_image_clip.vs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void main(void) {
write_clip(clip);

// vUv will contain how many times this image has wrapped around the image size.
vec2 texture_size = vec2(textureSize(COLOR_TEXTURE_0, 0));
vec2 texture_size = vec2(textureSize(sColor0, 0));
vec2 st0 = image.st_rect.xy / texture_size;
vec2 st1 = image.st_rect.zw / texture_size;

Expand Down
2 changes: 1 addition & 1 deletion webrender/res/ps_text.fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

void main(void) {
float a = texture(COLOR_TEXTURE_0, vUv).a;
float a = texture(sColor0, vUv).a;
#ifdef WR_FEATURE_TRANSFORM
float alpha = 0.0;
init_transform_fs(vLocalPos, vLocalRect, alpha);
Expand Down
2 changes: 1 addition & 1 deletion webrender/res/ps_text.vs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void main(void) {
vec2 f = (vi.local_clamped_pos - vi.local_rect.p0) / (vi.local_rect.p1 - vi.local_rect.p0);
#endif

vec2 texture_size = vec2(textureSize(COLOR_TEXTURE_0, 0));
vec2 texture_size = vec2(textureSize(sColor0, 0));
vec2 st0 = glyph.uv_rect.xy / texture_size;
vec2 st1 = glyph.uv_rect.zw / texture_size;

Expand Down
2 changes: 1 addition & 1 deletion webrender/res/ps_text_run.fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

void main(void) {
float a = texture(COLOR_TEXTURE_0, vUv).a;
float a = texture(sColor0, vUv).a;
#ifdef WR_FEATURE_TRANSFORM
float alpha = 0.0;
init_transform_fs(vLocalPos, vLocalRect, alpha);
Expand Down
2 changes: 1 addition & 1 deletion webrender/res/ps_text_run.vs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void main(void) {
vec2 f = (vi.local_clamped_pos - vi.local_rect.p0) / (vi.local_rect.p1 - vi.local_rect.p0);
#endif

vec2 texture_size = vec2(textureSize(COLOR_TEXTURE_0, 0));
vec2 texture_size = vec2(textureSize(sColor0, 0));
vec2 st0 = glyph.uv_rect.xy / texture_size;
vec2 st1 = glyph.uv_rect.zw / texture_size;

Expand Down
10 changes: 4 additions & 6 deletions webrender/res/shared.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@
//======================================================================================
// Shared shader uniforms
//======================================================================================
uniform sampler2D sTexture0;
uniform sampler2D sTexture1;

#define COLOR_TEXTURE_0 sTexture0
#define COLOR_TEXTURE_1 sTexture1
#define MASK_TEXTURE sTexture1
uniform sampler2D sColor0;
uniform sampler2D sColor1;
uniform sampler2D sColor2;
uniform sampler2D sMask;

//======================================================================================
// Interpolator definitions
Expand Down
4 changes: 2 additions & 2 deletions webrender/src/debug_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use debug_font_data;
use device::{Device, ProgramId, VAOId, TextureId, VertexFormat};
use device::{TextureFilter, VertexUsageHint, TextureTarget};
use euclid::{Matrix4D, Point2D, Size2D, Rect};
use internal_types::{ORTHO_NEAR_PLANE, ORTHO_FAR_PLANE, SAMPLER_COLOR_0};
use internal_types::{ORTHO_NEAR_PLANE, ORTHO_FAR_PLANE, TextureSampler};
use internal_types::{DebugFontVertex, DebugColorVertex, RenderTargetMode, PackedColor};
use std::f32;
use webrender_traits::{ColorF, ImageFormat};
Expand Down Expand Up @@ -196,7 +196,7 @@ impl DebugRenderer {

// Glyphs
device.bind_program(self.font_program_id, &projection);
device.bind_texture(SAMPLER_COLOR_0, self.font_texture_id);
device.bind_texture(TextureSampler::Color0, self.font_texture_id);
device.bind_vao(self.font_vao);
device.update_vao_indices(self.font_vao,
&self.font_indices,
Expand Down
38 changes: 23 additions & 15 deletions webrender/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use fnv::FnvHasher;
use gleam::gl;
use internal_types::{PackedVertex, PackedVertexForQuad};
use internal_types::{PackedVertexForTextureCacheUpdate, RenderTargetMode, TextureSampler};
use internal_types::{VertexAttribute, DebugFontVertex, DebugColorVertex};
use internal_types::{VertexAttribute, DebugFontVertex, DebugColorVertex, DEFAULT_SAMPLER};
//use notify::{self, Watcher};
use std::collections::HashMap;
use std::fs::File;
Expand Down Expand Up @@ -1105,7 +1105,7 @@ impl Device {

match mode {
RenderTargetMode::SimpleRenderTarget => {
self.bind_texture(TextureSampler::Slot0, texture_id);
self.bind_texture(DEFAULT_SAMPLER, texture_id);
self.set_texture_parameters(texture_id.target, filter);
self.upload_texture_image(texture_id.target,
width,
Expand All @@ -1117,12 +1117,12 @@ impl Device {
self.create_fbo_for_texture_if_necessary(texture_id, None);
}
RenderTargetMode::LayerRenderTarget(layer_count) => {
self.bind_texture(TextureSampler::Slot0, texture_id);
self.bind_texture(DEFAULT_SAMPLER, texture_id);
self.set_texture_parameters(texture_id.target, filter);
self.create_fbo_for_texture_if_necessary(texture_id, Some(layer_count));
}
RenderTargetMode::None => {
self.bind_texture(TextureSampler::Slot0, texture_id);
self.bind_texture(DEFAULT_SAMPLER, texture_id);
self.set_texture_parameters(texture_id.target, filter);
self.upload_texture_image(texture_id.target,
width,
Expand Down Expand Up @@ -1216,7 +1216,7 @@ impl Device {
self.create_fbo_for_texture_if_necessary(temp_texture_id, None);

self.bind_render_target(Some((texture_id, 0)), None);
self.bind_texture(TextureSampler::Slot0, temp_texture_id);
self.bind_texture(DEFAULT_SAMPLER, temp_texture_id);

gl::copy_tex_sub_image_2d(temp_texture_id.target,
0,
Expand All @@ -1231,7 +1231,7 @@ impl Device {
self.init_texture(texture_id, new_width, new_height, format, filter, mode, None);
self.create_fbo_for_texture_if_necessary(texture_id, None);
self.bind_render_target(Some((temp_texture_id, 0)), None);
self.bind_texture(TextureSampler::Slot0, texture_id);
self.bind_texture(DEFAULT_SAMPLER, texture_id);

gl::copy_tex_sub_image_2d(texture_id.target,
0,
Expand All @@ -1249,7 +1249,7 @@ impl Device {
pub fn deinit_texture(&mut self, texture_id: TextureId) {
debug_assert!(self.inside_frame);

self.bind_texture(TextureSampler::Slot0, texture_id);
self.bind_texture(DEFAULT_SAMPLER, texture_id);

let texture = self.textures.get_mut(&texture_id).unwrap();
let (internal_format, gl_format) = gl_texture_formats_for_image_format(texture.format);
Expand Down Expand Up @@ -1404,13 +1404,21 @@ impl Device {
program.u_transform = gl::get_uniform_location(program.id, "uTransform");

program_id.bind();
let u_texture_0 = gl::get_uniform_location(program.id, "sTexture0");
if u_texture_0 != -1 {
gl::uniform_1i(u_texture_0, TextureSampler::Slot0 as i32);
let u_color_0 = gl::get_uniform_location(program.id, "sColor0");
if u_color_0 != -1 {
gl::uniform_1i(u_color_0, TextureSampler::Color0 as i32);
}
let u_texture_1 = gl::get_uniform_location(program.id, "sTexture1");
if u_texture_1 != -1 {
gl::uniform_1i(u_texture_1, TextureSampler::Slot1 as i32);
let u_color1 = gl::get_uniform_location(program.id, "sColor1");
if u_color1 != -1 {
gl::uniform_1i(u_color1, TextureSampler::Color1 as i32);
}
let u_color_2 = gl::get_uniform_location(program.id, "sColor2");
if u_color_2 != -1 {
gl::uniform_1i(u_color_2, TextureSampler::Color2 as i32);
}
let u_mask = gl::get_uniform_location(program.id, "sMask");
if u_mask != -1 {
gl::uniform_1i(u_mask, TextureSampler::Mask as i32);
}
let u_device_pixel_ratio = gl::get_uniform_location(program.id, "uDevicePixelRatio");
if u_device_pixel_ratio != -1 {
Expand Down Expand Up @@ -1564,7 +1572,7 @@ impl Device {

assert!(data.len() as u32 == bpp * width * height);

self.bind_texture(TextureSampler::Slot0, texture_id);
self.bind_texture(DEFAULT_SAMPLER, texture_id);
self.update_image_for_2d_texture(texture_id.target,
x0 as gl::GLint,
y0 as gl::GLint,
Expand All @@ -1582,7 +1590,7 @@ impl Device {
src_y: i32,
width: i32,
height: i32) {
self.bind_texture(TextureSampler::Slot0, texture_id);
self.bind_texture(DEFAULT_SAMPLER, texture_id);
gl::copy_tex_sub_image_2d(texture_id.target,
0,
dest_x,
Expand Down
Loading

0 comments on commit c096a94

Please sign in to comment.