153 Dictionary<string, string> semanticsByAttribute,
154 Dictionary<string, string> samplersByTexture) {
155 string[] array = shaderCode.Split(
'\n');
156 for (
int i = 0; i < array.Length; i++) {
158 string text = array[i];
160 if (text.StartsWith(
"//")) {
161 text = text.Substring(2).TrimStart();
162 if (text.StartsWith(
'<')
163 && text.EndsWith(
"/>")) {
164 XElement xElement = XElement.Parse(text);
165 if (xElement.Name ==
"Semantic") {
166 XAttribute attribute = xElement.Attribute(
"Attribute");
167 if (attribute ==
null) {
168 throw new InvalidOperationException(
"Missing \"Attribute\" attribute in shader metadata.");
170 XAttribute name = xElement.Attribute(
"Name");
172 throw new InvalidOperationException(
"Missing \"Name\" attribute in shader metadata.");
174 semanticsByAttribute.Add(attribute.Value, name.Value);
177 if (!(xElement.Name ==
"Sampler")) {
178 throw new InvalidOperationException(
"Unrecognized shader metadata node.");
180 XAttribute texture = xElement.Attribute(
"Texture");
181 if (texture ==
null) {
182 throw new InvalidOperationException(
"Missing \"Texture\" attribute in shader metadata.");
184 XAttribute name = xElement.Attribute(
"Name");
186 throw new InvalidOperationException(
"Missing \"Name\" attribute in shader metadata.");
188 samplersByTexture.Add(texture.Value, name.Value);
193 catch (Exception ex) {
194 throw new InvalidOperationException($
"Error in shader metadata, line {i + 1}. {ex.Message}");
243 List<SharpDX.Direct3D11.Buffer> list =
new();
244 List<int> list2 =
new();
245 List<IntPtr> list3 =
new();
246 List<SharpDX.Direct3D11.Buffer> list4 =
new();
247 List<SharpDX.Direct3D11.Buffer> list5 =
new();
248 m_vertexShaderBytecode = CompileShader(
m_vertexShaderCode,
true, list, list2, list3, list4);
249 m_pixelShaderBytecode = CompileShader(
m_pixelShaderCode,
false, list, list2, list3, list5);
259 m_vertexShaderConstantBuffers = list4.ToArray();
260 m_pixelShaderConstantBuffers = list5.ToArray();
261 m_allConstantBuffers = list.ToArray();
262 m_allConstantBuffersSizes = list2.ToArray();
263 m_allConstantBuffersCpu = list3.ToArray();
268 Dictionary<string, string> dictionary = [];
269 Dictionary<string, string> dictionary2 = [];
274 uint vertexShader =
GLWrapper.
GL.CreateShader(ShaderType.VertexShader);
278 GLWrapper.
GL.GetShader(vertexShader, ShaderParameterName.CompileStatus, out
int @params);
280 string shaderInfoLog =
GLWrapper.
GL.GetShaderInfoLog(vertexShader);
281 throw new InvalidOperationException($
"Error compiling vertex shader.\n{shaderInfoLog}");
283 uint pixelShader =
GLWrapper.
GL.CreateShader(ShaderType.FragmentShader);
287 GLWrapper.
GL.GetShader(pixelShader, ShaderParameterName.CompileStatus, out
int params2);
289 string shaderInfoLog2 =
GLWrapper.
GL.GetShaderInfoLog(pixelShader);
290 throw new InvalidOperationException($
"Error compiling pixel shader.\n{shaderInfoLog2}");
297 GLWrapper.
GL.GetProgram(program, ProgramPropertyARB.LinkStatus, out
int params3);
299 string programInfoLog =
GLWrapper.
GL.GetProgramInfoLog(program);
300 throw new InvalidOperationException($
"Error linking program.\n{programInfoLog}");
302 GLWrapper.
GL.GetProgram(program, ProgramPropertyARB.ActiveAttributes, out
int params4);
303 for (
int i = 0; i < params4; i++) {
311 out
string stringBuilder
313 int attribLocation =
GLWrapper.
GL.GetAttribLocation(program, stringBuilder);
314 if (!dictionary.TryGetValue(stringBuilder, out
string value)) {
315 throw new InvalidOperationException($
"Attribute \"{stringBuilder}\" has no semantic defined in shader metadata.");
319 GLWrapper.
GL.GetProgram(program, ProgramPropertyARB.ActiveUniforms, out
int params5);
320 List<ShaderParameter> list = [];
321 Dictionary<string, ShaderParameter> dictionary3 = [];
322 for (
int j = 0; j < params5; j++) {
329 out UniformType type2,
330 out
string stringBuilder2
332 int uniformLocation =
GLWrapper.
GL.GetUniformLocation(program, stringBuilder2);
334 int num = stringBuilder2.IndexOf(
'[');
336 stringBuilder2 = stringBuilder2.Remove(num, stringBuilder2.Length - num);
338 ShaderParameter shaderParameter =
new(
this, stringBuilder2, shaderParameterType, size2) { Location = uniformLocation };
339 dictionary3.Add(shaderParameter.
Name, shaderParameter);
340 list.Add(shaderParameter);
342 if (!dictionary2.TryGetValue(shaderParameter.
Name, out
string value2)) {
343 throw new InvalidOperationException($
"Texture \"{shaderParameter.Name}\" has no sampler defined in shader metadata.");
346 dictionary3.Add(value2, shaderParameter2);
347 list.Add(shaderParameter2);
351 foreach (KeyValuePair<string, ShaderParameter> item
in dictionary3) {
353 value3.Location = item.Value.Location;
357 for (
int k = 0; k < parameters.Length; k++) {
367 throw new InvalidOperationException(
"u_glymul parameter has invalid type.");