move window out from GFX (#6844)

* window info accepts render pass

* move window out from GFX

* update effects

* fix formating

* match shader location to IA attributes
This commit is contained in:
Yun Hsiao Wu
2020-06-12 10:56:47 +08:00
committed by GitHub
parent 673518c724
commit f70f2dd6e3
34 changed files with 456 additions and 677 deletions
File diff suppressed because one or more lines are too long
+4 -4
View File
@@ -173,25 +173,25 @@ class BuiltinResMgr {
// sprite material
const spriteColorMtl = new legacyCC.Material();
spriteColorMtl._uuid = 'ui-sprite-material';
spriteColorMtl.initialize({ defines: { USE_TEXTURE: true, CC_ALPHA_SEPARATED: false, IS_GRAY: false }, effectName: 'builtin-sprite' });
spriteColorMtl.initialize({ defines: { USE_TEXTURE: true, CC_USE_EMBEDDED_ALPHA: false, IS_GRAY: false }, effectName: 'builtin-sprite' });
resources[spriteColorMtl._uuid] = spriteColorMtl;
// sprite gray material
const spriteGrayMtl = new legacyCC.Material();
spriteGrayMtl._uuid = 'ui-sprite-gray-material';
spriteGrayMtl.initialize({ defines: { USE_TEXTURE: true, CC_ALPHA_SEPARATED: false, IS_GRAY: true }, effectName: 'builtin-sprite' });
spriteGrayMtl.initialize({ defines: { USE_TEXTURE: true, CC_USE_EMBEDDED_ALPHA: false, IS_GRAY: true }, effectName: 'builtin-sprite' });
resources[spriteGrayMtl._uuid] = spriteGrayMtl;
// sprite alpha material
const spriteAlphaMtl = new legacyCC.Material();
spriteAlphaMtl._uuid = 'ui-sprite-alpha-sep-material';
spriteAlphaMtl.initialize({ defines: { USE_TEXTURE: true, CC_ALPHA_SEPARATED: true, IS_GRAY: false }, effectName: 'builtin-sprite' });
spriteAlphaMtl.initialize({ defines: { USE_TEXTURE: true, CC_USE_EMBEDDED_ALPHA: true, IS_GRAY: false }, effectName: 'builtin-sprite' });
resources[spriteAlphaMtl._uuid] = spriteAlphaMtl;
// sprite alpha & gray material
const spriteAlphaGrayMtl = new legacyCC.Material();
spriteAlphaGrayMtl._uuid = 'ui-sprite-gray-alpha-sep-material';
spriteAlphaGrayMtl.initialize({ defines: { USE_TEXTURE: true, CC_ALPHA_SEPARATED: true, IS_GRAY: true }, effectName: 'builtin-sprite' });
spriteAlphaGrayMtl.initialize({ defines: { USE_TEXTURE: true, CC_USE_EMBEDDED_ALPHA: true, IS_GRAY: true }, effectName: 'builtin-sprite' });
resources[spriteAlphaGrayMtl._uuid] = spriteAlphaGrayMtl;
// default particle material
+17 -13
View File
@@ -34,7 +34,6 @@ import { Component } from '../../components/component';
import { ccclass, help, executeInEditMode, menu, property } from '../../data/class-decorator';
import { ray } from '../../geometry';
import { GFXClearFlag } from '../../gfx/define';
import { GFXWindow } from '../../gfx/window';
import { Color, Rect, toRadian, Vec3 } from '../../math';
import { CAMERA_DEFAULT_MASK } from '../../pipeline/define';
import { view } from '../../platform/view';
@@ -45,6 +44,7 @@ import { Layers, Node, Scene } from '../../scene-graph';
import { Enum } from '../../value-types';
import { TransformBit } from '../../scene-graph/node-enum';
import { legacyCC } from '../../global-exports';
import { RenderWindow } from '../../pipeline';
const _temp_vec3_1 = new Vec3();
@@ -65,6 +65,17 @@ const ClearFlag = Enum({
DONT_CLEAR: GFXClearFlag.NONE,
});
// tslint:disable: no-shadowed-variable
export namespace CameraComponent {
export type ProjectionType = EnumAlias<typeof ProjectionType>;
export type FOVAxis = EnumAlias<typeof FOVAxis>;
export type ClearFlag = EnumAlias<typeof ClearFlag>;
export type Aperture = EnumAlias<typeof Aperture>;
export type Shutter = EnumAlias<typeof Shutter>;
export type ISO = EnumAlias<typeof ISO>;
}
// tslint:enable: no-shadowed-variable
/**
* @en The Camera Component.
* @zh 相机组件。
@@ -470,7 +481,8 @@ export class CameraComponent extends Component {
set inEditorMode (value) {
this._inEditorMode = value;
if (this._camera) {
this._camera.changeTargetWindow(value ? legacyCC.director.root && legacyCC.director.root.mainWindow : legacyCC.director.root && legacyCC.director.root.tempWindow);
this._camera.changeTargetWindow(value ? legacyCC.director.root && legacyCC.director.root.mainWindow :
legacyCC.director.root && legacyCC.director.root.tempWindow);
}
}
@@ -569,7 +581,8 @@ export class CameraComponent extends Component {
name: this.node.name,
node: this.node,
projection: this._projection,
window: this._inEditorMode ? legacyCC.director.root && legacyCC.director.root.mainWindow : legacyCC.director.root && legacyCC.director.root.tempWindow,
window: this._inEditorMode ? legacyCC.director.root && legacyCC.director.root.mainWindow :
legacyCC.director.root && legacyCC.director.root.tempWindow,
priority: this._priority,
flows: this._flows,
});
@@ -623,7 +636,7 @@ export class CameraComponent extends Component {
}
protected _chechTargetTextureEvent (old: RenderTexture | null) {
const resizeFunc = (window: GFXWindow) => {
const resizeFunc = (window: RenderWindow) => {
if (this._camera) {
this._camera.setFixedSize(window.width, window.height);
}
@@ -650,12 +663,3 @@ export class CameraComponent extends Component {
}
}
}
export namespace CameraComponent {
export type ProjectionType = EnumAlias<typeof ProjectionType>;
export type FOVAxis = EnumAlias<typeof FOVAxis>;
export type ClearFlag = EnumAlias<typeof ClearFlag>;
export type Aperture = EnumAlias<typeof Aperture>;
export type Shutter = EnumAlias<typeof Shutter>;
export type ISO = EnumAlias<typeof ISO>;
}
+1 -1
View File
@@ -48,7 +48,7 @@ export const PhotometricTerm = Enum({
* @en static light settings.
* @zh 静态灯光设置
*/
@ccclass('cc.ModelLightmapSettings')
@ccclass('cc.StaticLightSettings')
class StaticLightSettings {
@property
protected _editorOnly: boolean = false;
+14 -5
View File
@@ -5,6 +5,7 @@ import { Vec3 } from '../../math';
import { IGeometry } from '../../primitive/define';
import { writeBuffer } from './buffer';
import { BufferBlob } from './buffer-blob';
import { legacyCC } from '../../global-exports';
const _defAttrs: IGFXAttribute[] = [
{ name: GFXAttributeName.ATTR_POSITION, format: GFXFormat.RGB32F },
@@ -25,7 +26,8 @@ export function createMesh (geometry: IGeometry, out?: Mesh, options?: createMes
let attr: IGFXAttribute | null;
if (geometry.positions.length > 0) {
const positions = geometry.positions.slice();
if (positions.length > 0) {
attr = null;
if (geometry.attributes) {
for (const att of geometry.attributes) {
@@ -40,11 +42,18 @@ export function createMesh (geometry: IGeometry, out?: Mesh, options?: createMes
attr = _defAttrs[0];
}
// device NDC correction
const info = GFXFormatInfos[attr.format];
const ySign = legacyCC.director.root.device.projectionSignY;
for (let i = 1; i < positions.length; i += info.count) {
positions[i] *= ySign;
}
attributes.push(attr);
vertCount = Math.max(vertCount, Math.floor(geometry.positions.length / info.count));
channels.push({ offset: stride, data: geometry.positions, attribute: attr });
vertCount = Math.max(vertCount, Math.floor(positions.length / info.count));
channels.push({ offset: stride, data: positions, attribute: attr });
stride += info.size;
}
if (geometry.normals && geometry.normals.length > 0) {
@@ -199,7 +208,7 @@ export function createMesh (geometry: IGeometry, out?: Mesh, options?: createMes
if (!minPosition && options.calculateBounds) {
minPosition = Vec3.set(new Vec3(), Infinity, Infinity, Infinity);
for (let iVertex = 0; iVertex < vertCount; ++iVertex) {
Vec3.set(v3_1, geometry.positions[iVertex * 3 + 0], geometry.positions[iVertex * 3 + 1], geometry.positions[iVertex * 3 + 2]);
Vec3.set(v3_1, positions[iVertex * 3 + 0], positions[iVertex * 3 + 1], positions[iVertex * 3 + 2]);
Vec3.min(minPosition, minPosition, v3_1);
}
}
@@ -207,7 +216,7 @@ export function createMesh (geometry: IGeometry, out?: Mesh, options?: createMes
if (!maxPosition && options.calculateBounds) {
maxPosition = Vec3.set(new Vec3(), -Infinity, -Infinity, -Infinity);
for (let iVertex = 0; iVertex < vertCount; ++iVertex) {
Vec3.set(v3_1, geometry.positions[iVertex * 3 + 0], geometry.positions[iVertex * 3 + 1], geometry.positions[iVertex * 3 + 2]);
Vec3.set(v3_1, positions[iVertex * 3 + 0], positions[iVertex * 3 + 1], positions[iVertex * 3 + 2]);
Vec3.max(maxPosition, maxPosition, v3_1);
}
}
+2 -2
View File
@@ -44,7 +44,7 @@ import {
GFXPrimitiveMode,
} from '../gfx/define';
import { GFXDevice, GFXFeature } from '../gfx/device';
import { IGFXAttribute } from '../gfx/input-assembler';
import { IGFXAttribute, IGFXInputAssemblerInfo } from '../gfx/input-assembler';
import { warnID } from '../platform/debug';
import { sys } from '../platform/sys';
import { murmurhash2_32_gc } from '../utils/murmurhash2_gc';
@@ -102,7 +102,7 @@ export interface IFlatBuffer {
/**
* 渲染子网格。
*/
export class RenderingSubMesh {
export class RenderingSubMesh implements IGFXInputAssemblerInfo {
/**
* 使用的所有顶点缓冲区。
*/
+13 -14
View File
@@ -27,7 +27,7 @@ const preferCpuComputing = false;
*/
export class StdMorphRendering implements MorphRendering {
private _mesh: Mesh;
private _subMeshRenderings: Array<SubMeshMorphRendering | null> = [];
private _subMeshRenderings: (SubMeshMorphRendering | null)[] = [];
constructor (mesh: Mesh, gfxDevice: GFXDevice) {
this._mesh = mesh;
@@ -68,7 +68,7 @@ export class StdMorphRendering implements MorphRendering {
public createInstance (): MorphRenderingInstance {
const nSubMeshes = this._mesh.struct.primitives.length;
const subMeshInstances: Array<SubMeshMorphRenderingInstance | null> = new Array(nSubMeshes);
const subMeshInstances: (SubMeshMorphRenderingInstance | null)[] = new Array(nSubMeshes);
for (let iSubMesh = 0; iSubMesh < nSubMeshes; ++iSubMesh) {
subMeshInstances[iSubMesh] = this._subMeshRenderings[iSubMesh]?.createInstance() ?? null;
}
@@ -137,18 +137,18 @@ interface SubMeshMorphRenderingInstance {
/**
* Asks the define overrides needed to do the rendering.
*/
requiredPatches(): IMacroPatch[];
requiredPatches (): IMacroPatch[];
/**
* Adapts the pipelineState to apply the rendering.
* @param pipelineState
*/
adaptPipelineState(pipelineCreateInfo: IPSOCreateInfo): void;
adaptPipelineState (pipelineCreateInfo: IPSOCreateInfo): void;
/**
* Destroy this instance.
*/
destroy(): void;
destroy (): void;
}
/**
@@ -163,11 +163,11 @@ class GpuComputing implements SubMeshMorphRendering {
width: number;
height: number;
};
private _attributes: Array<{
private _attributes: {
name: string;
texture: Texture2D;
sampler: GFXSampler;
}>;
}[];
constructor (mesh: Mesh, subMeshIndex: number, morph: Morph, gfxDevice: GFXDevice) {
this._gfxDevice = gfxDevice;
@@ -195,7 +195,6 @@ class GpuComputing implements SubMeshMorphRendering {
// Creates texture for each attribute.
this._attributes = subMeshMorph.attributes.map((attributeName, attributeIndex) => {
const nTargets = subMeshMorph.targets.length;
const textureInfo = {
displacements: new Array<number>(),
targetOffsets: new Array<number>(nTargets).fill(0),
@@ -206,8 +205,8 @@ class GpuComputing implements SubMeshMorphRendering {
textureInfo.displacements.push(...new Float32Array(meshData, displacements.offset, displacements.count));
});
const pixelStride = 3; // For position, normal, tangent
const pixelFormat = Texture2D.PixelFormat.RGB32F; // For position, normal, tangent
const pixelStride = 4; // For position, normal, tangent
const pixelFormat = Texture2D.PixelFormat.RGBA32F; // For position, normal, tangent
const textureSource = new Float32Array(pixelStride * width * height);
const headPixels = nTargets;
@@ -298,12 +297,12 @@ class GpuComputing implements SubMeshMorphRendering {
*/
class CpuComputing implements SubMeshMorphRendering {
private _gfxDevice: GFXDevice;
private _attributes: Array<{
private _attributes: {
name: string;
targets: Array<{
targets: {
displacements: Float32Array;
}>;
}> = [];
}[];
}[] = [];
constructor (mesh: Mesh, subMeshIndex: number, morph: Morph, gfxDevice: GFXDevice) {
this._gfxDevice = gfxDevice;
+19 -12
View File
@@ -3,13 +3,14 @@
*/
import { ccclass, property } from '../data/class-decorator';
import { GFXFormat, GFXTexture } from '../gfx';
import { GFXFormat, GFXTexture, GFXColorAttachment, GFXDepthStencilAttachment, GFXTextureLayout } from '../gfx';
import { GFXDevice } from '../gfx/device';
import { GFXWindow } from '../gfx/window';
import { ccenum } from '../value-types/enum';
import { DepthStencilFormat, PixelFormat } from './asset-enum';
import { TextureBase } from './texture-base';
import { legacyCC } from '../global-exports';
import { RenderWindow } from '../pipeline';
import { IRenderWindowInfo } from '../pipeline/render-window';
export interface IRenderTextureCreateInfo {
name?: string;
@@ -24,7 +25,7 @@ ccenum(DepthStencilFormat);
@ccclass('cc.RenderTexture')
export class RenderTexture extends TextureBase {
public static DepthStencilFormat = DepthStencilFormat;
private _window: GFXWindow | null = null;
private _window: RenderWindow | null = null;
@property
private _depthStencilFormat: DepthStencilFormat = DepthStencilFormat.NONE;
@@ -65,13 +66,11 @@ export class RenderTexture extends TextureBase {
return this._window;
}
public getGFXTexture (
): GFXTexture | null /* TODO: Explicit since ISSUE https://github.com/microsoft/TypeScript/issues/31280 , changes required once the issue is fixed. */ {
return this._window ? this._window.colorTexture : null;
public getGFXTexture (): GFXTexture | null {
return this._window ? this._window.colorTextures[0] : null;
}
public getGFXStencilTexture (
): GFXTexture | null /* TODO: Explicit since ISSUE https://github.com/microsoft/TypeScript/issues/31280 , changes required once the issue is fixed. */ {
public getGFXStencilTexture (): GFXTexture | null {
return this._window ? this._window.depthStencilTexture : null;
}
@@ -140,16 +139,24 @@ export class RenderTexture extends TextureBase {
}
protected _createWindow (device: GFXDevice) {
const config = {
const colorAttachment = new GFXColorAttachment();
colorAttachment.format = this._format;
colorAttachment.endLayout = GFXTextureLayout.SHADER_READONLY_OPTIMAL;
const depthStencilAttachment = new GFXDepthStencilAttachment();
depthStencilAttachment.format = this._depthStencilFormat as unknown as GFXFormat;
const config: IRenderWindowInfo = {
title: this.name,
isOffscreen: true,
width: this._width,
height: this._height,
colorFmt: this._format,
depthStencilFmt: this._depthStencilFormat as unknown as GFXFormat,
renderPassInfo: {
colorAttachments: [colorAttachment],
depthStencilAttachment,
}
};
if (this._window){
if (this._window) {
this._window.initialize(config);
return this._window;
}
@@ -34,7 +34,6 @@ import { ccclass, help, disallowMultiple, executeInEditMode, executionOrder, men
import { director, Director } from '../../director';
import { game } from '../../game';
import { GFXClearFlag } from '../../gfx/define';
import { GFXWindow } from '../../gfx/window';
import { Color, Vec3, Rect } from '../../math';
import { view } from '../../platform/view';
import visibleRect from '../../platform/visible-rect';
@@ -45,6 +44,7 @@ import { Component } from '../component';
import { UITransformComponent } from './ui-transform-component';
import { EDITOR } from 'internal:constants';
import { legacyCC } from '../../global-exports';
import { RenderWindow } from '../../pipeline';
const _worldPos = new Vec3();
@@ -110,7 +110,7 @@ export class CanvasComponent extends Component {
@property({
tooltip: '清理颜色缓冲区后的颜色',
})
get color() {
get color () {
return this._color;
}
@@ -386,7 +386,7 @@ export class CanvasComponent extends Component {
}
protected _checkTargetTextureEvent (old: RenderTexture | null) {
const resizeFunc = (win: GFXWindow) => {
const resizeFunc = (win: RenderWindow) => {
if (this._camera) {
this._camera.setFixedSize(win.width, win.height);
}
+3 -3
View File
@@ -583,7 +583,7 @@ export class Game extends EventTarget {
}
if (!JSB && !EDITOR && !PREVIEW && legacyCC.internal.SplashScreen) {
legacyCC.internal.SplashScreen.instance.main(this._gfxDevice);
legacyCC.internal.SplashScreen.instance.main(legacyCC.director.root);
}
legacyCC.director.root.dataPoolManager.jointTexturePool.registerCustomTextureLayouts(config.customJointTextureLayouts);
@@ -738,12 +738,12 @@ export class Game extends EventTarget {
window.rAF = window.requestAnimationFrame;
window.cAF = window.cancelAnimationFrame;
}
else {
else {
if (this._intervalId) {
window.cAF(this._intervalId);
this._intervalId = 0;
}
if (frameRate !== 60 && frameRate !== 30) {
window.rAF = this._stTime;
window.cAF = this._ctTime;
-17
View File
@@ -18,7 +18,6 @@ import { GFXRenderPass, IGFXRenderPassInfo } from './render-pass';
import { GFXSampler, IGFXSamplerInfo } from './sampler';
import { GFXShader, IGFXShaderInfo } from './shader';
import { GFXTexture, IGFXTextureInfo, IGFXTextureViewInfo } from './texture';
import { GFXWindow, IGFXWindowInfo } from './window';
ccenum(GFXFormat);
@@ -142,14 +141,6 @@ export abstract class GFXDevice {
return this._nativeHeight;
}
/**
* @en Device main window.
* @zh 设备主窗口。
*/
get mainWindow (): GFXWindow {
return this._mainWindow as GFXWindow;
}
/**
* @en Device command allocator.
* @zh 命令分配器。
@@ -360,7 +351,6 @@ export abstract class GFXDevice {
protected _height: number = 0;
protected _nativeWidth: number = 0;
protected _nativeHeight: number = 0;
protected _mainWindow: GFXWindow | null = null;
protected _cmdAllocator: GFXCommandAllocator | null = null;
protected _maxVertexAttributes: number = 0;
protected _maxVertexUniformVectors: number = 0;
@@ -498,13 +488,6 @@ export abstract class GFXDevice {
*/
public abstract createFence (info: IGFXFenceInfo): GFXFence;
/**
* @en Create window.
* @zh 创建窗口。
* @param info GFX window description info.
*/
public abstract createWindow (info: IGFXWindowInfo): GFXWindow;
/**
* @en Begin current frame.
* @zh 开始当前帧。
-1
View File
@@ -32,7 +32,6 @@ export * from './render-pass';
export * from './sampler';
export * from './shader';
export * from './texture';
export * from './window';
legacyCC.GFXDevice = GFXDevice;
legacyCC.GFXBuffer = GFXBuffer;
+6 -6
View File
@@ -23,8 +23,8 @@ export class GFXColorAttachment {
public loadOp: GFXLoadOp = GFXLoadOp.CLEAR;
public storeOp: GFXStoreOp = GFXStoreOp.STORE;
public sampleCount: number = 1;
public beginLayout: GFXTextureLayout = GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL;
public endLayout: GFXTextureLayout = GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL;
public beginLayout: GFXTextureLayout = GFXTextureLayout.UNDEFINED;
public endLayout: GFXTextureLayout = GFXTextureLayout.PRESENT_SRC;
}
/**
@@ -38,7 +38,7 @@ export class GFXDepthStencilAttachment {
public stencilLoadOp: GFXLoadOp = GFXLoadOp.CLEAR;
public stencilStoreOp: GFXStoreOp = GFXStoreOp.STORE;
public sampleCount: number = 1;
public beginLayout: GFXTextureLayout = GFXTextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
public beginLayout: GFXTextureLayout = GFXTextureLayout.UNDEFINED;
public endLayout: GFXTextureLayout = GFXTextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
}
@@ -52,9 +52,9 @@ export interface IGFXSubPassInfo {
}
export interface IGFXRenderPassInfo {
colorAttachments?: GFXColorAttachment[];
depthStencilAttachment?: GFXDepthStencilAttachment;
subPasses? : IGFXSubPassInfo[];
colorAttachments: GFXColorAttachment[];
depthStencilAttachment: GFXDepthStencilAttachment;
subPasses?: IGFXSubPassInfo[];
}
/**
+3
View File
@@ -81,6 +81,7 @@ export function GFXFormatToWebGLType (format: GFXFormat, gl: WebGLRenderingConte
case GFXFormat.RGB32UI: return gl.UNSIGNED_INT;
case GFXFormat.RGB32I: return gl.INT;
case GFXFormat.BGRA8: return gl.UNSIGNED_BYTE;
case GFXFormat.RGBA8: return gl.UNSIGNED_BYTE;
case GFXFormat.SRGB8_A8: return gl.UNSIGNED_BYTE;
case GFXFormat.RGBA8SN: return gl.BYTE;
@@ -156,6 +157,7 @@ export function GFXFormatToWebGLInternalFormat (format: GFXFormat, gl: WebGLRend
case GFXFormat.RGB8: return gl.RGB;
case GFXFormat.RGB16F: return gl.RGB;
case GFXFormat.RGB32F: return gl.RGB;
case GFXFormat.BGRA8: return gl.RGBA;
case GFXFormat.RGBA8: return gl.RGBA;
case GFXFormat.RGBA16F: return gl.RGBA;
case GFXFormat.RGBA32F: return gl.RGBA;
@@ -210,6 +212,7 @@ export function GFXFormatToWebGLFormat (format: GFXFormat, gl: WebGLRenderingCon
case GFXFormat.RGB8: return gl.RGB;
case GFXFormat.RGB16F: return gl.RGB;
case GFXFormat.RGB32F: return gl.RGB;
case GFXFormat.BGRA8: return gl.RGBA;
case GFXFormat.RGBA8: return gl.RGBA;
case GFXFormat.RGBA16F: return gl.RGBA;
case GFXFormat.RGBA32F: return gl.RGBA;
-22
View File
@@ -29,7 +29,6 @@ import { GFXRenderPass, IGFXRenderPassInfo } from '../render-pass';
import { GFXSampler, IGFXSamplerInfo } from '../sampler';
import { GFXShader, IGFXShaderInfo } from '../shader';
import { GFXTexture, IGFXTextureInfo, IGFXTextureViewInfo } from '../texture';
import { GFXWindow, IGFXWindowInfo } from '../window';
import { WebGLGFXBindingLayout } from './webgl-binding-layout';
import { WebGLGFXBuffer } from './webgl-buffer';
import { WebGLGFXCommandAllocator } from './webgl-command-allocator';
@@ -47,7 +46,6 @@ import { WebGLGFXSampler } from './webgl-sampler';
import { WebGLGFXShader } from './webgl-shader';
import { WebGLStateCache } from './webgl-state-cache';
import { WebGLGFXTexture } from './webgl-texture';
import { WebGLGFXWindow } from './webgl-window';
export class WebGLGFXDevice extends GFXDevice {
@@ -440,15 +438,6 @@ export class WebGLGFXDevice extends GFXDevice {
// create primary window
const canvas = this._webGLRC.canvas as HTMLCanvasElement;
this._mainWindow = this.createWindow({
title: canvas.title || '',
left: canvas.offsetLeft || 0,
top: canvas.offsetTop || 0,
width: this._webGLRC.drawingBufferWidth,
height: this._webGLRC.drawingBufferHeight,
colorFmt: this._colorFmt,
depthStencilFmt: this._depthStencilFmt,
});
this._cmdAllocator = this.createCommandAllocator({});
@@ -518,11 +507,6 @@ export class WebGLGFXDevice extends GFXDevice {
this.nullTexCube = null;
}
if (this._mainWindow) {
this._mainWindow.destroy();
this._mainWindow = null;
}
if (this._cmdAllocator) {
this._cmdAllocator.destroy();
this._cmdAllocator = null;
@@ -632,12 +616,6 @@ export class WebGLGFXDevice extends GFXDevice {
return queue;
}
public createWindow (info: IGFXWindowInfo): GFXWindow {
const window = new WebGLGFXWindow(this);
window.initialize(info);
return window;
}
public acquire () {}
public present () {
+2 -2
View File
@@ -12,8 +12,8 @@ export class WebGLGFXRenderPass extends GFXRenderPass {
public initialize (info: IGFXRenderPassInfo): boolean {
this._colorInfos = info.colorAttachments || [];
this._depthStencilInfo = info.depthStencilAttachment || null;
this._colorInfos = info.colorAttachments;
this._depthStencilInfo = info.depthStencilAttachment;
this._gpuRenderPass = {
colorAttachments: this._colorInfos,
-160
View File
@@ -1,160 +0,0 @@
import {
GFXFormat,
GFXLoadOp,
GFXStoreOp,
GFXTextureFlagBit,
GFXTextureLayout,
GFXTextureType,
GFXTextureUsageBit,
GFXStatus,
} from '../define';
import { GFXWindow, IGFXWindowInfo } from '../window';
import { GFXTexture } from '../../gfx/texture';
export class WebGLGFXWindow extends GFXWindow {
public initialize (info: IGFXWindowInfo): boolean {
if (info.title !== undefined) {
this._title = info.title;
}
if (info.left !== undefined) {
this._left = info.left;
}
if (info.top !== undefined) {
this._top = info.top;
}
if (info.isOffscreen !== undefined) {
this._isOffscreen = info.isOffscreen;
}
this._width = info.width;
this._height = info.height;
this._nativeWidth = this._width;
this._nativeHeight = this._height;
this._colorFmt = info.colorFmt;
this._depthStencilFmt = info.depthStencilFmt;
this._renderPass = this._device.createRenderPass({
colorAttachments: [{
format: this._colorFmt,
loadOp: GFXLoadOp.CLEAR,
storeOp: GFXStoreOp.STORE,
sampleCount: 1,
beginLayout: GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL,
endLayout: GFXTextureLayout.PRESENT_SRC,
}],
depthStencilAttachment: {
format : this._depthStencilFmt,
depthLoadOp : GFXLoadOp.CLEAR,
depthStoreOp : GFXStoreOp.STORE,
stencilLoadOp : GFXLoadOp.CLEAR,
stencilStoreOp : GFXStoreOp.STORE,
sampleCount : 1,
beginLayout : GFXTextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
endLayout : GFXTextureLayout.PRESENT_SRC,
},
});
const colorTextures: GFXTexture[] = [];
if (this._isOffscreen) {
if (this._colorFmt !== GFXFormat.UNKNOWN) {
this._colorTex = this._device.createTexture({
type : GFXTextureType.TEX2D,
usage : GFXTextureUsageBit.COLOR_ATTACHMENT | GFXTextureUsageBit.SAMPLED,
format : this._colorFmt,
width : this._width,
height : this._height,
depth : 1,
arrayLayer : 1,
mipLevel : 1,
flags : GFXTextureFlagBit.NONE,
});
colorTextures.push(this._colorTex);
}
if (this._depthStencilFmt !== GFXFormat.UNKNOWN) {
this._depthStencilTex = this._device.createTexture({
type : GFXTextureType.TEX2D,
usage : GFXTextureUsageBit.DEPTH_STENCIL_ATTACHMENT,
format : this._depthStencilFmt,
width : this._width,
height : this._height,
depth : 1,
arrayLayer : 1,
mipLevel : 1,
flags : GFXTextureFlagBit.NONE,
});
}
}
this._framebuffer = this._device.createFramebuffer({
renderPass: this._renderPass,
colorTextures,
depthStencilTexture: this._depthStencilTex,
isOffscreen: this._isOffscreen,
});
this._status = GFXStatus.SUCCESS;
return true;
}
public destroy () {
if (this._depthStencilTex) {
this._depthStencilTex.destroy();
this._depthStencilTex = null;
}
if (this._colorTex) {
this._colorTex.destroy();
this._colorTex = null;
}
if (this._framebuffer) {
this._framebuffer.destroy();
this._framebuffer = null;
}
if (this._renderPass) {
this._renderPass.destroy();
this._renderPass = null;
}
this._status = GFXStatus.UNREADY;
}
public resize (width: number, height: number) {
this._width = width;
this._height = height;
if (width > this._nativeWidth ||
height > this._nativeHeight) {
this._nativeWidth = width;
this._nativeHeight = height;
if (this._depthStencilTex) {
this._depthStencilTex.resize(width, height);
}
if (this._colorTex) {
this._colorTex.resize(width, height);
}
if (this._framebuffer && this._framebuffer.isOffscreen) {
this._framebuffer.destroy();
this._framebuffer.initialize({
renderPass: this._renderPass!,
colorTextures: [ this._colorTex! ],
depthStencilTexture: this._depthStencilTex!,
});
}
}
}
}
+3
View File
@@ -114,6 +114,7 @@ export function GFXFormatToWebGLType (format: GFXFormat, gl: WebGL2RenderingCont
case GFXFormat.RGB32UI: return gl.UNSIGNED_INT;
case GFXFormat.RGB32I: return gl.INT;
case GFXFormat.BGRA8: return gl.UNSIGNED_BYTE;
case GFXFormat.RGBA8: return gl.UNSIGNED_BYTE;
case GFXFormat.SRGB8_A8: return gl.UNSIGNED_BYTE;
case GFXFormat.RGBA8SN: return gl.BYTE;
@@ -198,6 +199,7 @@ export function GFXFormatToWebGLInternalFormat (format: GFXFormat, gl: WebGL2Ren
case GFXFormat.RGB8SN: return gl.RGB8_SNORM;
case GFXFormat.RGB8UI: return gl.RGB8UI;
case GFXFormat.RGB8I: return gl.RGB8I;
case GFXFormat.BGRA8: return gl.RGBA8;
case GFXFormat.RGBA8: return gl.RGBA8;
case GFXFormat.RGBA8SN: return gl.RGBA8_SNORM;
case GFXFormat.RGBA8UI: return gl.RGBA8UI;
@@ -289,6 +291,7 @@ export function GFXFormatToWebGLFormat (format: GFXFormat, gl: WebGL2RenderingCo
case GFXFormat.RGB8SN:
case GFXFormat.RGB8UI:
case GFXFormat.RGB8I: return gl.RGB;
case GFXFormat.BGRA8:
case GFXFormat.RGBA8:
case GFXFormat.RGBA8SN:
case GFXFormat.RGBA8UI:
-25
View File
@@ -27,7 +27,6 @@ import { GFXRenderPass, IGFXRenderPassInfo } from '../render-pass';
import { GFXSampler, IGFXSamplerInfo } from '../sampler';
import { GFXShader, IGFXShaderInfo } from '../shader';
import { GFXTexture, IGFXTextureInfo, IGFXTextureViewInfo } from '../texture';
import { GFXWindow, IGFXWindowInfo } from '../window';
import { WebGL2GFXBindingLayout } from './webgl2-binding-layout';
import { WebGL2GFXBuffer } from './webgl2-buffer';
import { WebGL2GFXCommandAllocator } from './webgl2-command-allocator';
@@ -48,7 +47,6 @@ import { WebGL2GFXSampler } from './webgl2-sampler';
import { WebGL2GFXShader } from './webgl2-shader';
import { WebGL2StateCache } from './webgl2-state-cache';
import { WebGL2GFXTexture } from './webgl2-texture';
import { WebGL2GFXWindow } from './webgl2-window';
export class WebGL2GFXDevice extends GFXDevice {
@@ -328,18 +326,6 @@ export class WebGL2GFXDevice extends GFXDevice {
// create queue
this._queue = this.createQueue({ type: GFXQueueType.GRAPHICS });
// create primary window
const canvas = this._webGL2RC.canvas as HTMLCanvasElement;
this._mainWindow = this.createWindow({
title: canvas.title || '',
left: canvas.offsetLeft || 0,
top: canvas.offsetTop || 0,
width: this._webGL2RC.drawingBufferWidth,
height: this._webGL2RC.drawingBufferHeight,
colorFmt: this._colorFmt,
depthStencilFmt: this._depthStencilFmt,
});
this._cmdAllocator = this.createCommandAllocator({});
// create default null texture
@@ -408,11 +394,6 @@ export class WebGL2GFXDevice extends GFXDevice {
this.nullTexCube = null;
}
if (this._mainWindow) {
this._mainWindow.destroy();
this._mainWindow = null;
}
if (this._cmdAllocator) {
this._cmdAllocator.destroy();
this._cmdAllocator = null;
@@ -522,12 +503,6 @@ export class WebGL2GFXDevice extends GFXDevice {
return queue;
}
public createWindow (info: IGFXWindowInfo): GFXWindow {
const window = new WebGL2GFXWindow(this);
window.initialize(info);
return window;
}
public acquire () {}
public present () {
+2 -2
View File
@@ -12,8 +12,8 @@ export class WebGL2GFXRenderPass extends GFXRenderPass {
public initialize (info: IGFXRenderPassInfo): boolean {
this._colorInfos = info.colorAttachments || [];
this._depthStencilInfo = info.depthStencilAttachment || null;
this._colorInfos = info.colorAttachments;
this._depthStencilInfo = info.depthStencilAttachment;
this._gpuRenderPass = {
colorAttachments: this._colorInfos,
-160
View File
@@ -1,160 +0,0 @@
import {
GFXFormat,
GFXLoadOp,
GFXStoreOp,
GFXTextureFlagBit,
GFXTextureLayout,
GFXTextureType,
GFXTextureUsageBit,
GFXStatus,
} from '../define';
import { GFXTexture } from '../../gfx/texture';
import { GFXWindow, IGFXWindowInfo } from '../window';
export class WebGL2GFXWindow extends GFXWindow {
public initialize (info: IGFXWindowInfo): boolean {
if (info.title !== undefined) {
this._title = info.title;
}
if (info.left !== undefined) {
this._left = info.left;
}
if (info.top !== undefined) {
this._top = info.top;
}
if (info.isOffscreen !== undefined) {
this._isOffscreen = info.isOffscreen;
}
this._width = info.width;
this._height = info.height;
this._nativeWidth = this._width;
this._nativeHeight = this._height;
this._colorFmt = info.colorFmt;
this._depthStencilFmt = info.depthStencilFmt;
this._renderPass = this._device.createRenderPass({
colorAttachments: [{
format: this._colorFmt,
loadOp: GFXLoadOp.CLEAR,
storeOp: GFXStoreOp.STORE,
sampleCount: 1,
beginLayout: GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL,
endLayout: GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL,
}],
depthStencilAttachment: {
format : this._depthStencilFmt,
depthLoadOp : GFXLoadOp.CLEAR,
depthStoreOp : GFXStoreOp.STORE,
stencilLoadOp : GFXLoadOp.CLEAR,
stencilStoreOp : GFXStoreOp.STORE,
sampleCount : 1,
beginLayout : GFXTextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
endLayout : GFXTextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
},
});
const colorTextures: GFXTexture[] = [];
if (this._isOffscreen) {
if (this._colorFmt !== GFXFormat.UNKNOWN) {
this._colorTex = this._device.createTexture({
type : GFXTextureType.TEX2D,
usage : GFXTextureUsageBit.COLOR_ATTACHMENT | GFXTextureUsageBit.SAMPLED,
format : this._colorFmt,
width : this._width,
height : this._height,
depth : 1,
arrayLayer : 1,
mipLevel : 1,
flags : GFXTextureFlagBit.NONE,
});
colorTextures.push(this._colorTex);
}
if (this._depthStencilFmt !== GFXFormat.UNKNOWN) {
this._depthStencilTex = this._device.createTexture({
type : GFXTextureType.TEX2D,
usage : GFXTextureUsageBit.DEPTH_STENCIL_ATTACHMENT,
format : this._depthStencilFmt,
width : this._width,
height : this._height,
depth : 1,
arrayLayer : 1,
mipLevel : 1,
flags : GFXTextureFlagBit.NONE,
});
}
}
this._framebuffer = this._device.createFramebuffer({
renderPass: this._renderPass,
colorTextures,
depthStencilTexture: this._depthStencilTex,
isOffscreen: this._isOffscreen,
});
this._status = GFXStatus.SUCCESS;
return true;
}
public destroy () {
if (this._depthStencilTex) {
this._depthStencilTex.destroy();
this._depthStencilTex = null;
}
if (this._colorTex) {
this._colorTex.destroy();
this._colorTex = null;
}
if (this._framebuffer) {
this._framebuffer.destroy();
this._framebuffer = null;
}
if (this._renderPass) {
this._renderPass.destroy();
this._renderPass = null;
}
this._status = GFXStatus.UNREADY;
}
public resize (width: number, height: number) {
this._width = width;
this._height = height;
if (width > this._nativeWidth ||
height > this._nativeHeight) {
this._nativeWidth = width;
this._nativeHeight = height;
if (this._depthStencilTex) {
this._depthStencilTex.resize(width, height);
}
if (this._colorTex) {
this._colorTex.resize(width, height);
}
if (this._framebuffer && this._framebuffer.isOffscreen) {
this._framebuffer.destroy();
this._framebuffer.initialize({
renderPass: this._renderPass!,
colorTextures: [ this._colorTex! ],
depthStencilTexture: this._depthStencilTex!,
});
}
}
}
}
-132
View File
@@ -1,132 +0,0 @@
/**
* @category gfx
*/
import { GFXFormat, GFXObject, GFXObjectType } from './define';
import { GFXDevice } from './device';
import { GFXFramebuffer } from './framebuffer';
import { GFXRenderPass } from './render-pass';
import { GFXTexture } from './texture';
export interface IGFXWindowInfo {
title?: string;
left?: number;
top?: number;
width: number;
height: number;
colorFmt: GFXFormat;
depthStencilFmt: GFXFormat;
isOffscreen?: boolean;
}
/**
* @en GFX window.
* @zh GFX 窗口。
*/
export abstract class GFXWindow extends GFXObject {
/**
* @en Get window width.
* @zh 窗口宽度。
*/
get width (): number {
return this._width;
}
/**
* @en Get window height.
* @zh 窗口高度。
*/
get height (): number {
return this._height;
}
/**
* @en Get window color format.
* @zh 窗口颜色格式。
*/
get colorFormat (): GFXFormat {
return this._colorFmt;
}
/**
* @en Get window depth stencil format.
* @zh 窗口深度模板格式。
*/
get detphStencilFormat (): GFXFormat {
return this._depthStencilFmt;
}
/**
* @en Is this window offscreen?
* @zh 是否是离屏的。
*/
get isOffscreen (): boolean {
return this._isOffscreen;
}
/**
* @en Get the render pass of this window.
* @zh GFX 渲染过程。
*/
get renderPass (): GFXRenderPass {
return this._renderPass!;
}
/**
* @en Get color texture of this window.
* @zh 颜色纹理。
*/
get colorTexture (): GFXTexture | null {
return this._colorTex;
}
/**
* @en Get depth stencil texture of this window.
* @zh 深度模板纹理。
*/
get depthStencilTexture (): GFXTexture | null {
return this._depthStencilTex;
}
/**
* @en Get window frame buffer.
* @zh GFX帧缓冲。
*/
get framebuffer (): GFXFramebuffer {
return this._framebuffer!;
}
protected _device: GFXDevice;
protected _title: string = '';
protected _left: number = 0;
protected _top: number = 0;
protected _width: number = 0;
protected _height: number = 0;
protected _nativeWidth: number = 0;
protected _nativeHeight: number = 0;
protected _colorFmt: GFXFormat = GFXFormat.UNKNOWN;
protected _depthStencilFmt: GFXFormat = GFXFormat.UNKNOWN;
protected _isOffscreen: boolean = false;
protected _renderPass: GFXRenderPass | null = null;
protected _colorTex: GFXTexture | null = null;
protected _depthStencilTex: GFXTexture | null = null;
protected _framebuffer: GFXFramebuffer | null = null;
constructor (device: GFXDevice) {
super(GFXObjectType.WINDOW);
this._device = device;
}
public abstract initialize (info: IGFXWindowInfo): boolean;
public abstract destroy (): void;
/**
* @en Resize window.
* @zh 重置窗口大小。
* @param width The new width.
* @param height The new height.
*/
public abstract resize (width: number, height: number): void;
}
+1
View File
@@ -9,6 +9,7 @@ export { RenderPipeline } from './render-pipeline';
export { RenderFlow } from './render-flow';
export { RenderStage } from './render-stage';
export { RenderView } from './render-view';
export { RenderWindow } from './render-window';
export { ForwardPipeline } from './forward/forward-pipeline';
export { ForwardFlow } from './forward/forward-flow';
+12 -1
View File
@@ -26,10 +26,21 @@ export class PipelineStateManager {
const newHash = hash1 ^ hash2 ^ hash3;
let pso = this._PSOHashMap.get(newHash);
if (!pso) {
this._inputState.attributes = ia.attributes;
const pipelineLayout = device.createPipelineLayout({
layouts: [psoCreateInfo.bindingLayout]
});
const iaAttrs = this._inputState.attributes = ia.attributes;
const shaderAttrs = psoCreateInfo.shaderInput.attributes;
for (let i = 0; i < iaAttrs.length; i++) {
const attr = iaAttrs[i]; let j = 0;
for (; j < shaderAttrs.length; j++) {
const shaderAttr = shaderAttrs[j];
if (shaderAttr.name === attr.name) {
attr.location = shaderAttr.location;
break;
}
}
}
pso = device.createPipelineState({
primitive: psoCreateInfo.primitive,
shader: psoCreateInfo.shader,
+3 -11
View File
@@ -720,15 +720,7 @@ export abstract class RenderPipeline {
this._colorFmt = GFXFormat.RGBA8;
}
if (this._device.depthBits === 24) {
if (this._device.stencilBits === 8) {
this._depthStencilFmt = GFXFormat.D24S8;
} else {
this._depthStencilFmt = GFXFormat.D24;
}
} else {
this._depthStencilFmt = GFXFormat.D16;
}
this._depthStencilFmt = this._device.depthStencilFormat;
// colorFmt = GFXFormat.RGBA16F;
@@ -769,7 +761,7 @@ export abstract class RenderPipeline {
format: this._getTextureFormat(rtd.format, rtd.usage),
width: rtd.width,
height: rtd.height,
//FIXME: need other args?
// FIXME: need other args?
}));
}
for (let i = 0; i < this.renderPasses.length; i++) {
@@ -801,7 +793,7 @@ export abstract class RenderPipeline {
this._frameBuffers.set(fbd.name, this._device.createFramebuffer({
renderPass: rp,
colorTextures: ts,
colorMipmapLevels: colorMipmapLevels,
colorMipmapLevels,
depthStencilTexture: dsv,
depStencilMipmapLevel: 0,
}));
+1 -1
View File
@@ -86,7 +86,7 @@ export class RenderQueue {
const hash = (0 << 30) | pass.priority << 16 | subModel.priority << 8 | passIdx;
const rp = this._passPool.add();
rp.hash = hash;
rp.depth = renderObj.depth;
rp.depth = renderObj.depth || 0;
rp.shaderId = psoCreateInfo.shader.id;
rp.subModel = subModel;
rp.passIdx = passIdx;
-2
View File
@@ -235,8 +235,6 @@ export abstract class RenderStage {
throw new Error('');
}
this._device = this._flow.pipeline.root.device;
this._clearColors = [{ r: 0.3, g: 0.6, b: 0.9, a: 1.0 }];
this._renderArea = { x: 0, y: 0, width: 0, height: 0 };
+2 -2
View File
@@ -2,13 +2,13 @@
* @category pipeline
*/
import { GFXWindow } from '../gfx/window';
import { Camera } from '../renderer/scene/camera';
import { Root } from '../root';
import { CAMERA_DEFAULT_MASK } from './define';
import { RenderFlowType } from './pipeline-serialization';
import { RenderFlow } from './render-flow';
import { legacyCC } from '../global-exports';
import { RenderWindow } from './render-window';
/**
* @zh
@@ -134,7 +134,7 @@ export class RenderView {
* @zh
* GFX窗口。
*/
private _window: GFXWindow | null = null;
private _window: RenderWindow | null = null;
/**
* @zh
+239
View File
@@ -0,0 +1,239 @@
import {
GFXFormat,
GFXTextureFlagBit,
GFXTextureType,
GFXTextureUsageBit,
} from '../gfx/define';
import { GFXRenderPass, GFXTexture, GFXFramebuffer, IGFXRenderPassInfo } from '../gfx';
import { Root } from '../root';
export interface IRenderWindowInfo {
title?: string;
left?: number;
top?: number;
width: number;
height: number;
renderPassInfo: IGFXRenderPassInfo;
isOffscreen?: boolean;
}
export class RenderWindow {
/**
* @en Get window width.
* @zh 窗口宽度。
*/
get width (): number {
return this._width;
}
/**
* @en Get window height.
* @zh 窗口高度。
*/
get height (): number {
return this._height;
}
/**
* @en Is this window offscreen?
* @zh 是否是离屏的。
*/
get isOffscreen (): boolean {
return this._isOffscreen;
}
/**
* @en Get the render pass of this window.
* @zh GFX 渲染过程。
*/
get renderPass (): GFXRenderPass {
return this._renderPass!;
}
/**
* @en Get color texture of this window.
* @zh 颜色纹理。
*/
get colorTextures (): GFXTexture[] {
return this._colorTexs;
}
/**
* @en Get depth stencil texture of this window.
* @zh 深度模板纹理。
*/
get depthStencilTexture (): GFXTexture | null {
return this._depthStencilTex;
}
/**
* @en Get window frame buffer.
* @zh GFX帧缓冲。
*/
get framebuffer (): GFXFramebuffer {
return this._framebuffer!;
}
public static registerCreateFunc (root: Root) {
root._createWindowFun = (_root: Root): RenderWindow => new RenderWindow(_root);
}
protected _root: Root;
protected _title: string = '';
protected _left: number = 0;
protected _top: number = 0;
protected _width: number = 0;
protected _height: number = 0;
protected _nativeWidth: number = 0;
protected _nativeHeight: number = 0;
protected _isOffscreen: boolean = false;
protected _renderPass: GFXRenderPass | null = null;
protected _colorTexs: GFXTexture[] = [];
protected _depthStencilTex: GFXTexture | null = null;
protected _framebuffer: GFXFramebuffer | null = null;
private constructor (root: Root) {
this._root = root;
}
public initialize (info: IRenderWindowInfo): boolean {
if (info.title !== undefined) {
this._title = info.title;
}
if (info.left !== undefined) {
this._left = info.left;
}
if (info.top !== undefined) {
this._top = info.top;
}
if (info.isOffscreen !== undefined) {
this._isOffscreen = info.isOffscreen;
}
this._width = info.width;
this._height = info.height;
this._nativeWidth = this._width;
this._nativeHeight = this._height;
for (let i = 0; i < info.renderPassInfo.colorAttachments.length; i++) {
const attachment = info.renderPassInfo.colorAttachments[i];
if (attachment.format === GFXFormat.UNKNOWN) {
attachment.format = this._root.device.colorFormat;
}
}
if (info.renderPassInfo.depthStencilAttachment) {
const attachment = info.renderPassInfo.depthStencilAttachment;
if (attachment.format === GFXFormat.UNKNOWN) {
attachment.format = this._root.device.depthStencilFormat;
}
}
this._renderPass = this._root.device.createRenderPass(info.renderPassInfo);
let colorTexturesToCreate = info.renderPassInfo.colorAttachments.length;
if (!this._isOffscreen) { colorTexturesToCreate--; } // -1 for swapchain image
for (let i = 0; i < colorTexturesToCreate; i++) {
const format = info.renderPassInfo.colorAttachments[i].format;
const colorTex = this._root.device.createTexture({
type: GFXTextureType.TEX2D,
usage: GFXTextureUsageBit.COLOR_ATTACHMENT | GFXTextureUsageBit.SAMPLED,
format,
width: this._width,
height: this._height,
depth: 1,
arrayLayer: 1,
mipLevel: 1,
flags: GFXTextureFlagBit.NONE,
});
this._colorTexs.push(colorTex);
}
if (this._isOffscreen && info.renderPassInfo.depthStencilAttachment) {
const format = info.renderPassInfo.depthStencilAttachment.format;
this._depthStencilTex = this._root.device.createTexture({
type: GFXTextureType.TEX2D,
usage: GFXTextureUsageBit.DEPTH_STENCIL_ATTACHMENT,
format,
width: this._width,
height: this._height,
depth: 1,
arrayLayer: 1,
mipLevel: 1,
flags: GFXTextureFlagBit.NONE,
});
}
this._framebuffer = this._root.device.createFramebuffer({
renderPass: this._renderPass,
colorTextures: this._colorTexs,
depthStencilTexture: this._depthStencilTex,
isOffscreen: this._isOffscreen,
});
return true;
}
public destroy () {
if (this._depthStencilTex) {
this._depthStencilTex.destroy();
this._depthStencilTex = null;
}
for (let i = 0; i < this._colorTexs.length; i++) {
if (this._colorTexs[i]) {
this._colorTexs[i].destroy();
}
}
this._colorTexs.length = 0;
if (this._framebuffer) {
this._framebuffer.destroy();
this._framebuffer = null;
}
if (this._renderPass) {
this._renderPass.destroy();
this._renderPass = null;
}
}
/**
* @en Resize window.
* @zh 重置窗口大小。
* @param width The new width.
* @param height The new height.
*/
public resize (width: number, height: number) {
this._width = width;
this._height = height;
if (width > this._nativeWidth ||
height > this._nativeHeight) {
this._nativeWidth = width;
this._nativeHeight = height;
if (this._depthStencilTex) {
this._depthStencilTex.resize(width, height);
}
for (let i = 0; i < this._colorTexs.length; i++) {
if (this._colorTexs[i]) {
this._colorTexs[i].resize(width, height);
}
}
if (this._framebuffer && this._framebuffer.isOffscreen) {
this._framebuffer.destroy();
this._framebuffer.initialize({
renderPass: this._renderPass!,
colorTextures: this._colorTexs,
depthStencilTexture: this._depthStencilTex!,
});
}
}
}
}
+41 -3
View File
@@ -3,10 +3,11 @@
*/
import { GFXCommandBuffer } from '../../gfx/command-buffer';
import { GFXCommandBufferType, IGFXColor } from '../../gfx/define';
import { GFXCommandBufferType, IGFXColor, GFXLoadOp, GFXStoreOp, GFXTextureLayout } from '../../gfx/define';
import { RenderFlow } from '../render-flow';
import { IRenderStageInfo, RenderQueueSortMode, RenderStage } from '../render-stage';
import { RenderView } from '../render-view';
import { legacyCC } from '../../global-exports';
const bufs: GFXCommandBuffer[] = [];
const colors: IGFXColor[] = [];
@@ -31,10 +32,45 @@ export class UIStage extends RenderStage {
public activate (flow: RenderFlow) {
super.activate(flow);
this.createCmdBuffer();
const device = this._device!;
// UI uses a exclusive render pass
const renderPass = device.createRenderPass({
colorAttachments: [{
format: device.colorFormat,
loadOp: GFXLoadOp.LOAD, // shouldn't clear color attachment
storeOp: GFXStoreOp.STORE,
sampleCount: 1,
beginLayout: GFXTextureLayout.PRESENT_SRC,
endLayout: GFXTextureLayout.PRESENT_SRC,
}],
depthStencilAttachment: {
format : device.depthStencilFormat,
depthLoadOp : GFXLoadOp.CLEAR,
depthStoreOp : GFXStoreOp.STORE,
stencilLoadOp : GFXLoadOp.CLEAR,
stencilStoreOp : GFXStoreOp.STORE,
sampleCount : 1,
beginLayout : GFXTextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
endLayout : GFXTextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
},
});
this._framebuffer = device.createFramebuffer({
renderPass,
colorTextures: [],
depthStencilTexture: null,
isOffscreen: false
});
}
public destroy () {
if (this._framebuffer) {
this._framebuffer.renderPass!.destroy();
this._framebuffer.destroy();
}
if (this._cmdBuff) {
this._cmdBuff.destroy();
this._cmdBuff = null;
@@ -60,8 +96,10 @@ export class UIStage extends RenderStage {
}
this._renderQueues[0].sort();
const framebuffer = view.window!.framebuffer;
let framebuffer = view.window!.framebuffer;
if (!framebuffer.isOffscreen) {
framebuffer = this._framebuffer!;
}
const cmdBuff = this._cmdBuff!;
const camera = view.camera!;
+3 -3
View File
@@ -1,6 +1,5 @@
import { frustum, ray } from '../../geometry';
import { GFXClearFlag, IGFXColor } from '../../gfx/define';
import { GFXWindow } from '../../gfx/window';
import { lerp, Mat4, Rect, toRadian, Vec3 } from '../../math';
import { CAMERA_DEFAULT_MASK } from '../../pipeline/define';
import { RenderView } from '../../pipeline/render-view';
@@ -8,6 +7,7 @@ import { Node } from '../../scene-graph';
import { RenderScene } from './render-scene';
import { GFXDevice } from '../../gfx';
import { legacyCC } from '../../global-exports';
import { RenderWindow } from '../../pipeline';
export enum CameraFOVAxis {
VERTICAL,
@@ -78,7 +78,7 @@ export interface ICameraInfo {
node: Node;
projection: number;
targetDisplay?: number;
window?: GFXWindow | null;
window?: RenderWindow | null;
priority: number;
pipeline?: string;
flows?: string[];
@@ -524,7 +524,7 @@ export class Camera {
}
}
public changeTargetWindow (window: GFXWindow | null = null) {
public changeTargetWindow (window: RenderWindow | null = null) {
const win = window || legacyCC.director.root.mainWindow;
if (win && this._view) {
this._view.window = win;
+32 -37
View File
@@ -4,22 +4,19 @@
import { builtinResMgr } from './3d/builtin';
import { GFXDevice } from './gfx/device';
import { GFXWindow, IGFXWindowInfo } from './gfx/window';
import { Pool } from './memop';
import { RenderPipeline } from './pipeline/render-pipeline';
import { IRenderViewInfo, RenderView } from './pipeline/render-view';
import { Camera, Light, Model } from './renderer';
import { DataPoolManager } from './renderer/data-pool-manager';
import { DirectionalLight } from './renderer/scene/directional-light';
import { LightType } from './renderer/scene/light';
import { IRenderSceneInfo, RenderScene } from './renderer/scene/render-scene';
import { SphereLight } from './renderer/scene/sphere-light';
import { SpotLight } from './renderer/scene/spot-light';
import { UI } from './renderer/ui/ui';
import { legacyCC } from './global-exports';
export let _createSceneFun;
export let _createViewFun;
import { RenderWindow, IRenderWindowInfo } from './pipeline/render-window';
import { GFXColorAttachment, GFXDepthStencilAttachment } from './gfx/render-pass';
/**
* @zh
@@ -55,7 +52,7 @@ export class Root {
* @zh
* 主窗口
*/
public get mainWindow (): GFXWindow | null {
public get mainWindow (): RenderWindow | null {
return this._mainWindow;
}
@@ -63,11 +60,11 @@ export class Root {
* @zh
* 当前窗口
*/
public set curWindow (window: GFXWindow | null) {
public set curWindow (window: RenderWindow | null) {
this._curWindow = window;
}
public get curWindow (): GFXWindow | null {
public get curWindow (): RenderWindow | null {
return this._curWindow;
}
@@ -75,11 +72,11 @@ export class Root {
* @zh
* 临时窗口(用于数据传输)
*/
public set tempWindow (window: GFXWindow | null) {
public set tempWindow (window: RenderWindow | null) {
this._tempWindow = window;
}
public get tempWindow (): GFXWindow | null {
public get tempWindow (): RenderWindow | null {
return this._tempWindow;
}
@@ -87,7 +84,7 @@ export class Root {
* @zh
* 窗口列表
*/
public get windows (): GFXWindow[] {
public get windows (): RenderWindow[] {
return this._windows;
}
@@ -176,14 +173,15 @@ export class Root {
return this._dataPoolMgr;
}
public _createSceneFun;
public _createViewFun;
public _createSceneFun: (root: Root) => RenderScene = null!;
public _createViewFun: (root: Root, camera: Camera) => RenderView = null!;
public _createWindowFun: (root: Root) => RenderWindow = null!;
private _device: GFXDevice;
private _windows: GFXWindow[] = [];
private _mainWindow: GFXWindow | null = null;
private _curWindow: GFXWindow | null = null;
private _tempWindow: GFXWindow | null = null;
private _windows: RenderWindow[] = [];
private _mainWindow: RenderWindow | null = null;
private _curWindow: RenderWindow | null = null;
private _tempWindow: RenderWindow | null = null;
private _pipeline: RenderPipeline | null = null;
private _ui: UI | null = null;
private _dataPoolMgr: DataPoolManager;
@@ -192,9 +190,6 @@ export class Root {
private _modelPools: Map<Function, Pool<any>> = new Map<Function, Pool<any>>();
private _cameraPool: Pool<Camera> | null = null;
private _lightPools: Map<Function, Pool<any>> = new Map<Function, Pool<any>>();
private _directLightPool: Pool<DirectionalLight> | null = null;
private _sphereLightPool: Pool<SphereLight> | null = null;
private _spotLightPool: Pool<SpotLight> | null = null;
private _time: number = 0;
private _frameTime: number = 0;
private _fpsTime: number = 0;
@@ -213,6 +208,7 @@ export class Root {
RenderScene.registerCreateFunc(this);
RenderView.registerCreateFunc(this);
RenderWindow.registerCreateFunc(this);
this._cameraPool = new Pool(() => new Camera(this._device), 4);
}
@@ -224,11 +220,15 @@ export class Root {
*/
public initialize (info: IRootInfo): boolean {
if (!this._device.mainWindow) {
return false;
}
this._mainWindow = this._device.mainWindow;
this._mainWindow = this.createWindow({
title: 'rootMainWindow',
width: this._device.width,
height: this._device.height,
renderPassInfo: {
colorAttachments: [ new GFXColorAttachment() ],
depthStencilAttachment: new GFXDepthStencilAttachment(),
},
});
this._curWindow = this._mainWindow;
builtinResMgr.initBuiltinRes(this._device);
@@ -310,7 +310,7 @@ export class Root {
* 激活指定窗口为当前窗口
* @param window GFX窗口
*/
public activeWindow (window: GFXWindow) {
public activeWindow (window: RenderWindow) {
this._curWindow = window;
}
@@ -371,16 +371,11 @@ export class Root {
* 创建窗口
* @param info GFX窗口描述信息
*/
public createWindow (info: IGFXWindowInfo): GFXWindow | null {
if (this._device) {
const window = this._device.createWindow(info);
if (window) {
this._windows.push(window);
return window;
}
}
return null;
public createWindow (info: IRenderWindowInfo): RenderWindow | null {
const window = this._createWindowFun(this);
window.initialize(info);
this._windows.push(window);
return window;
}
/**
@@ -388,7 +383,7 @@ export class Root {
* 销毁指定的窗口
* @param window GFX窗口
*/
public destroyWindow (window: GFXWindow) {
public destroyWindow (window: RenderWindow) {
for (let i = 0; i < this._windows.length; ++i) {
if (this._windows[i] === window) {
window.destroy();
+7 -4
View File
@@ -21,6 +21,7 @@ import { GFXSampler } from './gfx';
import { IPSOCreateInfo } from './renderer';
import { PipelineStateManager } from './pipeline/pipeline-state-manager';
import { legacyCC } from './global-exports';
import { Root } from './root';
export type SplashEffectType = 'NONE' | 'FADE-INOUT';
@@ -49,6 +50,7 @@ export class SplashScreen {
private startTime: number = -1;
private setting!: ISplashSetting;
private image!: TexImageSource;
private root!: Root;
private device!: GFXDevice;
private sampler!: GFXSampler;
private cmdBuff!: GFXCommandBuffer;
@@ -80,8 +82,8 @@ export class SplashScreen {
private screenWidth!: number;
private screenHeight!: number;
public main (device: GFXDevice) {
if (device == null) return console.error('GFX DEVICE IS NULL.');
public main (root: Root) {
if (root == null) return console.error('RENDER ROOT IS NULL.');
if (window._CCSettings && window._CCSettings.splashScreen) {
this.setting = window._CCSettings.splashScreen;
@@ -116,7 +118,8 @@ export class SplashScreen {
} else {
legacyCC.view.setDesignResolutionSize(960, 640, 4);
}
this.device = device;
this.root = root;
this.device = root.device;
legacyCC.game.once(legacyCC.Game.EVENT_GAME_INITED, () => {
legacyCC.director._lateUpdate = performance.now();
}, legacyCC.director);
@@ -386,7 +389,7 @@ export class SplashScreen {
private initCMD () {
const device = this.device as GFXDevice;
this.renderArea = { x: 0, y: 0, width: device.width, height: device.height };
this.framebuffer = device.mainWindow.framebuffer;
this.framebuffer = this.root.mainWindow!.framebuffer;
this.cmdBuff = device.createCommandBuffer({
allocator: device.commandAllocator,
+1 -6
View File
@@ -300,12 +300,6 @@ export class Profiler {
}
}
// device NDC correction
const ySign = this._device!.projectionSignY;
for (let i = 1; i < vertexPos.length; i += 3) {
vertexPos[i] *= ySign;
}
const modelCom = managerNode.addComponent('cc.ModelComponent') as ModelComponent;
modelCom.mesh = createMesh({
positions: vertexPos,
@@ -313,6 +307,7 @@ export class Profiler {
colors: vertexUV, // pack all the necessary info in a_color: { x: u, y: v, z: id.x, w: id.y }
});
const ySign = this._device!.projectionSignY;
const _material = new Material();
_material.initialize({ effectName: 'util/profiler' });
_material.setProperty('offset', new Vec4(-0.9, -0.9 * ySign, this._eachNumWidth, 0));