@flighthq/texture 0.3.0-next.1032.e2b99fc → 0.3.0-next.1220.6982c21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/contract.d.ts +1 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +1 -0
- package/dist/contract.js.map +1 -1
- package/dist/cubeTexture.d.ts +2 -2
- package/dist/cubeTexture.d.ts.map +1 -1
- package/dist/cubeTexture.js +11 -13
- package/dist/cubeTexture.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/renderTexture.d.ts.map +1 -1
- package/dist/renderTexture.js +18 -19
- package/dist/renderTexture.js.map +1 -1
- package/dist/texture.d.ts +28 -5
- package/dist/texture.d.ts.map +1 -1
- package/dist/texture.js +124 -83
- package/dist/texture.js.map +1 -1
- package/dist/videoTexture.d.ts.map +1 -1
- package/dist/videoTexture.js +18 -14
- package/dist/videoTexture.js.map +1 -1
- package/dist/voxelGrid.d.ts +3 -0
- package/dist/voxelGrid.d.ts.map +1 -0
- package/dist/voxelGrid.js +5 -0
- package/dist/voxelGrid.js.map +1 -0
- package/package.json +4 -4
- package/src/cubeTexture.test.ts +31 -31
- package/src/renderTexture.test.ts +3 -6
- package/src/texture.test.ts +107 -86
- package/src/videoTexture.test.ts +15 -13
- package/src/voxelGrid.test.ts +37 -0
package/dist/contract.d.ts
CHANGED
package/dist/contract.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
|
package/dist/contract.js
CHANGED
package/dist/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
|
package/dist/cubeTexture.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { CreateCubeTextureOptions, CubeTexture,
|
|
1
|
+
import type { CreateCubeTextureOptions, CubeTexture, TextureSource } from '@flighthq/types/contract';
|
|
2
2
|
export declare function cloneCubeTexture(source: Readonly<CubeTexture>): CubeTexture;
|
|
3
3
|
export declare function copyCubeTexture(out: CubeTexture, source: Readonly<CubeTexture>): void;
|
|
4
4
|
export declare function createCubeTexture(opts?: Readonly<CreateCubeTextureOptions>): CubeTexture;
|
|
5
5
|
export declare function equalsCubeTexture(a: Readonly<CubeTexture> | null | undefined, b: Readonly<CubeTexture> | null | undefined): boolean;
|
|
6
6
|
export declare function getCubeTextureFaceSize(cube: Readonly<CubeTexture>): number;
|
|
7
7
|
export declare function isCubeTextureComplete(cube: Readonly<CubeTexture>): boolean;
|
|
8
|
-
export declare function setCubeTextureFace(cube: CubeTexture, faceIndex: number,
|
|
8
|
+
export declare function setCubeTextureFace(cube: CubeTexture, faceIndex: number, source: TextureSource | null): void;
|
|
9
9
|
//# sourceMappingURL=cubeTexture.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cubeTexture.d.ts","sourceRoot":"","sources":["../src/cubeTexture.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"cubeTexture.d.ts","sourceRoot":"","sources":["../src/cubeTexture.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,WAAW,EACX,aAAa,EAEd,MAAM,0BAA0B,CAAC;AASlC,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,WAAW,CAE3E;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,CAErF;AAED,wBAAgB,iBAAiB,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,wBAAwB,CAAC,GAAG,WAAW,CAOxF;AAED,wBAAgB,iBAAiB,CAC/B,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,GAAG,SAAS,EAC3C,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,GAAG,SAAS,GAC1C,OAAO,CAGT;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,MAAM,CAO1E;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,OAAO,CAE1E;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI,GAAG,IAAI,CAK3G"}
|
package/dist/cubeTexture.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cloneSampler } from './sampler';
|
|
2
2
|
import { cloneTexture, copyTexture, createTexture, equalsTexture } from './texture';
|
|
3
|
-
function
|
|
4
|
-
return texture.
|
|
3
|
+
function getCubeSources(texture) {
|
|
4
|
+
return texture.sources;
|
|
5
5
|
}
|
|
6
6
|
export function cloneCubeTexture(source) {
|
|
7
7
|
return cloneTexture(source);
|
|
@@ -13,10 +13,8 @@ export function createCubeTexture(opts) {
|
|
|
13
13
|
return createTexture({
|
|
14
14
|
colorSpace: opts?.colorSpace ?? 'srgb',
|
|
15
15
|
sampler: opts?.sampler ? cloneSampler(opts.sampler) : undefined,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
images: opts?.images ?? [null, null, null, null, null, null],
|
|
19
|
-
},
|
|
16
|
+
dimension: 'cube',
|
|
17
|
+
sources: opts?.sources ?? [null, null, null, null, null, null],
|
|
20
18
|
});
|
|
21
19
|
}
|
|
22
20
|
export function equalsCubeTexture(a, b) {
|
|
@@ -25,22 +23,22 @@ export function equalsCubeTexture(a, b) {
|
|
|
25
23
|
return equalsTexture(a, b);
|
|
26
24
|
}
|
|
27
25
|
export function getCubeTextureFaceSize(cube) {
|
|
28
|
-
const
|
|
26
|
+
const sources = getCubeSources(cube);
|
|
29
27
|
for (let i = 0; i < 6; i++) {
|
|
30
|
-
const face =
|
|
28
|
+
const face = sources[i];
|
|
31
29
|
if (face !== null)
|
|
32
30
|
return face.width;
|
|
33
31
|
}
|
|
34
32
|
return -1;
|
|
35
33
|
}
|
|
36
34
|
export function isCubeTextureComplete(cube) {
|
|
37
|
-
return
|
|
35
|
+
return getCubeSources(cube).every((face) => face !== null);
|
|
38
36
|
}
|
|
39
|
-
export function setCubeTextureFace(cube, faceIndex,
|
|
40
|
-
const
|
|
41
|
-
if (
|
|
37
|
+
export function setCubeTextureFace(cube, faceIndex, source) {
|
|
38
|
+
const sources = getCubeSources(cube);
|
|
39
|
+
if (sources[faceIndex] === source)
|
|
42
40
|
return;
|
|
43
|
-
|
|
41
|
+
sources[faceIndex] = source;
|
|
44
42
|
cube.version = (cube.version + 1) >>> 0;
|
|
45
43
|
}
|
|
46
44
|
//# sourceMappingURL=cubeTexture.js.map
|
package/dist/cubeTexture.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cubeTexture.js","sourceRoot":"","sources":["../src/cubeTexture.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cubeTexture.js","sourceRoot":"","sources":["../src/cubeTexture.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAEpF,SAAS,cAAc,CAAC,OAA8B;IACpD,OAAO,OAAO,CAAC,OAAO,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAA6B;IAC5D,OAAO,YAAY,CAAC,MAAM,CAAgB,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAgB,EAAE,MAA6B;IAC7E,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAyC;IACzE,OAAO,aAAa,CAAC;QACnB,UAAU,EAAE,IAAI,EAAE,UAAU,IAAI,MAAM;QACtC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS;QAC/D,SAAS,EAAE,MAAM;QACjB,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;KAC/D,CAAgB,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,CAA2C,EAC3C,CAA2C;IAE3C,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAC3B,OAAO,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,IAA2B;IAChE,MAAM,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IACrC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QACxB,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC;IACvC,CAAC;IACD,OAAO,CAAC,CAAC,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,IAA2B;IAC/D,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,IAAiB,EAAE,SAAiB,EAAE,MAA4B;IACnG,MAAM,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,OAAO,CAAC,SAAS,CAAC,KAAK,MAAM;QAAE,OAAO;IACzC,OAA+C,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;IACrE,IAAI,CAAC,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;AAC1C,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { advanceVideoTexture, cloneCubeTexture, cloneSampler, cloneTexture, cloneVideoTexture, copyCubeTexture, copySampler, copyTexture, copyVideoTexture, createAnisotropicSampler, createClampLinearSampler, createCubeTexture, createPixelArtSampler, createRenderTexture, createSampler, createTexture, createTilingSampler, createVideoTexture, equalsCubeTexture, equalsSampler, equalsTexture, getCubeTextureFaceSize,
|
|
1
|
+
export { advanceVideoTexture, cloneCubeTexture, cloneSampler, cloneTexture, cloneVideoTexture, copyCubeTexture, copySampler, copyTexture, copyVideoTexture, createAnisotropicSampler, createClampLinearSampler, createCubeTexture, createPixelArtSampler, createRenderTexture, createSampler, createTexture, createTilingSampler, createVideoTexture, equalsCubeTexture, equalsSampler, equalsTexture, getCubeTextureFaceSize, getTextureSourceKind, getTextureSource, getTextureHeight, getTextureInverseUvMatrix, getTextureUvMatrix, getTextureWidth, getVideoTextureHeight, getVideoTextureInverseUvMatrix, getVideoTextureUvMatrix, getVideoTextureWidth, hasTextureSource, hasTextureUvTransform, isCubeTextureComplete, isTextureReady, isVideoTextureFrameReady, invalidateVoxelGrid, resetTextureUvTransform, resetVideoTextureFrame, setCubeTextureFace, setTextureFlip, setTextureSource, setTextureUvOffset, setTextureUvFromPixelRect, setTextureUvRotation, setTextureUvScale, setVideoTextureSource, transformTextureUv, } from './contract';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,wBAAwB,EACxB,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,sBAAsB,EACtB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,wBAAwB,EACxB,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,sBAAsB,EACtB,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,yBAAyB,EACzB,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,8BAA8B,EAC9B,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,cAAc,EACd,wBAAwB,EACxB,mBAAmB,EACnB,uBAAuB,EACvB,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,yBAAyB,EACzB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { advanceVideoTexture, cloneCubeTexture, cloneSampler, cloneTexture, cloneVideoTexture, copyCubeTexture, copySampler, copyTexture, copyVideoTexture, createAnisotropicSampler, createClampLinearSampler, createCubeTexture, createPixelArtSampler, createRenderTexture, createSampler, createTexture, createTilingSampler, createVideoTexture, equalsCubeTexture, equalsSampler, equalsTexture, getCubeTextureFaceSize,
|
|
1
|
+
export { advanceVideoTexture, cloneCubeTexture, cloneSampler, cloneTexture, cloneVideoTexture, copyCubeTexture, copySampler, copyTexture, copyVideoTexture, createAnisotropicSampler, createClampLinearSampler, createCubeTexture, createPixelArtSampler, createRenderTexture, createSampler, createTexture, createTilingSampler, createVideoTexture, equalsCubeTexture, equalsSampler, equalsTexture, getCubeTextureFaceSize, getTextureSourceKind, getTextureSource, getTextureHeight, getTextureInverseUvMatrix, getTextureUvMatrix, getTextureWidth, getVideoTextureHeight, getVideoTextureInverseUvMatrix, getVideoTextureUvMatrix, getVideoTextureWidth, hasTextureSource, hasTextureUvTransform, isCubeTextureComplete, isTextureReady, isVideoTextureFrameReady, invalidateVoxelGrid, resetTextureUvTransform, resetVideoTextureFrame, setCubeTextureFace, setTextureFlip, setTextureSource, setTextureUvOffset, setTextureUvFromPixelRect, setTextureUvRotation, setTextureUvScale, setVideoTextureSource, transformTextureUv, } from './contract';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,wBAAwB,EACxB,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,sBAAsB,EACtB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,wBAAwB,EACxB,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,sBAAsB,EACtB,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,yBAAyB,EACzB,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,8BAA8B,EAC9B,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,cAAc,EACd,wBAAwB,EACxB,mBAAmB,EACnB,uBAAuB,EACvB,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,yBAAyB,EACzB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderTexture.d.ts","sourceRoot":"","sources":["../src/renderTexture.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"renderTexture.d.ts","sourceRoot":"","sources":["../src/renderTexture.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,EAAgB,aAAa,EAAE,MAAM,0BAA0B,CAAC;AASxG,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,QAAQ,CAAC,0BAA0B,CAAC,GAAG,aAAa,CAiChG"}
|
package/dist/renderTexture.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createEntity } from '@flighthq/entity/contract';
|
|
2
|
+
import { RenderTargetTextureSourceKind } from '@flighthq/types/contract';
|
|
2
3
|
import { copySampler } from './sampler';
|
|
3
4
|
import { createTexture } from './texture';
|
|
4
|
-
// Creates a universal Texture with a GPU-origin render-target
|
|
5
|
+
// Creates a universal Texture with a GPU-origin render-target source. Backend allocation stays lazy;
|
|
5
6
|
// renderIntoGlRenderTexture realizes the target in one state and resolveGlTexture later returns its
|
|
6
7
|
// color attachment without a CPU upload.
|
|
7
8
|
export function createRenderTexture(options) {
|
|
@@ -10,23 +11,21 @@ export function createRenderTexture(options) {
|
|
|
10
11
|
colorSpace: options.colorSpace ?? 'linear',
|
|
11
12
|
flipX: options.flipX ?? false,
|
|
12
13
|
flipY: options.flipY ?? false,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
},
|
|
29
|
-
},
|
|
14
|
+
dimension: '2d',
|
|
15
|
+
source: createEntity({
|
|
16
|
+
colorAttachments: options.colorAttachments,
|
|
17
|
+
colorFormats: options.colorFormats,
|
|
18
|
+
colorSpace,
|
|
19
|
+
clearColors: options.clearColors,
|
|
20
|
+
clearDepth: options.clearDepth,
|
|
21
|
+
depth: options.depth,
|
|
22
|
+
format: options.format,
|
|
23
|
+
height: options.height,
|
|
24
|
+
kind: RenderTargetTextureSourceKind,
|
|
25
|
+
sampleCount: options.sampleCount,
|
|
26
|
+
version: 0,
|
|
27
|
+
width: options.width,
|
|
28
|
+
}),
|
|
30
29
|
uvRotation: options.uvRotation,
|
|
31
30
|
});
|
|
32
31
|
if (options.sampler !== undefined)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderTexture.js","sourceRoot":"","sources":["../src/renderTexture.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"renderTexture.js","sourceRoot":"","sources":["../src/renderTexture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AAEzE,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,qGAAqG;AACrG,oGAAoG;AACpG,yCAAyC;AACzC,MAAM,UAAU,mBAAmB,CAAC,OAA6C;IAC/E,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,QAAQ,CAAC;IAClD,MAAM,OAAO,GAAG,aAAa,CAAC;QAC5B,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,QAAQ;QAC1C,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,KAAK;QAC7B,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ureOptions,
|
|
1
|
+
import type { CreateTextureOptions, TextureSource, Matrix3Like, Texture, Texture2D, TextureSourceKind, TextureLike, TextureUvTransform, Vector2Like } from '@flighthq/types/contract';
|
|
2
2
|
export declare function cloneTexture(source: Readonly<TextureLike>): Texture;
|
|
3
3
|
export declare function copyTexture(out: TextureLike, source: Readonly<TextureLike>): void;
|
|
4
|
-
|
|
4
|
+
type CreateTexture2DOptions = Extract<CreateTextureOptions, {
|
|
5
|
+
dimension?: '2d';
|
|
6
|
+
}>;
|
|
7
|
+
type CreateTexture2DArrayOptions = Extract<CreateTextureOptions, {
|
|
8
|
+
dimension: '2d-array';
|
|
9
|
+
}>;
|
|
10
|
+
type CreateTexture3DOptions = Extract<CreateTextureOptions, {
|
|
11
|
+
dimension: '3d';
|
|
12
|
+
}>;
|
|
13
|
+
type CreateTextureCubeOptions = Extract<CreateTextureOptions, {
|
|
14
|
+
dimension: 'cube';
|
|
15
|
+
}>;
|
|
16
|
+
export declare function createTexture(opts?: Readonly<CreateTexture2DOptions>): Texture2D;
|
|
17
|
+
export declare function createTexture(opts: Readonly<CreateTexture2DArrayOptions>): Extract<Texture, {
|
|
18
|
+
dimension: '2d-array';
|
|
19
|
+
}>;
|
|
20
|
+
export declare function createTexture(opts: Readonly<CreateTexture3DOptions>): Extract<Texture, {
|
|
21
|
+
dimension: '3d';
|
|
22
|
+
}>;
|
|
23
|
+
export declare function createTexture(opts: Readonly<CreateTextureCubeOptions>): Extract<Texture, {
|
|
24
|
+
dimension: 'cube';
|
|
25
|
+
}>;
|
|
5
26
|
export declare function equalsTexture(a: Readonly<TextureLike> | null | undefined, b: Readonly<TextureLike> | null | undefined): boolean;
|
|
6
|
-
export declare function getTextureBackingKind(texture: Readonly<TextureLike>): TextureBackingKind | null;
|
|
7
27
|
export declare function getTextureHeight(texture: Readonly<TextureLike>): number;
|
|
8
28
|
export declare function getTextureInverseUvMatrix(out: Matrix3Like, texture: Readonly<TextureLike>): void;
|
|
29
|
+
export declare function getTextureSource(texture: Readonly<TextureLike>): TextureSource | null;
|
|
30
|
+
export declare function getTextureSourceKind(texture: Readonly<TextureLike>): TextureSourceKind | null;
|
|
9
31
|
export declare function getTextureUvMatrix(out: Matrix3Like, texture: Readonly<TextureUvTransform>): void;
|
|
10
32
|
export declare function getTextureWidth(texture: Readonly<TextureLike>): number;
|
|
11
|
-
export declare function
|
|
33
|
+
export declare function hasTextureSource(texture: Readonly<TextureLike>): boolean;
|
|
12
34
|
export declare function hasTextureUvTransform(texture: Readonly<TextureUvTransform>): boolean;
|
|
13
35
|
export declare function isTextureReady(texture: Readonly<TextureLike>): boolean;
|
|
14
36
|
export declare function resetTextureUvTransform(texture: TextureLike): void;
|
|
15
37
|
export declare function setTextureFlip(texture: TextureLike, flipX: boolean, flipY: boolean): void;
|
|
16
|
-
export declare function
|
|
38
|
+
export declare function setTextureSource(texture: TextureLike, source: TextureSource | null): void;
|
|
17
39
|
export declare function setTextureUvFromPixelRect(texture: TextureLike, x: number, y: number, width: number, height: number): void;
|
|
18
40
|
export declare function setTextureUvOffset(texture: TextureLike, x: number, y: number): void;
|
|
19
41
|
export declare function setTextureUvRotation(texture: TextureLike, radians: number): void;
|
|
20
42
|
export declare function setTextureUvScale(texture: TextureLike, x: number, y: number): void;
|
|
21
43
|
export declare function transformTextureUv(out: Vector2Like, texture: Readonly<TextureLike>, u: number, v: number): void;
|
|
44
|
+
export {};
|
|
22
45
|
//# sourceMappingURL=texture.d.ts.map
|
package/dist/texture.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"texture.d.ts","sourceRoot":"","sources":["../src/texture.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,oBAAoB,EACpB,
|
|
1
|
+
{"version":3,"file":"texture.d.ts","sourceRoot":"","sources":["../src/texture.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,OAAO,EACP,SAAS,EACT,iBAAiB,EAEj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I,GAAG,IAAI,CAKzF;AAoBD,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,WAAW,EACpB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,IAAI,CAcN;AAID,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAGnF;AAGD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAEhF;AAGD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAGlF;AAMD,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAa/G"}
|
package/dist/texture.js
CHANGED
|
@@ -1,57 +1,56 @@
|
|
|
1
1
|
import { createEntity } from '@flighthq/entity/contract';
|
|
2
2
|
import { cloneVector2, copyVector2, createVector2, inverseMatrix3 } from '@flighthq/geometry/contract';
|
|
3
3
|
import { cloneSampler, copySampler, createSampler, equalsSampler } from './sampler';
|
|
4
|
-
function
|
|
5
|
-
switch (
|
|
4
|
+
function getFirstTextureSource(texture) {
|
|
5
|
+
switch (texture.dimension) {
|
|
6
6
|
case '2d':
|
|
7
|
-
return { dimension: '2d', image: storage.image, target: storage.target };
|
|
8
|
-
case '2d-array':
|
|
9
|
-
return { dimension: '2d-array', images: storage.images.slice(), target: storage.target };
|
|
10
7
|
case '3d':
|
|
11
|
-
return
|
|
12
|
-
case 'cube':
|
|
13
|
-
return {
|
|
14
|
-
dimension: 'cube',
|
|
15
|
-
images: storage.images.slice(),
|
|
16
|
-
target: storage.target,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function getTextureStorageImage(storage) {
|
|
21
|
-
switch (storage.dimension) {
|
|
22
|
-
case '2d':
|
|
23
|
-
return storage.image;
|
|
8
|
+
return texture.source;
|
|
24
9
|
case '2d-array':
|
|
25
10
|
case 'cube':
|
|
26
|
-
return
|
|
27
|
-
case '3d':
|
|
28
|
-
return null;
|
|
11
|
+
return texture.sources.find((source) => source !== null) ?? null;
|
|
29
12
|
}
|
|
30
13
|
}
|
|
31
|
-
// Allocates an independent
|
|
32
|
-
//
|
|
33
|
-
// while the Sampler and uv-transform vectors are deep-cloned for independent sampling.
|
|
14
|
+
// Allocates an independent sampling view over the same source identity. Sampler and uv-transform
|
|
15
|
+
// vectors are deep-cloned; array/cube source lists receive a fresh list.
|
|
34
16
|
export function cloneTexture(source) {
|
|
35
|
-
|
|
17
|
+
const common = {
|
|
36
18
|
colorSpace: source.colorSpace,
|
|
37
19
|
flipX: source.flipX,
|
|
38
20
|
flipY: source.flipY,
|
|
39
21
|
sampler: cloneSampler(source.sampler),
|
|
40
|
-
storage: cloneTextureStorage(source.storage),
|
|
41
22
|
uvOffset: cloneVector2(source.uvOffset),
|
|
42
23
|
uvRotation: source.uvRotation,
|
|
43
24
|
uvScale: cloneVector2(source.uvScale),
|
|
44
25
|
version: source.version >>> 0,
|
|
45
|
-
}
|
|
26
|
+
};
|
|
27
|
+
switch (source.dimension) {
|
|
28
|
+
case '2d':
|
|
29
|
+
return createEntity({ ...common, dimension: '2d', source: source.source });
|
|
30
|
+
case '2d-array':
|
|
31
|
+
return createEntity({
|
|
32
|
+
...common,
|
|
33
|
+
dimension: '2d-array',
|
|
34
|
+
sources: source.sources.slice(),
|
|
35
|
+
});
|
|
36
|
+
case '3d':
|
|
37
|
+
return createEntity({ ...common, dimension: '3d', source: source.source });
|
|
38
|
+
case 'cube':
|
|
39
|
+
return createEntity({
|
|
40
|
+
...common,
|
|
41
|
+
dimension: 'cube',
|
|
42
|
+
sources: source.sources.slice(),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
46
45
|
}
|
|
47
|
-
// Copies every
|
|
48
|
-
//
|
|
49
|
-
// identities are preserved). Safe when out aliases source.
|
|
46
|
+
// Copies every mutable field from source into a same-dimension out. Dimension is creation-time
|
|
47
|
+
// identity and never shape-shifts; source identities remain shared.
|
|
50
48
|
export function copyTexture(out, source) {
|
|
49
|
+
if (out.dimension !== source.dimension)
|
|
50
|
+
throw new Error('copyTexture requires matching dimensions');
|
|
51
51
|
const colorSpace = source.colorSpace;
|
|
52
52
|
const flipX = source.flipX;
|
|
53
53
|
const flipY = source.flipY;
|
|
54
|
-
const storage = cloneTextureStorage(source.storage);
|
|
55
54
|
const uvRotation = source.uvRotation;
|
|
56
55
|
const version = source.version >>> 0;
|
|
57
56
|
copySampler(out.sampler, source.sampler);
|
|
@@ -60,28 +59,77 @@ export function copyTexture(out, source) {
|
|
|
60
59
|
out.colorSpace = colorSpace;
|
|
61
60
|
out.flipX = flipX;
|
|
62
61
|
out.flipY = flipY;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
switch (out.dimension) {
|
|
63
|
+
case '2d':
|
|
64
|
+
if (source.dimension !== '2d')
|
|
65
|
+
throw new Error('copyTexture requires matching dimensions');
|
|
66
|
+
out.source = source.source;
|
|
67
|
+
break;
|
|
68
|
+
case '2d-array':
|
|
69
|
+
if (source.dimension !== '2d-array')
|
|
70
|
+
throw new Error('copyTexture requires matching dimensions');
|
|
71
|
+
out.sources = source.sources.slice();
|
|
72
|
+
break;
|
|
73
|
+
case '3d':
|
|
74
|
+
if (source.dimension !== '3d')
|
|
75
|
+
throw new Error('copyTexture requires matching dimensions');
|
|
76
|
+
out.source = source.source;
|
|
77
|
+
break;
|
|
78
|
+
case 'cube':
|
|
79
|
+
if (source.dimension !== 'cube')
|
|
80
|
+
throw new Error('copyTexture requires matching dimensions');
|
|
81
|
+
out.sources = source.sources.slice();
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
67
84
|
out.uvRotation = uvRotation;
|
|
68
85
|
out.version = version;
|
|
69
86
|
}
|
|
70
|
-
// Builds a Texture
|
|
71
|
-
//
|
|
72
|
-
// (zero offset, unit scale, no rotation). Pass TextureLike fields to override any of these.
|
|
87
|
+
// Builds a flat Texture union. Two-dimensional content is the default and retains a null source
|
|
88
|
+
// sentinel during the loader migration; non-2D variants are selected by their required dimension.
|
|
73
89
|
export function createTexture(opts) {
|
|
74
|
-
const
|
|
90
|
+
const common = {
|
|
75
91
|
colorSpace: opts?.colorSpace ?? 'srgb',
|
|
76
92
|
flipX: opts?.flipX ?? false,
|
|
77
93
|
flipY: opts?.flipY ?? false,
|
|
78
94
|
sampler: opts?.sampler ? cloneSampler(opts.sampler) : createSampler(),
|
|
79
|
-
storage: opts?.storage ? cloneTextureStorage(opts.storage) : { dimension: '2d', image: null },
|
|
80
95
|
uvOffset: opts?.uvOffset ? cloneVector2(opts.uvOffset) : createVector2(0, 0),
|
|
81
96
|
uvRotation: opts?.uvRotation ?? 0,
|
|
82
97
|
uvScale: opts?.uvScale ? cloneVector2(opts.uvScale) : createVector2(1, 1),
|
|
83
98
|
version: (opts?.version ?? 0) >>> 0,
|
|
84
|
-
}
|
|
99
|
+
};
|
|
100
|
+
let texture;
|
|
101
|
+
switch (opts?.dimension) {
|
|
102
|
+
case '2d-array':
|
|
103
|
+
texture = createEntity({
|
|
104
|
+
...common,
|
|
105
|
+
dimension: '2d-array',
|
|
106
|
+
sources: opts.sources?.slice() ?? [],
|
|
107
|
+
});
|
|
108
|
+
break;
|
|
109
|
+
case '3d':
|
|
110
|
+
texture = createEntity({
|
|
111
|
+
...common,
|
|
112
|
+
dimension: '3d',
|
|
113
|
+
source: opts.source ?? null,
|
|
114
|
+
});
|
|
115
|
+
break;
|
|
116
|
+
case 'cube':
|
|
117
|
+
texture = createEntity({
|
|
118
|
+
...common,
|
|
119
|
+
dimension: 'cube',
|
|
120
|
+
sources: (opts.sources?.slice() ?? [null, null, null, null, null, null]),
|
|
121
|
+
});
|
|
122
|
+
break;
|
|
123
|
+
default: {
|
|
124
|
+
const options = opts;
|
|
125
|
+
texture = createEntity({
|
|
126
|
+
...common,
|
|
127
|
+
dimension: '2d',
|
|
128
|
+
source: options?.source ?? null,
|
|
129
|
+
});
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
85
133
|
const resource = opts?.resource;
|
|
86
134
|
if (resource != null) {
|
|
87
135
|
(resource.textures ??= []).push(texture);
|
|
@@ -89,7 +137,7 @@ export function createTexture(opts) {
|
|
|
89
137
|
return texture;
|
|
90
138
|
}
|
|
91
139
|
// True when both textures describe identical state: same color space, same sampler state, the same
|
|
92
|
-
//
|
|
140
|
+
// source reference, and the same uv-transform values. Returns false for null/undefined operands.
|
|
93
141
|
export function equalsTexture(a, b) {
|
|
94
142
|
if (!a || !b)
|
|
95
143
|
return false;
|
|
@@ -98,7 +146,7 @@ export function equalsTexture(a, b) {
|
|
|
98
146
|
return (a.colorSpace === b.colorSpace &&
|
|
99
147
|
a.flipX === b.flipX &&
|
|
100
148
|
a.flipY === b.flipY &&
|
|
101
|
-
|
|
149
|
+
equalsTextureContent(a, b) &&
|
|
102
150
|
a.uvRotation === b.uvRotation &&
|
|
103
151
|
a.uvOffset.x === b.uvOffset.x &&
|
|
104
152
|
a.uvOffset.y === b.uvOffset.y &&
|
|
@@ -107,21 +155,9 @@ export function equalsTexture(a, b) {
|
|
|
107
155
|
a.version === b.version &&
|
|
108
156
|
equalsSampler(a.sampler, b.sampler));
|
|
109
157
|
}
|
|
110
|
-
// Returns the
|
|
111
|
-
// CPU-origin images own their key; GPU-origin targets own theirs, so TextureStorage carries no duplicate
|
|
112
|
-
// discriminant.
|
|
113
|
-
export function getTextureBackingKind(texture) {
|
|
114
|
-
const storage = texture.storage;
|
|
115
|
-
if (storage.dimension === '3d')
|
|
116
|
-
return storage.volume?.kind ?? storage.target?.kind ?? null;
|
|
117
|
-
return getTextureStorageImage(storage)?.kind ?? storage.target?.kind ?? null;
|
|
118
|
-
}
|
|
119
|
-
// Returns the height declared by the CPU image or render target backing, or -1 when unbound.
|
|
158
|
+
// Returns the height declared by the active source, or -1 when unbound.
|
|
120
159
|
export function getTextureHeight(texture) {
|
|
121
|
-
|
|
122
|
-
if (storage.dimension === '3d')
|
|
123
|
-
return storage.volume?.height ?? storage.target?.height ?? -1;
|
|
124
|
-
return getTextureStorageImage(storage)?.height ?? storage.target?.height ?? -1;
|
|
160
|
+
return getFirstTextureSource(texture)?.height ?? -1;
|
|
125
161
|
}
|
|
126
162
|
// Composes the KHR_texture_transform fields and inverts the result, producing the matrix that maps
|
|
127
163
|
// already-transformed uv coordinates back to the unit-square source uv. The forward transform is
|
|
@@ -133,6 +169,15 @@ export function getTextureInverseUvMatrix(out, texture) {
|
|
|
133
169
|
getTextureUvMatrix(out, texture);
|
|
134
170
|
inverseMatrix3(out, out);
|
|
135
171
|
}
|
|
172
|
+
// Returns the first active source. Array and cube textures yield their first bound layer/face;
|
|
173
|
+
// unbound and entirely incomplete textures return null.
|
|
174
|
+
export function getTextureSource(texture) {
|
|
175
|
+
return getFirstTextureSource(texture);
|
|
176
|
+
}
|
|
177
|
+
// Returns the open resolver key declared by the texture's active source, or null when unbound.
|
|
178
|
+
export function getTextureSourceKind(texture) {
|
|
179
|
+
return getFirstTextureSource(texture)?.kind ?? null;
|
|
180
|
+
}
|
|
136
181
|
// Composes the KHR_texture_transform fields (uvOffset, uvRotation, uvScale) into the 3×3 matrix
|
|
137
182
|
// a shader consumes at sample time. Column-major layout matching @flighthq/geometry Matrix3, so it
|
|
138
183
|
// uploads to a GL/WGSL mat3 uniform with no transpose. The resulting transform applies:
|
|
@@ -166,16 +211,13 @@ export function getTextureUvMatrix(out, texture) {
|
|
|
166
211
|
m[7] = ty; // (1,2)
|
|
167
212
|
m[8] = 1; // (2,2)
|
|
168
213
|
}
|
|
169
|
-
// Returns the width declared by the
|
|
214
|
+
// Returns the width declared by the active source, or -1 when unbound.
|
|
170
215
|
export function getTextureWidth(texture) {
|
|
171
|
-
|
|
172
|
-
if (storage.dimension === '3d')
|
|
173
|
-
return storage.volume?.width ?? storage.target?.width ?? -1;
|
|
174
|
-
return getTextureStorageImage(storage)?.width ?? storage.target?.width ?? -1;
|
|
216
|
+
return getFirstTextureSource(texture)?.width ?? -1;
|
|
175
217
|
}
|
|
176
|
-
// True when the texture declares
|
|
177
|
-
export function
|
|
178
|
-
return
|
|
218
|
+
// True when the texture declares at least one source.
|
|
219
|
+
export function hasTextureSource(texture) {
|
|
220
|
+
return getTextureSourceKind(texture) !== null;
|
|
179
221
|
}
|
|
180
222
|
// True when the texture carries a non-identity KHR_texture_transform — any non-unit scale, non-zero
|
|
181
223
|
// offset, or non-zero rotation. GPU material renderers gate the HAS_UV_TRANSFORM shader variant on
|
|
@@ -190,13 +232,13 @@ export function hasTextureUvTransform(texture) {
|
|
|
190
232
|
texture.uvOffset.y !== 0 ||
|
|
191
233
|
texture.uvRotation !== 0);
|
|
192
234
|
}
|
|
193
|
-
// True once the texture references a pixel source. A
|
|
194
|
-
//
|
|
235
|
+
// True once the texture references a pixel source. A null source is treated as an absent slot by
|
|
236
|
+
// materials, so this is the gate a material samples behind.
|
|
195
237
|
export function isTextureReady(texture) {
|
|
196
|
-
return
|
|
238
|
+
return hasTextureSource(texture);
|
|
197
239
|
}
|
|
198
240
|
// Resets the KHR_texture_transform to identity in place: zero offset, no rotation, unit scale, and
|
|
199
|
-
// no flip. Leaves
|
|
241
|
+
// no flip. Leaves the source, color space, sampler, and version untouched.
|
|
200
242
|
export function resetTextureUvTransform(texture) {
|
|
201
243
|
texture.flipX = false;
|
|
202
244
|
texture.flipY = false;
|
|
@@ -213,32 +255,31 @@ export function setTextureFlip(texture, flipX, flipY) {
|
|
|
213
255
|
texture.flipX = flipX;
|
|
214
256
|
texture.flipY = flipY;
|
|
215
257
|
}
|
|
216
|
-
// Binds (or clears, with null) the texture's
|
|
258
|
+
// Binds (or clears, with null) the texture's source in place and advances the u32 dirty-bit.
|
|
217
259
|
// Does not touch sampling state or the uv-transform.
|
|
218
|
-
export function
|
|
219
|
-
if (texture.
|
|
220
|
-
throw new Error('
|
|
221
|
-
if (texture.
|
|
260
|
+
export function setTextureSource(texture, source) {
|
|
261
|
+
if (texture.dimension !== '2d')
|
|
262
|
+
throw new Error('setTextureSource requires a Texture2D');
|
|
263
|
+
if (texture.source === source)
|
|
222
264
|
return;
|
|
223
|
-
texture.
|
|
265
|
+
texture.source = source;
|
|
224
266
|
texture.version = (texture.version + 1) >>> 0;
|
|
225
267
|
}
|
|
226
|
-
function
|
|
227
|
-
if (a.dimension !== b.dimension
|
|
268
|
+
function equalsTextureContent(a, b) {
|
|
269
|
+
if (a.dimension !== b.dimension)
|
|
228
270
|
return false;
|
|
229
271
|
switch (a.dimension) {
|
|
230
272
|
case '2d':
|
|
231
|
-
|
|
273
|
+
case '3d':
|
|
274
|
+
return b.dimension === a.dimension && a.source === b.source;
|
|
232
275
|
case '2d-array':
|
|
233
276
|
case 'cube':
|
|
234
277
|
return (b.dimension === a.dimension &&
|
|
235
|
-
a.
|
|
236
|
-
a.
|
|
237
|
-
case '3d':
|
|
238
|
-
return b.dimension === '3d' && a.volume === b.volume;
|
|
278
|
+
a.sources.length === b.sources.length &&
|
|
279
|
+
a.sources.every((source, index) => source === b.sources[index]));
|
|
239
280
|
}
|
|
240
281
|
}
|
|
241
|
-
// Maps a pixel-space rectangle in the texture's
|
|
282
|
+
// Maps a pixel-space rectangle in the texture's source to its normalized uv window. An unbound
|
|
242
283
|
// texture has no pixel extent, so it receives an empty window rather than dividing by a sentinel.
|
|
243
284
|
export function setTextureUvFromPixelRect(texture, x, y, width, height) {
|
|
244
285
|
const textureWidth = getTextureWidth(texture);
|