mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 15:42:39 +08:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3aeb193d42 | |||
| c4e4790ee6 | |||
| 143af30cf2 | |||
| d6ff23fed4 | |||
| 84e8d4ebf7 | |||
| f2b9936033 | |||
| 129eb437ad | |||
| c58c893334 | |||
| ab982aec68 | |||
| 2d2bbe6731 | |||
| 187387b03f | |||
| 661253a521 | |||
| b6d0f02e88 | |||
| dd1b155d3a | |||
| df96ee85f3 | |||
| 708a343ce8 | |||
| 393203c2f8 | |||
| f3d11f017b | |||
| 09c201017c | |||
| ce6107d930 | |||
| ab8792686b |
+10
-2
@@ -470,7 +470,15 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"test": "context.buildTimeConstants.SPINE_3_8",
|
||||
"test": "context.buildTimeConstants.SPINE_3_8 && context.buildTimeConstants.SPINE_4_2",
|
||||
"isVirtualModule": false,
|
||||
"overrides": {
|
||||
"cocos/spine/lib/spine-version.ts": "cocos/spine/lib/spine-version-dynamic.ts",
|
||||
"cocos/spine/lib/spine-instantiate.ts": "cocos/spine/lib/spine-instantiate-dynamic.ts"
|
||||
}
|
||||
},
|
||||
{
|
||||
"test": "context.buildTimeConstants.SPINE_3_8 && !context.buildTimeConstants.SPINE_4_2",
|
||||
"isVirtualModule": false,
|
||||
"overrides": {
|
||||
"cocos/spine/lib/spine-version.ts": "cocos/spine/lib/spine-version-3.8.ts",
|
||||
@@ -478,7 +486,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"test": "context.buildTimeConstants.SPINE_4_2",
|
||||
"test": "context.buildTimeConstants.SPINE_4_2 && !context.buildTimeConstants.SPINE_3_8",
|
||||
"isVirtualModule": false,
|
||||
"overrides": {
|
||||
"cocos/spine/lib/spine-version.ts": "cocos/spine/lib/spine-version-4.2.ts",
|
||||
|
||||
@@ -637,13 +637,13 @@ export class Graphics extends UIRenderer {
|
||||
const vertexBuffer = gfxDevice.createBuffer(new BufferInfo(
|
||||
BufferUsageBit.VERTEX | BufferUsageBit.TRANSFER_DST,
|
||||
MemoryUsageBit.DEVICE,
|
||||
65535 * stride,
|
||||
65536 * stride, // Uint16 can address 65536 vertices (indices 0–65535)
|
||||
stride,
|
||||
));
|
||||
const indexBuffer = gfxDevice.createBuffer(new BufferInfo(
|
||||
BufferUsageBit.INDEX | BufferUsageBit.TRANSFER_DST,
|
||||
MemoryUsageBit.DEVICE,
|
||||
65535 * Uint16Array.BYTES_PER_ELEMENT * 2,
|
||||
65536 * Uint16Array.BYTES_PER_ELEMENT * 2, // Uint16 can address 65536 vertices (indices 0–65535)
|
||||
Uint16Array.BYTES_PER_ELEMENT,
|
||||
));
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
*/
|
||||
|
||||
import { JSB } from 'internal:constants';
|
||||
import { Device, BufferUsageBit, MemoryUsageBit, Attribute, Buffer, BufferInfo, InputAssembler, InputAssemblerInfo, Feature, API } from '../../gfx';
|
||||
import { Device, BufferUsageBit, MemoryUsageBit, Attribute, Buffer, BufferInfo, InputAssembler, InputAssemblerInfo, Feature } from '../../gfx';
|
||||
import { getAttributeStride } from './vertex-format';
|
||||
import { sys, getError, warnID, assertIsTrue } from '../../core';
|
||||
import { NativeUIMeshBuffer } from './native-2d';
|
||||
@@ -251,11 +251,10 @@ export class MeshBuffer {
|
||||
|
||||
this.floatsPerVertex = getAttributeStride(attrs) >> 2;
|
||||
|
||||
var vDataCountLimit = 65536; // 2^16 - 1
|
||||
const glApi = device.gfxAPI;
|
||||
if (glApi === API.WEBGPU || glApi === API.WEBGL2 || glApi === API.WEBGL && device.hasFeature(Feature.ELEMENT_INDEX_UINT)) {
|
||||
vDataCountLimit = 4294967295; // 2^32 - 1
|
||||
}
|
||||
// Use the GPU's actual reported capability to determine max addressable vertex count.
|
||||
// Feature.ELEMENT_INDEX_UINT is set to true in: WebGL2, WebGPU, Vulkan, Metal, GLES3, GLES2+ext.
|
||||
// vDataCountLimit is a vertex COUNT limit (max index value + 1), not the max index value itself.
|
||||
const vDataCountLimit = device.hasFeature(Feature.ELEMENT_INDEX_UINT) ? 4294967296 : 65536; // Uint32 or Uint16 can address 2^32 or 2^16 vertices (indices 0–2^32-1 or 0–2^16-1)
|
||||
assertIsTrue(this._initVDataCount / this._floatsPerVertex < vDataCountLimit, getError(9005));
|
||||
|
||||
if (!this.vData || !this.iData) {
|
||||
|
||||
@@ -634,7 +634,7 @@ export class MeshRenderData extends BaseRenderData {
|
||||
const newVBytes = this._byteLength + vertexCount * this.stride;
|
||||
const newICount = this.indexCount + indexCount;
|
||||
|
||||
if (vertexCount + this.vertexCount > 65535) {
|
||||
if (vertexCount + this.vertexCount > 65536) { // Uint16 can address 65536 vertices (indices 0–65535)
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -697,13 +697,13 @@ export class MeshRenderData extends BaseRenderData {
|
||||
if (this._byteLength > vertexBuffer.size) {
|
||||
vertexBuffer.resize(this._byteLength);
|
||||
}
|
||||
vertexBuffer.update(verticesData);
|
||||
vertexBuffer.update(verticesData.buffer as ArrayBuffer, this._byteLength);
|
||||
|
||||
const indexBytes = indexCount << 1;
|
||||
if (indexBytes > this._indexBuffer.size) {
|
||||
this._indexBuffer.resize(indexBytes);
|
||||
}
|
||||
this._indexBuffer.update(indicesData);
|
||||
this._indexBuffer.update(indicesData.buffer as ArrayBuffer, indexBytes);
|
||||
}
|
||||
|
||||
public freeIAPool (): void {
|
||||
|
||||
@@ -165,6 +165,10 @@ export class StaticVBAccessor extends BufferAccessor {
|
||||
errorID(9004, byteLength);
|
||||
return null;
|
||||
}
|
||||
if (vertexCount > 65536) { // Vertex count must less than 65536 for index is uint16 (0 to 65535)
|
||||
errorID(9004, byteLength);
|
||||
return null;
|
||||
}
|
||||
let buf: MeshBuffer = null!;
|
||||
let freeList: IFreeEntry[];
|
||||
let bid = 0;
|
||||
@@ -176,9 +180,11 @@ export class StaticVBAccessor extends BufferAccessor {
|
||||
freeList = this._freeLists[i];
|
||||
// Loop entries
|
||||
for (let e = 0; e < freeList.length; ++e) {
|
||||
const freeEntry = freeList[e];
|
||||
const vertexOffset: number = freeEntry.offset / this.vertexFormatBytes;
|
||||
// Found suitable free entry
|
||||
if (freeList[e].length >= byteLength) {
|
||||
entry = freeList[e];
|
||||
if (freeEntry.length >= byteLength && vertexOffset + (vertexCount - 1) <= 65535) {
|
||||
entry = freeEntry;
|
||||
bid = i;
|
||||
eid = e;
|
||||
break;
|
||||
|
||||
@@ -508,7 +508,7 @@ export class Mesh extends Asset {
|
||||
let dstSize = idxView.length;
|
||||
if (dstStride === 4 && !gfxDevice.hasFeature(Feature.ELEMENT_INDEX_UINT)) {
|
||||
const vertexCount = this._struct.vertexBundles[prim.vertexBundelIndices[0]].view.count;
|
||||
if (vertexCount >= 65536) {
|
||||
if (vertexCount > 65536) { // Uint16 can address 65536 vertices (indices 0–65535)
|
||||
warnID(10001, vertexCount, 65536);
|
||||
continue; // Ignore this primitive
|
||||
} else {
|
||||
|
||||
@@ -185,7 +185,7 @@ export class WebGL2Swapchain extends Swapchain {
|
||||
self._canvas = info.windowHandle;
|
||||
|
||||
self._webGL2ContextLostHandler = self._onWebGLContextLost.bind(self);
|
||||
self._canvas.addEventListener(eventWebGLContextLost, self._onWebGLContextLost);
|
||||
self._canvas.addEventListener(eventWebGLContextLost, self._webGL2ContextLostHandler);
|
||||
|
||||
const { instance } = WebGL2DeviceManager;
|
||||
const { gl, capabilities } = instance;
|
||||
|
||||
@@ -233,8 +233,8 @@ export class ParticleSystem extends ModelRenderer {
|
||||
public startLifetime = new CurveRange();
|
||||
|
||||
/**
|
||||
* @en Particle system duration time.
|
||||
* @zh 粒子系统运行时间。
|
||||
* @en Particle system emitter duration time.
|
||||
* @zh 粒子系统发射器运行时间。
|
||||
*/
|
||||
@serializable
|
||||
@displayOrder(0)
|
||||
|
||||
@@ -779,7 +779,8 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas
|
||||
|
||||
const matIns: MaterialInstance | null = ps.getMaterialInstance(1);
|
||||
if (matIns === null || matIns === undefined) {
|
||||
ps.setSharedMaterial(mat, 1); // set material[1] as trail material for ui-mesh-renderer to use
|
||||
ps.setSharedMaterial(mat.parent, 1); // set material[1] as trail material for ui-mesh-renderer to use
|
||||
ps.setMaterialInstance(mat, 1);
|
||||
}
|
||||
|
||||
const texture = mat.getProperty('mainTexture', 0) as Texture2D | null;
|
||||
|
||||
@@ -377,7 +377,10 @@ export default class TrailModule {
|
||||
if (this.lifeTime.getMax() < 1.0) {
|
||||
warnID(6036);
|
||||
}
|
||||
this._trailNum = Math.ceil(psTime * Math.ceil(this.lifeTime.getMax()) * 60 * (psRate * duration + burstCount));
|
||||
let pCount: number = psRate * duration; // potential particle count
|
||||
pCount = ps.prewarm ? pCount * 2 : pCount; // if prewarm we need double space
|
||||
pCount = pCount > ps.capacity ? ps.capacity : pCount; // max particle count is less/equal than capacity
|
||||
this._trailNum = Math.ceil(psTime * Math.ceil(this.lifeTime.getMax()) * 60 * (pCount + burstCount));
|
||||
this._trailSegments = new Pool(
|
||||
(): TrailSegment => new TrailSegment(10),
|
||||
Math.ceil(psRate * duration),
|
||||
|
||||
@@ -126,7 +126,7 @@ export class RenderAdditiveLightQueue {
|
||||
private declare _lightBuffer: Buffer;
|
||||
private declare _firstLightBufferView: Buffer;
|
||||
private declare _lightBufferData: Float32Array;
|
||||
private _instancedQueues: RenderInstancedQueue[] = [];
|
||||
private _instancedQueues: (RenderInstancedQueue | undefined)[] = [];
|
||||
private _lightMeterScale = 10000.0;
|
||||
|
||||
constructor (pipeline: PipelineRuntime) {
|
||||
@@ -151,7 +151,9 @@ export class RenderAdditiveLightQueue {
|
||||
|
||||
public clear (): void {
|
||||
this._instancedQueues.forEach((instancedQueue) => {
|
||||
instancedQueue.clear();
|
||||
if (instancedQueue) {
|
||||
instancedQueue.clear();
|
||||
}
|
||||
});
|
||||
this._instancedQueues.length = 0;
|
||||
|
||||
@@ -196,7 +198,7 @@ export class RenderAdditiveLightQueue {
|
||||
|
||||
this._lightCulling(model, validPunctualLights);
|
||||
|
||||
if (!_lightIndices.length && validPunctualLights.length > 0) { continue; }
|
||||
if (!_lightIndices.length) { continue; }
|
||||
|
||||
for (let j = 0; j < subModels.length; j++) {
|
||||
const lightPassIdx = _lightPassIndices[j];
|
||||
@@ -219,15 +221,14 @@ export class RenderAdditiveLightQueue {
|
||||
public gatherLightPasses (camera: Camera, cmdBuff: CommandBuffer, passLayout = 'default'): void {
|
||||
this.clear();
|
||||
|
||||
const validPunctualLights = this._pipeline.pipelineSceneData.validPunctualLights;
|
||||
if (!validPunctualLights.length) {
|
||||
this._bindForwardAddLight(validPunctualLights, passLayout);
|
||||
return;
|
||||
}
|
||||
|
||||
this._updateUBOs(camera, cmdBuff);
|
||||
this._updateLightDescriptorSet(camera, cmdBuff);
|
||||
|
||||
const validPunctualLights = this._pipeline.pipelineSceneData.validPunctualLights;
|
||||
if (!validPunctualLights.length) { return; }
|
||||
|
||||
this._bindForwardAddLight(validPunctualLights, passLayout);
|
||||
|
||||
// only for instanced and batched, no light culling applied
|
||||
for (let l = 0; l < validPunctualLights.length; l++) {
|
||||
const light = validPunctualLights[l];
|
||||
@@ -236,17 +237,21 @@ export class RenderAdditiveLightQueue {
|
||||
}
|
||||
|
||||
this._instancedQueues.forEach((instancedQueue) => {
|
||||
instancedQueue.uploadBuffers(cmdBuff);
|
||||
if (instancedQueue) {
|
||||
instancedQueue.uploadBuffers(cmdBuff);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public recordCommandBuffer (device: Device, renderPass: RenderPass, cmdBuff: CommandBuffer): void {
|
||||
const globalDSManager: GlobalDSManager = this._pipeline.globalDSManager;
|
||||
for (let j = 0; j < this._instancedQueues.length; ++j) {
|
||||
const queue = this._instancedQueues[j];
|
||||
if (!queue) { continue; }
|
||||
const light = this._instancedLightPassPool.lights[j];
|
||||
_dynamicOffsets[0] = this._instancedLightPassPool.dynamicOffsets[j];
|
||||
const descriptorSet = globalDSManager.getOrCreateDescriptorSet(light);
|
||||
this._instancedQueues[j].recordCommandBuffer(device, renderPass, cmdBuff, descriptorSet, _dynamicOffsets);
|
||||
queue.recordCommandBuffer(device, renderPass, cmdBuff, descriptorSet, _dynamicOffsets);
|
||||
}
|
||||
|
||||
for (let i = 0; i < this._lightPasses.length; i++) {
|
||||
@@ -318,11 +323,14 @@ export class RenderAdditiveLightQueue {
|
||||
if (((visibility & model.node.layer) === model.node.layer)) {
|
||||
switch (batchingScheme) {
|
||||
case BatchingSchemes.INSTANCING: {
|
||||
const buffer = pass.getInstancedBuffer(l);
|
||||
const buffer = pass.getInstancedBuffer(lightIdx);
|
||||
buffer.merge(subModel, lightPassIdx);
|
||||
buffer.dynamicOffsets[0] = this._lightBufferStride;
|
||||
if (!this._instancedQueues[l]) { this._instancedQueues[l] = new RenderInstancedQueue(); }
|
||||
this._instancedQueues[l].queue.add(buffer);
|
||||
buffer.dynamicOffsets[0] = this._lightBufferStride * lightIdx;
|
||||
if (this._instancedQueues.length <= lightIdx || !this._instancedQueues[lightIdx]) {
|
||||
this._instancedQueues.length = lightIdx + 1;
|
||||
this._instancedQueues[lightIdx] = new RenderInstancedQueue();
|
||||
}
|
||||
this._instancedQueues[lightIdx]!.queue.add(buffer);
|
||||
} break;
|
||||
default:
|
||||
lp!.lights.push(light);
|
||||
@@ -370,9 +378,6 @@ export class RenderAdditiveLightQueue {
|
||||
this._shadowUBO[UBOShadowEnum.SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET + 1] = packing;
|
||||
this._shadowUBO[UBOShadowEnum.SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET + 2] = 0.0;
|
||||
this._shadowUBO[UBOShadowEnum.SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET + 3] = 0.0;
|
||||
|
||||
// Reserve sphere light shadow interface
|
||||
Color.toArray(this._shadowUBO, shadowInfo.shadowColor, UBOShadowEnum.SHADOW_COLOR_OFFSET);
|
||||
break;
|
||||
}
|
||||
case LightType.SPOT: {
|
||||
@@ -437,8 +442,6 @@ export class RenderAdditiveLightQueue {
|
||||
this._shadowUBO[UBOShadowEnum.SHADOW_PROJ_INFO_OFFSET + 2] = 1.0 / matShadowProj.m00;
|
||||
this._shadowUBO[UBOShadowEnum.SHADOW_PROJ_INFO_OFFSET + 3] = 1.0 / matShadowProj.m05;
|
||||
|
||||
Color.toArray(this._shadowUBO, shadowInfo.shadowColor, UBOShadowEnum.SHADOW_COLOR_OFFSET);
|
||||
|
||||
// Spot light sampler binding
|
||||
if (shadowFrameBufferMap.has(light)) {
|
||||
const texture = shadowFrameBufferMap.get(light)?.colorTextures[0];
|
||||
@@ -463,15 +466,15 @@ export class RenderAdditiveLightQueue {
|
||||
this._shadowUBO[UBOShadowEnum.SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET + 1] = packing;
|
||||
this._shadowUBO[UBOShadowEnum.SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET + 2] = 0.0;
|
||||
this._shadowUBO[UBOShadowEnum.SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET + 3] = 0.0;
|
||||
|
||||
// Reserve point light shadow interface
|
||||
Color.toArray(this._shadowUBO, shadowInfo.shadowColor, UBOShadowEnum.SHADOW_COLOR_OFFSET);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
}
|
||||
globalDSManager.update();
|
||||
cmdBuff.updateBuffer(descriptorSet.getBuffer(UBOShadow.BINDING)!, this._shadowUBO);
|
||||
Color.toArray(this._shadowUBO, shadowInfo.shadowColor, UBOShadowEnum.SHADOW_COLOR_OFFSET);
|
||||
|
||||
descriptorSet.update();
|
||||
|
||||
cmdBuff.updateBuffer(descriptorSet.getBuffer(UBOShadow.BINDING)!, this._shadowUBO.buffer, this._shadowUBO.byteLength);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -627,6 +630,6 @@ export class RenderAdditiveLightQueue {
|
||||
}
|
||||
}
|
||||
|
||||
cmdBuff.updateBuffer(this._lightBuffer, this._lightBufferData);
|
||||
cmdBuff.updateBuffer(this._lightBuffer, this._lightBufferData.buffer as ArrayBuffer, this._lightBufferData.byteLength);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Runtime-selectable spine instantiation. Used only when both spine-3.8 and spine-4.2 are compiled into
|
||||
// the engine (editor/preview): cc.config.json's moduleOverrides then replaces spine-instantiate.ts with
|
||||
// this file. Unlike the fixed-version files (spine-instantiate-3.8.ts / -4.2.ts), both the 3.8 and 4.2
|
||||
// external references are kept here (so both wasm/asm binaries are bundled), and the matching one is
|
||||
// executed at runtime according to the selected version.
|
||||
// The version comes from the preview boot (game-boot.js / engine-bootstrap.ts), which reads it from
|
||||
// cocos.config.json before engine init and writes globalThis._CC_SPINE_VERSION.
|
||||
|
||||
import { ensureWasmModuleReady } from 'pal/wasm';
|
||||
import { error } from '../../core';
|
||||
import { shouldUseWasmModule, initWasm, initAsmJS } from './spine-wasm-utils';
|
||||
// Import setSpineVersion through the overridden './spine-version' (= spine-version-dynamic) so it is the
|
||||
// same module instance whose SPINE_VERSION live binding is read by the shared spine-define.ts.
|
||||
import { setSpineVersion } from './spine-version';
|
||||
|
||||
function getSelectedSpineVersion (): string {
|
||||
const v = (globalThis as any)._CC_SPINE_VERSION;
|
||||
return v === '4.2' ? '4.2' : '3.8';
|
||||
}
|
||||
|
||||
export function waitForSpineWasmInstantiation (): Promise<void> {
|
||||
const errorReport = (msg: any): void => { error(msg); };
|
||||
// The version must be set before wasm instantiation and before spine-define patches prototypes.
|
||||
const version = getSelectedSpineVersion();
|
||||
setSpineVersion(version);
|
||||
return ensureWasmModuleReady().then((): Promise<void> => {
|
||||
//We should use static code here, import operation will cause file copy to cache folder.
|
||||
if (version === '4.2') {
|
||||
if (shouldUseWasmModule()) {
|
||||
return Promise.all([
|
||||
import('external:emscripten/spine/4.2/spine.wasm.js'),
|
||||
import('external:emscripten/spine/4.2/spine.wasm'),
|
||||
]).then(([
|
||||
{ default: wasmFactory },
|
||||
{ default: spineWasmUrl },
|
||||
]) => initWasm(wasmFactory, spineWasmUrl));
|
||||
} else {
|
||||
return Promise.all([
|
||||
import('external:emscripten/spine/4.2/spine.asm.js'),
|
||||
import('external:emscripten/spine/4.2/spine.js.mem'),
|
||||
]).then(([
|
||||
{ default: asmFactory },
|
||||
{ default: asmJsMemUrl },
|
||||
]) => initAsmJS(asmFactory, asmJsMemUrl));
|
||||
}
|
||||
} else {
|
||||
if (shouldUseWasmModule()) {
|
||||
return Promise.all([
|
||||
import('external:emscripten/spine/3.8/spine.wasm.js'),
|
||||
import('external:emscripten/spine/3.8/spine.wasm'),
|
||||
]).then(([
|
||||
{ default: wasmFactory },
|
||||
{ default: spineWasmUrl },
|
||||
]) => initWasm(wasmFactory, spineWasmUrl));
|
||||
} else {
|
||||
return Promise.all([
|
||||
import('external:emscripten/spine/3.8/spine.asm.js'),
|
||||
import('external:emscripten/spine/3.8/spine.js.mem'),
|
||||
]).then(([
|
||||
{ default: asmFactory },
|
||||
{ default: asmJsMemUrl },
|
||||
]) => initAsmJS(asmFactory, asmJsMemUrl));
|
||||
}
|
||||
}
|
||||
}).catch(errorReport);
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Runtime-selectable spine version. Used only when both spine-3.8 and spine-4.2 are compiled into the
|
||||
// engine (editor/preview): cc.config.json's moduleOverrides then replaces spine-version.ts with this file.
|
||||
// Unlike the fixed-version files (spine-version-3.8.ts / -4.2.ts), SPINE_VERSION is a mutable `let`
|
||||
// (a live ES binding), so the shared layer (spine-define.ts / skeleton.ts) reads the runtime value and
|
||||
// keeps both `SPINE_VERSION === '3.8' / '4.2'` branches instead of tree-shaking to a single one.
|
||||
// The version is set by spine-instantiate-dynamic.ts before instantiation, sourced from the host-provided
|
||||
// globalThis._CC_SPINE_VERSION (injected by the preview boot from cocos.config.json).
|
||||
import { DataInput, SkeletonBinary } from './spine-binary';
|
||||
import { BUILD } from 'internal:constants';
|
||||
|
||||
// Typed as string so comparisons in the shared layer against the other version literal are not flagged by TS.
|
||||
export let SPINE_VERSION: string = '3.8';
|
||||
|
||||
/**
|
||||
* Sets the current spine version. Must be called before spine wasm instantiation and before spine-define runs.
|
||||
*/
|
||||
export function setSpineVersion (version: string): void {
|
||||
SPINE_VERSION = version === '4.2' ? '4.2' : '3.8';
|
||||
}
|
||||
|
||||
function isVersionCompatible (version: string | null): boolean {
|
||||
if (!BUILD) {
|
||||
if (SPINE_VERSION === '3.8') {
|
||||
if (!version || version === '3.8.75' || !version.startsWith('3.8.')) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!version || !version.startsWith('4.2.')) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Used only by editor.
|
||||
*/
|
||||
export function isBinaryCompatible (buffer: Uint8Array): boolean {
|
||||
if (!BUILD) {
|
||||
const input = new DataInput(buffer);
|
||||
// The binary hash header differs between versions: 3.8 uses one string, 4.2 uses two ints.
|
||||
if (SPINE_VERSION === '3.8') {
|
||||
SkeletonBinary.readString(input); // read hash
|
||||
} else {
|
||||
SkeletonBinary.readInt(input); // read hash
|
||||
SkeletonBinary.readInt(input); // read hash
|
||||
}
|
||||
const version = SkeletonBinary.readString(input);
|
||||
|
||||
return isVersionCompatible(version);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Used only by editor.
|
||||
*/
|
||||
export function isJsonCompatible (json: JSON): boolean {
|
||||
if (!BUILD) {
|
||||
return isVersionCompatible(json['skeleton']['spine']);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -24,6 +24,12 @@
|
||||
|
||||
export const SPINE_VERSION = '3.8';
|
||||
|
||||
// Placeholder so spine-instantiate-dynamic.ts can import setSpineVersion from './spine-version' and type-check.
|
||||
// When building the engine with runtime-selectable spine, moduleOverrides replaces this file with
|
||||
// spine-version-dynamic.ts (the real implementation). In fixed single-version builds (spine-3.8 / spine-4.2)
|
||||
// spine-instantiate-dynamic is not used, so this no-op is never called.
|
||||
export function setSpineVersion (version: string): void {}
|
||||
|
||||
export function isBinaryCompatible (buffer: Uint8Array): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -878,7 +878,7 @@ export class TiledLayer extends UIRenderer {
|
||||
const axis = this._staggerAxis;
|
||||
|
||||
switch (this._layerOrientation) {
|
||||
// left top to right dowm
|
||||
// left top to right down
|
||||
case Orientation.ORTHO:
|
||||
col = Math.floor(x / maptw);
|
||||
row = Math.floor(y / mapth);
|
||||
@@ -889,7 +889,7 @@ export class TiledLayer extends UIRenderer {
|
||||
col = Math.floor(x / maptw2);
|
||||
row = Math.floor(y / mapth2);
|
||||
break;
|
||||
// left top to right dowm
|
||||
// left top to right down
|
||||
case Orientation.HEX:
|
||||
if (axis === StaggerAxis.STAGGERAXIS_Y) {
|
||||
row = Math.floor(y / (mapth - this._diffY1!));
|
||||
@@ -1017,7 +1017,7 @@ export class TiledLayer extends UIRenderer {
|
||||
}
|
||||
|
||||
switch (layerOrientation) {
|
||||
// left top to right dowm
|
||||
// left top to right down
|
||||
case Orientation.ORTHO:
|
||||
cullingCol = col;
|
||||
cullingRow = rows - row - 1;
|
||||
@@ -1039,7 +1039,7 @@ export class TiledLayer extends UIRenderer {
|
||||
left = maptw2 * cullingCol;
|
||||
bottom = mapth2 * cullingRow;
|
||||
break;
|
||||
// left top to right dowm
|
||||
// left top to right down
|
||||
case Orientation.HEX:
|
||||
diffX2 = (axis! === StaggerAxis.STAGGERAXIS_Y && row % 2 === 1) ? maptw2 * odd_even! : 0;
|
||||
diffY2 = (axis! === StaggerAxis.STAGGERAXIS_X && col % 2 === 1) ? mapth2 * -odd_even! : 0;
|
||||
|
||||
@@ -10,7 +10,7 @@ vec3 HDRToLDR(vec3 color)
|
||||
#endif
|
||||
{
|
||||
// linear exposure has already applied to light intensity
|
||||
#if CC_TONE_MAPPING_TYPE == HDR_TONE_MAPPING_ACES
|
||||
#if CC_TONE_MAPPING_TYPE == TONE_MAPPING_ACES
|
||||
color.rgb = ACESToneMap(color.rgb);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -79,8 +79,12 @@ vec4 saturate(vec4 value) { return clamp(value, vec4(0.0), vec4(1.0)); }
|
||||
#define IS_RANGED_DIRECTIONAL_LIGHT(light_type) equalf_lowp(light_type, LIGHT_TYPE_RANGED_DIRECTIONAL)
|
||||
|
||||
// CC_TONE_MAPPING_TYPE Values
|
||||
#define TONE_MAPPING_ACES 0
|
||||
#define TONE_MAPPING_LINEAR 1
|
||||
#ifndef TONE_MAPPING_ACES
|
||||
#define TONE_MAPPING_ACES 0
|
||||
#endif
|
||||
#ifndef TONE_MAPPING_LINEAR
|
||||
#define TONE_MAPPING_LINEAR 1
|
||||
#endif
|
||||
|
||||
// Material
|
||||
#define SURFACES_MAX_TRANSMIT_DEPTH_VALUE 999999.0
|
||||
|
||||
@@ -7,7 +7,7 @@ vec4 CCFragOutput (vec4 color) {
|
||||
#if CC_USE_RGBE_OUTPUT
|
||||
color = packRGBE(color.rgb);
|
||||
#elif !CC_USE_FLOAT_OUTPUT
|
||||
#if CC_USE_HDR && CC_TONE_MAPPING_TYPE == HDR_TONE_MAPPING_ACES
|
||||
#if CC_USE_HDR && CC_TONE_MAPPING_TYPE == TONE_MAPPING_ACES
|
||||
color.rgb = ACESToneMap(color.rgb);
|
||||
#endif
|
||||
color.rgb = LinearToSRGB(color.rgb);
|
||||
|
||||
@@ -70,7 +70,9 @@ CCProgram smaa-edge-fs %{
|
||||
vec3 ToLDR(vec3 color) {
|
||||
#if CC_USE_HDR
|
||||
color *= cc_exposure.x * FP_SCALE_INV;
|
||||
color = ACESToneMap(color);
|
||||
#if CC_TONE_MAPPING_TYPE == TONE_MAPPING_ACES
|
||||
color = ACESToneMap(color);
|
||||
#endif
|
||||
color = LinearToSRGB(color);
|
||||
#endif
|
||||
return color;
|
||||
|
||||
@@ -55,7 +55,9 @@ CCProgram tonemap-fs %{
|
||||
vec3 ToLDR(vec3 color) {
|
||||
#if CC_USE_HDR
|
||||
color *= cc_exposure.x * FP_SCALE_INV;
|
||||
color = ACESToneMap(color);
|
||||
#if CC_TONE_MAPPING_TYPE == TONE_MAPPING_ACES
|
||||
color = ACESToneMap(color);
|
||||
#endif
|
||||
color = LinearToSRGB(color);
|
||||
#endif
|
||||
return color;
|
||||
|
||||
@@ -58,13 +58,13 @@ void UIModelProxy::activeSubModels() {
|
||||
auto* vertexBuffer = _device->createBuffer({
|
||||
gfx::BufferUsageBit::VERTEX | gfx::BufferUsageBit::TRANSFER_DST,
|
||||
gfx::MemoryUsageBit::DEVICE,
|
||||
65535 * _stride,
|
||||
65536 * _stride, // Uint16 can address 65536 vertices (indices 0–65535)
|
||||
_stride,
|
||||
});
|
||||
auto* indexBuffer = _device->createBuffer({
|
||||
gfx::BufferUsageBit::INDEX | gfx::BufferUsageBit::TRANSFER_DST,
|
||||
gfx::MemoryUsageBit::DEVICE,
|
||||
65535 * sizeof(uint16_t) * 2,
|
||||
65536 * sizeof(uint16_t) * 2, // Uint16 can address 65536 vertices (indices 0–65535)
|
||||
sizeof(uint16_t),
|
||||
});
|
||||
gfx::BufferList vbReference;
|
||||
|
||||
@@ -530,7 +530,7 @@ void Mesh::initialize() {
|
||||
if (dstStride == 4) {
|
||||
uint32_t vertexCount = _struct.vertexBundles[prim.vertexBundelIndices[0]].view.count;
|
||||
#if CC_OPTIMIZE_MESH_DATA
|
||||
if (vertexCount < 65536) {
|
||||
if (vertexCount <= 65536) { // Uint16 can address 65536 vertices (indices 0–65535)
|
||||
dstStride >>= 1; // Reduce to short.
|
||||
dstSize >>= 1;
|
||||
} else if (!gfxDevice->hasFeature(gfx::Feature::ELEMENT_INDEX_UINT)) {
|
||||
@@ -538,7 +538,7 @@ void Mesh::initialize() {
|
||||
}
|
||||
#else
|
||||
if (!gfxDevice->hasFeature(gfx::Feature::ELEMENT_INDEX_UINT)) {
|
||||
if (vertexCount >= 65536) {
|
||||
if (vertexCount > 65536) { // Uint16 can address 65536 vertices (indices 0–65535)
|
||||
CC_LOG_WARNING("Device does not support UINT element index type and vertexCount (%u) is larger than ushort", vertexCount);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -185,7 +185,11 @@ Mesh::ICreateInfo MeshUtils::createMeshInfo(const IGeometry &geometry, const ccs
|
||||
|
||||
if (geometry.customAttributes.has_value()) {
|
||||
for (const auto &ca : geometry.customAttributes.value()) {
|
||||
const auto &info = gfx::GFX_FORMAT_INFOS[static_cast<uint32_t>(attr->format)];
|
||||
if (ca.values.empty()) {
|
||||
CC_LOG_WARNING("Custom attribute %s has no values, skipped.", ca.attr.name.c_str());
|
||||
continue;
|
||||
}
|
||||
const auto &info = gfx::GFX_FORMAT_INFOS[static_cast<uint32_t>(ca.attr.format)];
|
||||
attributes.emplace_back(ca.attr);
|
||||
vertCount = std::max(vertCount, static_cast<uint32_t>(std::floor(ca.values.size() / info.count)));
|
||||
channels.emplace_back(Channel{stride, ca.values, ca.attr});
|
||||
|
||||
@@ -68,6 +68,9 @@ unsigned int AudioEngine::sMaxInstances = MAX_AUDIOINSTANCES;
|
||||
AudioEngine::ProfileHelper *AudioEngine::sDefaultProfileHelper = nullptr;
|
||||
ccstd::unordered_map<int, AudioEngine::AudioInfo> AudioEngine::sAudioIDInfoMap;
|
||||
AudioEngineImpl *AudioEngine::sAudioEngineImpl = nullptr;
|
||||
// Decoder-only fallback instance, defined here to keep AudioDecoderManager
|
||||
// initialization separate from OpenAL initialization.
|
||||
AudioEngineImpl *AudioEngine::sDecoderImpl = nullptr;
|
||||
|
||||
float AudioEngine::sVolumeFactor = 1.0F;
|
||||
events::EnterBackground::Listener AudioEngine::sOnPauseListenerID;
|
||||
@@ -156,6 +159,9 @@ void AudioEngine::end() {
|
||||
delete sAudioEngineImpl;
|
||||
sAudioEngineImpl = nullptr;
|
||||
|
||||
delete sDecoderImpl;
|
||||
sDecoderImpl = nullptr;
|
||||
|
||||
delete sDefaultProfileHelper;
|
||||
sDefaultProfileHelper = nullptr;
|
||||
|
||||
@@ -587,12 +593,48 @@ bool AudioEngine::isEnabled() {
|
||||
return sIsEnabled;
|
||||
}
|
||||
|
||||
PCMHeader AudioEngine::getPCMHeader(const char *url) {
|
||||
lazyInit();
|
||||
return sAudioEngineImpl->getPCMHeader(url);
|
||||
AudioEngineImpl *AudioEngine::getDecoderImpl() {
|
||||
if (AudioEngine::sAudioEngineImpl != nullptr) {
|
||||
return AudioEngine::sAudioEngineImpl;
|
||||
}
|
||||
// Try full init first; if it succeeds we get OpenAL + decoder.
|
||||
AudioEngine::lazyInit();
|
||||
if (AudioEngine::sAudioEngineImpl != nullptr) {
|
||||
return AudioEngine::sAudioEngineImpl;
|
||||
}
|
||||
// On oalsoft platforms, PCM decoding via AudioDecoderManager works
|
||||
// independently of OpenAL — create a decoder-only fallback instance.
|
||||
// On Android/OpenHarmony and Apple, AudioEngineImpl::getPCMHeader/
|
||||
// getOriginalPCMBuffer dereferences _audioPlayerProvider/_engineEngine
|
||||
// which are only set up by init(). Returning nullptr here lets callers
|
||||
// fail gracefully instead of crashing.
|
||||
#if CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_OHOS || \
|
||||
CC_PLATFORM == CC_PLATFORM_LINUX || CC_PLATFORM == CC_PLATFORM_QNX
|
||||
if (AudioEngine::sDecoderImpl == nullptr) {
|
||||
AudioEngine::sDecoderImpl = ccnew AudioEngineImpl();
|
||||
AudioEngineImpl::initDecoder();
|
||||
}
|
||||
return AudioEngine::sDecoderImpl;
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
PCMHeader AudioEngine::getPCMHeader(const char *url) {
|
||||
AudioEngineImpl *impl = AudioEngine::getDecoderImpl();
|
||||
if (impl == nullptr) {
|
||||
CC_LOG_WARNING("AudioEngine::getPCMHeader: audio engine unavailable, url: %s", url);
|
||||
return {};
|
||||
}
|
||||
return impl->getPCMHeader(url);
|
||||
}
|
||||
|
||||
ccstd::vector<uint8_t> AudioEngine::getOriginalPCMBuffer(const char *url, uint32_t channelID) {
|
||||
lazyInit();
|
||||
return sAudioEngineImpl->getOriginalPCMBuffer(url, channelID);
|
||||
AudioEngineImpl *impl = AudioEngine::getDecoderImpl();
|
||||
if (impl == nullptr) {
|
||||
CC_LOG_WARNING("AudioEngine::getOriginalPCMBuffer: audio engine unavailable, url: %s", url);
|
||||
return {};
|
||||
}
|
||||
return impl->getOriginalPCMBuffer(url, channelID);
|
||||
}
|
||||
} // namespace cc
|
||||
|
||||
@@ -426,6 +426,12 @@ void AudioEngineImpl::onResume() {
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioEngineImpl::initDecoder() {
|
||||
// On Android the decoder infrastructure is set up by init().
|
||||
// This method exists so AudioEngine.cpp compiles uniformly across all platforms.
|
||||
return true;
|
||||
}
|
||||
|
||||
PCMHeader AudioEngineImpl::getPCMHeader(const char *url) {
|
||||
PCMHeader header{};
|
||||
ccstd::string fileFullPath = FileUtils::getInstance()->fullPathForFilename(url);
|
||||
|
||||
@@ -55,6 +55,7 @@ public:
|
||||
~AudioEngineImpl() override;
|
||||
|
||||
bool init();
|
||||
static bool initDecoder();
|
||||
int play2d(const ccstd::string &filePath, bool loop, float volume);
|
||||
void setVolume(int audioID, float volume);
|
||||
void setLoop(int audioID, bool loop);
|
||||
|
||||
@@ -43,6 +43,7 @@ public:
|
||||
~AudioEngineImpl();
|
||||
|
||||
bool init();
|
||||
static bool initDecoder();
|
||||
int play2d(const ccstd::string &fileFullPath, bool loop, float volume);
|
||||
void setVolume(int audioID, float volume);
|
||||
void setLoop(int audioID, bool loop);
|
||||
|
||||
@@ -632,6 +632,12 @@ bool AudioEngineImpl::checkAudioIdValid(int audioID) {
|
||||
return _audioPlayers.find(audioID) != _audioPlayers.end();
|
||||
}
|
||||
|
||||
bool AudioEngineImpl::initDecoder() {
|
||||
// On Apple the decoder infrastructure is set up by init().
|
||||
// This method exists so AudioEngine.cpp compiles uniformly across all platforms.
|
||||
return true;
|
||||
}
|
||||
|
||||
PCMHeader AudioEngineImpl::getPCMHeader(const char *url){
|
||||
PCMHeader header {};
|
||||
auto itr = _audioCaches.find(url);
|
||||
|
||||
@@ -339,6 +339,19 @@ protected:
|
||||
static void pauseAll(ccstd::vector<int> *pausedAudioIDs);
|
||||
static void resumeAll(ccstd::vector<int> *pausedAudioIDs);
|
||||
|
||||
/**
|
||||
* @brief Get Audio Decoder
|
||||
*
|
||||
* Strategy:
|
||||
* 1. If the full impl (with OpenAL) is already alive, reuse it (cache + decoder both available).
|
||||
* 2. If OpenAL init has not been attempted yet, try lazyInit() so that a successful OpenAL
|
||||
* environment still gets the full impl (keeps _audioCaches coherent with play2d).
|
||||
* 3. Only fall back to the decoder-only sDecoderImpl when lazyInit() has failed
|
||||
* (alcOpenDevice returned null, headless / OHOS / CI environments).
|
||||
* @return The impl instance to use for PCM decoding.
|
||||
*/
|
||||
static AudioEngineImpl *getDecoderImpl();
|
||||
|
||||
struct ProfileHelper {
|
||||
AudioProfile profile;
|
||||
|
||||
@@ -382,6 +395,10 @@ protected:
|
||||
static ProfileHelper *sDefaultProfileHelper;
|
||||
|
||||
static AudioEngineImpl *sAudioEngineImpl;
|
||||
// Decoder-only fallback instance used when OpenAL is unavailable.
|
||||
// getPCMHeader / getOriginalPCMBuffer do not depend on OpenAL and use this
|
||||
// instance directly instead of going through lazyInit().
|
||||
static AudioEngineImpl *sDecoderImpl;
|
||||
|
||||
class AudioEngineThreadPool;
|
||||
static AudioEngineThreadPool *sThreadPool;
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
// log, CC_LOG_DEBUG aren't threadsafe, since we uses sub threads for parsing pcm data, threadsafe log output
|
||||
// is needed. Define the following macros (ALOGV, ALOGD, ALOGI, ALOGW, ALOGE) for threadsafe log output.
|
||||
|
||||
//IDEA: Move _winLog, winLog to a separated file
|
||||
// IDEA: Move _winLog, winLog to a separate file
|
||||
static void _winLog(const char *format, va_list args) {
|
||||
static const int MAX_LOG_LENGTH = 16 * 1024;
|
||||
int bufferSize = MAX_LOG_LENGTH;
|
||||
@@ -153,31 +153,50 @@ AudioEngineImpl::~AudioEngineImpl() {
|
||||
AudioDecoderManager::destroy();
|
||||
}
|
||||
|
||||
bool AudioEngineImpl::initDecoder() {
|
||||
return AudioDecoderManager::init();
|
||||
}
|
||||
|
||||
bool AudioEngineImpl::init() {
|
||||
bool ret = false;
|
||||
do {
|
||||
sALDevice = alcOpenDevice(nullptr);
|
||||
|
||||
if (sALDevice) {
|
||||
alGetError();
|
||||
sALContext = alcCreateContext(sALDevice, nullptr);
|
||||
alcMakeContextCurrent(sALContext);
|
||||
|
||||
alGenSources(MAX_AUDIOINSTANCES, _alSources);
|
||||
auto alError = alGetError();
|
||||
if (alError != AL_NO_ERROR) {
|
||||
CC_LOG_ERROR("%s:generating sources failed! error = %x\n", __FUNCTION__, alError);
|
||||
break;
|
||||
}
|
||||
|
||||
for (unsigned int src : _alSources) {
|
||||
_alSourceUsed[src] = false;
|
||||
}
|
||||
|
||||
_scheduler = CC_CURRENT_ENGINE()->getScheduler();
|
||||
ret = AudioDecoderManager::init();
|
||||
CC_LOG_DEBUG("OpenAL was initialized successfully!");
|
||||
if (sALDevice == nullptr) {
|
||||
// alcGetError(nullptr) is valid when no device is open
|
||||
ALCenum alcErr = alcGetError(nullptr);
|
||||
CC_LOG_ERROR("%s: alcOpenDevice failed, ALC error = 0x%x", __FUNCTION__, alcErr);
|
||||
break;
|
||||
}
|
||||
|
||||
alGetError();
|
||||
sALContext = alcCreateContext(sALDevice, nullptr);
|
||||
if (sALContext == nullptr) {
|
||||
ALCenum alcErr = alcGetError(sALDevice);
|
||||
CC_LOG_ERROR("%s: alcCreateContext failed, ALC error = 0x%x", __FUNCTION__, alcErr);
|
||||
break;
|
||||
}
|
||||
|
||||
alcMakeContextCurrent(sALContext);
|
||||
|
||||
std::fill(std::begin(_alSources), std::end(_alSources), 0);
|
||||
|
||||
alGenSources(MAX_AUDIOINSTANCES, _alSources);
|
||||
auto alError = alGetError();
|
||||
if (alError != AL_NO_ERROR) {
|
||||
CC_LOG_ERROR("%s:generating sources failed! error = %x\n", __FUNCTION__, alError);
|
||||
alcMakeContextCurrent(nullptr);
|
||||
alcDestroyContext(sALContext);
|
||||
sALContext = nullptr;
|
||||
break;
|
||||
}
|
||||
|
||||
for (unsigned int src : _alSources) {
|
||||
_alSourceUsed[src] = false;
|
||||
}
|
||||
|
||||
_scheduler = CC_CURRENT_ENGINE()->getScheduler();
|
||||
ret = initDecoder();
|
||||
CC_LOG_DEBUG("OpenAL was initialized successfully!");
|
||||
} while (false);
|
||||
|
||||
return ret;
|
||||
@@ -264,7 +283,7 @@ int AudioEngineImpl::play2d(const ccstd::string &filePath, bool loop, float volu
|
||||
}
|
||||
|
||||
void AudioEngineImpl::play2dImpl(AudioCache *cache, int audioID) {
|
||||
//Note: It may bn in sub thread or main thread :(
|
||||
// Note: It may be in sub thread or main thread :(
|
||||
if (!*cache->_isDestroyed && cache->_state == AudioCache::State::READY) {
|
||||
_threadMutex.lock();
|
||||
auto playerIt = _audioPlayers.find(audioID);
|
||||
|
||||
@@ -45,6 +45,9 @@ public:
|
||||
~AudioEngineImpl() override;
|
||||
|
||||
bool init();
|
||||
// Initialize only the PCM decoder subsystem (AudioDecoderManager).
|
||||
// Does not require an OpenAL device. Safe to call when init() failed.
|
||||
static bool initDecoder();
|
||||
int play2d(const ccstd::string &filePath, bool loop, float volume);
|
||||
void setVolume(int audioID, float volume);
|
||||
void setLoop(int audioID, bool loop);
|
||||
|
||||
@@ -699,7 +699,7 @@ static bool js_Model_setInstancedAttribute(se::State &s) // NOLINT(readability-i
|
||||
value[i] = dataVal.toFloat();
|
||||
}
|
||||
|
||||
cobj->setInstancedAttribute(name, value);
|
||||
cobj->setInstancedAttribute(name, std::move(value));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2025 Xiamen Yaji Software Co., Ltd.
|
||||
Copyright (c) 2022-2026 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
@@ -23,11 +23,11 @@ THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#define COCOS_MAJOR_VERSION 3
|
||||
#define COCOS_MINJOR_VERSION 8
|
||||
#define COCOS_PATCH_VERSION 8
|
||||
#define COCOS_VERSION_STRING "3.8.8"
|
||||
#define COCOS_MAJOR_VERSION 4
|
||||
#define COCOS_MINJOR_VERSION 0
|
||||
#define COCOS_PATCH_VERSION 0
|
||||
#define COCOS_VERSION_STRING "4.0.0"
|
||||
#define COCOS_VERSION_DEFINED 1
|
||||
#define COCOS_VERSION 30808
|
||||
#define COCOS_VERSION 40000
|
||||
|
||||
// #define COCOS_PRE_RELEASE "release"
|
||||
// #define COCOS_PRE_RELEASE "alpha"
|
||||
|
||||
@@ -68,6 +68,7 @@ RenderAdditiveLightQueue::RenderAdditiveLightQueue(RenderPipeline *pipeline) : _
|
||||
void RenderAdditiveLightQueue::recordCommandBuffer(gfx::Device *device, scene::Camera *camera, gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuffer) {
|
||||
const uint32_t offset = _pipeline->getPipelineUBO()->getCurrentCameraUBOOffset();
|
||||
for (uint32_t i = 0; i < _instancedQueues.size(); ++i) {
|
||||
if (!this->_instancedQueues[i]) { continue; }
|
||||
const auto *light = _instancedLightPass.lights[i];
|
||||
_dynamicOffsets[0] = _instancedLightPass.dynamicOffsets[i];
|
||||
auto *globalDescriptorSet = _pipeline->getGlobalDSManager()->getOrCreateDescriptorSet(light);
|
||||
@@ -109,13 +110,12 @@ void RenderAdditiveLightQueue::gatherLightPasses(const scene::Camera *camera, gf
|
||||
|
||||
clear();
|
||||
|
||||
_validPunctualLights = _pipeline->getPipelineSceneData()->getValidPunctualLights();
|
||||
|
||||
if (_validPunctualLights.empty()) return;
|
||||
|
||||
updateUBOs(camera, cmdBuffer);
|
||||
updateLightDescriptorSet(camera, cmdBuffer);
|
||||
|
||||
_validPunctualLights = _pipeline->getPipelineSceneData()->getValidPunctualLights();
|
||||
if (_validPunctualLights.empty()) return;
|
||||
|
||||
const auto &renderObjects = _pipeline->getPipelineSceneData()->getRenderObjects();
|
||||
for (const auto &renderObject : renderObjects) {
|
||||
const auto *const model = renderObject.model;
|
||||
@@ -154,20 +154,19 @@ void RenderAdditiveLightQueue::gatherLightPasses(const scene::Camera *camera, gf
|
||||
_instancedLightPass.dynamicOffsets.emplace_back(_lightBufferStride * l);
|
||||
}
|
||||
for (const auto &instancedQueue : _instancedQueues) {
|
||||
instancedQueue->uploadBuffers(cmdBuffer);
|
||||
if (instancedQueue) {
|
||||
instancedQueue->uploadBuffers(cmdBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RenderAdditiveLightQueue::clear() {
|
||||
for (const auto &instancedQueue : _instancedQueues) {
|
||||
instancedQueue->clear();
|
||||
if (instancedQueue) {
|
||||
instancedQueue->clear();
|
||||
}
|
||||
}
|
||||
_instancedQueues.clear();
|
||||
|
||||
for (auto lightPass : _lightPasses) {
|
||||
lightPass.dynamicOffsets.clear();
|
||||
lightPass.lights.clear();
|
||||
}
|
||||
_lightPasses.clear();
|
||||
|
||||
_instancedLightPass.dynamicOffsets.clear();
|
||||
@@ -212,13 +211,14 @@ void RenderAdditiveLightQueue::addRenderQueue(scene::SubModel *subModel, const s
|
||||
if ((visibility & model->getNode()->getLayer()) == model->getNode()->getLayer()) {
|
||||
switch (batchingScheme) {
|
||||
case scene::BatchingSchemes::INSTANCING: {
|
||||
auto *buffer = pass->getInstancedBuffer(i);
|
||||
auto *buffer = pass->getInstancedBuffer(lightIdx);
|
||||
buffer->merge(subModel, lightPassIdx);
|
||||
buffer->setDynamicOffset(0, _lightBufferStride);
|
||||
if (i >= _instancedQueues.size()) {
|
||||
_instancedQueues.emplace_back(ccnew RenderInstancedQueue());
|
||||
buffer->setDynamicOffset(0, _lightBufferStride * lightIdx);
|
||||
if (_instancedQueues.size() <= lightIdx || !_instancedQueues[lightIdx]) {
|
||||
_instancedQueues.resize(lightIdx + 1);
|
||||
_instancedQueues[lightIdx] = ccnew RenderInstancedQueue();
|
||||
}
|
||||
_instancedQueues[i]->add(buffer);
|
||||
_instancedQueues[lightIdx]->add(buffer);
|
||||
} break;
|
||||
case scene::BatchingSchemes::NONE: {
|
||||
lightPass.lights.emplace_back(light);
|
||||
@@ -243,6 +243,7 @@ void RenderAdditiveLightQueue::updateUBOs(const scene::Camera *camera, gfx::Comm
|
||||
|
||||
size_t offset = 0;
|
||||
if (validLightCount > _lightBufferCount) {
|
||||
_firstLightBufferView->destroy();
|
||||
_lightBufferCount = nextPow2(static_cast<uint32_t>(validLightCount));
|
||||
_lightBuffer->resize(utils::toUint(_lightBufferStride * _lightBufferCount));
|
||||
_lightBufferData.resize(static_cast<size_t>(_lightBufferElementCount) * _lightBufferCount);
|
||||
@@ -432,7 +433,7 @@ void RenderAdditiveLightQueue::updateLightDescriptorSet(const scene::Camera *cam
|
||||
memcpy(_shadowUBO.data() + UBOShadow::MAT_LIGHT_VIEW_PROJ_OFFSET, matShadowViewProj.m, sizeof(matShadowViewProj));
|
||||
|
||||
// shadow info
|
||||
float shadowNFLSInfos[4] = {0.1F, spotLight->getRange(), 0.0F, 0.0F};
|
||||
float shadowNFLSInfos[4] = {0.01F, spotLight->getRange(), 0.0F, 0.0F};
|
||||
memcpy(_shadowUBO.data() + UBOShadow::SHADOW_NEAR_FAR_LINEAR_SATURATION_INFO_OFFSET, &shadowNFLSInfos, sizeof(shadowNFLSInfos));
|
||||
|
||||
const auto &shadowSize = shadowInfo->getSize();
|
||||
@@ -491,15 +492,17 @@ bool RenderAdditiveLightQueue::getLightPassIndex(const scene::Model *model, ccst
|
||||
bool hasValidLightPass = false;
|
||||
|
||||
for (const auto &subModel : model->getSubModels()) {
|
||||
int lightPassIndex = 0;
|
||||
int lightPassIndex = -1; // use -1 to indicate no valid light pass found
|
||||
int k = 0;
|
||||
for (const auto &pass : *(subModel->getPasses())) {
|
||||
if (pass->getPhase() == _phaseID) {
|
||||
lightPassIndex = k;
|
||||
hasValidLightPass = true;
|
||||
break;
|
||||
}
|
||||
++lightPassIndex;
|
||||
++k;
|
||||
}
|
||||
lightPassIndices->push_back(lightPassIndex);
|
||||
lightPassIndices->push_back(static_cast<uint32_t>(lightPassIndex));
|
||||
}
|
||||
|
||||
return hasValidLightPass;
|
||||
@@ -517,7 +520,7 @@ void RenderAdditiveLightQueue::lightCulling(const scene::Model *model) {
|
||||
isCulled = cullSpotLight(static_cast<const scene::SpotLight *>(light), model);
|
||||
break;
|
||||
case scene::LightType::POINT:
|
||||
isCulled = cullSphereLight(static_cast<const scene::SphereLight *>(light), model);
|
||||
isCulled = cullPointLight(static_cast<const scene::PointLight *>(light), model);
|
||||
break;
|
||||
case scene::LightType::RANGED_DIRECTIONAL:
|
||||
isCulled = cullRangedDirLight(static_cast<const scene::RangedDirectionalLight *>(light), model);
|
||||
|
||||
@@ -753,7 +753,7 @@ uint32_t LightResource::addLight(
|
||||
// already added
|
||||
auto iter = lightIndex.find(light);
|
||||
if (iter != lightIndex.end()) {
|
||||
return iter->second;
|
||||
return iter->second * elementSize;
|
||||
}
|
||||
|
||||
// resize buffer
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "cocos-creator",
|
||||
"version": "4.0.0-alpha.25",
|
||||
"version": "4.0.0-alpha.28",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "cocos-creator",
|
||||
"version": "4.0.0-alpha.25",
|
||||
"version": "4.0.0-alpha.28",
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cocos-creator",
|
||||
"version": "4.0.0-alpha.25",
|
||||
"version": "4.0.0-alpha.28",
|
||||
"description": "Cocos Creator is a cross-platform 2D & 3D game engine written in C++ and TypeScript, licensed under MIT.",
|
||||
"homepage": "http://www.cocos.com",
|
||||
"license": "MIT",
|
||||
|
||||
Reference in New Issue
Block a user