Skip to content

Commit

Permalink
feat(texture): fix "assemble wdb"->BatchSetTextureAllDataSystem->batc…
Browse files Browse the repository at this point in the history
…hSetNewDiffueMaps

solution
now add to texture group
  • Loading branch information
yyc-git committed May 24, 2019
1 parent 33d2053 commit e5f1cd7
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 72 deletions.
109 changes: 60 additions & 49 deletions src/asset/assemble/BatchSetTextureAllDataSystem.re
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,59 @@ let _batchSetNewMap =
(
(materialArr, textureArr, mapCount),
(setMapUnitFunc, setTextureIndexFunc),
(
textureCountPerMaterial,
textureIndices,
mapUnits,
emptyMapUnitArrayMap,
),
textureCountPerMaterial,
state,
) => {
let newTextureCount = mapCount |> succ;

materialArr
|> WonderCommonlib.ArrayService.reduceOneParami(
(. (textureIndices, mapUnits, emptyMapUnitArrayMap), material, index) => {
let texture = Array.unsafe_get(textureArr, index);

let (mapUnit, emptyMapUnitArrayMap) =
EmptyMapUnitArrayMapService.unsafeGetEmptyMapUnitAndPop(
material,
emptyMapUnitArrayMap,
);
let state =
materialArr
|> WonderCommonlib.ArrayService.reduceOneParami(
(. state, material, index) => {
let texture = Array.unsafe_get(textureArr, index);

(
setTextureIndexFunc(.
(material, mapUnit, textureCountPerMaterial),
texture,
textureIndices,
),
setMapUnitFunc(. material, mapUnit, mapUnits),
emptyMapUnitArrayMap,
);
},
(textureIndices, mapUnits, emptyMapUnitArrayMap),
);
};
state
|> GroupTextureMainService.addMaterial(
(material, MaterialType.LightMaterial),
texture,
);
},
state,
);

let batchSetNewDiffueMaps =
(
diffuseMapLightMaterials,
lightMaterialDiffuseMaps,
{settingRecord} as state,
) => {
let (
{textureIndices, diffuseMapUnits, emptyMapUnitArrayMap}: LightMaterialType.lightMaterialRecord
) as lightMaterialRecord =
RecordLightMaterialMainService.getRecord(state);
let (textureIndices, diffuseMapUnits, emptyMapUnitArrayMap) =
_batchSetNewMap(
(diffuseMapLightMaterials, lightMaterialDiffuseMaps, 0),
(
OperateTypeArrayLightMaterialService.setDiffuseMapUnit,
OperateTypeArrayLightMaterialService.setTextureIndex,
),
(
BufferSettingService.getTextureCountPerMaterial(settingRecord),
textureIndices,
diffuseMapUnits,
emptyMapUnitArrayMap,
),
);

let (textureIndices, mapUnits, emptyMapUnitArrayMap) =
materialArr
|> WonderCommonlib.ArrayService.reduceOneParami(
(.
(textureIndices, mapUnits, emptyMapUnitArrayMap),
material,
index,
) => {
let texture = Array.unsafe_get(textureArr, index);

let (mapUnit, emptyMapUnitArrayMap) =
EmptyMapUnitArrayMapService.unsafeGetEmptyMapUnitAndPop(
material,
emptyMapUnitArrayMap,
);

(
setTextureIndexFunc(.
(material, mapUnit, textureCountPerMaterial),
texture,
textureIndices,
),
setMapUnitFunc(. material, mapUnit, mapUnits),
emptyMapUnitArrayMap,
);
},
(textureIndices, diffuseMapUnits, emptyMapUnitArrayMap),
);

{
...state,
Expand All @@ -77,6 +72,22 @@ let batchSetNewDiffueMaps =
};
};

let batchSetNewDiffueMaps =
(
diffuseMapLightMaterials,
lightMaterialDiffuseMaps,
{settingRecord} as state,
) =>
_batchSetNewMap(
(diffuseMapLightMaterials, lightMaterialDiffuseMaps, 0),
(
OperateTypeArrayLightMaterialService.setDiffuseMapUnit,
OperateTypeArrayLightMaterialService.setTextureIndex,
),
BufferSettingService.getTextureCountPerMaterial(settingRecord),
state,
);

let batchSetBasicSourceTextureData =
(
samplerBasicSourceTextures,
Expand Down
8 changes: 7 additions & 1 deletion src/service/primitive/texture/DisposeTextureService.re
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ let disposeGlTextureMap = (texture, gl, glTextureMap) =>

glTextureMap |> WonderCommonlib.MutableSparseMapService.deleteVal(texture);
| None => glTextureMap
};
};

let addDisposeIndex = (texture, disposedIndexArray) =>
disposedIndexArray |> ArrayService.push(texture);

let isAlive = (texture, disposedIndexArray) =>
DisposeComponentService.isAlive(texture, disposedIndexArray);
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ open ArrayBufferViewSourceTextureType;

open DisposeComponentService;

let isAlive = (texture, {disposedIndexArray}) =>
DisposeTextureService.isAlive(texture, disposedIndexArray);

let _disposeData = (texture, textureIndexInTypeArr, state) => {
let {
wrapSs,
Expand Down Expand Up @@ -132,7 +135,23 @@ let _disposeData = (texture, textureIndexInTypeArr, state) => {
};
};

let handleDispose = (materialData, textureArr, state) =>
let handleDispose = (materialData, textureArr, state) => {
WonderLog.Contract.requireCheck(
() =>
WonderLog.(
Contract.(
Operators.(
DisposeComponentService.checkComponentShouldAliveWithBatchDispose(
textureArr,
isAlive,
state |> RecordArrayBufferViewSourceTextureMainService.getRecord,
)
)
)
),
IsDebugMainService.getIsDebug(StateDataMain.stateData),
);

textureArr
|> WonderCommonlib.ArrayService.reduceOneParam(
(. state, texture) => {
Expand Down Expand Up @@ -176,7 +195,7 @@ let handleDispose = (materialData, textureArr, state) =>
Some({
...arrayBufferViewSourceTextureRecord,
disposedIndexArray:
DisposeMaterialService.addDisposeIndex(
DisposeTextureService.addDisposeIndex(
textureIndexInTypeArr,
arrayBufferViewSourceTextureRecord.disposedIndexArray,
),
Expand All @@ -185,4 +204,5 @@ let handleDispose = (materialData, textureArr, state) =>
};
},
state,
);
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ open BasicSourceTextureType;

open DisposeComponentService;

let isAlive = (texture, {disposedIndexArray}) =>
DisposeTextureService.isAlive(texture, disposedIndexArray);

let _disposeData = (texture, state) => {
let {
wrapSs,
Expand Down Expand Up @@ -108,7 +111,23 @@ let _disposeData = (texture, state) => {
};
};

let handleDispose = (materialData, textureArr, state) =>
let handleDispose = (materialData, textureArr, state) => {
WonderLog.Contract.requireCheck(
() =>
WonderLog.(
Contract.(
Operators.(
DisposeComponentService.checkComponentShouldAliveWithBatchDispose(
textureArr,
isAlive,
state |> RecordBasicSourceTextureMainService.getRecord,
)
)
)
),
IsDebugMainService.getIsDebug(StateDataMain.stateData),
);

textureArr
|> WonderCommonlib.ArrayService.reduceOneParam(
(. state, texture) => {
Expand Down Expand Up @@ -142,7 +161,7 @@ let handleDispose = (materialData, textureArr, state) =>
Some({
...basicSourceTextureRecord,
disposedIndexArray:
DisposeMaterialService.addDisposeIndex(
DisposeTextureService.addDisposeIndex(
texture,
basicSourceTextureRecord.disposedIndexArray,
),
Expand All @@ -151,4 +170,5 @@ let handleDispose = (materialData, textureArr, state) =>
};
},
state,
);
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,31 @@ let _ =
},
)
);

describe("test dispose gameObject after assemble", () =>
describe("test basic source texture", () =>
testPromise(
"if the wdb use shared texture, the disposedIndexArray after dispose should has no duplicate items",
() => {
let state = state^;
let state =
state
|> FakeGlTool.setFakeGl(FakeGlTool.buildFakeGl(~sandbox, ()));

AssembleWDBSystemTool.testGLB(
sandbox^,
GLBTool.buildGLBFilePath("AlphaBlendModeTest.glb"),
((state, _, rootGameObject)) => {
let state =
GameObjectTool.disposeAllGameObjects(rootGameObject, state);

BasicSourceTextureTool.getDisposedIndexArray(state)
|> expect == [|1, 0|];
},
state,
);
},
)
)
);
});
9 changes: 8 additions & 1 deletion test/tool/service/gameObject/GameObjectTool.re
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,11 @@ let unsafeFindGameObjectByName = (targetGameObject, name, state) =>
|> ArrayService.unsafeGetFirst;

let isDeferDisposed = (gameObject, state) =>
state.gameObjectRecord.disposedUidArray |> Js.Array.includes(gameObject);
state.gameObjectRecord.disposedUidArray |> Js.Array.includes(gameObject);

let disposeAllGameObjects = (rootGameObject, state) =>
GameObjectAPI.getAllGameObjects(rootGameObject, state)
|> WonderCommonlib.ArrayService.reduceOneParam(
(. state, gameObject) => disposeGameObject(gameObject, state),
state,
);
33 changes: 18 additions & 15 deletions test/tool/service/texture/BasicSourceTextureTool.re
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,20 @@ let setBindTextureUnitCacheMap = (unit, bindedTexture, state) => {
};

/* let setBindTextureUnitMap = (texture, unit, state) => {
let basicSourceTextureRecord =
RecordBasicSourceTextureMainService.getRecord(state);
{
...state,
basicSourceTextureRecord:
Some({
...basicSourceTextureRecord,
bindTextureUnitMap:
basicSourceTextureRecord.bindTextureUnitMap
|> WonderCommonlib.MutableSparseMapService.set(texture, unit),
}),
};
}; */
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);
Expand All @@ -155,4 +155,7 @@ let getNeedAddedSourceArray = state =>

let getNeedInitedTextureIndexArray = state =>
RecordBasicSourceTextureMainService.getRecord(state).
needInitedTextureIndexArray;
needInitedTextureIndexArray;

let getDisposedIndexArray = state =>
RecordBasicSourceTextureMainService.getRecord(state).disposedIndexArray;

0 comments on commit e5f1cd7

Please sign in to comment.