Callin Rim
Callin Rim

Reputation: 134

how to set SharedArrayBuffer type bufferData in webgl?

I try to use SharedArrayBuffer as a bufferData in webgl.

MDN document tell me that can be possible.

I just Change"ArrayBuffer" to "SharedArrayBuffer" why my code spit out error.

[.WebGL-0x7fc1c209b800]GL ERROR :GL_INVALID_OPERATION : glDrawArrays: attempt to access out of range vertices in attribute 0

[Codepen](https://codepen.io/callin/pen/WLJdpq)

Upvotes: 0

Views: 466

Answers (1)

Callin Rim
Callin Rim

Reputation: 134

I change second parameter of "bufferData()" from sharedArraybuffer to view. It's weird!

original error code

        NODE_COUNT = 1
        storage = new SharedArrayBuffer( BYTES_PER_NODE * NODE_COUNT )
        console.log 'storage', storage.byteLength
        position = new Float32Array(storage)

        position.set([-.5,.3], 0)

        positionBuffer = gl.createBuffer();
        gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
        gl.bufferData(gl.ARRAY_BUFFER, storage, gl.STATIC_DRAW);

error fixed code

        NODE_COUNT = 1
        storage = new SharedArrayBuffer( BYTES_PER_NODE * NODE_COUNT )
        console.log 'storage', storage.byteLength
        position = new Float32Array(storage)

        position.set([-.5,.3], 0)

        positionBuffer = gl.createBuffer();
        gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
        gl.bufferData(gl.ARRAY_BUFFER, position, gl.STATIC_DRAW); # <-- error fixed

Upvotes: 1

Related Questions