mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
@@ -292,7 +292,7 @@ export const barFilled: IAssembler = {
|
||||
commitBuffer.meshBuffer = buffer;
|
||||
commitBuffer.material = sprite.material!;
|
||||
commitBuffer.texture = sprite.spriteFrame!;
|
||||
commitBuffer.camera = renderer.getScreen(sprite.visibility)!.camera!;
|
||||
commitBuffer.priority = sprite.priority;
|
||||
renderer.addToQueue(commitBuffer);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -381,7 +381,7 @@ export const radialFilled: IAssembler = {
|
||||
commitBuffer.meshBuffer = buffer;
|
||||
commitBuffer.material = comp.material!;
|
||||
commitBuffer.texture = comp.spriteFrame!;
|
||||
commitBuffer.camera = renderer.getScreen(comp.visibility)!.camera!;
|
||||
commitBuffer.priority = comp.priority;
|
||||
renderer.addToQueue(commitBuffer);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -141,7 +141,7 @@ export const simple: IAssembler = {
|
||||
commitBuffer.meshBuffer = buffer;
|
||||
commitBuffer.material = sprite.material!;
|
||||
commitBuffer.texture = sprite.spriteFrame!;
|
||||
commitBuffer.camera = renderer.getScreen(sprite.visibility)!.camera!;
|
||||
commitBuffer.priority = sprite.priority;
|
||||
renderer.addToQueue(commitBuffer);
|
||||
},
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ export const sliced: IAssembler = {
|
||||
commitBuffer.meshBuffer = buffer;
|
||||
commitBuffer.material = sprite.material!;
|
||||
commitBuffer.texture = sprite.spriteFrame!;
|
||||
commitBuffer.camera = renderer.getScreen(sprite.visibility)!.camera!;
|
||||
commitBuffer.priority = sprite.priority;
|
||||
renderer.addToQueue(commitBuffer);
|
||||
},
|
||||
|
||||
|
||||
@@ -241,7 +241,7 @@ export const tilled: IAssembler = {
|
||||
commitBuffer.meshBuffer = buffer;
|
||||
commitBuffer.material = sprite.material!;
|
||||
commitBuffer.texture = sprite.spriteFrame!;
|
||||
commitBuffer.camera = renderer.getScreen(sprite.visibility)!.camera!;
|
||||
commitBuffer.priority = sprite.priority;
|
||||
renderer.addToQueue(commitBuffer);
|
||||
},
|
||||
|
||||
|
||||
@@ -95,18 +95,18 @@ export class CanvasComponent extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* !#en priority in render
|
||||
* !#zh 显示优先级
|
||||
*/
|
||||
@property
|
||||
get priority () {
|
||||
return this._priority;
|
||||
}
|
||||
// /**
|
||||
// * !#en priority in render
|
||||
// * !#zh 显示优先级
|
||||
// */
|
||||
// @property
|
||||
// get priority () {
|
||||
// return this._priority;
|
||||
// }
|
||||
|
||||
set priority (value: number) {
|
||||
this._priority = value;
|
||||
}
|
||||
// set priority (value: number) {
|
||||
// this._priority = value;
|
||||
// }
|
||||
|
||||
get visibility () {
|
||||
if (this._camera) {
|
||||
@@ -133,8 +133,8 @@ export class CanvasComponent extends Component {
|
||||
private _fitWidth = false;
|
||||
@property
|
||||
private _fitHeight = true;
|
||||
@property
|
||||
private _priority = 0;
|
||||
// @property
|
||||
// private _priority = 0;
|
||||
|
||||
private _thisOnResized: ()=>void;
|
||||
|
||||
|
||||
@@ -95,11 +95,29 @@ export class UIRenderComponent extends RenderableComponent {
|
||||
this._updateBlendFunc(true);
|
||||
}
|
||||
|
||||
get color () {
|
||||
/**
|
||||
* !#en render order, render order according to width, and arrange once under the same level node.
|
||||
* !#zh 渲染先后顺序,按照广度渲染排列,同级节点下进行一次排列
|
||||
*/
|
||||
@property
|
||||
get priority() {
|
||||
return this._priority;
|
||||
}
|
||||
|
||||
set priority(value) {
|
||||
this._priority = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* !#en render color
|
||||
* !#zh 渲染颜色
|
||||
* @property color
|
||||
*/
|
||||
get color() {
|
||||
return this._color;
|
||||
}
|
||||
|
||||
set color (value) {
|
||||
set color(value) {
|
||||
if (this._color === value) {
|
||||
return;
|
||||
}
|
||||
@@ -127,6 +145,8 @@ export class UIRenderComponent extends RenderableComponent {
|
||||
protected _dstBlendFactor: number = macro.BlendFactor.ONE_MINUS_SRC_ALPHA;
|
||||
@property
|
||||
protected _color: Color = Color.WHITE;
|
||||
@property
|
||||
protected _priority: number = 0;
|
||||
protected _renderData: RenderData | null = null;
|
||||
// _allocedDatas = [];
|
||||
// _vertexFormat = null;
|
||||
|
||||
+74
-27
@@ -25,10 +25,10 @@ import { GFXInputAssembler, IGFXInputAttribute } from '../../gfx/input-assembler
|
||||
import { GFXUniformBlock } from '../../gfx/shader';
|
||||
import { GFXTextureView } from '../../gfx/texture-view';
|
||||
import { vfmt } from '../../gfx/vertex-format-sample';
|
||||
import { BaseNode } from '../../scene-graph/base-node';
|
||||
import { Camera } from '../scene/camera';
|
||||
import { RenderScene } from '../scene/render-scene';
|
||||
import { IUIMaterialInfo, UIMaterial } from './ui-material';
|
||||
import { Node } from '../../scene-graph/node';
|
||||
|
||||
export class UBOUI {
|
||||
public static MAT_VIEW_PROJ_OFFSET: number = 0;
|
||||
@@ -76,7 +76,11 @@ export interface IUIRenderData {
|
||||
meshBuffer: MeshBuffer;
|
||||
material: Material;
|
||||
texture: SpriteFrame;
|
||||
priority: number;
|
||||
}
|
||||
export interface IUICanvas {
|
||||
camera: Camera;
|
||||
datas: IUIRenderData[];
|
||||
}
|
||||
|
||||
export class UI {
|
||||
@@ -107,6 +111,10 @@ export class UI {
|
||||
private _batches: CachedArray<UIDrawBatch>;
|
||||
private _bufferInitData: IMeshBufferInitData | null = null;
|
||||
private _commitUIRenderDatas: IUIRenderData[] = [];
|
||||
private _commitUICanvasDatas: IUICanvas[] = [];
|
||||
private _sortChildList: RecyclePool = new RecyclePool(() => {
|
||||
return [];
|
||||
}, 128);
|
||||
|
||||
constructor (private _root: Root) {
|
||||
this._device = _root.device;
|
||||
@@ -201,15 +209,14 @@ export class UI {
|
||||
this._screens.push(comp);
|
||||
}
|
||||
|
||||
public getScreen (visibility: number) {
|
||||
for (const screen of this._screens) {
|
||||
public getScreen(visibility: number) {
|
||||
this._screens.forEach((screen) => {
|
||||
if (screen.camera) {
|
||||
if (screen.camera.visibility === visibility) {
|
||||
return screen;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -237,7 +244,7 @@ export class UI {
|
||||
}
|
||||
|
||||
public update (dt: number) {
|
||||
|
||||
|
||||
for (let i = 0; i < this._batches.length; ++i) {
|
||||
const batch = this._batches.array[i];
|
||||
batch.clear();
|
||||
@@ -245,7 +252,7 @@ export class UI {
|
||||
}
|
||||
this._batches.clear();
|
||||
|
||||
this._commitUIRenderDatas = [];
|
||||
// this._commitUIRenderDatas = [];
|
||||
|
||||
this._renderScreens();
|
||||
|
||||
@@ -324,16 +331,52 @@ export class UI {
|
||||
}
|
||||
}
|
||||
|
||||
private _walk (node, fn1, fn2, level = 0) {
|
||||
level += 1;
|
||||
const len = node.children.length;
|
||||
fn1(node);
|
||||
for (let i = 0; i < len; ++i) {
|
||||
const child = node.children[i];
|
||||
this._walk(child, fn1, fn2, level);
|
||||
// skip the first object
|
||||
private _walk (renderComp, fn1, fn2, level = 0) {
|
||||
let renderCompList;
|
||||
if(level === 0){
|
||||
level+=1;
|
||||
renderCompList = this._defineNodeOrder(renderComp.children);
|
||||
renderCompList.forEach(comp => {
|
||||
this._walk(comp, fn1, fn2, level);
|
||||
});
|
||||
this._sortChildList.remove(renderCompList);
|
||||
return;
|
||||
}
|
||||
|
||||
fn2(node);
|
||||
// const len = node.children.length;
|
||||
fn1(renderComp);
|
||||
|
||||
renderCompList = this._defineNodeOrder(renderComp.node.children);
|
||||
for (const comp of renderCompList){
|
||||
this._walk(comp, fn1, fn2, level);
|
||||
}
|
||||
// for (let i = 0; i < len; ++i) {
|
||||
// const child = node.children[i];
|
||||
// this._walk(child, fn1, fn2, level);
|
||||
// }
|
||||
|
||||
|
||||
this._sortChildList.remove(renderCompList);
|
||||
fn2(renderComp);
|
||||
level += 1;
|
||||
}
|
||||
|
||||
private _defineNodeOrder(childs: Node[]) {
|
||||
let sortList = this._sortChildList.add();
|
||||
|
||||
childs.forEach((child) => {
|
||||
let renderComp = child.getComponent(UIRenderComponent);
|
||||
if (renderComp) {
|
||||
sortList.push(renderComp);
|
||||
}
|
||||
})
|
||||
|
||||
sortList.sort((a, b) => {
|
||||
return (a.priority - b.priority);
|
||||
});
|
||||
|
||||
return sortList;
|
||||
}
|
||||
|
||||
private _renderScreens () {
|
||||
@@ -343,24 +386,28 @@ export class UI {
|
||||
continue;
|
||||
}
|
||||
// this._currScreen = screen;
|
||||
this._commitUIRenderDatas.length = 0;
|
||||
|
||||
this._walk(screen.node, (c: BaseNode) => {
|
||||
const renderComponent = c.getComponent(UIRenderComponent);
|
||||
if (renderComponent && renderComponent.enabledInHierarchy) {
|
||||
this._commitComp(renderComponent);
|
||||
this._walk(screen.node, (c: UIRenderComponent) => {
|
||||
// const renderComponent = c.getComponent(UIRenderComponent);
|
||||
if (c.enabledInHierarchy) {
|
||||
this._commitComp(c);
|
||||
}
|
||||
}, (c: UIRenderComponent) => {
|
||||
// const renderComponent = c.getComponent(UIRenderComponent);
|
||||
if (c.enabledInHierarchy) {
|
||||
this._postCommitComp(c);
|
||||
}
|
||||
}, (c: BaseNode) => {
|
||||
const renderComponent = c.getComponent(UIRenderComponent);
|
||||
if (renderComponent && renderComponent.enabledInHierarchy) {
|
||||
this._postCommitComp(renderComponent);
|
||||
}
|
||||
});
|
||||
|
||||
this._commitUICanvasDatas.push({ camera: screen.camera!, datas: this._commitUIRenderDatas });
|
||||
}
|
||||
}
|
||||
|
||||
private _reset () {
|
||||
this._bufferPool.reset();
|
||||
this._commitUIRenderDataPool.reset();
|
||||
this._commitUICanvasDatas.length = 0;
|
||||
}
|
||||
|
||||
private _commitComp (comp: UIRenderComponent) {
|
||||
@@ -384,7 +431,7 @@ export class UI {
|
||||
let curBufferBatch: UIBufferBatch = this._bufferBatches[bufferBatchIdx++];
|
||||
let idxCount = 0;
|
||||
let vertCount = 0;
|
||||
|
||||
|
||||
let vf32: Float32Array;
|
||||
let vui16: Uint16Array;
|
||||
let vbSize = 0;
|
||||
@@ -441,7 +488,7 @@ export class UI {
|
||||
isNewBatch = true;
|
||||
curCamera = uiRenderData.camera;
|
||||
}
|
||||
|
||||
|
||||
if (curTexView !== uiRenderData.texture.getGFXTextureView()) {
|
||||
curTexView = uiRenderData.texture.getGFXTextureView();
|
||||
isNewBatch = true;
|
||||
@@ -454,7 +501,7 @@ export class UI {
|
||||
batch.uiMaterial = this._uiMaterial!;
|
||||
batch.texView = curTexView!;
|
||||
batch.idxCount = idxCount;
|
||||
|
||||
|
||||
this._batches.push(batch);
|
||||
}
|
||||
} // for
|
||||
|
||||
Reference in New Issue
Block a user