[英]Trying to share Metal texture with Opengl texture
我查看了文檔,但不知道如何獲取紋理ID。 我實際上是從SDK獲取金屬質感的,我想與Ogre Texture分享。 我的問題該代碼可以編譯,但是我不知道如何獲取紋理ID,因此我無法將其用於Ogre進行渲染。 代碼崩潰,並且根本不起作用。 我花了很多時間來構造它。 希望有人能節省我的時間。
例如,它現在在此行崩潰,但是ioSurface已初始化
id<MTLTexture> metalTexture = [device newTextureWithDescriptor:textureDescriptor
ioSurface:surface
plane:0];
無法識別的選擇器已發送到實例
-
void* texPtr = SixDegreesSDK_GetBackgroundTexture();
if (texPtr != nil) {
id<MTLTexture> mtlTexture = (__bridge id<MTLTexture>)texPtr;
id<MTLDevice> device = [mtlTexture device];
// !!! Not fond of creating a new command queue for every texture
id<MTLCommandQueue> commandQueue = [device newCommandQueue];
id<MTLCommandBuffer> commandBuffer = [commandQueue commandBuffer];
id<MTLBlitCommandEncoder> blitEncoder = [commandBuffer blitCommandEncoder];
NSUInteger textureWidth = mtlTexture.width;
NSUInteger textureHeight = mtlTexture.height;
NSUInteger rowbytes = mtlTexture.bufferBytesPerRow;
MTLPixelFormat pixFormat = mtlTexture.pixelFormat;
CVPixelBufferRef _CVPixelBuffer = NULL;
NSDictionary* cvBufferProperties = @{
(__bridge NSString*)kCVPixelBufferOpenGLCompatibilityKey : @YES,
(__bridge NSString*)kCVPixelBufferMetalCompatibilityKey : @YES,
};
CVReturn cvret = CVPixelBufferCreate(kCFAllocatorDefault,
textureWidth, textureHeight,
kCVPixelFormatType_32RGBA,
(__bridge CFDictionaryRef)cvBufferProperties,
&_CVPixelBuffer);
const IOSurfaceRef surface = CVPixelBufferGetIOSurface(_CVPixelBuffer); // available in ios11 sdk, ios4 runtime
MTLTextureDescriptor* textureDescriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:pixFormat
width:textureWidth
height:textureHeight
mipmapped:NO];
id<MTLTexture> metalTexture = [device newTextureWithDescriptor:textureDescriptor
ioSurface:surface
plane:0];
MTLRegion region = MTLRegionMake2D(0, 0, textureWidth, textureHeight);
[blitEncoder copyFromTexture:mtlTexture
sourceSlice:0
sourceLevel:0
sourceOrigin:region.origin
sourceSize:region.size
toTexture:metalTexture
destinationSlice:0
destinationLevel:0
destinationOrigin:region.origin];
[blitEncoder endEncoding];
[commandBuffer commit];
[self.mEAGLContext texImageIOSurface:surface target:GL_TEXTURE_2D internalFormat:GL_RGBA width:textureWidth height:textureHeight format:GL_RGBA type:GL_UNSIGNED_BYTE plane:0];
我相信您想要的將是CVOpenGLTextureGetName
。 我相信這會返回您傳遞給它的紋理的紋理ID。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.