nullEngine.ts 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. import { Logger } from "../Misc/logger";
  2. import { Nullable, FloatArray, IndicesArray } from "../types";
  3. import { Scene } from "../scene";
  4. import { Engine } from "../Engines/engine";
  5. import { RenderTargetCreationOptions } from "../Materials/Textures/renderTargetCreationOptions";
  6. import { VertexBuffer } from "../Meshes/buffer";
  7. import { InternalTexture, InternalTextureSource } from "../Materials/Textures/internalTexture";
  8. import { Effect } from "../Materials/effect";
  9. import { Constants } from "./constants";
  10. import { IPipelineContext } from './IPipelineContext';
  11. import { DataBuffer } from '../Meshes/dataBuffer';
  12. import { IColor4Like, IViewportLike } from '../Maths/math.like';
  13. declare const global: any;
  14. /**
  15. * Options to create the null engine
  16. */
  17. export class NullEngineOptions {
  18. /**
  19. * Render width (Default: 512)
  20. */
  21. public renderWidth = 512;
  22. /**
  23. * Render height (Default: 256)
  24. */
  25. public renderHeight = 256;
  26. /**
  27. * Texture size (Default: 512)
  28. */
  29. public textureSize = 512;
  30. /**
  31. * If delta time between frames should be constant
  32. * @see https://doc.babylonjs.com/babylon101/animations#deterministic-lockstep
  33. */
  34. public deterministicLockstep = false;
  35. /**
  36. * Maximum about of steps between frames (Default: 4)
  37. * @see https://doc.babylonjs.com/babylon101/animations#deterministic-lockstep
  38. */
  39. public lockstepMaxSteps = 4;
  40. }
  41. /**
  42. * The null engine class provides support for headless version of babylon.js.
  43. * This can be used in server side scenario or for testing purposes
  44. */
  45. export class NullEngine extends Engine {
  46. private _options: NullEngineOptions;
  47. /**
  48. * Gets a boolean indicating that the engine is running in deterministic lock step mode
  49. * @see http://doc.babylonjs.com/babylon101/animations#deterministic-lockstep
  50. * @returns true if engine is in deterministic lock step mode
  51. */
  52. public isDeterministicLockStep(): boolean {
  53. return this._options.deterministicLockstep;
  54. }
  55. /**
  56. * Gets the max steps when engine is running in deterministic lock step
  57. * @see http://doc.babylonjs.com/babylon101/animations#deterministic-lockstep
  58. * @returns the max steps
  59. */
  60. public getLockstepMaxSteps(): number {
  61. return this._options.lockstepMaxSteps;
  62. }
  63. /**
  64. * Gets the current hardware scaling level.
  65. * By default the hardware scaling level is computed from the window device ratio.
  66. * if level = 1 then the engine will render at the exact resolution of the canvas. If level = 0.5 then the engine will render at twice the size of the canvas.
  67. * @returns a number indicating the current hardware scaling level
  68. */
  69. public getHardwareScalingLevel(): number {
  70. return 1.0;
  71. }
  72. public constructor(options: NullEngineOptions = new NullEngineOptions()) {
  73. super(null);
  74. if (options.deterministicLockstep === undefined) {
  75. options.deterministicLockstep = false;
  76. }
  77. if (options.lockstepMaxSteps === undefined) {
  78. options.lockstepMaxSteps = 4;
  79. }
  80. this._options = options;
  81. // Init caps
  82. // We consider we are on a webgl1 capable device
  83. this._caps = {
  84. maxTexturesImageUnits: 16,
  85. maxVertexTextureImageUnits: 16,
  86. maxCombinedTexturesImageUnits: 32,
  87. maxTextureSize: 512,
  88. maxCubemapTextureSize: 512,
  89. maxRenderTextureSize: 512,
  90. maxVertexAttribs: 16,
  91. maxVaryingVectors: 16,
  92. maxFragmentUniformVectors: 16,
  93. maxVertexUniformVectors: 16,
  94. standardDerivatives: false,
  95. astc: null,
  96. pvrtc: null,
  97. etc1: null,
  98. etc2: null,
  99. maxAnisotropy: 0,
  100. uintIndices: false,
  101. fragmentDepthSupported: false,
  102. highPrecisionShaderSupported: true,
  103. colorBufferFloat: false,
  104. textureFloat: false,
  105. textureFloatLinearFiltering: false,
  106. textureFloatRender: false,
  107. textureHalfFloat: false,
  108. textureHalfFloatLinearFiltering: false,
  109. textureHalfFloatRender: false,
  110. textureLOD: false,
  111. drawBuffersExtension: false,
  112. depthTextureExtension: false,
  113. vertexArrayObject: false,
  114. instancedArrays: false,
  115. canUseTimestampForTimerQuery: false,
  116. maxMSAASamples: 1,
  117. blendMinMax: false
  118. };
  119. Logger.Log(`Babylon.js v${Engine.Version} - Null engine`);
  120. // Wrappers
  121. const theCurrentGlobal = (typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : window);
  122. if (typeof URL === "undefined") {
  123. theCurrentGlobal.URL = {
  124. createObjectURL: function() { },
  125. revokeObjectURL: function() { }
  126. };
  127. }
  128. if (typeof Blob === "undefined") {
  129. theCurrentGlobal.Blob = function() { };
  130. }
  131. }
  132. /**
  133. * Creates a vertex buffer
  134. * @param vertices the data for the vertex buffer
  135. * @returns the new WebGL static buffer
  136. */
  137. public createVertexBuffer(vertices: FloatArray): DataBuffer {
  138. let buffer = new DataBuffer();
  139. buffer.references = 1;
  140. return buffer;
  141. }
  142. /**
  143. * Creates a new index buffer
  144. * @param indices defines the content of the index buffer
  145. * @param updatable defines if the index buffer must be updatable
  146. * @returns a new webGL buffer
  147. */
  148. public createIndexBuffer(indices: IndicesArray): DataBuffer {
  149. let buffer = new DataBuffer();
  150. buffer.references = 1;
  151. return buffer;
  152. }
  153. /**
  154. * Clear the current render buffer or the current render target (if any is set up)
  155. * @param color defines the color to use
  156. * @param backBuffer defines if the back buffer must be cleared
  157. * @param depth defines if the depth buffer must be cleared
  158. * @param stencil defines if the stencil buffer must be cleared
  159. */
  160. public clear(color: IColor4Like, backBuffer: boolean, depth: boolean, stencil: boolean = false): void {
  161. }
  162. /**
  163. * Gets the current render width
  164. * @param useScreen defines if screen size must be used (or the current render target if any)
  165. * @returns a number defining the current render width
  166. */
  167. public getRenderWidth(useScreen = false): number {
  168. if (!useScreen && this._currentRenderTarget) {
  169. return this._currentRenderTarget.width;
  170. }
  171. return this._options.renderWidth;
  172. }
  173. /**
  174. * Gets the current render height
  175. * @param useScreen defines if screen size must be used (or the current render target if any)
  176. * @returns a number defining the current render height
  177. */
  178. public getRenderHeight(useScreen = false): number {
  179. if (!useScreen && this._currentRenderTarget) {
  180. return this._currentRenderTarget.height;
  181. }
  182. return this._options.renderHeight;
  183. }
  184. /**
  185. * Set the WebGL's viewport
  186. * @param viewport defines the viewport element to be used
  187. * @param requiredWidth defines the width required for rendering. If not provided the rendering canvas' width is used
  188. * @param requiredHeight defines the height required for rendering. If not provided the rendering canvas' height is used
  189. */
  190. public setViewport(viewport: IViewportLike, requiredWidth?: number, requiredHeight?: number): void {
  191. this._cachedViewport = viewport;
  192. }
  193. public createShaderProgram(pipelineContext: IPipelineContext, vertexCode: string, fragmentCode: string, defines: string, context?: WebGLRenderingContext): WebGLProgram {
  194. return {
  195. __SPECTOR_rebuildProgram: null,
  196. };
  197. }
  198. /**
  199. * Gets the list of webGL uniform locations associated with a specific program based on a list of uniform names
  200. * @param pipelineContext defines the pipeline context to use
  201. * @param uniformsNames defines the list of uniform names
  202. * @returns an array of webGL uniform locations
  203. */
  204. public getUniforms(pipelineContext: IPipelineContext, uniformsNames: string[]): Nullable<WebGLUniformLocation>[] {
  205. return [];
  206. }
  207. /**
  208. * Gets the lsit of active attributes for a given webGL program
  209. * @param pipelineContext defines the pipeline context to use
  210. * @param attributesNames defines the list of attribute names to get
  211. * @returns an array of indices indicating the offset of each attribute
  212. */
  213. public getAttributes(pipelineContext: IPipelineContext, attributesNames: string[]): number[] {
  214. return [];
  215. }
  216. /**
  217. * Binds an effect to the webGL context
  218. * @param effect defines the effect to bind
  219. */
  220. public bindSamplers(effect: Effect): void {
  221. this._currentEffect = null;
  222. }
  223. /**
  224. * Activates an effect, mkaing it the current one (ie. the one used for rendering)
  225. * @param effect defines the effect to activate
  226. */
  227. public enableEffect(effect: Effect): void {
  228. this._currentEffect = effect;
  229. if (effect.onBind) {
  230. effect.onBind(effect);
  231. }
  232. if (effect._onBindObservable) {
  233. effect._onBindObservable.notifyObservers(effect);
  234. }
  235. }
  236. /**
  237. * Set various states to the webGL context
  238. * @param culling defines backface culling state
  239. * @param zOffset defines the value to apply to zOffset (0 by default)
  240. * @param force defines if states must be applied even if cache is up to date
  241. * @param reverseSide defines if culling must be reversed (CCW instead of CW and CW instead of CCW)
  242. */
  243. public setState(culling: boolean, zOffset: number = 0, force?: boolean, reverseSide = false): void {
  244. }
  245. /**
  246. * Set the value of an uniform to an array of int32
  247. * @param uniform defines the webGL uniform location where to store the value
  248. * @param array defines the array of int32 to store
  249. */
  250. public setIntArray(uniform: WebGLUniformLocation, array: Int32Array): void {
  251. }
  252. /**
  253. * Set the value of an uniform to an array of int32 (stored as vec2)
  254. * @param uniform defines the webGL uniform location where to store the value
  255. * @param array defines the array of int32 to store
  256. */
  257. public setIntArray2(uniform: WebGLUniformLocation, array: Int32Array): void {
  258. }
  259. /**
  260. * Set the value of an uniform to an array of int32 (stored as vec3)
  261. * @param uniform defines the webGL uniform location where to store the value
  262. * @param array defines the array of int32 to store
  263. */
  264. public setIntArray3(uniform: WebGLUniformLocation, array: Int32Array): void {
  265. }
  266. /**
  267. * Set the value of an uniform to an array of int32 (stored as vec4)
  268. * @param uniform defines the webGL uniform location where to store the value
  269. * @param array defines the array of int32 to store
  270. */
  271. public setIntArray4(uniform: WebGLUniformLocation, array: Int32Array): void {
  272. }
  273. /**
  274. * Set the value of an uniform to an array of float32
  275. * @param uniform defines the webGL uniform location where to store the value
  276. * @param array defines the array of float32 to store
  277. */
  278. public setFloatArray(uniform: WebGLUniformLocation, array: Float32Array): void {
  279. }
  280. /**
  281. * Set the value of an uniform to an array of float32 (stored as vec2)
  282. * @param uniform defines the webGL uniform location where to store the value
  283. * @param array defines the array of float32 to store
  284. */
  285. public setFloatArray2(uniform: WebGLUniformLocation, array: Float32Array): void {
  286. }
  287. /**
  288. * Set the value of an uniform to an array of float32 (stored as vec3)
  289. * @param uniform defines the webGL uniform location where to store the value
  290. * @param array defines the array of float32 to store
  291. */
  292. public setFloatArray3(uniform: WebGLUniformLocation, array: Float32Array): void {
  293. }
  294. /**
  295. * Set the value of an uniform to an array of float32 (stored as vec4)
  296. * @param uniform defines the webGL uniform location where to store the value
  297. * @param array defines the array of float32 to store
  298. */
  299. public setFloatArray4(uniform: WebGLUniformLocation, array: Float32Array): void {
  300. }
  301. /**
  302. * Set the value of an uniform to an array of number
  303. * @param uniform defines the webGL uniform location where to store the value
  304. * @param array defines the array of number to store
  305. */
  306. public setArray(uniform: WebGLUniformLocation, array: number[]): void {
  307. }
  308. /**
  309. * Set the value of an uniform to an array of number (stored as vec2)
  310. * @param uniform defines the webGL uniform location where to store the value
  311. * @param array defines the array of number to store
  312. */
  313. public setArray2(uniform: WebGLUniformLocation, array: number[]): void {
  314. }
  315. /**
  316. * Set the value of an uniform to an array of number (stored as vec3)
  317. * @param uniform defines the webGL uniform location where to store the value
  318. * @param array defines the array of number to store
  319. */
  320. public setArray3(uniform: WebGLUniformLocation, array: number[]): void {
  321. }
  322. /**
  323. * Set the value of an uniform to an array of number (stored as vec4)
  324. * @param uniform defines the webGL uniform location where to store the value
  325. * @param array defines the array of number to store
  326. */
  327. public setArray4(uniform: WebGLUniformLocation, array: number[]): void {
  328. }
  329. /**
  330. * Set the value of an uniform to an array of float32 (stored as matrices)
  331. * @param uniform defines the webGL uniform location where to store the value
  332. * @param matrices defines the array of float32 to store
  333. */
  334. public setMatrices(uniform: WebGLUniformLocation, matrices: Float32Array): void {
  335. }
  336. /**
  337. * Set the value of an uniform to a matrix (3x3)
  338. * @param uniform defines the webGL uniform location where to store the value
  339. * @param matrix defines the Float32Array representing the 3x3 matrix to store
  340. */
  341. public setMatrix3x3(uniform: WebGLUniformLocation, matrix: Float32Array): void {
  342. }
  343. /**
  344. * Set the value of an uniform to a matrix (2x2)
  345. * @param uniform defines the webGL uniform location where to store the value
  346. * @param matrix defines the Float32Array representing the 2x2 matrix to store
  347. */
  348. public setMatrix2x2(uniform: WebGLUniformLocation, matrix: Float32Array): void {
  349. }
  350. /**
  351. * Set the value of an uniform to a number (float)
  352. * @param uniform defines the webGL uniform location where to store the value
  353. * @param value defines the float number to store
  354. */
  355. public setFloat(uniform: WebGLUniformLocation, value: number): void {
  356. }
  357. /**
  358. * Set the value of an uniform to a vec2
  359. * @param uniform defines the webGL uniform location where to store the value
  360. * @param x defines the 1st component of the value
  361. * @param y defines the 2nd component of the value
  362. */
  363. public setFloat2(uniform: WebGLUniformLocation, x: number, y: number): void {
  364. }
  365. /**
  366. * Set the value of an uniform to a vec3
  367. * @param uniform defines the webGL uniform location where to store the value
  368. * @param x defines the 1st component of the value
  369. * @param y defines the 2nd component of the value
  370. * @param z defines the 3rd component of the value
  371. */
  372. public setFloat3(uniform: WebGLUniformLocation, x: number, y: number, z: number): void {
  373. }
  374. /**
  375. * Set the value of an uniform to a boolean
  376. * @param uniform defines the webGL uniform location where to store the value
  377. * @param bool defines the boolean to store
  378. */
  379. public setBool(uniform: WebGLUniformLocation, bool: number): void {
  380. }
  381. /**
  382. * Set the value of an uniform to a vec4
  383. * @param uniform defines the webGL uniform location where to store the value
  384. * @param x defines the 1st component of the value
  385. * @param y defines the 2nd component of the value
  386. * @param z defines the 3rd component of the value
  387. * @param w defines the 4th component of the value
  388. */
  389. public setFloat4(uniform: WebGLUniformLocation, x: number, y: number, z: number, w: number): void {
  390. }
  391. /**
  392. * Sets the current alpha mode
  393. * @param mode defines the mode to use (one of the Engine.ALPHA_XXX)
  394. * @param noDepthWriteChange defines if depth writing state should remains unchanged (false by default)
  395. * @see http://doc.babylonjs.com/resources/transparency_and_how_meshes_are_rendered
  396. */
  397. public setAlphaMode(mode: number, noDepthWriteChange: boolean = false): void {
  398. if (this._alphaMode === mode) {
  399. return;
  400. }
  401. this.alphaState.alphaBlend = (mode !== Constants.ALPHA_DISABLE);
  402. if (!noDepthWriteChange) {
  403. this.setDepthWrite(mode === Constants.ALPHA_DISABLE);
  404. }
  405. this._alphaMode = mode;
  406. }
  407. /**
  408. * Bind webGl buffers directly to the webGL context
  409. * @param vertexBuffers defines the vertex buffer to bind
  410. * @param indexBuffer defines the index buffer to bind
  411. * @param vertexDeclaration defines the vertex declaration to use with the vertex buffer
  412. * @param vertexStrideSize defines the vertex stride of the vertex buffer
  413. * @param effect defines the effect associated with the vertex buffer
  414. */
  415. public bindBuffers(vertexBuffers: { [key: string]: VertexBuffer; }, indexBuffer: DataBuffer, effect: Effect): void {
  416. }
  417. /**
  418. * Force the entire cache to be cleared
  419. * You should not have to use this function unless your engine needs to share the webGL context with another engine
  420. * @param bruteForce defines a boolean to force clearing ALL caches (including stencil, detoh and alpha states)
  421. */
  422. public wipeCaches(bruteForce?: boolean): void {
  423. if (this.preventCacheWipeBetweenFrames) {
  424. return;
  425. }
  426. this.resetTextureCache();
  427. this._currentEffect = null;
  428. if (bruteForce) {
  429. this._currentProgram = null;
  430. this.stencilState.reset();
  431. this.depthCullingState.reset();
  432. this.alphaState.reset();
  433. }
  434. this._cachedVertexBuffers = null;
  435. this._cachedIndexBuffer = null;
  436. this._cachedEffectForVertexBuffers = null;
  437. }
  438. /**
  439. * Send a draw order
  440. * @param useTriangles defines if triangles must be used to draw (else wireframe will be used)
  441. * @param indexStart defines the starting index
  442. * @param indexCount defines the number of index to draw
  443. * @param instancesCount defines the number of instances to draw (if instanciation is enabled)
  444. */
  445. public draw(useTriangles: boolean, indexStart: number, indexCount: number, instancesCount?: number): void {
  446. }
  447. /**
  448. * Draw a list of indexed primitives
  449. * @param fillMode defines the primitive to use
  450. * @param indexStart defines the starting index
  451. * @param indexCount defines the number of index to draw
  452. * @param instancesCount defines the number of instances to draw (if instanciation is enabled)
  453. */
  454. public drawElementsType(fillMode: number, indexStart: number, indexCount: number, instancesCount?: number): void {
  455. }
  456. /**
  457. * Draw a list of unindexed primitives
  458. * @param fillMode defines the primitive to use
  459. * @param verticesStart defines the index of first vertex to draw
  460. * @param verticesCount defines the count of vertices to draw
  461. * @param instancesCount defines the number of instances to draw (if instanciation is enabled)
  462. */
  463. public drawArraysType(fillMode: number, verticesStart: number, verticesCount: number, instancesCount?: number): void {
  464. }
  465. /** @hidden */
  466. public _createTexture(): WebGLTexture {
  467. return {};
  468. }
  469. /** @hidden */
  470. public _releaseTexture(texture: InternalTexture): void {
  471. }
  472. /**
  473. * Usually called from Texture.ts.
  474. * Passed information to create a WebGLTexture
  475. * @param urlArg defines a value which contains one of the following:
  476. * * A conventional http URL, e.g. 'http://...' or 'file://...'
  477. * * A base64 string of in-line texture data, e.g. 'data:image/jpg;base64,/...'
  478. * * An indicator that data being passed using the buffer parameter, e.g. 'data:mytexture.jpg'
  479. * @param noMipmap defines a boolean indicating that no mipmaps shall be generated. Ignored for compressed textures. They must be in the file
  480. * @param invertY when true, image is flipped when loaded. You probably want true. Certain compressed textures may invert this if their default is inverted (eg. ktx)
  481. * @param scene needed for loading to the correct scene
  482. * @param samplingMode mode with should be used sample / access the texture (Default: Texture.TRILINEAR_SAMPLINGMODE)
  483. * @param onLoad optional callback to be called upon successful completion
  484. * @param onError optional callback to be called upon failure
  485. * @param buffer a source of a file previously fetched as either a base64 string, an ArrayBuffer (compressed or image format), HTMLImageElement (image format), or a Blob
  486. * @param fallBack an internal argument in case the function must be called again, due to etc1 not having alpha capabilities
  487. * @param format internal format. Default: RGB when extension is '.jpg' else RGBA. Ignored for compressed textures
  488. * @param forcedExtension defines the extension to use to pick the right loader
  489. * @param excludeLoaders array of texture loaders that should be excluded when picking a loader for the texture (default: empty array)
  490. * @returns a InternalTexture for assignment back into BABYLON.Texture
  491. */
  492. public createTexture(urlArg: string, noMipmap: boolean, invertY: boolean, scene: Scene, samplingMode: number = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,
  493. onLoad: Nullable<() => void> = null, onError: Nullable<(message: string, exception: any) => void> = null,
  494. buffer: Nullable<ArrayBuffer | HTMLImageElement> = null, fallBack?: InternalTexture, format?: number): InternalTexture {
  495. var texture = new InternalTexture(this, InternalTextureSource.Url);
  496. var url = String(urlArg);
  497. texture.url = url;
  498. texture.generateMipMaps = !noMipmap;
  499. texture.samplingMode = samplingMode;
  500. texture.invertY = invertY;
  501. texture.baseWidth = this._options.textureSize;
  502. texture.baseHeight = this._options.textureSize;
  503. texture.width = this._options.textureSize;
  504. texture.height = this._options.textureSize;
  505. if (format) {
  506. texture.format = format;
  507. }
  508. texture.isReady = true;
  509. if (onLoad) {
  510. onLoad();
  511. }
  512. this._internalTexturesCache.push(texture);
  513. return texture;
  514. }
  515. /**
  516. * Creates a new render target texture
  517. * @param size defines the size of the texture
  518. * @param options defines the options used to create the texture
  519. * @returns a new render target texture stored in an InternalTexture
  520. */
  521. public createRenderTargetTexture(size: any, options: boolean | RenderTargetCreationOptions): InternalTexture {
  522. let fullOptions = new RenderTargetCreationOptions();
  523. if (options !== undefined && typeof options === "object") {
  524. fullOptions.generateMipMaps = options.generateMipMaps;
  525. fullOptions.generateDepthBuffer = options.generateDepthBuffer === undefined ? true : options.generateDepthBuffer;
  526. fullOptions.generateStencilBuffer = fullOptions.generateDepthBuffer && options.generateStencilBuffer;
  527. fullOptions.type = options.type === undefined ? Constants.TEXTURETYPE_UNSIGNED_INT : options.type;
  528. fullOptions.samplingMode = options.samplingMode === undefined ? Constants.TEXTURE_TRILINEAR_SAMPLINGMODE : options.samplingMode;
  529. } else {
  530. fullOptions.generateMipMaps = <boolean>options;
  531. fullOptions.generateDepthBuffer = true;
  532. fullOptions.generateStencilBuffer = false;
  533. fullOptions.type = Constants.TEXTURETYPE_UNSIGNED_INT;
  534. fullOptions.samplingMode = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE;
  535. }
  536. var texture = new InternalTexture(this, InternalTextureSource.RenderTarget);
  537. var width = size.width || size;
  538. var height = size.height || size;
  539. texture._depthStencilBuffer = {};
  540. texture._framebuffer = {};
  541. texture.baseWidth = width;
  542. texture.baseHeight = height;
  543. texture.width = width;
  544. texture.height = height;
  545. texture.isReady = true;
  546. texture.samples = 1;
  547. texture.generateMipMaps = fullOptions.generateMipMaps ? true : false;
  548. texture.samplingMode = fullOptions.samplingMode;
  549. texture.type = fullOptions.type;
  550. texture._generateDepthBuffer = fullOptions.generateDepthBuffer;
  551. texture._generateStencilBuffer = fullOptions.generateStencilBuffer ? true : false;
  552. this._internalTexturesCache.push(texture);
  553. return texture;
  554. }
  555. /**
  556. * Update the sampling mode of a given texture
  557. * @param samplingMode defines the required sampling mode
  558. * @param texture defines the texture to update
  559. */
  560. public updateTextureSamplingMode(samplingMode: number, texture: InternalTexture): void {
  561. texture.samplingMode = samplingMode;
  562. }
  563. /**
  564. * Binds the frame buffer to the specified texture.
  565. * @param texture The texture to render to or null for the default canvas
  566. * @param faceIndex The face of the texture to render to in case of cube texture
  567. * @param requiredWidth The width of the target to render to
  568. * @param requiredHeight The height of the target to render to
  569. * @param forceFullscreenViewport Forces the viewport to be the entire texture/screen if true
  570. * @param lodLevel defines le lod level to bind to the frame buffer
  571. */
  572. public bindFramebuffer(texture: InternalTexture, faceIndex?: number, requiredWidth?: number, requiredHeight?: number, forceFullscreenViewport?: boolean): void {
  573. if (this._currentRenderTarget) {
  574. this.unBindFramebuffer(this._currentRenderTarget);
  575. }
  576. this._currentRenderTarget = texture;
  577. this._currentFramebuffer = texture._MSAAFramebuffer ? texture._MSAAFramebuffer : texture._framebuffer;
  578. if (this._cachedViewport && !forceFullscreenViewport) {
  579. this.setViewport(this._cachedViewport, requiredWidth, requiredHeight);
  580. }
  581. }
  582. /**
  583. * Unbind the current render target texture from the webGL context
  584. * @param texture defines the render target texture to unbind
  585. * @param disableGenerateMipMaps defines a boolean indicating that mipmaps must not be generated
  586. * @param onBeforeUnbind defines a function which will be called before the effective unbind
  587. */
  588. public unBindFramebuffer(texture: InternalTexture, disableGenerateMipMaps = false, onBeforeUnbind?: () => void): void {
  589. this._currentRenderTarget = null;
  590. if (onBeforeUnbind) {
  591. if (texture._MSAAFramebuffer) {
  592. this._currentFramebuffer = texture._framebuffer;
  593. }
  594. onBeforeUnbind();
  595. }
  596. this._currentFramebuffer = null;
  597. }
  598. /**
  599. * Creates a dynamic vertex buffer
  600. * @param vertices the data for the dynamic vertex buffer
  601. * @returns the new WebGL dynamic buffer
  602. */
  603. public createDynamicVertexBuffer(vertices: FloatArray): DataBuffer {
  604. let buffer = new DataBuffer();
  605. buffer.references = 1;
  606. buffer.capacity = 1;
  607. return buffer;
  608. }
  609. /**
  610. * Update the content of a dynamic texture
  611. * @param texture defines the texture to update
  612. * @param canvas defines the canvas containing the source
  613. * @param invertY defines if data must be stored with Y axis inverted
  614. * @param premulAlpha defines if alpha is stored as premultiplied
  615. * @param format defines the format of the data
  616. * @param forceBindTexture if the texture should be forced to be bound eg. after a graphics context loss (Default: false)
  617. */
  618. public updateDynamicTexture(texture: Nullable<InternalTexture>, canvas: HTMLCanvasElement, invertY: boolean, premulAlpha: boolean = false, format?: number): void {
  619. }
  620. /**
  621. * Gets a boolean indicating if all created effects are ready
  622. * @returns true if all effects are ready
  623. */
  624. public areAllEffectsReady(): boolean {
  625. return true;
  626. }
  627. /**
  628. * @hidden
  629. * Get the current error code of the webGL context
  630. * @returns the error code
  631. * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getError
  632. */
  633. public getError(): number {
  634. return 0;
  635. }
  636. /** @hidden */
  637. public _getUnpackAlignement(): number {
  638. return 1;
  639. }
  640. /** @hidden */
  641. public _unpackFlipY(value: boolean) {
  642. }
  643. /**
  644. * Update a dynamic index buffer
  645. * @param indexBuffer defines the target index buffer
  646. * @param indices defines the data to update
  647. * @param offset defines the offset in the target index buffer where update should start
  648. */
  649. public updateDynamicIndexBuffer(indexBuffer: WebGLBuffer, indices: IndicesArray, offset: number = 0): void {
  650. }
  651. /**
  652. * Updates a dynamic vertex buffer.
  653. * @param vertexBuffer the vertex buffer to update
  654. * @param vertices the data used to update the vertex buffer
  655. * @param byteOffset the byte offset of the data (optional)
  656. * @param byteLength the byte length of the data (optional)
  657. */
  658. public updateDynamicVertexBuffer(vertexBuffer: WebGLBuffer, vertices: FloatArray, byteOffset?: number, byteLength?: number): void {
  659. }
  660. /** @hidden */
  661. public _bindTextureDirectly(target: number, texture: InternalTexture): boolean {
  662. if (this._boundTexturesCache[this._activeChannel] !== texture) {
  663. this._boundTexturesCache[this._activeChannel] = texture;
  664. return true;
  665. }
  666. return false;
  667. }
  668. /** @hidden */
  669. public _bindTexture(channel: number, texture: InternalTexture): void {
  670. if (channel < 0) {
  671. return;
  672. }
  673. this._bindTextureDirectly(0, texture);
  674. }
  675. protected _deleteBuffer(buffer: WebGLBuffer): void {
  676. }
  677. /**
  678. * Force the engine to release all cached effects. This means that next effect compilation will have to be done completely even if a similar effect was already compiled
  679. */
  680. public releaseEffects() {
  681. }
  682. public displayLoadingUI(): void {
  683. }
  684. public hideLoadingUI(): void {
  685. }
  686. /** @hidden */
  687. public _uploadCompressedDataToTextureDirectly(texture: InternalTexture, internalFormat: number, width: number, height: number, data: ArrayBufferView, faceIndex: number = 0, lod: number = 0) {
  688. }
  689. /** @hidden */
  690. public _uploadDataToTextureDirectly(texture: InternalTexture, imageData: ArrayBufferView, faceIndex: number = 0, lod: number = 0): void {
  691. }
  692. /** @hidden */
  693. public _uploadArrayBufferViewToTexture(texture: InternalTexture, imageData: ArrayBufferView, faceIndex: number = 0, lod: number = 0): void {
  694. }
  695. /** @hidden */
  696. public _uploadImageToTexture(texture: InternalTexture, image: HTMLImageElement, faceIndex: number = 0, lod: number = 0) {
  697. }
  698. }