Generic RenderGroup
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using Diamond.Buffers;
|
||||
using Diamond.Buffers;
|
||||
using Diamond.Shaders;
|
||||
using Diamond.Textures;
|
||||
using Diamond.Util;
|
||||
@@ -7,25 +6,55 @@ using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
namespace Diamond.Render
|
||||
{
|
||||
public class RenderGroup
|
||||
/// <summary>
|
||||
/// Manage a group of buffers, ranges, and uniforms to render
|
||||
/// </summary>
|
||||
/// <typeparam name="TInstance">The type of data to use as Instance information</typeparam>
|
||||
/// <typeparam name="TVertex">The type of data to use as Vertex information</typeparam>
|
||||
public class RenderGroup<TInstance, TVertex> where TInstance : struct where TVertex : struct
|
||||
{
|
||||
public SubArray<TileData> Tiles;
|
||||
public Mesh<ObjVertex> Mesh;
|
||||
/// <summary>
|
||||
/// The range of instance values to render
|
||||
/// </summary>
|
||||
public SubArray<TInstance> Instances;
|
||||
/// <summary>
|
||||
/// The range of vertex values to render
|
||||
/// </summary>
|
||||
public Mesh<TVertex> Vertices;
|
||||
|
||||
public Buffer<TileData> TileBuffer;
|
||||
public Buffer<ObjVertex> MeshBuffer;
|
||||
/// <summary>
|
||||
/// The buffer to use for instance data
|
||||
/// </summary>
|
||||
public Buffer<TInstance> InstanceBuffer;
|
||||
/// <summary>
|
||||
/// The buffer to use for instance data
|
||||
/// </summary>
|
||||
public Buffer<TVertex> VertexBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// The program to use to render this Rendergroup
|
||||
/// </summary>
|
||||
public Program Program;
|
||||
|
||||
/// <summary>
|
||||
/// The Texture to use for this Rendergroup
|
||||
/// </summary>
|
||||
public Texture Texture;
|
||||
|
||||
/// <summary>
|
||||
/// View and Projection information for this Rendergroup
|
||||
/// </summary>
|
||||
public Camera Camera;
|
||||
|
||||
/// <summary>
|
||||
/// Draw this rendergroup using the predefined settings.
|
||||
/// </summary>
|
||||
public void Draw()
|
||||
{
|
||||
Program.Use();
|
||||
|
||||
TileBuffer.PointTo(Program);
|
||||
MeshBuffer.PointTo(Program);
|
||||
InstanceBuffer.PointTo(Program);
|
||||
VertexBuffer.PointTo(Program);
|
||||
|
||||
Texture.Bind(0);
|
||||
|
||||
@@ -40,7 +69,7 @@ namespace Diamond.Render
|
||||
if (projLoc.HasValue)
|
||||
GL.UniformMatrix4(projLoc.Value, false, ref Camera.Projection);
|
||||
|
||||
Mesh.DrawInstanced(Tiles);
|
||||
Vertices.DrawInstanced(Instances);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Diamond.Buffers;
|
||||
using NLog;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
@@ -9,6 +10,8 @@ namespace Diamond.Util
|
||||
{
|
||||
public class Mesh<T> where T : struct
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetLogger("Mesh");
|
||||
|
||||
public SubArray<T> Vertices;
|
||||
public PrimitiveType Primitive;
|
||||
|
||||
@@ -45,6 +48,11 @@ namespace Diamond.Util
|
||||
{
|
||||
var tiVdi = VertexDataInfo.GetInfo<TI>();
|
||||
|
||||
if (tiVdi.Divisor == 0)
|
||||
{
|
||||
Logger.Error("Cannot render mesh with instances of type {0} - Divisor is 0", typeof(TI).Name);
|
||||
}
|
||||
|
||||
tVdi.EnableVertexPointers();
|
||||
tiVdi.EnableVertexPointers();
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace hexworld
|
||||
private Buffer<ObjVertex> _meshBuffer;
|
||||
private Buffer<TileData> _tileBuffer;
|
||||
|
||||
private RenderGroup _renderGroup;
|
||||
private RenderGroup<TileData, ObjVertex> _renderGroup;
|
||||
|
||||
protected override void OnClosed(EventArgs e)
|
||||
{
|
||||
@@ -105,15 +105,15 @@ namespace hexworld
|
||||
|
||||
_camera = new Camera();
|
||||
|
||||
_renderGroup = new RenderGroup()
|
||||
_renderGroup = new RenderGroup<TileData, ObjVertex>()
|
||||
{
|
||||
Camera = _camera,
|
||||
Mesh = _cubeMesh,
|
||||
MeshBuffer = _meshBuffer,
|
||||
Vertices = _cubeMesh,
|
||||
VertexBuffer = _meshBuffer,
|
||||
Program = _texPgm,
|
||||
Texture = _grassTex,
|
||||
TileBuffer = _tileBuffer,
|
||||
Tiles = _floorTiles
|
||||
InstanceBuffer = _tileBuffer,
|
||||
Instances = _floorTiles
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user