Started refactors for logging and level loading
This commit is contained in:
@@ -25,10 +25,7 @@ namespace Diamond.Buffers
|
||||
GL.BindBuffer(Target, Id);
|
||||
}
|
||||
|
||||
protected override void Delete()
|
||||
{
|
||||
GL.DeleteBuffer(Id);
|
||||
}
|
||||
protected override void Delete() => GL.DeleteBuffer(Id);
|
||||
|
||||
public void Data<T>(T[] data) where T : struct
|
||||
{
|
||||
|
||||
@@ -45,28 +45,28 @@ namespace Diamond.Buffers
|
||||
yield return Array[Offset + i];
|
||||
}
|
||||
|
||||
public static T[] Join<T>(params SubArray<T>[] subArrays) => Join((IEnumerable<SubArray<T>>) subArrays);
|
||||
public static T1[] Join<T1>(params SubArray<T1>[] subArrays) => Join((IEnumerable<SubArray<T1>>) subArrays);
|
||||
|
||||
public static T[] Join<T>(IEnumerable<SubArray<T>> subArrays)
|
||||
public static T1[] Join<T1>(IEnumerable<SubArray<T1>> subArrays)
|
||||
{
|
||||
HashSet<T[]> uniqueArrays = new HashSet<T[]>();
|
||||
HashSet<T1[]> uniqueArrays = new HashSet<T1[]>();
|
||||
foreach (var subArray in subArrays)
|
||||
{
|
||||
uniqueArrays.Add(subArray.Array);
|
||||
}
|
||||
|
||||
if (uniqueArrays.Count == 0) return new T[0];
|
||||
if (uniqueArrays.Count == 0) return new T1[0];
|
||||
if (uniqueArrays.Count == 1) return uniqueArrays.ToArray()[0];
|
||||
|
||||
var length = 0;
|
||||
var offsets = new Dictionary<T[], int>();
|
||||
var offsets = new Dictionary<T1[], int>();
|
||||
foreach (var uniqueArray in uniqueArrays)
|
||||
{
|
||||
offsets[uniqueArray] = length;
|
||||
length += uniqueArray.Length;
|
||||
}
|
||||
|
||||
var array = new T[length];
|
||||
var array = new T1[length];
|
||||
foreach (var uniqueArray in uniqueArrays)
|
||||
{
|
||||
System.Array.ConstrainedCopy(uniqueArray, 0, array, offsets[uniqueArray], uniqueArray.Length);
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
namespace Diamond
|
||||
{
|
||||
@@ -19,6 +23,7 @@ namespace Diamond
|
||||
protected GLObject(uint id)
|
||||
{
|
||||
Id = id;
|
||||
Debug.WriteLine($"Created GLObject {ToString()} ({Id})");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -26,16 +31,18 @@ namespace Diamond
|
||||
/// </summary>
|
||||
protected abstract void Delete();
|
||||
|
||||
private bool _disposed = false;
|
||||
|
||||
/// <summary>
|
||||
/// Free the name of this object
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed) return;
|
||||
_disposed = true;
|
||||
if (GraphicsContext.CurrentContext == null)
|
||||
{
|
||||
Debug.WriteLine($"No active context. Assuming {this} ({Id}) is disposed.", "[Warning]");
|
||||
return;
|
||||
}
|
||||
Delete();
|
||||
Debug.WriteLine($"Disposed GLObject {ToString()} ({Id})");
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,10 +19,7 @@ namespace Diamond.Shaders
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Delete()
|
||||
{
|
||||
GL.DeleteProgram(Id);
|
||||
}
|
||||
protected override void Delete() => GL.DeleteProgram(Id);
|
||||
|
||||
public void Attach(Shader shader) => GL.AttachShader(Id, shader.Id);
|
||||
|
||||
|
||||
@@ -13,7 +13,12 @@ namespace Diamond.Shaders
|
||||
/// The type of this shader.
|
||||
/// </summary>
|
||||
public readonly ShaderType Type;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The source file name, if it was loaded from a file.
|
||||
/// </summary>
|
||||
public string SourceFile { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets and sets the shader source with <code>glShaderSource</code> and <code>glGetShaderSource</code>.
|
||||
/// </summary>
|
||||
@@ -55,13 +60,7 @@ namespace Diamond.Shaders
|
||||
Type = type;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Frees this gl object. Called by <code>GLObject.Dispose()</code>.
|
||||
/// </summary>
|
||||
protected override void Delete()
|
||||
{
|
||||
GL.DeleteShader(Id);
|
||||
}
|
||||
protected override void Delete() => GL.DeleteShader(Id);
|
||||
|
||||
/// <summary>
|
||||
/// Compile the shader.
|
||||
@@ -93,8 +92,11 @@ namespace Diamond.Shaders
|
||||
/// <returns>The compiled shader</returns>
|
||||
public static Shader FromFile(string path, ShaderType type, out bool success)
|
||||
{
|
||||
var s = new Shader(type);
|
||||
s.Source = File.ReadAllText(path);
|
||||
var s = new Shader(type)
|
||||
{
|
||||
Source = File.ReadAllText(path),
|
||||
SourceFile = ""
|
||||
};
|
||||
success = s.Compile();
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -18,10 +18,7 @@ namespace Diamond.Textures
|
||||
Target = target;
|
||||
}
|
||||
|
||||
protected override void Delete()
|
||||
{
|
||||
GL.DeleteTexture(Id);
|
||||
}
|
||||
protected override void Delete() => GL.DeleteTexture(Id);
|
||||
|
||||
public void Bind()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user