Skip to content

Commit

Permalink
feat(dispose): add "dispose texture" logic(draft)
Browse files Browse the repository at this point in the history
update wonder-webgl version
  • Loading branch information
yyc-git committed May 20, 2019
1 parent fa10df7 commit dce7094
Show file tree
Hide file tree
Showing 27 changed files with 947 additions and 381 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@
"wonder-imgui": "^0.0.34",
"wonder-log": "^0.2.11",
"wonder-most-animation-frame": "0.0.3",
"wonder-webgl": "^0.0.9"
"wonder-webgl": "^0.0.10"
},
"resolutions": {
"wonder-log": "^0.2.11",
"wonder-webgl": "^0.0.9",
"wonder-webgl": "^0.0.10",
"wonder-commonlib": "0.2.31",
"wonder-bs-jest": "0.3.0",
"wonder-bs-puppeteer": "^0.1.6"
Expand Down
19 changes: 19 additions & 0 deletions src/service/primitive/GameObjectsMapGroupService.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
let isGroup = (component, gameObjectsMap) =>
switch (GameObjectsMapService.getGameObjects(component, gameObjectsMap)) {
| Some(arr) when arr |> Js.Array.length > 0 => true
| _ => false
};

let removeGameObject = (gameObject, component, gameObjectsMap) =>
GameObjectsMapService.removeGameObject(
gameObject,
component,
gameObjectsMap,
);

let batchRemoveGameObjects = (gameObjectArr, component, gameObjectsMap) =>
GameObjectsMapService.batchRemoveGameObjects(
gameObjectArr,
component,
gameObjectsMap,
);
86 changes: 0 additions & 86 deletions src/service/primitive/GroupService.re

This file was deleted.

117 changes: 57 additions & 60 deletions src/service/primitive/buffer/DisposeTypeArrayService.re
Original file line number Diff line number Diff line change
@@ -1,75 +1,72 @@
let deleteBySwapAndResetFloat32TypeArr =
[@bs]
(
((sourceIndex, targetIndex), typeArr, length, defaultValueArr) => {
open Js.Typed_array;
for (i in 0 to length - 1) {
Float32Array.unsafe_set(
typeArr,
sourceIndex + i,
Float32Array.unsafe_get(typeArr, targetIndex + i)
);
Float32Array.unsafe_set(typeArr, targetIndex + i, defaultValueArr[i])
};
typeArr
}
);
(. (sourceIndex, targetIndex), typeArr, length, defaultValueArr) => {
open Js.Typed_array;
for (i in 0 to length - 1) {
Float32Array.unsafe_set(
typeArr,
sourceIndex + i,
Float32Array.unsafe_get(typeArr, targetIndex + i),
);
Float32Array.unsafe_set(typeArr, targetIndex + i, defaultValueArr[i]);
};
typeArr;
};

let deleteSingleValueBySwapAndResetFloat32TypeArr =
[@bs]
(
((sourceIndex, targetIndex), typeArr, length: int, defaultValue) => {
open Js.Typed_array;
Float32Array.unsafe_set(typeArr, sourceIndex, Float32Array.unsafe_get(typeArr, targetIndex));
Float32Array.unsafe_set(typeArr, targetIndex, defaultValue);
typeArr
}
);
(. (sourceIndex, targetIndex), typeArr, length: int, defaultValue) => {
open Js.Typed_array;
Float32Array.unsafe_set(
typeArr,
sourceIndex,
Float32Array.unsafe_get(typeArr, targetIndex),
);
Float32Array.unsafe_set(typeArr, targetIndex, defaultValue);
typeArr;
};

let deleteSingleValueBySwapUint32TypeArr = (sourceIndex, lastIndex, typeArr) => {
open Js.Typed_array;
Uint32Array.unsafe_set(typeArr, sourceIndex, Uint32Array.unsafe_get(typeArr, lastIndex));
typeArr
Uint32Array.unsafe_set(
typeArr,
sourceIndex,
Uint32Array.unsafe_get(typeArr, lastIndex),
);
typeArr;
};

let deleteAndResetFloat32TypeArr =
[@bs]
(
(sourceIndex, length, defaultValueArr, typeArr) => {
open Js.Typed_array;
for (i in 0 to length - 1) {
Float32Array.unsafe_set(typeArr, sourceIndex + i, defaultValueArr[i])
};
typeArr
}
);
(. sourceIndex, length, defaultValueArr, typeArr) => {
open Js.Typed_array;
for (i in 0 to length - 1) {
Float32Array.unsafe_set(typeArr, sourceIndex + i, defaultValueArr[i]);
};
typeArr;
};

let deleteAndResetFloat32 =
[@bs]
(
(sourceIndex, defaultValue, typeArr) => {
open Js.Typed_array;
Float32Array.unsafe_set(typeArr, sourceIndex, defaultValue);
typeArr
}
);
(. sourceIndex, defaultValue, typeArr) => {
open Js.Typed_array;
Float32Array.unsafe_set(typeArr, sourceIndex, defaultValue);
typeArr;
};

let deleteAndResetUint32 =
[@bs]
(
(sourceIndex, defaultValue, typeArr) => {
open Js.Typed_array;
Uint32Array.unsafe_set(typeArr, sourceIndex, defaultValue);
typeArr
}
);
(. sourceIndex, defaultValue, typeArr) => {
open Js.Typed_array;
Uint32Array.unsafe_set(typeArr, sourceIndex, defaultValue);
typeArr;
};

let deleteAndResetUint8 =
[@bs]
(
(sourceIndex, defaultValue, typeArr) => {
open Js.Typed_array;
Uint8Array.unsafe_set(typeArr, sourceIndex, defaultValue);
typeArr
}
);
(. sourceIndex, defaultValue, typeArr) => {
open Js.Typed_array;
Uint8Array.unsafe_set(typeArr, sourceIndex, defaultValue);
typeArr;
};

let deleteAndResetUint16 =
(. sourceIndex, defaultValue, typeArr) => {
open Js.Typed_array;
Uint16Array.unsafe_set(typeArr, sourceIndex, defaultValue);
typeArr;
};
6 changes: 5 additions & 1 deletion src/service/primitive/data/MaterialType.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ type shaderIndexMap = WonderCommonlib.MutableSparseMapService.t(int);

type colorMap = WonderCommonlib.MutableSparseMapService.t(array(float));

type disposedIndexArray = array(int);
type disposedIndexArray = array(int);

type materialType =
| BasicMaterial
| LightMaterial;
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,22 @@ 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),
disposedIndexArray: array(int),
needAddedSourceArray: array((int, Js.Typed_array.Uint8Array.t)),
needInitedTextureIndexArray: array(int),
nameMap: WonderCommonlib.MutableSparseMapService.t(string),
materialsMap:
WonderCommonlib.MutableSparseMapService.t(
array((int, MaterialType.materialType)),
),
};

external arrayArrayBufferViewSourceToSparseMap :
external arrayArrayBufferViewSourceToSparseMap:
array(Js.Typed_array.Uint8Array.t) =>
WonderCommonlib.MutableSparseMapService.t(Js.Typed_array.Uint8Array.t) =
"%identity";
14 changes: 11 additions & 3 deletions src/service/record/main/data/texture/BasicSourceTextureType.re
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ 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),
disposedIndexArray: array(int),
needAddedSourceArray: array((int, WonderWebgl.DomExtendType.imageElement)),
needInitedTextureIndexArray: array(int),
nameMap: WonderCommonlib.MutableSparseMapService.t(string)
nameMap: WonderCommonlib.MutableSparseMapService.t(string),
materialsMap:
WonderCommonlib.MutableSparseMapService.t(
array((int, MaterialType.materialType)),
),
};
6 changes: 3 additions & 3 deletions src/service/record/main/geometry/GroupGeometryService.re
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
open GeometryType;

let isGroupGeometry = (geometry, record) =>
GroupService.isGroup(geometry, record.gameObjectsMap);
GameObjectsMapGroupService.isGroup(geometry, record.gameObjectsMap);

let removeGameObject = (gameObject, geometry, {gameObjectsMap} as record) => {
...record,
gameObjectsMap:
GroupService.removeGameObject(gameObject, geometry, gameObjectsMap),
GameObjectsMapGroupService.removeGameObject(gameObject, geometry, gameObjectsMap),
};

let batchRemoveGameObjects =
(gameObjectArr, geometry, {gameObjectsMap} as record) => {
...record,
gameObjectsMap:
GroupService.batchRemoveGameObjects(
GameObjectsMapGroupService.batchRemoveGameObjects(
gameObjectArr,
geometry,
gameObjectsMap,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
open BasicMaterialType;

let isGroupBasicMaterial = (material, record) =>
GroupService.isGroup(material, record.gameObjectsMap);
GameObjectsMapGroupService.isGroup(material, record.gameObjectsMap);

let removeGameObject = (gameObject, material, {gameObjectsMap} as record) => {
...record,
gameObjectsMap:
GroupService.removeGameObject(gameObject, material, gameObjectsMap),
GameObjectsMapGroupService.removeGameObject(gameObject, material, gameObjectsMap),
};

let batchRemoveGameObjects =
(gameObjectArr, material, {gameObjectsMap} as record) => {
...record,
gameObjectsMap:
GroupService.batchRemoveGameObjects(
GameObjectsMapGroupService.batchRemoveGameObjects(
gameObjectArr,
material,
gameObjectsMap,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
open LightMaterialType;

let isGroupLightMaterial = (material, record) =>
GroupService.isGroup(material, record.gameObjectsMap);
GameObjectsMapGroupService.isGroup(material, record.gameObjectsMap);

let removeGameObject = (gameObject, material, {gameObjectsMap} as record) => {
...record,
gameObjectsMap:
GroupService.removeGameObject(gameObject, material, gameObjectsMap),
GameObjectsMapGroupService.removeGameObject(gameObject, material, gameObjectsMap),
};

let batchRemoveGameObjects =
(gameObjectArr, material, {gameObjectsMap} as record) => {
...record,
gameObjectsMap:
GroupService.batchRemoveGameObjects(
GameObjectsMapGroupService.batchRemoveGameObjects(
gameObjectArr,
material,
gameObjectsMap,
Expand Down
Loading

0 comments on commit dce7094

Please sign in to comment.