PixelDatatype.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import freezeObject from '../Core/freezeObject.js';
  2. import WebGLConstants from '../Core/WebGLConstants.js';
  3. /**
  4. * @private
  5. */
  6. var PixelDatatype = {
  7. UNSIGNED_BYTE : WebGLConstants.UNSIGNED_BYTE,
  8. UNSIGNED_SHORT : WebGLConstants.UNSIGNED_SHORT,
  9. UNSIGNED_INT : WebGLConstants.UNSIGNED_INT,
  10. FLOAT : WebGLConstants.FLOAT,
  11. HALF_FLOAT : WebGLConstants.HALF_FLOAT_OES,
  12. UNSIGNED_INT_24_8 : WebGLConstants.UNSIGNED_INT_24_8,
  13. UNSIGNED_SHORT_4_4_4_4 : WebGLConstants.UNSIGNED_SHORT_4_4_4_4,
  14. UNSIGNED_SHORT_5_5_5_1 : WebGLConstants.UNSIGNED_SHORT_5_5_5_1,
  15. UNSIGNED_SHORT_5_6_5 : WebGLConstants.UNSIGNED_SHORT_5_6_5,
  16. isPacked : function(pixelDatatype) {
  17. return pixelDatatype === PixelDatatype.UNSIGNED_INT_24_8 ||
  18. pixelDatatype === PixelDatatype.UNSIGNED_SHORT_4_4_4_4 ||
  19. pixelDatatype === PixelDatatype.UNSIGNED_SHORT_5_5_5_1 ||
  20. pixelDatatype === PixelDatatype.UNSIGNED_SHORT_5_6_5;
  21. },
  22. sizeInBytes : function(pixelDatatype) {
  23. switch (pixelDatatype) {
  24. case PixelDatatype.UNSIGNED_BYTE:
  25. return 1;
  26. case PixelDatatype.UNSIGNED_SHORT:
  27. case PixelDatatype.UNSIGNED_SHORT_4_4_4_4:
  28. case PixelDatatype.UNSIGNED_SHORT_5_5_5_1:
  29. case PixelDatatype.UNSIGNED_SHORT_5_6_5:
  30. case PixelDatatype.HALF_FLOAT:
  31. return 2;
  32. case PixelDatatype.UNSIGNED_INT:
  33. case PixelDatatype.FLOAT:
  34. case PixelDatatype.UNSIGNED_INT_24_8:
  35. return 4;
  36. }
  37. },
  38. validate : function(pixelDatatype) {
  39. return ((pixelDatatype === PixelDatatype.UNSIGNED_BYTE) ||
  40. (pixelDatatype === PixelDatatype.UNSIGNED_SHORT) ||
  41. (pixelDatatype === PixelDatatype.UNSIGNED_INT) ||
  42. (pixelDatatype === PixelDatatype.FLOAT) ||
  43. (pixelDatatype === PixelDatatype.HALF_FLOAT) ||
  44. (pixelDatatype === PixelDatatype.UNSIGNED_INT_24_8) ||
  45. (pixelDatatype === PixelDatatype.UNSIGNED_SHORT_4_4_4_4) ||
  46. (pixelDatatype === PixelDatatype.UNSIGNED_SHORT_5_5_5_1) ||
  47. (pixelDatatype === PixelDatatype.UNSIGNED_SHORT_5_6_5));
  48. }
  49. };
  50. export default freezeObject(PixelDatatype);