Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RenderTaget type problem #741

Merged
merged 2 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/core/src/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/Script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/texture/RenderTarget.ts
Original file line number Diff line number Diff line change
@@ -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";

/**
Expand All @@ -13,7 +13,7 @@ export class RenderTarget extends EngineObject {
_platformRenderTarget: IPlatformRenderTarget;

/** @internal */
_depth: Texture | TextureFormat | null;
_depth: Texture | RenderBufferDepthFormat | null;
/** @internal */
_antiAliasing: number;

Expand Down Expand Up @@ -76,15 +76,15 @@ 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(
engine: Engine,
width: number,
height: number,
colorTexture: Texture,
depthFormat?: TextureFormat | null,
depthFormat?: RenderBufferDepthFormat | null,
antiAliasing?: number
);

Expand Down Expand Up @@ -113,15 +113,15 @@ 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(
engine: Engine,
width: number,
height: number,
colorTextures: Texture[],
depthFormat?: TextureFormat | null,
depthFormat?: RenderBufferDepthFormat | null,
antiAliasing?: number
);

Expand Down Expand Up @@ -151,7 +151,7 @@ export class RenderTarget extends EngineObject {
width: number,
height: number,
renderTexture: Texture | Array<Texture> | null,
depth: Texture | TextureFormat | null = TextureFormat.Depth,
depth: Texture | RenderBufferDepthFormat | null = RenderBufferDepthFormat.Depth,
antiAliasing: number = 1
) {
super(engine);
Expand Down
22 changes: 22 additions & 0 deletions packages/core/src/texture/enums/RenderBufferDepthFormat.ts
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions packages/core/src/texture/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { RenderBufferDepthFormat } from "./enums/RenderBufferDepthFormat";
export { TextureCubeFace } from "./enums/TextureCubeFace";
export { TextureFilterMode } from "./enums/TextureFilterMode";
export { TextureFormat } from "./enums/TextureFormat";
Expand Down
23 changes: 16 additions & 7 deletions packages/rhi-webgl/src/GLTexture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
TextureCubeFace,
TextureFilterMode,
TextureFormat,
RenderBufferDepthFormat,
TextureWrapMode
} from "@oasis-engine/core";
import { GLCompressedTextureInternalFormat, TextureFormatDetail } from "./type";
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down