Skip to content
Open
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
2 changes: 1 addition & 1 deletion docs/en/core/engine.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Below is a description of the [configuration](/apis/galacean/#WebGLEngineConfigu
| Configuration | Description |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
| canvas | Can be a canvas ID (`string`) or a canvas object (`HTMLCanvasElement | OffscreenCanvas`) |
| [graphicDeviceOptions](/apis/galacean/#WebGLGraphicDeviceOptions) | Configuration related to the graphics device, e.g., `webGLMode` can control WebGL1/2. Properties other than `webGLMode` will be passed to the context, more details can be found in [getContext parameters explanation](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext#parameters). |
| [graphicDeviceOptions](/apis/galacean/#WebGLGraphicDeviceOptions) | WebGL context creation attributes. |
| [colorSpace](/apis/galacean/#ColorSpace) | Color space, `ColorSpace.Gamma` or `ColorSpace.Linear`. |
| gltf | GLTF Loader configuration, `workerCount` is used to configure the number of workers for meshOpt: `{ meshOpt: { workerCount: number } }`. |
| ktx2Loader | KTX2 Loader configuration, `workerCount` is used to configure the number of workers for the ktx2 decoder: `{ priorityFormats: Array<KTX2TargetFormat>; transcoder: KTX2Transcoder; workerCount: number }`. If workerCount is greater than 0, worker threads will be created; if it equals 0, only the main thread will be used. |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/core/engine.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const engine = await WebGLEngine.create({
| 配置 | 解释 |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
| canvas | 可以是画布 ID( `string`) 或画布对象(`HTMLCanvasElement |OffscreenCanvas`)。 |
| [graphicDeviceOptions](/apis/galacean/#WebGLGraphicDeviceOptions) | 图形设备相关配置,比如 `webGLMode` 可以用 控制 WebGL1/2。除 `webGLMode` 外的属性将透传给上下文,详情可参考 [getContext 参数释义](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext#parameters)。 |
| [graphicDeviceOptions](/apis/galacean/#WebGLGraphicDeviceOptions) | 传给 WebGL 上下文的创建参数。 |
| [colorSpace](/apis/galacean/#ColorSpace) | 颜色空间, `ColorSpace.Gamma` 或 `ColorSpace.Linear`。 |
| gltf | gltf Loader 配置,`workerCount` 用来配置 meshOpt 的 worker 数量:`{ meshOpt: { workerCount: number } }` 。 |
| ktx2Loader | KTX2 Loader 配置,`workerCount` 用来配置 ktx2 解码器的worker 数量:`{ priorityFormats: Array<KTX2TargetFormat>; transcoder: KTX2Transcoder; workerCount: number }`。如果 workCount 大于 0,将会创建 worker 线程,等于 0 则只用主线程。 |
Expand Down
6 changes: 2 additions & 4 deletions e2e/case/camera-ssao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import {
PrimitiveMesh,
SkyBoxMaterial,
Vector3,
WebGLEngine,
WebGLMode
WebGLEngine
} from "@galacean/engine";
import { ShaderCompiler } from "@galacean/engine-shader-compiler";
import { initScreenshot, updateForE2E } from "./.mockForE2E";
Expand All @@ -27,8 +26,7 @@ Logger.enable();
// Create engine
WebGLEngine.create({
canvas: "canvas",
shaderCompiler: new ShaderCompiler(),
graphicDeviceOptions: { webGLMode: WebGLMode.WebGL1 }
shaderCompiler: new ShaderCompiler()
}).then((engine) => {
engine.canvas.setAutoResolution(2);

Expand Down
4 changes: 1 addition & 3 deletions e2e/case/multi-camera-no-clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ import {
PrimitiveMesh,
Scene,
TonemappingEffect,
WebGLEngine,
WebGLMode
WebGLEngine
} from "@galacean/engine";
import { initScreenshot, updateForE2E } from "./.mockForE2E";

Logger.enable();
WebGLEngine.create({
canvas: "canvas",
graphicDeviceOptions: {
webGLMode: WebGLMode.WebGL2,
antialias: false
}
}).then((engine) => {
Expand Down
8 changes: 2 additions & 6 deletions e2e/case/multi-scene-no-clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@ import {
PrimitiveMesh,
Scene,
TonemappingEffect,
WebGLEngine,
WebGLMode
WebGLEngine
} from "@galacean/engine";
import { initScreenshot, updateForE2E } from "./.mockForE2E";

Logger.enable();
WebGLEngine.create({
canvas: "canvas",
graphicDeviceOptions: {
webGLMode: WebGLMode.WebGL2
}
canvas: "canvas"
}).then((engine) => {
const firstCamera = initFirstScene(engine);
const secondCamera = initSecondScene(engine);
Expand Down
6 changes: 2 additions & 4 deletions e2e/case/particleRenderer-emissive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ import {
ParticleRenderer,
Texture2D,
Vector3,
WebGLEngine,
WebGLMode
WebGLEngine
} from "@galacean/engine";
import { initScreenshot, updateForE2E } from "./.mockForE2E";

// Create engine
WebGLEngine.create({
canvas: "canvas",
graphicDeviceOptions: { webGLMode: WebGLMode.Auto }
canvas: "canvas"
}).then((engine) => {
Logger.enable();

Expand Down
3 changes: 1 addition & 2 deletions e2e/case/particleRenderer-force.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import {
Scene,
Texture2D,
Vector3,
WebGLEngine,
WebGLMode
WebGLEngine
} from "@galacean/engine";
import { initScreenshot, updateForE2E } from "./.mockForE2E";

Expand Down
6 changes: 2 additions & 4 deletions e2e/case/particleRenderer-inherit-velocity-stretched.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ import {
ParticleRenderMode,
ParticleSimulationSpace,
Script,
WebGLEngine,
WebGLMode
WebGLEngine
} from "@galacean/engine";
import { initScreenshot, updateForE2E } from "./.mockForE2E";

WebGLEngine.create({
canvas: "canvas",
graphicDeviceOptions: { webGLMode: WebGLMode.WebGL2 }
canvas: "canvas"
}).then((engine) => {
const scene = engine.sceneManager.activeScene;
scene.background.solidColor = new Color(0.01, 0.01, 0.015, 1);
Expand Down
6 changes: 2 additions & 4 deletions e2e/case/particleRenderer-shape-mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ import {
ParticleRenderer,
Texture2D,
Vector3,
WebGLEngine,
WebGLMode
WebGLEngine
} from "@galacean/engine";
import { initScreenshot, updateForE2E } from "./.mockForE2E";

// Create engine
WebGLEngine.create({
canvas: "canvas",
graphicDeviceOptions: { webGLMode: WebGLMode.Auto }
canvas: "canvas"
}).then((engine) => {
Logger.enable();

Expand Down
6 changes: 2 additions & 4 deletions e2e/case/particleRenderer-sub-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ import {
ParticleSubEmitterType,
SphereShape,
Texture2D,
WebGLEngine,
WebGLMode
WebGLEngine
} from "@galacean/engine";
import { initScreenshot, updateForE2E } from "./.mockForE2E";

WebGLEngine.create({
canvas: "canvas",
graphicDeviceOptions: { webGLMode: WebGLMode.WebGL2 }
canvas: "canvas"
}).then((engine) => {
const scene = engine.sceneManager.activeScene;
const rootEntity = scene.createRootEntity();
Expand Down
6 changes: 2 additions & 4 deletions e2e/case/particleRenderer-velocity-orbital-constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ import {
ParticleSimulationSpace,
Texture2D,
Vector3,
WebGLEngine,
WebGLMode
WebGLEngine
} from "@galacean/engine";
import { initScreenshot, updateForE2E } from "./.mockForE2E";

WebGLEngine.create({
canvas: "canvas",
graphicDeviceOptions: { webGLMode: WebGLMode.WebGL2 }
canvas: "canvas"
}).then((engine) => {
const scene = engine.sceneManager.activeScene;
const rootEntity = scene.createRootEntity();
Expand Down
8 changes: 2 additions & 6 deletions e2e/case/shadow-transparent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@ import {
ShadowResolution,
ShadowType,
Vector3,
WebGLEngine,
WebGLMode
WebGLEngine
} from "@galacean/engine";
import { initScreenshot, updateForE2E } from "./.mockForE2E";
Logger.enable();

WebGLEngine.create({
canvas: "canvas",
graphicDeviceOptions: {
webGLMode: WebGLMode.WebGL2
}
canvas: "canvas"
}).then((engine) => {
const scene = engine.sceneManager.activeScene;
const rootEntity = scene.createRootEntity();
Expand Down
6 changes: 2 additions & 4 deletions examples/src/CSS-DOM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ import {
Logger,
Script,
Vector3,
WebGLEngine,
WebGLMode
WebGLEngine
} from "@galacean/engine";
import { OrbitControl } from "@galacean/engine-toolkit";

async function main() {
// Create engine
const htmlCanvas = document.getElementById("canvas") as HTMLCanvasElement;
const engine = await WebGLEngine.create({
canvas: htmlCanvas,
graphicDeviceOptions: { webGLMode: WebGLMode.Auto }
canvas: htmlCanvas
});

// Create root entity
Expand Down
4 changes: 1 addition & 3 deletions examples/src/gpu-instancing-auto-batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import {
ShaderProperty,
Vector3,
Vector4,
WebGLEngine,
WebGLMode
WebGLEngine
} from "@galacean/engine";
import { ShaderCompiler } from "@galacean/engine-shader-compiler";

Expand Down Expand Up @@ -122,7 +121,6 @@ const customInstanceShaderSource = `Shader "CustomInstanceShader" {
Logger.enable();
WebGLEngine.create({
canvas: "canvas",
graphicDeviceOptions: { webGLMode: WebGLMode.WebGL2 },
shaderCompiler
}).then(async (engine) => {
Shader.create(customInstanceShaderSource);
Expand Down
4 changes: 1 addition & 3 deletions examples/src/gpu-instancing-custom-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import {
ShaderProperty,
Vector3,
Vector4,
WebGLEngine,
WebGLMode
WebGLEngine
} from "@galacean/engine";
import { ShaderCompiler } from "@galacean/engine-shader-compiler";

Expand Down Expand Up @@ -107,7 +106,6 @@ const customInstanceShaderSource = `Shader "CustomInstanceShader" {

WebGLEngine.create({
canvas: "canvas",
graphicDeviceOptions: { webGLMode: WebGLMode.WebGL2 },
shaderCompiler
}).then((engine) => {
Shader.create(customInstanceShaderSource);
Expand Down
9 changes: 6 additions & 3 deletions packages/core/src/2d/atlas/FontAtlas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ export class FontAtlas extends ReferResource {
constructor(engine: Engine) {
super(engine);
this.isGCIgnored = true;
const format = engine._hardwareRenderer.isWebGL2 ? TextureFormat.R8 : TextureFormat.Alpha8;
const texture = new Texture2D(engine, 512, 512, format, false, false);
this.texture = this._createTexture(engine);
}

private _createTexture(engine: Engine): Texture2D {
const texture = new Texture2D(engine, 512, 512, TextureFormat.R8, false, false);
texture.filterMode = TextureFilterMode.Bilinear;
texture.isGCIgnored = true;
this.texture = texture;
return texture;
}

uploadCharTexture(charInfo: CharInfo): boolean {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/2d/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ export { OverflowMode } from "./enums/TextOverflow";
export * from "./sprite/index";
export * from "./text/index";
export type { ITextRenderer } from "./text/ITextRenderer";
/** @internal */
export { FontAtlas } from "./atlas/FontAtlas";
41 changes: 22 additions & 19 deletions packages/core/src/BasicResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,25 +183,7 @@ export class BasicResources {
true
);

const isWebGL2 = engine._hardwareRenderer.isWebGL2;
if (isWebGL2) {
this.whiteTexture2DArray = this._create1x1Texture(
engine,
TextureType.Texture2DArray,
TextureFormat.R8G8B8A8,
whitePixel,
true
);

const whitePixel32 = new Uint32Array([255, 255, 255, 255]);
this.uintWhiteTexture2D = this._create1x1Texture(
engine,
TextureType.Texture2D,
TextureFormat.R32G32B32A32_UInt,
whitePixel32,
false
);
}
[this.whiteTexture2DArray, this.uintWhiteTexture2D] = this._createDefaultArrayTextures(engine, whitePixel);

this.spriteDefaultMaterial = this._create2DMaterial(engine, shaders.sprite);
this.textDefaultMaterial = this._create2DMaterial(engine, shaders.text);
Expand All @@ -211,6 +193,27 @@ export class BasicResources {
this.particleMagentaMaterial = this._createMagentaMaterial(engine, shaders.particle);
}

private _createDefaultArrayTextures(engine: Engine, whitePixel: Uint8Array): [Texture2DArray, Texture2D] {
const arrayTexture = this._create1x1Texture<Texture2DArray>(
engine,
TextureType.Texture2DArray,
TextureFormat.R8G8B8A8,
whitePixel,
true
);

const whitePixel32 = new Uint32Array([255, 255, 255, 255]);
const uintTexture = this._create1x1Texture<Texture2D>(
engine,
TextureType.Texture2D,
TextureFormat.R32G32B32A32_UInt,
whitePixel32,
false
);

return [arrayTexture, uintTexture];
}

/**
* @internal
*/
Expand Down
14 changes: 2 additions & 12 deletions packages/core/src/Camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { BasicRenderPipeline } from "./RenderPipeline/BasicRenderPipeline";
import { Transform } from "./Transform";
import { UpdateFlagManager } from "./UpdateFlagManager";
import { VirtualCamera } from "./VirtualCamera";
import { GLCapabilityType, Logger } from "./base";
import { Logger } from "./base";
import { ignoreClone } from "./clone/CloneDecorators";
import { AntiAliasing } from "./enums/AntiAliasing";
import { CameraClearFlags } from "./enums/CameraClearFlags";
Expand Down Expand Up @@ -378,12 +378,6 @@ export class Camera extends Component {

set enableHDR(value: boolean) {
if (this.enableHDR !== value) {
const rhi = this.engine._hardwareRenderer;
const supportHDR = rhi.isWebGL2 || rhi.canIUse(GLCapabilityType.textureHalfFloat);
if (value && !supportHDR) {
Logger.warn("Can't enable HDR in this device.");
return;
}
this._enableHDR = value;
}
}
Expand Down Expand Up @@ -659,10 +653,6 @@ export class Camera extends Component {
this._globalShaderMacro
);

if (mipLevel > 0 && !engine._hardwareRenderer.isWebGL2) {
mipLevel = 0;
Logger.error("mipLevel only take effect in WebGL2.0");
}
let ignoreClearFlags: CameraClearFlags | undefined;
if (this._cameraType !== CameraType.Normal && !this._renderTarget) {
ignoreClearFlags = engine.xrManager._getCameraIgnoreClearFlags(this._cameraType);
Expand Down Expand Up @@ -769,7 +759,7 @@ export class Camera extends Component {
*/
_getInternalColorTextureFormat(): TextureFormat {
return this._enableHDR
? this.engine._hardwareRenderer.isWebGL2 && !this.isAlphaOutputRequired
? !this.isAlphaOutputRequired
? TextureFormat.R11G11B10_UFloat
: TextureFormat.R16G16B16A16
: TextureFormat.R8G8B8A8;
Expand Down
Loading
Loading