Buffer.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*global define*/
  2. define([
  3. '../Core/defaultValue',
  4. '../Core/defineProperties',
  5. '../Core/destroyObject',
  6. '../Core/DeveloperError'
  7. ], function(
  8. defaultValue,
  9. defineProperties,
  10. destroyObject,
  11. DeveloperError) {
  12. "use strict";
  13. /**
  14. * @private
  15. */
  16. var Buffer = function(gl, bufferTarget, sizeInBytes, usage, buffer) {
  17. this._gl = gl;
  18. this._bufferTarget = bufferTarget;
  19. this._sizeInBytes = sizeInBytes;
  20. this._usage = usage;
  21. this._buffer = buffer;
  22. this.vertexArrayDestroyable = true;
  23. };
  24. defineProperties(Buffer.prototype, {
  25. sizeInBytes : {
  26. get : function() {
  27. return this._sizeInBytes;
  28. }
  29. },
  30. usage: {
  31. get : function() {
  32. return this._usage;
  33. }
  34. }
  35. });
  36. Buffer.prototype._getBuffer = function() {
  37. return this._buffer;
  38. };
  39. Buffer.prototype.copyFromArrayView = function(arrayView, offsetInBytes) {
  40. offsetInBytes = defaultValue(offsetInBytes, 0);
  41. //>>includeStart('debug', pragmas.debug);
  42. if (!arrayView) {
  43. throw new DeveloperError('arrayView is required.');
  44. }
  45. if (offsetInBytes + arrayView.byteLength > this._sizeInBytes) {
  46. throw new DeveloperError('This buffer is not large enough.');
  47. }
  48. //>>includeEnd('debug');
  49. var gl = this._gl;
  50. var target = this._bufferTarget;
  51. gl.bindBuffer(target, this._buffer);
  52. gl.bufferSubData(target, offsetInBytes, arrayView);
  53. gl.bindBuffer(target, null);
  54. };
  55. Buffer.prototype.isDestroyed = function() {
  56. return false;
  57. };
  58. Buffer.prototype.destroy = function() {
  59. this._gl.deleteBuffer(this._buffer);
  60. return destroyObject(this);
  61. };
  62. return Buffer;
  63. });