Skip to content

Commit

Permalink
synchronize light data to native (cocos#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
minggo committed May 18, 2021
1 parent a1b0009 commit 1c152b9
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
11 changes: 7 additions & 4 deletions cocos/core/renderer/scene/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,10 @@ export class Camera {
CameraPool.setMat4(this._poolHandle, CameraView.MAT_VIEW_PROJ_INV, this._matViewProjInv);
this._nativeObj.matViewProj = this._matViewProj;
this._nativeObj.matViewProjInv = this._matViewProjInv;

recordFrustumToSharedMemory(this._frustumHandle, this._frustum);
this._nativeObj.frustum = this._frustum;
}
recordFrustumToSharedMemory(this._frustumHandle, this._frustum);
this._nativeObj.frustum = this._frustum;
}
}

Expand Down Expand Up @@ -578,8 +579,10 @@ export class Camera {

set frustum (val) {
this._frustum = val;
recordFrustumToSharedMemory(this._frustumHandle, val);
this._nativeObj.frustum = this._frustum;
if (JSB) {
recordFrustumToSharedMemory(this._frustumHandle, val);
this._nativeObj.frustum = this._frustum;
}
}

get frustum () {
Expand Down
2 changes: 1 addition & 1 deletion cocos/core/renderer/scene/directional-light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class DirectionalLight extends Light {
Vec3.normalize(this._dir, dir);
if (JSB) {
LightPool.setVec3(this._handle, LightView.DIRECTION, this._dir);
this._nativeObj.setDir(dir);
this._nativeObj.setDirection(dir);
}
}

Expand Down
12 changes: 7 additions & 5 deletions cocos/core/renderer/scene/render-scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { TransformBit } from '../../scene-graph/node-enum';
import { ScenePool, SceneView, ModelArrayPool, ModelArrayHandle, SceneHandle, NULL_HANDLE,
UIBatchArrayHandle, UIBatchArrayPool, LightArrayHandle, LightArrayPool } from '../core/memory-pools';
import { DrawBatch2D } from '../../../2d/renderer/draw-batch';
import { scene } from '..';

export interface IRenderSceneInfo {
name: string;
Expand Down Expand Up @@ -222,13 +221,10 @@ export class RenderScene {
if (this._mainLight === dl) {
const dlList = this._directionalLights;
if (dlList.length) {
this._mainLight = dlList[dlList.length - 1];
this._nativeObj.setMainLight(this._mainLight);
this.setMainLight(dlList[dlList.length - 1]);
if (this._mainLight.node) { // trigger update
this._mainLight.node.hasChangedFlags |= TransformBit.ROTATION;
}
} else {
this._nativeObj.setMainLight(null);
}
}
}
Expand All @@ -253,6 +249,7 @@ export class RenderScene {
this._sphereLights.push(pl);
if (JSB) {
LightArrayPool.push(this._sphereLightsHandle, pl.handle);
this._nativeObj.addSphereLight(pl.native);
}
}

Expand All @@ -263,6 +260,7 @@ export class RenderScene {
this._sphereLights.splice(i, 1);
if (JSB) {
LightArrayPool.erase(this._sphereLightsHandle, i);
this._nativeObj.removeSphereLight(pl.native);
}
return;
}
Expand All @@ -274,6 +272,7 @@ export class RenderScene {
this._spotLights.push(sl);
if (JSB) {
LightArrayPool.push(this._spotLightsHandle, sl.handle);
this._nativeObj.addSpotLight(sl.native);
}
}

Expand All @@ -284,6 +283,7 @@ export class RenderScene {
this._spotLights.splice(i, 1);
if (JSB) {
LightArrayPool.erase(this._spotLightsHandle, i);
this._nativeObj.removeSpotLight(sl.native);
}
return;
}
Expand All @@ -297,6 +297,7 @@ export class RenderScene {
this._sphereLights.length = 0;
if (JSB) {
LightArrayPool.clear(this._sphereLightsHandle);
this._nativeObj.removeSphereLights();
}
}

Expand All @@ -307,6 +308,7 @@ export class RenderScene {
this._spotLights = [];
if (JSB) {
LightArrayPool.clear(this._spotLightsHandle);
this._nativeObj.removeSpotLights();
}
}

Expand Down
6 changes: 6 additions & 0 deletions cocos/core/renderer/scene/sphere-light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export class SphereLight extends Light {
LightPool.setVec3(this._handle, LightView.POSITION, this._pos);
AABBPool.setVec3(this._hAABB, AABBView.CENTER, this._aabb.center);
AABBPool.setVec3(this._hAABB, AABBView.HALF_EXTENSION, this._aabb.halfExtents);

this._nativeObj.setPosition(this._pos);
this._nativeObj.setAABB(this._aabb);
}
}

Expand All @@ -63,6 +66,7 @@ export class SphereLight extends Light {
this._size = size;
if (JSB) {
LightPool.set(this._handle, LightView.SIZE, size);
this._nativeObj.setSize(size);
}
}

Expand All @@ -74,6 +78,7 @@ export class SphereLight extends Light {
this._range = range;
if (JSB) {
LightPool.set(this._handle, LightView.RANGE, range);
this._nativeObj.setRange(range);
}

this._needUpdate = true;
Expand All @@ -87,6 +92,7 @@ export class SphereLight extends Light {
this._luminance = lum;
if (JSB) {
LightPool.set(this._handle, LightView.ILLUMINANCE, lum);
this._nativeObj.setIlluminance(lum);
}
}

Expand Down
10 changes: 10 additions & 0 deletions cocos/core/renderer/scene/spot-light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export class SpotLight extends Light {
this._dir.set(dir);
if (JSB) {
LightPool.setVec3(this._handle, LightView.DIRECTION, this._dir);
this._nativeObj.setDirection(dir);
}
}

Expand All @@ -102,6 +103,10 @@ export class SpotLight extends Light {
AABBPool.setVec3(this._hAABB, AABBView.CENTER, this._aabb.center);
AABBPool.setVec3(this._hAABB, AABBView.HALF_EXTENSION, this._aabb.halfExtents);
recordFrustumToSharedMemory(this._hFrustum, this._frustum);
this._nativeObj.setFrustum(this._frustum);
this._nativeObj.setAABB(this._aabb);
this._nativeObj.setDirection(this._dir);
this._nativeObj.setPosition(this._pos);
}
}

Expand All @@ -113,6 +118,7 @@ export class SpotLight extends Light {
this._size = size;
if (JSB) {
LightPool.set(this._handle, LightView.SIZE, size);
this._nativeObj.setSize(size);
}
}

Expand All @@ -124,6 +130,7 @@ export class SpotLight extends Light {
this._range = range;
if (JSB) {
LightPool.set(this._handle, LightView.RANGE, range);
this._nativeObj.setRange(range);
}

this._needUpdate = true;
Expand All @@ -137,6 +144,7 @@ export class SpotLight extends Light {
this._luminance = lum;
if (JSB) {
LightPool.set(this._handle, LightView.ILLUMINANCE, lum);
this._nativeObj.setIlluminance(lum);
}
}

Expand All @@ -157,6 +165,7 @@ export class SpotLight extends Light {
this._spotAngle = Math.cos(val * 0.5);
if (JSB) {
LightPool.set(this._handle, LightView.SPOT_ANGLE, this._spotAngle);
this._nativeObj.setAngle(this._spotAngle);
}

this._needUpdate = true;
Expand All @@ -166,6 +175,7 @@ export class SpotLight extends Light {
this._aspect = val;
if (JSB) {
LightPool.set(this._handle, LightView.ASPECT, val);
this._nativeObj.setAspect(val);
}

this._needUpdate = true;
Expand Down
3 changes: 2 additions & 1 deletion cocos/core/renderer/scene/submodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,15 @@ export class SubModel {
}

public destroy (): void {
this._destroy();
this._destroyDescriptorSet();
this._destroyInputAssembler();
this.priority = RenderPriority.DEFAULT;

this._patches = null;
this._subMesh = null;
this._passes = null;

this._destroy();
}

public update (): void {
Expand Down

0 comments on commit 1c152b9

Please sign in to comment.