mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-12 14:46:08 +00:00
Add 1- and 2-component texture formats.
Implemented {uint8, unorm8} x {r, rg} texture formats.
Backend support added for Metal, D3D12 and OpenGL.
This commit is contained in:
committed by
Corentin Wallez
parent
8d742d1375
commit
cd4f8a2e2f
@@ -21,6 +21,12 @@ namespace backend {
|
||||
|
||||
uint32_t TextureFormatPixelSize(nxt::TextureFormat format) {
|
||||
switch (format) {
|
||||
case nxt::TextureFormat::R8Unorm:
|
||||
case nxt::TextureFormat::R8Uint:
|
||||
return 1;
|
||||
case nxt::TextureFormat::R8G8Unorm:
|
||||
case nxt::TextureFormat::R8G8Uint:
|
||||
return 2;
|
||||
case nxt::TextureFormat::R8G8B8A8Unorm:
|
||||
case nxt::TextureFormat::R8G8B8A8Uint:
|
||||
case nxt::TextureFormat::B8G8R8A8Unorm:
|
||||
@@ -34,40 +40,28 @@ namespace backend {
|
||||
|
||||
bool TextureFormatHasDepth(nxt::TextureFormat format) {
|
||||
switch (format) {
|
||||
case nxt::TextureFormat::R8G8B8A8Unorm:
|
||||
case nxt::TextureFormat::R8G8B8A8Uint:
|
||||
case nxt::TextureFormat::B8G8R8A8Unorm:
|
||||
return false;
|
||||
case nxt::TextureFormat::D32FloatS8Uint:
|
||||
return true;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool TextureFormatHasStencil(nxt::TextureFormat format) {
|
||||
switch (format) {
|
||||
case nxt::TextureFormat::R8G8B8A8Unorm:
|
||||
case nxt::TextureFormat::R8G8B8A8Uint:
|
||||
case nxt::TextureFormat::B8G8R8A8Unorm:
|
||||
return false;
|
||||
case nxt::TextureFormat::D32FloatS8Uint:
|
||||
return true;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool TextureFormatHasDepthOrStencil(nxt::TextureFormat format) {
|
||||
switch (format) {
|
||||
case nxt::TextureFormat::R8G8B8A8Unorm:
|
||||
case nxt::TextureFormat::R8G8B8A8Uint:
|
||||
case nxt::TextureFormat::B8G8R8A8Unorm:
|
||||
return false;
|
||||
case nxt::TextureFormat::D32FloatS8Uint:
|
||||
return true;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,8 +88,16 @@ namespace backend { namespace d3d12 {
|
||||
switch (format) {
|
||||
case nxt::TextureFormat::R8G8B8A8Unorm:
|
||||
return DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
case nxt::TextureFormat::R8G8Unorm:
|
||||
return DXGI_FORMAT_R8G8_UNORM;
|
||||
case nxt::TextureFormat::R8Unorm:
|
||||
return DXGI_FORMAT_R8_UNORM;
|
||||
case nxt::TextureFormat::R8G8B8A8Uint:
|
||||
return DXGI_FORMAT_R8G8B8A8_UINT;
|
||||
case nxt::TextureFormat::R8G8Uint:
|
||||
return DXGI_FORMAT_R8G8_UINT;
|
||||
case nxt::TextureFormat::R8Uint:
|
||||
return DXGI_FORMAT_R8_UINT;
|
||||
case nxt::TextureFormat::B8G8R8A8Unorm:
|
||||
return DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
case nxt::TextureFormat::D32FloatS8Uint:
|
||||
|
||||
@@ -22,8 +22,16 @@ namespace backend { namespace metal {
|
||||
switch (format) {
|
||||
case nxt::TextureFormat::R8G8B8A8Unorm:
|
||||
return MTLPixelFormatRGBA8Unorm;
|
||||
case nxt::TextureFormat::R8G8Unorm:
|
||||
return MTLPixelFormatRG8Unorm;
|
||||
case nxt::TextureFormat::R8Unorm:
|
||||
return MTLPixelFormatR8Unorm;
|
||||
case nxt::TextureFormat::R8G8B8A8Uint:
|
||||
return MTLPixelFormatRGBA8Uint;
|
||||
case nxt::TextureFormat::R8G8Uint:
|
||||
return MTLPixelFormatRG8Uint;
|
||||
case nxt::TextureFormat::R8Uint:
|
||||
return MTLPixelFormatR8Uint;
|
||||
case nxt::TextureFormat::B8G8R8A8Unorm:
|
||||
return MTLPixelFormatBGRA8Unorm;
|
||||
case nxt::TextureFormat::D32FloatS8Uint:
|
||||
|
||||
@@ -36,8 +36,16 @@ namespace backend { namespace opengl {
|
||||
switch (format) {
|
||||
case nxt::TextureFormat::R8G8B8A8Unorm:
|
||||
return {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE};
|
||||
case nxt::TextureFormat::R8G8Unorm:
|
||||
return {GL_RG8, GL_RG, GL_UNSIGNED_BYTE};
|
||||
case nxt::TextureFormat::R8Unorm:
|
||||
return {GL_R8, GL_RED, GL_UNSIGNED_BYTE};
|
||||
case nxt::TextureFormat::R8G8B8A8Uint:
|
||||
return {GL_RGBA8UI, GL_RGBA, GL_UNSIGNED_INT};
|
||||
case nxt::TextureFormat::R8G8Uint:
|
||||
return {GL_RG8UI, GL_RG, GL_UNSIGNED_INT};
|
||||
case nxt::TextureFormat::R8Uint:
|
||||
return {GL_R8UI, GL_RED, GL_UNSIGNED_INT};
|
||||
case nxt::TextureFormat::B8G8R8A8Unorm:
|
||||
// This doesn't have an enum for the internal format in OpenGL, so use RGBA8.
|
||||
return {GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE};
|
||||
|
||||
Reference in New Issue
Block a user