Skip to content

Add specific shaders for rectangles with CLIP feature. #591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions webrender/res/ps_rectangle.fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ void main(void) {
init_transform_fs(vLocalPos, vLocalRect, alpha);
#endif

#ifdef WR_FEATURE_CLIP
alpha = min(alpha, do_clip());
#endif
oFragColor = vColor * vec4(1.0, 1.0, 1.0, alpha);
}
2 changes: 2 additions & 0 deletions webrender/res/ps_rectangle.vs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ void main(void) {
prim.tile);
#endif

#ifdef WR_FEATURE_CLIP
write_clip(vi.global_clamped_pos, prim.clip_area);
#endif
}
17 changes: 15 additions & 2 deletions webrender/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ impl VertexDataTexture {

const TRANSFORM_FEATURE: &'static str = "TRANSFORM";
const SUBPIXEL_AA_FEATURE: &'static str = "SUBPIXEL_AA";
const CLIP_FEATURE: &'static str = "CLIP";

enum ShaderKind {
Primitive,
Expand Down Expand Up @@ -346,6 +347,7 @@ pub struct Renderer {
// output, and the cache_image shader blits the results of
// a cache shader (e.g. blur) to the screen.
ps_rectangle: PrimitiveShader,
ps_rectangle_clip: PrimitiveShader,
ps_text_run: PrimitiveShader,
ps_text_run_subpixel: PrimitiveShader,
ps_image: PrimitiveShader,
Expand Down Expand Up @@ -503,6 +505,12 @@ impl Renderer {
&mut device,
&[],
options.precache_shaders);
let ps_rectangle_clip = PrimitiveShader::new("ps_rectangle",
max_ubo_vectors,
max_prim_instances,
&mut device,
&[ CLIP_FEATURE ],
options.precache_shaders);
let ps_text_run = PrimitiveShader::new("ps_text_run",
max_ubo_vectors,
max_prim_instances,
Expand Down Expand Up @@ -699,6 +707,7 @@ impl Renderer {
cs_text_run: cs_text_run,
cs_blur: cs_blur,
ps_rectangle: ps_rectangle,
ps_rectangle_clip: ps_rectangle_clip,
ps_text_run: ps_text_run,
ps_text_run_subpixel: ps_text_run_subpixel,
ps_image: ps_image,
Expand Down Expand Up @@ -1198,7 +1207,7 @@ impl Renderer {
for batch in &target.alpha_batcher.batches {
let transform_kind = batch.key.flags.transform_kind();
let needs_clipping = batch.key.flags.needs_clipping();
assert!(!needs_clipping || batch.key.blend_mode == BlendMode::Alpha);
debug_assert!(!needs_clipping || batch.key.blend_mode == BlendMode::Alpha);

if batch.key.blend_mode != prev_blend_mode {
match batch.key.blend_mode {
Expand Down Expand Up @@ -1256,7 +1265,11 @@ impl Renderer {
}
&PrimitiveBatchData::Rectangles(ref ubo_data) => {
self.gpu_profile.add_marker(GPU_TAG_PRIM_RECT);
let (shader, max_prim_items) = self.ps_rectangle.get(&mut self.device, transform_kind);
let (shader, max_prim_items) = if needs_clipping {
self.ps_rectangle_clip.get(&mut self.device, transform_kind)
} else {
self.ps_rectangle.get(&mut self.device, transform_kind)
};
self.draw_ubo_batch(ubo_data,
shader,
1,
Expand Down