<commit_before>import { CpuTimer } from './cpu-timer.js';
import { GpuTimer } from './gpu-timer.js';

// render 2d textured quads
function Render2d(device, maxQuads) {
    maxQuads = maxQuads || 128;

    var vertexShader =
        'attribute vec2 vertex_position;\n' +       // unnormalized
        'attribute vec4 vertex_texCoord0;\n' +      // unnormalized texture space uv, normalized uv
        'uniform vec4 screenAndTextureSize;\n' +    // xy: screen size, zw: texture size
        'varying vec4 uv0;\n' +
        'void main(void) {\n' +
        '    vec2 pos = vertex_position.xy / screenAndTextureSize.xy;\n' +
        '    gl_Position = vec4(pos * 2.0 - 1.0, 0.5, 1.0);\n' +
        '    uv0 = vec4(vertex_texCoord0.xy / screenAndTextureSize.zw, vertex_texCoord0.zw);\n' +
        '}\n';

    // this fragment shader renders the bits required for text and graphs. The text is identified
    // in the texture by its white color channel. The graph data is specified as a single row of
    // pixels where the R channel denotes the height of the 1st graph and the G channel the height
    // of the second graph (the B channel could also be used, but is currently not).
    var fragmentShader =
        'varying vec4 uv0;\n' +
        'uniform vec4 clr;\n' +
        'uniform sampler2D source;\n' +
        'void main (void) {\n' +
        '    vec4 tex = texture2D(source, uv0.xy);\n' +
        '    if (tex.rgb != vec3(1, 1, 1)) {\n' +
        '       if (uv0.w < tex.r)\n' +
        '           tex = vec4(1.0, 0.3, 0.3, 1.0);\n' +
        '       else if (uv0.w < tex.g)\n' +
        '           tex = vec4(0.3, 1.0, 0.3, 1.0);\n' +
        '       else\n' +
        '           tex = vec4(0.0, 0.0, 0.0, 1.0);\n' +
        '    }\n' +
        '    gl_FragColor = tex * clr;\n' +
        '}\n';

    var format = new pc.VertexFormat(device, [{
        semantic: pc.SEMANTIC_POSITION,
        components: 2,
        type: pc.TYPE_FLOAT32
    }, {
        semantic: pc.SEMANTIC_TEXCOORD0,
        components: 4,
        type: pc.TYPE_FLOAT32
    }]);

    // generate quad indices
    var indices = new Uint32Array(maxQuads * 6);
    for (var i = 0; i < maxQuads; ++i) {
        indices[i * 6 + 0] = i * 4;
        indices[i * 6 + 1] = i * 4 + 1;
        indices[i * 6 + 2] = i * 4 + 2;
        indices[i * 6 + 3] = i * 4;
        indices[i * 6 + 4] = i * 4 + 2;
        indices[i * 6 + 5] = i * 4 + 3;
    }

    this.device = device;
    this.shader = pc.shaderChunks.createShaderFromCode(device,
                                                       vertexShader,
                                                       fragmentShader,
                                                       "mini-stats");
    this.buffer = new pc.VertexBuffer(device, format, maxQuads * 4, pc.BUFFER_STREAM);
    this.data = new Float32Array(this.buffer.numBytes / 4);

    this.indexBuffer = new pc.IndexBuffer(device, pc.INDEXFORMAT_UINT32, maxQuads * 6, pc.BUFFER_STATIC, indices);

    this.prims = [];
    this.prim = null;
    this.primIndex = -1;
    this.quads = 0;

    this.clrId = device.scope.resolve('clr');
    this.clr = new Float32Array(4);

    this.screenTextureSizeId = device.scope.resolve('screenAndTextureSize');
    this.screenTextureSize = new Float32Array(4);
}

Object.assign(Render2d.prototype, {
    quad: function (texture, x, y, w, h, u, v, uw, uh) {
        var quad = this.quads++;

        // update primitive
        var prim = this.prim;
        if (prim && prim.texture === texture) {
            prim.count += 6;
        } else {
            this.primIndex++;
            if (this.primIndex === this.prims.length) {<commit_msg>[Fix] Mini-stats uses 16bit index buffer insead of 32 (#2347)<commit_after>import { CpuTimer } from './cpu-timer.js';
import { GpuTimer } from './gpu-timer.js';

// render 2d textured quads
function Render2d(device, maxQuads) {
    maxQuads = maxQuads || 128;

    var vertexShader =
        'attribute vec2 vertex_position;\n' +       // unnormalized
        'attribute vec4 vertex_texCoord0;\n' +      // unnormalized texture space uv, normalized uv
        'uniform vec4 screenAndTextureSize;\n' +    // xy: screen size, zw: texture size
        'varying vec4 uv0;\n' +
        'void main(void) {\n' +
        '    vec2 pos = vertex_position.xy / screenAndTextureSize.xy;\n' +
        '    gl_Position = vec4(pos * 2.0 - 1.0, 0.5, 1.0);\n' +
        '    uv0 = vec4(vertex_texCoord0.xy / screenAndTextureSize.zw, vertex_texCoord0.zw);\n' +
        '}\n';

    // this fragment shader renders the bits required for text and graphs. The text is identified
    // in the texture by its white color channel. The graph data is specified as a single row of
    // pixels where the R channel denotes the height of the 1st graph and the G channel the height
    // of the second graph (the B channel could also be used, but is currently not).
    var fragmentShader =
        'varying vec4 uv0;\n' +
        'uniform vec4 clr;\n' +
        'uniform sampler2D source;\n' +
        'void main (void) {\n' +
        '    vec4 tex = texture2D(source, uv0.xy);\n' +
        '    if (tex.rgb != vec3(1, 1, 1)) {\n' +
        '       if (uv0.w < tex.r)\n' +
        '           tex = vec4(1.0, 0.3, 0.3, 1.0);\n' +
        '       else if (uv0.w < tex.g)\n' +
        '           tex = vec4(0.3, 1.0, 0.3, 1.0);\n' +
        '       else\n' +
        '           tex = vec4(0.0, 0.0, 0.0, 1.0);\n' +
        '    }\n' +
        '    gl_FragColor = tex * clr;\n' +
        '}\n';

    var format = new pc.VertexFormat(device, [{
        semantic: pc.SEMANTIC_POSITION,
        components: 2,
        type: pc.TYPE_FLOAT32
    }, {
        semantic: pc.SEMANTIC_TEXCOORD0,
        components: 4,
        type: pc.TYPE_FLOAT32
    }]);

    // generate quad indices
    var indices = new Uint16Array(maxQuads * 6);
    for (var i = 0; i < maxQuads; ++i) {
        indices[i * 6 + 0] = i * 4;
        indices[i * 6 + 1] = i * 4 + 1;
        indices[i * 6 + 2] = i * 4 + 2;
        indices[i * 6 + 3] = i * 4;
        indices[i * 6 + 4] = i * 4 + 2;
        indices[i * 6 + 5] = i * 4 + 3;
    }

    this.device = device;
    this.shader = pc.shaderChunks.createShaderFromCode(device,
                                                       vertexShader,
                                                       fragmentShader,
                                                       "mini-stats");
    this.buffer = new pc.VertexBuffer(device, format, maxQuads * 4, pc.BUFFER_STREAM);
    this.data = new Float32Array(this.buffer.numBytes / 4);

    this.indexBuffer = new pc.IndexBuffer(device, pc.INDEXFORMAT_UINT16, maxQuads * 6, pc.BUFFER_STATIC, indices);

    this.prims = [];
    this.prim = null;
    this.primIndex = -1;
    this.quads = 0;

    this.clrId = device.scope.resolve('clr');
    this.clr = new Float32Array(4);

    this.screenTextureSizeId = device.scope.resolve('screenAndTextureSize');
    this.screenTextureSize = new Float32Array(4);
}

Object.assign(Render2d.prototype, {
    quad: function (texture, x, y, w, h, u, v, uw, uh) {
        var quad = this.quads++;

        // update primitive
        var prim = this.prim;
        if (prim && prim.texture === texture) {
            prim.count += 6;
        } else {
            this.primIndex++;
            if (this.primIndex === this.prims.length) {
{'fraction_non_alphanumeric': 0.13487109905020353, 'fraction_numerical': 0.032564450474898234, 'mean_word_length': 1.7720947724708538, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3806698', 'n_tokens_mistral': 2579, 'n_tokens_neox': 2395, 'n_words': 651}