Fully migrated GLObject to factory pattern - some bug fixes still needed
This commit is contained in:
@@ -26,10 +26,7 @@ namespace Diamond
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
if (GraphicsContext.CurrentContext == null)
|
||||
Logger.Error("No graphics context, cannot delete {0}", this);
|
||||
else
|
||||
Wrapper.Dispose();
|
||||
Wrapper.Dispose();
|
||||
}
|
||||
|
||||
_disposed = true;
|
||||
|
||||
@@ -7,6 +7,8 @@ namespace Diamond
|
||||
{
|
||||
internal abstract class GLWrapper : IDisposable
|
||||
{
|
||||
private static Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public int Id { get; protected set; }
|
||||
|
||||
public override string ToString() => $"{GetType().Name} {Id}";
|
||||
@@ -26,7 +28,10 @@ namespace Diamond
|
||||
|
||||
// no managed resources to dispose
|
||||
|
||||
GLDelete();
|
||||
if (GraphicsContext.CurrentContext == null)
|
||||
Logger.Error("No graphics context, cannot delete {0}", this);
|
||||
else
|
||||
GLDelete();
|
||||
|
||||
Id = 0;
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ namespace Diamond.Shaders
|
||||
|
||||
public static Program Current { get; private set; }
|
||||
|
||||
private readonly List<Shader> _shaders = new List<Shader>();
|
||||
private readonly Dictionary<string, int> _uniforms = new Dictionary<string, int>();
|
||||
private readonly Dictionary<string, int> _attributes = new Dictionary<string, int>();
|
||||
|
||||
@@ -113,6 +114,12 @@ namespace Diamond.Shaders
|
||||
return true;
|
||||
}
|
||||
|
||||
private void Attach(Shader shader)
|
||||
{
|
||||
_shaders.Add(shader);
|
||||
_program.Attach((ShaderWrapper) shader.Wrapper);
|
||||
}
|
||||
|
||||
public override string ToString() => $"Program \'{Name}\' ({Id})";
|
||||
|
||||
#region Factory Methods
|
||||
@@ -142,7 +149,7 @@ namespace Diamond.Shaders
|
||||
return null;
|
||||
}
|
||||
|
||||
wrapper.Attach((ShaderWrapper) shader.Wrapper);
|
||||
service.Attach(shader);
|
||||
}
|
||||
|
||||
service.Link();
|
||||
@@ -171,9 +178,6 @@ namespace Diamond.Shaders
|
||||
return FromShaders(name, shaderList);
|
||||
}
|
||||
|
||||
public static Program FromFiles(string name, params string[] paths) => FromShaders(name,
|
||||
paths.Select(Shader.FromFile));
|
||||
|
||||
public static Program FromFiles(params string[] paths) => FromShaders(paths.Select(Shader.FromFile));
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Diamond.Shaders
|
||||
}
|
||||
}
|
||||
|
||||
public string InfoLog => GL.GetShaderInfoLog(Id).Trim();
|
||||
public string InfoLog => GL.GetShaderInfoLog(Id);
|
||||
|
||||
public void Compile() => GL.CompileShader(Id);
|
||||
|
||||
@@ -66,12 +66,12 @@ namespace Diamond.Shaders
|
||||
|
||||
#region Factory Methods
|
||||
|
||||
private static readonly Dictionary<string, ShaderType> _extensions = new Dictionary<string, ShaderType>
|
||||
private static readonly Dictionary<string, ShaderType> Extensions = new Dictionary<string, ShaderType>
|
||||
{
|
||||
[".vs"] = ShaderType.VertexShader,
|
||||
[".vert"] = ShaderType.VertexShader,
|
||||
[".fs"] = ShaderType.VertexShader,
|
||||
[".frag"] = ShaderType.VertexShader,
|
||||
[".fs"] = ShaderType.FragmentShader,
|
||||
[".frag"] = ShaderType.FragmentShader,
|
||||
};
|
||||
|
||||
public static Shader FromSource(string source, ShaderType type, string name = "Shader")
|
||||
@@ -122,16 +122,16 @@ namespace Diamond.Shaders
|
||||
|
||||
|
||||
if (ext != null)
|
||||
if (!_extensions.ContainsKey(ext))
|
||||
if (!Extensions.ContainsKey(ext))
|
||||
ext = Path.GetExtension(name);
|
||||
|
||||
if (ext == null || !_extensions.ContainsKey(ext))
|
||||
if (ext == null || !Extensions.ContainsKey(ext))
|
||||
{
|
||||
Logger.Warn("Could not infer shader type from glsl file name {0}", path);
|
||||
return null;
|
||||
}
|
||||
|
||||
var type = _extensions[ext];
|
||||
var type = Extensions[ext];
|
||||
return FromFile(path, type);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user