// Copyright (c) 2010-2014 SharpDX - SharpDX Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// currently it is working correctly only on Desktop platform
using System;
using System.Runtime.InteropServices;
namespace SharpDX.Diagnostics
{
///
/// Helper class to allow programmatic capturing of graphics information that can be loaded later in Visual Studio.
/// This is a managed implementation of the VsDbg class (http://msdn.microsoft.com/en-us/library/vstudio/dn440549.aspx).
/// Requires to have installed VS Remote Tools.
/// http://msdn.microsoft.com/en-us/library/vstudio/hh708963.aspx
/// http://msdn.microsoft.com/en-us/library/vstudio/hh780905.aspx
///
public sealed class VSGraphicsDebugger : DisposeBase
{
///
/// Helper structure to ease the begin/end graphics capturing
///
///
/// var debugger = new VSGraphicsDebugger();
/// using(debugger.BeginCapture())
/// {
/// ...
/// }
///
public struct CaptureToken : IDisposable
{
private readonly VSGraphicsDebugger debugger;
///
/// Creates a new instance of the structure.
///
/// The attanched graphics debugger.
internal CaptureToken(VSGraphicsDebugger debugger)
: this()
{
this.debugger = debugger;
}
///
/// Ends the capture by calling .
///
public void Dispose()
{
debugger.EndCapture();
}
}
///
/// Creates a new instance of the class and prepares the in-app component of graphics diagnostics to actively capture and record graphics information..
///
/// The destination filename for log writing.
public VSGraphicsDebugger(string logFileName)
{
VsgDbgInit(logFileName);
}
///
/// Copies the contents of the active graphics log (.vsglog) file into a new file.
///
/// The new log file name.
public void CopyLogFile(string destinationFileName)
{
VsgDbgCopy(destinationFileName);
}
///
/// Toggles the graphics diagnostics HUD overlay on or off.
///
public void ToggleHUD()
{
VsgDbgToggleHUD();
}
///
/// Adds a custom message to the graphics diagnostics HUD (Head-Up Display).
///
/// The message to add.
public void AddHUDMessage(string message)
{
VsgDbgAddHUDMessage(message);
}
///
/// Captures the remainder of the current frame to the graphics log file.
///
public void CaptureCurrentFrame()
{
VsgDbgCaptureCurrentFrame();
}
///
/// Begins a capture interval that will end with .
///
/// A instance that once disposed, calls automatically the method.
public CaptureToken BeginCapture()
{
VsgDbgBeginCapture();
return new CaptureToken(this);
}
///
/// Ends a capture interval that was started with .
///
public void EndCapture()
{
VsgDbgEndCapture();
}
///
/// Finalizes the graphics log file, closes it, and frees resources that were used while the app was actively recording graphics information.
///
/// Ignored.
protected override void Dispose(bool disposing)
{
VsgDbgUnInit();
}
#region vsgcapture.h imports:
// extern "C" void __stdcall VsgDbgInit(_In_z_ wchar_t const * szVSGLog);
[DllImport("VsGraphicsHelper.dll", EntryPoint = "VsgDbgInit", CharSet = CharSet.Unicode)]
private static extern void VsgDbgInit(string logName);
// extern "C" void __stdcall VsgDbgUnInit();
[DllImport("VsGraphicsHelper.dll", EntryPoint = "VsgDbgUnInit", CharSet = CharSet.Unicode)]
private static extern void VsgDbgUnInit();
// extern "C" void __stdcall VsgDbgToggleHUD();
[DllImport("VsGraphicsHelper.dll", EntryPoint = "VsgDbgToggleHUD", CharSet = CharSet.Unicode)]
private static extern void VsgDbgToggleHUD();
// extern "C" void __stdcall VsgDbgCaptureCurrentFrame();
[DllImport("VsGraphicsHelper.dll", EntryPoint = "VsgDbgCaptureCurrentFrame", CharSet = CharSet.Unicode)]
private static extern void VsgDbgCaptureCurrentFrame();
// extern "C" void __stdcall VsgDbgBeginCapture();
[DllImport("VsGraphicsHelper.dll", EntryPoint = "VsgDbgBeginCapture", CharSet = CharSet.Unicode)]
private static extern void VsgDbgBeginCapture();
// extern "C" void __stdcall VsgDbgEndCapture();
[DllImport("VsGraphicsHelper.dll", EntryPoint = "VsgDbgEndCapture", CharSet = CharSet.Unicode)]
private static extern void VsgDbgEndCapture();
// extern "C" void __stdcall VsgDbgCopy(_In_z_ wchar_t const * szNewVSGLog);
[DllImport("VsGraphicsHelper.dll", EntryPoint = "VsgDbgCopy", CharSet = CharSet.Unicode)]
private static extern void VsgDbgCopy(string newLogName);
// extern "C" void __stdcall VsgDbgAddHUDMessage(_In_z_ wchar_t const * szMessage);
[DllImport("VsGraphicsHelper.dll", EntryPoint = "VsgDbgAddHUDMessage", CharSet = CharSet.Unicode)]
private static extern void VsgDbgAddHUDMessage(string message);
#endregion
}
}