Version: 2021.3

Texture2D.CreateExternalTexture

切换到手册
public static Texture2D CreateExternalTexture (int width, int height, TextureFormat format, bool mipChain, bool linear, IntPtr nativeTex);

参数

nativeTex 原生 2D 纹理对象。
width 纹理宽度(以像素为单位)。
height 纹理高度(以像素为单位)。
format 底层纹理对象的格式。
mipmap 该纹理是否有多级渐进纹理?
linear 纹理是否使用线性颜色空间?

描述

Creates a Unity Texture out of an externally created native texture object.

此函数最适用于原生代码插件,这些插件在 Unity 外部创建平台特定的纹理 对象,并且需要在 Unity 场景中使用这些纹理。也可以在 Unity 中创建纹理, 然后获取指向底层平台表示的指针;请参阅 Texture.GetNativeTexturePtr

Parameters passed to CreateExternalTexture should match what the texture actually is; and the underlying texture should be 2D.

For Direct3D-like devices, the nativeTex parameter is a pointer to the underlying Direct3D base type, from which a texture can be created. They can be:

D3D11: ID3D11ShaderResourceView*ID3D11Texture2D*
D3D12: ID3D12Texture2D*

For OpenGL/OpenGL ES, the nativeTex parameter is a GLuint.

For Metal, the nativeTex parameter is an id<MTLTexture>.

For Vulkan, the nativeTex parameter is a VkImage*.

另请参阅:UpdateExternalTextureTexture.GetNativeTexturePtr