Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Nov 17, 2024
1 parent a8ea6ed commit b699345
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions webgl-memory.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* webgl-memory@1.0.16, license MIT */
/* webgl-memory@1.1.1, license MIT */
(function (factory) {
typeof define === 'function' && define.amd ? define(factory) :
factory();
Expand Down Expand Up @@ -396,6 +396,22 @@
return typeof v === 'number';
}

function collectObjects(state, type) {
const list = [...state.webglObjectToMemory.keys()]
.filter(obj => obj instanceof type)
.map((obj) => state.webglObjectToMemory.get(obj));

return list;
}

function getStackTrace() {
const stack = (new Error()).stack;
const lines = stack.split('\n');
// Remove the first two entries, the error message and this function itself, or the webgl-memory itself.
const userLines = lines.slice(2).filter((l) => !l.includes('webgl-memory.js'));
return userLines.join('\n');
}

/*
The MIT License (MIT)
Expand All @@ -419,7 +435,6 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/


//------------ [ from https://github.com/KhronosGroup/WebGLDeveloperTools ]

/*
Expand Down Expand Up @@ -487,6 +502,9 @@
},
};
},
getResourcesInfo(type) {
return collectObjects(sharedState, type);
},
},
},
},
Expand Down Expand Up @@ -592,6 +610,7 @@
++resources[typeName];
webglObjectToMemory.set(webglObj, {
size: 0,
stackCreated: getStackTrace(),
});
};
}
Expand Down Expand Up @@ -634,6 +653,7 @@

memory.renderbuffer -= info.size;
info.size = newSize;
info.stackUpdated = getStackTrace();
memory.renderbuffer += newSize;
}

Expand Down Expand Up @@ -703,6 +723,8 @@

memory.texture -= oldSize;
memory.texture += info.size;

info.stackUpdated = getStackTrace();
}

function updateTexStorage(target, levels, internalFormat, width, height, depth) {
Expand Down Expand Up @@ -789,6 +811,7 @@

memory.buffer -= info.size;
info.size = newSize;
info.stackUpdated = getStackTrace();
memory.buffer += newSize;
},

Expand Down Expand Up @@ -1121,7 +1144,6 @@
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/


function wrapGetContext(Ctor) {
const oldFn = Ctor.prototype.getContext;
Ctor.prototype.getContext = function(type, ...args) {
Expand Down

0 comments on commit b699345

Please sign in to comment.