engine.dynamicBuffer.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { ThinEngine } from "../../Engines/thinEngine.js";
  2. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  3. ThinEngine.prototype.updateDynamicIndexBuffer = function (indexBuffer, indices, offset = 0) {
  4. // Force cache update
  5. this._currentBoundBuffer[this._gl.ELEMENT_ARRAY_BUFFER] = null;
  6. this.bindIndexBuffer(indexBuffer);
  7. let view;
  8. if (indexBuffer.is32Bits) {
  9. // anything else than Uint32Array needs to be converted to Uint32Array
  10. view = indices instanceof Uint32Array ? indices : new Uint32Array(indices);
  11. }
  12. else {
  13. // anything else than Uint16Array needs to be converted to Uint16Array
  14. view = indices instanceof Uint16Array ? indices : new Uint16Array(indices);
  15. }
  16. this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER, view, this._gl.DYNAMIC_DRAW);
  17. this._resetIndexBufferBinding();
  18. };
  19. ThinEngine.prototype.updateDynamicVertexBuffer = function (vertexBuffer, data, byteOffset, byteLength) {
  20. this.bindArrayBuffer(vertexBuffer);
  21. if (byteOffset === undefined) {
  22. byteOffset = 0;
  23. }
  24. const dataLength = data.byteLength || data.length;
  25. if (byteLength === undefined || (byteLength >= dataLength && byteOffset === 0)) {
  26. if (data instanceof Array) {
  27. this._gl.bufferSubData(this._gl.ARRAY_BUFFER, byteOffset, new Float32Array(data));
  28. }
  29. else {
  30. this._gl.bufferSubData(this._gl.ARRAY_BUFFER, byteOffset, data);
  31. }
  32. }
  33. else {
  34. if (data instanceof Array) {
  35. this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, new Float32Array(data).subarray(byteOffset, byteOffset + byteLength));
  36. }
  37. else {
  38. if (data instanceof ArrayBuffer) {
  39. data = new Uint8Array(data, byteOffset, byteLength);
  40. }
  41. else {
  42. data = new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
  43. }
  44. this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, data);
  45. }
  46. }
  47. this._resetVertexBufferBinding();
  48. };
  49. //# sourceMappingURL=engine.dynamicBuffer.js.map