|
|
@ -1,14 +1,15 @@ |
|
|
|
namespace ClickableTransparentOverlay |
|
|
|
// <auto-generated /> |
|
|
|
|
|
|
|
namespace ClickableTransparentOverlay |
|
|
|
{ |
|
|
|
{ |
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
|
|
using System.IO; |
|
|
|
using System.Numerics; |
|
|
|
using System.Numerics; |
|
|
|
using System.Reflection; |
|
|
|
using System.Reflection; |
|
|
|
using System.IO; |
|
|
|
|
|
|
|
using Veldrid; |
|
|
|
|
|
|
|
using System.Runtime.CompilerServices; |
|
|
|
using System.Runtime.CompilerServices; |
|
|
|
using ImGuiNET; |
|
|
|
using ImGuiNET; |
|
|
|
using NativeLibraryLoader; |
|
|
|
using NativeLibraryLoader; |
|
|
|
|
|
|
|
using Veldrid; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// A modified version of ImGui.NET.SampleProgram's ImGuiController. |
|
|
|
/// A modified version of ImGui.NET.SampleProgram's ImGuiController. |
|
|
@ -16,93 +17,135 @@ |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
public sealed class ImGuiController : IDisposable |
|
|
|
public sealed class ImGuiController : IDisposable |
|
|
|
{ |
|
|
|
{ |
|
|
|
private GraphicsDevice _gd; |
|
|
|
#pragma warning disable CS0169 // Force Copy this DLL |
|
|
|
private bool _frameBegun; |
|
|
|
private readonly DefaultPathResolver useless; |
|
|
|
|
|
|
|
#pragma warning restore CS0169 |
|
|
|
|
|
|
|
|
|
|
|
// Veldrid objects |
|
|
|
private readonly IntPtr fontAtlasID = (IntPtr)1; |
|
|
|
private DeviceBuffer _vertexBuffer; |
|
|
|
|
|
|
|
private DeviceBuffer _indexBuffer; |
|
|
|
|
|
|
|
private DeviceBuffer _projMatrixBuffer; |
|
|
|
|
|
|
|
private Texture _fontTexture; |
|
|
|
|
|
|
|
private TextureView _fontTextureView; |
|
|
|
|
|
|
|
private Shader _vertexShader; |
|
|
|
|
|
|
|
private Shader _fragmentShader; |
|
|
|
|
|
|
|
private ResourceLayout _layout; |
|
|
|
|
|
|
|
private ResourceLayout _textureLayout; |
|
|
|
|
|
|
|
private Pipeline _pipeline; |
|
|
|
|
|
|
|
private ResourceSet _mainResourceSet; |
|
|
|
|
|
|
|
private ResourceSet _fontTextureResourceSet; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private IntPtr _fontAtlasID = (IntPtr)1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int _windowWidth; |
|
|
|
|
|
|
|
private int _windowHeight; |
|
|
|
|
|
|
|
private Vector2 _scaleFactor = Vector2.One; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Image trackers |
|
|
|
// Image trackers |
|
|
|
private readonly Dictionary<TextureView, ResourceSetInfo> _setsByView |
|
|
|
private readonly Dictionary<TextureView, ResourceSetInfo> setsByView |
|
|
|
= new Dictionary<TextureView, ResourceSetInfo>(); |
|
|
|
= new Dictionary<TextureView, ResourceSetInfo>(); |
|
|
|
private readonly Dictionary<Texture, TextureView> _autoViewsByTexture |
|
|
|
|
|
|
|
|
|
|
|
private readonly Dictionary<Texture, TextureView> autoViewsByTexture |
|
|
|
= new Dictionary<Texture, TextureView>(); |
|
|
|
= new Dictionary<Texture, TextureView>(); |
|
|
|
private readonly Dictionary<IntPtr, ResourceSetInfo> _viewsById = new Dictionary<IntPtr, ResourceSetInfo>(); |
|
|
|
|
|
|
|
private readonly List<IDisposable> _ownedResources = new List<IDisposable>(); |
|
|
|
|
|
|
|
private int _lastAssignedID = 100; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma warning disable CS0169 // Force Copy this DLL |
|
|
|
private readonly Dictionary<IntPtr, ResourceSetInfo> viewsById |
|
|
|
private static DefaultPathResolver ___; |
|
|
|
= new Dictionary<IntPtr, ResourceSetInfo>(); |
|
|
|
#pragma warning restore CS0169 |
|
|
|
|
|
|
|
|
|
|
|
private readonly List<IDisposable> ownedResources |
|
|
|
|
|
|
|
= new List<IDisposable>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int lastAssignedID = 100; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private GraphicsDevice gd; |
|
|
|
|
|
|
|
private bool frameBegun; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Veldrid objects |
|
|
|
|
|
|
|
private DeviceBuffer vertexBuffer; |
|
|
|
|
|
|
|
private DeviceBuffer indexBuffer; |
|
|
|
|
|
|
|
private DeviceBuffer projMatrixBuffer; |
|
|
|
|
|
|
|
private Texture fontTexture; |
|
|
|
|
|
|
|
private TextureView fontTextureView; |
|
|
|
|
|
|
|
private Shader vertexShader; |
|
|
|
|
|
|
|
private Shader fragmentShader; |
|
|
|
|
|
|
|
private ResourceLayout layout; |
|
|
|
|
|
|
|
private ResourceLayout textureLayout; |
|
|
|
|
|
|
|
private Pipeline pipeline; |
|
|
|
|
|
|
|
private ResourceSet mainResourceSet; |
|
|
|
|
|
|
|
private ResourceSet fontTextureResourceSet; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int windowWidth; |
|
|
|
|
|
|
|
private int windowHeight; |
|
|
|
|
|
|
|
private Vector2 scaleFactor = Vector2.One; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Constructs a new ImGuiController. |
|
|
|
/// Initializes a new instance of the <see cref="ImGuiController"/> class. |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="gd"> |
|
|
|
|
|
|
|
/// Graphic Device |
|
|
|
|
|
|
|
/// </param> |
|
|
|
|
|
|
|
/// <param name="outputDescription"> |
|
|
|
|
|
|
|
/// Output Description |
|
|
|
|
|
|
|
/// </param> |
|
|
|
|
|
|
|
/// <param name="width"> |
|
|
|
|
|
|
|
/// SDL2Window Window width |
|
|
|
|
|
|
|
/// </param> |
|
|
|
|
|
|
|
/// <param name="height"> |
|
|
|
|
|
|
|
/// SDL2Window Window height |
|
|
|
|
|
|
|
/// </param> |
|
|
|
|
|
|
|
/// <param name="fps"> |
|
|
|
|
|
|
|
/// desired FPS of the ImGui Overlay |
|
|
|
|
|
|
|
/// </param> |
|
|
|
public ImGuiController(GraphicsDevice gd, OutputDescription outputDescription, int width, int height, int fps) |
|
|
|
public ImGuiController(GraphicsDevice gd, OutputDescription outputDescription, int width, int height, int fps) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_gd = gd; |
|
|
|
this.gd = gd; |
|
|
|
_windowWidth = width; |
|
|
|
this.windowWidth = width; |
|
|
|
_windowHeight = height; |
|
|
|
this.windowHeight = height; |
|
|
|
|
|
|
|
|
|
|
|
IntPtr context = ImGui.CreateContext(); |
|
|
|
IntPtr context = ImGui.CreateContext(); |
|
|
|
ImGui.SetCurrentContext(context); |
|
|
|
ImGui.SetCurrentContext(context); |
|
|
|
|
|
|
|
|
|
|
|
ImGui.GetIO().Fonts.AddFontDefault(); |
|
|
|
ImGui.GetIO().Fonts.AddFontDefault(); |
|
|
|
|
|
|
|
|
|
|
|
CreateDeviceResources(gd, outputDescription); |
|
|
|
this.CreateDeviceResources(gd, outputDescription); |
|
|
|
SetKeyMappings(); |
|
|
|
SetKeyMappings(); |
|
|
|
|
|
|
|
|
|
|
|
SetPerFrameImGuiData(1f / fps); |
|
|
|
this.SetPerFrameImGuiData(1f / fps); |
|
|
|
|
|
|
|
|
|
|
|
ImGui.NewFrame(); |
|
|
|
ImGui.NewFrame(); |
|
|
|
_frameBegun = true; |
|
|
|
this.frameBegun = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// Updates the ImGui about the SDL2Window Size |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="width"> |
|
|
|
|
|
|
|
/// Width of the SDL2Window |
|
|
|
|
|
|
|
/// </param> |
|
|
|
|
|
|
|
/// <param name="height"> |
|
|
|
|
|
|
|
/// Height of the SDL2Window |
|
|
|
|
|
|
|
/// </param> |
|
|
|
public void WindowResized(int width, int height) |
|
|
|
public void WindowResized(int width, int height) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_windowWidth = width; |
|
|
|
this.windowWidth = width; |
|
|
|
_windowHeight = height; |
|
|
|
this.windowHeight = height; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// Disposes the resources acquired by the ImGuiController class. |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
public void DestroyDeviceObjects() |
|
|
|
public void DestroyDeviceObjects() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Dispose(); |
|
|
|
this.Dispose(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// Initializes different resources for ImGui Controller class. |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="gd"> |
|
|
|
|
|
|
|
/// Graphic Device |
|
|
|
|
|
|
|
/// </param> |
|
|
|
|
|
|
|
/// <param name="outputDescription"> |
|
|
|
|
|
|
|
/// Output Description |
|
|
|
|
|
|
|
/// </param> |
|
|
|
public void CreateDeviceResources(GraphicsDevice gd, OutputDescription outputDescription) |
|
|
|
public void CreateDeviceResources(GraphicsDevice gd, OutputDescription outputDescription) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_gd = gd; |
|
|
|
this.gd = gd; |
|
|
|
ResourceFactory factory = gd.ResourceFactory; |
|
|
|
ResourceFactory factory = gd.ResourceFactory; |
|
|
|
_vertexBuffer = factory.CreateBuffer(new BufferDescription(10000, BufferUsage.VertexBuffer | BufferUsage.Dynamic)); |
|
|
|
this.vertexBuffer = factory.CreateBuffer(new BufferDescription(10000, BufferUsage.VertexBuffer | BufferUsage.Dynamic)); |
|
|
|
_vertexBuffer.Name = "ImGui.NET Vertex Buffer"; |
|
|
|
this.vertexBuffer.Name = "ImGui.NET Vertex Buffer"; |
|
|
|
_indexBuffer = factory.CreateBuffer(new BufferDescription(2000, BufferUsage.IndexBuffer | BufferUsage.Dynamic)); |
|
|
|
this.indexBuffer = factory.CreateBuffer(new BufferDescription(2000, BufferUsage.IndexBuffer | BufferUsage.Dynamic)); |
|
|
|
_indexBuffer.Name = "ImGui.NET Index Buffer"; |
|
|
|
this.indexBuffer.Name = "ImGui.NET Index Buffer"; |
|
|
|
RecreateFontDeviceTexture(gd); |
|
|
|
this.RecreateFontDeviceTexture(gd); |
|
|
|
|
|
|
|
|
|
|
|
_projMatrixBuffer = factory.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer | BufferUsage.Dynamic)); |
|
|
|
this.projMatrixBuffer = factory.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer | BufferUsage.Dynamic)); |
|
|
|
_projMatrixBuffer.Name = "ImGui.NET Projection Buffer"; |
|
|
|
this.projMatrixBuffer.Name = "ImGui.NET Projection Buffer"; |
|
|
|
|
|
|
|
|
|
|
|
byte[] vertexShaderBytes = LoadEmbeddedShaderCode(gd.ResourceFactory, "imgui-vertex", ShaderStages.Vertex); |
|
|
|
byte[] vertexShaderBytes = this.LoadEmbeddedShaderCode(gd.ResourceFactory, "imgui-vertex", ShaderStages.Vertex); |
|
|
|
byte[] fragmentShaderBytes = LoadEmbeddedShaderCode(gd.ResourceFactory, "imgui-frag", ShaderStages.Fragment); |
|
|
|
byte[] fragmentShaderBytes = this.LoadEmbeddedShaderCode(gd.ResourceFactory, "imgui-frag", ShaderStages.Fragment); |
|
|
|
_vertexShader = factory.CreateShader(new ShaderDescription(ShaderStages.Vertex, vertexShaderBytes, "VS")); |
|
|
|
this.vertexShader = factory.CreateShader(new ShaderDescription(ShaderStages.Vertex, vertexShaderBytes, "VS")); |
|
|
|
_fragmentShader = factory.CreateShader(new ShaderDescription(ShaderStages.Fragment, fragmentShaderBytes, "FS")); |
|
|
|
this.fragmentShader = factory.CreateShader(new ShaderDescription(ShaderStages.Fragment, fragmentShaderBytes, "FS")); |
|
|
|
|
|
|
|
|
|
|
|
VertexLayoutDescription[] vertexLayouts = new VertexLayoutDescription[] |
|
|
|
VertexLayoutDescription[] vertexLayouts = new VertexLayoutDescription[] |
|
|
|
{ |
|
|
|
{ |
|
|
@ -112,10 +155,10 @@ |
|
|
|
new VertexElementDescription("in_color", VertexElementSemantic.Color, VertexElementFormat.Byte4_Norm)) |
|
|
|
new VertexElementDescription("in_color", VertexElementSemantic.Color, VertexElementFormat.Byte4_Norm)) |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
_layout = factory.CreateResourceLayout(new ResourceLayoutDescription( |
|
|
|
this.layout = factory.CreateResourceLayout(new ResourceLayoutDescription( |
|
|
|
new ResourceLayoutElementDescription("ProjectionMatrixBuffer", ResourceKind.UniformBuffer, ShaderStages.Vertex), |
|
|
|
new ResourceLayoutElementDescription("ProjectionMatrixBuffer", ResourceKind.UniformBuffer, ShaderStages.Vertex), |
|
|
|
new ResourceLayoutElementDescription("MainSampler", ResourceKind.Sampler, ShaderStages.Fragment))); |
|
|
|
new ResourceLayoutElementDescription("MainSampler", ResourceKind.Sampler, ShaderStages.Fragment))); |
|
|
|
_textureLayout = factory.CreateResourceLayout(new ResourceLayoutDescription( |
|
|
|
this.textureLayout = factory.CreateResourceLayout(new ResourceLayoutDescription( |
|
|
|
new ResourceLayoutElementDescription("MainTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment))); |
|
|
|
new ResourceLayoutElementDescription("MainTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment))); |
|
|
|
|
|
|
|
|
|
|
|
GraphicsPipelineDescription pd = new GraphicsPipelineDescription( |
|
|
|
GraphicsPipelineDescription pd = new GraphicsPipelineDescription( |
|
|
@ -123,65 +166,85 @@ |
|
|
|
new DepthStencilStateDescription(false, false, ComparisonKind.Always), |
|
|
|
new DepthStencilStateDescription(false, false, ComparisonKind.Always), |
|
|
|
new RasterizerStateDescription(FaceCullMode.None, PolygonFillMode.Solid, FrontFace.Clockwise, false, true), |
|
|
|
new RasterizerStateDescription(FaceCullMode.None, PolygonFillMode.Solid, FrontFace.Clockwise, false, true), |
|
|
|
PrimitiveTopology.TriangleList, |
|
|
|
PrimitiveTopology.TriangleList, |
|
|
|
new ShaderSetDescription(vertexLayouts, new[] { _vertexShader, _fragmentShader }), |
|
|
|
new ShaderSetDescription(vertexLayouts, new[] { this.vertexShader, this.fragmentShader }), |
|
|
|
new ResourceLayout[] { _layout, _textureLayout }, |
|
|
|
new ResourceLayout[] { this.layout, this.textureLayout }, |
|
|
|
outputDescription); |
|
|
|
outputDescription); |
|
|
|
_pipeline = factory.CreateGraphicsPipeline(ref pd); |
|
|
|
this.pipeline = factory.CreateGraphicsPipeline(ref pd); |
|
|
|
|
|
|
|
|
|
|
|
_mainResourceSet = factory.CreateResourceSet(new ResourceSetDescription(_layout, |
|
|
|
this.mainResourceSet = factory.CreateResourceSet(new ResourceSetDescription( |
|
|
|
_projMatrixBuffer, |
|
|
|
this.layout, this.projMatrixBuffer, gd.PointSampler)); |
|
|
|
gd.PointSampler)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_fontTextureResourceSet = factory.CreateResourceSet(new ResourceSetDescription(_textureLayout, _fontTextureView)); |
|
|
|
this.fontTextureResourceSet = factory.CreateResourceSet( |
|
|
|
|
|
|
|
new ResourceSetDescription(this.textureLayout, this.fontTextureView)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Gets or creates a handle for a texture to be drawn with ImGui. |
|
|
|
/// Gets or creates a handle for a texture to be drawn with ImGui. |
|
|
|
/// Pass the returned handle to Image() or ImageButton(). |
|
|
|
/// Pass the returned handle to Image() or ImageButton(). |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="factory"> |
|
|
|
|
|
|
|
/// Resource Factory |
|
|
|
|
|
|
|
/// </param> |
|
|
|
|
|
|
|
/// <param name="textureView"> |
|
|
|
|
|
|
|
/// Texture View |
|
|
|
|
|
|
|
/// </param> |
|
|
|
|
|
|
|
/// <returns> |
|
|
|
|
|
|
|
/// Creates ImGui Binding |
|
|
|
|
|
|
|
/// </returns> |
|
|
|
public IntPtr GetOrCreateImGuiBinding(ResourceFactory factory, TextureView textureView) |
|
|
|
public IntPtr GetOrCreateImGuiBinding(ResourceFactory factory, TextureView textureView) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!_setsByView.TryGetValue(textureView, out ResourceSetInfo rsi)) |
|
|
|
if (!this.setsByView.TryGetValue(textureView, out ResourceSetInfo rsi)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ResourceSet resourceSet = factory.CreateResourceSet(new ResourceSetDescription(_textureLayout, textureView)); |
|
|
|
ResourceSet resourceSet = factory.CreateResourceSet( |
|
|
|
rsi = new ResourceSetInfo(GetNextImGuiBindingID(), resourceSet); |
|
|
|
new ResourceSetDescription(this.textureLayout, textureView)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rsi = new ResourceSetInfo(this.GetNextImGuiBindingID(), resourceSet); |
|
|
|
|
|
|
|
|
|
|
|
_setsByView.Add(textureView, rsi); |
|
|
|
this.setsByView.Add(textureView, rsi); |
|
|
|
_viewsById.Add(rsi.ImGuiBinding, rsi); |
|
|
|
this.viewsById.Add(rsi.ImGuiBinding, rsi); |
|
|
|
_ownedResources.Add(resourceSet); |
|
|
|
this.ownedResources.Add(resourceSet); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return rsi.ImGuiBinding; |
|
|
|
return rsi.ImGuiBinding; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private IntPtr GetNextImGuiBindingID() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int newID = _lastAssignedID++; |
|
|
|
|
|
|
|
return (IntPtr)newID; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Gets or creates a handle for a texture to be drawn with ImGui. |
|
|
|
/// Gets or creates a handle for a texture to be drawn with ImGui. |
|
|
|
/// Pass the returned handle to Image() or ImageButton(). |
|
|
|
/// Pass the returned handle to Image() or ImageButton(). |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="factory"> |
|
|
|
|
|
|
|
/// Resource Factory |
|
|
|
|
|
|
|
/// </param> |
|
|
|
|
|
|
|
/// <param name="texture"> |
|
|
|
|
|
|
|
/// Texture information |
|
|
|
|
|
|
|
/// </param> |
|
|
|
|
|
|
|
/// <returns> |
|
|
|
|
|
|
|
/// Pointer to the resource |
|
|
|
|
|
|
|
/// </returns> |
|
|
|
public IntPtr GetOrCreateImGuiBinding(ResourceFactory factory, Texture texture) |
|
|
|
public IntPtr GetOrCreateImGuiBinding(ResourceFactory factory, Texture texture) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!_autoViewsByTexture.TryGetValue(texture, out TextureView textureView)) |
|
|
|
if (!this.autoViewsByTexture.TryGetValue(texture, out TextureView textureView)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
textureView = factory.CreateTextureView(texture); |
|
|
|
textureView = factory.CreateTextureView(texture); |
|
|
|
_autoViewsByTexture.Add(texture, textureView); |
|
|
|
this.autoViewsByTexture.Add(texture, textureView); |
|
|
|
_ownedResources.Add(textureView); |
|
|
|
this.ownedResources.Add(textureView); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return GetOrCreateImGuiBinding(factory, textureView); |
|
|
|
return this.GetOrCreateImGuiBinding(factory, textureView); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Retrieves the shader texture binding for the given helper handle. |
|
|
|
/// Retrieves the shader texture binding for the given helper handle. |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="imGuiBinding"> |
|
|
|
|
|
|
|
/// ImGui Binding resource pointer. |
|
|
|
|
|
|
|
/// </param> |
|
|
|
|
|
|
|
/// <returns> |
|
|
|
|
|
|
|
/// Resource |
|
|
|
|
|
|
|
/// </returns> |
|
|
|
public ResourceSet GetImageResourceSet(IntPtr imGuiBinding) |
|
|
|
public ResourceSet GetImageResourceSet(IntPtr imGuiBinding) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!_viewsById.TryGetValue(imGuiBinding, out ResourceSetInfo tvi)) |
|
|
|
if (!this.viewsById.TryGetValue(imGuiBinding, out ResourceSetInfo tvi)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("No registered ImGui binding with id " + imGuiBinding.ToString()); |
|
|
|
throw new InvalidOperationException("No registered ImGui binding with id " + imGuiBinding.ToString()); |
|
|
|
} |
|
|
|
} |
|
|
@ -189,83 +252,51 @@ |
|
|
|
return tvi.ResourceSet; |
|
|
|
return tvi.ResourceSet; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// Clears the cache images. |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
public void ClearCachedImageResources() |
|
|
|
public void ClearCachedImageResources() |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach (IDisposable resource in _ownedResources) |
|
|
|
foreach (IDisposable resource in this.ownedResources) |
|
|
|
{ |
|
|
|
{ |
|
|
|
resource.Dispose(); |
|
|
|
resource.Dispose(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_ownedResources.Clear(); |
|
|
|
this.ownedResources.Clear(); |
|
|
|
_setsByView.Clear(); |
|
|
|
this.setsByView.Clear(); |
|
|
|
_viewsById.Clear(); |
|
|
|
this.viewsById.Clear(); |
|
|
|
_autoViewsByTexture.Clear(); |
|
|
|
this.autoViewsByTexture.Clear(); |
|
|
|
_lastAssignedID = 100; |
|
|
|
this.lastAssignedID = 100; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private byte[] LoadEmbeddedShaderCode(ResourceFactory factory, string name, ShaderStages stage) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
switch (factory.BackendType) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
case GraphicsBackend.Direct3D11: |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
string resourceName = name + ".hlsl.bytes"; |
|
|
|
|
|
|
|
return GetEmbeddedResourceBytes(resourceName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case GraphicsBackend.OpenGL: |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
string resourceName = name + ".glsl"; |
|
|
|
|
|
|
|
return GetEmbeddedResourceBytes(resourceName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case GraphicsBackend.Vulkan: |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
string resourceName = name + ".spv"; |
|
|
|
|
|
|
|
return GetEmbeddedResourceBytes(resourceName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case GraphicsBackend.Metal: |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
string resourceName = name + ".metallib"; |
|
|
|
|
|
|
|
return GetEmbeddedResourceBytes(resourceName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
throw new NotImplementedException(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private byte[] GetEmbeddedResourceBytes(string resourceName) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Assembly assembly = typeof(ImGuiController).Assembly; |
|
|
|
|
|
|
|
using (Stream s = assembly.GetManifestResourceStream(resourceName)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
byte[] ret = new byte[s.Length]; |
|
|
|
|
|
|
|
s.Read(ret, 0, (int)s.Length); |
|
|
|
|
|
|
|
return ret; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Recreates the device texture used to render text. |
|
|
|
/// Recreates the device texture used to render text. |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="gd"> |
|
|
|
|
|
|
|
/// Graphic Device |
|
|
|
|
|
|
|
/// </param> |
|
|
|
public unsafe void RecreateFontDeviceTexture(GraphicsDevice gd) |
|
|
|
public unsafe void RecreateFontDeviceTexture(GraphicsDevice gd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ImGuiIOPtr io = ImGui.GetIO(); |
|
|
|
ImGuiIOPtr io = ImGui.GetIO(); |
|
|
|
|
|
|
|
|
|
|
|
// Build |
|
|
|
// Build |
|
|
|
byte* pixels; |
|
|
|
byte* pixels; |
|
|
|
int width, height, bytesPerPixel; |
|
|
|
int width, height, bytesPerPixel; |
|
|
|
io.Fonts.GetTexDataAsRGBA32(out pixels, out width, out height, out bytesPerPixel); |
|
|
|
io.Fonts.GetTexDataAsRGBA32(out pixels, out width, out height, out bytesPerPixel); |
|
|
|
|
|
|
|
|
|
|
|
// Store our identifier |
|
|
|
// Store our identifier |
|
|
|
io.Fonts.SetTexID(_fontAtlasID); |
|
|
|
io.Fonts.SetTexID(this.fontAtlasID); |
|
|
|
|
|
|
|
|
|
|
|
_fontTexture = gd.ResourceFactory.CreateTexture(TextureDescription.Texture2D( |
|
|
|
this.fontTexture = gd.ResourceFactory.CreateTexture(TextureDescription.Texture2D( |
|
|
|
(uint)width, |
|
|
|
(uint)width, |
|
|
|
(uint)height, |
|
|
|
(uint)height, |
|
|
|
1, |
|
|
|
1, |
|
|
|
1, |
|
|
|
1, |
|
|
|
PixelFormat.R8_G8_B8_A8_UNorm, |
|
|
|
PixelFormat.R8_G8_B8_A8_UNorm, |
|
|
|
TextureUsage.Sampled)); |
|
|
|
TextureUsage.Sampled)); |
|
|
|
_fontTexture.Name = "ImGui.NET Font Texture"; |
|
|
|
this.fontTexture.Name = "ImGui.NET Font Texture"; |
|
|
|
gd.UpdateTexture( |
|
|
|
gd.UpdateTexture( |
|
|
|
_fontTexture, |
|
|
|
this.fontTexture, |
|
|
|
(IntPtr)pixels, |
|
|
|
(IntPtr)pixels, |
|
|
|
(uint)(bytesPerPixel * width * height), |
|
|
|
(uint)(bytesPerPixel * width * height), |
|
|
|
0, |
|
|
|
0, |
|
|
@ -276,7 +307,7 @@ |
|
|
|
1, |
|
|
|
1, |
|
|
|
0, |
|
|
|
0, |
|
|
|
0); |
|
|
|
0); |
|
|
|
_fontTextureView = gd.ResourceFactory.CreateTextureView(_fontTexture); |
|
|
|
this.fontTextureView = gd.ResourceFactory.CreateTextureView(this.fontTexture); |
|
|
|
|
|
|
|
|
|
|
|
io.Fonts.ClearTexData(); |
|
|
|
io.Fonts.ClearTexData(); |
|
|
|
} |
|
|
|
} |
|
|
@ -287,46 +318,67 @@ |
|
|
|
/// or index data has increased beyond the capacity of the existing buffers. |
|
|
|
/// or index data has increased beyond the capacity of the existing buffers. |
|
|
|
/// A <see cref="CommandList"/> is needed to submit drawing and resource update commands. |
|
|
|
/// A <see cref="CommandList"/> is needed to submit drawing and resource update commands. |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="gd"> |
|
|
|
|
|
|
|
/// Graphic Device |
|
|
|
|
|
|
|
/// </param> |
|
|
|
|
|
|
|
/// <param name="cl"> |
|
|
|
|
|
|
|
/// Command List |
|
|
|
|
|
|
|
/// </param> |
|
|
|
public void Render(GraphicsDevice gd, CommandList cl) |
|
|
|
public void Render(GraphicsDevice gd, CommandList cl) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (_frameBegun) |
|
|
|
if (this.frameBegun) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_frameBegun = false; |
|
|
|
this.frameBegun = false; |
|
|
|
ImGui.Render(); |
|
|
|
ImGui.Render(); |
|
|
|
RenderImDrawData(ImGui.GetDrawData(), gd, cl); |
|
|
|
this.RenderImDrawData(ImGui.GetDrawData(), gd, cl); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Initilizes a new frame |
|
|
|
/// Initilizes a new frame |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="deltaSeconds"> |
|
|
|
|
|
|
|
/// FPS delay |
|
|
|
|
|
|
|
/// </param> |
|
|
|
public void InitlizeFrame(float deltaSeconds) |
|
|
|
public void InitlizeFrame(float deltaSeconds) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (_frameBegun) |
|
|
|
if (this.frameBegun) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ImGui.Render(); |
|
|
|
ImGui.Render(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SetPerFrameImGuiData(deltaSeconds); |
|
|
|
this.SetPerFrameImGuiData(deltaSeconds); |
|
|
|
|
|
|
|
|
|
|
|
_frameBegun = true; |
|
|
|
this.frameBegun = true; |
|
|
|
ImGui.NewFrame(); |
|
|
|
ImGui.NewFrame(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Sets per-frame data based on the associated window. |
|
|
|
/// Frees all graphics resources used by the renderer. |
|
|
|
/// This is called by Update(float). |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
private void SetPerFrameImGuiData(float deltaSeconds) |
|
|
|
public void Dispose() |
|
|
|
{ |
|
|
|
{ |
|
|
|
ImGuiIOPtr io = ImGui.GetIO(); |
|
|
|
this.vertexBuffer.Dispose(); |
|
|
|
io.DisplaySize = new Vector2( |
|
|
|
this.indexBuffer.Dispose(); |
|
|
|
_windowWidth / _scaleFactor.X, |
|
|
|
this.projMatrixBuffer.Dispose(); |
|
|
|
_windowHeight / _scaleFactor.Y); |
|
|
|
this.fontTexture.Dispose(); |
|
|
|
io.DisplayFramebufferScale = _scaleFactor; |
|
|
|
this.fontTextureView.Dispose(); |
|
|
|
io.DeltaTime = deltaSeconds; // DeltaTime is in seconds. |
|
|
|
this.vertexShader.Dispose(); |
|
|
|
|
|
|
|
this.fragmentShader.Dispose(); |
|
|
|
|
|
|
|
this.layout.Dispose(); |
|
|
|
|
|
|
|
this.textureLayout.Dispose(); |
|
|
|
|
|
|
|
this.pipeline.Dispose(); |
|
|
|
|
|
|
|
this.mainResourceSet.Dispose(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (IDisposable resource in this.ownedResources) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
resource.Dispose(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// Allows ImGui to identify the Keys |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
private static void SetKeyMappings() |
|
|
|
private static void SetKeyMappings() |
|
|
|
{ |
|
|
|
{ |
|
|
|
ImGuiIOPtr io = ImGui.GetIO(); |
|
|
|
ImGuiIOPtr io = ImGui.GetIO(); |
|
|
@ -343,7 +395,8 @@ |
|
|
|
io.KeyMap[(int)ImGuiKey.Backspace] = (int)System.Windows.Forms.Keys.Back; |
|
|
|
io.KeyMap[(int)ImGuiKey.Backspace] = (int)System.Windows.Forms.Keys.Back; |
|
|
|
io.KeyMap[(int)ImGuiKey.Enter] = (int)System.Windows.Forms.Keys.Enter; |
|
|
|
io.KeyMap[(int)ImGuiKey.Enter] = (int)System.Windows.Forms.Keys.Enter; |
|
|
|
io.KeyMap[(int)ImGuiKey.Escape] = (int)System.Windows.Forms.Keys.Escape; |
|
|
|
io.KeyMap[(int)ImGuiKey.Escape] = (int)System.Windows.Forms.Keys.Escape; |
|
|
|
//io.KeyMap[(int)ImGuiKey.COUNT] = (int)System.Windows.Forms.Keys.un; |
|
|
|
|
|
|
|
|
|
|
|
// io.KeyMap[(int)ImGuiKey.COUNT] = (int)System.Windows.Forms.Keys.un; |
|
|
|
io.KeyMap[(int)ImGuiKey.Insert] = (int)System.Windows.Forms.Keys.Insert; |
|
|
|
io.KeyMap[(int)ImGuiKey.Insert] = (int)System.Windows.Forms.Keys.Insert; |
|
|
|
io.KeyMap[(int)ImGuiKey.Space] = (int)System.Windows.Forms.Keys.Space; |
|
|
|
io.KeyMap[(int)ImGuiKey.Space] = (int)System.Windows.Forms.Keys.Space; |
|
|
|
io.KeyMap[(int)ImGuiKey.A] = (int)System.Windows.Forms.Keys.A; |
|
|
|
io.KeyMap[(int)ImGuiKey.A] = (int)System.Windows.Forms.Keys.A; |
|
|
@ -354,6 +407,94 @@ |
|
|
|
io.KeyMap[(int)ImGuiKey.Z] = (int)System.Windows.Forms.Keys.Z; |
|
|
|
io.KeyMap[(int)ImGuiKey.Z] = (int)System.Windows.Forms.Keys.Z; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// Get the Next ImGui Binding ID. |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <returns> |
|
|
|
|
|
|
|
/// ImGui next binding ID. |
|
|
|
|
|
|
|
/// </returns> |
|
|
|
|
|
|
|
private IntPtr GetNextImGuiBindingID() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int newID = this.lastAssignedID++; |
|
|
|
|
|
|
|
return (IntPtr)newID; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// Loading Shader Code |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="factory"> |
|
|
|
|
|
|
|
/// Resource Factory |
|
|
|
|
|
|
|
/// </param> |
|
|
|
|
|
|
|
/// <param name="name"> |
|
|
|
|
|
|
|
/// Shader file name |
|
|
|
|
|
|
|
/// </param> |
|
|
|
|
|
|
|
/// <param name="stage"> |
|
|
|
|
|
|
|
/// Shader stage |
|
|
|
|
|
|
|
/// </param> |
|
|
|
|
|
|
|
/// <returns> |
|
|
|
|
|
|
|
/// Returns shader byte code |
|
|
|
|
|
|
|
/// </returns> |
|
|
|
|
|
|
|
private byte[] LoadEmbeddedShaderCode(ResourceFactory factory, string name, ShaderStages stage) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
switch (factory.BackendType) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
case GraphicsBackend.Direct3D11: |
|
|
|
|
|
|
|
string resourceName = name + ".hlsl.bytes"; |
|
|
|
|
|
|
|
return this.GetEmbeddedResourceBytes(resourceName); |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
throw new NotImplementedException(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// Get embedded resource file in bytes |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="resourceName"> |
|
|
|
|
|
|
|
/// Name of the resource file |
|
|
|
|
|
|
|
/// </param> |
|
|
|
|
|
|
|
/// <returns> |
|
|
|
|
|
|
|
/// Byte code of the resource file |
|
|
|
|
|
|
|
/// </returns> |
|
|
|
|
|
|
|
private byte[] GetEmbeddedResourceBytes(string resourceName) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Assembly assembly = typeof(ImGuiController).Assembly; |
|
|
|
|
|
|
|
using (Stream s = assembly.GetManifestResourceStream(resourceName)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
byte[] ret = new byte[s.Length]; |
|
|
|
|
|
|
|
s.Read(ret, 0, (int)s.Length); |
|
|
|
|
|
|
|
return ret; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// Sets per-frame data based on the associated window. |
|
|
|
|
|
|
|
/// This is called by Update(float). |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="deltaSeconds"> |
|
|
|
|
|
|
|
/// FPS delay |
|
|
|
|
|
|
|
/// </param> |
|
|
|
|
|
|
|
private void SetPerFrameImGuiData(float deltaSeconds) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ImGuiIOPtr io = ImGui.GetIO(); |
|
|
|
|
|
|
|
io.DisplaySize = new Vector2( |
|
|
|
|
|
|
|
this.windowWidth / this.scaleFactor.X, |
|
|
|
|
|
|
|
this.windowHeight / this.scaleFactor.Y); |
|
|
|
|
|
|
|
io.DisplayFramebufferScale = this.scaleFactor; |
|
|
|
|
|
|
|
io.DeltaTime = deltaSeconds; // DeltaTime is in seconds. |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// Draw the ImGui graphic data |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="draw_data"> |
|
|
|
|
|
|
|
/// ImGui data to draw |
|
|
|
|
|
|
|
/// </param> |
|
|
|
|
|
|
|
/// <param name="gd"> |
|
|
|
|
|
|
|
/// Graphic Device |
|
|
|
|
|
|
|
/// </param> |
|
|
|
|
|
|
|
/// <param name="cl"> |
|
|
|
|
|
|
|
/// Command List |
|
|
|
|
|
|
|
/// </param> |
|
|
|
private void RenderImDrawData(ImDrawDataPtr draw_data, GraphicsDevice gd, CommandList cl) |
|
|
|
private void RenderImDrawData(ImDrawDataPtr draw_data, GraphicsDevice gd, CommandList cl) |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint vertexOffsetInVertices = 0; |
|
|
|
uint vertexOffsetInVertices = 0; |
|
|
@ -365,17 +506,19 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint totalVBSize = (uint)(draw_data.TotalVtxCount * Unsafe.SizeOf<ImDrawVert>()); |
|
|
|
uint totalVBSize = (uint)(draw_data.TotalVtxCount * Unsafe.SizeOf<ImDrawVert>()); |
|
|
|
if (totalVBSize > _vertexBuffer.SizeInBytes) |
|
|
|
if (totalVBSize > this.vertexBuffer.SizeInBytes) |
|
|
|
{ |
|
|
|
{ |
|
|
|
gd.DisposeWhenIdle(_vertexBuffer); |
|
|
|
gd.DisposeWhenIdle(this.vertexBuffer); |
|
|
|
_vertexBuffer = gd.ResourceFactory.CreateBuffer(new BufferDescription((uint)(totalVBSize * 1.5f), BufferUsage.VertexBuffer | BufferUsage.Dynamic)); |
|
|
|
this.vertexBuffer = gd.ResourceFactory.CreateBuffer(new BufferDescription( |
|
|
|
|
|
|
|
(uint)(totalVBSize * 1.5f), BufferUsage.VertexBuffer | BufferUsage.Dynamic)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint totalIBSize = (uint)(draw_data.TotalIdxCount * sizeof(ushort)); |
|
|
|
uint totalIBSize = (uint)(draw_data.TotalIdxCount * sizeof(ushort)); |
|
|
|
if (totalIBSize > _indexBuffer.SizeInBytes) |
|
|
|
if (totalIBSize > this.indexBuffer.SizeInBytes) |
|
|
|
{ |
|
|
|
{ |
|
|
|
gd.DisposeWhenIdle(_indexBuffer); |
|
|
|
gd.DisposeWhenIdle(this.indexBuffer); |
|
|
|
_indexBuffer = gd.ResourceFactory.CreateBuffer(new BufferDescription((uint)(totalIBSize * 1.5f), BufferUsage.IndexBuffer | BufferUsage.Dynamic)); |
|
|
|
this.indexBuffer = gd.ResourceFactory.CreateBuffer(new BufferDescription( |
|
|
|
|
|
|
|
(uint)(totalIBSize * 1.5f), BufferUsage.IndexBuffer | BufferUsage.Dynamic)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < draw_data.CmdListsCount; i++) |
|
|
|
for (int i = 0; i < draw_data.CmdListsCount; i++) |
|
|
@ -383,13 +526,13 @@ |
|
|
|
ImDrawListPtr cmd_list = draw_data.CmdListsRange[i]; |
|
|
|
ImDrawListPtr cmd_list = draw_data.CmdListsRange[i]; |
|
|
|
|
|
|
|
|
|
|
|
cl.UpdateBuffer( |
|
|
|
cl.UpdateBuffer( |
|
|
|
_vertexBuffer, |
|
|
|
this.vertexBuffer, |
|
|
|
vertexOffsetInVertices * (uint)Unsafe.SizeOf<ImDrawVert>(), |
|
|
|
vertexOffsetInVertices * (uint)Unsafe.SizeOf<ImDrawVert>(), |
|
|
|
cmd_list.VtxBuffer.Data, |
|
|
|
cmd_list.VtxBuffer.Data, |
|
|
|
(uint)(cmd_list.VtxBuffer.Size * Unsafe.SizeOf<ImDrawVert>())); |
|
|
|
(uint)(cmd_list.VtxBuffer.Size * Unsafe.SizeOf<ImDrawVert>())); |
|
|
|
|
|
|
|
|
|
|
|
cl.UpdateBuffer( |
|
|
|
cl.UpdateBuffer( |
|
|
|
_indexBuffer, |
|
|
|
this.indexBuffer, |
|
|
|
indexOffsetInElements * sizeof(ushort), |
|
|
|
indexOffsetInElements * sizeof(ushort), |
|
|
|
cmd_list.IdxBuffer.Data, |
|
|
|
cmd_list.IdxBuffer.Data, |
|
|
|
(uint)(cmd_list.IdxBuffer.Size * sizeof(ushort))); |
|
|
|
(uint)(cmd_list.IdxBuffer.Size * sizeof(ushort))); |
|
|
@ -408,12 +551,12 @@ |
|
|
|
-1.0f, |
|
|
|
-1.0f, |
|
|
|
1.0f); |
|
|
|
1.0f); |
|
|
|
|
|
|
|
|
|
|
|
_gd.UpdateBuffer(_projMatrixBuffer, 0, ref mvp); |
|
|
|
this.gd.UpdateBuffer(this.projMatrixBuffer, 0, ref mvp); |
|
|
|
|
|
|
|
|
|
|
|
cl.SetVertexBuffer(0, _vertexBuffer); |
|
|
|
cl.SetVertexBuffer(0, this.vertexBuffer); |
|
|
|
cl.SetIndexBuffer(_indexBuffer, IndexFormat.UInt16); |
|
|
|
cl.SetIndexBuffer(this.indexBuffer, IndexFormat.UInt16); |
|
|
|
cl.SetPipeline(_pipeline); |
|
|
|
cl.SetPipeline(this.pipeline); |
|
|
|
cl.SetGraphicsResourceSet(0, _mainResourceSet); |
|
|
|
cl.SetGraphicsResourceSet(0, this.mainResourceSet); |
|
|
|
|
|
|
|
|
|
|
|
draw_data.ScaleClipRects(io.DisplayFramebufferScale); |
|
|
|
draw_data.ScaleClipRects(io.DisplayFramebufferScale); |
|
|
|
|
|
|
|
|
|
|
@ -434,13 +577,15 @@ |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (pcmd.TextureId != IntPtr.Zero) |
|
|
|
if (pcmd.TextureId != IntPtr.Zero) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (pcmd.TextureId == _fontAtlasID) |
|
|
|
if (pcmd.TextureId == this.fontAtlasID) |
|
|
|
{ |
|
|
|
{ |
|
|
|
cl.SetGraphicsResourceSet(1, _fontTextureResourceSet); |
|
|
|
cl.SetGraphicsResourceSet( |
|
|
|
|
|
|
|
1, this.fontTextureResourceSet); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
cl.SetGraphicsResourceSet(1, GetImageResourceSet(pcmd.TextureId)); |
|
|
|
cl.SetGraphicsResourceSet( |
|
|
|
|
|
|
|
1, this.GetImageResourceSet(pcmd.TextureId)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -456,33 +601,14 @@ |
|
|
|
|
|
|
|
|
|
|
|
idx_offset += (int)pcmd.ElemCount; |
|
|
|
idx_offset += (int)pcmd.ElemCount; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
vtx_offset += cmd_list.VtxBuffer.Size; |
|
|
|
vtx_offset += cmd_list.VtxBuffer.Size; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Frees all graphics resources used by the renderer. |
|
|
|
/// ResourceSetInfo |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
public void Dispose() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
_vertexBuffer.Dispose(); |
|
|
|
|
|
|
|
_indexBuffer.Dispose(); |
|
|
|
|
|
|
|
_projMatrixBuffer.Dispose(); |
|
|
|
|
|
|
|
_fontTexture.Dispose(); |
|
|
|
|
|
|
|
_fontTextureView.Dispose(); |
|
|
|
|
|
|
|
_vertexShader.Dispose(); |
|
|
|
|
|
|
|
_fragmentShader.Dispose(); |
|
|
|
|
|
|
|
_layout.Dispose(); |
|
|
|
|
|
|
|
_textureLayout.Dispose(); |
|
|
|
|
|
|
|
_pipeline.Dispose(); |
|
|
|
|
|
|
|
_mainResourceSet.Dispose(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (IDisposable resource in _ownedResources) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
resource.Dispose(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private struct ResourceSetInfo |
|
|
|
private struct ResourceSetInfo |
|
|
|
{ |
|
|
|
{ |
|
|
|
public readonly IntPtr ImGuiBinding; |
|
|
|
public readonly IntPtr ImGuiBinding; |
|
|
@ -490,8 +616,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
public ResourceSetInfo(IntPtr imGuiBinding, ResourceSet resourceSet) |
|
|
|
public ResourceSetInfo(IntPtr imGuiBinding, ResourceSet resourceSet) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ImGuiBinding = imGuiBinding; |
|
|
|
this.ImGuiBinding = imGuiBinding; |
|
|
|
ResourceSet = resourceSet; |
|
|
|
this.ResourceSet = resourceSet; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|