2014-09-17 12:46:47 +00:00
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using CodeImp.DoomBuilder.VisualModes;
|
2014-09-16 08:51:27 +00:00
|
|
|
|
using SlimDX.Direct3D9;
|
2013-03-18 13:52:27 +00:00
|
|
|
|
using CodeImp.DoomBuilder.Rendering;
|
|
|
|
|
|
2014-09-17 12:46:47 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2013-03-18 13:52:27 +00:00
|
|
|
|
namespace CodeImp.DoomBuilder.GZBuilder.Rendering
|
|
|
|
|
{
|
2014-09-17 12:46:47 +00:00
|
|
|
|
internal sealed class VisualVertexHandle : IDisposable, ID3DResource
|
2013-03-18 13:52:27 +00:00
|
|
|
|
{
|
2014-09-17 12:46:47 +00:00
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
|
|
private VertexBuffer upper;
|
|
|
|
|
private VertexBuffer lower;
|
|
|
|
|
private bool isdisposed;
|
|
|
|
|
|
|
|
|
|
#endregion
|
2013-03-18 13:52:27 +00:00
|
|
|
|
|
2014-09-17 12:46:47 +00:00
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
|
|
public VertexBuffer Upper { get { return upper; } }
|
2013-03-18 13:52:27 +00:00
|
|
|
|
public VertexBuffer Lower { get { return lower; } }
|
|
|
|
|
|
2014-09-17 12:46:47 +00:00
|
|
|
|
#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();
|
|
|
|
|
if(lower != null) lower.Dispose();
|
|
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
|
{
|
2014-09-16 08:51:27 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2015-12-28 15:01:53 +00:00
|
|
|
|
WorldVertex[] vu = new []{ c, v0,
|
|
|
|
|
c, v1,
|
|
|
|
|
c, v2,
|
|
|
|
|
c, v3,
|
2013-03-18 13:52:27 +00:00
|
|
|
|
|
2015-12-28 15:01:53 +00:00
|
|
|
|
v0, v1,
|
|
|
|
|
v1, v2,
|
|
|
|
|
v2, v3,
|
|
|
|
|
v3, v0 };
|
2013-03-18 13:52:27 +00:00
|
|
|
|
|
2014-09-17 12:46:47 +00:00
|
|
|
|
upper = new VertexBuffer(General.Map.Graphics.Device, WorldVertex.Stride * vu.Length, Usage.WriteOnly | Usage.Dynamic, VertexFormat.None, Pool.Default);
|
|
|
|
|
upper.Lock(0, WorldVertex.Stride * vu.Length, LockFlags.None).WriteRange(vu);
|
2013-03-18 13:52:27 +00:00
|
|
|
|
upper.Unlock();
|
|
|
|
|
|
2015-12-28 15:01:53 +00:00
|
|
|
|
WorldVertex[] vl = new[]{ c, v4,
|
|
|
|
|
c, v5,
|
|
|
|
|
c, v6,
|
|
|
|
|
c, v7,
|
2013-03-18 13:52:27 +00:00
|
|
|
|
|
2015-12-28 15:01:53 +00:00
|
|
|
|
v4, v5,
|
|
|
|
|
v5, v6,
|
|
|
|
|
v6, v7,
|
|
|
|
|
v7, v4 };
|
2013-03-18 13:52:27 +00:00
|
|
|
|
|
2014-09-17 12:46:47 +00:00
|
|
|
|
lower = new VertexBuffer(General.Map.Graphics.Device, WorldVertex.Stride * vl.Length, Usage.WriteOnly | Usage.Dynamic, VertexFormat.None, Pool.Default);
|
|
|
|
|
lower.Lock(0, WorldVertex.Stride * vl.Length, LockFlags.None).WriteRange(vl);
|
2013-03-18 13:52:27 +00:00
|
|
|
|
lower.Unlock();
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-17 12:46:47 +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();
|
|
|
|
|
if(lower != null) lower.Dispose();
|
2014-09-17 12:46:47 +00:00
|
|
|
|
upper = null;
|
|
|
|
|
lower = null;
|
2013-03-18 13:52:27 +00:00
|
|
|
|
}
|
2014-09-17 12:46:47 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
2013-03-18 13:52:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|