From 55a176618d16eae05c4d63fbaab80340d2b8e00f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Mon, 19 Oct 2015 21:11:42 -0700 Subject: [PATCH] Metal: Fixed fallback texture format. --- src/renderer_mtl.h | 5 +++++ src/renderer_mtl.mm | 43 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/renderer_mtl.h b/src/renderer_mtl.h index 495f7abf..052c7859 100644 --- a/src/renderer_mtl.h +++ b/src/renderer_mtl.h @@ -58,6 +58,11 @@ namespace bgfx { namespace mtl return [m_obj computeCommandEncoder]; } + id blitCommandEncoder() + { + return [m_obj blitCommandEncoder]; + } + // Scheduling and Executing Commands void enqueue() { diff --git a/src/renderer_mtl.mm b/src/renderer_mtl.mm index 007c2bcb..aa5fa04a 100644 --- a/src/renderer_mtl.mm +++ b/src/renderer_mtl.mm @@ -429,9 +429,17 @@ namespace bgfx { namespace mtl for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) { - uint8_t support = (s_textureFormat[ii].m_fmt != MTLPixelFormatInvalid) ? BGFX_CAPS_FORMAT_TEXTURE_COLOR : BGFX_CAPS_FORMAT_TEXTURE_NONE; + uint8_t support = 0; - support |= (s_textureFormat[ii].m_fmtSrgb != MTLPixelFormatInvalid) ? BGFX_CAPS_FORMAT_TEXTURE_COLOR_SRGB : BGFX_CAPS_FORMAT_TEXTURE_NONE; + support |= MTLPixelFormatInvalid != s_textureFormat[ii].m_fmt + ? BGFX_CAPS_FORMAT_TEXTURE_COLOR + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + support |= MTLPixelFormatInvalid != s_textureFormat[ii].m_fmtSrgb + ? BGFX_CAPS_FORMAT_TEXTURE_COLOR_SRGB + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; //TODO: additional caps flags // support |= BGFX_CAPS_FORMAT_TEXTURE_VERTEX : BGFX_CAPS_FORMAT_TEXTURE_NONE; @@ -441,6 +449,20 @@ namespace bgfx { namespace mtl g_caps.formats[ii] = support; } + if (BX_ENABLED(BX_PLATFORM_OSX) ) + { + g_caps.formats[TextureFormat::ETC1 ] = + g_caps.formats[TextureFormat::ETC2 ] = + g_caps.formats[TextureFormat::ETC2A ] = + g_caps.formats[TextureFormat::ETC2A1] = + g_caps.formats[TextureFormat::PTC12 ] = + g_caps.formats[TextureFormat::PTC14 ] = + g_caps.formats[TextureFormat::PTC12A] = + g_caps.formats[TextureFormat::PTC14A] = + g_caps.formats[TextureFormat::PTC22 ] = + g_caps.formats[TextureFormat::PTC24 ] = BGFX_CAPS_FORMAT_TEXTURE_NONE; + } + // Init reserved part of view name. for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii) { @@ -752,9 +774,11 @@ namespace bgfx { namespace mtl rce.setScissorRect(rc); rce.setCullMode(MTLCullModeNone); - uint64_t state = BGFX_STATE_RGB_WRITE - | BGFX_STATE_ALPHA_WRITE - | BGFX_STATE_DEPTH_TEST_ALWAYS; + uint64_t state = 0 + | BGFX_STATE_RGB_WRITE + | BGFX_STATE_ALPHA_WRITE + | BGFX_STATE_DEPTH_TEST_ALWAYS + ; setDepthStencilState(state); @@ -1772,12 +1796,17 @@ namespace bgfx { namespace mtl const uint32_t textureWidth = bx::uint32_max(blockInfo.blockWidth, imageContainer.m_width >>startLod); const uint32_t textureHeight = bx::uint32_max(blockInfo.blockHeight, imageContainer.m_height>>startLod); + bool convert = BGFX_CAPS_FORMAT_TEXTURE_NONE == g_caps.formats[m_requestedFormat]; + m_flags = _flags; m_requestedFormat = (uint8_t)imageContainer.m_format; - m_textureFormat = (uint8_t)imageContainer.m_format; + m_textureFormat = convert + ? uint8_t(TextureFormat::BGRA8) + : m_requestedFormat + ; const TextureFormatInfo& tfi = s_textureFormat[m_requestedFormat]; - const bool convert = MTLPixelFormatInvalid == tfi.m_fmt; + convert = MTLPixelFormatInvalid == tfi.m_fmt; uint8_t bpp = getBitsPerPixel(TextureFormat::Enum(m_textureFormat) ); if (convert)