本文整理汇总了C#中IStream.WriteUInt32方法的典型用法代码示例。如果您正苦于以下问题:C# IStream.WriteUInt32方法的具体用法?C# IStream.WriteUInt32怎么用?C# IStream.WriteUInt32使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IStream
的用法示例。
在下文中一共展示了IStream.WriteUInt32方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportShader
/// <summary>
/// Deserializes a serialized shader and injects it into the cache file.
/// </summary>
/// <param name="serializedShader">The serialized shader data to inject.</param>
/// <param name="stream">The stream to manipulate. It should be positioned where the shader pointer should be written.</param>
/// <returns>
/// <c>true</c> if the shader was successfully deserialized and injected.
/// </returns>
public bool ImportShader(byte[] serializedShader, IStream stream)
{
if (serializedShader == null || serializedShader.Length == 0)
{
// Null shader
stream.WriteUInt32(0);
return true;
}
var pointerOffset = stream.Position + _cacheFile.MetaArea.OffsetToPointer(0);
using (var reader = new EndianReader(new MemoryStream(serializedShader), Endian.BigEndian))
{
// Check the magic
if (reader.ReadInt32() != SerializationMagic)
return false;
// Read the shader type and determine which info layout to use
var type = (ShaderType)reader.ReadByte();
StructureLayout infoLayout = null;
if (type == ShaderType.Pixel)
infoLayout = _pixelShaderInfoLayout;
else if (type == ShaderType.Vertex)
infoLayout = _vertexShaderInfoLayout;
if (infoLayout == null)
return false;
// Read and verify the layout size
var infoLayoutSize = reader.ReadInt32();
if (infoLayoutSize != infoLayout.Size)
return false;
// Read the raw debug info and data
var debugInfoSize = reader.ReadUInt32();
var debugInfo = reader.ReadBlock((int)debugInfoSize);
var dataSize = reader.ReadUInt32();
var data = reader.ReadBlock((int)dataSize);
// Allocate space for the shader data and write it in
var dataAddr = _cacheFile.Allocator.Allocate((int)dataSize, 0x10, stream); // 16-byte aligned
var dataOffset = _cacheFile.MetaArea.PointerToOffset(dataAddr);
stream.SeekTo(dataOffset);
stream.WriteBlock(data);
// Allocate and zero space for the info structures
var infoSize = infoLayoutSize + (int)debugInfoSize;
var infoAddr = _cacheFile.Allocator.Allocate(infoSize, stream);
var infoOffset = _cacheFile.MetaArea.PointerToOffset(infoAddr);
stream.SeekTo(infoOffset);
StreamUtil.Fill(stream, 0, infoSize);
// Write the basic info structure
stream.SeekTo(infoOffset);
var infoValues = new StructureValueCollection();
infoValues.SetInteger("shader data address", dataAddr);
StructureWriter.WriteStructure(infoValues, infoLayout, stream);
// Write the debug info structure
stream.WriteBlock(debugInfo);
// Finally, write the shader pointer
stream.SeekTo(pointerOffset - _cacheFile.MetaArea.OffsetToPointer(0));
stream.WriteUInt32(infoAddr);
}
return true;
}