Repository: alacritty/alacritty
File: alacritty/src/renderer/text/gles2.rs (Rust)

Code before:
        unsafe {
            let num_indices = (self.batch.len() / 4 * 6) as i32;

            // The rendering is inspired by
            // https://github.com/servo/webrender/blob/master/webrender/doc/text-rendering.md.

            // Draw background.
            self.program.set_rendering_pass(RenderingPass::Background);
            gl::BlendFunc(gl::ONE, gl::ZERO);
            gl::DrawElements(gl::TRIANGLES, num_indices, gl::UNSIGNED_SHORT, ptr::null());

            self.program.set_rendering_pass(RenderingPass::SubpixelPass1);
            if self.dual_source_blending {
                // Text rendering pass.
                gl::BlendFunc(gl::SRC1_COLOR, gl::ONE_MINUS_SRC1_COLOR);
            } else {
                // First text rendering pass.
                gl::BlendFuncSeparate(gl::ZERO, gl::ONE_MINUS_SRC_COLOR, gl::ZERO, gl::ONE);
                gl::DrawElements(gl::TRIANGLES, num_indices, gl::UNSIGNED_SHORT, ptr::null());

                // Second text rendering pass.
                self.program.set_rendering_pass(RenderingPass::SubpixelPass2);
                gl::BlendFuncSeparate(gl::ONE_MINUS_DST_ALPHA, gl::ONE, gl::ZERO, gl::ONE);
                gl::DrawElements(gl::TRIANGLES, num_indices, gl::UNSIGNED_SHORT, ptr::null());

                // Third pass.
                self.program.set_rendering_pass(RenderingPass::SubpixelPass3);
                gl::BlendFuncSeparate(gl::ONE, gl::ONE, gl::ONE, gl::ONE_MINUS_SRC_ALPHA);
            }

            gl::DrawElements(gl::TRIANGLES, num_indices, gl::UNSIGNED_SHORT, ptr::null());
        }

        self.batch.clear();
    }
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
struct TextVertex {
    // Cell coordinates.
    x: i16,
    y: i16,

    // Glyph coordinates.
    glyph_x: i16,
    glyph_y: i16,

    // Offsets into Atlas.
    u: f32,
    v: f32,

Review comment (suggestion):
Wasn't changed in this PR, but it's kinda strange that we include "text rendering" twice then leave it out for the third. Might as well make it consistent so people don't think the third pass is for something else.

Code after:
        unsafe {
            let num_indices = (self.batch.len() / 4 * 6) as i32;

            // The rendering is inspired by
            // https://github.com/servo/webrender/blob/master/webrender/doc/text-rendering.md.

            // Draw background.
            self.program.set_rendering_pass(RenderingPass::Background);
            gl::BlendFunc(gl::ONE, gl::ZERO);
            gl::DrawElements(gl::TRIANGLES, num_indices, gl::UNSIGNED_SHORT, ptr::null());

            self.program.set_rendering_pass(RenderingPass::SubpixelPass1);
            if self.dual_source_blending {
                // Text rendering pass.
                gl::BlendFunc(gl::SRC1_COLOR, gl::ONE_MINUS_SRC1_COLOR);
            } else {
                // First text rendering pass.
                gl::BlendFuncSeparate(gl::ZERO, gl::ONE_MINUS_SRC_COLOR, gl::ZERO, gl::ONE);
                gl::DrawElements(gl::TRIANGLES, num_indices, gl::UNSIGNED_SHORT, ptr::null());

                // Second text rendering pass.
                self.program.set_rendering_pass(RenderingPass::SubpixelPass2);
                gl::BlendFuncSeparate(gl::ONE_MINUS_DST_ALPHA, gl::ONE, gl::ZERO, gl::ONE);
                gl::DrawElements(gl::TRIANGLES, num_indices, gl::UNSIGNED_SHORT, ptr::null());

                // Third text rendering pass.
                self.program.set_rendering_pass(RenderingPass::SubpixelPass3);
                gl::BlendFuncSeparate(gl::ONE, gl::ONE, gl::ONE, gl::ONE_MINUS_SRC_ALPHA);
            }

            gl::DrawElements(gl::TRIANGLES, num_indices, gl::UNSIGNED_SHORT, ptr::null());
        }

        self.batch.clear();
    }
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
struct TextVertex {
    // Cell coordinates.
    x: i16,
    y: i16,

    // Glyph coordinates.
    glyph_x: i16,
    glyph_y: i16,

    // Offsets into Atlas.
    u: f32,
    v: f32,