Skip to content

Commit

Permalink
Merge pull request #28 from Live2D/feature/fix_sprite_memory_leak
Browse files Browse the repository at this point in the history
Fix sprite buffer memory leak
  • Loading branch information
ono-at-live2d-com authored May 8, 2019
2 parents ea8be62 + 7f417e0 commit a376b6e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions Sample/TypeScript/Demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<head>
<meta charset="utf-8" />
<title>TypeScript HTML App</title>
<meta name="viewport" content="width=1900">
</head>
<body>
<!-- Canvas -->
Expand Down
24 changes: 12 additions & 12 deletions Sample/TypeScript/Demo/src/lappsprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ import { gl, canvas } from "./lappdelegate";

// uvバッファ、座標初期化
{
this._uvArray = [
this._uvArray = new Float32Array([
1.0, 0.0,
0.0, 0.0,
0.0, 1.0,
1.0, 1.0
];
]);

// uvバッファを作成
this._uvBuffer = gl.createBuffer();
Expand All @@ -121,12 +121,12 @@ import { gl, canvas } from "./lappdelegate";
let maxHeight = canvas.height;

// 頂点データ
this._positionArray = [
this._positionArray = new Float32Array([
(this._rect.right - maxWidth * 0.5) / (maxWidth * 0.5), (this._rect.up - maxHeight * 0.5) / (maxHeight * 0.5),
(this._rect.left - maxWidth * 0.5) / (maxWidth * 0.5), (this._rect.up - maxHeight * 0.5) / (maxHeight * 0.5),
(this._rect.left - maxWidth * 0.5) / (maxWidth * 0.5), (this._rect.down - maxHeight * 0.5) / (maxHeight * 0.5),
(this._rect.right - maxWidth * 0.5) / (maxWidth * 0.5), (this._rect.down - maxHeight * 0.5) / (maxHeight * 0.5)
];
]);

// 頂点バッファを作成
this._vertexBuffer = gl.createBuffer();
Expand All @@ -135,10 +135,10 @@ import { gl, canvas } from "./lappdelegate";
// 頂点インデックスバッファ、初期化
{
// インデックスデータ
this._indexArray = [
this._indexArray = new Uint16Array([
0, 1, 2,
3, 2, 0
];
]);

// インデックスバッファを作成
this._indexBuffer = gl.createBuffer();
Expand All @@ -149,21 +149,21 @@ import { gl, canvas } from "./lappdelegate";

// UV座標登録
gl.bindBuffer(gl.ARRAY_BUFFER, this._uvBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this._uvArray), gl.STATIC_DRAW);
gl.bufferData(gl.ARRAY_BUFFER, this._uvArray, gl.STATIC_DRAW);

// attribute属性を登録
gl.vertexAttribPointer(this._uvLocation, 2, gl.FLOAT, false, 0, 0);

// 頂点座標を登録
gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this._positionArray), gl.STATIC_DRAW);
gl.bufferData(gl.ARRAY_BUFFER, this._positionArray, gl.STATIC_DRAW);

// attribute属性を登録
gl.vertexAttribPointer(this._positionLocation, 2, gl.FLOAT, false, 0, 0);

// 頂点インデックスを作成
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(this._indexArray), gl.DYNAMIC_DRAW);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this._indexArray, gl.DYNAMIC_DRAW);

// モデルの描画
gl.bindTexture(gl.TEXTURE_2D, this._texture);
Expand Down Expand Up @@ -198,9 +198,9 @@ import { gl, canvas } from "./lappdelegate";
_uvLocation: number;
_textureLocation: WebGLUniformLocation;

_positionArray: number[];
_uvArray: number[];
_indexArray: number[];
_positionArray: Float32Array;
_uvArray: Float32Array;
_indexArray: Uint16Array;

_firstDraw: boolean;
}
Expand Down

0 comments on commit a376b6e

Please sign in to comment.