Skip to content

Commit 3d82cd3

Browse files
committed
build
1 parent d2c9e8a commit 3d82cd3

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

webgl-memory.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* webgl-memory@1.0.14, license MIT */
1+
/* webgl-memory@1.0.15, license MIT */
22
(function (factory) {
33
typeof define === 'function' && define.amd ? define(factory) :
44
factory();
@@ -361,22 +361,29 @@
361361

362362
function getDrawingbufferInfo(gl) {
363363
return {
364-
samples: gl.getParameter(gl.SAMPLES),
364+
samples: gl.getParameter(gl.SAMPLES) || 1,
365365
depthBits: gl.getParameter(gl.DEPTH_BITS),
366+
stencilBits: gl.getParameter(gl.STENCIL_BITS),
366367
contextAttributes: gl.getContextAttributes(),
367368
};
368369
}
370+
371+
function computeDepthStencilSize(drawingBufferInfo) {
372+
const {depthBits, stencilBits} = drawingBufferInfo;
373+
const depthSize = (depthBits + stencilBits + 7) / 8 | 0;
374+
return depthSize === 3 ? 4 : depthSize;
375+
}
376+
369377
function computeDrawingbufferSize(gl, drawingBufferInfo) {
370-
// this will need to change for hi-color support
371378
if (gl.isContextLost()) {
372379
return 0;
373380
}
374-
const {samples, depthBits, contextAttributes} = drawingBufferInfo;
375-
const size = gl.drawingBufferWidth * gl.drawingBufferHeight * 4 || 0;
376-
const depth = contextAttributes.depth ? 1 : 0;
377-
const stencil = contextAttributes.stencil ? 1 : 0;
378-
const depthSize = Math.min(stencil + depthBits > 16 ? 4 : 2, 4);
379-
return size + size * samples + size * depth * depthSize;
381+
const {samples} = drawingBufferInfo;
382+
// this will need to change for hi-color support
383+
const colorSize = 4;
384+
const size = gl.drawingBufferWidth * gl.drawingBufferHeight;
385+
const depthStencilSize = computeDepthStencilSize(drawingBufferInfo);
386+
return size * colorSize + size * samples * colorSize + size * depthStencilSize;
380387
}
381388

382389
// I know this is not a full check

0 commit comments

Comments
 (0)