public static void SaveShaderInstance(string path, ulong guid, string name) { using (Stream stream = IO.OpenFile(guid)) { if (stream == null) { return; } teShaderInstance instance = new teShaderInstance(stream); using (Stream stream2 = IO.OpenFile(instance.Header.ShaderCode)) { if (stream2 == null) { return; } teShaderCode shaderCode = new teShaderCode(stream2); SaveShaderInstance(path, guid, name, instance, shaderCode); } } }
public void SaveShaderGroup(teShaderGroup shaderGroup, string path) { int i = 0; foreach (ulong shaderGroupInstance in shaderGroup.Instances) { teShaderInstance instance = new teShaderInstance(IO.OpenFile(shaderGroupInstance)); teShaderCode shaderCode = new teShaderCode(IO.OpenFile(instance.Header.ShaderCode)); string name = null; if (shaderGroup.Hashes != null && shaderGroup.Hashes[i] != 0) { name = shaderGroup.Hashes[i].ToString("X8"); } SaveShaderInstance(path, shaderGroupInstance, name, instance, shaderCode); i++; } }
public static void SaveShaderInstance(string path, ulong guid, string name, teShaderInstance instance, teShaderCode shaderCode) { if (name == null) { name = teResourceGUID.AsString(guid); } string instanceDirectory = Path.Combine(path, shaderCode.Header.ShaderType.ToString(), name); IO.WriteFile(guid, instanceDirectory); IO.WriteFile(instance.Header.ShaderCode, instanceDirectory); //using (Stream file = File.OpenWrite(Path.Combine(instanceDirectory, IO.GetFileName(instance.Header.ShaderCode)))) { // file.SetLength(0); // file.Write(shaderCode.Data, 0, shaderCode.Header.DataSize); //} using (StreamWriter writer = new StreamWriter(Path.Combine(instanceDirectory, IO.GetFileName(instance.Header.ShaderCode)) + ".meta")) { writer.WriteLine($"{shaderCode.Header.ShaderType}"); writer.WriteLine("{texture \"hash\"} : {shader input index}"); if (instance.ShaderResources == null) { return; } foreach (teShaderInstance.ShaderResourceDefinition textureInputDefinition in instance.ShaderResources) { writer.WriteLine($"{textureInputDefinition.NameHash:X8} : {textureInputDefinition.Register}"); } } }