MCPcopy Create free account
hub / github.com/ZDoom/Raze / LoadShaders

Function LoadShaders

source/common/rendering/gl/gl_shader.cpp:117–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115}
116
117static void LoadShaders()
118{
119 static bool loaded = false;
120 if (loaded)
121 return;
122 loaded = true;
123
124 try
125 {
126 FString path = CreateProgramCacheName(false);
127 FileReader fr;
128 if (!fr.OpenFile(path.GetChars()))
129 I_Error("Could not open shader file");
130
131 char magic[4];
132 fr.Read(magic, 4);
133 if (memcmp(magic, ShaderMagic, 4) != 0)
134 I_Error("Not a shader cache file");
135
136 uint32_t count = fr.ReadUInt32();
137 if (count > 512)
138 I_Error("Too many shaders cached");
139
140 for (uint32_t i = 0; i < count; i++)
141 {
142 char hexdigest[33];
143 if (fr.Read(hexdigest, 32) != 32)
144 I_Error("Read error");
145 hexdigest[32] = 0;
146
147 std::unique_ptr<ProgramBinary> binary(new ProgramBinary());
148 binary->format = fr.ReadUInt32();
149 uint32_t size = fr.ReadUInt32();
150 if (size > 1024 * 1024)
151 I_Error("Shader too big, probably file corruption");
152
153 binary->data.Resize(size);
154 if (fr.Read(binary->data.Data(), binary->data.Size()) != binary->data.Size())
155 I_Error("Read error");
156
157 ShaderCache[hexdigest] = std::move(binary);
158 }
159 }
160 catch (...)
161 {
162 ShaderCache.clear();
163 }
164}
165
166static void SaveShaders()
167{

Callers 1

LoadCachedProgramBinaryFunction · 0.70

Calls 11

I_ErrorFunction · 0.85
moveFunction · 0.85
CreateProgramCacheNameFunction · 0.70
OpenFileMethod · 0.45
GetCharsMethod · 0.45
ReadMethod · 0.45
ReadUInt32Method · 0.45
ResizeMethod · 0.45
DataMethod · 0.45
SizeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected