diff --git a/OgreMain/include/OgreTextureFilters.h b/OgreMain/include/OgreTextureFilters.h index 0784878c609..dc61ba1abee 100644 --- a/OgreMain/include/OgreTextureFilters.h +++ b/OgreMain/include/OgreTextureFilters.h @@ -83,7 +83,9 @@ namespace TextureFilter See DefaultMipmapGen::DefaultMipmapGen */ static uint8 selectMipmapGen( uint32 filters, const Image2 &image, + PixelFormatGpu finalPixelFormat, const TextureGpuManager *textureManager ); + public: static void createFilters( uint32 filters, FilterBaseArray &outFilters, const TextureGpu *texture, const Image2 &image, diff --git a/OgreMain/src/OgreTextureFilters.cpp b/OgreMain/src/OgreTextureFilters.cpp index 95ebed5574e..2414eabab05 100644 --- a/OgreMain/src/OgreTextureFilters.cpp +++ b/OgreMain/src/OgreTextureFilters.cpp @@ -45,6 +45,7 @@ namespace TextureFilter } //----------------------------------------------------------------------------------- uint8 FilterBase::selectMipmapGen( uint32 filters, const Image2 &image, + PixelFormatGpu finalPixelFormat, const TextureGpuManager *textureManager ) { DefaultMipmapGen::DefaultMipmapGen retVal = DefaultMipmapGen::NoMipmaps; @@ -64,7 +65,7 @@ namespace TextureFilter defaultMipmapGeneration : defaultMipmapGenerationCubemaps; - if( PixelFormatGpuUtils::supportsHwMipmaps( image.getPixelFormat() ) ) + if( textureManager->checkSupport( finalPixelFormat, TextureFlags::AllowAutomipmaps ) ) retVal = mipmapGen; else retVal = DefaultMipmapGen::SwMode; @@ -73,15 +74,6 @@ namespace TextureFilter retVal = DefaultMipmapGen::HwMode; else retVal = DefaultMipmapGen::SwMode; - - if( retVal == DefaultMipmapGen::HwMode ) - { - if( !textureManager->checkSupport( image.getPixelFormat(), - TextureFlags::AllowAutomipmaps ) ) - { - retVal = DefaultMipmapGen::SwMode; - } - } } return retVal; @@ -93,15 +85,24 @@ namespace TextureFilter FilterBaseArray filtersVec; filtersVec.swap( outFilters ); + PixelFormatGpu finalPixelFormat = image.getPixelFormat(); + if( filters & TextureFilter::TypePrepareForNormalMapping ) + { + finalPixelFormat = PrepareForNormalMapping::getDestinationFormat( finalPixelFormat ); filtersVec.push_back( OGRE_NEW TextureFilter::PrepareForNormalMapping() ); + } if( filters & TextureFilter::TypeLeaveChannelR ) + { + finalPixelFormat = LeaveChannelR::getDestinationFormat( finalPixelFormat ); filtersVec.push_back( OGRE_NEW TextureFilter::LeaveChannelR() ); + } //Add mipmap generation as one of the last steps if( filters & TextureFilter::TypeGenerateDefaultMipmaps ) { - const uint8 mipmapGen = selectMipmapGen( filters, image, texture->getTextureManager() ); + const uint8 mipmapGen = + selectMipmapGen( filters, image, finalPixelFormat, texture->getTextureManager() ); //If the user wants Mipmaps when loading OnStorage -> OnSystemRam //then he should either explicitly ask only for SW filters, or //load the texture to Resident first, then download to OnSystemRam. @@ -141,16 +142,17 @@ namespace TextureFilter //Add mipmap generation as one of the last steps if( filters & TextureFilter::TypeGenerateDefaultMipmaps ) { - const uint8 mipmapGen = selectMipmapGen( filters, image, textureGpuManager ); + const uint8 mipmapGen = + selectMipmapGen( filters, image, inOutPixelFormat, textureGpuManager ); const bool canDoMipmaps = - (mipmapGen == DefaultMipmapGen::HwMode && - PixelFormatGpuUtils::supportsHwMipmaps( image.getPixelFormat() )) || - (mipmapGen == DefaultMipmapGen::SwMode && - Image2::supportsSwMipmaps( image.getPixelFormat(), image.getDepthOrSlices(), - image.getTextureType(), - static_cast( - GenerateSwMipmaps::getFilter( image ) ) ) ); + ( mipmapGen == DefaultMipmapGen::HwMode && + textureGpuManager->checkSupport( inOutPixelFormat, + TextureFlags::AllowAutomipmaps ) ) || + ( mipmapGen == DefaultMipmapGen::SwMode && + Image2::supportsSwMipmaps( + inOutPixelFormat, image.getDepthOrSlices(), image.getTextureType(), + static_cast( GenerateSwMipmaps::getFilter( image ) ) ) ); if( canDoMipmaps && inOutNumMipmaps <= 1u) { diff --git a/OgreMain/src/OgreTextureGpuManager.cpp b/OgreMain/src/OgreTextureGpuManager.cpp index abcf6968581..ed1e67892b4 100644 --- a/OgreMain/src/OgreTextureGpuManager.cpp +++ b/OgreMain/src/OgreTextureGpuManager.cpp @@ -856,6 +856,13 @@ namespace Ogre OGRE_ASSERT_LOW( textureFlags != TextureFlags::NotTexture && "Invalid textureFlags combination. Asking to check if format is supported to do nothing" ); + + if( textureFlags & TextureFlags::AllowAutomipmaps ) + { + if( !PixelFormatGpuUtils::supportsHwMipmaps( format ) ) + return false; + } + return true; } //----------------------------------------------------------------------------------- diff --git a/RenderSystems/Metal/src/OgreMetalTextureGpuManager.mm b/RenderSystems/Metal/src/OgreMetalTextureGpuManager.mm index bab258b97ab..d4f8e40b17d 100644 --- a/RenderSystems/Metal/src/OgreMetalTextureGpuManager.mm +++ b/RenderSystems/Metal/src/OgreMetalTextureGpuManager.mm @@ -254,6 +254,13 @@ OGRE_NEW MetalStagingTexture( mVaoManager, break; } #endif + + if( textureFlags & TextureFlags::AllowAutomipmaps ) + { + if( !PixelFormatGpuUtils::supportsHwMipmaps( format ) ) + return false; + } + return true; } } diff --git a/RenderSystems/Vulkan/src/OgreVulkanTextureGpuManager.cpp b/RenderSystems/Vulkan/src/OgreVulkanTextureGpuManager.cpp index 62d5294af1c..341aa97b2cf 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanTextureGpuManager.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanTextureGpuManager.cpp @@ -526,7 +526,11 @@ namespace Ogre } if( textureFlags & TextureFlags::AllowAutomipmaps ) + { features |= VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT; + if( !PixelFormatGpuUtils::supportsHwMipmaps( format ) ) + return false; + } if( ( props.optimalTilingFeatures & features ) == features ) return true;