mirror of https://github.com/axmolengine/axmol.git
get supported depthStencil pixel format (#19774)
This commit is contained in:
parent
9b0d36c6a9
commit
8faf4a758f
|
@ -1,14 +1,9 @@
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "DeviceMTL.h"
|
#include "DeviceMTL.h"
|
||||||
|
#include "base/CCConfiguration.h"
|
||||||
|
|
||||||
#define COLOR_ATTAHCMENT_PIXEL_FORMAT MTLPixelFormatBGRA8Unorm
|
#define COLOR_ATTAHCMENT_PIXEL_FORMAT MTLPixelFormatBGRA8Unorm
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
|
||||||
#define DEPTH_STENCIL_ATTACHMENT_PIXEL_FORMAT MTLPixelFormatDepth32Float_Stencil8
|
|
||||||
#else
|
|
||||||
#define DEPTH_STENCIL_ATTACHMENT_PIXEL_FORMAT MTLPixelFormatDepth24Unorm_Stencil8
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CC_BACKEND_BEGIN
|
CC_BACKEND_BEGIN
|
||||||
|
|
||||||
id<MTLTexture> Utils::_defaultColorAttachmentTexture = nil;
|
id<MTLTexture> Utils::_defaultColorAttachmentTexture = nil;
|
||||||
|
@ -47,11 +42,22 @@ namespace {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MTLPixelFormat getSupportedDepthStencilFormat()
|
||||||
|
{
|
||||||
|
MTLPixelFormat pixelFormat = MTLPixelFormatDepth32Float_Stencil8;
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||||
|
bool isDepth24Stencil8PixelFormatSupported = Configuration::getInstance()->supportsOESPackedDepthStencil();
|
||||||
|
if(isDepth24Stencil8PixelFormatSupported)
|
||||||
|
pixelFormat = MTLPixelFormatDepth24Unorm_Stencil8;
|
||||||
|
#endif
|
||||||
|
return pixelFormat;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MTLPixelFormat Utils::getDefaultDepthStencilAttachmentPixelFormat()
|
MTLPixelFormat Utils::getDefaultDepthStencilAttachmentPixelFormat()
|
||||||
{
|
{
|
||||||
return DEPTH_STENCIL_ATTACHMENT_PIXEL_FORMAT;
|
return getSupportedDepthStencilFormat();
|
||||||
}
|
}
|
||||||
|
|
||||||
MTLPixelFormat Utils::getDefaultColorAttachmentPixelFormat()
|
MTLPixelFormat Utils::getDefaultColorAttachmentPixelFormat()
|
||||||
|
@ -104,7 +110,7 @@ MTLPixelFormat Utils::toMTLPixelFormat(TextureFormat textureFormat)
|
||||||
|
|
||||||
//on mac, D24S8 means MTLPixelFormatDepth24Unorm_Stencil8, while on ios it means MTLPixelFormatDepth32Float_Stencil8
|
//on mac, D24S8 means MTLPixelFormatDepth24Unorm_Stencil8, while on ios it means MTLPixelFormatDepth32Float_Stencil8
|
||||||
case TextureFormat::D24S8:
|
case TextureFormat::D24S8:
|
||||||
return DEPTH_STENCIL_ATTACHMENT_PIXEL_FORMAT;
|
return getSupportedDepthStencilFormat();
|
||||||
case TextureFormat::SYSTEM_DEFAULT:
|
case TextureFormat::SYSTEM_DEFAULT:
|
||||||
return COLOR_ATTAHCMENT_PIXEL_FORMAT;
|
return COLOR_ATTAHCMENT_PIXEL_FORMAT;
|
||||||
case TextureFormat::NONE:
|
case TextureFormat::NONE:
|
||||||
|
@ -119,7 +125,7 @@ id<MTLTexture> Utils::createDepthStencilAttachmentTexture()
|
||||||
MTLTextureDescriptor* textureDescriptor = [[MTLTextureDescriptor alloc] init];
|
MTLTextureDescriptor* textureDescriptor = [[MTLTextureDescriptor alloc] init];
|
||||||
textureDescriptor.width = CAMetalLayer.drawableSize.width;
|
textureDescriptor.width = CAMetalLayer.drawableSize.width;
|
||||||
textureDescriptor.height = CAMetalLayer.drawableSize.height;
|
textureDescriptor.height = CAMetalLayer.drawableSize.height;
|
||||||
textureDescriptor.pixelFormat = DEPTH_STENCIL_ATTACHMENT_PIXEL_FORMAT;
|
textureDescriptor.pixelFormat = getSupportedDepthStencilFormat();
|
||||||
textureDescriptor.resourceOptions = MTLResourceStorageModePrivate;
|
textureDescriptor.resourceOptions = MTLResourceStorageModePrivate;
|
||||||
textureDescriptor.usage = MTLTextureUsageRenderTarget;
|
textureDescriptor.usage = MTLTextureUsageRenderTarget;
|
||||||
auto ret = [CAMetalLayer.device newTextureWithDescriptor:textureDescriptor];
|
auto ret = [CAMetalLayer.device newTextureWithDescriptor:textureDescriptor];
|
||||||
|
|
Loading…
Reference in New Issue