UNPKG

@antv/g-webgpu-raytracer

Version:

A simple ray tracer implemented with WebGPU

60 lines (52 loc) 1.67 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.Buffer = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var Buffer = /*#__PURE__*/function () { function Buffer(bindingPoint, length) { (0, _classCallCheck2.default)(this, Buffer); this.cursor = 0; this.buffer = void 0; this.bindingPoint = void 0; this.i32 = void 0; this.f32 = void 0; // we only use Int32 and Float32, so 4 bytes for each item this.buffer = new ArrayBuffer(length * 4); this.i32 = new Int32Array(this.buffer); this.f32 = new Float32Array(this.buffer); this.bindingPoint = bindingPoint; } // createWebGLBuffer(gl: WebGL2Context) { // const id = gl.createBuffer(); // gl.bindBuffer(gl.SHADER_STORAGE_BUFFER, id); // // Important! Tell the buffer to bind to a specific binding point // gl.bindBufferBase(gl.SHADER_STORAGE_BUFFER, this.bindingPoint, id); // return { // name, // buffer: id as WebGLBuffer, // length: 0, // }; // } (0, _createClass2.default)(Buffer, [{ key: "appendF", value: function appendF(n) { this.f32[this.cursor++] = n; } }, { key: "appendI", value: function appendI(n) { this.i32[this.cursor++] = n; } }, { key: "pad", value: function pad(n) { this.cursor += n; } }]); return Buffer; }(); exports.Buffer = Buffer; //# sourceMappingURL=Buffer.js.map