Suggested changes
This commit is contained in:
@@ -14,9 +14,8 @@ namespace Diamond.Buffers
|
||||
public class Buffer<T> : GLObject where T : struct
|
||||
{
|
||||
internal readonly BufferWrap Wrapper;
|
||||
private readonly VertexDataInfo _vdi;
|
||||
|
||||
protected readonly int Size;
|
||||
private readonly VertexDataInfo _vdi;
|
||||
|
||||
/// <summary>
|
||||
/// The target for this buffer; its type
|
||||
@@ -37,7 +36,6 @@ namespace Diamond.Buffers
|
||||
{
|
||||
Wrapper = wrapper;
|
||||
Name = name;
|
||||
Size = Marshal.SizeOf<T>();
|
||||
_vdi = VertexDataInfo.GetInfo<T>();
|
||||
}
|
||||
|
||||
@@ -45,7 +43,7 @@ namespace Diamond.Buffers
|
||||
/// Upload data to this buffer
|
||||
/// </summary>
|
||||
/// <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>
|
||||
/// Upload a range of data to this buffer
|
||||
@@ -53,7 +51,7 @@ namespace Diamond.Buffers
|
||||
/// <param name="offset">The range offset</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>
|
||||
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>
|
||||
/// Upload a range of data to this buffer
|
||||
|
||||
@@ -11,12 +11,12 @@ namespace Diamond
|
||||
/// <summary>
|
||||
/// Logger for all GLObjects
|
||||
/// </summary>
|
||||
protected static readonly Logger Logger = LogManager.GetLogger("GLObject");
|
||||
protected static readonly Logger Logger = LogManager.GetLogger(nameof(GLObject));
|
||||
|
||||
/// <summary>
|
||||
/// Name of this GLObject used for identification
|
||||
/// </summary>
|
||||
public string Name { get; protected set; } = "GLObject";
|
||||
public string Name { get; protected set; } = nameof(GLObject);
|
||||
|
||||
/// <summary>
|
||||
/// Delegate Dispose to underlying wrapper class
|
||||
|
||||
@@ -2,15 +2,28 @@
|
||||
|
||||
namespace Diamond.Render
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages a projection and view matrix
|
||||
/// </summary>
|
||||
public class Camera
|
||||
{
|
||||
private Vector3 _position = Vector3.Zero;
|
||||
private Vector3 _target = -Vector3.One;
|
||||
private Vector3 _up = Vector3.UnitZ;
|
||||
|
||||
/// <summary>
|
||||
/// The view matrix
|
||||
/// </summary>
|
||||
public Matrix4 View;
|
||||
|
||||
/// <summary>
|
||||
/// The projection matrix
|
||||
/// </summary>
|
||||
public Matrix4 Projection;
|
||||
|
||||
/// <summary>
|
||||
/// Sets and updates the position of the view matrix
|
||||
/// </summary>
|
||||
public Vector3 Position
|
||||
{
|
||||
set
|
||||
@@ -21,6 +34,9 @@ namespace Diamond.Render
|
||||
get => _position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets and updates the target of the view matrix
|
||||
/// </summary>
|
||||
public Vector3 Target
|
||||
{
|
||||
set
|
||||
@@ -31,6 +47,9 @@ namespace Diamond.Render
|
||||
get => _target;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets and updates the up vector of the view matrix
|
||||
/// </summary>
|
||||
public Vector3 Up
|
||||
{
|
||||
set
|
||||
@@ -41,6 +60,9 @@ namespace Diamond.Render
|
||||
get => _up;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recalculate the view matrix
|
||||
/// </summary>
|
||||
private void UpdateView()
|
||||
{
|
||||
View = Matrix4.LookAt(_position, _target, _up);
|
||||
|
||||
@@ -12,21 +12,38 @@ using Buffer = Diamond.Buffers.Buffer;
|
||||
|
||||
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
|
||||
{
|
||||
private Logger Logger = LogManager.GetLogger("VertexBuffer");
|
||||
|
||||
/// <summary>
|
||||
/// The name of this buffer object for identification
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The underlying buffer for this object
|
||||
/// </summary>
|
||||
public Buffer<T> Buffer;
|
||||
|
||||
/// <summary>
|
||||
/// A subset of the Buffer's array for this buffer
|
||||
/// </summary>
|
||||
public SubArray<T> Vertices;
|
||||
|
||||
/// <summary>
|
||||
/// Primitive type to render this object
|
||||
/// </summary>
|
||||
public PrimitiveType Primitive;
|
||||
|
||||
private static readonly VertexDataInfo tVdi;
|
||||
|
||||
static VertexBuffer()
|
||||
{
|
||||
tVdi = VertexDataInfo.GetInfo<T>();
|
||||
}
|
||||
/// <summary>
|
||||
/// Vertex data info for this type of data
|
||||
/// </summary>
|
||||
private static readonly VertexDataInfo tVdi = VertexDataInfo.GetInfo<T>();
|
||||
|
||||
internal VertexBuffer(Buffer<T> buffer, SubArray<T> vertices, PrimitiveType primitive, string name)
|
||||
{
|
||||
@@ -36,6 +53,9 @@ namespace Diamond.Render
|
||||
Name = name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Render this buffer
|
||||
/// </summary>
|
||||
public void Draw()
|
||||
{
|
||||
Buffer.PointTo(Program.Current);
|
||||
@@ -47,6 +67,11 @@ namespace Diamond.Render
|
||||
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
|
||||
{
|
||||
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 VertexBuffer<T>[] FromArrays<T>(T[][] arrays, PrimitiveType primitive = PrimitiveType.Triangles,
|
||||
|
||||
@@ -5,11 +5,6 @@
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
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
|
||||
|
||||
private List<RenderGroup<TileData, ObjVertex>> _renderGroups;
|
||||
// private RenderGroup<TileData, ObjVertex> _renderGroup;
|
||||
|
||||
private Camera _camera;
|
||||
|
||||
@@ -100,25 +99,25 @@ namespace hexworld
|
||||
|
||||
_camera = new Camera();
|
||||
|
||||
_renderGroups = new List<RenderGroup<TileData, ObjVertex>>();
|
||||
|
||||
_renderGroups.Add(new RenderGroup<TileData, ObjVertex>()
|
||||
_renderGroups = new List<RenderGroup<TileData, ObjVertex>>
|
||||
{
|
||||
Vertices = _meshVbos["Cube"],
|
||||
Instance = _tileVbos[0],
|
||||
Program = _texPgm,
|
||||
Texture = _stoneTex,
|
||||
Camera = _camera,
|
||||
});
|
||||
|
||||
_renderGroups.Add(new RenderGroup<TileData, ObjVertex>()
|
||||
{
|
||||
Vertices = _meshVbos["Cube"],
|
||||
Instance = _tileVbos[1],
|
||||
Program = _texPgm,
|
||||
Texture = _grassTex,
|
||||
Camera = _camera,
|
||||
});
|
||||
new RenderGroup<TileData, ObjVertex>()
|
||||
{
|
||||
Vertices = _meshVbos["Cube"],
|
||||
Instance = _tileVbos[0],
|
||||
Program = _texPgm,
|
||||
Texture = _stoneTex,
|
||||
Camera = _camera,
|
||||
},
|
||||
new RenderGroup<TileData, ObjVertex>()
|
||||
{
|
||||
Vertices = _meshVbos["Cube"],
|
||||
Instance = _tileVbos[1],
|
||||
Program = _texPgm,
|
||||
Texture = _grassTex,
|
||||
Camera = _camera,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override void OnUpdateFrame(FrameEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user