本文整理汇总了C#中Texture2D.LoadRawTextureData方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.LoadRawTextureData方法的具体用法?C# Texture2D.LoadRawTextureData怎么用?C# Texture2D.LoadRawTextureData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Texture2D
的用法示例。
在下文中一共展示了Texture2D.LoadRawTextureData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadTexture
// Loads a texture
public static Texture2D LoadTexture(string path, bool compress, bool upload, bool unreadable)
{
Texture2D map = null;
path = Directory.GetCurrentDirectory() + "/GameData/" + path;
if (File.Exists(path))
{
bool uncaught = true;
try
{
if (path.ToLower().EndsWith(".dds"))
{
// Borrowed from stock KSP 1.0 DDS loader (hi Mike!)
// Also borrowed the extra bits from Sarbian.
BinaryReader binaryReader = new BinaryReader(File.OpenRead(path));
uint num = binaryReader.ReadUInt32();
if (num == DDSHeaders.DDSValues.uintMagic)
{
DDSHeaders.DDSHeader dDSHeader = new DDSHeaders.DDSHeader(binaryReader);
if (dDSHeader.ddspf.dwFourCC == DDSHeaders.DDSValues.uintDX10)
{
new DDSHeaders.DDSHeaderDX10(binaryReader);
}
bool alpha = (dDSHeader.dwFlags & 0x00000002) != 0;
bool fourcc = (dDSHeader.dwFlags & 0x00000004) != 0;
bool rgb = (dDSHeader.dwFlags & 0x00000040) != 0;
bool alphapixel = (dDSHeader.dwFlags & 0x00000001) != 0;
bool luminance = (dDSHeader.dwFlags & 0x00020000) != 0;
bool rgb888 = dDSHeader.ddspf.dwRBitMask == 0x000000ff && dDSHeader.ddspf.dwGBitMask == 0x0000ff00 && dDSHeader.ddspf.dwBBitMask == 0x00ff0000;
//bool bgr888 = dDSHeader.ddspf.dwRBitMask == 0x00ff0000 && dDSHeader.ddspf.dwGBitMask == 0x0000ff00 && dDSHeader.ddspf.dwBBitMask == 0x000000ff;
bool rgb565 = dDSHeader.ddspf.dwRBitMask == 0x0000F800 && dDSHeader.ddspf.dwGBitMask == 0x000007E0 && dDSHeader.ddspf.dwBBitMask == 0x0000001F;
bool argb4444 = dDSHeader.ddspf.dwABitMask == 0x0000f000 && dDSHeader.ddspf.dwRBitMask == 0x00000f00 && dDSHeader.ddspf.dwGBitMask == 0x000000f0 && dDSHeader.ddspf.dwBBitMask == 0x0000000f;
bool rbga4444 = dDSHeader.ddspf.dwABitMask == 0x0000000f && dDSHeader.ddspf.dwRBitMask == 0x0000f000 && dDSHeader.ddspf.dwGBitMask == 0x000000f0 && dDSHeader.ddspf.dwBBitMask == 0x00000f00;
bool mipmap = (dDSHeader.dwCaps & DDSHeaders.DDSPixelFormatCaps.MIPMAP) != (DDSHeaders.DDSPixelFormatCaps)0u;
bool isNormalMap = ((dDSHeader.ddspf.dwFlags & 524288u) != 0u || (dDSHeader.ddspf.dwFlags & 2147483648u) != 0u);
if (fourcc)
{
if (dDSHeader.ddspf.dwFourCC == DDSHeaders.DDSValues.uintDXT1)
{
map = new Texture2D((int)dDSHeader.dwWidth, (int)dDSHeader.dwHeight, TextureFormat.DXT1, mipmap);
map.LoadRawTextureData(LoadRestOfReader(binaryReader));
}
else if (dDSHeader.ddspf.dwFourCC == DDSHeaders.DDSValues.uintDXT3)
{
map = new Texture2D((int)dDSHeader.dwWidth, (int)dDSHeader.dwHeight, (TextureFormat)11, mipmap);
map.LoadRawTextureData(LoadRestOfReader(binaryReader));
}
else if (dDSHeader.ddspf.dwFourCC == DDSHeaders.DDSValues.uintDXT5)
{
map = new Texture2D((int)dDSHeader.dwWidth, (int)dDSHeader.dwHeight, TextureFormat.DXT5, mipmap);
map.LoadRawTextureData(LoadRestOfReader(binaryReader));
}
else if (dDSHeader.ddspf.dwFourCC == DDSHeaders.DDSValues.uintDXT2)
{
Debug.Log("[Kopernicus]: DXT2 not supported" + path);
}
else if (dDSHeader.ddspf.dwFourCC == DDSHeaders.DDSValues.uintDXT4)
{
Debug.Log("[Kopernicus]: DXT4 not supported: " + path);
}
else if (dDSHeader.ddspf.dwFourCC == DDSHeaders.DDSValues.uintDX10)
{
Debug.Log("[Kopernicus]: DX10 dds not supported: " + path);
}
else
fourcc = false;
}
if (!fourcc)
{
TextureFormat textureFormat = TextureFormat.ARGB32;
bool ok = true;
if (rgb && (rgb888 /*|| bgr888*/))
{
// RGB or RGBA format
textureFormat = alphapixel
? TextureFormat.RGBA32
: TextureFormat.RGB24;
}
else if (rgb && rgb565)
{
// Nvidia texconv B5G6R5_UNORM
textureFormat = TextureFormat.RGB565;
}
else if (rgb && alphapixel && argb4444)
{
// Nvidia texconv B4G4R4A4_UNORM
textureFormat = TextureFormat.ARGB4444;
}
else if (rgb && alphapixel && rbga4444)
{
textureFormat = TextureFormat.RGBA4444;
}
else if (!rgb && alpha != luminance)
{
// A8 format or Luminance 8
textureFormat = TextureFormat.Alpha8;
//.........这里部分代码省略.........