mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-05 11:02:40 +08:00
dfc3d141f2
* gfx: descriptor sets * gfx: descriptor set, singular * better structure * adapt upper layers: first pass finally all compiler errors cleared. OKAY IT'S HAPPENING EVERYBODY STAY THE ****ING CALM * adapt upper layers: second pass THERE AND BACK AGAIN * unified light pass & shadow shader * gfx: descriptor set & pipeline layout * light pass: better structure * light pass: dynamic uniform * even more type checking for memory pools * Fix particleSystem and lineComponent. * delete comment * guard pool init param * Fix trail module error. * delete space * light pass: instancing & batching support * don't polyfill gfx stuff inside EffectAsset * better light pass structure * fix spot light culling Co-authored-by: caryliu <caryliu1999@gmail.com>
67 lines
2.6 KiB
TypeScript
67 lines
2.6 KiB
TypeScript
import { GFXFramebuffer, IGFXFramebufferInfo } from '../framebuffer';
|
|
import { WebGL2CmdFuncCreateFramebuffer, WebGL2CmdFuncDestroyFramebuffer } from './webgl2-commands';
|
|
import { WebGL2Device } from './webgl2-device';
|
|
import { IWebGL2GPUFramebuffer, IWebGL2GPUTexture } from './webgl2-gpu-objects';
|
|
import { WebGL2RenderPass } from './webgl2-render-pass';
|
|
import { WebGL2Texture } from './webgl2-texture';
|
|
|
|
export class WebGL2Framebuffer extends GFXFramebuffer {
|
|
|
|
get gpuFramebuffer (): IWebGL2GPUFramebuffer {
|
|
return this._gpuFramebuffer!;
|
|
}
|
|
|
|
private _gpuFramebuffer: IWebGL2GPUFramebuffer | null = null;
|
|
|
|
public initialize (info: IGFXFramebufferInfo): boolean {
|
|
|
|
this._renderPass = info.renderPass;
|
|
this._colorTextures = info.colorTextures || [];
|
|
this._depthStencilTexture = info.depthStencilTexture || null;
|
|
|
|
if (info.depStencilMipmapLevel && info.depStencilMipmapLevel !== 0) {
|
|
console.warn('The mipmap level of th texture image to be attached of depth stencil attachment should be 0. Convert to 0.');
|
|
}
|
|
if (info.colorMipmapLevels && info.colorMipmapLevels.length > 0) {
|
|
for (let i = 0; i < info.colorMipmapLevels.length; ++i) {
|
|
if (info.colorMipmapLevels[i] !== 0) {
|
|
console.warn(`The mipmap level of th texture image to be attached of color attachment ${i} should be 0. Convert to 0.`);
|
|
}
|
|
}
|
|
}
|
|
|
|
const gpuColorTextures: IWebGL2GPUTexture[] = [];
|
|
if (info.colorTextures !== undefined) {
|
|
for (let i = 0; i < info.colorTextures.length; i++) {
|
|
const colorTexture = info.colorTextures[i];
|
|
if (colorTexture) {
|
|
gpuColorTextures.push((colorTexture as WebGL2Texture).gpuTexture);
|
|
}
|
|
}
|
|
}
|
|
|
|
let gpuDepthStencilTexture: IWebGL2GPUTexture | null = null;
|
|
if (info.depthStencilTexture) {
|
|
gpuDepthStencilTexture = (info.depthStencilTexture as WebGL2Texture).gpuTexture;
|
|
}
|
|
|
|
this._gpuFramebuffer = {
|
|
gpuRenderPass: (info.renderPass as WebGL2RenderPass).gpuRenderPass,
|
|
gpuColorTextures,
|
|
gpuDepthStencilTexture,
|
|
glFramebuffer: null,
|
|
};
|
|
|
|
WebGL2CmdFuncCreateFramebuffer(this._device as WebGL2Device, this._gpuFramebuffer);
|
|
|
|
return true;
|
|
}
|
|
|
|
public destroy () {
|
|
if (this._gpuFramebuffer) {
|
|
WebGL2CmdFuncDestroyFramebuffer(this._device as WebGL2Device, this._gpuFramebuffer);
|
|
this._gpuFramebuffer = null;
|
|
}
|
|
}
|
|
}
|