-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Consolidate core and WebGL texture format info handling (#2220)
- Loading branch information
Showing
23 changed files
with
859 additions
and
1,012 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ on: | |
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
strategy: | ||
matrix: | ||
node-version: [20] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
modules/core/src/gpu-type-utils/texture-format-capabilities.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// luma.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
|
||
import type {TextureFormat} from './texture-formats'; | ||
import type {TextureFeature} from './texture-features'; | ||
import {decodeTextureFormat} from './decode-texture-format'; | ||
|
||
import {TEXTURE_FORMAT_TABLE} from './texture-format-table'; | ||
|
||
/** | ||
* Texture format capabilities. | ||
* @note Not directly usable. Can contain TextureFeature strings that need to be checked against a specific device. | ||
*/ | ||
export type TextureFormatCapabilities = { | ||
format: TextureFormat; | ||
/** Can the format be created */ | ||
create: TextureFeature | boolean; | ||
/** If a feature string, the specified device feature determines if format is renderable. */ | ||
render: TextureFeature | boolean; | ||
/** If a feature string, the specified device feature determines if format is filterable. */ | ||
filter: TextureFeature | boolean; | ||
/** If a feature string, the specified device feature determines if format is blendable. */ | ||
blend: TextureFeature | boolean; | ||
/** If a feature string, the specified device feature determines if format is storeable. */ | ||
store: TextureFeature | boolean; | ||
}; | ||
|
||
export function getTextureFormatCapabilities(format: TextureFormat): TextureFormatCapabilities { | ||
const info = TEXTURE_FORMAT_TABLE[format]; | ||
if (!info) { | ||
throw new Error(`Unknown texture format ${format}`); | ||
} | ||
|
||
const formatCapabilities: Required<TextureFormatCapabilities> = { | ||
format, | ||
create: info.create ?? true, | ||
render: info.render ?? true, | ||
filter: info.filter ?? true, | ||
blend: info.blend ?? true, | ||
store: info.store ?? true | ||
}; | ||
|
||
const formatInfo = decodeTextureFormat(format); | ||
const isDepthStencil = format.startsWith('depth') || format.startsWith('stencil'); | ||
const isSigned = formatInfo?.signed; | ||
const isInteger = formatInfo?.integer; | ||
const isWebGLSpecific = formatInfo?.webgl; | ||
|
||
// signed formats are not renderable | ||
formatCapabilities.render &&= !isSigned; | ||
// signed and integer formats are not filterable | ||
formatCapabilities.filter &&= !isDepthStencil && !isSigned && !isInteger && !isWebGLSpecific; | ||
|
||
return formatCapabilities; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.