mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
fix ui render view
This commit is contained in:
Vendored
+1
-1
@@ -118,7 +118,7 @@ export default [
|
||||
{
|
||||
"name": "builtin-effect-sprite|sprite-vs:vert|sprite-fs:frag",
|
||||
"vert": "\nattribute vec3 a_position;\nattribute vec2 a_texCoord;\nattribute vec4 a_color;\n uniform mat4 cc_matViewProj;\nvarying vec2 v_uv0;\nvarying vec4 v_color;\nvec4 vert () {\n vec4 pos = cc_matViewProj * vec4(a_position, 1);\n v_uv0 = a_texCoord;\n v_color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n",
|
||||
"frag": "\nuniform sampler2D u_texSampler;\nvarying vec2 v_uv0;\nvarying vec4 v_color;\nvec4 frag () {\n \n return vec4(0.0, 1.0, 0.0, 1.0);\n}\nvoid main() { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); }\n",
|
||||
"frag": "\nuniform sampler2D u_texSampler;\nvarying vec2 v_uv0;\nvarying vec4 v_color;\nvec4 frag () {\n return texture2D(u_texSampler, v_uv0) * v_color;\n \n}\nvoid main() { gl_FragColor = frag(); }\n",
|
||||
"defines": [],
|
||||
"blocks": [
|
||||
{"name": "UI", "size": 64, "defines": [], "binding": 0, "members": [
|
||||
|
||||
@@ -201,10 +201,11 @@ export class CanvasComponent extends Component {
|
||||
orthoHeight: 10,
|
||||
far: 4096,
|
||||
near: -0.1,
|
||||
color: cc.color(255, 0, 0, 1),
|
||||
color: cc.color(0, 0, 0, 255),
|
||||
clearFlags: GFXClearFlag.DEPTH | GFXClearFlag.STENCIL,
|
||||
rect: new Rect(0, 0, 1, 1),
|
||||
depth: 1,
|
||||
isUI: true,
|
||||
} as ICameraInfo;
|
||||
this._camera = this._getRenderScene().createCamera(this._cameraInfo);
|
||||
cc.director.root.ui.addScreen(this);
|
||||
|
||||
+7
-5
@@ -150,7 +150,7 @@ export class Root {
|
||||
this._frameTime = deltaTime;
|
||||
|
||||
for (const view of this._views) {
|
||||
if (view.isEnable() && view.window === this._mainWindow) {
|
||||
if (view.isEnable && view.window === this._mainWindow) {
|
||||
this._pipeline!.render(view);
|
||||
}
|
||||
}
|
||||
@@ -218,10 +218,12 @@ export class Root {
|
||||
const view: RenderView = this._createViewFun(this, info.camera);
|
||||
view.initialize(info);
|
||||
|
||||
this._views.push(view);
|
||||
this._views.sort((a: RenderView, b: RenderView) => {
|
||||
return a.priority - b.priority;
|
||||
});
|
||||
if (!info.isUI) {
|
||||
this._views.push(view);
|
||||
this._views.sort((a: RenderView, b: RenderView) => {
|
||||
return a.priority - b.priority;
|
||||
});
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ export interface IRenderViewInfo {
|
||||
camera: Camera;
|
||||
name: string;
|
||||
priority: number;
|
||||
isUI: boolean;
|
||||
}
|
||||
|
||||
export class RenderView {
|
||||
@@ -41,6 +42,14 @@ export class RenderView {
|
||||
return this._camera!;
|
||||
}
|
||||
|
||||
public get isEnable (): boolean {
|
||||
return this._isEnable;
|
||||
}
|
||||
|
||||
public get isUI (): boolean {
|
||||
return this._isUI;
|
||||
}
|
||||
|
||||
public static registerCreateFunc (root: Root) {
|
||||
root._createViewFun = (_root: Root, _camera: Camera): RenderView => new RenderView(_root, _camera);
|
||||
}
|
||||
@@ -52,6 +61,7 @@ export class RenderView {
|
||||
private _visibility: number = 0;
|
||||
private _camera: Camera;
|
||||
private _isEnable: boolean = true;
|
||||
private _isUI: boolean = false;
|
||||
|
||||
private constructor (root: Root, camera: Camera) {
|
||||
this._root = root;
|
||||
@@ -62,6 +72,7 @@ export class RenderView {
|
||||
|
||||
this._name = info.name;
|
||||
this._priority = info.priority;
|
||||
this._isUI = info.isUI;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -78,8 +89,4 @@ export class RenderView {
|
||||
public enable (isEnable: boolean) {
|
||||
this._isEnable = isEnable;
|
||||
}
|
||||
|
||||
public isEnable (): boolean {
|
||||
return this._isEnable;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ export interface ICameraInfo {
|
||||
clearFlags: GFXClearFlag;
|
||||
rect: Rect;
|
||||
targetDisplay: number;
|
||||
isUI?: boolean;
|
||||
}
|
||||
|
||||
const v_a = cc.v3();
|
||||
@@ -61,7 +62,7 @@ export class Camera {
|
||||
|
||||
constructor (scene: RenderScene, info: ICameraInfo) {
|
||||
this._scene = scene;
|
||||
this._name = name;
|
||||
this._name = info.name;
|
||||
this._node = info.node;
|
||||
this._proj = info.projection;
|
||||
this._fov = toRadian(info.fov);
|
||||
@@ -82,6 +83,7 @@ export class Camera {
|
||||
camera: this,
|
||||
name: this._name,
|
||||
priority: RenderViewPriority.GENERAL,
|
||||
isUI: (info.isUI !== undefined? info.isUI : false),
|
||||
});
|
||||
|
||||
this.changeTargetDisplay(info.targetDisplay);
|
||||
|
||||
@@ -112,6 +112,7 @@ export class UI {
|
||||
this._device = _root.device;
|
||||
this._scene = this._root.createScene({
|
||||
name: 'GUIScene',
|
||||
isUIScene: true,
|
||||
});
|
||||
|
||||
this._batches = new CachedArray(64);
|
||||
@@ -287,8 +288,8 @@ export class UI {
|
||||
if (curCamera) {
|
||||
cmdBuff.endRenderPass();
|
||||
}
|
||||
this._renderArea.width = camera.orthoHeight * camera.aspect;
|
||||
this._renderArea.height = camera.orthoHeight;
|
||||
this._renderArea.width = camera.width;
|
||||
this._renderArea.height = camera.height;
|
||||
|
||||
camera.update();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user