-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShaderModelParser.cs
More file actions
103 lines (87 loc) · 3.91 KB
/
Copy pathShaderModelParser.cs
File metadata and controls
103 lines (87 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Collections.Generic;
using BfshaLibrary.Core;
using BfshaLibrary;
using BfshaLibrary.Switch.Core;
namespace BfshaLibrary.Switch
{
public class ShaderModelParser
{
public static void Load(BfshaFileSwitchLoader loader, ShaderModel shaderModel)
{
shaderModel.Name = loader.LoadString();
shaderModel.StaticOptions = loader.LoadDictValues<ShaderOption>();
shaderModel.DynamiOptions = loader.LoadDictValues<ShaderOption>();
shaderModel.Attributes = loader.LoadDictValues<Attribute>();
shaderModel.Samplers = loader.LoadDictValues<Sampler>();
if (loader.BfshaFile.VersionMajor2 >= 8)
{
loader.ReadInt64();
loader.ReadInt64();
}
shaderModel.UniformBlocks = loader.LoadDictValues<UniformBlock>();
long uniformArrayOffset = loader.ReadOffset();
if (loader.BfshaFile.VersionMajor2 >= 7)
{
loader.ReadInt64();
loader.ReadInt64();
loader.ReadInt64();
}
long shaderProgramArrayOffset = loader.ReadOffset();
long keyTableOffset = loader.ReadOffset();
long shaderArchiveOffset = loader.ReadOffset();
long glShaderInfoOffset = loader.ReadOffset();
long shaderFileOffset = loader.ReadOffset();
long MutexTypePtr = loader.ReadOffset();
long userPointer = loader.ReadOffset();
long updateCallback = loader.ReadOffset();
if (loader.BfshaFile.VersionMajor2 >= 7)
{
//padding
loader.ReadInt64();
loader.ReadInt64();
}
uint uniformCount = loader.ReadUInt32();
if (loader.BfshaFile.VersionMajor2 >= 7) {
uint shaderStorageCount = loader.ReadUInt32();
}
int defaultProgramIndex = loader.ReadInt32();
ushort staticOptionCount = loader.ReadUInt16();
ushort dynamicOptionCount = loader.ReadUInt16();
ushort programCount = loader.ReadUInt16();
if (loader.BfshaFile.VersionMajor2 < 7)
loader.ReadUInt16();
shaderModel.StaticKeyLength = loader.ReadByte();
shaderModel.DynamicKeyLength = loader.ReadByte();
byte attribCount = loader.ReadByte();
byte samplerCount = loader.ReadByte();
if (loader.BfshaFile.VersionMajor2 >= 8)
loader.ReadByte();
byte uniformBlockCount = loader.ReadByte();
loader.ReadByte();
byte[] systemBlockIndices = loader.ReadBytes(4);
if (loader.BfshaFile.VersionMajor2 >= 8)
loader.ReadBytes(11);
else if (loader.BfshaFile.VersionMajor2 >= 7)
loader.ReadBytes(4);
else
loader.ReadBytes(6);
int bnshSize = 0;
if (shaderFileOffset != 0)
{
//Go into the bnsh file and get the file size
using (loader.TemporarySeek(shaderFileOffset + 0x1C, System.IO.SeekOrigin.Begin)) {
bnshSize = (int)loader.ReadUInt32();
}
}
shaderModel.BnshFileStream = new SubStream(loader.BaseStream, shaderFileOffset, bnshSize);
shaderModel.UniformVars = loader.LoadList<UniformVar>((int)uniformCount, (uint)uniformArrayOffset);
shaderModel.Programs = loader.LoadList<ResShaderProgram>(programCount, (uint)shaderProgramArrayOffset);
shaderModel.shaderOffset = shaderFileOffset;
//Static and dynamic keys for each program
shaderModel.KeyTable = loader.LoadCustom(() => loader.ReadInt32s(
(shaderModel.StaticKeyLength + shaderModel.DynamicKeyLength) * shaderModel.ProgramCount),
(uint)keyTableOffset);
}
}
}