Skip to content
Permalink
Browse files

feat(dispose): fix "dispose basic source texture/array buffer view so…

…urce texture->bindTextureUnitCacheMap"

update wonder-commonlib version
  • Loading branch information...
yyc-git committed May 23, 2019
1 parent d5c6e77 commit c56411fd0eab6f80f7d1053ff17fa618d838e479
@@ -71,7 +71,7 @@
"bs-fetch": "^0.3.0",
"wonder-bs-json": "^0.0.1",
"wonder-bs-most": "^0.0.3",
"wonder-commonlib": "^0.2.31",
"wonder-commonlib": "^0.2.32",
"wonder-imgui": "^0.0.34",
"wonder-log": "^0.2.11",
"wonder-most-animation-frame": "0.0.3",
@@ -80,7 +80,7 @@
"resolutions": {
"wonder-log": "^0.2.11",
"wonder-webgl": "^0.0.10",
"wonder-commonlib": "0.2.31",
"wonder-commonlib": "0.2.32",
"wonder-bs-jest": "0.3.0",
"wonder-bs-puppeteer": "^0.1.6"
}
@@ -1,5 +1,8 @@
let isCached = (unit, texture, bindTextureUnitCacheMap) =>
switch (bindTextureUnitCacheMap |> WonderCommonlib.MutableSparseMapService.get(unit)) {
switch (
bindTextureUnitCacheMap
|> WonderCommonlib.MutableSparseMapService.get(unit)
) {
| None => false
| Some(bindedTexture) => bindedTexture === texture
};
@@ -11,13 +14,19 @@ let addActiveTexture = (unit, texture, bindTextureUnitCacheMap) => {
Contract.(
Operators.(
test(
Log.buildAssertMessage(~expect={j|not cached|j}, ~actual={j||j}),
() => isCached(unit, texture, bindTextureUnitCacheMap) |> assertFalse
Log.buildAssertMessage(
~expect={j|not cached|j},
~actual={j||j},
),
() =>
isCached(unit, texture, bindTextureUnitCacheMap) |> assertFalse
)
)
)
),
IsDebugMainService.getIsDebug(StateDataMain.stateData)
IsDebugMainService.getIsDebug(StateDataMain.stateData),
);
bindTextureUnitCacheMap |> WonderCommonlib.MutableSparseMapService.set(unit, texture)

bindTextureUnitCacheMap
|> WonderCommonlib.MutableSparseMapService.set(unit, texture);
};
@@ -9,9 +9,17 @@ type arrayBufferViewSourceTextureRecord = {
flipYs: Js.Typed_array.Uint8Array.t,
widths: Js.Typed_array.Uint16Array.t,
heights: Js.Typed_array.Uint16Array.t,
sourceMap: WonderCommonlib.MutableSparseMapService.t(Js.Typed_array.Uint8Array.t),
glTextureMap: WonderCommonlib.MutableSparseMapService.t(WonderWebgl.GlType.texture),
sourceMap:
WonderCommonlib.MutableSparseMapService.t(Js.Typed_array.Uint8Array.t),
glTextureMap:
WonderCommonlib.MutableSparseMapService.t(WonderWebgl.GlType.texture),
bindTextureUnitCacheMap: WonderCommonlib.MutableSparseMapService.t(int),
setFlipYFunc: (WonderWebgl.GlType.webgl1Context, bool, BrowserDetectType.browserDetectRecord) => unit,
textureIndexOffset: int
setFlipYFunc:
(
WonderWebgl.GlType.webgl1Context,
bool,
BrowserDetectType.browserDetectRecord
) =>
unit,
textureIndexOffset: int,
};
@@ -7,8 +7,18 @@ type basicSourceTextureRecord = {
types: Js.Typed_array.Uint8Array.t,
isNeedUpdates: Js.Typed_array.Uint8Array.t,
flipYs: Js.Typed_array.Uint8Array.t,
sourceMap: WonderCommonlib.MutableSparseMapService.t(WonderWebgl.DomExtendType.imageElement),
glTextureMap: WonderCommonlib.MutableSparseMapService.t(WonderWebgl.GlType.texture),
sourceMap:
WonderCommonlib.MutableSparseMapService.t(
WonderWebgl.DomExtendType.imageElement,
),
glTextureMap:
WonderCommonlib.MutableSparseMapService.t(WonderWebgl.GlType.texture),
bindTextureUnitCacheMap: WonderCommonlib.MutableSparseMapService.t(int),
setFlipYFunc: (WonderWebgl.GlType.webgl1Context, bool, BrowserDetectType.browserDetectRecord) => unit
setFlipYFunc:
(
WonderWebgl.GlType.webgl1Context,
bool,
BrowserDetectType.browserDetectRecord
) =>
unit,
};
@@ -104,4 +104,21 @@ let clearNeedDisposedTextureIndexArray = state => {
...RecordArrayBufferViewSourceTextureMainService.getRecord(state),
needDisposedTextureIndexArray: [||],
}),
};
};

let disposeBindTextureUnitCacheMap = (texture, bindTextureUnitCacheMap) =>
switch (
bindTextureUnitCacheMap
|> WonderCommonlib.MutableSparseMapService.getValidDataArr
|> Js.Array.filter(((unit, bindedTexture)) => bindedTexture === texture)
) {
| arr when Js.Array.length(arr) > 0 =>
arr
|> WonderCommonlib.ArrayService.reduceOneParam(
(. bindTextureUnitCacheMap, (unit, texture)) =>
bindTextureUnitCacheMap
|> DisposeComponentService.disposeSparseMapData(unit),
bindTextureUnitCacheMap,
)
| _ => bindTextureUnitCacheMap
};
@@ -113,7 +113,10 @@ let _disposeData = (texture, textureIndexInTypeArr, state) => {
),
sourceMap: sourceMap |> disposeSparseMapData(texture),
bindTextureUnitCacheMap:
bindTextureUnitCacheMap |> disposeSparseMapData(texture),
DisposeTextureMainService.disposeBindTextureUnitCacheMap(
texture,
bindTextureUnitCacheMap,
),
needAddedSourceArray:
DisposeTextureMainService.disposeNeedAddedSourceArray(
texture,
@@ -131,14 +134,6 @@ let _disposeData = (texture, textureIndexInTypeArr, state) => {

let handleDispose = (materialData, textureArr, state) =>
textureArr
/* |> Js.Array.map(texture =>
IndexSourceTextureService.getArrayBufferViewSourceTextureIndexInTypeArray(
texture,
IndexSourceTextureMainService.getArrayBufferViewSourceTextureIndexOffset(
state,
),
)
) */
|> WonderCommonlib.ArrayService.reduceOneParam(
(. state, texture) => {
let arrayBufferViewSourceTextureRecord =
@@ -89,7 +89,10 @@ let _disposeData = (texture, state) => {
),
sourceMap: sourceMap |> disposeSparseMapData(texture),
bindTextureUnitCacheMap:
bindTextureUnitCacheMap |> disposeSparseMapData(texture),
DisposeTextureMainService.disposeBindTextureUnitCacheMap(
texture,
bindTextureUnitCacheMap,
),
needAddedSourceArray:
DisposeTextureMainService.disposeNeedAddedSourceArray(
texture,
@@ -70,15 +70,15 @@ let getMaterialDataArr = (texture, state) =>
materialsMap,
);

let getBindTextureUnitCacheMap = (texture, state) => {
/* let getBindTextureUnitCacheMap = (texture, state) => {
let arrayBufferViewSourceTextureRecord =
RecordArrayBufferViewSourceTextureMainService.getRecord(state);
arrayBufferViewSourceTextureRecord.bindTextureUnitCacheMap
|> WonderCommonlib.MutableSparseMapService.get(texture);
};
}; */

let setBindTextureUnitCacheMap = (texture, unit, state) => {
/* let setBindTextureUnitCacheMap = (texture, unit, state) => {
let arrayBufferViewSourceTextureRecord =
RecordArrayBufferViewSourceTextureMainService.getRecord(state);
@@ -92,7 +92,7 @@ let setBindTextureUnitCacheMap = (texture, unit, state) => {
|> WonderCommonlib.MutableSparseMapService.set(texture, unit),
}),
};
};
}; */

let unsafeGetMaterialDataArr = (texture, state) =>
getMaterialDataArr(texture, state) |> OptionService.unsafeGet;
@@ -104,15 +104,15 @@ let getMaterialDataArr = (texture, state) =>
let unsafeGetMaterialDataArr = (texture, state) =>
getMaterialDataArr(texture, state) |> OptionService.unsafeGet;

let getBindTextureUnitCacheMap = (texture, state) => {
let getBindTextureUnitCacheMap = (unit, state) => {
let basicSourceTextureRecord =
RecordBasicSourceTextureMainService.getRecord(state);

basicSourceTextureRecord.bindTextureUnitCacheMap
|> WonderCommonlib.MutableSparseMapService.get(texture);
|> WonderCommonlib.MutableSparseMapService.get(unit);
};

let setBindTextureUnitCacheMap = (texture, unit, state) => {
let setBindTextureUnitCacheMap = (unit, bindedTexture, state) => {
let basicSourceTextureRecord =
RecordBasicSourceTextureMainService.getRecord(state);

@@ -123,11 +123,27 @@ let setBindTextureUnitCacheMap = (texture, unit, state) => {
...basicSourceTextureRecord,
bindTextureUnitCacheMap:
basicSourceTextureRecord.bindTextureUnitCacheMap
|> WonderCommonlib.MutableSparseMapService.set(texture, unit),
|> WonderCommonlib.MutableSparseMapService.set(unit, bindedTexture),
}),
};
};

/* let setBindTextureUnitMap = (texture, unit, state) => {
let basicSourceTextureRecord =
RecordBasicSourceTextureMainService.getRecord(state);
{
...state,
basicSourceTextureRecord:
Some({
...basicSourceTextureRecord,
bindTextureUnitMap:
basicSourceTextureRecord.bindTextureUnitMap
|> WonderCommonlib.MutableSparseMapService.set(texture, unit),
}),
};
}; */

let getBasicSourceTextureSource = (texture, state: StateDataMainType.state) => {
let {sourceMap} = RecordBasicSourceTextureMainService.getRecord(state);

@@ -263,47 +263,6 @@ let _ =
});

describe("else", () => {
test("remove from sourceMap, bindTextureUnitCacheMap, nameMap", () => {
let (
state,
material1,
(diffuseMap, specularMap, source1, source2),
) =
LightMaterialTool.createMaterialWithArrayBufferViewMap(state^);
let state =
state
|> ArrayBufferViewSourceTextureAPI.setArrayBufferViewSourceTextureName(
diffuseMap,
"name",
)
|> ArrayBufferViewSourceTextureTool.setBindTextureUnitCacheMap(
diffuseMap,
1,
);

let state =
LightMaterialAPI.batchDisposeLightMaterial(
[|material1|],
state,
);

(
ArrayBufferViewSourceTextureTool.getArrayBufferViewSourceTextureName(
diffuseMap,
state,
),
ArrayBufferViewSourceTextureTool.getArrayBufferViewSourceTextureSource(
diffuseMap,
state,
),
ArrayBufferViewSourceTextureTool.getBindTextureUnitCacheMap(
diffuseMap,
state,
),
)
|> expect == (None, None, None);
});

describe("test remove from type array", () => {
let _testRemoveFromTypeArr =
(
@@ -288,7 +288,7 @@ let _ =
});

describe("else", () => {
test("remove from sourceMap, bindTextureUnitCacheMap, nameMap", () => {
test("remove from sourceMap, nameMap", () => {
let (
state,
material1,
@@ -321,12 +321,50 @@ let _ =
diffuseMap,
state,
),
BasicSourceTextureTool.getBindTextureUnitCacheMap(
diffuseMap,
)
|> expect == (None, None);
});
test("remove from bindTextureUnitCacheMap", () => {
let (
state,
material1,
(diffuseMap1, specularMap1, source1_1, source1_2),
) =
LightMaterialTool.createMaterialWithMap(state^);
let (
state,
material2,
(diffuseMap2, specularMap2, source2_1, source2_2),
) =
LightMaterialTool.createMaterialWithMap(state);

let unit0 = 0;
let unit1 = 1;

let state =
state
|> BasicSourceTextureTool.setBindTextureUnitCacheMap(
unit1,
diffuseMap1,
)
|> BasicSourceTextureTool.setBindTextureUnitCacheMap(
unit0,
diffuseMap2,
);

let state =
LightMaterialAPI.batchDisposeLightMaterial(
[|material1|],
state,
),
);

(
BasicSourceTextureTool.getBindTextureUnitCacheMap(unit1, state)
|> Js.Option.isNone,
BasicSourceTextureTool.getBindTextureUnitCacheMap(unit0, state)
|> Js.Option.isNone,
)
|> expect == (None, None, None);
|> expect == (true, false);
});

describe("test remove from type array", () => {

0 comments on commit c56411f

Please sign in to comment.
You can’t perform that action at this time.