<commit_before>use std::default::Default;
use std::marker::PhantomData;
use std::mem;

use gfx;
use gfx::traits::*;

use bitmap_font::BitmapFont;
use utils::{grow_buffer, MAT4_ID};

pub struct TextRenderer<R: gfx::Resources> {
    program: gfx::handle::Program<R>,
    state: gfx::DrawState,
    bitmap_font: BitmapFont,
    vertex_data: Vec<Vertex>,
    index_data: Vec<u32>,
    vertex_buffer: gfx::handle::Buffer<R, Vertex>,
    index_buffer: gfx::handle::IndexBuffer<R, u32>,
    params: TextShaderParams<R>,
}

impl<R: gfx::Resources> TextRenderer<R> {

    pub fn new<F: gfx::Factory<R>> (
        device_capabilities: gfx::device::Capabilities,
        factory: &mut F,
        frame_size: [u32; 2],
        initial_buffer_size: usize,
        bitmap_font: BitmapFont,
        font_texture: gfx::handle::Texture<R>,
    ) -> Result<TextRenderer<R>, gfx::ProgramError> {

        let shader_model = device_capabilities.shader_model;

        let vertex = gfx::ShaderSource {
            glsl_120: Some(VERTEX_SRC[0]),
            glsl_150: Some(VERTEX_SRC[1]),
            .. gfx::ShaderSource::empty()
        };

        let fragment = gfx::ShaderSource {
            glsl_120: Some(FRAGMENT_SRC[0]),
            glsl_150: Some(FRAGMENT_SRC[1]),
            .. gfx::ShaderSource::empty()
        };

        let program = match factory.link_program(
            vertex.choose(shader_model).unwrap(),
            fragment.choose(shader_model).unwrap()
        ) {
            Ok(program_handle) => program_handle,
            Err(e) => return Err(e),
        };

        let vertex_buffer = factory.create_buffer::<Vertex>(initial_buffer_size, gfx::BufferUsage::Dynamic);
        let index_buffer = gfx::handle::IndexBuffer::from_raw(
            factory.create_buffer_raw(initial_buffer_size * mem::size_of::<u32>(), gfx::BufferUsage::Dynamic)
        );

        let sampler = factory.create_sampler(
           gfx::tex::SamplerInfo::new(
               gfx::tex::FilterMethod::Scale,
               gfx::tex::WrapMode::Clamp
            )
        );

        let state = gfx::DrawState::new().blend(gfx::BlendPreset::Alpha);

        Ok(TextRenderer {
            vertex_data: Vec::new(),
            index_data: Vec::new(),
            bitmap_font: bitmap_font,
            program: program,
            state: state,
            vertex_buffer: vertex_buffer,
            index_buffer: index_buffer,
            params: TextShaderParams {<commit_msg>Using link_program_source<commit_after>use std::default::Default;
use std::marker::PhantomData;
use std::mem;

use gfx;
use gfx::traits::*;

use bitmap_font::BitmapFont;
use utils::{grow_buffer, MAT4_ID};

pub struct TextRenderer<R: gfx::Resources> {
    program: gfx::handle::Program<R>,
    state: gfx::DrawState,
    bitmap_font: BitmapFont,
    vertex_data: Vec<Vertex>,
    index_data: Vec<u32>,
    vertex_buffer: gfx::handle::Buffer<R, Vertex>,
    index_buffer: gfx::handle::IndexBuffer<R, u32>,
    params: TextShaderParams<R>,
}

impl<R: gfx::Resources> TextRenderer<R> {

    pub fn new<F: gfx::Factory<R>> (
        device_capabilities: gfx::device::Capabilities,
        factory: &mut F,
        frame_size: [u32; 2],
        initial_buffer_size: usize,
        bitmap_font: BitmapFont,
        font_texture: gfx::handle::Texture<R>,
    ) -> Result<TextRenderer<R>, gfx::ProgramError> {

        let vertex = gfx::ShaderSource {
            glsl_120: Some(VERTEX_SRC[0]),
            glsl_150: Some(VERTEX_SRC[1]),
            .. gfx::ShaderSource::empty()
        };

        let fragment = gfx::ShaderSource {
            glsl_120: Some(FRAGMENT_SRC[0]),
            glsl_150: Some(FRAGMENT_SRC[1]),
            .. gfx::ShaderSource::empty()
        };

        let program = match factory.link_program_source(
            vertex, fragment, &device_capabilities
        ) {
            Ok(program_handle) => program_handle,
            Err(e) => return Err(e),
        };

        let vertex_buffer = factory.create_buffer::<Vertex>(initial_buffer_size, gfx::BufferUsage::Dynamic);
        let index_buffer = gfx::handle::IndexBuffer::from_raw(
            factory.create_buffer_raw(initial_buffer_size * mem::size_of::<u32>(), gfx::BufferUsage::Dynamic)
        );

        let sampler = factory.create_sampler(
           gfx::tex::SamplerInfo::new(
               gfx::tex::FilterMethod::Scale,
               gfx::tex::WrapMode::Clamp
            )
        );

        let state = gfx::DrawState::new().blend(gfx::BlendPreset::Alpha);

        Ok(TextRenderer {
            vertex_data: Vec::new(),
            index_data: Vec::new(),
            bitmap_font: bitmap_font,
            program: program,
            state: state,
            vertex_buffer: vertex_buffer,
            index_buffer: index_buffer,
            params: TextShaderParams {
{'fraction_non_alphanumeric': 0.13434071620782448, 'fraction_numerical': 0.010763817015110743, 'mean_word_length': 2.6578349735049205, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6678287', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1497, 'n_words': 251}