SampledTexture.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. import Binding from './Binding.js';
  2. let _id = 0;
  3. /**
  4. * Represents a sampled texture binding type.
  5. *
  6. * @private
  7. * @augments Binding
  8. */
  9. class SampledTexture extends Binding {
  10. /**
  11. * Constructs a new sampled texture.
  12. *
  13. * @param {String} name - The sampled texture's name.
  14. * @param {Texture?} texture - The texture this binding is referring to.
  15. */
  16. constructor( name, texture ) {
  17. super( name );
  18. /**
  19. * This identifier.
  20. *
  21. * @type {Number}
  22. */
  23. this.id = _id ++;
  24. /**
  25. * The texture this binding is referring to.
  26. *
  27. * @type {Texture?}
  28. */
  29. this.texture = texture;
  30. /**
  31. * The binding's version.
  32. *
  33. * @type {Number}
  34. */
  35. this.version = texture ? texture.version : 0;
  36. /**
  37. * Whether the texture is a storage texture or not.
  38. *
  39. * @type {Boolean}
  40. * @default false
  41. */
  42. this.store = false;
  43. /**
  44. * The binding's generation which is an additional version
  45. * qualifier.
  46. *
  47. * @type {Number?}
  48. * @default null
  49. */
  50. this.generation = null;
  51. /**
  52. * This flag can be used for type testing.
  53. *
  54. * @type {Boolean}
  55. * @readonly
  56. * @default true
  57. */
  58. this.isSampledTexture = true;
  59. }
  60. /**
  61. * Returns `true` whether this binding requires an update for the
  62. * given generation.
  63. *
  64. * @param {Number} generation - The generation.
  65. * @return {Boolean} Whether an update is required or not.
  66. */
  67. needsBindingsUpdate( generation ) {
  68. const { texture } = this;
  69. if ( generation !== this.generation ) {
  70. this.generation = generation;
  71. return true;
  72. }
  73. return texture.isVideoTexture;
  74. }
  75. /**
  76. * Updates the binding.
  77. *
  78. * @return {Boolean} Whether the texture has been updated and must be
  79. * uploaded to the GPU.
  80. */
  81. update() {
  82. const { texture, version } = this;
  83. if ( version !== texture.version ) {
  84. this.version = texture.version;
  85. return true;
  86. }
  87. return false;
  88. }
  89. }
  90. /**
  91. * Represents a sampled array texture binding type.
  92. *
  93. * @private
  94. * @augments SampledTexture
  95. */
  96. class SampledArrayTexture extends SampledTexture {
  97. /**
  98. * Constructs a new sampled array texture.
  99. *
  100. * @param {String} name - The sampled array texture's name.
  101. * @param {(DataArrayTexture|CompressedArrayTexture)?} texture - The texture this binding is referring to.
  102. */
  103. constructor( name, texture ) {
  104. super( name, texture );
  105. /**
  106. * This flag can be used for type testing.
  107. *
  108. * @type {Boolean}
  109. * @readonly
  110. * @default true
  111. */
  112. this.isSampledArrayTexture = true;
  113. }
  114. }
  115. /**
  116. * Represents a sampled 3D texture binding type.
  117. *
  118. * @private
  119. * @augments SampledTexture
  120. */
  121. class Sampled3DTexture extends SampledTexture {
  122. /**
  123. * Constructs a new sampled 3D texture.
  124. *
  125. * @param {String} name - The sampled 3D texture's name.
  126. * @param {Data3DTexture?} texture - The texture this binding is referring to.
  127. */
  128. constructor( name, texture ) {
  129. super( name, texture );
  130. /**
  131. * This flag can be used for type testing.
  132. *
  133. * @type {Boolean}
  134. * @readonly
  135. * @default true
  136. */
  137. this.isSampled3DTexture = true;
  138. }
  139. }
  140. /**
  141. * Represents a sampled cube texture binding type.
  142. *
  143. * @private
  144. * @augments SampledTexture
  145. */
  146. class SampledCubeTexture extends SampledTexture {
  147. /**
  148. * Constructs a new sampled cube texture.
  149. *
  150. * @param {String} name - The sampled cube texture's name.
  151. * @param {(CubeTexture|CompressedCubeTexture)?} texture - The texture this binding is referring to.
  152. */
  153. constructor( name, texture ) {
  154. super( name, texture );
  155. /**
  156. * This flag can be used for type testing.
  157. *
  158. * @type {Boolean}
  159. * @readonly
  160. * @default true
  161. */
  162. this.isSampledCubeTexture = true;
  163. }
  164. }
  165. export { SampledTexture, SampledArrayTexture, Sampled3DTexture, SampledCubeTexture };
粤ICP备19079148号