本文整理汇总了C#中ITexture.SetTextureData方法的典型用法代码示例。如果您正苦于以下问题:C# ITexture.SetTextureData方法的具体用法?C# ITexture.SetTextureData怎么用?C# ITexture.SetTextureData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITexture
的用法示例。
在下文中一共展示了ITexture.SetTextureData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadTextureData
public static void LoadTextureData(ITexture texture, string fileName)
{
DirectXTex.ImageStruct img = DirectXTex.DDSIO.ReadDDS(fileName);
switch ((DXGI_FORMAT)img.Format)
{
// compressed
case DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM:
texture.Reset(img.Width, img.Height, img.MipMapLevels, img.GetRowPitch() / 4, TextureFormat.D3DFMT_DXT1);
texture.SetTextureData(img.Data);
break;
case DXGI_FORMAT.DXGI_FORMAT_BC2_UNORM:
texture.Reset(img.Width, img.Height, img.MipMapLevels, img.GetRowPitch() / 4, TextureFormat.D3DFMT_DXT3);
texture.SetTextureData(img.Data);
break;
case DXGI_FORMAT.DXGI_FORMAT_BC3_UNORM:
texture.Reset(img.Width, img.Height, img.MipMapLevels, img.GetRowPitch() / 4, TextureFormat.D3DFMT_DXT5);
texture.SetTextureData(img.Data);
break;
case DXGI_FORMAT.DXGI_FORMAT_BC4_UNORM:
texture.Reset(img.Width, img.Height, img.MipMapLevels, img.GetRowPitch() / 4, TextureFormat.D3DFMT_ATI1);
texture.SetTextureData(img.Data);
break;
case DXGI_FORMAT.DXGI_FORMAT_BC5_UNORM:
texture.Reset(img.Width, img.Height, img.MipMapLevels, img.GetRowPitch() / 4, TextureFormat.D3DFMT_ATI2);
texture.SetTextureData(img.Data);
break;
case DXGI_FORMAT.DXGI_FORMAT_BC7_UNORM:
texture.Reset(img.Width, img.Height, img.MipMapLevels, img.GetRowPitch() / 4, TextureFormat.D3DFMT_BC7);
texture.SetTextureData(img.Data);
break;
// uncompressed
case DXGI_FORMAT.DXGI_FORMAT_B5G5R5A1_UNORM:
texture.Reset(img.Width, img.Height, img.MipMapLevels, img.GetRowPitch(), TextureFormat.D3DFMT_A1R5G5B5);
texture.SetTextureData(img.Data);
break;
case DXGI_FORMAT.DXGI_FORMAT_A8_UNORM:
texture.Reset(img.Width, img.Height, img.MipMapLevels, img.GetRowPitch(), TextureFormat.D3DFMT_A8);
texture.SetTextureData(img.Data);
break;
case DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM:
texture.Reset(img.Width, img.Height, img.MipMapLevels, img.GetRowPitch(), TextureFormat.D3DFMT_A8B8G8R8);
texture.SetTextureData(img.Data);
break;
case DXGI_FORMAT.DXGI_FORMAT_R8_UNORM:
texture.Reset(img.Width, img.Height, img.MipMapLevels, img.GetRowPitch(), TextureFormat.D3DFMT_L8);
texture.SetTextureData(img.Data);
break;
case DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM:
texture.Reset(img.Width, img.Height, img.MipMapLevels, img.GetRowPitch(), TextureFormat.D3DFMT_A8R8G8B8);
texture.SetTextureData(img.Data);
break;
default:
MessageBox.Show("format not supported!");
throw new Exception("unsupported format");
}
}
示例2: LoadTextureData
public static void LoadTextureData(ITexture texture, Stream stream)
{
byte[] readbuf = new byte[16777216];
IntPtr p = IntPtr.Zero;
int width = 0;
int height = 0;
int mipLevels = 0;
int format = 0;
int stride = 0;
int readsize = 16777216;
var strBuf = new byte[stream.Length];
stream.Position = 0;
stream.Read(strBuf, 0, strBuf.Length);
DXTexdds.LoadDDSImageFromStream(strBuf, strBuf.Length, readbuf, ref readsize, ref width, ref height, ref stride, ref mipLevels, ref format);
if (readsize > 16777216)
{
readbuf = new byte[readsize];
DXTexdds.LoadDDSImageFromStream(strBuf, strBuf.Length, readbuf, ref readsize, ref width, ref height, ref stride, ref mipLevels, ref format);
}
Array.Resize<byte>(ref readbuf, readsize);
//int length = stride * height / 4;
//int totalLength = 0;
//for (int i = 0; i < mipLevels; i++)
//{
// totalLength += length;
// length /= 4;
//}
//var buffer = new byte[totalLength/2];
//Marshal.Copy(p, buffer, 0, buffer.Length);
switch ((DXGI_FORMAT)format)
{
// compressed
case DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM:
texture.Reset(width, height, mipLevels, stride / 4, TextureFormat.D3DFMT_DXT1);
texture.SetTextureData(readbuf);
break;
case DXGI_FORMAT.DXGI_FORMAT_BC2_UNORM:
texture.Reset(width, height, mipLevels, stride / 4, TextureFormat.D3DFMT_DXT3);
texture.SetTextureData(readbuf);
break;
case DXGI_FORMAT.DXGI_FORMAT_BC3_UNORM:
texture.Reset(width, height, mipLevels, stride / 4, TextureFormat.D3DFMT_DXT5);
texture.SetTextureData(readbuf);
break;
case DXGI_FORMAT.DXGI_FORMAT_BC4_UNORM:
texture.Reset(width, height, mipLevels, stride / 4, TextureFormat.D3DFMT_ATI1);
texture.SetTextureData(readbuf);
break;
case DXGI_FORMAT.DXGI_FORMAT_BC5_UNORM:
texture.Reset(width, height, mipLevels, stride / 4, TextureFormat.D3DFMT_ATI2);
texture.SetTextureData(readbuf);
break;
case DXGI_FORMAT.DXGI_FORMAT_BC7_UNORM:
texture.Reset(width, height, mipLevels, stride / 4, TextureFormat.D3DFMT_BC7);
texture.SetTextureData(readbuf);
break;
// uncompressed
case DXGI_FORMAT.DXGI_FORMAT_B5G5R5A1_UNORM:
texture.Reset(width, height, mipLevels, stride, TextureFormat.D3DFMT_A1R5G5B5);
texture.SetTextureData(readbuf);
break;
case DXGI_FORMAT.DXGI_FORMAT_A8_UNORM:
texture.Reset(width, height, mipLevels, stride, TextureFormat.D3DFMT_A8);
texture.SetTextureData(readbuf);
break;
case DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM:
texture.Reset(width, height, mipLevels, stride, TextureFormat.D3DFMT_A8B8G8R8);
texture.SetTextureData(readbuf);
break;
case DXGI_FORMAT.DXGI_FORMAT_R8_UNORM:
texture.Reset(width, height, mipLevels, stride, TextureFormat.D3DFMT_L8);
texture.SetTextureData(readbuf);
break;
case DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM:
texture.Reset(width, height, mipLevels, stride, TextureFormat.D3DFMT_A8R8G8B8);
texture.SetTextureData(readbuf);
break;
default:
MessageBox.Show("format not supported!");
throw new Exception("unsupported format");
}
}