import { GfxColor , GfxFormat } from "../platform/GfxPlatform" ; import { colorNewFromRGBA , OpaqueBlack } from "../../Color" ; import { reverseDepthForClearValue } from "./ReversedDepthHelpers" ; import { GfxrAttachmentSlot , GfxrGraphBuilder , GfxrRenderTargetDescription , GfxrRenderTargetID } from "../render/GfxRenderGraph" ; import { pushFXAAPass } from "../passes/FXAA" ; import { GfxRenderHelper } from "../render/GfxRenderHelper" ; export function makeAttachmentClearDescriptor ( clearColor ) { return { colorClearColor : clearColor , depthClearValue : reverseDepthForClearValue ( 1.0 ) , stencilClearValue : 0.0 , } ; } export const standardFullClearRenderPassDescriptor = makeAttachmentClearDescriptor ( colorNewFromRGBA ( 0.88 , 0.88 , 0.88 , 1.0 ) ) ; export const opaqueBlackFullClearRenderPassDescriptor = makeAttachmentClearDescriptor ( OpaqueBlack ) ; export const enum AntialiasingMode { None , FXAA , MSAAx4 } interface RenderInput { backbufferWidth : number ; backbufferHeight : number ; antialiasingMode : AntialiasingMode ; } function selectFormatSimple ( slot ) { if ( slot === GfxrAttachmentSlot . Color0 ) return GfxFormat . U8_RGBA_RT ; else if ( slot === GfxrAttachmentSlot . DepthStencil ) return GfxFormat . D24 ; else throw "whoops" ; } function selectSampleCount ( renderInput ) { if ( renderInput . antialiasingMode === AntialiasingMode . MSAAx4 ) return 4 ; else return 1 ; } export function setBackbufferDescSimple ( desc , renderInput ) { const sampleCount = selectSampleCount ( renderInput ) ; desc . setDimensions ( renderInput . backbufferWidth , renderInput . backbufferHeight , sampleCount ) ; } export interface GfxrAttachmentClearDescriptor { colorClearColor : Readonly < GfxColor > | 'load' ; depthClearValue : number ; stencilClearValue : number ; } export function makeBackbufferDescSimple ( slot , renderInput , clearDescriptor ) { const pixelFormat = selectFormatSimple ( slot ) ; const desc = new GfxrRenderTargetDescription ( pixelFormat ) ; setBackbufferDescSimple ( desc , renderInput ) ; if ( clearDescriptor !== null ) { desc . colorClearColor = clearDescriptor . colorClearColor ; desc . depthClearValue = clearDescriptor . depthClearValue ; desc . stencilClearValue = clearDescriptor . stencilClearValue ; } return desc ; } export function pushAntialiasingPostProcessPass ( builder , renderHelper , renderInput , mainColorTargetID ) { if ( renderInput . antialiasingMode === AntialiasingMode . FXAA ) { pushFXAAPass ( builder , renderHelper , renderInput , mainColorTargetID ) ; } }