Skip to content

Commit

Permalink
Output image is cleared when a new image is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
jobtalle committed May 30, 2023
1 parent 91f9cec commit dcb1f48
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions js/sdfMaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ export class SDFMaker {
gl.bindTexture(gl.TEXTURE_2D, this.#input);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this.#inputTarget);

this.#clearOutputImage();

this.#loaded = true;
}

#clearOutputImage() {
if (this.#outputImage) {
this.#outputContainer.removeChild(this.#outputImage);

Expand All @@ -233,8 +239,6 @@ export class SDFMaker {
this.#outputImage = null;
this.#updated = true;
}

this.#loaded = true;
}

#onDrop(event) {
Expand Down Expand Up @@ -300,6 +304,8 @@ export class SDFMaker {
this.#radius,
this.#threshold);

this.#clearOutputImage();

this.#outputContainer.appendChild(this.#outputImage = this.#makeOutputImage(
this.#outputWidth,
this.#outputHeight,
Expand All @@ -324,7 +330,7 @@ export class SDFMaker {
if (this.#updated) {
gl.clear(gl.COLOR_BUFFER_BIT);

if (this.#previewVisible) {
if (this.#previewVisible && this.#outputImage) {
this.#shaderPreview.use();
this.#shaderPreview.setCenter(this.#previewX / SDFMaker.#SIZE, this.#previewY / SDFMaker.#SIZE);
this.#shaderPreview.setZoom(this.#previewZoom ? SDFMaker.#PREVIEW_ZOOM : 1);
Expand Down

0 comments on commit dcb1f48

Please sign in to comment.