tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

sample_color0.glsl (1093B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2  * License, v. 2.0. If a copy of the MPL was not distributed with this
      3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 /// This file provides the boilerplate for sampling from sColor0 with strict sample bounds.
      6 
      7 #include shared
      8 
      9 flat varying mediump vec4 v_uv0_sample_bounds;
     10 varying highp vec2 v_uv0;
     11 
     12 #ifdef WR_VERTEX_SHADER
     13 
     14 /// sample_pos is in 0..1 normalized coordinates
     15 /// uv_rect is in pixel.
     16 void vs_init_sample_color0(vec2 sample_pos, RectWithEndpoint uv_rect) {
     17     vec2 uv = mix(uv_rect.p0, uv_rect.p1, sample_pos);
     18 
     19     vec2 texture_size = vec2(TEX_SIZE(sColor0));
     20 
     21     v_uv0 = uv / texture_size;
     22 
     23     v_uv0_sample_bounds = vec4(
     24         uv_rect.p0 + vec2(0.5),
     25         uv_rect.p1 - vec2(0.5)
     26     ) / texture_size.xyxy;
     27 }
     28 
     29 #endif
     30 
     31 #ifdef WR_FRAGMENT_SHADER
     32 
     33 /// The vertex shader must have called vs_init_sample_color0
     34 vec4 fs_sample_color0() {
     35     vec2 uv = clamp(v_uv0, v_uv0_sample_bounds.xy, v_uv0_sample_bounds.zw);
     36     vec4 texel = TEX_SAMPLE(sColor0, uv);
     37 
     38     return texel;
     39 }
     40 
     41 #endif