mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
Fix for iOS UIView adaptation
This commit is contained in:
@@ -54,9 +54,12 @@ CCMTLContext::CCMTLContext(Device *device)
|
||||
bool CCMTLContext::initialize(const ContextInfo &info) {
|
||||
_vsyncMode = info.vsyncMode;
|
||||
_windowHandle = info.windowHandle;
|
||||
CAMetalLayer *layer = (CAMetalLayer *)((CCMTLDevice *)_device)->getMTLLayer();
|
||||
|
||||
CCMTLDevice *device = (CCMTLDevice *)_device;
|
||||
CAMetalLayer *layer = (CAMetalLayer *)device->getMTLLayer();
|
||||
_colorFmt = toFormat(layer.pixelFormat);
|
||||
_depthStencilFmt = toFormat(MTLPixelFormatDepth24Unorm_Stencil8);
|
||||
id<MTLTexture> dssTex = (id<MTLTexture>)device->getDSSTexture();
|
||||
_depthStencilFmt = toFormat(dssTex.pixelFormat);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,11 @@ bool CCMTLDevice::initialize(const DeviceInfo &info) {
|
||||
_inFlightSemaphore = CC_NEW(CCMTLSemaphore(MAX_FRAMES_IN_FLIGHT));
|
||||
_currentFrameIndex = 0;
|
||||
|
||||
#if CC_PLATFORM == CC_PLATFORM_MAC_OSX
|
||||
NSView *view = (NSView *)_windowHandle;
|
||||
#else
|
||||
UIView *view = (UIView *)_windowHandle;
|
||||
#endif
|
||||
CAMetalLayer *layer = static_cast<CAMetalLayer *>(view.layer);
|
||||
_mtlLayer = layer;
|
||||
id<MTLDevice> mtlDevice = (id<MTLDevice>)layer.device;
|
||||
@@ -104,13 +108,13 @@ bool CCMTLDevice::initialize(const DeviceInfo &info) {
|
||||
}
|
||||
|
||||
// Persistent depth stencil texture
|
||||
MTLTextureDescriptor *textureDescriptor = [[MTLTextureDescriptor alloc] init];
|
||||
textureDescriptor.pixelFormat = mu::getSupportedDepthStencilFormat(mtlDevice, gpuFamily, _depthBits);
|
||||
textureDescriptor.width = info.width;
|
||||
textureDescriptor.height = info.height;
|
||||
textureDescriptor.storageMode = MTLStorageModePrivate;
|
||||
textureDescriptor.usage = MTLTextureUsageRenderTarget;
|
||||
_dssTex = [mtlDevice newTextureWithDescriptor:textureDescriptor];
|
||||
MTLTextureDescriptor *dssDescriptor = [[MTLTextureDescriptor alloc] init];
|
||||
dssDescriptor.pixelFormat = mu::getSupportedDepthStencilFormat(mtlDevice, gpuFamily, _depthBits);
|
||||
dssDescriptor.width = info.width;
|
||||
dssDescriptor.height = info.height;
|
||||
dssDescriptor.storageMode = MTLStorageModePrivate;
|
||||
dssDescriptor.usage = MTLTextureUsageRenderTarget;
|
||||
_dssTex = [mtlDevice newTextureWithDescriptor:dssDescriptor];
|
||||
_stencilBits = 8;
|
||||
|
||||
ContextInfo contextCreateInfo;
|
||||
|
||||
Reference in New Issue
Block a user