Skip to content

Commit

Permalink
memory management to make chrome happy
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoes committed Jul 31, 2024
1 parent 088559d commit 3af47bb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 42 deletions.
14 changes: 8 additions & 6 deletions src/GLShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1475,12 +1475,14 @@ export class GLShape {

this.shapeObj.add(mesh);

var lineMaterial = new LineBasicMaterial({
linewidth: this.linewidth,
color: this.color
});
var line = new Line(this.linegeo, lineMaterial as Material, LineStyle.LinePieces);
this.shapeObj.add(line);
if(this.linegeo && this.linegeo.vertices > 0) {
var lineMaterial = new LineBasicMaterial({
linewidth: this.linewidth,
color: this.color
});
var line = new Line(this.linegeo, lineMaterial as Material, LineStyle.LinePieces);
this.shapeObj.add(line);
}

this.renderedShapeObj = this.shapeObj.clone();
group.add(this.renderedShapeObj);
Expand Down
79 changes: 43 additions & 36 deletions src/WebGL/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -934,42 +934,49 @@ export class Renderer {
this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._gl.CLAMP_TO_EDGE);

//shading texture - for AO and maybe eventually shadows? I don't like shadows

this._gl.bindTexture(this._gl.TEXTURE_2D, this._shadingTexture);
this._gl.texImage2D(
this._gl.TEXTURE_2D,
0,
(this._gl as WebGL2RenderingContext).DEPTH_COMPONENT32F,
width,
height,
0,
this._gl.DEPTH_COMPONENT,
this._gl.FLOAT,
null
);
this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, this._gl.NEAREST);
this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MAG_FILTER, this._gl.NEAREST);
this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, this._gl.CLAMP_TO_EDGE);
this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._gl.CLAMP_TO_EDGE);

//scratch texture, needed by AO to do blur
this._gl.bindTexture(this._gl.TEXTURE_2D, this._scratchTexture);
this._gl.texImage2D(
this._gl.TEXTURE_2D,
0,
(this._gl as WebGL2RenderingContext).DEPTH_COMPONENT32F,
width,
height,
0,
this._gl.DEPTH_COMPONENT,
this._gl.FLOAT,
null
);
this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, this._gl.NEAREST);
this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MAG_FILTER, this._gl.NEAREST);
this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, this._gl.CLAMP_TO_EDGE);
this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._gl.CLAMP_TO_EDGE);

if(this._shadingTexture) {
//for whatever reason, chrome seems to require this manual memory management
//for these textures, at least in the auto tests webpage where many viewers are being created/destroyed
this._gl.deleteTexture(this._shadingTexture);
this._shadingTexture = this._gl.createTexture();
this._gl.bindTexture(this._gl.TEXTURE_2D, this._shadingTexture);
this._gl.texImage2D(
this._gl.TEXTURE_2D,
0,
(this._gl as WebGL2RenderingContext).DEPTH_COMPONENT32F,
width,
height,
0,
this._gl.DEPTH_COMPONENT,
this._gl.FLOAT,
null
);
this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, this._gl.NEAREST);
this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MAG_FILTER, this._gl.NEAREST);
this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, this._gl.CLAMP_TO_EDGE);
this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._gl.CLAMP_TO_EDGE);

//scratch texture, needed by AO to do blur
this._gl.deleteTexture(this._scratchTexture);
this._scratchTexture = this._gl.createTexture();
this._gl.bindTexture(this._gl.TEXTURE_2D, this._scratchTexture);
this._gl.texImage2D(
this._gl.TEXTURE_2D,
0,
(this._gl as WebGL2RenderingContext).DEPTH_COMPONENT32F,
width,
height,
0,
this._gl.DEPTH_COMPONENT,
this._gl.FLOAT,
null
);
this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, this._gl.NEAREST);
this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MAG_FILTER, this._gl.NEAREST);
this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, this._gl.CLAMP_TO_EDGE);
this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._gl.CLAMP_TO_EDGE);

}
//bind fb
this._gl.bindFramebuffer(this._gl.FRAMEBUFFER, this._fb);
this._gl.framebufferTexture2D(
Expand Down

0 comments on commit 3af47bb

Please sign in to comment.