<commit_before>var fs = require('fs');
var plask = require('plask');

var vert = fs.readFileSync(__dirname + '/PlaskVideo.vert', 'utf8');
var frag = fs.readFileSync(__dirname + '/PlaskVideo.frag', 'utf8');

function PlaskVideo(ctx, file) {
    this.ctx = ctx;

    this.planeVAO = this.createPlaneVAO();

    this.player = new plask.AVPlayer(ctx.getGL());
    if (file) {
        this.player.appendFile(file);
    }

    this.videoTexture = ctx.createTexture2D(null, 1280, 1280);

    this.fbo = ctx.createFramebuffer([ { texture: this.videoTexture } ]);

    this.program = ctx.createProgram(vert, frag);

    var loops = false;

    Object.defineProperty(this, 'duration', {
        get: function() { return this.player.currentDuration(); }
    });

    Object.defineProperty(this, 'currentTime', {
        get: function() { return this.player.currentTime(); },
        set: function(time) { this.player.seekToTime(time); }
    });

    Object.defineProperty(this, 'loop', {
        get: function() { return loops; },
        set: function(state) { loops = state; this.player.setLoops(state); }
    });
}

PlaskVideo.prototype.getTexture = function() {
    return this.videoTexture;
}

PlaskVideo.prototype.update = function() {
    if (this.player.rate() === 0) this.player.setRate(1);

    var tex = this.player.currentFrameTexture();
    var ctx = this.ctx;
    var gl = ctx.getGL();

    gl.enable(gl.TEXTURE_RECTANGLE);
    ctx.pushState(ctx.FRAMEBUFFER_BIT | ctx.PROGRAM_BUT | ctx.TEXTURE_BIT | ctx.VERTEX_ARRAY_BIT | ctx.VIEWPORT_BIT);
    ctx.bindFramebuffer(this.fbo);
    ctx.setViewport(0, 0, this.videoTexture.getWidth(), this.videoTexture.getHeight())
    ctx.setClearColor(1,0,0,1);
    ctx.clear(ctx.COLOR_BIT);
    ctx.bindProgram(this.program);
    if (tex) {
        gl.activeTexture(gl.TEXTURE0);
        gl.bindTexture(gl.TEXTURE_RECTANGLE, tex.texture);<commit_msg>PlaskVideo automatically update videoTexture size<commit_after>var fs = require('fs');
var plask = require('plask');

var vert = fs.readFileSync(__dirname + '/PlaskVideo.vert', 'utf8');
var frag = fs.readFileSync(__dirname + '/PlaskVideo.frag', 'utf8');

function PlaskVideo(ctx, file) {
    this.ctx = ctx;

    this.planeVAO = this.createPlaneVAO();

    this.player = new plask.AVPlayer(ctx.getGL());
    if (file) {
        this.player.appendFile(file);
    }

    this.videoTexture = ctx.createTexture2D(null, 1, 1);

    this.fbo = ctx.createFramebuffer([ { texture: this.videoTexture } ]);

    this.program = ctx.createProgram(vert, frag);

    var loops = false;

    Object.defineProperty(this, 'duration', {
        get: function() { return this.player.currentDuration(); }
    });

    Object.defineProperty(this, 'currentTime', {
        get: function() { return this.player.currentTime(); },
        set: function(time) { this.player.seekToTime(time); }
    });

    Object.defineProperty(this, 'loop', {
        get: function() { return loops; },
        set: function(state) { loops = state; this.player.setLoops(state); }
    });
}

PlaskVideo.prototype.getTexture = function() {
    return this.videoTexture;
}

PlaskVideo.prototype.update = function() {
    if (this.player.rate() === 0) this.player.setRate(1);

    var tex = this.player.currentFrameTexture();
    var ctx = this.ctx;
    var gl = ctx.getGL();

    if (tex && (tex.s1 != this.videoTexture.getWidth() || tex.t1 != this.videoTexture.getHeight())) {
        //resize video texture to match the video size
        this.videoTexture.update(null, tex.s1, tex.t1)
    }

    gl.enable(gl.TEXTURE_RECTANGLE);
    ctx.pushState(ctx.FRAMEBUFFER_BIT | ctx.PROGRAM_BUT | ctx.TEXTURE_BIT | ctx.VERTEX_ARRAY_BIT | ctx.VIEWPORT_BIT);
    ctx.bindFramebuffer(this.fbo);
    ctx.setViewport(0, 0, this.videoTexture.getWidth(), this.videoTexture.getHeight())
    ctx.setClearColor(1,0,0,1);
    ctx.clear(ctx.COLOR_BIT);
    ctx.bindProgram(this.program);
    if (tex) {
        gl.activeTexture(gl.TEXTURE0);
        gl.bindTexture(gl.TEXTURE_RECTANGLE, tex.texture);
{'fraction_non_alphanumeric': 0.15453416149068322, 'fraction_numerical': 0.009440993788819876, 'mean_word_length': 3.4683684794672587, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5234460', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1311, 'n_words': 234}