-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c0f2c4
commit 5c80527
Showing
8 changed files
with
341 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import {assertEquals, assertStrictEquals} from "std/testing/asserts.ts"; | ||
import {Mesh, Vec3} from "../../../../../src/mod.js"; | ||
import {FakeVertexState, mockVertexStateSingleAttribute} from "./shared.js"; | ||
import {assertVecAlmostEquals} from "../../../shared/asserts.js"; | ||
|
||
Deno.test({ | ||
name: "maintains the same vertexState instance", | ||
fn() { | ||
const mesh = new Mesh(); | ||
const vertexState = /** @type {import("../../../../../src/mod.js").VertexState} */ (new FakeVertexState([])); | ||
mesh.setVertexState(vertexState); | ||
|
||
const clone = mesh.clone(); | ||
assertStrictEquals(clone.vertexState, vertexState); | ||
}, | ||
}); | ||
|
||
Deno.test({ | ||
name: "clones used buffers", | ||
fn() { | ||
const mesh = new Mesh(); | ||
mesh.setVertexState(mockVertexStateSingleAttribute); | ||
mesh.setVertexCount(3); | ||
mesh.setVertexData(Mesh.AttributeType.POSITION, [new Vec3(1, 2, 3)]); | ||
|
||
const clone = mesh.clone(); | ||
const positionBuffer1 = clone.getBufferForAttributeType(Mesh.AttributeType.POSITION); | ||
const vertexData1 = Array.from(positionBuffer1.getVertexData(Mesh.AttributeType.POSITION)); | ||
assertVecAlmostEquals(vertexData1[0], [1, 2, 3]); | ||
|
||
mesh.setVertexData(Mesh.AttributeType.POSITION, [new Vec3(4, 5, 6)]); | ||
const positionBuffer2 = clone.getBufferForAttributeType(Mesh.AttributeType.POSITION); | ||
const vertexData2 = Array.from(positionBuffer2.getVertexData(Mesh.AttributeType.POSITION)); | ||
assertVecAlmostEquals(vertexData2[0], [1, 2, 3]); | ||
}, | ||
}); | ||
|
||
Deno.test({ | ||
name: "clones unused buffers", | ||
fn() { | ||
const mesh = new Mesh(); | ||
mesh.setVertexCount(3); | ||
mesh.setVertexData(Mesh.AttributeType.POSITION, [new Vec3(1, 2, 3)]); | ||
|
||
const clone = mesh.clone(); | ||
const buffers1 = Array.from(clone.getBuffers()); | ||
assertEquals(buffers1.length, 1); | ||
const vertexData1 = Array.from(buffers1[0].getVertexData(Mesh.AttributeType.POSITION)); | ||
assertVecAlmostEquals(vertexData1[0], [1, 2, 3]); | ||
|
||
mesh.setVertexData(Mesh.AttributeType.POSITION, [new Vec3(4, 5, 6)]); | ||
const buffers2 = Array.from(clone.getBuffers()); | ||
assertEquals(buffers2.length, 1); | ||
const vertexData2 = Array.from(buffers2[0].getVertexData(Mesh.AttributeType.POSITION)); | ||
assertVecAlmostEquals(vertexData2[0], [1, 2, 3]); | ||
}, | ||
}); | ||
|
||
Deno.test({ | ||
name: "clones the index buffer", | ||
fn() { | ||
const mesh = new Mesh(); | ||
mesh.setIndexFormat(Mesh.IndexFormat.UINT_32); | ||
mesh.setIndexData([1, 2, 3]); | ||
|
||
const clone = mesh.clone(); | ||
assertEquals(Array.from(clone.getIndexData()), [1, 2, 3]); | ||
assertEquals(clone.indexFormat, Mesh.IndexFormat.UINT_32); | ||
assertEquals(clone.indexCount, 3); | ||
|
||
mesh.setIndexData([4, 5, 6]); | ||
assertEquals(Array.from(clone.getIndexData()), [1, 2, 3]); | ||
}, | ||
}); | ||
|
||
Deno.test({ | ||
name: "clones the vertex count", | ||
fn() { | ||
const mesh = new Mesh(); | ||
mesh.setVertexCount(3); | ||
|
||
const clone = mesh.clone(); | ||
assertEquals(clone.vertexCount, 3); | ||
|
||
mesh.setVertexCount(4); | ||
assertEquals(clone.vertexCount, 3); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import {Mesh} from "../../../../../src/mod.js"; | ||
|
||
export class FakeVertexState { | ||
/** | ||
* @param {unknown[]} buffers | ||
*/ | ||
constructor(buffers) { | ||
this.buffers = buffers; | ||
} | ||
} | ||
|
||
export const mockVertexStateSingleAttribute = /** @type {import("../../../../../src/mod.js").VertexState} */ (new FakeVertexState([ | ||
{ | ||
attributes: new Map([ | ||
[ | ||
Mesh.AttributeType.POSITION, | ||
{ | ||
attributeType: Mesh.AttributeType.POSITION, | ||
offset: 0, | ||
format: Mesh.AttributeFormat.FLOAT32, | ||
componentCount: 3, | ||
}, | ||
], | ||
]), | ||
}, | ||
])); | ||
export const mockVertexStateTwoAttributes = /** @type {import("../../../../../src/mod.js").VertexState} */ (new FakeVertexState([ | ||
{ | ||
attributes: new Map([ | ||
[ | ||
Mesh.AttributeType.POSITION, | ||
{ | ||
attributeType: Mesh.AttributeType.POSITION, | ||
offset: 0, | ||
format: Mesh.AttributeFormat.FLOAT32, | ||
componentCount: 3, | ||
}, | ||
], | ||
[ | ||
Mesh.AttributeType.NORMAL, | ||
{ | ||
attributeType: Mesh.AttributeType.NORMAL, | ||
offset: 12, | ||
format: Mesh.AttributeFormat.FLOAT32, | ||
componentCount: 3, | ||
}, | ||
], | ||
]), | ||
}, | ||
])); |
Oops, something went wrong.