texture dimensions

This commit is contained in:
Gyuri Horák 2023-02-26 16:56:55 +01:00
parent ae27c95b3d
commit 46064c7d93
Signed by: dyuri
GPG Key ID: 4993F07B3EAE8D38
2 changed files with 7 additions and 1 deletions

View File

@ -326,6 +326,7 @@ class RepaShader extends HTMLElement {
this._textures.forEach((t) => {
this._uniLocation[t.texElement.name] = this._gl.getUniformLocation(this.program, t.texElement.name); // texture
this._uniLocation[t.texElement.name+'_d'] = this._gl.getUniformLocation(this.program, t.texElement.name+'_d'); // dimensions
t.texElement.forceUpdate();
});
this._attLocation = this._gl.getAttribLocation(this.program, 'position');
@ -377,7 +378,7 @@ class RepaShader extends HTMLElement {
}
this._gl.uniform1i(this._uniLocation[t.texElement.name], i + this.mrt);
// TODO dimension
this._gl.uniform2fv(this._uniLocation[t.texElement.name+'_d'], [t.texElement.width || 1, t.texElement.height || 1]);
});
this._gl.drawArrays(this._gl.TRIANGLE_STRIP, 0, 4);
@ -535,6 +536,7 @@ void main() {
return this._textures.map(t => {
return `
uniform sampler2D ${t.texElement.name};
uniform vec2 ${t.texElement.name}_d;
`;
}).join('');
}

View File

@ -242,6 +242,10 @@ class RepaTexture extends HTMLElement {
return this.content;
}
forceUpdate() {
this._forceUpdate = true;
}
get shouldUpdate() {
return this.ready && (this._forceUpdate || (this.ref && this.ref instanceof HTMLVideoElement && this.ref.readyState === this.ref.HAVE_ENOUGH_DATA));
}