import { mat4 } from "gl-matrix" ; import { GfxCompareMode } from "../platform/GfxPlatform" ; export const IS_DEPTH_REVERSED = true ; const reverseDepthMatrix = mat4 . fromValues ( 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , - 1 , 0 , 0 , 0 , 0 , 1 ) ; export function projectionMatrixReverseDepth ( m , isDepthReversed = IS_DEPTH_REVERSED ) { if ( isDepthReversed ) mat4 . mul ( m , reverseDepthMatrix , m ) ; } export function reverseDepthForCompareMode ( compareMode , isDepthReversed = IS_DEPTH_REVERSED ) { if ( isDepthReversed ) { switch ( compareMode ) { case GfxCompareMode . Less : return GfxCompareMode . Greater ; case GfxCompareMode . LessEqual : return GfxCompareMode . GreaterEqual ; case GfxCompareMode . GreaterEqual : return GfxCompareMode . LessEqual ; case GfxCompareMode . Greater : return GfxCompareMode . Less ; default : return compareMode ; } } else { return compareMode ; } } export function reverseDepthForClearValue ( n , isDepthReversed = IS_DEPTH_REVERSED ) { if ( isDepthReversed ) { return 1.0 - n ; } else { return n ; } } export function reverseDepthForDepthOffset ( n , isDepthReversed = IS_DEPTH_REVERSED ) { if ( isDepthReversed ) { return - n ; } else { return n ; } } export function compareDepthValues ( a , b , op , isDepthReversed = IS_DEPTH_REVERSED ) { op = reverseDepthForCompareMode ( op , isDepthReversed ) ; if ( op === GfxCompareMode . Less ) return a < b ; else if ( op === GfxCompareMode . LessEqual ) return a <= b ; else if ( op === GfxCompareMode . Greater ) return a > b ; else if ( op === GfxCompareMode . GreaterEqual ) return a >= b ; else throw "whoops" ; }