From 0e116113fbdf7817964acb9f8ddb0f88dcc4e660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Fri, 23 Oct 2015 16:05:35 -0700 Subject: [PATCH] Cleanup. --- src/bgfx.cpp | 13 +++++++------ src/renderer_mtl.mm | 28 +++++++++++++++++----------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 1c34fef1..1fdaefd5 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -1143,19 +1143,20 @@ namespace bgfx for (uint32_t ii = 0; ii < BX_COUNTOF(s_emulatedFormats); ++ii) { - if (0 == (g_caps.formats[s_emulatedFormats[ii] ] & BGFX_CAPS_FORMAT_TEXTURE_2D) ) + const uint32_t fmt = s_emulatedFormats[ii]; + if (0 == (g_caps.formats[fmt] & BGFX_CAPS_FORMAT_TEXTURE_2D) ) { - g_caps.formats[s_emulatedFormats[ii] ] |= BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED; + g_caps.formats[fmt] |= BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED; } - if (0 == (g_caps.formats[s_emulatedFormats[ii] ] & BGFX_CAPS_FORMAT_TEXTURE_3D) ) + if (0 == (g_caps.formats[fmt] & BGFX_CAPS_FORMAT_TEXTURE_3D) ) { - g_caps.formats[s_emulatedFormats[ii] ] |= BGFX_CAPS_FORMAT_TEXTURE_3D_EMULATED; + g_caps.formats[fmt] |= BGFX_CAPS_FORMAT_TEXTURE_3D_EMULATED; } - if (0 == (g_caps.formats[s_emulatedFormats[ii] ] & BGFX_CAPS_FORMAT_TEXTURE_CUBE) ) + if (0 == (g_caps.formats[fmt] & BGFX_CAPS_FORMAT_TEXTURE_CUBE) ) { - g_caps.formats[s_emulatedFormats[ii] ] |= BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED; + g_caps.formats[fmt] |= BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED; } } diff --git a/src/renderer_mtl.mm b/src/renderer_mtl.mm index f89bd197..f855c5a4 100644 --- a/src/renderer_mtl.mm +++ b/src/renderer_mtl.mm @@ -434,11 +434,15 @@ namespace bgfx { namespace mtl support |= MTLPixelFormatInvalid != s_textureFormat[ii].m_fmt ? BGFX_CAPS_FORMAT_TEXTURE_2D + | BGFX_CAPS_FORMAT_TEXTURE_3D + | BGFX_CAPS_FORMAT_TEXTURE_CUBE : BGFX_CAPS_FORMAT_TEXTURE_NONE ; support |= MTLPixelFormatInvalid != s_textureFormat[ii].m_fmtSrgb ? BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB + | BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB + | BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB : BGFX_CAPS_FORMAT_TEXTURE_NONE ; @@ -464,6 +468,15 @@ namespace bgfx { namespace mtl g_caps.formats[TextureFormat::PTC24 ] = BGFX_CAPS_FORMAT_TEXTURE_NONE; } + for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) + { + if (BGFX_CAPS_FORMAT_TEXTURE_NONE == g_caps.formats[ii]) + { + s_textureFormat[ii].m_fmt = MTLPixelFormatInvalid; + s_textureFormat[ii].m_fmtSrgb = MTLPixelFormatInvalid; + } + } + // Init reserved part of view name. for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii) { @@ -1807,22 +1820,15 @@ 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); - const uint16_t formatMask = imageContainer.m_cubeMap - ? BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED - : imageContainer.m_depth > 1 - ? BGFX_CAPS_FORMAT_TEXTURE_3D_EMULATED - : BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED - ; - - const bool convert = 0 != (g_caps.formats[m_requestedFormat] & formatMask); - m_flags = _flags; m_requestedFormat = (uint8_t)imageContainer.m_format; - m_textureFormat = convert + m_textureFormat = MTLPixelFormatInvalid == s_textureFormat[m_requestedFormat].m_fmt ? uint8_t(TextureFormat::BGRA8) : m_requestedFormat ; + const bool convert = m_requestedFormat != m_textureFormat; + uint8_t bpp = getBitsPerPixel(TextureFormat::Enum(m_textureFormat) ); if (convert) { @@ -1860,7 +1866,7 @@ namespace bgfx { namespace mtl ); const bool bufferOnly = 0 != (_flags&BGFX_TEXTURE_RT_BUFFER_ONLY); - const bool computeWrite = 0 != (_flags&BGFX_TEXTURE_COMPUTE_WRITE); +// const bool computeWrite = 0 != (_flags&BGFX_TEXTURE_COMPUTE_WRITE); // const bool renderTarget = 0 != (_flags&BGFX_TEXTURE_RT_MASK); const bool srgb = 0 != (_flags&BGFX_TEXTURE_SRGB) || imageContainer.m_srgb; // const uint32_t msaaQuality = bx::uint32_satsub( (_flags&BGFX_TEXTURE_RT_MSAA_MASK)>>BGFX_TEXTURE_RT_MSAA_SHIFT, 1);