IE 11 bufferData()不会将数据分配/传输到VBO

时间:2017-10-30 17:37:49

标签: javascript internet-explorer webgl internet-explorer-11

我遇到了IE 11,bufferData调用的问题,其中参数是一个DataView实例。在IE 11中,这导致INVALID_OPERATION:drawArrays:在调用drawArrays()期间缓冲区大小错误。该代码适用于Chrome 61和Firefox 56。

我的问题是有经验的WebGL / JS开发人员,无论是IE漏洞还是我滥用DataView以及任何变通方法。在我的应用程序中,我想要的设计是:分配一个字节数组缓冲区,根据程序某些部分的上下文,使用适当的数据视图(如Float32Array)对其进行操作,然后将其复制到WebGL VBO缓冲区中的不同部分。程序,而不必弄清楚特定的DataView实例(如Float32Array)。

我使用灵魂线http://jsfiddle.net/soulwire/XLnVW/中的简单三角形WebGL示例作为基础来复制问题。我的修改发布在下方,可用http://jsfiddle.net/1h3225uj/4/

function initBuffers() {
    //allocate space for 3 * vec3 * 4 bytes/component
    rawPolygonArrayBuffer = new ArrayBuffer(3 * 3 * 4);

    //fill vertices using Float32Array view
    float32PolygonArrayBufferView = new Float32Array(rawPolygonArrayBuffer);
    float32PolygonArrayBufferView[0] = -0.5;
    float32PolygonArrayBufferView[1] = -0.5;
    float32PolygonArrayBufferView[2] = 0.0;
    float32PolygonArrayBufferView[3] = 0.0;
    float32PolygonArrayBufferView[4] = 0.5;
    float32PolygonArrayBufferView[5] = 0.0;
    float32PolygonArrayBufferView[6] = 0.5;
    float32PolygonArrayBufferView[7] = -0.5;
    float32PolygonArrayBufferView[8] = 0.0;

    //Create a generic view into ArrayBuffer object
    genericPolygonArrayBufferView = new DataView(rawPolygonArrayBuffer);

    vertexBuffer = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
    //gl.bufferData(gl.ARRAY_BUFFER, float32PolygonArrayBufferView, gl.STATIC_DRAW); //<-- WORKS
    gl.bufferData(gl.ARRAY_BUFFER, genericPolygonArrayBufferView, gl.STATIC_DRAW); //<-- Doesn't work
    glBufferAllocatedBytes = gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_SIZE);
    console.log("glBufferAllocatedBytes: " + glBufferAllocatedBytes);
    console.log("rawPolygonArrayBuffer.byteLength: " + rawPolygonArrayBuffer.byteLength);
}

console.log显示IEO上的VBO缓冲区大小为0字节,Firefox / Chrome中为36字节。

1 个答案:

答案 0 :(得分:2)

WebGL spec状态TASK [debug] ******************************************************************* ok: [localhost] => { "padded.result": [ { "applications": [ { "port": "08302", "protocol": "tcp" }, { "port": "02000", "protocol": "udp" }, { "port": "02000", "protocol": "tcp" } ], "ip_addresses": [ "010.010.010.010", "011.011.011.011" ], "name": "name1", "nat_destination_addresses": [ { "destination": "013.013.013.013", "host": "012.012.012.012" }, { "destination": "015.015.015.015", "host": "014.014.014.014" } ], "nat_source_address": "016.016.016.016" }, { "ip_addresses": [ "017.017.017.017" ], "name": "name2" }, { "ip_addresses": [ "018.018.018.018", "019.019.019.019" ], "name": "name3" } ] } bufferData接受bufferSubData s依次为specified on MDN

  

BufferSource是一个typedef,用于表示对象本身是 ArrayBuffer ,或者是 TypedArray 提供 ArrayBufferView

DataView不是这样,但是它确实通过其BufferSource成员公开了其基础ArrayBuffer,因此您只需使用它来上传数据:

buffer