From 47756bb3365e203317797563cefd3e5ff3f67fc1 Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Tue, 19 Apr 2022 11:40:02 +0800 Subject: [PATCH 1/2] initMaterial --- packages/core/src/texture/RenderTarget.ts | 14 +++++------ .../texture/enums/RenderBufferDepthFormat.ts | 22 ++++++++++++++++++ packages/core/src/texture/index.ts | 1 + packages/rhi-webgl/src/GLTexture.ts | 23 +++++++++++++------ 4 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 packages/core/src/texture/enums/RenderBufferDepthFormat.ts diff --git a/packages/core/src/texture/RenderTarget.ts b/packages/core/src/texture/RenderTarget.ts index 695421517e..271ab6a6e9 100644 --- a/packages/core/src/texture/RenderTarget.ts +++ b/packages/core/src/texture/RenderTarget.ts @@ -1,8 +1,8 @@ import { EngineObject } from "../base"; import { Engine } from "../Engine"; import { IPlatformRenderTarget } from "../renderingHardwareInterface"; +import { RenderBufferDepthFormat } from "./enums/RenderBufferDepthFormat"; import { TextureCubeFace } from "./enums/TextureCubeFace"; -import { TextureFormat } from "./enums/TextureFormat"; import { Texture } from "./Texture"; /** @@ -13,7 +13,7 @@ export class RenderTarget extends EngineObject { _platformRenderTarget: IPlatformRenderTarget; /** @internal */ - _depth: Texture | TextureFormat | null; + _depth: Texture | RenderBufferDepthFormat | null; /** @internal */ _antiAliasing: number; @@ -76,7 +76,7 @@ export class RenderTarget extends EngineObject { * @param width - Render target width * @param height - Render target height * @param colorTexture - Render color texture - * @param depthFormat - Depth format. default TextureFormat.Depth, engine will automatically select the supported precision + * @param depthFormat - Depth format. default RenderBufferDepthFormat.Depth, engine will automatically select the supported precision * @param antiAliasing - Anti-aliasing level, default is 1 */ constructor( @@ -84,7 +84,7 @@ export class RenderTarget extends EngineObject { width: number, height: number, colorTexture: Texture, - depthFormat?: TextureFormat | null, + depthFormat?: RenderBufferDepthFormat | null, antiAliasing?: number ); @@ -113,7 +113,7 @@ export class RenderTarget extends EngineObject { * @param width - Render target width * @param height - Render target height * @param colorTextures - Render color texture array - * @param depthFormat - Depth format. default TextureFormat.Depth,engine will automatically select the supported precision + * @param depthFormat - Depth format. default RenderBufferDepthFormat.Depth,engine will automatically select the supported precision * @param antiAliasing - Anti-aliasing level, default is 1 */ constructor( @@ -121,7 +121,7 @@ export class RenderTarget extends EngineObject { width: number, height: number, colorTextures: Texture[], - depthFormat?: TextureFormat | null, + depthFormat?: RenderBufferDepthFormat | null, antiAliasing?: number ); @@ -151,7 +151,7 @@ export class RenderTarget extends EngineObject { width: number, height: number, renderTexture: Texture | Array | null, - depth: Texture | TextureFormat | null = TextureFormat.Depth, + depth: Texture | RenderBufferDepthFormat | null = RenderBufferDepthFormat.Depth, antiAliasing: number = 1 ) { super(engine); diff --git a/packages/core/src/texture/enums/RenderBufferDepthFormat.ts b/packages/core/src/texture/enums/RenderBufferDepthFormat.ts new file mode 100644 index 0000000000..a791530831 --- /dev/null +++ b/packages/core/src/texture/enums/RenderBufferDepthFormat.ts @@ -0,0 +1,22 @@ +/** + * Render buffer depth format enumeration. + */ +export enum RenderBufferDepthFormat { + /** Render to depth buffer,engine will automatically select the supported precision. */ + Depth, + /** Render to depth stencil buffer, engine will automatically select the supported precision. */ + DepthStencil, + /** Render to stencil buffer. */ + Stencil, + + /** Force 16-bit depth buffer. */ + Depth16, + /** Force 24-bit depth buffer. */ + Depth24, + /** Force 32-bit depth buffer. */ + Depth32, + /** Force 16-bit depth + 8-bit stencil buffer. */ + Depth24Stencil8, + /** Force 32-bit depth + 8-bit stencil buffer. */ + Depth32Stencil8 +} diff --git a/packages/core/src/texture/index.ts b/packages/core/src/texture/index.ts index d9668928fc..91575c7c66 100644 --- a/packages/core/src/texture/index.ts +++ b/packages/core/src/texture/index.ts @@ -1,3 +1,4 @@ +export { RenderBufferDepthFormat } from "./enums/RenderBufferDepthFormat"; export { TextureCubeFace } from "./enums/TextureCubeFace"; export { TextureFilterMode } from "./enums/TextureFilterMode"; export { TextureFormat } from "./enums/TextureFormat"; diff --git a/packages/rhi-webgl/src/GLTexture.ts b/packages/rhi-webgl/src/GLTexture.ts index 2bedccd5c4..a44a180c7e 100644 --- a/packages/rhi-webgl/src/GLTexture.ts +++ b/packages/rhi-webgl/src/GLTexture.ts @@ -6,6 +6,7 @@ import { TextureCubeFace, TextureFilterMode, TextureFormat, + RenderBufferDepthFormat, TextureWrapMode } from "@oasis-engine/core"; import { GLCompressedTextureInternalFormat, TextureFormatDetail } from "./type"; @@ -192,6 +193,7 @@ export class GLTexture implements IPlatformTexture { ): TextureFormatDetail { switch (format) { case TextureFormat.Depth: + case RenderBufferDepthFormat.Depth: return { internalFormat: isWebGL2 ? gl.DEPTH_COMPONENT32F : gl.DEPTH_COMPONENT16, baseFormat: gl.DEPTH_COMPONENT, @@ -200,6 +202,7 @@ export class GLTexture implements IPlatformTexture { attachment: gl.DEPTH_ATTACHMENT }; case TextureFormat.DepthStencil: + case RenderBufferDepthFormat.DepthStencil: return { internalFormat: isWebGL2 ? gl.DEPTH24_STENCIL8 : gl.DEPTH_STENCIL, baseFormat: gl.DEPTH_STENCIL, @@ -208,6 +211,7 @@ export class GLTexture implements IPlatformTexture { attachment: gl.DEPTH_STENCIL_ATTACHMENT }; case TextureFormat.Stencil: + case RenderBufferDepthFormat.Stencil: return { internalFormat: gl.STENCIL_INDEX8, baseFormat: gl.STENCIL_ATTACHMENT, @@ -216,6 +220,7 @@ export class GLTexture implements IPlatformTexture { attachment: gl.STENCIL_ATTACHMENT }; case TextureFormat.Depth16: + case RenderBufferDepthFormat.Depth16: return { internalFormat: isWebGL2 ? gl.DEPTH_COMPONENT16 : gl.DEPTH_COMPONENT16, baseFormat: gl.DEPTH_COMPONENT, @@ -224,6 +229,7 @@ export class GLTexture implements IPlatformTexture { attachment: gl.DEPTH_ATTACHMENT }; case TextureFormat.Depth24: + case RenderBufferDepthFormat.Depth24: return { internalFormat: gl.DEPTH_COMPONENT24, baseFormat: gl.DEPTH_COMPONENT, @@ -232,6 +238,7 @@ export class GLTexture implements IPlatformTexture { attachment: gl.DEPTH_ATTACHMENT }; case TextureFormat.Depth32: + case RenderBufferDepthFormat.Depth32: return { internalFormat: gl.DEPTH_COMPONENT32F, baseFormat: gl.DEPTH_COMPONENT, @@ -240,6 +247,7 @@ export class GLTexture implements IPlatformTexture { attachment: gl.DEPTH_ATTACHMENT }; case TextureFormat.Depth24Stencil8: + case RenderBufferDepthFormat.Depth24Stencil8: return { internalFormat: isWebGL2 ? gl.DEPTH24_STENCIL8 : gl.DEPTH_STENCIL, baseFormat: gl.DEPTH_STENCIL, @@ -248,6 +256,7 @@ export class GLTexture implements IPlatformTexture { attachment: gl.DEPTH_STENCIL_ATTACHMENT }; case TextureFormat.Depth32Stencil8: + case RenderBufferDepthFormat.Depth32Stencil8: return { internalFormat: gl.DEPTH32F_STENCIL8, baseFormat: gl.DEPTH_STENCIL, @@ -325,18 +334,18 @@ export class GLTexture implements IPlatformTexture { } switch (format) { + case RenderBufferDepthFormat.Stencil: case TextureFormat.Stencil: - { - isSupported = false; - } + isSupported = false; break; case TextureFormat.Depth24: case TextureFormat.Depth32: case TextureFormat.Depth32Stencil8: - { - if (!isWebGL2) { - isSupported = false; - } + case RenderBufferDepthFormat.Depth24: + case RenderBufferDepthFormat.Depth32: + case RenderBufferDepthFormat.Depth32Stencil8: + if (!isWebGL2) { + isSupported = false; } break; } From de7b1cc9c0cf0d8a15a23518202bc15dd795a512 Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Tue, 19 Apr 2022 17:29:07 +0800 Subject: [PATCH 2/2] refactor: fix bug --- packages/core/src/Engine.ts | 3 +-- packages/core/src/Script.ts | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/core/src/Engine.ts b/packages/core/src/Engine.ts index 92d3b82363..a8ec6c5c7d 100644 --- a/packages/core/src/Engine.ts +++ b/packages/core/src/Engine.ts @@ -278,9 +278,8 @@ export class Engine extends EventDispatcher { componentsManager.callScriptOnUpdate(deltaTime); componentsManager.callAnimationUpdate(deltaTime); componentsManager.callScriptOnLateUpdate(deltaTime); - componentsManager.handlingInvalidScripts(); - this._render(scene); + componentsManager.handlingInvalidScripts(); } engineFeatureManager.callFeatureMethod(this, "postTick", [this, this._sceneManager._activeScene]); diff --git a/packages/core/src/Script.ts b/packages/core/src/Script.ts index eb8960261e..055680e67d 100644 --- a/packages/core/src/Script.ts +++ b/packages/core/src/Script.ts @@ -219,8 +219,8 @@ export class Script extends Component { */ _handlingInValid(): void { const componentsManager = this.engine._componentsManager; - // Use "xxIndex" is more safe. - // When call onDisable it maybe it still not in script queue,for example write "entity.isActive = false" in onWake(). + // Use "xxIndex !== -1" to project. + // Developer maybe call onDisable it maybe it still not in script queue, for example write "entity.isActive = false" in onWake(). if (this._onStartIndex !== -1) { componentsManager.removeOnStartScript(this); }