일반적으로 WebGL 호출은 빠릅니다. 예를 들어, 모든 모델의 모든 모델 속성이 다른 버퍼에 있었고 모든 모델에 위치, 법선, 문자 코드, 정점 색상이 있다고 말할 수 있습니다. 인덱스 된 정점을 사용하고 있다고 가정합니다. 그리고 적어도 9 함수를 호출 필요로 전화를 그리기 위해 설정하는
for each model
gl.bindBuffer(gl.ARRAY_BUFFER, model.positionBuffer);
gl.vertexAttribPointer(model.positionLocation, ...);
gl.bindBuffer(gl.ARRAY_BUFFER, model.normalBuffer);
gl.vertexAttribPointer(model.normalLocation, ...);
gl.bindBuffer(gl.ARRAY_BUFFER, model.texcoordBuffer);
gl.vertexAttribPointer(model.texcoordLocation, ...);
gl.bindBuffer(gl.ARRAY_BUFFER, model.vertexColorBuffer);
gl.vertexAttribPointer(model.vertexColorLocation, ...);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, model.indexBuffer);
...
gl.drawElements(...);
그 모든 속성은 모든 모델이있는 경우 6 개 기능
for each model
gl.bindBuffer(gl.ARRAY_BUFFER, model.buffer);
gl.vertexAttribPointer(model.positionLocation, ...);
gl.vertexAttribPointer(model.normalLocation, ...);
gl.vertexAttribPointer(model.texcoordLocation, ...);
gl.vertexAttribPointer(model.vertexColorLocation, ...);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, model.indexBuffer);
...
gl.drawElements(...);
에 감소 다음 같은 버퍼에있는 경우 동일한 버퍼를 사용하지만 오프셋을 약간만 줄이는 것이 필요합니다. 그것은 5 개 기능
gl.bindBuffer(gl.ARRAY_BUFFER, model.buffer);
for each model
gl.vertexAttribPointer(model.positionLocation, ...);
gl.vertexAttribPointer(model.normalLocation, ...);
gl.vertexAttribPointer(model.texcoordLocation, ...);
gl.vertexAttribPointer(model.vertexColorLocation, ...);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, model.indexBuffer);
...
gl.drawElements(...);
대신 모든 모델이 동일한 버퍼에서 인덱스를 사용하는 경우
그것은 더욱 당신이있어 감소 후 사용됩니다 이제 아래로 0 기능 속성을 설정하는 0입니다 물론
gl.bindBuffer(gl.ARRAY_BUFFER, model.buffer);
gl.vertexAttribPointer(model.positionLocation, ...);
gl.vertexAttribPointer(model.normalLocation, ...);
gl.vertexAttribPointer(model.texcoordLocation, ...);
gl.vertexAttribPointer(model.vertexColorLocation, ...);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, model.indexBuffer);
for each model
...
gl.drawElements(..., model.indexOffset);
에 . 유니폼을 설치하라는 전화가 여러 번있을 것입니다.
따라서 이론적으로 더 빠를 것입니다. 그러나 그것은 드로잉을 설정하는 것이 병목 현상이라고 가정합니다. 종종 병목 현상이 다른 곳에서 발생합니다. GPU (픽셀 그리기) 또는 충돌이나 물리와 같은 다른 것.
각 작은 비트가 도움이되므로 인덱스를 사용하여 모델을 분리하고 모든 나머지 데이터를 거대한 버퍼에 넣는 것이 승리인지 여부는 귀하에게 달려 있습니다. PITA처럼 들리 겠지만 그만한 가치는 없습니다. 단지 의견입니다.
WebGL은 기본적으로 16 비트 인덱스 만 지원합니다. an extension that allows 32bit indices과 according to webglstats.com it's available on 95% of machines that run WebGL이 있습니다.
렌더링 할 모델의 최대 수는 얼마입니까? 버텍스 당 얼마만큼의 데이터? 위치와 법선을 언급 했으므로 정점 당 약 24 바이트입니까? –
버텍스 당 32 바이트. 얼마나 많은 모델? 가능한 한 많이 말하기가 어렵습니까?아마도 모델 수를 줄이기 위해 일부 메시를 병합해야 할 것입니다. –