nativeInterfaces.d.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. import type { DeviceType } from "../../DeviceInput/InputDevices/deviceEnums";
  2. import type { IDeviceInputSystem } from "../../DeviceInput/inputInterfaces";
  3. import type { InternalTexture } from "../../Materials/Textures/internalTexture";
  4. import type { Nullable } from "../../types";
  5. import type { ICanvas, IImage } from "../ICanvas";
  6. import type { NativeData, NativeDataStream } from "./nativeDataStream";
  7. export type NativeTexture = NativeData;
  8. export type NativeFramebuffer = NativeData;
  9. export type NativeVertexArrayObject = NativeData;
  10. export type NativeProgram = NativeData;
  11. export type NativeUniform = NativeData;
  12. /** @internal */
  13. export interface INativeEngine {
  14. dispose(): void;
  15. requestAnimationFrame(callback: () => void): void;
  16. setDeviceLostCallback(callback: () => void): void;
  17. createVertexArray(): NativeData;
  18. createIndexBuffer(dataBuffer: ArrayBuffer, dataByteOffset: number, dataByteLength: number, is32Bits: boolean, dynamic: boolean): NativeData;
  19. recordIndexBuffer(vertexArray: NativeData, indexBuffer: NativeData): void;
  20. updateDynamicIndexBuffer(indexBuffer: NativeData, data: ArrayBuffer, dataByteOffset: number, dataByteLength: number, startIndex: number): void;
  21. createVertexBuffer(dataBuffer: ArrayBuffer, dataByteOffset: number, dataByteLength: number, dynamic: boolean): NativeData;
  22. recordVertexBuffer(vertexArray: NativeData, vertexBuffer: NativeData, location: number, byteOffset: number, byteStride: number, numElements: number, type: number, normalized: boolean, instanceDivisor: number): void;
  23. updateDynamicVertexBuffer(vertexBuffer: NativeData, dataBuffer: ArrayBuffer, dataByteOffset: number, dataByteLength: number, vertexByteOffset?: number): void;
  24. createProgram(vertexShader: string, fragmentShader: string): NativeProgram;
  25. createProgramAsync(vertexShader: string, fragmentShader: string, onSuccess: () => void, onError: (error: Error) => void): NativeProgram;
  26. getUniforms(shaderProgram: NativeProgram, uniformsNames: string[]): WebGLUniformLocation[];
  27. getAttributes(shaderProgram: NativeProgram, attributeNames: string[]): number[];
  28. createTexture(): NativeTexture;
  29. initializeTexture(texture: NativeTexture, width: number, height: number, hasMips: boolean, format: number, renderTarget: boolean, srgb: boolean, samples: number): void;
  30. loadTexture(texture: NativeTexture, data: ArrayBufferView, generateMips: boolean, invertY: boolean, srgb: boolean, onSuccess: () => void, onError: () => void): void;
  31. loadRawTexture(texture: NativeTexture, data: ArrayBufferView, width: number, height: number, format: number, generateMips: boolean, invertY: boolean): void;
  32. loadRawTexture2DArray(texture: NativeTexture, data: Nullable<ArrayBufferView>, width: number, height: number, depth: number, format: number, generateMipMaps: boolean, invertY: boolean): void;
  33. loadCubeTexture(texture: NativeTexture, data: Array<ArrayBufferView>, generateMips: boolean, invertY: boolean, srgb: boolean, onSuccess: () => void, onError: () => void): void;
  34. loadCubeTextureWithMips(texture: NativeTexture, data: Array<Array<ArrayBufferView>>, invertY: boolean, srgb: boolean, onSuccess: () => void, onError: () => void): void;
  35. getTextureWidth(texture: NativeTexture): number;
  36. getTextureHeight(texture: NativeTexture): number;
  37. copyTexture(desination: NativeTexture, source: NativeTexture): void;
  38. deleteTexture(texture: NativeTexture): void;
  39. readTexture(texture: NativeTexture, mipLevel: number, x: number, y: number, width: number, height: number, buffer: Nullable<ArrayBuffer>, bufferOffset: number, bufferLength: number): Promise<ArrayBuffer>;
  40. createImageBitmap(data: ArrayBufferView | IImage): ImageBitmap;
  41. resizeImageBitmap(image: ImageBitmap, bufferWidth: number, bufferHeight: number): Uint8Array;
  42. createFrameBuffer(texture: Nullable<NativeTexture>, width: number, height: number, generateStencilBuffer: boolean, generateDepthBuffer: boolean, samples: number): NativeFramebuffer;
  43. getRenderWidth(): number;
  44. getRenderHeight(): number;
  45. setHardwareScalingLevel(level: number): void;
  46. setViewPort(x: number, y: number, width: number, height: number): void;
  47. setCommandDataStream(dataStream: NativeDataStream): void;
  48. submitCommands(): void;
  49. }
  50. /** @internal */
  51. interface INativeEngineConstructor {
  52. prototype: INativeEngine;
  53. new (): INativeEngine;
  54. readonly PROTOCOL_VERSION: number;
  55. readonly CAPS_LIMITS_MAX_TEXTURE_SIZE: number;
  56. readonly CAPS_LIMITS_MAX_TEXTURE_LAYERS: number;
  57. readonly TEXTURE_NEAREST_NEAREST: number;
  58. readonly TEXTURE_LINEAR_LINEAR: number;
  59. readonly TEXTURE_LINEAR_LINEAR_MIPLINEAR: number;
  60. readonly TEXTURE_NEAREST_NEAREST_MIPNEAREST: number;
  61. readonly TEXTURE_NEAREST_LINEAR_MIPNEAREST: number;
  62. readonly TEXTURE_NEAREST_LINEAR_MIPLINEAR: number;
  63. readonly TEXTURE_NEAREST_LINEAR: number;
  64. readonly TEXTURE_NEAREST_NEAREST_MIPLINEAR: number;
  65. readonly TEXTURE_LINEAR_NEAREST_MIPNEAREST: number;
  66. readonly TEXTURE_LINEAR_NEAREST_MIPLINEAR: number;
  67. readonly TEXTURE_LINEAR_LINEAR_MIPNEAREST: number;
  68. readonly TEXTURE_LINEAR_NEAREST: number;
  69. readonly DEPTH_TEST_LESS: number;
  70. readonly DEPTH_TEST_LEQUAL: number;
  71. readonly DEPTH_TEST_EQUAL: number;
  72. readonly DEPTH_TEST_GEQUAL: number;
  73. readonly DEPTH_TEST_GREATER: number;
  74. readonly DEPTH_TEST_NOTEQUAL: number;
  75. readonly DEPTH_TEST_NEVER: number;
  76. readonly DEPTH_TEST_ALWAYS: number;
  77. readonly ADDRESS_MODE_WRAP: number;
  78. readonly ADDRESS_MODE_MIRROR: number;
  79. readonly ADDRESS_MODE_CLAMP: number;
  80. readonly ADDRESS_MODE_BORDER: number;
  81. readonly ADDRESS_MODE_MIRROR_ONCE: number;
  82. readonly TEXTURE_FORMAT_BC1: number;
  83. readonly TEXTURE_FORMAT_BC2: number;
  84. readonly TEXTURE_FORMAT_BC3: number;
  85. readonly TEXTURE_FORMAT_BC4: number;
  86. readonly TEXTURE_FORMAT_BC5: number;
  87. readonly TEXTURE_FORMAT_BC6H: number;
  88. readonly TEXTURE_FORMAT_BC7: number;
  89. readonly TEXTURE_FORMAT_ETC1: number;
  90. readonly TEXTURE_FORMAT_ETC2: number;
  91. readonly TEXTURE_FORMAT_ETC2A: number;
  92. readonly TEXTURE_FORMAT_ETC2A1: number;
  93. readonly TEXTURE_FORMAT_PTC12: number;
  94. readonly TEXTURE_FORMAT_PTC14: number;
  95. readonly TEXTURE_FORMAT_PTC12A: number;
  96. readonly TEXTURE_FORMAT_PTC14A: number;
  97. readonly TEXTURE_FORMAT_PTC22: number;
  98. readonly TEXTURE_FORMAT_PTC24: number;
  99. readonly TEXTURE_FORMAT_ATC: number;
  100. readonly TEXTURE_FORMAT_ATCE: number;
  101. readonly TEXTURE_FORMAT_ATCI: number;
  102. readonly TEXTURE_FORMAT_ASTC4x4: number;
  103. readonly TEXTURE_FORMAT_ASTC5x4: number;
  104. readonly TEXTURE_FORMAT_ASTC5x5: number;
  105. readonly TEXTURE_FORMAT_ASTC6x5: number;
  106. readonly TEXTURE_FORMAT_ASTC6x6: number;
  107. readonly TEXTURE_FORMAT_ASTC8x5: number;
  108. readonly TEXTURE_FORMAT_ASTC8x6: number;
  109. readonly TEXTURE_FORMAT_ASTC8x8: number;
  110. readonly TEXTURE_FORMAT_ASTC10x5: number;
  111. readonly TEXTURE_FORMAT_ASTC10x6: number;
  112. readonly TEXTURE_FORMAT_ASTC10x8: number;
  113. readonly TEXTURE_FORMAT_ASTC10x10: number;
  114. readonly TEXTURE_FORMAT_ASTC12x10: number;
  115. readonly TEXTURE_FORMAT_ASTC12x12: number;
  116. readonly TEXTURE_FORMAT_R1: number;
  117. readonly TEXTURE_FORMAT_A8: number;
  118. readonly TEXTURE_FORMAT_R8: number;
  119. readonly TEXTURE_FORMAT_R8I: number;
  120. readonly TEXTURE_FORMAT_R8U: number;
  121. readonly TEXTURE_FORMAT_R8S: number;
  122. readonly TEXTURE_FORMAT_R16: number;
  123. readonly TEXTURE_FORMAT_R16I: number;
  124. readonly TEXTURE_FORMAT_R16U: number;
  125. readonly TEXTURE_FORMAT_R16F: number;
  126. readonly TEXTURE_FORMAT_R16S: number;
  127. readonly TEXTURE_FORMAT_R32I: number;
  128. readonly TEXTURE_FORMAT_R32U: number;
  129. readonly TEXTURE_FORMAT_R32F: number;
  130. readonly TEXTURE_FORMAT_RG8: number;
  131. readonly TEXTURE_FORMAT_RG8I: number;
  132. readonly TEXTURE_FORMAT_RG8U: number;
  133. readonly TEXTURE_FORMAT_RG8S: number;
  134. readonly TEXTURE_FORMAT_RG16: number;
  135. readonly TEXTURE_FORMAT_RG16I: number;
  136. readonly TEXTURE_FORMAT_RG16U: number;
  137. readonly TEXTURE_FORMAT_RG16F: number;
  138. readonly TEXTURE_FORMAT_RG16S: number;
  139. readonly TEXTURE_FORMAT_RG32I: number;
  140. readonly TEXTURE_FORMAT_RG32U: number;
  141. readonly TEXTURE_FORMAT_RG32F: number;
  142. readonly TEXTURE_FORMAT_RGB8: number;
  143. readonly TEXTURE_FORMAT_RGB8I: number;
  144. readonly TEXTURE_FORMAT_RGB8U: number;
  145. readonly TEXTURE_FORMAT_RGB8S: number;
  146. readonly TEXTURE_FORMAT_RGB9E5F: number;
  147. readonly TEXTURE_FORMAT_BGRA8: number;
  148. readonly TEXTURE_FORMAT_RGBA8: number;
  149. readonly TEXTURE_FORMAT_RGBA8I: number;
  150. readonly TEXTURE_FORMAT_RGBA8U: number;
  151. readonly TEXTURE_FORMAT_RGBA8S: number;
  152. readonly TEXTURE_FORMAT_RGBA16: number;
  153. readonly TEXTURE_FORMAT_RGBA16I: number;
  154. readonly TEXTURE_FORMAT_RGBA16U: number;
  155. readonly TEXTURE_FORMAT_RGBA16F: number;
  156. readonly TEXTURE_FORMAT_RGBA16S: number;
  157. readonly TEXTURE_FORMAT_RGBA32I: number;
  158. readonly TEXTURE_FORMAT_RGBA32U: number;
  159. readonly TEXTURE_FORMAT_RGBA32F: number;
  160. readonly TEXTURE_FORMAT_B5G6R5: number;
  161. readonly TEXTURE_FORMAT_R5G6B5: number;
  162. readonly TEXTURE_FORMAT_BGRA4: number;
  163. readonly TEXTURE_FORMAT_RGBA4: number;
  164. readonly TEXTURE_FORMAT_BGR5A1: number;
  165. readonly TEXTURE_FORMAT_RGB5A1: number;
  166. readonly TEXTURE_FORMAT_RGB10A2: number;
  167. readonly TEXTURE_FORMAT_RG11B10F: number;
  168. readonly TEXTURE_FORMAT_D16: number;
  169. readonly TEXTURE_FORMAT_D24: number;
  170. readonly TEXTURE_FORMAT_D24S8: number;
  171. readonly TEXTURE_FORMAT_D32: number;
  172. readonly TEXTURE_FORMAT_D16F: number;
  173. readonly TEXTURE_FORMAT_D24F: number;
  174. readonly TEXTURE_FORMAT_D32F: number;
  175. readonly TEXTURE_FORMAT_D0S8: number;
  176. readonly ATTRIB_TYPE_INT8: number;
  177. readonly ATTRIB_TYPE_UINT8: number;
  178. readonly ATTRIB_TYPE_INT16: number;
  179. readonly ATTRIB_TYPE_UINT16: number;
  180. readonly ATTRIB_TYPE_FLOAT: number;
  181. readonly ALPHA_DISABLE: number;
  182. readonly ALPHA_ADD: number;
  183. readonly ALPHA_COMBINE: number;
  184. readonly ALPHA_SUBTRACT: number;
  185. readonly ALPHA_MULTIPLY: number;
  186. readonly ALPHA_MAXIMIZED: number;
  187. readonly ALPHA_ONEONE: number;
  188. readonly ALPHA_PREMULTIPLIED: number;
  189. readonly ALPHA_PREMULTIPLIED_PORTERDUFF: number;
  190. readonly ALPHA_INTERPOLATE: number;
  191. readonly ALPHA_SCREENMODE: number;
  192. readonly STENCIL_TEST_LESS: number;
  193. readonly STENCIL_TEST_LEQUAL: number;
  194. readonly STENCIL_TEST_EQUAL: number;
  195. readonly STENCIL_TEST_GEQUAL: number;
  196. readonly STENCIL_TEST_GREATER: number;
  197. readonly STENCIL_TEST_NOTEQUAL: number;
  198. readonly STENCIL_TEST_NEVER: number;
  199. readonly STENCIL_TEST_ALWAYS: number;
  200. readonly STENCIL_OP_FAIL_S_ZERO: number;
  201. readonly STENCIL_OP_FAIL_S_KEEP: number;
  202. readonly STENCIL_OP_FAIL_S_REPLACE: number;
  203. readonly STENCIL_OP_FAIL_S_INCR: number;
  204. readonly STENCIL_OP_FAIL_S_INCRSAT: number;
  205. readonly STENCIL_OP_FAIL_S_DECR: number;
  206. readonly STENCIL_OP_FAIL_S_DECRSAT: number;
  207. readonly STENCIL_OP_FAIL_S_INVERT: number;
  208. readonly STENCIL_OP_FAIL_Z_ZERO: number;
  209. readonly STENCIL_OP_FAIL_Z_KEEP: number;
  210. readonly STENCIL_OP_FAIL_Z_REPLACE: number;
  211. readonly STENCIL_OP_FAIL_Z_INCR: number;
  212. readonly STENCIL_OP_FAIL_Z_INCRSAT: number;
  213. readonly STENCIL_OP_FAIL_Z_DECR: number;
  214. readonly STENCIL_OP_FAIL_Z_DECRSAT: number;
  215. readonly STENCIL_OP_FAIL_Z_INVERT: number;
  216. readonly STENCIL_OP_PASS_Z_ZERO: number;
  217. readonly STENCIL_OP_PASS_Z_KEEP: number;
  218. readonly STENCIL_OP_PASS_Z_REPLACE: number;
  219. readonly STENCIL_OP_PASS_Z_INCR: number;
  220. readonly STENCIL_OP_PASS_Z_INCRSAT: number;
  221. readonly STENCIL_OP_PASS_Z_DECR: number;
  222. readonly STENCIL_OP_PASS_Z_DECRSAT: number;
  223. readonly STENCIL_OP_PASS_Z_INVERT: number;
  224. readonly COMMAND_DELETEVERTEXARRAY: NativeData;
  225. readonly COMMAND_DELETEINDEXBUFFER: NativeData;
  226. readonly COMMAND_DELETEVERTEXBUFFER: NativeData;
  227. readonly COMMAND_SETPROGRAM: NativeData;
  228. readonly COMMAND_SETMATRIX: NativeData;
  229. readonly COMMAND_SETMATRIX3X3: NativeData;
  230. readonly COMMAND_SETMATRIX2X2: NativeData;
  231. readonly COMMAND_SETMATRICES: NativeData;
  232. readonly COMMAND_SETINT: NativeData;
  233. readonly COMMAND_SETINTARRAY: NativeData;
  234. readonly COMMAND_SETINTARRAY2: NativeData;
  235. readonly COMMAND_SETINTARRAY3: NativeData;
  236. readonly COMMAND_SETINTARRAY4: NativeData;
  237. readonly COMMAND_SETFLOATARRAY: NativeData;
  238. readonly COMMAND_SETFLOATARRAY2: NativeData;
  239. readonly COMMAND_SETFLOATARRAY3: NativeData;
  240. readonly COMMAND_SETFLOATARRAY4: NativeData;
  241. readonly COMMAND_SETTEXTURESAMPLING: NativeData;
  242. readonly COMMAND_SETTEXTUREWRAPMODE: NativeData;
  243. readonly COMMAND_SETTEXTUREANISOTROPICLEVEL: NativeData;
  244. readonly COMMAND_SETTEXTURE: NativeData;
  245. readonly COMMAND_BINDVERTEXARRAY: NativeData;
  246. readonly COMMAND_SETSTATE: NativeData;
  247. readonly COMMAND_DELETEPROGRAM: NativeData;
  248. readonly COMMAND_SETZOFFSET: NativeData;
  249. readonly COMMAND_SETZOFFSETUNITS: NativeData;
  250. readonly COMMAND_SETDEPTHTEST: NativeData;
  251. readonly COMMAND_SETDEPTHWRITE: NativeData;
  252. readonly COMMAND_SETCOLORWRITE: NativeData;
  253. readonly COMMAND_SETBLENDMODE: NativeData;
  254. readonly COMMAND_SETFLOAT: NativeData;
  255. readonly COMMAND_SETFLOAT2: NativeData;
  256. readonly COMMAND_SETFLOAT3: NativeData;
  257. readonly COMMAND_SETFLOAT4: NativeData;
  258. readonly COMMAND_BINDFRAMEBUFFER: NativeData;
  259. readonly COMMAND_UNBINDFRAMEBUFFER: NativeData;
  260. readonly COMMAND_DELETEFRAMEBUFFER: NativeData;
  261. readonly COMMAND_DRAWINDEXED: NativeData;
  262. readonly COMMAND_DRAWINDEXEDINSTANCED?: NativeData;
  263. readonly COMMAND_DRAW: NativeData;
  264. readonly COMMAND_DRAWINSTANCED?: NativeData;
  265. readonly COMMAND_CLEAR: NativeData;
  266. readonly COMMAND_SETSTENCIL: NativeData;
  267. readonly COMMAND_SETVIEWPORT: NativeData;
  268. readonly COMMAND_SETSCISSOR: NativeData;
  269. }
  270. /** @internal */
  271. export interface INativeCamera {
  272. createVideo(constraints: MediaTrackConstraints): any;
  273. updateVideoTexture(texture: Nullable<InternalTexture>, video: HTMLVideoElement, invertY: boolean): void;
  274. }
  275. /** @internal */
  276. interface INativeCameraConstructor {
  277. prototype: INativeCamera;
  278. new (): INativeCamera;
  279. }
  280. /** @internal */
  281. interface INativeCanvasConstructor {
  282. prototype: ICanvas;
  283. new (): ICanvas;
  284. loadTTFAsync(fontName: string, buffer: ArrayBuffer): void;
  285. }
  286. /** @internal */
  287. interface INativeImageConstructor {
  288. prototype: IImage;
  289. new (): IImage;
  290. }
  291. /** @internal */
  292. interface IDeviceInputSystemConstructor {
  293. prototype: IDeviceInputSystem;
  294. new (onDeviceConnected: (deviceType: DeviceType, deviceSlot: number) => void, onDeviceDisconnected: (deviceType: DeviceType, deviceSlot: number) => void, onInputChanged: (deviceType: DeviceType, deviceSlot: number, inputIndex: number, currentState: number) => void): IDeviceInputSystem;
  295. }
  296. /** @internal */
  297. export interface INativeDataStream {
  298. writeBuffer(buffer: ArrayBuffer, length: number): void;
  299. }
  300. /** @internal */
  301. interface INativeDataStreamConstructor {
  302. prototype: INativeDataStream;
  303. new (requestFlushCallback: () => void): INativeDataStream;
  304. readonly VALIDATION_ENABLED: boolean;
  305. readonly VALIDATION_UINT_32: number;
  306. readonly VALIDATION_INT_32: number;
  307. readonly VALIDATION_FLOAT_32: number;
  308. readonly VALIDATION_UINT_32_ARRAY: number;
  309. readonly VALIDATION_INT_32_ARRAY: number;
  310. readonly VALIDATION_FLOAT_32_ARRAY: number;
  311. readonly VALIDATION_NATIVE_DATA: number;
  312. readonly VALIDATION_BOOLEAN: number;
  313. }
  314. /** @internal */
  315. export interface INative {
  316. Engine: INativeEngineConstructor;
  317. Camera: INativeCameraConstructor;
  318. Canvas: INativeCanvasConstructor;
  319. Image: INativeImageConstructor;
  320. XMLHttpRequest: any;
  321. DeviceInputSystem: IDeviceInputSystemConstructor;
  322. NativeDataStream: INativeDataStreamConstructor;
  323. }
  324. export {};