瀏覽代碼

missing function mandatory for some validation tests (#8999)

* missing function mandatory for some validation tests

* dummy transparent texture for validation tests

* 32b png

* RTT support with post process and partial shadow
Cedric Guillemet 4 年之前
父節點
當前提交
d4c37f5524
共有 1 個文件被更改,包括 49 次插入3 次删除
  1. 49 3
      src/Engines/nativeEngine.ts

+ 49 - 3
src/Engines/nativeEngine.ts

@@ -24,6 +24,8 @@ import { IWebRequest } from '../Misc/interfaces/iWebRequest';
 import { EngineStore } from './engineStore';
 import { ShaderCodeInliner } from "./Processors/shaderCodeInliner";
 import { WebGL2ShaderProcessor } from '../Engines/WebGL/webGL2ShaderProcessors';
+import { RenderTargetTextureSize } from '../Engines/Extensions/engine.renderTarget';
+import { DepthTextureCreationOptions } from '../Engines/depthTextureCreationOptions';
 
 interface INativeEngine {
 
@@ -129,6 +131,7 @@ interface INativeEngine {
     setFloat4(uniform: WebGLUniformLocation, x: number, y: number, z: number, w: number): void;
 
     createTexture(): WebGLTexture;
+    createDepthTexture(texture: WebGLTexture, width: number, height: number): WebGLTexture;
     loadTexture(texture: WebGLTexture, data: ArrayBufferView, generateMips: boolean, invertY: boolean, onSuccess: () => void, onError: () => void): void;
     loadCubeTexture(texture: WebGLTexture, data: Array<ArrayBufferView>, generateMips: boolean, onSuccess: () => void, onError: () => void): void;
     loadCubeTextureWithMips(texture: WebGLTexture, data: Array<Array<ArrayBufferView>>, onSuccess: () => void, onError: () => void): void;
@@ -964,6 +967,22 @@ export class NativeEngine extends Engine {
         this._native.deleteTexture(texture);
     }
 
+    /**
+     * Update the content of a dynamic texture
+     * @param texture defines the texture to update
+     * @param canvas defines the canvas containing the source
+     * @param invertY defines if data must be stored with Y axis inverted
+     * @param premulAlpha defines if alpha is stored as premultiplied
+     * @param format defines the format of the data
+     * @param forceBindTexture if the texture should be forced to be bound eg. after a graphics context loss (Default: false)
+     */
+    public updateDynamicTexture(texture: Nullable<InternalTexture>, canvas: HTMLCanvasElement, invertY: boolean, premulAlpha: boolean = false, format?: number): void {
+        // TODO: Stub! This function is needed for some GLTF validation tests.
+        // Loads a dummy 8x8 transparent png
+        var imageData = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYSURBVChTY/z//z8DPsAEpXGC4aCAgQEAGGMDDWwwgqsAAAAASUVORK5CYII=';
+        this.createTexture('data:my_image_name', true, invertY, null, Texture.BILINEAR_SAMPLINGMODE, undefined, undefined, imageData, texture, NativeEngine.TEXTUREFORMAT_RGBA, null, undefined);
+    }
+
     // TODO: Refactor to share more logic with babylon.engine.ts version.
     /**
      * Usually called from Texture.ts.
@@ -1119,6 +1138,25 @@ export class NativeEngine extends Engine {
         return texture;
     }
 
+    _createDepthStencilTexture(size: RenderTargetTextureSize, options: DepthTextureCreationOptions): NativeTexture {
+        var texture = new NativeTexture(this, InternalTextureSource.Depth);
+
+        const width = (<{ width: number, height: number, layers?: number }>size).width || <number>size;
+        const height = (<{ width: number, height: number, layers?: number }>size).height || <number>size;
+
+        var framebuffer = this._native.createDepthTexture(
+            texture._webGLTexture!,
+            width,
+            height);
+
+        texture._framebuffer = framebuffer;
+        return texture;
+    }
+
+    public _releaseFramebufferObjects(texture: InternalTexture): void {
+        // TODO
+    }
+
     /**
      * Creates a cube texture
      * @param rootUrl defines the url where the files to load is located
@@ -1327,10 +1365,14 @@ export class NativeEngine extends Engine {
         }
 
         if (forceFullscreenViewport) {
-            throw new Error("forceFullscreenViewport for frame buffers not yet supported in NativeEngine.");
+            //Not supported yet but don't stop rendering
         }
 
-        this._bindUnboundFramebuffer(texture._framebuffer);
+        if (texture._depthStencilTexture) {
+            this._bindUnboundFramebuffer(texture._depthStencilTexture._framebuffer);
+        } else {
+            this._bindUnboundFramebuffer(texture._framebuffer);
+        }
     }
 
     public unBindFramebuffer(texture: InternalTexture, disableGenerateMipMaps = false, onBeforeUnbind?: () => void): void {
@@ -1464,7 +1506,11 @@ export class NativeEngine extends Engine {
 
     /** @hidden */
     public _bindTexture(channel: number, texture: InternalTexture): void {
-        throw new Error("_bindTexture not implemented.");
+        let uniform = this._boundUniforms[channel];
+        if (!uniform) {
+            return ;
+        }
+        this._native.setTexture(uniform, texture._webGLTexture);
     }
 
     protected _deleteBuffer(buffer: NativeDataBuffer): void {