From 2253c7ad4ce3778c93bd0b55c3b86412663db8a7 Mon Sep 17 00:00:00 2001 From: deepkolos Date: Tue, 3 Sep 2024 17:37:12 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20drawingBufferSize=20calc?= =?UTF-8?q?=20when=20samples=20equals=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils.js | 2 +- webgl-memory.js | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/utils.js b/src/utils.js index 7f42976..eea1a62 100644 --- a/src/utils.js +++ b/src/utils.js @@ -119,7 +119,7 @@ export function computeDrawingbufferSize(gl, drawingBufferInfo) { const colorSize = 4; const size = gl.drawingBufferWidth * gl.drawingBufferHeight; const depthStencilSize = computeDepthStencilSize(drawingBufferInfo); - return size * colorSize + size * samples * colorSize + size * depthStencilSize; + return size * colorSize + size * (samples === 1 ? 0 : samples) * colorSize + size * depthStencilSize; } // I know this is not a full check diff --git a/webgl-memory.js b/webgl-memory.js index e4637d9..dd2ae9d 100644 --- a/webgl-memory.js +++ b/webgl-memory.js @@ -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(); @@ -388,7 +388,7 @@ const colorSize = 4; const size = gl.drawingBufferWidth * gl.drawingBufferHeight; const depthStencilSize = computeDepthStencilSize(drawingBufferInfo); - return size * colorSize + size * samples * colorSize + size * depthStencilSize; + return size * colorSize + size * (samples === 1 ? 0 : samples) * colorSize + size * depthStencilSize; } // I know this is not a full check @@ -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) @@ -487,6 +503,9 @@ }, }; }, + getResourcesInfo(type) { + return collectObjects(sharedState, type); + }, }, }, }, @@ -592,6 +611,7 @@ ++resources[typeName]; webglObjectToMemory.set(webglObj, { size: 0, + stackCreated: getStackTrace(), }); }; } @@ -634,6 +654,7 @@ memory.renderbuffer -= info.size; info.size = newSize; + info.stackUpdated = getStackTrace(); memory.renderbuffer += newSize; } @@ -703,6 +724,8 @@ memory.texture -= oldSize; memory.texture += info.size; + + info.stackUpdated = getStackTrace(); } function updateTexStorage(target, levels, internalFormat, width, height, depth) { @@ -789,6 +812,7 @@ memory.buffer -= info.size; info.size = newSize; + info.stackUpdated = getStackTrace(); memory.buffer += newSize; },