Added ToString and descriptive log messages, use IBO
This commit is contained in:
@@ -82,6 +82,7 @@ namespace Diamond
|
||||
get => _elementArrayBuffer;
|
||||
set
|
||||
{
|
||||
Logger.Debug("Using {0} as ElementArrayBuffer for {1}", (object)value ?? "default buffer", this);
|
||||
Current = this;
|
||||
Buffer.ElementArrayBuffer = _elementArrayBuffer = value;
|
||||
}
|
||||
@@ -112,18 +113,19 @@ namespace Diamond
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.Debug("Attaching {0} to {1}", buffer, this);
|
||||
|
||||
Current = this;
|
||||
Buffer.ArrayBuffer = buffer;
|
||||
|
||||
var stride = Marshal.SizeOf<T>();
|
||||
foreach (var field in typeof(T).GetFields())
|
||||
{
|
||||
Logger.Debug("Analyzing {0}", field.Name);
|
||||
var offset = Marshal.OffsetOf<T>(field.Name);
|
||||
foreach (var vai in field.GetCustomAttributes<VertexAttribAttribute>(false))
|
||||
{
|
||||
Logger.Debug(
|
||||
$"Enabling {vai.Attribute}, {vai.Size}, {vai.Type}, {vai.Normalized}, {stride}, {offset}");
|
||||
Logger.Debug($"Enabling attribute (id:{vai.Attribute}, size:{vai.Size}, " +
|
||||
$"type:{vai.Type}, norm:{vai.Normalized}, stride:{stride}, offset:{offset})");
|
||||
|
||||
GL.EnableVertexAttribArray(vai.Attribute);
|
||||
GL.VertexAttribPointer(vai.Attribute, vai.Size, vai.Type, vai.Normalized, stride, offset);
|
||||
@@ -136,6 +138,10 @@ namespace Diamond
|
||||
/// </summary>
|
||||
public void Bind() => Bind(this);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString() =>
|
||||
$"'Vertex Array {Id}'";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Factory Methods
|
||||
|
||||
@@ -33,12 +33,14 @@ namespace hexworld
|
||||
Y = (DisplayDevice.Default.Height - Height) / 2;
|
||||
}
|
||||
|
||||
private Buffer<Vert> _vbo;
|
||||
|
||||
private VertexArray _triVao;
|
||||
private Buffer<Vert> _triVbo;
|
||||
private Buffer<uint> _triIbo;
|
||||
private Program _whitePgm;
|
||||
|
||||
private VertexArray _recVao;
|
||||
private Buffer<Vert> _recVbo;
|
||||
private Buffer<uint> _recIbo;
|
||||
private Program _redPgm;
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -54,18 +56,11 @@ namespace hexworld
|
||||
_redPgm = Program.FromShaders(vs, white);
|
||||
}
|
||||
|
||||
_triVbo = Buffer.FromData(new[]
|
||||
_vbo = Buffer.FromData(new[]
|
||||
{
|
||||
new Vert(-.8f, -.8f),
|
||||
new Vert(+.8f, -.8f),
|
||||
new Vert(+.0f, +.8f)
|
||||
});
|
||||
Program.Current = _redPgm;
|
||||
_triVao = VertexArray.Create();
|
||||
_triVao.Attach(_triVbo);
|
||||
|
||||
_recVbo = Buffer.FromData(new[]
|
||||
{
|
||||
new Vert(+.0f, +.8f),
|
||||
new Vert(-.9f, -.5f),
|
||||
new Vert(+.9f, -.5f),
|
||||
new Vert(+.9f, +.5f),
|
||||
@@ -73,9 +68,26 @@ namespace hexworld
|
||||
new Vert(-.9f, +.5f),
|
||||
new Vert(-.9f, -.5f)
|
||||
});
|
||||
|
||||
_triIbo = Buffer.FromData(new uint[]
|
||||
{
|
||||
0, 1, 2
|
||||
});
|
||||
|
||||
Program.Current = _redPgm;
|
||||
_triVao = VertexArray.Create();
|
||||
_triVao.Attach(_vbo);
|
||||
_triVao.ElementArrayBuffer = _triIbo;
|
||||
|
||||
_recIbo = Buffer.FromData(new uint[]
|
||||
{
|
||||
3, 4, 5, 6, 7, 8
|
||||
});
|
||||
|
||||
Program.Current = _whitePgm;
|
||||
_recVao = VertexArray.Create();
|
||||
_recVao.Attach(_recVbo);
|
||||
_recVao.Attach(_vbo);
|
||||
_recVao.ElementArrayBuffer = _recIbo;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -83,9 +95,6 @@ namespace hexworld
|
||||
{
|
||||
base.OnUnload(e);
|
||||
|
||||
_triVbo?.Dispose();
|
||||
_recVbo?.Dispose();
|
||||
|
||||
_whitePgm?.Dispose();
|
||||
_redPgm?.Dispose();
|
||||
}
|
||||
@@ -101,11 +110,11 @@ namespace hexworld
|
||||
|
||||
Program.Current = _redPgm;
|
||||
VertexArray.Current = _triVao;
|
||||
GL.DrawArrays(PrimitiveType.Triangles, 0, 3);
|
||||
GL.DrawElements(PrimitiveType.Triangles, 3, DrawElementsType.UnsignedInt, 0);
|
||||
|
||||
Program.Current = _whitePgm;
|
||||
VertexArray.Current = _recVao;
|
||||
GL.DrawArrays(PrimitiveType.Triangles, 0, 6);
|
||||
GL.DrawElements(PrimitiveType.Triangles, 6, DrawElementsType.UnsignedInt, 0);
|
||||
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user