Convert int? *location to bool has* and int *location
This commit is contained in:
@@ -78,9 +78,9 @@ namespace Diamond.Buffers
|
||||
Wrapper.Bind();
|
||||
foreach (var attr in _vdi.Pointers)
|
||||
{
|
||||
var loc = program.AttributeLocation(attr.Name);
|
||||
if (loc.HasValue)
|
||||
GL.VertexAttribPointer((int) loc, attr.Size, attr.Type, attr.Normalized, _vdi.Stride, attr.Offset);
|
||||
if (program.HasAttribute(attr.Name))
|
||||
GL.VertexAttribPointer(program.AttributeLocation(attr.Name), attr.Size, attr.Type, attr.Normalized,
|
||||
_vdi.Stride, attr.Offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,11 +51,11 @@ namespace Diamond.Buffers
|
||||
|
||||
foreach (var attr in Pointers)
|
||||
{
|
||||
var loc = Program.Current.AttributeLocation(attr.Name);
|
||||
if (!loc.HasValue)
|
||||
if (!Program.Current.HasAttribute(attr.Name))
|
||||
continue;
|
||||
GL.EnableVertexAttribArray((int) loc);
|
||||
GL.VertexAttribDivisor((int) loc, Divisor);
|
||||
var loc = Program.Current.AttributeLocation(attr.Name);
|
||||
GL.EnableVertexAttribArray(loc);
|
||||
GL.VertexAttribDivisor(loc, Divisor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,10 +69,10 @@ namespace Diamond.Buffers
|
||||
|
||||
foreach (var attr in Pointers)
|
||||
{
|
||||
var loc = Program.Current.AttributeLocation(attr.Name);
|
||||
if (!loc.HasValue)
|
||||
if (!Program.Current.HasAttribute(attr.Name))
|
||||
continue;
|
||||
GL.DisableVertexAttribArray((int) loc);
|
||||
var loc = Program.Current.AttributeLocation(attr.Name);
|
||||
GL.DisableVertexAttribArray(loc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,16 +45,12 @@ namespace Diamond.Render
|
||||
|
||||
Texture.Bind(0);
|
||||
|
||||
var texLoc = Program.UniformLocation("tex");
|
||||
var viewLoc = Program.UniformLocation("view");
|
||||
var projLoc = Program.UniformLocation("proj");
|
||||
|
||||
if (texLoc.HasValue)
|
||||
GL.Uniform1(texLoc.Value, 0);
|
||||
if (viewLoc.HasValue)
|
||||
GL.UniformMatrix4(viewLoc.Value, false, ref Camera.View);
|
||||
if (projLoc.HasValue)
|
||||
GL.UniformMatrix4(projLoc.Value, false, ref Camera.Projection);
|
||||
if (Program.HasUniform("tex"))
|
||||
GL.Uniform1(Program.UniformLocation("tex"), 0);
|
||||
if (Program.HasUniform("view"))
|
||||
GL.UniformMatrix4(Program.UniformLocation("view"), false, ref Camera.View);
|
||||
if (Program.HasUniform("proj"))
|
||||
GL.UniformMatrix4(Program.UniformLocation("proj"), false, ref Camera.Projection);
|
||||
|
||||
if (Instance != null)
|
||||
Vertices.DrawInstanced(Instance);
|
||||
|
||||
@@ -28,28 +28,46 @@ namespace Diamond.Shaders
|
||||
Name = name;
|
||||
}
|
||||
|
||||
// todo change these to not use int? - possibly use TryGet, or return negative value if not present
|
||||
/// <summary>
|
||||
/// Check if the program has a uniform
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the uniform</param>
|
||||
/// <returns>Whether the program has this uniform</returns>
|
||||
public bool HasUniform(string name)
|
||||
{
|
||||
return _uniforms.ContainsKey(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the location of a uniform
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the uniform</param>
|
||||
/// <returns>The location, or no value if uniform not present</returns>
|
||||
public int? UniformLocation(string name)
|
||||
/// <returns>The location of the uniform</returns>
|
||||
public int UniformLocation(string name)
|
||||
{
|
||||
if (_uniforms.ContainsKey(name)) return _uniforms[name];
|
||||
return null;
|
||||
if (HasUniform(name)) return _uniforms[name];
|
||||
throw new KeyNotFoundException($"Shader {this} does not contain uniform {name}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the program has an attribute
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the attribute</param>
|
||||
/// <returns>Whether the program has this attribute</returns>
|
||||
public bool HasAttribute(string name)
|
||||
{
|
||||
return _attributes.ContainsKey(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the location of an attribute
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the attribute</param>
|
||||
/// <returns>The location, or no value if attribute not present</returns>
|
||||
public int? AttributeLocation(string name)
|
||||
/// <returns>The location of the attribute</returns>
|
||||
public int AttributeLocation(string name)
|
||||
{
|
||||
if (_attributes.ContainsKey(name)) return _attributes[name];
|
||||
return null;
|
||||
if (HasAttribute(name)) return _attributes[name];
|
||||
throw new KeyNotFoundException($"Shader {this} does not contain attribute {name}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user