Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix #15: drawingBufferSize calc when samples equals 1 #16

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 26 additions & 2 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 @@ -388,14 +388,30 @@
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
function isNumber(v) {
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 Down Expand Up @@ -487,6 +503,9 @@
},
};
},
getResourcesInfo(type) {
return collectObjects(sharedState, type);
},
},
},
},
Expand Down Expand Up @@ -592,6 +611,7 @@
++resources[typeName];
webglObjectToMemory.set(webglObj, {
size: 0,
stackCreated: getStackTrace(),
});
};
}
Expand Down Expand Up @@ -634,6 +654,7 @@

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

Expand Down Expand Up @@ -703,6 +724,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 +812,7 @@

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

Expand Down