UltimateZoneBuilder/Source/Core/Rendering/VisualVertexHandle.cs

117 lines
2.8 KiB
C#
Raw Normal View History

#region ================== Namespaces
using System;
using CodeImp.DoomBuilder.VisualModes;
2013-03-18 13:52:27 +00:00
#endregion
2016-04-27 09:13:07 +00:00
namespace CodeImp.DoomBuilder.Rendering
2013-03-18 13:52:27 +00:00
{
2019-08-09 21:22:16 +00:00
internal sealed class VisualVertexHandle : IDisposable, IRenderResource
2013-03-18 13:52:27 +00:00
{
#region ================== Variables
private VertexBuffer upper;
private VertexBuffer lower;
private bool isdisposed;
#endregion
2013-03-18 13:52:27 +00:00
#region ================== Properties
public VertexBuffer Upper { get { return upper; } }
2013-03-18 13:52:27 +00:00
public VertexBuffer Lower { get { return lower; } }
#endregion
#region ================== Constructor / Disposer
public VisualVertexHandle()
{
// Create geometry
ReloadResource();
// Register as resource
General.Map.Graphics.RegisterResource(this);
}
public void Dispose()
{
// Not already disposed?
if(!isdisposed)
{
if(upper != null) upper.Dispose();
upper = null;
if(lower != null) lower.Dispose();
lower = null;
// Unregister resource
General.Map.Graphics.UnregisterResource(this);
// Done
isdisposed = true;
}
}
#endregion
#region ================== Methods
// This is called resets when the device is reset
// (when resized or display adapter was changed)
public void ReloadResource()
{
float radius = VisualVertex.DEFAULT_SIZE * General.Settings.GZVertexScale3D;
2013-03-18 13:52:27 +00:00
WorldVertex c = new WorldVertex();
WorldVertex v0 = new WorldVertex(-radius, -radius, -radius);
WorldVertex v1 = new WorldVertex(-radius, radius, -radius);
WorldVertex v2 = new WorldVertex(radius, radius, -radius);
WorldVertex v3 = new WorldVertex(radius, -radius, -radius);
WorldVertex v4 = new WorldVertex(-radius, -radius, radius);
WorldVertex v5 = new WorldVertex(-radius, radius, radius);
WorldVertex v6 = new WorldVertex(radius, radius, radius);
WorldVertex v7 = new WorldVertex(radius, -radius, radius);
WorldVertex[] vu = new []{ c, v0,
c, v1,
c, v2,
c, v3,
2013-03-18 13:52:27 +00:00
v0, v1,
v1, v2,
v2, v3,
v3, v0 };
2013-03-18 13:52:27 +00:00
2019-08-08 05:10:35 +00:00
upper = new VertexBuffer(WorldVertex.Stride * vu.Length);
2019-08-08 18:06:35 +00:00
upper.SetBufferData(vu);
2013-03-18 13:52:27 +00:00
WorldVertex[] vl = new[]{ c, v4,
c, v5,
c, v6,
c, v7,
2013-03-18 13:52:27 +00:00
v4, v5,
v5, v6,
v6, v7,
v7, v4 };
2013-03-18 13:52:27 +00:00
2019-08-08 05:10:35 +00:00
lower = new VertexBuffer(WorldVertex.Stride * vl.Length);
2019-08-08 18:06:35 +00:00
lower.SetBufferData(vl);
2013-03-18 13:52:27 +00:00
}
// This is called before a device is reset
// (when resized or display adapter was changed)
public void UnloadResource()
{
// Trash geometry buffers
2013-03-18 13:52:27 +00:00
if(upper != null) upper.Dispose();
upper = null;
if(lower != null) lower.Dispose();
lower = null;
2013-03-18 13:52:27 +00:00
}
#endregion
2013-03-18 13:52:27 +00:00
}
}