<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use debug_font_data;
use device::{Device, GpuMarker, Program, VAOId, TextureId, VertexDescriptor};
use device::{TextureFilter, VertexAttribute, VertexUsageHint, VertexAttributeKind, TextureTarget};
use euclid::{Transform3D, Point2D, Size2D, Rect};
use internal_types::{ORTHO_NEAR_PLANE, ORTHO_FAR_PLANE, TextureSampler};
use internal_types::RenderTargetMode;
use std::f32;
use api::{ColorU, ImageFormat, DeviceUintSize};

const DESC_FONT: VertexDescriptor = VertexDescriptor {
    vertex_attributes: &[
        VertexAttribute { name: "aPosition", count: 2, kind: VertexAttributeKind::F32 },
        VertexAttribute { name: "aColor", count: 4, kind: VertexAttributeKind::U8Norm },
        VertexAttribute { name: "aColorTexCoord", count: 2, kind: VertexAttributeKind::F32 },
    ],
    instance_attributes: &[]
};

const DESC_COLOR: VertexDescriptor = VertexDescriptor {
    vertex_attributes: &[
        VertexAttribute { name: "aPosition", count: 2, kind: VertexAttributeKind::F32 },
        VertexAttribute { name: "aColor", count: 4, kind: VertexAttributeKind::U8Norm },
    ],
    instance_attributes: &[]
};

#[repr(C)]
pub struct DebugFontVertex {
    pub x: f32,
    pub y: f32,
    pub color: ColorU,
    pub u: f32,
    pub v: f32,
}

impl DebugFontVertex {
    pub fn new(x: f32, y: f32, u: f32, v: f32, color: ColorU) -> DebugFontVertex {
        DebugFontVertex {
            x,
            y,
            color,
            u,
            v,
        }
    }
}

#[repr(C)]
pub struct DebugColorVertex {
    pub x: f32,
    pub y: f32,
    pub color: ColorU,
}

impl DebugColorVertex {
    pub fn new(x: f32, y: f32, color: ColorU) -> DebugColorVertex {
        DebugColorVertex {
            x,
            y,
            color,
        }
    }
}

pub struct DebugRenderer {
    font_vertices: Vec<DebugFontVertex>,
    font_indices: Vec<u32>,
    font_program: Program,
    font_vao: VAOId,
    font_texture_id: TextureId,

    tri_vertices: Vec<DebugColorVertex>,
    tri_indices: Vec<u32>,
    tri_vao: VAOId,
    line_vertices: Vec<DebugColorVertex>,
    line_vao: VAOId,
    color_program: Program,
}

impl DebugRenderer {
    pub fn new(device: &mut Device) -> DebugRenderer {
        let font_program = device.create_program("debug_font", "shared_other", &DESC_FONT).unwrap();
        let color_program = device.create_program("debug_color", "shared_other", &DESC_COLOR).unwrap();

        let font_vao = device.create_vao(&DESC_FONT, 32);
        let line_vao = device.create_vao(&DESC_COLOR, 32);
        let tri_vao = device.create_vao(&DESC_COLOR, 32);

        let font_texture_id = device.create_texture_ids(1, TextureTarget::Default)[0];
        device.init_texture(font_texture_id,
                            debug_font_data::BMP_WIDTH,
                            debug_font_data::BMP_HEIGHT,
                            ImageFormat::A8,
                            TextureFilter::Linear,
                            RenderTargetMode::None,
                            Some(&debug_font_data::FONT_BITMAP));

        DebugRenderer {
            font_vertices: Vec::new(),
            font_indices: Vec::new(),
            line_vertices: Vec::new(),
            tri_vao,
            tri_vertices: Vec::new(),
            tri_indices: Vec::new(),
            font_program,
            color_program,
            font_vao,
            line_vao,
            font_texture_id,
        }
    }

    pub fn deinit(&mut self, device: &mut Device) {
        device.delete_program(&mut self.font_program);
        device.delete_program(&mut self.color_program);
    }

    pub fn line_height(&self) -> f32 {
        debug_font_data::FONT_SIZE as f32 * 1.1
    }
<commit_msg>Switch debug renderer to use array textures.<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use debug_font_data;
use device::{Device, GpuMarker, Program, VAOId, TextureId, VertexDescriptor};
use device::{TextureFilter, VertexAttribute, VertexUsageHint, VertexAttributeKind, TextureTarget};
use euclid::{Transform3D, Point2D, Size2D, Rect};
use internal_types::{ORTHO_NEAR_PLANE, ORTHO_FAR_PLANE, TextureSampler};
use internal_types::RenderTargetMode;
use std::f32;
use api::{ColorU, ImageFormat, DeviceUintSize};

const DESC_FONT: VertexDescriptor = VertexDescriptor {
    vertex_attributes: &[
        VertexAttribute { name: "aPosition", count: 2, kind: VertexAttributeKind::F32 },
        VertexAttribute { name: "aColor", count: 4, kind: VertexAttributeKind::U8Norm },
        VertexAttribute { name: "aColorTexCoord", count: 2, kind: VertexAttributeKind::F32 },
    ],
    instance_attributes: &[]
};

const DESC_COLOR: VertexDescriptor = VertexDescriptor {
    vertex_attributes: &[
        VertexAttribute { name: "aPosition", count: 2, kind: VertexAttributeKind::F32 },
        VertexAttribute { name: "aColor", count: 4, kind: VertexAttributeKind::U8Norm },
    ],
    instance_attributes: &[]
};

#[repr(C)]
pub struct DebugFontVertex {
    pub x: f32,
    pub y: f32,
    pub color: ColorU,
    pub u: f32,
    pub v: f32,
}

impl DebugFontVertex {
    pub fn new(x: f32, y: f32, u: f32, v: f32, color: ColorU) -> DebugFontVertex {
        DebugFontVertex {
            x,
            y,
            color,
            u,
            v,
        }
    }
}

#[repr(C)]
pub struct DebugColorVertex {
    pub x: f32,
    pub y: f32,
    pub color: ColorU,
}

impl DebugColorVertex {
    pub fn new(x: f32, y: f32, color: ColorU) -> DebugColorVertex {
        DebugColorVertex {
            x,
            y,
            color,
        }
    }
}

pub struct DebugRenderer {
    font_vertices: Vec<DebugFontVertex>,
    font_indices: Vec<u32>,
    font_program: Program,
    font_vao: VAOId,
    font_texture_id: TextureId,

    tri_vertices: Vec<DebugColorVertex>,
    tri_indices: Vec<u32>,
    tri_vao: VAOId,
    line_vertices: Vec<DebugColorVertex>,
    line_vao: VAOId,
    color_program: Program,
}

impl DebugRenderer {
    pub fn new(device: &mut Device) -> DebugRenderer {
        let font_program = device.create_program("debug_font", "shared_other", &DESC_FONT).unwrap();
        let color_program = device.create_program("debug_color", "shared_other", &DESC_COLOR).unwrap();

        let font_vao = device.create_vao(&DESC_FONT, 32);
        let line_vao = device.create_vao(&DESC_COLOR, 32);
        let tri_vao = device.create_vao(&DESC_COLOR, 32);

        let font_texture_id = device.create_texture_ids(1, TextureTarget::Array)[0];
        device.init_texture(font_texture_id,
                            debug_font_data::BMP_WIDTH,
                            debug_font_data::BMP_HEIGHT,
                            ImageFormat::A8,
                            TextureFilter::Linear,
                            RenderTargetMode::None,
                            1,
                            Some(&debug_font_data::FONT_BITMAP));

        DebugRenderer {
            font_vertices: Vec::new(),
            font_indices: Vec::new(),
            line_vertices: Vec::new(),
            tri_vao,
            tri_vertices: Vec::new(),
            tri_indices: Vec::new(),
            font_program,
            color_program,
            font_vao,
            line_vao,
            font_texture_id,
        }
    }

    pub fn deinit(&mut self, device: &mut Device) {
        device.delete_program(&mut self.font_program);
        device.delete_program(&mut self.color_program);
    }

    pub fn line_height(&self) -> f32 {
        debug_font_data::FONT_SIZE as f32 * 1.1
    }

{'fraction_non_alphanumeric': 0.10905401978189196, 'fraction_numerical': 0.016611716966776567, 'mean_word_length': 2.5288590604026844, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, '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': '5806032', 'n_tokens_mistral': 2562, 'n_tokens_neox': 2470, 'n_words': 575}