Skip to content

Commit

Permalink
Better "destroy" for particles and ribbons
Browse files Browse the repository at this point in the history
  • Loading branch information
4eb0da committed May 2, 2022
1 parent c6fffdc commit 8e471f1
Show file tree
Hide file tree
Showing 5 changed files with 380 additions and 323 deletions.
2 changes: 1 addition & 1 deletion docs/preview/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ function initDragDrop () {


function setTextures (textures) {
let promises: Promise<void>[] = [];
const promises: Promise<void>[] = [];

for (const texture of model.Textures) {
if (texture.Image) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "war3-model",
"version": "2.1.0",
"version": "2.2.0",
"description": "Warcraft 3 model parser, generator, convertor and previewer",
"keywords": [
"warcraft3",
Expand Down
17 changes: 13 additions & 4 deletions renderer/modelRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {vec3, quat, mat3, mat4} from 'gl-matrix';
import parseDds from 'parse-dds';
import {mat4fromRotationOrigin, getShader, isWebGL2} from './util';
import {ModelInterp} from './modelInterp';
import {ParticlesController} from './particles';
import {RendererData, NodeWrapper} from './rendererData';
import {ParticlesController} from './particles';
import {RibbonsController} from './ribbons';

// actually, all is number
Expand Down Expand Up @@ -338,6 +338,15 @@ export class ModelRenderer {
}

public destroy (): void {
if (this.particlesController) {
this.particlesController.destroy();
this.particlesController = null;
}
if (this.ribbonsController) {
this.ribbonsController.destroy();
this.ribbonsController = null;
}

if (this.skeletonShaderProgram) {
if (this.skeletonVertexShader) {
this.gl.detachShader(this.skeletonShaderProgram, this.skeletonVertexShader);
Expand Down Expand Up @@ -369,7 +378,7 @@ export class ModelRenderer {
}
}

public initGL (glContext: WebGLRenderingContext): void {
public initGL (glContext: WebGL2RenderingContext | WebGLRenderingContext): void {
this.gl = glContext;
// Max bones + MV + P
this.softwareSkinning = this.gl.getParameter(this.gl.MAX_VERTEX_UNIFORM_VECTORS) < 4 * (MAX_NODES + 2);
Expand All @@ -380,8 +389,8 @@ export class ModelRenderer {
);
this.initShaders();
this.initBuffers();
ParticlesController.initGL(glContext);
RibbonsController.initGL(glContext);
this.particlesController.initGL(glContext);
this.ribbonsController.initGL(glContext);
}

public setTextureImage (path: string, img: HTMLImageElement, flags: TextureFlags): void {
Expand Down
Loading

0 comments on commit 8e471f1

Please sign in to comment.