Chrome版本51.0.2704.84
在gl.bufferSubData行上,chrome表示:
WebGL: INVALID_VALUE: bufferSubData: buffer overflow
请注意,我使用maxAmountWritten变量跟踪了VBO的长度。当我用bufferData设置它的大小时,我什至把它增加了1个元素。因此subBufferData不可能覆盖VBO的边缘。
实际代码:
updatePlacementVBO() {
var gl = this.sceneApi.getGlContext();
var paramsVbo = this.placementVBO;
if (!paramsVbo) {
paramsVbo = gl.createBuffer();
this.maxAmountWritten = 0;
}
var written = 0;
var permanentBuffer = [];
for (var i = 0; i < this.mdxObjectList.length; i++) {
var mdxObject = this.mdxObjectList[i];
if (!mdxObject.getIsRendered()) continue;
var placementMatrix = mdxObject.placementMatrix;
var diffuseColor = mdxObject.getDiffuseColor();
for (var j = 0; j < 16; j++) {
permanentBuffer[i*20+j] = placementMatrix[j];
}
for (var j = 0; j < 4; j++) {
permanentBuffer[i*20+16+j] = diffuseColor[j];
}
written++;
}
if (written>0) {
gl.bindBuffer(gl.ARRAY_BUFFER, paramsVbo);
if (written > this.maxAmountWritten) {
permanentBuffer[permanentBuffer.length] = 0;
var typedBuf = new Float32Array(permanentBuffer);
gl.bufferData(gl.ARRAY_BUFFER, typedBuf, gl.DYNAMIC_DRAW);
this.maxAmountWritten = written;
} else {
gl.bufferSubData(gl.ARRAY_BUFFER, 0, new Float32Array(permanentBuffer));
}
}
this.placementVBO = paramsVbo;
this.lastUpdatedNumber = written;
}
我没主意了
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句