nativeHelpers.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. import { ErrorCodes, RuntimeError } from "../../Misc/error.js";
  2. import { VertexBuffer } from "../../Buffers/buffer.js";
  3. export function getNativeTextureFormat(format, type) {
  4. switch (format) {
  5. // Depth (type is ignored)
  6. case 15:
  7. return _native.Engine.TEXTURE_FORMAT_D16;
  8. case 16:
  9. return _native.Engine.TEXTURE_FORMAT_D24;
  10. case 13:
  11. return _native.Engine.TEXTURE_FORMAT_D24S8;
  12. case 14:
  13. return _native.Engine.TEXTURE_FORMAT_D32F;
  14. // Compressed (type is ignored)
  15. case 36492:
  16. return _native.Engine.TEXTURE_FORMAT_BC7;
  17. case 36494:
  18. return _native.Engine.TEXTURE_FORMAT_BC6H;
  19. case 33779:
  20. return _native.Engine.TEXTURE_FORMAT_BC3;
  21. case 33778:
  22. return _native.Engine.TEXTURE_FORMAT_BC2;
  23. case 33777:
  24. return _native.Engine.TEXTURE_FORMAT_BC1;
  25. case 33776:
  26. return _native.Engine.TEXTURE_FORMAT_BC1;
  27. case 37808:
  28. return _native.Engine.TEXTURE_FORMAT_ASTC4x4;
  29. case 36196:
  30. return _native.Engine.TEXTURE_FORMAT_ETC1;
  31. case 37492:
  32. return _native.Engine.TEXTURE_FORMAT_ETC2;
  33. case 37496:
  34. return _native.Engine.TEXTURE_FORMAT_ETC2A;
  35. case 4: {
  36. switch (type) {
  37. case 0:
  38. return _native.Engine.TEXTURE_FORMAT_RGB8;
  39. case 3:
  40. return _native.Engine.TEXTURE_FORMAT_RGB8S;
  41. case 6:
  42. return _native.Engine.TEXTURE_FORMAT_RGB8I;
  43. case 7:
  44. return _native.Engine.TEXTURE_FORMAT_RGB8U;
  45. }
  46. break;
  47. }
  48. case 5: {
  49. switch (type) {
  50. case 0:
  51. return _native.Engine.TEXTURE_FORMAT_RGBA8;
  52. case 1:
  53. return _native.Engine.TEXTURE_FORMAT_RGBA32F;
  54. case 2:
  55. return _native.Engine.TEXTURE_FORMAT_RGBA16F;
  56. case 3:
  57. return _native.Engine.TEXTURE_FORMAT_RGBA8S;
  58. case 4:
  59. return _native.Engine.TEXTURE_FORMAT_RGBA16I;
  60. case 5:
  61. return _native.Engine.TEXTURE_FORMAT_RGBA16U;
  62. case 6:
  63. return _native.Engine.TEXTURE_FORMAT_RGBA32I;
  64. case 7:
  65. return _native.Engine.TEXTURE_FORMAT_RGBA32U;
  66. }
  67. break;
  68. }
  69. case 6: {
  70. switch (type) {
  71. case 0:
  72. return _native.Engine.TEXTURE_FORMAT_R8;
  73. case 1:
  74. return _native.Engine.TEXTURE_FORMAT_R32F;
  75. case 2:
  76. return _native.Engine.TEXTURE_FORMAT_R16F;
  77. case 3:
  78. return _native.Engine.TEXTURE_FORMAT_R8S;
  79. case 4:
  80. return _native.Engine.TEXTURE_FORMAT_R16S;
  81. case 5:
  82. return _native.Engine.TEXTURE_FORMAT_R16U;
  83. case 6:
  84. return _native.Engine.TEXTURE_FORMAT_R32I;
  85. case 7:
  86. return _native.Engine.TEXTURE_FORMAT_R32U;
  87. }
  88. break;
  89. }
  90. case 7: {
  91. switch (type) {
  92. case 0:
  93. return _native.Engine.TEXTURE_FORMAT_RG8;
  94. case 1:
  95. return _native.Engine.TEXTURE_FORMAT_RG32F;
  96. case 2:
  97. return _native.Engine.TEXTURE_FORMAT_RG16F;
  98. case 3:
  99. return _native.Engine.TEXTURE_FORMAT_RG8S;
  100. case 4:
  101. return _native.Engine.TEXTURE_FORMAT_RG16S;
  102. case 5:
  103. return _native.Engine.TEXTURE_FORMAT_RG16U;
  104. case 6:
  105. return _native.Engine.TEXTURE_FORMAT_RG32I;
  106. case 7:
  107. return _native.Engine.TEXTURE_FORMAT_RG32U;
  108. }
  109. break;
  110. }
  111. case 12: {
  112. switch (type) {
  113. case 0:
  114. return _native.Engine.TEXTURE_FORMAT_BGRA8;
  115. }
  116. break;
  117. }
  118. }
  119. throw new RuntimeError(`Unsupported texture format or type: format ${format}, type ${type}.`, ErrorCodes.UnsupportedTextureError);
  120. }
  121. export function getNativeSamplingMode(samplingMode) {
  122. switch (samplingMode) {
  123. case 1:
  124. return _native.Engine.TEXTURE_NEAREST_NEAREST;
  125. case 2:
  126. return _native.Engine.TEXTURE_LINEAR_LINEAR;
  127. case 3:
  128. return _native.Engine.TEXTURE_LINEAR_LINEAR_MIPLINEAR;
  129. case 4:
  130. return _native.Engine.TEXTURE_NEAREST_NEAREST_MIPNEAREST;
  131. case 5:
  132. return _native.Engine.TEXTURE_NEAREST_LINEAR_MIPNEAREST;
  133. case 6:
  134. return _native.Engine.TEXTURE_NEAREST_LINEAR_MIPLINEAR;
  135. case 7:
  136. return _native.Engine.TEXTURE_NEAREST_LINEAR;
  137. case 8:
  138. return _native.Engine.TEXTURE_NEAREST_NEAREST_MIPLINEAR;
  139. case 9:
  140. return _native.Engine.TEXTURE_LINEAR_NEAREST_MIPNEAREST;
  141. case 10:
  142. return _native.Engine.TEXTURE_LINEAR_NEAREST_MIPLINEAR;
  143. case 11:
  144. return _native.Engine.TEXTURE_LINEAR_LINEAR_MIPNEAREST;
  145. case 12:
  146. return _native.Engine.TEXTURE_LINEAR_NEAREST;
  147. default:
  148. throw new Error(`Unsupported sampling mode: ${samplingMode}.`);
  149. }
  150. }
  151. export function getNativeAddressMode(wrapMode) {
  152. switch (wrapMode) {
  153. case 1:
  154. return _native.Engine.ADDRESS_MODE_WRAP;
  155. case 0:
  156. return _native.Engine.ADDRESS_MODE_CLAMP;
  157. case 2:
  158. return _native.Engine.ADDRESS_MODE_MIRROR;
  159. default:
  160. throw new Error("Unexpected wrap mode: " + wrapMode + ".");
  161. }
  162. }
  163. export function getNativeStencilFunc(func) {
  164. switch (func) {
  165. case 513:
  166. return _native.Engine.STENCIL_TEST_LESS;
  167. case 515:
  168. return _native.Engine.STENCIL_TEST_LEQUAL;
  169. case 514:
  170. return _native.Engine.STENCIL_TEST_EQUAL;
  171. case 518:
  172. return _native.Engine.STENCIL_TEST_GEQUAL;
  173. case 516:
  174. return _native.Engine.STENCIL_TEST_GREATER;
  175. case 517:
  176. return _native.Engine.STENCIL_TEST_NOTEQUAL;
  177. case 512:
  178. return _native.Engine.STENCIL_TEST_NEVER;
  179. case 519:
  180. return _native.Engine.STENCIL_TEST_ALWAYS;
  181. default:
  182. throw new Error(`Unsupported stencil func mode: ${func}.`);
  183. }
  184. }
  185. export function getNativeStencilOpFail(opFail) {
  186. switch (opFail) {
  187. case 7680:
  188. return _native.Engine.STENCIL_OP_FAIL_S_KEEP;
  189. case 0:
  190. return _native.Engine.STENCIL_OP_FAIL_S_ZERO;
  191. case 7681:
  192. return _native.Engine.STENCIL_OP_FAIL_S_REPLACE;
  193. case 7682:
  194. return _native.Engine.STENCIL_OP_FAIL_S_INCR;
  195. case 7683:
  196. return _native.Engine.STENCIL_OP_FAIL_S_DECR;
  197. case 5386:
  198. return _native.Engine.STENCIL_OP_FAIL_S_INVERT;
  199. case 34055:
  200. return _native.Engine.STENCIL_OP_FAIL_S_INCRSAT;
  201. case 34056:
  202. return _native.Engine.STENCIL_OP_FAIL_S_DECRSAT;
  203. default:
  204. throw new Error(`Unsupported stencil OpFail mode: ${opFail}.`);
  205. }
  206. }
  207. export function getNativeStencilDepthFail(depthFail) {
  208. switch (depthFail) {
  209. case 7680:
  210. return _native.Engine.STENCIL_OP_FAIL_Z_KEEP;
  211. case 0:
  212. return _native.Engine.STENCIL_OP_FAIL_Z_ZERO;
  213. case 7681:
  214. return _native.Engine.STENCIL_OP_FAIL_Z_REPLACE;
  215. case 7682:
  216. return _native.Engine.STENCIL_OP_FAIL_Z_INCR;
  217. case 7683:
  218. return _native.Engine.STENCIL_OP_FAIL_Z_DECR;
  219. case 5386:
  220. return _native.Engine.STENCIL_OP_FAIL_Z_INVERT;
  221. case 34055:
  222. return _native.Engine.STENCIL_OP_FAIL_Z_INCRSAT;
  223. case 34056:
  224. return _native.Engine.STENCIL_OP_FAIL_Z_DECRSAT;
  225. default:
  226. throw new Error(`Unsupported stencil depthFail mode: ${depthFail}.`);
  227. }
  228. }
  229. export function getNativeStencilDepthPass(opPass) {
  230. switch (opPass) {
  231. case 7680:
  232. return _native.Engine.STENCIL_OP_PASS_Z_KEEP;
  233. case 0:
  234. return _native.Engine.STENCIL_OP_PASS_Z_ZERO;
  235. case 7681:
  236. return _native.Engine.STENCIL_OP_PASS_Z_REPLACE;
  237. case 7682:
  238. return _native.Engine.STENCIL_OP_PASS_Z_INCR;
  239. case 7683:
  240. return _native.Engine.STENCIL_OP_PASS_Z_DECR;
  241. case 5386:
  242. return _native.Engine.STENCIL_OP_PASS_Z_INVERT;
  243. case 34055:
  244. return _native.Engine.STENCIL_OP_PASS_Z_INCRSAT;
  245. case 34056:
  246. return _native.Engine.STENCIL_OP_PASS_Z_DECRSAT;
  247. default:
  248. throw new Error(`Unsupported stencil opPass mode: ${opPass}.`);
  249. }
  250. }
  251. export function getNativeAlphaMode(mode) {
  252. switch (mode) {
  253. case 0:
  254. return _native.Engine.ALPHA_DISABLE;
  255. case 1:
  256. return _native.Engine.ALPHA_ADD;
  257. case 2:
  258. return _native.Engine.ALPHA_COMBINE;
  259. case 3:
  260. return _native.Engine.ALPHA_SUBTRACT;
  261. case 4:
  262. return _native.Engine.ALPHA_MULTIPLY;
  263. case 5:
  264. return _native.Engine.ALPHA_MAXIMIZED;
  265. case 6:
  266. return _native.Engine.ALPHA_ONEONE;
  267. case 7:
  268. return _native.Engine.ALPHA_PREMULTIPLIED;
  269. case 8:
  270. return _native.Engine.ALPHA_PREMULTIPLIED_PORTERDUFF;
  271. case 9:
  272. return _native.Engine.ALPHA_INTERPOLATE;
  273. case 10:
  274. return _native.Engine.ALPHA_SCREENMODE;
  275. default:
  276. throw new Error(`Unsupported alpha mode: ${mode}.`);
  277. }
  278. }
  279. export function getNativeAttribType(type) {
  280. switch (type) {
  281. case VertexBuffer.BYTE:
  282. return _native.Engine.ATTRIB_TYPE_INT8;
  283. case VertexBuffer.UNSIGNED_BYTE:
  284. return _native.Engine.ATTRIB_TYPE_UINT8;
  285. case VertexBuffer.SHORT:
  286. return _native.Engine.ATTRIB_TYPE_INT16;
  287. case VertexBuffer.UNSIGNED_SHORT:
  288. return _native.Engine.ATTRIB_TYPE_UINT16;
  289. case VertexBuffer.FLOAT:
  290. return _native.Engine.ATTRIB_TYPE_FLOAT;
  291. default:
  292. throw new Error(`Unsupported attribute type: ${type}.`);
  293. }
  294. }
  295. //# sourceMappingURL=nativeHelpers.js.map