pex-gl / pex-context

Modern WebGL state wrapper for PEX: allocate GPU resources (textures, buffers), setup state pipelines and passes, and combine them into commands.
http://pex-gl.github.io/pex-context/
MIT License
160 stars 12 forks source link

Invalid index buffer type #47

Open vorg opened 6 years ago

vorg commented 6 years ago

When using pex-renderer with uint32 the indices type was uint16 while cmd.indices.buffer.type was uint32 which causes glitches in rendering. https://github.com/pex-gl/pex-context/blob/master/index.js#L761

var type = cmd.indices.type || indexBuffer.type

Test code. Is it because we are updating geometry?

ctx.gl.getExtension('OES_element_index_uint')
newGeo.cells = { buffer: ctx.indexBuffer(new Uint32Array(newGeo.cellsFlat)) }
pointCube.getComponent('Geometry').set(newGeo)
vorg commented 6 years ago

Why do we support cmd.indices.type at all? Is this for gltf where shared subbuffer has to be reinterpreted as index data?

The problematic code in pex-renderer is here https://github.com/pex-gl/pex-renderer/blob/master/geometry.js#L123

As just using typed array keeps old Uint16 type still set.]

g.cells = new Uint32Array(flatten(g.cells))

This can can be solved by

g.cells = { data: new Uint32Array(flatten(g.cells)), type: graph.ctx.DataType.Uint32 }
vorg commented 6 years ago

Error: Unknown buffer type: 5125

vorg commented 6 years ago

So this is more tricky because in pex-context buffers have type while in webgl they dont https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bufferData

Index element arrays and attrib buffers do https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements

That's why i duplicate type in both buffer and attribute. attrib.type || buffer.type || gl.FLOAT