Suggested changes
This commit is contained in:
@@ -14,9 +14,8 @@ namespace Diamond.Buffers
|
|||||||
public class Buffer<T> : GLObject where T : struct
|
public class Buffer<T> : GLObject where T : struct
|
||||||
{
|
{
|
||||||
internal readonly BufferWrap Wrapper;
|
internal readonly BufferWrap Wrapper;
|
||||||
private readonly VertexDataInfo _vdi;
|
|
||||||
|
|
||||||
protected readonly int Size;
|
private readonly VertexDataInfo _vdi;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The target for this buffer; its type
|
/// The target for this buffer; its type
|
||||||
@@ -37,7 +36,6 @@ namespace Diamond.Buffers
|
|||||||
{
|
{
|
||||||
Wrapper = wrapper;
|
Wrapper = wrapper;
|
||||||
Name = name;
|
Name = name;
|
||||||
Size = Marshal.SizeOf<T>();
|
|
||||||
_vdi = VertexDataInfo.GetInfo<T>();
|
_vdi = VertexDataInfo.GetInfo<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +43,7 @@ namespace Diamond.Buffers
|
|||||||
/// Upload data to this buffer
|
/// Upload data to this buffer
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data">The data to upload</param>
|
/// <param name="data">The data to upload</param>
|
||||||
public void Data(T[] data) => Wrapper.Data(Size, data);
|
public void Data(T[] data) => Wrapper.Data(_vdi.Stride, data);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Upload a range of data to this buffer
|
/// Upload a range of data to this buffer
|
||||||
@@ -53,7 +51,7 @@ namespace Diamond.Buffers
|
|||||||
/// <param name="offset">The range offset</param>
|
/// <param name="offset">The range offset</param>
|
||||||
/// <param name="count">The range length</param>
|
/// <param name="count">The range length</param>
|
||||||
/// <param name="data">The data to upload, offset and length apply to both this and the target</param>
|
/// <param name="data">The data to upload, offset and length apply to both this and the target</param>
|
||||||
public void Data(int offset, int count, T[] data) => Wrapper.SubData(Size, offset, count, data);
|
public void Data(int offset, int count, T[] data) => Wrapper.SubData(_vdi.Stride, offset, count, data);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Upload a range of data to this buffer
|
/// Upload a range of data to this buffer
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ namespace Diamond
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Logger for all GLObjects
|
/// Logger for all GLObjects
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected static readonly Logger Logger = LogManager.GetLogger("GLObject");
|
protected static readonly Logger Logger = LogManager.GetLogger(nameof(GLObject));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Name of this GLObject used for identification
|
/// Name of this GLObject used for identification
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Name { get; protected set; } = "GLObject";
|
public string Name { get; protected set; } = nameof(GLObject);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delegate Dispose to underlying wrapper class
|
/// Delegate Dispose to underlying wrapper class
|
||||||
|
|||||||
@@ -2,15 +2,28 @@
|
|||||||
|
|
||||||
namespace Diamond.Render
|
namespace Diamond.Render
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Manages a projection and view matrix
|
||||||
|
/// </summary>
|
||||||
public class Camera
|
public class Camera
|
||||||
{
|
{
|
||||||
private Vector3 _position = Vector3.Zero;
|
private Vector3 _position = Vector3.Zero;
|
||||||
private Vector3 _target = -Vector3.One;
|
private Vector3 _target = -Vector3.One;
|
||||||
private Vector3 _up = Vector3.UnitZ;
|
private Vector3 _up = Vector3.UnitZ;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The view matrix
|
||||||
|
/// </summary>
|
||||||
public Matrix4 View;
|
public Matrix4 View;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The projection matrix
|
||||||
|
/// </summary>
|
||||||
public Matrix4 Projection;
|
public Matrix4 Projection;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets and updates the position of the view matrix
|
||||||
|
/// </summary>
|
||||||
public Vector3 Position
|
public Vector3 Position
|
||||||
{
|
{
|
||||||
set
|
set
|
||||||
@@ -21,6 +34,9 @@ namespace Diamond.Render
|
|||||||
get => _position;
|
get => _position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets and updates the target of the view matrix
|
||||||
|
/// </summary>
|
||||||
public Vector3 Target
|
public Vector3 Target
|
||||||
{
|
{
|
||||||
set
|
set
|
||||||
@@ -31,6 +47,9 @@ namespace Diamond.Render
|
|||||||
get => _target;
|
get => _target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets and updates the up vector of the view matrix
|
||||||
|
/// </summary>
|
||||||
public Vector3 Up
|
public Vector3 Up
|
||||||
{
|
{
|
||||||
set
|
set
|
||||||
@@ -41,6 +60,9 @@ namespace Diamond.Render
|
|||||||
get => _up;
|
get => _up;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Recalculate the view matrix
|
||||||
|
/// </summary>
|
||||||
private void UpdateView()
|
private void UpdateView()
|
||||||
{
|
{
|
||||||
View = Matrix4.LookAt(_position, _target, _up);
|
View = Matrix4.LookAt(_position, _target, _up);
|
||||||
|
|||||||
@@ -12,21 +12,38 @@ using Buffer = Diamond.Buffers.Buffer;
|
|||||||
|
|
||||||
namespace Diamond.Render
|
namespace Diamond.Render
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Manage a vertex buffer object
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">Buffer data type</typeparam>
|
||||||
public class VertexBuffer<T> : IDisposable where T : struct
|
public class VertexBuffer<T> : IDisposable where T : struct
|
||||||
{
|
{
|
||||||
private Logger Logger = LogManager.GetLogger("VertexBuffer");
|
private Logger Logger = LogManager.GetLogger("VertexBuffer");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The name of this buffer object for identification
|
||||||
|
/// </summary>
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The underlying buffer for this object
|
||||||
|
/// </summary>
|
||||||
public Buffer<T> Buffer;
|
public Buffer<T> Buffer;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A subset of the Buffer's array for this buffer
|
||||||
|
/// </summary>
|
||||||
public SubArray<T> Vertices;
|
public SubArray<T> Vertices;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Primitive type to render this object
|
||||||
|
/// </summary>
|
||||||
public PrimitiveType Primitive;
|
public PrimitiveType Primitive;
|
||||||
|
|
||||||
private static readonly VertexDataInfo tVdi;
|
/// <summary>
|
||||||
|
/// Vertex data info for this type of data
|
||||||
static VertexBuffer()
|
/// </summary>
|
||||||
{
|
private static readonly VertexDataInfo tVdi = VertexDataInfo.GetInfo<T>();
|
||||||
tVdi = VertexDataInfo.GetInfo<T>();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal VertexBuffer(Buffer<T> buffer, SubArray<T> vertices, PrimitiveType primitive, string name)
|
internal VertexBuffer(Buffer<T> buffer, SubArray<T> vertices, PrimitiveType primitive, string name)
|
||||||
{
|
{
|
||||||
@@ -36,6 +53,9 @@ namespace Diamond.Render
|
|||||||
Name = name;
|
Name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Render this buffer
|
||||||
|
/// </summary>
|
||||||
public void Draw()
|
public void Draw()
|
||||||
{
|
{
|
||||||
Buffer.PointTo(Program.Current);
|
Buffer.PointTo(Program.Current);
|
||||||
@@ -47,6 +67,11 @@ namespace Diamond.Render
|
|||||||
tVdi.DisableVertexPointers();
|
tVdi.DisableVertexPointers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Render this buffer using a second buffer as instance data
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TI"></typeparam>
|
||||||
|
/// <param name="instance"></param>
|
||||||
public void DrawInstanced<TI>(VertexBuffer<TI> instance) where TI : struct
|
public void DrawInstanced<TI>(VertexBuffer<TI> instance) where TI : struct
|
||||||
{
|
{
|
||||||
var tiVdi = VertexBuffer<TI>.tVdi;
|
var tiVdi = VertexBuffer<TI>.tVdi;
|
||||||
@@ -76,6 +101,9 @@ namespace Diamond.Render
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Static operations for vertex buffers
|
||||||
|
/// </summary>
|
||||||
public static class VertexBuffer
|
public static class VertexBuffer
|
||||||
{
|
{
|
||||||
public static VertexBuffer<T>[] FromArrays<T>(T[][] arrays, PrimitiveType primitive = PrimitiveType.Triangles,
|
public static VertexBuffer<T>[] FromArrays<T>(T[][] arrays, PrimitiveType primitive = PrimitiveType.Triangles,
|
||||||
|
|||||||
@@ -5,11 +5,6 @@
|
|||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
using (var gw = new HexRender(1280, 720)) gw.Run();
|
using (var gw = new HexRender(1280, 720)) gw.Run();
|
||||||
|
|
||||||
// var tile = JsonConvert.DeserializeObject<TileInfo>("{\"mesh\":\"RightColumn\", \"pos\": {\"x\": 1, \"y\": 2, \"z\": 3}}");
|
|
||||||
//
|
|
||||||
// Console.Out.WriteLine("tile = {0}", tile);
|
|
||||||
// Console.ReadKey();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,6 @@ namespace hexworld
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private List<RenderGroup<TileData, ObjVertex>> _renderGroups;
|
private List<RenderGroup<TileData, ObjVertex>> _renderGroups;
|
||||||
// private RenderGroup<TileData, ObjVertex> _renderGroup;
|
|
||||||
|
|
||||||
private Camera _camera;
|
private Camera _camera;
|
||||||
|
|
||||||
@@ -100,25 +99,25 @@ namespace hexworld
|
|||||||
|
|
||||||
_camera = new Camera();
|
_camera = new Camera();
|
||||||
|
|
||||||
_renderGroups = new List<RenderGroup<TileData, ObjVertex>>();
|
_renderGroups = new List<RenderGroup<TileData, ObjVertex>>
|
||||||
|
|
||||||
_renderGroups.Add(new RenderGroup<TileData, ObjVertex>()
|
|
||||||
{
|
{
|
||||||
Vertices = _meshVbos["Cube"],
|
new RenderGroup<TileData, ObjVertex>()
|
||||||
Instance = _tileVbos[0],
|
{
|
||||||
Program = _texPgm,
|
Vertices = _meshVbos["Cube"],
|
||||||
Texture = _stoneTex,
|
Instance = _tileVbos[0],
|
||||||
Camera = _camera,
|
Program = _texPgm,
|
||||||
});
|
Texture = _stoneTex,
|
||||||
|
Camera = _camera,
|
||||||
_renderGroups.Add(new RenderGroup<TileData, ObjVertex>()
|
},
|
||||||
{
|
new RenderGroup<TileData, ObjVertex>()
|
||||||
Vertices = _meshVbos["Cube"],
|
{
|
||||||
Instance = _tileVbos[1],
|
Vertices = _meshVbos["Cube"],
|
||||||
Program = _texPgm,
|
Instance = _tileVbos[1],
|
||||||
Texture = _grassTex,
|
Program = _texPgm,
|
||||||
Camera = _camera,
|
Texture = _grassTex,
|
||||||
});
|
Camera = _camera,
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnUpdateFrame(FrameEventArgs e)
|
protected override void OnUpdateFrame(FrameEventArgs e)
|
||||||
|
|||||||
Reference in New Issue
Block a user